OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2009 The Android Open Source Project | 3 * Copyright 2009 The Android Open Source Project |
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 #include "SkColorTable.h" | 10 #include "SkColorTable.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 SkASSERT(colors); | 40 SkASSERT(colors); |
41 } | 41 } |
42 | 42 |
43 SkColorTable::~SkColorTable() { | 43 SkColorTable::~SkColorTable() { |
44 sk_free(fColors); | 44 sk_free(fColors); |
45 // f16BitCache frees itself | 45 // f16BitCache frees itself |
46 } | 46 } |
47 | 47 |
48 #include "SkColorPriv.h" | 48 #include "SkColorPriv.h" |
49 | 49 |
50 const uint16_t* SkColorTable::read16BitCache() const { | 50 namespace { |
51 return f16BitCache.get([&]{ | 51 struct Build16BitCache { |
| 52 const SkPMColor* fColors; |
| 53 int fCount; |
| 54 |
| 55 uint16_t* operator()() const { |
52 uint16_t* cache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t)); | 56 uint16_t* cache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t)); |
53 for (int i = 0; i < fCount; i++) { | 57 for (int i = 0; i < fCount; i++) { |
54 cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]); | 58 cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]); |
55 } | 59 } |
56 return cache; | 60 return cache; |
57 }); | 61 } |
| 62 }; |
| 63 }//namespace |
| 64 |
| 65 void SkColorTable::Free16BitCache(uint16_t* cache) { sk_free(cache); } |
| 66 |
| 67 const uint16_t* SkColorTable::read16BitCache() const { |
| 68 const Build16BitCache create = { fColors, fCount }; |
| 69 return f16BitCache.get(create); |
58 } | 70 } |
59 | 71 |
60 /////////////////////////////////////////////////////////////////////////////// | 72 /////////////////////////////////////////////////////////////////////////////// |
61 | 73 |
62 #if 0 | 74 #if 0 |
63 SkColorTable::SkColorTable(SkReadBuffer& buffer) { | 75 SkColorTable::SkColorTable(SkReadBuffer& buffer) { |
64 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { | 76 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { |
65 /*fAlphaType = */buffer.readUInt(); | 77 /*fAlphaType = */buffer.readUInt(); |
66 } | 78 } |
67 | 79 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 115 |
104 const size_t allocSize = count * sizeof(SkPMColor); | 116 const size_t allocSize = count * sizeof(SkPMColor); |
105 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); | 117 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); |
106 if (!buffer.readColorArray(colors, count)) { | 118 if (!buffer.readColorArray(colors, count)) { |
107 return nullptr; | 119 return nullptr; |
108 } | 120 } |
109 | 121 |
110 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc); | 122 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc); |
111 } | 123 } |
112 | 124 |
OLD | NEW |