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 "SkBitmapCache.h" | 9 #include "SkBitmapCache.h" |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 if (!SkBitmapCache::Find(this->getGenerationID(), info.fWidth, info.fHeight,
&fLockedBitmap)) { | 47 if (!SkBitmapCache::Find(this->getGenerationID(), info.fWidth, info.fHeight,
&fLockedBitmap)) { |
48 // Cache has been purged, must re-decode. | 48 // Cache has been purged, must re-decode. |
49 if (!fLockedBitmap.allocPixels(info, fRowBytes)) { | 49 if (!fLockedBitmap.allocPixels(info, fRowBytes)) { |
50 fErrorInDecoding = true; | 50 fErrorInDecoding = true; |
51 return false; | 51 return false; |
52 } | 52 } |
53 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt
es)) { | 53 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt
es)) { |
54 fErrorInDecoding = true; | 54 fErrorInDecoding = true; |
55 return false; | 55 return false; |
56 } | 56 } |
| 57 fLockedBitmap.setImmutable(); |
57 SkBitmapCache::Add(this->getGenerationID(), info.fWidth, info.fHeight, f
LockedBitmap); | 58 SkBitmapCache::Add(this->getGenerationID(), info.fWidth, info.fHeight, f
LockedBitmap); |
58 } | 59 } |
59 | 60 |
60 // Now bitmap should contain a concrete PixelRef of the decoded image. | 61 // Now bitmap should contain a concrete PixelRef of the decoded image. |
61 void* pixels = fLockedBitmap.getPixels(); | 62 void* pixels = fLockedBitmap.getPixels(); |
62 SkASSERT(pixels != NULL); | 63 SkASSERT(pixels != NULL); |
63 rec->fPixels = pixels; | 64 rec->fPixels = pixels; |
64 rec->fColorTable = NULL; | 65 rec->fColorTable = NULL; |
65 rec->fRowBytes = fLockedBitmap.rowBytes(); | 66 rec->fRowBytes = fLockedBitmap.rowBytes(); |
66 return true; | 67 return true; |
67 } | 68 } |
68 | 69 |
69 void SkCachingPixelRef::onUnlockPixels() { | 70 void SkCachingPixelRef::onUnlockPixels() { |
70 fLockedBitmap.reset(); | 71 fLockedBitmap.reset(); |
71 } | 72 } |
OLD | NEW |