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

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: name 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
« no previous file with comments | « src/core/SkBigPicture.cpp ('k') | src/core/SkData.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const uint16_t* SkColorTable::read16BitCache() const {
51 struct Build16BitCache { 51 return f16BitCache.get([&]{
52 const SkPMColor* fColors;
53 int fCount;
54
55 uint16_t* operator()() const {
56 uint16_t* cache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t)); 52 uint16_t* cache = (uint16_t*)sk_malloc_throw(fCount * sizeof(uint16_t));
57 for (int i = 0; i < fCount; i++) { 53 for (int i = 0; i < fCount; i++) {
58 cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]); 54 cache[i] = SkPixel32ToPixel16_ToU16(fColors[i]);
59 } 55 }
60 return cache; 56 return cache;
61 } 57 });
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 } 58 }
71 59
72 /////////////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////////////
73 61
74 #if 0 62 #if 0
75 SkColorTable::SkColorTable(SkReadBuffer& buffer) { 63 SkColorTable::SkColorTable(SkReadBuffer& buffer) {
76 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) { 64 if (buffer.isVersionLT(SkReadBuffer::kRemoveColorTableAlpha_Version)) {
77 /*fAlphaType = */buffer.readUInt(); 65 /*fAlphaType = */buffer.readUInt();
78 } 66 }
79 67
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 103
116 const size_t allocSize = count * sizeof(SkPMColor); 104 const size_t allocSize = count * sizeof(SkPMColor);
117 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize)); 105 SkAutoTDelete<SkPMColor> colors((SkPMColor*)sk_malloc_throw(allocSize));
118 if (!buffer.readColorArray(colors, count)) { 106 if (!buffer.readColorArray(colors, count)) {
119 return nullptr; 107 return nullptr;
120 } 108 }
121 109
122 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc); 110 return new SkColorTable(colors.detach(), count, kAllocatedWithMalloc);
123 } 111 }
124 112
OLDNEW
« no previous file with comments | « src/core/SkBigPicture.cpp ('k') | src/core/SkData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698