OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "Sk64.h" | 8 #include "Sk64.h" |
9 #include "SkLazyPixelRef.h" | 9 #include "SkLazyPixelRef.h" |
10 #include "SkColorTable.h" | 10 #include "SkColorTable.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 SkBitmapFactory::Target target; | 111 SkBitmapFactory::Target target; |
112 target.fAddr = bm->getPixels(); | 112 target.fAddr = bm->getPixels(); |
113 target.fRowBytes = bm->rowBytes(); | 113 target.fRowBytes = bm->rowBytes(); |
114 *rowBytes = target.fRowBytes; | 114 *rowBytes = target.fRowBytes; |
115 if (!decodeProc(data->data(), data->size(), info, &target)) { | 115 if (!decodeProc(data->data(), data->size(), info, &target)) { |
116 return NULL; | 116 return NULL; |
117 } | 117 } |
118 return target.fAddr; | 118 return target.fAddr; |
119 } | 119 } |
120 | 120 |
121 void* SkLazyPixelRef::lockScaledImageCachePixels() { | 121 void* SkLazyPixelRef::lockScaledImageCachePixels(SkImageInfo* info, |
| 122 size_t* rowBytes) { |
122 SkASSERT(!fErrorInDecoding); | 123 SkASSERT(!fErrorInDecoding); |
123 SkASSERT(NULL == fImageCache); | 124 SkASSERT(NULL == fImageCache); |
124 SkBitmap bitmap; | 125 SkBitmap bitmap; |
125 const SkImageInfo* info = this->getCachedInfo(); | 126 const SkImageInfo* cachedInfo = this->getCachedInfo(); |
126 if (info == NULL) { | 127 if (cachedInfo == NULL) { |
127 return NULL; | 128 return NULL; |
128 } | 129 } |
| 130 *info = *cachedInfo; |
| 131 |
129 // If this is the first time though, this is guaranteed to fail. | 132 // If this is the first time though, this is guaranteed to fail. |
130 // Maybe we should have a flag that says "don't even bother looking" | 133 // Maybe we should have a flag that says "don't even bother looking" |
131 fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(), | 134 fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(), |
132 info->fWidth, | 135 info->fWidth, |
133 info->fHeight, | 136 info->fHeight, |
134 &bitmap); | 137 &bitmap); |
135 if (fScaledCacheId != NULL) { | 138 if (fScaledCacheId != NULL) { |
136 SkAutoLockPixels autoLockPixels(bitmap); | 139 SkAutoLockPixels autoLockPixels(bitmap); |
137 void* pixels = bitmap.getPixels(); | 140 void* pixels = bitmap.getPixels(); |
138 SkASSERT(NULL != pixels); | 141 SkASSERT(NULL != pixels); |
139 // At this point, the autoLockPixels will unlockPixels() | 142 // At this point, the autoLockPixels will unlockPixels() |
140 // to remove bitmap's lock on the pixels. We will then | 143 // to remove bitmap's lock on the pixels. We will then |
141 // destroy bitmap. The *only* guarantee that this pointer | 144 // destroy bitmap. The *only* guarantee that this pointer |
142 // remains valid is the guarantee made by | 145 // remains valid is the guarantee made by |
143 // SkScaledImageCache that it will not destroy the *other* | 146 // SkScaledImageCache that it will not destroy the *other* |
144 // bitmap (SkScaledImageCache::Rec.fBitmap) that holds a | 147 // bitmap (SkScaledImageCache::Rec.fBitmap) that holds a |
145 // reference to the concrete PixelRef while this record is | 148 // reference to the concrete PixelRef while this record is |
146 // locked. | 149 // locked. |
| 150 *rowBytes = bitmap.rowBytes(); |
147 return pixels; | 151 return pixels; |
148 } else { | 152 } else { |
149 // Cache has been purged, must re-decode. | 153 // Cache has been purged, must re-decode. |
150 void* pixels = decode_into_bitmap(const_cast<SkImageInfo*>(info), | 154 void* pixels = decode_into_bitmap(const_cast<SkImageInfo*>(info), |
151 fDecodeProc, &fRowBytes, fData, | 155 fDecodeProc, &fRowBytes, fData, |
152 &bitmap); | 156 &bitmap); |
153 if (NULL == pixels) { | 157 if (NULL == pixels) { |
154 fErrorInDecoding = true; | 158 fErrorInDecoding = true; |
155 return NULL; | 159 return NULL; |
156 } | 160 } |
157 fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(), | 161 fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(), |
158 info->fWidth, | 162 info->fWidth, |
159 info->fHeight, | 163 info->fHeight, |
160 bitmap); | 164 bitmap); |
161 SkASSERT(fScaledCacheId != NULL); | 165 SkASSERT(fScaledCacheId != NULL); |
| 166 *rowBytes = bitmap.rowBytes(); |
162 return pixels; | 167 return pixels; |
163 } | 168 } |
164 } | 169 } |
165 | 170 |
166 void* SkLazyPixelRef::onLockPixels(SkColorTable**) { | 171 void* SkLazyPixelRef::onLockPixels(SkImageInfo* info, size_t* rowBytes, |
| 172 SkColorTable**) { |
167 if (fErrorInDecoding) { | 173 if (fErrorInDecoding) { |
168 return NULL; | 174 return NULL; |
169 } | 175 } |
170 if (NULL == fImageCache) { | 176 if (NULL == fImageCache) { |
171 return this->lockScaledImageCachePixels(); | 177 return this->lockScaledImageCachePixels(info, rowBytes); |
172 } else { | 178 } else { |
173 return this->lockImageCachePixels(); | 179 return this->lockImageCachePixels(info, rowBytes); |
174 } | 180 } |
175 } | 181 } |
176 | 182 |
177 void* SkLazyPixelRef::lockImageCachePixels() { | 183 void* SkLazyPixelRef::lockImageCachePixels(SkImageInfo* info, size_t* rowBytes)
{ |
178 SkASSERT(fImageCache != NULL); | 184 SkASSERT(fImageCache != NULL); |
179 SkASSERT(!fErrorInDecoding); | 185 SkASSERT(!fErrorInDecoding); |
180 SkBitmapFactory::Target target; | 186 SkBitmapFactory::Target target; |
181 // Check to see if the pixels still exist in the cache. | 187 // Check to see if the pixels still exist in the cache. |
182 if (SkImageCache::UNINITIALIZED_ID == fCacheId) { | 188 if (SkImageCache::UNINITIALIZED_ID == fCacheId) { |
183 target.fAddr = NULL; | 189 target.fAddr = NULL; |
184 } else { | 190 } else { |
185 SkImageCache::DataStatus status; | 191 SkImageCache::DataStatus status; |
186 target.fAddr = fImageCache->pinCache(fCacheId, &status); | 192 target.fAddr = fImageCache->pinCache(fCacheId, &status); |
187 if (target.fAddr == NULL) { | 193 if (target.fAddr == NULL) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 308 |
303 target.fAddr = tmp.getPixels(); | 309 target.fAddr = tmp.getPixels(); |
304 fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, &target
); | 310 fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, &target
); |
305 if (fErrorInDecoding) { | 311 if (fErrorInDecoding) { |
306 return false; | 312 return false; |
307 } | 313 } |
308 | 314 |
309 *bitmap = tmp; | 315 *bitmap = tmp; |
310 return true; | 316 return true; |
311 } | 317 } |
OLD | NEW |