diff options
author | 2015-07-29 11:44:52 -0700 | |
---|---|---|
committer | 2015-07-29 11:44:52 -0700 | |
commit | 26e0e587f76f2a9338652c100f835c2377c908d3 (patch) | |
tree | 6abb5c61ad62b2a8e17985a662cbb05b1899dd73 /src/image/SkSurface.cpp | |
parent | 2481b8b71941914ed053400700299f20f7ff32fc (diff) |
SkImage_Raster's pixels are always immutable.
To make this work, we tag their pixelrefs as temporarily immutable, allowing
ourselves to restore the pixels to mutability only when the image drops away.
This should allow us to wobble back and forth between writing to the Surface
and reading from the Image without a COW, with the Surface seeing mutable
pixels and the Image seeing immutable pixels.
The big idea is, Image doesn't need forever-immutable pixels, it just needs
pixels that are immutable as long as it's alive.
BUG=skia:
patch from issue 804523002 at patchset 40001 (http://crrev.com/804523002#ps40001)
Review URL: https://codereview.chromium.org/1254383006
Diffstat (limited to 'src/image/SkSurface.cpp')
-rw-r--r-- | src/image/SkSurface.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index bfc019bd4f..8c356a8080 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -99,7 +99,8 @@ void SkSurface_Base::aboutToDraw(ContentChangeMode mode) { // the surface may need to fork its backend, if its sharing it with // the cached image. Note: we only call if there is an outstanding owner // on the image (besides us). - if (!fCachedImage->unique()) { + bool unique = fCachedImage->unique(); + if (!unique) { this->onCopyOnWrite(mode); } @@ -107,6 +108,13 @@ void SkSurface_Base::aboutToDraw(ContentChangeMode mode) { // that the next request will get our new contents. fCachedImage->unref(); fCachedImage = NULL; + + if (unique) { + // Our content isn't held by any image now, so we can consider that content mutable. + // Raster surfaces need to be told it's safe to consider its pixels mutable again. + // We make this call after the ->unref() so the subclass can assert there are no images. + this->onRestoreBackingMutability(); + } } else if (kDiscard_ContentChangeMode == mode) { this->onDiscard(); } |