diff options
author | reed <reed@google.com> | 2015-07-29 11:44:52 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-29 11:44:52 -0700 |
commit | 26e0e587f76f2a9338652c100f835c2377c908d3 (patch) | |
tree | 6abb5c61ad62b2a8e17985a662cbb05b1899dd73 /src/core | |
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/core')
-rw-r--r-- | src/core/SkPixelRef.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index 6d36915d9a..56bcc9a792 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -106,7 +106,7 @@ SkPixelRef::SkPixelRef(const SkImageInfo& info) fRec.zero(); fLockCount = 0; this->needsNewGenID(); - fIsImmutable = false; + fMutability = kMutable; fPreLocked = false; fAddedToCache.store(false); } @@ -125,7 +125,7 @@ SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) fRec.zero(); fLockCount = 0; this->needsNewGenID(); - fIsImmutable = false; + fMutability = kMutable; fPreLocked = false; fAddedToCache.store(false); } @@ -341,7 +341,7 @@ void SkPixelRef::callGenIDChangeListeners() { void SkPixelRef::notifyPixelsChanged() { #ifdef SK_DEBUG - if (fIsImmutable) { + if (this->isImmutable()) { SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); } #endif @@ -355,7 +355,17 @@ void SkPixelRef::changeAlphaType(SkAlphaType at) { } void SkPixelRef::setImmutable() { - fIsImmutable = true; + fMutability = kImmutable; +} +void SkPixelRef::setTemporarilyImmutable() { + SkASSERT(fMutability != kImmutable); + fMutability = kTemporarilyImmutable; +} + +void SkPixelRef::restoreMutability() { + SkASSERT(fMutability != kImmutable); + fMutability = kMutable; + this->notifyPixelsChanged(); // This is just precautionary. } bool SkPixelRef::readPixels(SkBitmap* dst, const SkIRect* subset) { |