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 26 matching lines...) Expand all Loading... |
37 SkDELETE(fImageGenerator); | 37 SkDELETE(fImageGenerator); |
38 // Assert always unlock before unref. | 38 // Assert always unlock before unref. |
39 } | 39 } |
40 | 40 |
41 bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) { | 41 bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) { |
42 if (fErrorInDecoding) { | 42 if (fErrorInDecoding) { |
43 return false; // don't try again. | 43 return false; // don't try again. |
44 } | 44 } |
45 | 45 |
46 const SkImageInfo& info = this->info(); | 46 const SkImageInfo& info = this->info(); |
47 if (!SkBitmapCache::Find(this->getGenerationID(), info.fWidth, info.fHeight,
&fLockedBitmap)) { | 47 if (!SkBitmapCache::Find(this->getGenerationID(), info.width(), info.height(
), &fLockedBitmap)) { |
48 // Cache has been purged, must re-decode. | 48 // Cache has been purged, must re-decode. |
49 if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) { | 49 if (!fLockedBitmap.tryAllocPixels(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 fLockedBitmap.setImmutable(); |
58 SkBitmapCache::Add(this->getGenerationID(), info.fWidth, info.fHeight, f
LockedBitmap); | 58 SkBitmapCache::Add(this->getGenerationID(), info.width(), info.height(),
fLockedBitmap); |
59 } | 59 } |
60 | 60 |
61 // Now bitmap should contain a concrete PixelRef of the decoded image. | 61 // Now bitmap should contain a concrete PixelRef of the decoded image. |
62 void* pixels = fLockedBitmap.getPixels(); | 62 void* pixels = fLockedBitmap.getPixels(); |
63 SkASSERT(pixels != NULL); | 63 SkASSERT(pixels != NULL); |
64 rec->fPixels = pixels; | 64 rec->fPixels = pixels; |
65 rec->fColorTable = NULL; | 65 rec->fColorTable = NULL; |
66 rec->fRowBytes = fLockedBitmap.rowBytes(); | 66 rec->fRowBytes = fLockedBitmap.rowBytes(); |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 void SkCachingPixelRef::onUnlockPixels() { | 70 void SkCachingPixelRef::onUnlockPixels() { |
71 fLockedBitmap.reset(); | 71 fLockedBitmap.reset(); |
72 } | 72 } |
OLD | NEW |