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
This commit is contained in:
junov@chromium.org 2011-12-15 20:14:06 +00:00
parent c315aeb480
commit b052129a41
2 changed files with 30 additions and 2 deletions

View File

@ -158,6 +158,19 @@ public:
*/
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 @@ private:
mutable int fRawPixelGenerationID;
enum Flags {
kImageIsOpaque_Flag = 0x01,
kImageIsVolatile_Flag = 0x02
kImageIsOpaque_Flag = 0x01,
kImageIsVolatile_Flag = 0x02,
kImageIsImmutable_Flag = 0x04
};
uint32_t fRowBytes;

View File

@ -409,6 +409,7 @@ uint32_t SkBitmap::getGenerationID() const {
}
void SkBitmap::notifyPixelsChanged() const {
SkASSERT(!this->isImmutable());
if (fPixelRef) {
fPixelRef->notifyPixelsChanged();
} else {
@ -504,6 +505,19 @@ bool SkBitmap::copyPixelsTo(void* const dst, size_t dstSize,
///////////////////////////////////////////////////////////////////////////////
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: