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