Exposing the isImmutable/setImmutable API of SkPixelRef in SkBitmap
REVIEW=http://codereview.appspot.com/5491055/
git-svn-id: http://skia.googlecode.com/svn/trunk@2883 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index f280a24..57b80e5 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -158,6 +158,19 @@
*/
Sk64 getSafeSize64() const ;
+ /** Returns true if this bitmap is marked as immutable, meaning that the
+ contents of its pixels will not change for the lifetime of the bitmap.
+ */
+ bool isImmutable() const;
+
+ /** Marks this bitmap as immutable, meaning that the contents of its
+ pixels will not change for the lifetime of the bitmap and of the
+ underlying pixelref. This state can be set, but it cannot be
+ cleared once it is set. This state propagates to all other bitmaps
+ that share the same pixelref.
+ */
+ void setImmutable();
+
/** Returns true if the bitmap is opaque (has no translucent/transparent pixels).
*/
bool isOpaque() const;
@@ -589,8 +602,9 @@
mutable int fRawPixelGenerationID;
enum Flags {
- kImageIsOpaque_Flag = 0x01,
- kImageIsVolatile_Flag = 0x02
+ kImageIsOpaque_Flag = 0x01,
+ kImageIsVolatile_Flag = 0x02,
+ kImageIsImmutable_Flag = 0x04
};
uint32_t fRowBytes;
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 24a1839..2376dd3 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -409,6 +409,7 @@
}
void SkBitmap::notifyPixelsChanged() const {
+ SkASSERT(!this->isImmutable());
if (fPixelRef) {
fPixelRef->notifyPixelsChanged();
} else {
@@ -504,6 +505,19 @@
///////////////////////////////////////////////////////////////////////////////
+bool SkBitmap::isImmutable() const {
+ return fPixelRef ? fPixelRef->isImmutable() :
+ fFlags & kImageIsImmutable_Flag;
+}
+
+void SkBitmap::setImmutable() {
+ if (fPixelRef) {
+ fPixelRef->setImmutable();
+ } else {
+ fFlags |= kImageIsImmutable_Flag;
+ }
+}
+
bool SkBitmap::isOpaque() const {
switch (fConfig) {
case kNo_Config: