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 "../private/SkOncePtr.h" | 13 #include "../private/SkOnce.h" |
14 #include "SkColor.h" | 14 #include "SkColor.h" |
15 #include "SkFlattenable.h" | 15 #include "SkFlattenable.h" |
16 #include "SkImageInfo.h" | 16 #include "SkImageInfo.h" |
17 | 17 |
18 /** \class SkColorTable | 18 /** \class SkColorTable |
19 | 19 |
20 SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by | 20 SkColorTable holds an array SkPMColors (premultiplied 32-bit colors) used by |
21 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 | 22 |
23 SkColorTable is thread-safe. | 23 SkColorTable is thread-safe. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 static SkColorTable* Create(SkReadBuffer&); | 55 static SkColorTable* Create(SkReadBuffer&); |
56 | 56 |
57 private: | 57 private: |
58 enum AllocatedWithMalloc { | 58 enum AllocatedWithMalloc { |
59 kAllocatedWithMalloc | 59 kAllocatedWithMalloc |
60 }; | 60 }; |
61 // assumes ownership of colors (assumes it was allocated w/ malloc) | 61 // assumes ownership of colors (assumes it was allocated w/ malloc) |
62 SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc); | 62 SkColorTable(SkPMColor* colors, int count, AllocatedWithMalloc); |
63 | 63 |
64 SkPMColor* fColors; | 64 SkPMColor* fColors; |
65 SkOncePtr<uint16_t[]> f16BitCache; | 65 mutable uint16_t* f16BitCache = nullptr; |
| 66 mutable SkOnce f16BitCacheOnce; |
66 int fCount; | 67 int fCount; |
67 | 68 |
68 void init(const SkPMColor* colors, int count); | 69 void init(const SkPMColor* colors, int count); |
69 | 70 |
70 friend class SkImageGenerator; | 71 friend class SkImageGenerator; |
71 // Only call if no other thread or cache has seen this table. | 72 // Only call if no other thread or cache has seen this table. |
72 void dangerous_overwriteColors(const SkPMColor newColors[], int count) { | 73 void dangerous_overwriteColors(const SkPMColor newColors[], int count) { |
73 if (count < 0 || count > fCount) { | 74 if (count < 0 || count > fCount) { |
74 sk_throw(); | 75 sk_throw(); |
75 } | 76 } |
76 // assumes that f16BitCache nas NOT been initialized yet, so we don't tr
y to update it | 77 // assumes that f16BitCache nas NOT been initialized yet, so we don't tr
y to update it |
77 memcpy(fColors, newColors, count * sizeof(SkPMColor)); | 78 memcpy(fColors, newColors, count * sizeof(SkPMColor)); |
78 fCount = count; // update fCount, in case count is smaller | 79 fCount = count; // update fCount, in case count is smaller |
79 } | 80 } |
80 | 81 |
81 typedef SkRefCnt INHERITED; | 82 typedef SkRefCnt INHERITED; |
82 }; | 83 }; |
83 | 84 |
84 #endif | 85 #endif |
OLD | NEW |