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 #ifdef SK_LEGACY_IMAGE_GENERATOR_ENUMS_AND_OPTIONS |
56 const SkImageGenerator::Result result = fImageGenerator->getPixels(info, | 57 const SkImageGenerator::Result result = fImageGenerator->getPixels(info, |
57 fLockedBitmap.getPixels(), fRowBytes); | 58 fLockedBitmap.getPixels(), fRowBytes); |
58 switch (result) { | 59 switch (result) { |
59 case SkImageGenerator::kIncompleteInput: | 60 case SkImageGenerator::kIncompleteInput: |
60 case SkImageGenerator::kSuccess: | 61 case SkImageGenerator::kSuccess: |
61 break; | 62 break; |
62 default: | 63 default: |
63 fErrorInDecoding = true; | 64 #else |
64 return false; | 65 if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowByt
es)) { |
| 66 #endif |
| 67 fErrorInDecoding = true; |
| 68 return false; |
65 } | 69 } |
66 fLockedBitmap.setImmutable(); | 70 fLockedBitmap.setImmutable(); |
67 SkBitmapCache::Add(this, info.bounds(), fLockedBitmap); | 71 SkBitmapCache::Add(this, info.bounds(), fLockedBitmap); |
68 } | 72 } |
69 | 73 |
70 // Now bitmap should contain a concrete PixelRef of the decoded image. | 74 // Now bitmap should contain a concrete PixelRef of the decoded image. |
71 void* pixels = fLockedBitmap.getPixels(); | 75 void* pixels = fLockedBitmap.getPixels(); |
72 SkASSERT(pixels != NULL); | 76 SkASSERT(pixels != NULL); |
73 rec->fPixels = pixels; | 77 rec->fPixels = pixels; |
74 rec->fColorTable = NULL; | 78 rec->fColorTable = NULL; |
75 rec->fRowBytes = fLockedBitmap.rowBytes(); | 79 rec->fRowBytes = fLockedBitmap.rowBytes(); |
76 return true; | 80 return true; |
77 } | 81 } |
78 | 82 |
79 void SkCachingPixelRef::onUnlockPixels() { | 83 void SkCachingPixelRef::onUnlockPixels() { |
80 fLockedBitmap.reset(); | 84 fLockedBitmap.reset(); |
81 } | 85 } |
OLD | NEW |