Bug 1165710 - Make DrawTargetSkia own its snapshot instead of the other way around. r=gw280
☠☠ backed out by dc683817edec ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 26 May 2015 15:10:25 +1200
changeset 245641 af2af798ad8fcdaaefcc85a995f1d73689dcb922
parent 245640 3569f024ef4768a2a56bcbd73f74da892ebd148f
child 245642 45998275f42373a83a7014618c5a52a856446a54
push id13177
push userkwierso@gmail.com
push dateTue, 26 May 2015 23:26:28 +0000
treeherderfx-team@b991cd5a0ad1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw280
bugs1165710
milestone41.0a1
Bug 1165710 - Make DrawTargetSkia own its snapshot instead of the other way around. r=gw280
gfx/2d/DrawTargetSkia.cpp
gfx/2d/DrawTargetSkia.h
gfx/2d/SourceSurfaceSkia.cpp
gfx/2d/SourceSurfaceSkia.h
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -127,27 +127,28 @@ DrawTargetSkia::DrawTargetSkia()
  mTexture(0),
 #endif
  mSnapshot(nullptr)
 {
 }
 
 DrawTargetSkia::~DrawTargetSkia()
 {
+  MarkChanged();
 }
 
 TemporaryRef<SourceSurface>
 DrawTargetSkia::Snapshot()
 {
   RefPtr<SourceSurfaceSkia> snapshot = mSnapshot;
   if (!snapshot) {
     snapshot = new SourceSurfaceSkia();
+    if (!snapshot->InitFromCanvas(mCanvas.get(), mFormat))
+      return nullptr;
     mSnapshot = snapshot;
-    if (!snapshot->InitFromCanvas(mCanvas.get(), mFormat, this))
-      return nullptr;
   }
 
   return snapshot.forget();
 }
 
 bool
 DrawTargetSkia::LockBits(uint8_t** aData, IntSize* aSize,
                           int32_t* aStride, SurfaceFormat* aFormat)
@@ -1003,16 +1004,10 @@ DrawTargetSkia::MarkChanged()
 // Return a rect (in user space) that covers the entire surface by applying
 // the inverse of GetTransform() to (0, 0, mSize.width, mSize.height).
 SkRect
 DrawTargetSkia::SkRectCoveringWholeSurface() const
 {
   return RectToSkRect(mTransform.TransformBounds(Rect(0, 0, mSize.width, mSize.height)));
 }
 
-void
-DrawTargetSkia::SnapshotDestroyed()
-{
-  mSnapshot = nullptr;
-}
-
 }
 }
--- a/gfx/2d/DrawTargetSkia.h
+++ b/gfx/2d/DrawTargetSkia.h
@@ -120,32 +120,31 @@ public:
   operator std::string() const {
     std::stringstream stream;
     stream << "DrawTargetSkia(" << this << ")";
     return stream.str();
   }
 
 private:
   friend class SourceSurfaceSkia;
-  void SnapshotDestroyed();
 
   void MarkChanged();
 
   bool ShouldLCDRenderText(FontType aFontType, AntialiasMode aAntialiasMode);
 
   SkRect SkRectCoveringWholeSurface() const;
 
   bool UsingSkiaGPU() const;
 
 #ifdef USE_SKIA_GPU
   RefPtrSkia<GrContext> mGrContext;
   uint32_t mTexture;
 #endif
 
   IntSize mSize;
   RefPtrSkia<SkCanvas> mCanvas;
-  SourceSurfaceSkia* mSnapshot;
+  RefPtr<SourceSurfaceSkia> mSnapshot;
 };
 
 }
 }
 
 #endif // _MOZILLA_GFX_SOURCESURFACESKIA_H
--- a/gfx/2d/SourceSurfaceSkia.cpp
+++ b/gfx/2d/SourceSurfaceSkia.cpp
@@ -12,55 +12,51 @@
 #include "DrawTargetSkia.h"
 #include "DataSurfaceHelpers.h"
 #include "skia/SkGrPixelRef.h"
 
 namespace mozilla {
 namespace gfx {
 
 SourceSurfaceSkia::SourceSurfaceSkia()
-  : mDrawTarget(nullptr), mLocked(false)
+  : mLocked(false)
+  , mBitmapDataOwned(false)
 {
 }
 
 SourceSurfaceSkia::~SourceSurfaceSkia()
 {
   MaybeUnlock();
-  if (mDrawTarget) {
-    mDrawTarget->SnapshotDestroyed();
-    mDrawTarget = nullptr;
-  }
 }
 
 IntSize
 SourceSurfaceSkia::GetSize() const
 {
   return mSize;
 }
 
 SurfaceFormat
 SourceSurfaceSkia::GetFormat() const
 {
   return mFormat;
 }
 
 bool
 SourceSurfaceSkia::InitFromCanvas(SkCanvas* aCanvas,
-                                  SurfaceFormat aFormat,
-                                  DrawTargetSkia* aOwner)
+                                  SurfaceFormat aFormat)
 {
   SkISize size = aCanvas->getDeviceSize();
 
   mBitmap = (SkBitmap)aCanvas->getDevice()->accessBitmap(false);
 
   mFormat = aFormat;
 
   mSize = IntSize(size.fWidth, size.fHeight);
   mStride = mBitmap.rowBytes();
-  mDrawTarget = aOwner;
+  mBitmapDataOwned = true;
 
   return true;
 }
 
 bool 
 SourceSurfaceSkia::InitFromData(unsigned char* aData,
                                 const IntSize &aSize,
                                 int32_t aStride,
@@ -110,17 +106,16 @@ SourceSurfaceSkia::InitFromTexture(DrawT
 
   GrTexture *skiaTexture = aOwner->mGrContext->wrapBackendTexture(skiaTexGlue);
   SkImageInfo imgInfo = SkImageInfo::Make(aSize.width, aSize.height, GfxFormatToSkiaColorType(aFormat), kOpaque_SkAlphaType);
   SkGrPixelRef *texRef = new SkGrPixelRef(imgInfo, skiaTexture, false);
   mBitmap.setInfo(imgInfo, aSize.width*aSize.height*4);
   mBitmap.setPixelRef(texRef);
 #endif
 
-  mDrawTarget = aOwner;
   return true;
 }
 
 unsigned char*
 SourceSurfaceSkia::GetData()
 {
   if (!mLocked) {
     mBitmap.lockPixels();
@@ -129,20 +124,19 @@ SourceSurfaceSkia::GetData()
 
   unsigned char *pixels = (unsigned char *)mBitmap.getPixels();
   return pixels;
 }
 
 void
 SourceSurfaceSkia::DrawTargetWillChange()
 {
-  if (mDrawTarget) {
+  if (mBitmapDataOwned) {
     MaybeUnlock();
 
-    mDrawTarget = nullptr;
     SkBitmap temp = mBitmap;
     mBitmap.reset();
     temp.copyTo(&mBitmap, temp.colorType());
   }
 }
 
 void
 SourceSurfaceSkia::MaybeUnlock()
--- a/gfx/2d/SourceSurfaceSkia.h
+++ b/gfx/2d/SourceSurfaceSkia.h
@@ -31,42 +31,40 @@ public:
   SkBitmap& GetBitmap() { return mBitmap; }
 
   bool InitFromData(unsigned char* aData,
                     const IntSize &aSize,
                     int32_t aStride,
                     SurfaceFormat aFormat);
 
   bool InitFromCanvas(SkCanvas* aCanvas,
-                      SurfaceFormat aFormat,
-                      DrawTargetSkia* aOwner);
+                      SurfaceFormat aFormat);
 
   /**
    * NOTE: While wrapping a Texture for SkiaGL, the texture *must* be created
    *       with the same GLcontext of DrawTargetSkia
    */
   bool InitFromTexture(DrawTargetSkia* aOwner,
                        unsigned int aTexture,
                        const IntSize &aSize,
                        SurfaceFormat aFormat);
 
   virtual unsigned char *GetData();
 
   virtual int32_t Stride() { return mStride; }
 
 private:
   friend class DrawTargetSkia;
-
   void DrawTargetWillChange();
   void MaybeUnlock();
 
   SkBitmap mBitmap;
   SurfaceFormat mFormat;
   IntSize mSize;
   int32_t mStride;
-  RefPtr<DrawTargetSkia> mDrawTarget;
   bool mLocked;
+  bool mBitmapDataOwned;
 };
 
 }
 }
 
 #endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */