From 0e8d0d6cdc2e02946b099006d0a47e60764905e5 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Mon, 27 Jan 2014 15:41:07 +0000 Subject: [PATCH] add optional SkAlphaType parameter to notifyPixelsChanged R=scroggo@google.com, halcanary@google.com, robertphillips@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/147213002 git-svn-id: http://skia.googlecode.com/svn/trunk@13192 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkBitmap.h | 7 +++++++ include/core/SkPixelRef.h | 21 ++++++++++++++------- src/core/SkBitmap.cpp | 7 ++++++- src/core/SkPixelRef.cpp | 3 ++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 4dcf327..1dd2c80 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -128,6 +128,13 @@ public: * Set the bitmap's alphaType, returning true on success. If false is * returned, then the specified new alphaType is incompatible with the * Config, and the current alphaType is unchanged. + * + * Note: this changes the alphatype for the underlying pixels, which means + * that all bitmaps that might be sharing (subsets of) the pixels will + * be affected. This is an expensive change for some backends (e.g. GPU) + * since changing the alphatype can invalidate internal caches. Thus this + * call should only be made if it is associated with real changes to the + * pixel data. */ bool setAlphaType(SkAlphaType); diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index e65f4a0..62edc3e 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -1,4 +1,3 @@ - /* * Copyright 2008 The Android Open Source Project * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef SkPixelRef_DEFINED #define SkPixelRef_DEFINED @@ -128,11 +126,19 @@ public: */ uint32_t getGenerationID() const; - /** Call this if you have changed the contents of the pixels. This will in- - turn cause a different generation ID value to be returned from - getGenerationID(). - */ - void notifyPixelsChanged(); + /** + * Call this if you have changed the contents of the pixels. This will in- + * turn cause a different generation ID value to be returned from + * getGenerationID(). + * + * If the alphatype has also changed, specify its new value as well. If + * the new pixels' alphatype is the same, this can be called with no + * parameter. + */ + void notifyPixelsChanged(SkAlphaType); + void notifyPixelsChanged() { + this->notifyPixelsChanged(fInfo.fAlphaType); + } /** Returns true if this pixelref is marked as immutable, meaning that the contents of its pixels will not change for the lifetime of the pixelref. @@ -333,6 +339,7 @@ protected: private: SkBaseMutex* fMutex; // must remain in scope for the life of this object + // mostly const. fInfo.fAlpahType can be changed at runtime. const SkImageInfo fInfo; // LockRec is only valid if we're in a locked state (isLocked()) diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 7074386..825b1dc 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -321,7 +321,12 @@ bool SkBitmap::setAlphaType(SkAlphaType alphaType) { if (!validate_alphaType(this->config(), alphaType, &alphaType)) { return false; } - fAlphaType = SkToU8(alphaType); + if (fAlphaType != alphaType) { + fAlphaType = SkToU8(alphaType); + if (fPixelRef) { + fPixelRef->notifyPixelsChanged(alphaType); + } + } return true; } diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp index 10e1309..507a4fc 100644 --- a/src/core/SkPixelRef.cpp +++ b/src/core/SkPixelRef.cpp @@ -254,12 +254,13 @@ void SkPixelRef::callGenIDChangeListeners() { fGenIDChangeListeners.deleteAll(); } -void SkPixelRef::notifyPixelsChanged() { +void SkPixelRef::notifyPixelsChanged(SkAlphaType at) { #ifdef SK_DEBUG if (fIsImmutable) { SkDebugf("========== notifyPixelsChanged called on immutable pixelref"); } #endif + *const_cast(&fInfo.fAlphaType) = at; this->callGenIDChangeListeners(); this->needsNewGenID(); } -- 2.7.4