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 if (NULL == fDiscardableMemory) { | 64 if (NULL == fDiscardableMemory) { |
65 fDiscardableMemoryIsLocked = false; | 65 fDiscardableMemoryIsLocked = false; |
66 return false; // Memory allocation failed. | 66 return false; // Memory allocation failed. |
67 } | 67 } |
68 | 68 |
69 void* pixels = fDiscardableMemory->data(); | 69 void* pixels = fDiscardableMemory->data(); |
70 const SkImageInfo& info = this->info(); | 70 const SkImageInfo& info = this->info(); |
71 SkPMColor colors[256]; | 71 SkPMColor colors[256]; |
72 int colorCount = 0; | 72 int colorCount = 0; |
73 | 73 |
74 const SkImageGenerator::Result result = fGenerator->getPixels(info, pixels,
fRowBytes, NULL, | 74 if (!fGenerator->getPixels(info, pixels, fRowBytes, colors, &colorCount)) { |
75 colors, &color
Count); | 75 fDiscardableMemory->unlock(); |
76 switch (result) { | 76 fDiscardableMemoryIsLocked = false; |
77 case SkImageGenerator::kSuccess: | 77 SkDELETE(fDiscardableMemory); |
78 case SkImageGenerator::kIncompleteInput: | 78 fDiscardableMemory = NULL; |
79 break; | 79 return false; |
80 default: | |
81 fDiscardableMemory->unlock(); | |
82 fDiscardableMemoryIsLocked = false; | |
83 SkDELETE(fDiscardableMemory); | |
84 fDiscardableMemory = NULL; | |
85 return false; | |
86 } | 80 } |
87 | 81 |
88 // Note: our ctable is not purgeable, as it is not stored in the discardable
memory block. | 82 // Note: our ctable is not purgeable, as it is not stored in the discardable
memory block. |
89 // This is because SkColorTable is refcntable, and therefore our caller coul
d hold onto it | 83 // This is because SkColorTable is refcntable, and therefore our caller coul
d hold onto it |
90 // beyond the scope of a lock/unlock. If we change the API/lifecycle for SkC
olorTable, we | 84 // beyond the scope of a lock/unlock. If we change the API/lifecycle for SkC
olorTable, we |
91 // could move it into the block, but then again perhaps it is small enough t
hat this doesn't | 85 // could move it into the block, but then again perhaps it is small enough t
hat this doesn't |
92 // really matter. | 86 // really matter. |
93 if (colorCount > 0) { | 87 if (colorCount > 0) { |
94 fCTable.reset(SkNEW_ARGS(SkColorTable, (colors, colorCount))); | 88 fCTable.reset(SkNEW_ARGS(SkColorTable, (colors, colorCount))); |
95 } else { | 89 } else { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // These are the public API | 146 // These are the public API |
153 | 147 |
154 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { | 148 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { |
155 return SkInstallDiscardablePixelRef(generator, NULL, dst, NULL); | 149 return SkInstallDiscardablePixelRef(generator, NULL, dst, NULL); |
156 } | 150 } |
157 | 151 |
158 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { | 152 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { |
159 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded); | 153 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded); |
160 return generator ? SkInstallDiscardablePixelRef(generator, NULL, dst, NULL)
: false; | 154 return generator ? SkInstallDiscardablePixelRef(generator, NULL, dst, NULL)
: false; |
161 } | 155 } |
OLD | NEW |