| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void SkDiscardablePixelRef::onUnlockPixels() { | 91 void SkDiscardablePixelRef::onUnlockPixels() { |
| 92 fDiscardableMemory->unlock(); | 92 fDiscardableMemory->unlock(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst, | 95 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst, |
| 96 SkDiscardableMemory::Factory* factory) { | 96 SkDiscardableMemory::Factory* factory) { |
| 97 SkImageInfo info; | 97 SkImageInfo info; |
| 98 SkAutoTDelete<SkImageGenerator> autoGenerator(generator); | 98 SkAutoTDelete<SkImageGenerator> autoGenerator(generator); |
| 99 if ((NULL == autoGenerator.get()) | 99 if ((NULL == autoGenerator.get()) |
| 100 || (!autoGenerator->getInfo(&info)) | 100 || (!autoGenerator->getInfo(&info)) |
| 101 || info.isEmpty() |
| 101 || (!dst->setInfo(info))) { | 102 || (!dst->setInfo(info))) { |
| 102 return false; | 103 return false; |
| 103 } | 104 } |
| 104 // Since dst->setInfo() may have changed/fixed-up info, we copy it back from
that bitmap | 105 // Since dst->setInfo() may have changed/fixed-up info, we copy it back from
that bitmap |
| 105 info = dst->info(); | 106 info = dst->info(); |
| 106 | 107 |
| 107 SkASSERT(info.colorType() != kUnknown_SkColorType); | 108 SkASSERT(info.colorType() != kUnknown_SkColorType); |
| 108 if (dst->empty()) { // Use a normal pixelref. | 109 if (dst->empty()) { // Use a normal pixelref. |
| 109 return dst->tryAllocPixels(); | 110 return dst->tryAllocPixels(); |
| 110 } | 111 } |
| 111 SkAutoTUnref<SkDiscardablePixelRef> ref( | 112 SkAutoTUnref<SkDiscardablePixelRef> ref( |
| 112 SkNEW_ARGS(SkDiscardablePixelRef, | 113 SkNEW_ARGS(SkDiscardablePixelRef, |
| 113 (info, autoGenerator.detach(), dst->rowBytes(), factory))); | 114 (info, autoGenerator.detach(), dst->rowBytes(), factory))); |
| 114 dst->setPixelRef(ref); | 115 dst->setPixelRef(ref); |
| 115 return true; | 116 return true; |
| 116 } | 117 } |
| 117 | 118 |
| 118 // This is the public API | 119 // This is the public API |
| 119 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { | 120 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { |
| 120 return SkInstallDiscardablePixelRef(generator, dst, NULL); | 121 return SkInstallDiscardablePixelRef(generator, dst, NULL); |
| 121 } | 122 } |
| OLD | NEW |