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 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 SkASSERT(fRowBytes > 0); | 22 SkASSERT(fRowBytes > 0); |
23 // The SkImageGenerator contract requires fGenerator to always | 23 // The SkImageGenerator contract requires fGenerator to always |
24 // decode the same image on each call to getPixels(). | 24 // decode the same image on each call to getPixels(). |
25 this->setImmutable(); | 25 this->setImmutable(); |
26 } | 26 } |
27 | 27 |
28 SkDiscardablePixelRef::~SkDiscardablePixelRef() { | 28 SkDiscardablePixelRef::~SkDiscardablePixelRef() { |
29 SkDELETE(fGenerator); | 29 SkDELETE(fGenerator); |
30 } | 30 } |
31 | 31 |
32 void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) { | 32 bool SkDiscardablePixelRef::onGetInfo(SkImageInfo* info) { |
| 33 *info = fInfo; |
| 34 return true; |
| 35 } |
| 36 |
| 37 bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { |
33 if (fDiscardableMemory != NULL) { | 38 if (fDiscardableMemory != NULL) { |
34 if (fDiscardableMemory->lock()) { | 39 if (fDiscardableMemory->lock()) { |
35 return fDiscardableMemory->data(); | 40 rec->fPixels = fDiscardableMemory->data(); |
| 41 rec->fColorTable = NULL; |
| 42 rec->fRowBytes = fRowBytes; |
| 43 return true; |
36 } | 44 } |
37 fDiscardableMemory = NULL; | 45 fDiscardableMemory = NULL; |
38 } | 46 } |
39 fDiscardableMemory = SkDiscardableMemory::Create(fSize); | 47 fDiscardableMemory = SkDiscardableMemory::Create(fSize); |
40 if (NULL == fDiscardableMemory) { | 48 if (NULL == fDiscardableMemory) { |
41 return NULL; // Memory allocation failed. | 49 return false; // Memory allocation failed. |
42 } | 50 } |
43 void* pixels = fDiscardableMemory->data(); | 51 void* pixels = fDiscardableMemory->data(); |
44 if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) { | 52 if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) { |
45 return NULL; // TODO(halcanary) Find out correct thing to do. | 53 return false; // TODO(halcanary) Find out correct thing to do. |
46 } | 54 } |
47 return pixels; | 55 |
| 56 rec->fPixels = pixels; |
| 57 rec->fColorTable = NULL; |
| 58 rec->fRowBytes = fRowBytes; |
| 59 return true; |
48 } | 60 } |
49 void SkDiscardablePixelRef::onUnlockPixels() { | 61 void SkDiscardablePixelRef::onUnlockPixels() { |
50 if (fDiscardableMemory != NULL) { | 62 if (fDiscardableMemory != NULL) { |
51 fDiscardableMemory->unlock(); | 63 fDiscardableMemory->unlock(); |
52 } | 64 } |
53 } | 65 } |
54 | 66 |
55 bool SkDiscardablePixelRef::Install(SkImageGenerator* generator, | 67 bool SkDiscardablePixelRef::Install(SkImageGenerator* generator, |
56 SkBitmap* dst) { | 68 SkBitmap* dst) { |
57 SkImageInfo info; | 69 SkImageInfo info; |
58 SkASSERT(generator != NULL); | 70 SkASSERT(generator != NULL); |
59 if ((NULL == generator) | 71 if ((NULL == generator) |
60 || (!generator->getInfo(&info)) | 72 || (!generator->getInfo(&info)) |
61 || (!dst->setConfig(info, 0))) { | 73 || (!dst->setConfig(info, 0))) { |
62 SkDELETE(generator); | 74 SkDELETE(generator); |
63 return false; | 75 return false; |
64 } | 76 } |
65 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, | 77 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, |
66 (generator, info, | 78 (generator, info, |
67 dst->getSize(), | 79 dst->getSize(), |
68 dst->rowBytes()))); | 80 dst->rowBytes()))); |
69 dst->setPixelRef(ref); | 81 dst->setPixelRef(ref); |
70 return true; | 82 return true; |
71 } | 83 } |
OLD | NEW |