From 48d9ff5b3475ad4b345fae35e1ce36b34069691b Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 9 Oct 2013 16:49:45 +0000 Subject: Revert "change SkColorTable to be immutable" This reverts commit 1c0ff422868b3badf5ffe0790a5d051d1896e2f7. BUG= Review URL: https://codereview.chromium.org/26709002 git-svn-id: http://skia.googlecode.com/svn/trunk@11677 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkAlpha.h | 3 --- include/core/SkBitmap.h | 4 ++-- include/core/SkColorTable.h | 51 +++++++++++++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 23 deletions(-) (limited to 'include/core') diff --git a/include/core/SkAlpha.h b/include/core/SkAlpha.h index 74ea687f96..9e0fcab0e2 100644 --- a/include/core/SkAlpha.h +++ b/include/core/SkAlpha.h @@ -47,7 +47,4 @@ enum SkAlphaType { kLastEnum_SkAlphaType = kUnpremul_SkAlphaType }; -static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) { - return (unsigned)at <= kOpaque_SkAlphaType; -} #endif diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h index 07d2b95553..887169ccb5 100644 --- a/include/core/SkBitmap.h +++ b/include/core/SkBitmap.h @@ -748,7 +748,7 @@ public: } ~SkAutoLockColors() { if (fCTable) { - fCTable->unlockColors(); + fCTable->unlockColors(false); } } @@ -762,7 +762,7 @@ public: */ const SkPMColor* lockColors(SkColorTable* ctable) { if (fCTable) { - fCTable->unlockColors(); + fCTable->unlockColors(false); } fCTable = ctable; fColors = ctable ? ctable->lockColors() : NULL; diff --git a/include/core/SkColorTable.h b/include/core/SkColorTable.h index c6e31b94d4..f8d1ccf07b 100644 --- a/include/core/SkColorTable.h +++ b/include/core/SkColorTable.h @@ -10,7 +10,6 @@ #ifndef SkColorTable_DEFINED #define SkColorTable_DEFINED -#include "SkAlpha.h" #include "SkColor.h" #include "SkFlattenable.h" @@ -26,15 +25,25 @@ public: /** Makes a deep copy of colors. */ SkColorTable(const SkColorTable& src); - SkColorTable(const SkPMColor colors[], int count, - SkAlphaType alphaType = kPremul_SkAlphaType); + /** Preallocates the colortable to have 'count' colors, which + * are initially set to 0. + */ + explicit SkColorTable(int count); + SkColorTable(const SkPMColor colors[], int count); virtual ~SkColorTable(); - SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; } + enum Flags { + kColorsAreOpaque_Flag = 0x01 //!< if set, all of the colors in the table are opaque (alpha==0xFF) + }; + /** Returns the flag bits for the color table. These can be changed with setFlags(). + */ + unsigned getFlags() const { return fFlags; } + /** Set the flags for the color table. See the Flags enum for possible values. + */ + void setFlags(unsigned flags); - bool isOpaque() const { - return SkAlphaTypeIsOpaque(this->alphaType()); - } + bool isOpaque() const { return (fFlags & kColorsAreOpaque_Flag) != 0; } + void setIsOpaque(bool isOpaque); /** Returns the number of colors in the table. */ @@ -48,19 +57,25 @@ public: return fColors[index]; } - /** - * Return the array of colors for reading. This must be balanced by a call - * to unlockColors(). - */ - const SkPMColor* lockColors() { + /** Specify the number of colors in the color table. This does not initialize the colors + to any value, just allocates memory for them. To initialize the values, either call + setColors(array, count), or follow setCount(count) with a call to + lockColors()/{set the values}/unlockColors(true). + */ +// void setColors(int count) { this->setColors(NULL, count); } +// void setColors(const SkPMColor[], int count); + + /** Return the array of colors for reading and/or writing. This must be + balanced by a call to unlockColors(changed?), telling the colortable if + the colors were changed during the lock. + */ + SkPMColor* lockColors() { SkDEBUGCODE(sk_atomic_inc(&fColorLockCount);) return fColors; } - - /** - * Balancing call to lockColors(). - */ - void unlockColors(); + /** Balancing call to lockColors(). If the colors have been changed, pass true. + */ + void unlockColors(bool changed); /** Similar to lockColors(), lock16BitCache() returns the array of RGB16 colors that mirror the 32bit colors. However, this function @@ -85,7 +100,7 @@ private: SkPMColor* fColors; uint16_t* f16BitCache; uint16_t fCount; - uint8_t fAlphaType; + uint8_t fFlags; SkDEBUGCODE(int fColorLockCount;) SkDEBUGCODE(int f16BitCacheLockCount;) -- cgit v1.2.3