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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 if (NULL == fDiscardableMemory) { | 51 if (NULL == fDiscardableMemory) { |
52 return NULL; // Memory allocation failed. | 52 return NULL; // Memory allocation failed. |
53 } | 53 } |
54 void* pixels = fDiscardableMemory->data(); | 54 void* pixels = fDiscardableMemory->data(); |
55 if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) { | 55 if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) { |
56 return NULL; // TODO(halcanary) Find out correct thing to do. | 56 return NULL; // TODO(halcanary) Find out correct thing to do. |
57 } | 57 } |
58 return pixels; | 58 return pixels; |
59 } | 59 } |
60 void SkDiscardablePixelRef::onUnlockPixels() { | 60 void SkDiscardablePixelRef::onUnlockPixels() { |
61 if (fDiscardableMemory != NULL) { | 61 fDiscardableMemory->unlock(); |
62 fDiscardableMemory->unlock(); | |
63 } | |
64 } | 62 } |
65 | 63 |
66 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, | 64 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, |
67 SkBitmap* dst, | 65 SkBitmap* dst, |
68 SkDiscardableMemory::Factory* factory) { | 66 SkDiscardableMemory::Factory* factory) { |
69 SkImageInfo info; | 67 SkImageInfo info; |
70 SkASSERT(generator != NULL); | 68 SkASSERT(generator != NULL); |
71 if ((NULL == generator) | 69 if ((NULL == generator) |
72 || (!generator->getInfo(&info)) | 70 || (!generator->getInfo(&info)) |
73 || (!dst->setConfig(info, 0))) { | 71 || (!dst->setConfig(info, 0))) { |
74 SkDELETE(generator); | 72 SkDELETE(generator); |
75 return false; | 73 return false; |
76 } | 74 } |
77 SkASSERT(dst->config() != SkBitmap::kNo_Config); | 75 SkASSERT(dst->config() != SkBitmap::kNo_Config); |
78 if (dst->empty()) { // Use a normal pixelref. | 76 if (dst->empty()) { // Use a normal pixelref. |
79 SkDELETE(generator); // Do not need this anymore. | 77 SkDELETE(generator); // Do not need this anymore. |
80 return dst->allocPixels(NULL, NULL); | 78 return dst->allocPixels(NULL, NULL); |
81 } | 79 } |
82 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, | 80 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, |
83 (generator, info, | 81 (generator, info, |
84 dst->getSize(), | 82 dst->getSize(), |
85 dst->rowBytes(), | 83 dst->rowBytes(), |
86 factory))); | 84 factory))); |
87 dst->setPixelRef(ref); | 85 dst->setPixelRef(ref); |
88 return true; | 86 return true; |
89 } | 87 } |
OLD | NEW |