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 "SkCachingPixelRef.h" | 8 #include "SkCachingPixelRef.h" |
9 #include "SkScaledImageCache.h" | 9 #include "SkScaledImageCache.h" |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 bool SkCachingPixelRef::configure(SkBitmap* bitmap) { | 39 bool SkCachingPixelRef::configure(SkBitmap* bitmap) { |
40 SkASSERT(bitmap != NULL); | 40 SkASSERT(bitmap != NULL); |
41 SkImageInfo info; | 41 SkImageInfo info; |
42 if (!this->getInfo(&info)) { | 42 if (!this->getInfo(&info)) { |
43 return false; | 43 return false; |
44 } | 44 } |
45 return bitmap->setConfig(info, 0); | 45 return bitmap->setConfig(info, 0); |
46 } | 46 } |
47 | 47 |
48 void* SkCachingPixelRef::onLockPixels(SkColorTable** colorTable) { | 48 void* SkCachingPixelRef::onLockPixels(SkImageInfo* infoPtr, size_t* rowBytes, |
49 (void)colorTable; | 49 SkColorTable** colorTable) { |
50 SkImageInfo info; | 50 SkImageInfo info; |
51 if (!this->getInfo(&info)) { | 51 if (!this->getInfo(&info)) { |
52 return NULL; | 52 return NULL; |
53 } | 53 } |
54 SkBitmap bitmap; | 54 SkBitmap bitmap; |
55 | 55 |
56 fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(), | 56 fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(), |
57 info.fWidth, | 57 info.fWidth, |
58 info.fHeight, | 58 info.fHeight, |
59 &bitmap); | 59 &bitmap); |
60 if (NULL == fScaledCacheId) { | 60 if (NULL == fScaledCacheId) { |
61 // Cache has been purged, must re-decode. | 61 // Cache has been purged, must re-decode. |
62 if (!this->onDecodeInto(0, &bitmap)) { | 62 if (!this->onDecodeInto(0, &bitmap)) { |
63 return NULL; | 63 return NULL; |
64 } | 64 } |
65 fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(), | 65 fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(), |
66 info.fWidth, | 66 info.fWidth, |
67 info.fHeight, | 67 info.fHeight, |
68 bitmap); | 68 bitmap); |
69 SkASSERT(fScaledCacheId != NULL); | 69 SkASSERT(fScaledCacheId != NULL); |
70 } | 70 } |
71 // Now bitmap should contain a concrete PixelRef of the decoded | 71 // Now bitmap should contain a concrete PixelRef of the decoded |
72 // image. | 72 // image. |
73 SkAutoLockPixels autoLockPixels(bitmap); | 73 SkAutoLockPixels autoLockPixels(bitmap); |
74 void* pixels = bitmap.getPixels(); | 74 void* pixels = bitmap.getPixels(); |
75 SkASSERT(pixels != NULL); | 75 SkASSERT(pixels != NULL); |
| 76 |
| 77 *infoPtr = info; |
| 78 *rowBytes = bitmap.rowBytes(); |
| 79 *colorTable = NULL; |
| 80 |
76 // At this point, the autoLockPixels will unlockPixels() | 81 // At this point, the autoLockPixels will unlockPixels() |
77 // to remove bitmap's lock on the pixels. We will then | 82 // to remove bitmap's lock on the pixels. We will then |
78 // destroy bitmap. The *only* guarantee that this pointer | 83 // destroy bitmap. The *only* guarantee that this pointer |
79 // remains valid is the guarantee made by | 84 // remains valid is the guarantee made by |
80 // SkScaledImageCache that it will not destroy the *other* | 85 // SkScaledImageCache that it will not destroy the *other* |
81 // bitmap (SkScaledImageCache::Rec.fBitmap) that holds a | 86 // bitmap (SkScaledImageCache::Rec.fBitmap) that holds a |
82 // reference to the concrete PixelRef while this record is | 87 // reference to the concrete PixelRef while this record is |
83 // locked. | 88 // locked. |
84 return pixels; | 89 return pixels; |
85 } | 90 } |
(...skipping 16 matching lines...) Expand all Loading... |
102 return false; | 107 return false; |
103 } | 108 } |
104 SkAssertResult(this->getInfo(&info)); // since configure() succeeded. | 109 SkAssertResult(this->getInfo(&info)); // since configure() succeeded. |
105 if (!this->onDecodePixels(info, tmp.getPixels(), tmp.rowBytes())) { | 110 if (!this->onDecodePixels(info, tmp.getPixels(), tmp.rowBytes())) { |
106 fErrorInDecoding = true; | 111 fErrorInDecoding = true; |
107 return false; | 112 return false; |
108 } | 113 } |
109 *bitmap = tmp; | 114 *bitmap = tmp; |
110 return true; | 115 return true; |
111 } | 116 } |
OLD | NEW |