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 #include "SkRect.h" | 10 #include "SkRect.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 SkDELETE(fImageGenerator); | 38 SkDELETE(fImageGenerator); |
39 // Assert always unlock before unref. | 39 // Assert always unlock before unref. |
40 } | 40 } |
41 | 41 |
42 bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) { | 42 bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) { |
43 if (fErrorInDecoding) { | 43 if (fErrorInDecoding) { |
44 return false; // don't try again. | 44 return false; // don't try again. |
45 } | 45 } |
46 | 46 |
47 const SkImageInfo& info = this->info(); | 47 const SkImageInfo& info = this->info(); |
48 if (!SkBitmapCache::Find(this->getGenerationID(), | 48 if (!SkBitmapCache::Find( |
49 SkIRect::MakeWH(info.width(), info.height()), | 49 this->getGenerationID(), info.bounds(), &fLockedBitmap)) { |
50 &fLockedBitmap)) { | |
51 // Cache has been purged, must re-decode. | 50 // Cache has been purged, must re-decode. |
52 if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) { | 51 if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) { |
53 fErrorInDecoding = true; | 52 fErrorInDecoding = true; |
54 return false; | 53 return false; |
55 } | 54 } |
56 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt
es)) { | 55 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt
es)) { |
57 fErrorInDecoding = true; | 56 fErrorInDecoding = true; |
58 return false; | 57 return false; |
59 } | 58 } |
60 fLockedBitmap.setImmutable(); | 59 fLockedBitmap.setImmutable(); |
61 SkBitmapCache::Add(this->getGenerationID(), | 60 SkBitmapCache::Add( |
62 SkIRect::MakeWH(info.width(), info.height()), | 61 this->getGenerationID(), info.bounds(), fLockedBitmap); |
63 fLockedBitmap); | |
64 } | 62 } |
65 | 63 |
66 // Now bitmap should contain a concrete PixelRef of the decoded image. | 64 // Now bitmap should contain a concrete PixelRef of the decoded image. |
67 void* pixels = fLockedBitmap.getPixels(); | 65 void* pixels = fLockedBitmap.getPixels(); |
68 SkASSERT(pixels != NULL); | 66 SkASSERT(pixels != NULL); |
69 rec->fPixels = pixels; | 67 rec->fPixels = pixels; |
70 rec->fColorTable = NULL; | 68 rec->fColorTable = NULL; |
71 rec->fRowBytes = fLockedBitmap.rowBytes(); | 69 rec->fRowBytes = fLockedBitmap.rowBytes(); |
72 return true; | 70 return true; |
73 } | 71 } |
74 | 72 |
75 void SkCachingPixelRef::onUnlockPixels() { | 73 void SkCachingPixelRef::onUnlockPixels() { |
76 fLockedBitmap.reset(); | 74 fLockedBitmap.reset(); |
77 } | 75 } |
OLD | NEW |