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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 const SkImageInfo& info = this->info(); | 48 const SkImageInfo& info = this->info(); |
49 SkBitmap bitmap; | 49 SkBitmap bitmap; |
50 SkASSERT(NULL == fScaledCacheId); | 50 SkASSERT(NULL == fScaledCacheId); |
51 fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(), | 51 fScaledCacheId = SkScaledImageCache::FindAndLock(this->getGenerationID(), |
52 info.fWidth, | 52 info.fWidth, |
53 info.fHeight, | 53 info.fHeight, |
54 &bitmap); | 54 &bitmap); |
55 if (NULL == fScaledCacheId) { | 55 if (NULL == fScaledCacheId) { |
56 // Cache has been purged, must re-decode. | 56 // Cache has been purged, must re-decode. |
57 if ((!bitmap.setInfo(info, fRowBytes)) || !bitmap.allocPixels()) { | 57 if (!bitmap.allocPixels(info, fRowBytes)) { |
58 fErrorInDecoding = true; | 58 fErrorInDecoding = true; |
59 return false; | 59 return false; |
60 } | 60 } |
61 SkAutoLockPixels autoLockPixels(bitmap); | 61 SkAutoLockPixels autoLockPixels(bitmap); |
62 if (!fImageGenerator->getPixels(info, bitmap.getPixels(), fRowBytes)) { | 62 if (!fImageGenerator->getPixels(info, bitmap.getPixels(), fRowBytes)) { |
63 fErrorInDecoding = true; | 63 fErrorInDecoding = true; |
64 return false; | 64 return false; |
65 } | 65 } |
66 fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(), | 66 fScaledCacheId = SkScaledImageCache::AddAndLock(this->getGenerationID(), |
67 info.fWidth, | 67 info.fWidth, |
(...skipping 20 matching lines...) Expand all Loading... |
88 rec->fColorTable = NULL; | 88 rec->fColorTable = NULL; |
89 rec->fRowBytes = bitmap.rowBytes(); | 89 rec->fRowBytes = bitmap.rowBytes(); |
90 return true; | 90 return true; |
91 } | 91 } |
92 | 92 |
93 void SkCachingPixelRef::onUnlockPixels() { | 93 void SkCachingPixelRef::onUnlockPixels() { |
94 SkASSERT(fScaledCacheId != NULL); | 94 SkASSERT(fScaledCacheId != NULL); |
95 SkScaledImageCache::Unlock( static_cast<SkScaledImageCache::ID*>(fScaledCach
eId)); | 95 SkScaledImageCache::Unlock( static_cast<SkScaledImageCache::ID*>(fScaledCach
eId)); |
96 fScaledCacheId = NULL; | 96 fScaledCacheId = NULL; |
97 } | 97 } |
OLD | NEW |