| OLD | NEW |
| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 public: | 23 public: |
| 24 SK_DECLARE_INST_COUNT(SkColorTable) | 24 SK_DECLARE_INST_COUNT(SkColorTable) |
| 25 | 25 |
| 26 /** Makes a deep copy of colors. | 26 /** Makes a deep copy of colors. |
| 27 */ | 27 */ |
| 28 SkColorTable(const SkColorTable& src); | 28 SkColorTable(const SkColorTable& src); |
| 29 SkColorTable(const SkPMColor colors[], int count); | 29 SkColorTable(const SkPMColor colors[], int count); |
| 30 virtual ~SkColorTable(); | 30 virtual ~SkColorTable(); |
| 31 | 31 |
| 32 /** Returns the number of colors in the table. | 32 /** Returns the number of colors in the table. |
| 33 */ | 33 */ |
| 34 int count() const { return fCount; } | 34 int count() const { return fCount; } |
| 35 | 35 |
| 36 /** Returns the specified color from the table. In the debug build, this ass
erts that | 36 /** Returns the specified color from the table. In the debug build, this ass
erts that |
| 37 the index is in range (0 <= index < count). | 37 * the index is in range (0 <= index < count). |
| 38 */ | 38 */ |
| 39 SkPMColor operator[](int index) const { | 39 SkPMColor operator[](int index) const { |
| 40 SkASSERT(fColors != NULL && (unsigned)index < (unsigned)fCount); | 40 SkASSERT(fColors != NULL && (unsigned)index < (unsigned)fCount); |
| 41 return fColors[index]; | 41 return fColors[index]; |
| 42 } | 42 } |
| 43 | 43 |
| 44 /** | 44 // TODO: Would making the read() methods const allow us to avoid copies? |
| 45 * Return the array of colors for reading. This must be balanced by a call | 45 |
| 46 * to unlockColors(). | 46 /** Return the array of colors for reading. |
| 47 */ | 47 */ |
| 48 const SkPMColor* lockColors() { | 48 const SkPMColor* readColors() { return fColors; } |
| 49 SkDEBUGCODE(sk_atomic_inc(&fColorLockCount);) | |
| 50 return fColors; | |
| 51 } | |
| 52 | 49 |
| 53 /** | 50 /** read16BitCache() returns the array of RGB16 colors that mirror the 32bit
colors. |
| 54 * Balancing call to lockColors(). | |
| 55 */ | 51 */ |
| 56 void unlockColors(); | 52 const uint16_t* read16BitCache(); |
| 57 | |
| 58 /** Similar to lockColors(), lock16BitCache() returns the array of | |
| 59 RGB16 colors that mirror the 32bit colors. However, this function | |
| 60 will return null if kColorsAreOpaque_Flag is not set. | |
| 61 Also, unlike lockColors(), the returned array here cannot be modified. | |
| 62 */ | |
| 63 const uint16_t* lock16BitCache(); | |
| 64 /** Balancing call to lock16BitCache(). | |
| 65 */ | |
| 66 void unlock16BitCache() { | |
| 67 SkASSERT(f16BitCacheLockCount > 0); | |
| 68 SkDEBUGCODE(sk_atomic_dec(&f16BitCacheLockCount);) | |
| 69 } | |
| 70 | 53 |
| 71 explicit SkColorTable(SkReadBuffer&); | 54 explicit SkColorTable(SkReadBuffer&); |
| 72 void writeToBuffer(SkWriteBuffer&) const; | 55 void writeToBuffer(SkWriteBuffer&) const; |
| 73 | 56 |
| 74 private: | 57 private: |
| 75 SkPMColor* fColors; | 58 SkPMColor* fColors; |
| 76 uint16_t* f16BitCache; | 59 uint16_t* f16BitCache; |
| 77 int fCount; | 60 int fCount; |
| 78 SkDEBUGCODE(int fColorLockCount;) | |
| 79 SkDEBUGCODE(int f16BitCacheLockCount;) | |
| 80 | 61 |
| 81 void init(const SkPMColor* colors, int count); | 62 void init(const SkPMColor* colors, int count); |
| 82 | 63 |
| 83 void inval16BitCache(); | |
| 84 | |
| 85 typedef SkRefCnt INHERITED; | 64 typedef SkRefCnt INHERITED; |
| 86 }; | 65 }; |
| 87 | 66 |
| 88 #endif | 67 #endif |
| OLD | NEW |