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

Side by Side Diff: src/core/SkColorTable.cpp

Issue 1322933005: Port uses of SkLazyPtr to SkOncePtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: the rest Created 5 years, 3 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
OLDNEW
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
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 namespace { 50 void SkColorTable::Free16BitCache::operator()(uint16_t* cache) const { sk_free(c ache); }
51 struct Build16BitCache {
52 const SkPMColor* fColors;
53 int fCount;
54 51
55 uint16_t* operator()() const { 52 const uint16_t* SkColorTable::read16BitCache() const {
53 return f16BitCache.get([&]{
56 uint16_t* cache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t)); 54 uint16_t* cache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
57 for (int i = 0; i < fCount; i++) { 55 for (int i = 0; i < fCount; i++) {
58 cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]); 56 cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]);
59 } 57 }
60 return cache; 58 return cache;
61 } 59 });
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);
70 } 60 }
71 61
72 /////////////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////////////
73 63
74 #if 0 64 #if 0
75 SkColorTable::SkColorTable(SkReadBuffer& buffer) { 65 SkColorTable::SkColorTable(SkReadBuffer& buffer) {
76 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { 66 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) {
77 /*fAlphaType = */buffer.readUInt(); 67 /*fAlphaType = */buffer.readUInt();
78 } 68 }
79 69
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 105
116 const size_t allocSize = count * sizeof(SkPMColor); 106 const size_t allocSize = count * sizeof(SkPMColor);
117 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); 107 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize));
118 if (!buffer.readColorArray(colors, count)) { 108 if (!buffer.readColorArray(colors, count)) {
119 return nullptr; 109 return nullptr;
120 } 110 }
121 111
122 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc); 112 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc);
123 } 113 }
124 114
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698