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 | 11 |
11 SkDiscardablePixelRef::SkDiscardablePixelRef(SkImageGenerator* generator, | 12 SkDiscardablePixelRef::SkDiscardablePixelRef(SkImageGenerator* generator, |
12 const SkImageInfo& info, | 13 const SkImageInfo& info, |
13 size_t size, | 14 size_t size, |
14 size_t rowBytes, | 15 size_t rowBytes, |
15 SkDiscardableMemory::Factory* fact) | 16 SkDiscardableMemory::Factory* fact) |
16 : fGenerator(generator) | 17 : fGenerator(generator) |
17 , fDMFactory(fact) | 18 , fDMFactory(fact) |
18 , fInfo(info) | 19 , fInfo(info) |
19 , fSize(size) | 20 , fSize(size) |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return NULL; // TODO(halcanary) Find out correct thing to do. | 56 return NULL; // TODO(halcanary) Find out correct thing to do. |
56 } | 57 } |
57 return pixels; | 58 return pixels; |
58 } | 59 } |
59 void SkDiscardablePixelRef::onUnlockPixels() { | 60 void SkDiscardablePixelRef::onUnlockPixels() { |
60 if (fDiscardableMemory != NULL) { | 61 if (fDiscardableMemory != NULL) { |
61 fDiscardableMemory->unlock(); | 62 fDiscardableMemory->unlock(); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 bool SkDiscardablePixelRef::Install(SkImageGenerator* generator, | 66 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, |
66 SkBitmap* dst, | 67 SkBitmap* dst, |
67 SkDiscardableMemory::Factory* factory) { | 68 SkDiscardableMemory::Factory* factory) { |
68 SkImageInfo info; | 69 SkImageInfo info; |
69 SkASSERT(generator != NULL); | 70 SkASSERT(generator != NULL); |
70 if ((NULL == generator) | 71 if ((NULL == generator) |
71 || (!generator->getInfo(&info)) | 72 || (!generator->getInfo(&info)) |
72 || (!dst->setConfig(info, 0)) | 73 || (!dst->setConfig(info, 0))) { |
73 || (0 == dst->getSize())) { // dst->getSize=0 Probably a bad config | |
74 SkDELETE(generator); | 74 SkDELETE(generator); |
75 return false; | 75 return false; |
76 } | 76 } |
| 77 SkASSERT(dst->config() != SkBitmap::kNo_Config); |
| 78 if (dst->empty()) { // Use a normal pixelref. |
| 79 SkDELETE(generator); // Do not need this anymore. |
| 80 return dst->allocPixels(NULL, NULL); |
| 81 } |
77 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, | 82 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, |
78 (generator, info, | 83 (generator, info, |
79 dst->getSize(), | 84 dst->getSize(), |
80 dst->rowBytes(), | 85 dst->rowBytes(), |
81 factory))); | 86 factory))); |
82 dst->setPixelRef(ref); | 87 dst->setPixelRef(ref); |
83 return true; | 88 return true; |
84 } | 89 } |
OLD | NEW |