OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDiscardablePixelRef.h" | 8 #include "SkDiscardablePixelRef.h" |
9 #include "SkDiscardableMemory.h" | 9 #include "SkDiscardableMemory.h" |
10 #include "SkImageGenerator.h" | 10 #include "SkImageGenerator.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 SkPMColor colors[256]; | 64 SkPMColor colors[256]; |
65 int colorCount = 0; | 65 int colorCount = 0; |
66 | 66 |
67 if (!fGenerator->getPixels(info, pixels, fRowBytes, colors, &colorCount)) { | 67 if (!fGenerator->getPixels(info, pixels, fRowBytes, colors, &colorCount)) { |
68 fDiscardableMemory->unlock(); | 68 fDiscardableMemory->unlock(); |
69 SkDELETE(fDiscardableMemory); | 69 SkDELETE(fDiscardableMemory); |
70 fDiscardableMemory = NULL; | 70 fDiscardableMemory = NULL; |
71 return false; | 71 return false; |
72 } | 72 } |
73 | 73 |
74 // Note: our ctable is not purgable, as it is not stored in the discardablem
emory block. | 74 // Note: our ctable is not purgeable, as it is not stored in the discardable
memory block. |
75 // This is because SkColorTable is refcntable, and therefore our caller coul
d hold onto it | 75 // This is because SkColorTable is refcntable, and therefore our caller coul
d hold onto it |
76 // beyond the scope of a lock/unlock. If we change the API/lifecycle for SkC
olorTable, we | 76 // beyond the scope of a lock/unlock. If we change the API/lifecycle for SkC
olorTable, we |
77 // could move it into the block, but then again perhaps it is small enough t
hat this doesn't | 77 // could move it into the block, but then again perhaps it is small enough t
hat this doesn't |
78 // really matter. | 78 // really matter. |
79 if (colorCount > 0) { | 79 if (colorCount > 0) { |
80 fCTable.reset(SkNEW_ARGS(SkColorTable, (colors, colorCount))); | 80 fCTable.reset(SkNEW_ARGS(SkColorTable, (colors, colorCount))); |
81 } else { | 81 } else { |
82 fCTable.reset(NULL); | 82 fCTable.reset(NULL); |
83 } | 83 } |
84 | 84 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // These are the public API | 119 // These are the public API |
120 | 120 |
121 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { | 121 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { |
122 return SkInstallDiscardablePixelRef(generator, dst, NULL); | 122 return SkInstallDiscardablePixelRef(generator, dst, NULL); |
123 } | 123 } |
124 | 124 |
125 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { | 125 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { |
126 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded); | 126 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded); |
127 return generator ? SkInstallDiscardablePixelRef(generator, dst, NULL) : fals
e; | 127 return generator ? SkInstallDiscardablePixelRef(generator, dst, NULL) : fals
e; |
128 } | 128 } |
OLD | NEW |