From 39c705971226d9185511d3d9a0e38bd12c63b6ff Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Tue, 26 May 2015 15:10:25 +1200 Subject: [PATCH] Bug 1165710 - Make DrawTargetSkia own its snapshot instead of the other way around. r=gw280 --- gfx/2d/DrawTargetSkia.cpp | 11 +++-------- gfx/2d/DrawTargetSkia.h | 3 +-- gfx/2d/SourceSurfaceSkia.cpp | 16 +++++----------- gfx/2d/SourceSurfaceSkia.h | 6 ++---- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp index 8acad3bbd9e..ad4ead1f349 100644 --- a/gfx/2d/DrawTargetSkia.cpp +++ b/gfx/2d/DrawTargetSkia.cpp @@ -132,6 +132,7 @@ DrawTargetSkia::DrawTargetSkia() DrawTargetSkia::~DrawTargetSkia() { + MarkChanged(); } TemporaryRef @@ -140,9 +141,9 @@ DrawTargetSkia::Snapshot() RefPtr snapshot = mSnapshot; if (!snapshot) { snapshot = new SourceSurfaceSkia(); - mSnapshot = snapshot; - if (!snapshot->InitFromCanvas(mCanvas.get(), mFormat, this)) + if (!snapshot->InitFromCanvas(mCanvas.get(), mFormat)) return nullptr; + mSnapshot = snapshot; } return snapshot.forget(); @@ -1008,11 +1009,5 @@ DrawTargetSkia::SkRectCoveringWholeSurface() const return RectToSkRect(mTransform.TransformBounds(Rect(0, 0, mSize.width, mSize.height))); } -void -DrawTargetSkia::SnapshotDestroyed() -{ - mSnapshot = nullptr; -} - } } diff --git a/gfx/2d/DrawTargetSkia.h b/gfx/2d/DrawTargetSkia.h index c15a179848b..3bbfbd33290 100644 --- a/gfx/2d/DrawTargetSkia.h +++ b/gfx/2d/DrawTargetSkia.h @@ -125,7 +125,6 @@ public: private: friend class SourceSurfaceSkia; - void SnapshotDestroyed(); void MarkChanged(); @@ -142,7 +141,7 @@ private: IntSize mSize; RefPtrSkia mCanvas; - SourceSurfaceSkia* mSnapshot; + RefPtr mSnapshot; }; } diff --git a/gfx/2d/SourceSurfaceSkia.cpp b/gfx/2d/SourceSurfaceSkia.cpp index 959e4f235c0..cf0b630e0e8 100644 --- a/gfx/2d/SourceSurfaceSkia.cpp +++ b/gfx/2d/SourceSurfaceSkia.cpp @@ -17,17 +17,14 @@ namespace mozilla { namespace gfx { SourceSurfaceSkia::SourceSurfaceSkia() - : mDrawTarget(nullptr), mLocked(false) + : mLocked(false) + , mBitmapDataOwned(false) { } SourceSurfaceSkia::~SourceSurfaceSkia() { MaybeUnlock(); - if (mDrawTarget) { - mDrawTarget->SnapshotDestroyed(); - mDrawTarget = nullptr; - } } IntSize @@ -44,8 +41,7 @@ SourceSurfaceSkia::GetFormat() const bool SourceSurfaceSkia::InitFromCanvas(SkCanvas* aCanvas, - SurfaceFormat aFormat, - DrawTargetSkia* aOwner) + SurfaceFormat aFormat) { SkISize size = aCanvas->getDeviceSize(); @@ -55,7 +51,7 @@ SourceSurfaceSkia::InitFromCanvas(SkCanvas* aCanvas, mSize = IntSize(size.fWidth, size.fHeight); mStride = mBitmap.rowBytes(); - mDrawTarget = aOwner; + mBitmapDataOwned = true; return true; } @@ -115,7 +111,6 @@ SourceSurfaceSkia::InitFromTexture(DrawTargetSkia* aOwner, mBitmap.setPixelRef(texRef); #endif - mDrawTarget = aOwner; return true; } @@ -134,10 +129,9 @@ SourceSurfaceSkia::GetData() void SourceSurfaceSkia::DrawTargetWillChange() { - if (mDrawTarget) { + if (mBitmapDataOwned) { MaybeUnlock(); - mDrawTarget = nullptr; SkBitmap temp = mBitmap; mBitmap.reset(); temp.copyTo(&mBitmap, temp.colorType()); diff --git a/gfx/2d/SourceSurfaceSkia.h b/gfx/2d/SourceSurfaceSkia.h index d13d3873759..63b257d32a6 100644 --- a/gfx/2d/SourceSurfaceSkia.h +++ b/gfx/2d/SourceSurfaceSkia.h @@ -36,8 +36,7 @@ public: SurfaceFormat aFormat); bool InitFromCanvas(SkCanvas* aCanvas, - SurfaceFormat aFormat, - DrawTargetSkia* aOwner); + SurfaceFormat aFormat); /** * NOTE: While wrapping a Texture for SkiaGL, the texture *must* be created @@ -54,7 +53,6 @@ public: private: friend class DrawTargetSkia; - void DrawTargetWillChange(); void MaybeUnlock(); @@ -62,8 +60,8 @@ private: SurfaceFormat mFormat; IntSize mSize; int32_t mStride; - RefPtr mDrawTarget; bool mLocked; + bool mBitmapDataOwned; }; }