| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } | 57 } |
| 58 if (NULL == fDiscardableMemory) { | 58 if (NULL == fDiscardableMemory) { |
| 59 return false; // Memory allocation failed. | 59 return false; // Memory allocation failed. |
| 60 } | 60 } |
| 61 | 61 |
| 62 void* pixels = fDiscardableMemory->data(); | 62 void* pixels = fDiscardableMemory->data(); |
| 63 const SkImageInfo& info = this->info(); | 63 const SkImageInfo& info = this->info(); |
| 64 SkPMColor colors[256]; | 64 SkPMColor colors[256]; |
| 65 int colorCount = 0; | 65 int colorCount = 0; |
| 66 | 66 |
| 67 #ifdef SK_SUPPORT_LEGACY_IMAGEGENERATORAPI | |
| 68 if (!fGenerator->getPixels(info, pixels, fRowBytes)) { | |
| 69 #else | |
| 70 if (!fGenerator->getPixels(info, pixels, fRowBytes, colors, &colorCount)) { | 67 if (!fGenerator->getPixels(info, pixels, fRowBytes, colors, &colorCount)) { |
| 71 #endif | |
| 72 fDiscardableMemory->unlock(); | 68 fDiscardableMemory->unlock(); |
| 73 SkDELETE(fDiscardableMemory); | 69 SkDELETE(fDiscardableMemory); |
| 74 fDiscardableMemory = NULL; | 70 fDiscardableMemory = NULL; |
| 75 return false; | 71 return false; |
| 76 } | 72 } |
| 77 | 73 |
| 78 // Note: our ctable is not purgable, as it is not stored in the discardablem
emory block. | 74 // Note: our ctable is not purgable, as it is not stored in the discardablem
emory block. |
| 79 // 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 |
| 80 // 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 |
| 81 // 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 SkNEW_ARGS(SkDiscardablePixelRef, | 112 SkNEW_ARGS(SkDiscardablePixelRef, |
| 117 (info, autoGenerator.detach(), dst->rowBytes(), factory))); | 113 (info, autoGenerator.detach(), dst->rowBytes(), factory))); |
| 118 dst->setPixelRef(ref); | 114 dst->setPixelRef(ref); |
| 119 return true; | 115 return true; |
| 120 } | 116 } |
| 121 | 117 |
| 122 // This is the public API | 118 // This is the public API |
| 123 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { | 119 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { |
| 124 return SkInstallDiscardablePixelRef(generator, dst, NULL); | 120 return SkInstallDiscardablePixelRef(generator, dst, NULL); |
| 125 } | 121 } |
| OLD | NEW |