Chromium Code Reviews| 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 |
| 11 #define SkColorTable_DEFINED | 11 #define SkColorTable_DEFINED |
| 12 | 12 |
| 13 #include "SkColor.h" | 13 #include "SkColor.h" |
| 14 #include "SkFlattenable.h" | 14 #include "SkFlattenable.h" |
| 15 #include "SkImageInfo.h" | 15 #include "SkImageInfo.h" |
| 16 #include "SkLazyPtr.h" | |
| 16 | 17 |
| 17 /** \class SkColorTable | 18 /** \class SkColorTable |
| 18 | 19 |
| 19 SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by | 20 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. | 21 8-bit bitmaps, where the bitmap bytes are interpreted as indices into the co lortable. |
| 22 | |
| 23 SkColorTable is thread-safe. | |
| 21 */ | 24 */ |
| 22 class SK_API SkColorTable : public SkRefCnt { | 25 class SK_API SkColorTable : public SkRefCnt { |
| 23 public: | 26 public: |
| 24 SK_DECLARE_INST_COUNT(SkColorTable) | 27 SK_DECLARE_INST_COUNT(SkColorTable) |
| 25 | 28 |
| 26 /** Makes a deep copy of colors. | |
| 27 */ | |
| 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 // TODO: Would making the read() methods const allow us to avoid copies? | |
| 45 | |
| 46 /** Return the array of colors for reading. | 44 /** Return the array of colors for reading. |
| 47 */ | 45 */ |
| 48 const SkPMColor* readColors() { return fColors; } | 46 const SkPMColor* readColors() const { return fColors; } |
| 49 | 47 |
| 50 /** read16BitCache() returns the array of RGB16 colors that mirror the 32bit colors. | 48 /** read16BitCache() returns the array of RGB16 colors that mirror the 32bit colors. |
| 51 */ | 49 */ |
| 52 const uint16_t* read16BitCache(); | 50 const uint16_t* read16BitCache() const; |
| 53 | 51 |
| 54 explicit SkColorTable(SkReadBuffer&); | 52 explicit SkColorTable(SkReadBuffer&); |
| 55 void writeToBuffer(SkWriteBuffer&) const; | 53 void writeToBuffer(SkWriteBuffer&) const; |
| 56 | 54 |
| 57 private: | 55 private: |
| 58 SkPMColor* fColors; | 56 static void Free16BitCache(uint16_t* cache) { sk_free(cache); } |
| 59 uint16_t* f16BitCache; | 57 |
| 60 int fCount; | 58 SkPMColor* fColors; |
| 59 SkLazyPtr<uint16_t, Free16BitCache> f16BitCache; | |
| 60 int fCount; | |
|
reed1
2014/12/02 17:46:31
can we make fColors and fCount const?
mtklein
2014/12/02 17:51:18
Maybe, but it'll be an awkward enough rewrite of S
| |
| 61 | 61 |
| 62 void init(const SkPMColor* colors, int count); | 62 void init(const SkPMColor* colors, int count); |
| 63 | 63 |
| 64 typedef SkRefCnt INHERITED; | 64 typedef SkRefCnt INHERITED; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 #endif | 67 #endif |
| OLD | NEW |