Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: include/core/SkColorTable.h

Issue 26709002: Revert "change SkColorTable to be immutable" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkBitmap.h ('k') | samplecode/SampleBlur.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkColorTable_DEFINED 10 #ifndef SkColorTable_DEFINED
11 #define SkColorTable_DEFINED 11 #define SkColorTable_DEFINED
12 12
13 #include "SkAlpha.h"
14 #include "SkColor.h" 13 #include "SkColor.h"
15 #include "SkFlattenable.h" 14 #include "SkFlattenable.h"
16 15
17 /** \class SkColorTable 16 /** \class SkColorTable
18 17
19 SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by 18 SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by
20 8-bit bitmaps, where the bitmap bytes are interpreted as indices into the co lortable. 19 8-bit bitmaps, where the bitmap bytes are interpreted as indices into the co lortable.
21 */ 20 */
22 class SkColorTable : public SkFlattenable { 21 class SkColorTable : public SkFlattenable {
23 public: 22 public:
24 SK_DECLARE_INST_COUNT(SkColorTable) 23 SK_DECLARE_INST_COUNT(SkColorTable)
25 24
26 /** Makes a deep copy of colors. 25 /** Makes a deep copy of colors.
27 */ 26 */
28 SkColorTable(const SkColorTable& src); 27 SkColorTable(const SkColorTable& src);
29 SkColorTable(const SkPMColor colors[], int count, 28 /** Preallocates the colortable to have 'count' colors, which
30 SkAlphaType alphaType = kPremul_SkAlphaType); 29 * are initially set to 0.
30 */
31 explicit SkColorTable(int count);
32 SkColorTable(const SkPMColor colors[], int count);
31 virtual ~SkColorTable(); 33 virtual ~SkColorTable();
32 34
33 SkAlphaType alphaType() const { return (SkAlphaType)fAlphaType; } 35 enum Flags {
36 kColorsAreOpaque_Flag = 0x01 //!< if set, all of the colors in the ta ble are opaque (alpha==0xFF)
37 };
38 /** Returns the flag bits for the color table. These can be changed with set Flags().
39 */
40 unsigned getFlags() const { return fFlags; }
41 /** Set the flags for the color table. See the Flags enum for possible value s.
42 */
43 void setFlags(unsigned flags);
34 44
35 bool isOpaque() const { 45 bool isOpaque() const { return (fFlags & kColorsAreOpaque_Flag) != 0; }
36 return SkAlphaTypeIsOpaque(this->alphaType()); 46 void setIsOpaque(bool isOpaque);
37 }
38 47
39 /** Returns the number of colors in the table. 48 /** Returns the number of colors in the table.
40 */ 49 */
41 int count() const { return fCount; } 50 int count() const { return fCount; }
42 51
43 /** Returns the specified color from the table. In the debug build, this ass erts that 52 /** Returns the specified color from the table. In the debug build, this ass erts that
44 the index is in range (0 <= index < count). 53 the index is in range (0 <= index < count).
45 */ 54 */
46 SkPMColor operator[](int index) const { 55 SkPMColor operator[](int index) const {
47 SkASSERT(fColors != NULL && (unsigned)index < fCount); 56 SkASSERT(fColors != NULL && (unsigned)index < fCount);
48 return fColors[index]; 57 return fColors[index];
49 } 58 }
50 59
51 /** 60 /** Specify the number of colors in the color table. This does not initializ e the colors
52 * Return the array of colors for reading. This must be balanced by a call 61 to any value, just allocates memory for them. To initialize the values, either call
53 * to unlockColors(). 62 setColors(array, count), or follow setCount(count) with a call to
54 */ 63 lockColors()/{set the values}/unlockColors(true).
55 const SkPMColor* lockColors() { 64 */
65 // void setColors(int count) { this->setColors(NULL, count); }
66 // void setColors(const SkPMColor[], int count);
67
68 /** Return the array of colors for reading and/or writing. This must be
69 balanced by a call to unlockColors(changed?), telling the colortable if
70 the colors were changed during the lock.
71 */
72 SkPMColor* lockColors() {
56 SkDEBUGCODE(sk_atomic_inc(&fColorLockCount);) 73 SkDEBUGCODE(sk_atomic_inc(&fColorLockCount);)
57 return fColors; 74 return fColors;
58 } 75 }
59 76 /** Balancing call to lockColors(). If the colors have been changed, pass tr ue.
60 /** 77 */
61 * Balancing call to lockColors(). 78 void unlockColors(bool changed);
62 */
63 void unlockColors();
64 79
65 /** Similar to lockColors(), lock16BitCache() returns the array of 80 /** Similar to lockColors(), lock16BitCache() returns the array of
66 RGB16 colors that mirror the 32bit colors. However, this function 81 RGB16 colors that mirror the 32bit colors. However, this function
67 will return null if kColorsAreOpaque_Flag is not set. 82 will return null if kColorsAreOpaque_Flag is not set.
68 Also, unlike lockColors(), the returned array here cannot be modified. 83 Also, unlike lockColors(), the returned array here cannot be modified.
69 */ 84 */
70 const uint16_t* lock16BitCache(); 85 const uint16_t* lock16BitCache();
71 /** Balancing call to lock16BitCache(). 86 /** Balancing call to lock16BitCache().
72 */ 87 */
73 void unlock16BitCache() { 88 void unlock16BitCache() {
74 SkASSERT(f16BitCacheLockCount > 0); 89 SkASSERT(f16BitCacheLockCount > 0);
75 SkDEBUGCODE(f16BitCacheLockCount -= 1); 90 SkDEBUGCODE(f16BitCacheLockCount -= 1);
76 } 91 }
77 92
78 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorTable) 93 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorTable)
79 94
80 protected: 95 protected:
81 explicit SkColorTable(SkFlattenableReadBuffer&); 96 explicit SkColorTable(SkFlattenableReadBuffer&);
82 void flatten(SkFlattenableWriteBuffer&) const; 97 void flatten(SkFlattenableWriteBuffer&) const;
83 98
84 private: 99 private:
85 SkPMColor* fColors; 100 SkPMColor* fColors;
86 uint16_t* f16BitCache; 101 uint16_t* f16BitCache;
87 uint16_t fCount; 102 uint16_t fCount;
88 uint8_t fAlphaType; 103 uint8_t fFlags;
89 SkDEBUGCODE(int fColorLockCount;) 104 SkDEBUGCODE(int fColorLockCount;)
90 SkDEBUGCODE(int f16BitCacheLockCount;) 105 SkDEBUGCODE(int f16BitCacheLockCount;)
91 106
92 void inval16BitCache(); 107 void inval16BitCache();
93 108
94 typedef SkFlattenable INHERITED; 109 typedef SkFlattenable INHERITED;
95 }; 110 };
96 111
97 #endif 112 #endif
OLDNEW
« no previous file with comments | « include/core/SkBitmap.h ('k') | samplecode/SampleBlur.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698