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 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS |
74 const SkImageGenerator::Result result = fGenerator->getPixels(info, pixels,
fRowBytes, NULL, | 75 const SkImageGenerator::Result result = fGenerator->getPixels(info, pixels,
fRowBytes, NULL, |
75 colors, &color
Count); | 76 colors, &color
Count); |
76 switch (result) { | 77 switch (result) { |
77 case SkImageGenerator::kSuccess: | 78 case SkImageGenerator::kSuccess: |
78 case SkImageGenerator::kIncompleteInput: | 79 case SkImageGenerator::kIncompleteInput: |
79 break; | 80 break; |
80 default: | 81 default: |
81 fDiscardableMemory->unlock(); | 82 #else |
82 fDiscardableMemoryIsLocked = false; | 83 if (!fGenerator->getPixels(info, pixels, fRowBytes, colors, &colorCount)) { |
83 SkDELETE(fDiscardableMemory); | 84 #endif |
84 fDiscardableMemory = NULL; | 85 fDiscardableMemory->unlock(); |
85 return false; | 86 fDiscardableMemoryIsLocked = false; |
| 87 SkDELETE(fDiscardableMemory); |
| 88 fDiscardableMemory = NULL; |
| 89 return false; |
86 } | 90 } |
87 | 91 |
88 // Note: our ctable is not purgeable, as it is not stored in the discardable
memory block. | 92 // 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 | 93 // 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 | 94 // 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 | 95 // could move it into the block, but then again perhaps it is small enough t
hat this doesn't |
92 // really matter. | 96 // really matter. |
93 if (colorCount > 0) { | 97 if (colorCount > 0) { |
94 fCTable.reset(SkNEW_ARGS(SkColorTable, (colors, colorCount))); | 98 fCTable.reset(SkNEW_ARGS(SkColorTable, (colors, colorCount))); |
95 } else { | 99 } else { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // These are the public API | 156 // These are the public API |
153 | 157 |
154 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { | 158 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { |
155 return SkInstallDiscardablePixelRef(generator, NULL, dst, NULL); | 159 return SkInstallDiscardablePixelRef(generator, NULL, dst, NULL); |
156 } | 160 } |
157 | 161 |
158 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { | 162 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { |
159 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded); | 163 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded); |
160 return generator ? SkInstallDiscardablePixelRef(generator, NULL, dst, NULL)
: false; | 164 return generator ? SkInstallDiscardablePixelRef(generator, NULL, dst, NULL)
: false; |
161 } | 165 } |
OLD | NEW |