diff options
author | bsalomon <bsalomon@google.com> | 2016-02-22 11:02:58 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-22 11:02:58 -0800 |
commit | f47b9a3b88a037a481eb70f01a4cf9f5be34dc28 (patch) | |
tree | 99856c248a165000a16d96722170198bc248c745 /src/image/SkSurface_Raster.cpp | |
parent | 8d9f2e474ac9d175c28079357b022d31408e2fe4 (diff) |
Allow client to force an SkImage snapshot to be unique (and uniquely own its backing store).
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1686163002
Review URL: https://codereview.chromium.org/1686163002
Diffstat (limited to 'src/image/SkSurface_Raster.cpp')
-rw-r--r-- | src/image/SkSurface_Raster.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp index d9763c0c95..37790a0dd9 100644 --- a/src/image/SkSurface_Raster.cpp +++ b/src/image/SkSurface_Raster.cpp @@ -24,7 +24,7 @@ public: SkCanvas* onNewCanvas() override; SkSurface* onNewSurface(const SkImageInfo&) override; - SkImage* onNewImageSnapshot(Budgeted) override; + SkImage* onNewImageSnapshot(Budgeted, ForceCopyMode) override; void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override; void onCopyOnWrite(ContentChangeMode) override; void onRestoreBackingMutability() override; @@ -118,18 +118,20 @@ void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, canvas->drawBitmap(fBitmap, x, y, paint); } -SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted) { +SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted, ForceCopyMode forceCopyMode) { if (fWeOwnThePixels) { // SkImage_raster requires these pixels are immutable for its full lifetime. // We'll undo this via onRestoreBackingMutability() if we can avoid the COW. if (SkPixelRef* pr = fBitmap.pixelRef()) { pr->setTemporarilyImmutable(); } + } else { + forceCopyMode = kYes_ForceCopyMode; } + // Our pixels are in memory, so read access on the snapshot SkImage could be cheap. // Lock the shared pixel ref to ensure peekPixels() is usable. - return SkNewImageFromRasterBitmap(fBitmap, - fWeOwnThePixels ? kNo_ForceCopyMode : kYes_ForceCopyMode); + return SkNewImageFromRasterBitmap(fBitmap, forceCopyMode); } void SkSurface_Raster::onRestoreBackingMutability() { @@ -141,8 +143,9 @@ void SkSurface_Raster::onRestoreBackingMutability() { void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { // are we sharing pixelrefs with the image? - SkASSERT(this->getCachedImage(kNo_Budgeted)); - if (SkBitmapImageGetPixelRef(this->getCachedImage(kNo_Budgeted)) == fBitmap.pixelRef()) { + SkAutoTUnref<SkImage> cached(this->refCachedImage(kNo_Budgeted, kNo_ForceUnique)); + SkASSERT(cached); + if (SkBitmapImageGetPixelRef(cached) == fBitmap.pixelRef()) { SkASSERT(fWeOwnThePixels); if (kDiscard_ContentChangeMode == mode) { fBitmap.allocPixels(); |