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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 | 47 |
48 const SkImageInfo& info = this->info(); | 48 const SkImageInfo& info = this->info(); |
49 if (!SkBitmapCache::Find( | 49 if (!SkBitmapCache::Find( |
50 this->getGenerationID(), info.bounds(), &fLockedBitmap)) { | 50 this->getGenerationID(), info.bounds(), &fLockedBitmap)) { |
51 // Cache has been purged, must re-decode. | 51 // Cache has been purged, must re-decode. |
52 if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) { | 52 if (!fLockedBitmap.tryAllocPixels(info, fRowBytes)) { |
53 fErrorInDecoding = true; | 53 fErrorInDecoding = true; |
54 return false; | 54 return false; |
55 } | 55 } |
56 const SkImageGenerator::Result result = fImageGenerator->getPixels(info, | 56 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt
es)) { |
57 fLockedBitmap.getPixels(), fRowBytes); | 57 fErrorInDecoding = true; |
58 switch (result) { | 58 return false; |
59 case SkImageGenerator::kIncompleteInput: | |
60 case SkImageGenerator::kSuccess: | |
61 break; | |
62 default: | |
63 fErrorInDecoding = true; | |
64 return false; | |
65 } | 59 } |
66 fLockedBitmap.setImmutable(); | 60 fLockedBitmap.setImmutable(); |
67 SkBitmapCache::Add(this, info.bounds(), fLockedBitmap); | 61 SkBitmapCache::Add(this, info.bounds(), fLockedBitmap); |
68 } | 62 } |
69 | 63 |
70 // Now bitmap should contain a concrete PixelRef of the decoded image. | 64 // Now bitmap should contain a concrete PixelRef of the decoded image. |
71 void* pixels = fLockedBitmap.getPixels(); | 65 void* pixels = fLockedBitmap.getPixels(); |
72 SkASSERT(pixels != NULL); | 66 SkASSERT(pixels != NULL); |
73 rec->fPixels = pixels; | 67 rec->fPixels = pixels; |
74 rec->fColorTable = NULL; | 68 rec->fColorTable = NULL; |
75 rec->fRowBytes = fLockedBitmap.rowBytes(); | 69 rec->fRowBytes = fLockedBitmap.rowBytes(); |
76 return true; | 70 return true; |
77 } | 71 } |
78 | 72 |
79 void SkCachingPixelRef::onUnlockPixels() { | 73 void SkCachingPixelRef::onUnlockPixels() { |
80 fLockedBitmap.reset(); | 74 fLockedBitmap.reset(); |
81 } | 75 } |
OLD | NEW |