OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "Sk64.h" | 8 #include "Sk64.h" |
9 #include "SkLazyPixelRef.h" | 9 #include "SkLazyPixelRef.h" |
10 #include "SkColorTable.h" | 10 #include "SkColorTable.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 #if LAZY_CACHE_STATS | 81 #if LAZY_CACHE_STATS |
82 sk_atomic_inc(&gCacheMisses); | 82 sk_atomic_inc(&gCacheMisses); |
83 #endif | 83 #endif |
84 } | 84 } |
85 SkASSERT(NULL == target.fAddr); | 85 SkASSERT(NULL == target.fAddr); |
86 SkImage::Info info; | 86 SkImage::Info info; |
87 SkASSERT(fData != NULL && fData->size() > 0); | 87 SkASSERT(fData != NULL && fData->size() > 0); |
88 // FIXME: As an optimization, only do this part once. | 88 // FIXME: As an optimization, only do this part once. |
89 fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, NULL); | 89 fErrorInDecoding = !fDecodeProc(fData->data(), fData->size(), &info, NULL); |
90 if (fErrorInDecoding) { | 90 if (fErrorInDecoding) { |
| 91 // In case a previous call to allocAndPinCache succeeded. |
| 92 fImageCache->throwAwayCache(fCacheId); |
91 fCacheId = SkImageCache::UNINITIALIZED_ID; | 93 fCacheId = SkImageCache::UNINITIALIZED_ID; |
92 return NULL; | 94 return NULL; |
93 } | 95 } |
94 // Allocate the memory. | 96 // Allocate the memory. |
95 size_t bytes = ComputeMinRowBytesAndSize(info, &target.fRowBytes); | 97 size_t bytes = ComputeMinRowBytesAndSize(info, &target.fRowBytes); |
96 | 98 |
97 target.fAddr = fImageCache->allocAndPinCache(bytes, &fCacheId); | 99 target.fAddr = fImageCache->allocAndPinCache(bytes, &fCacheId); |
98 if (NULL == target.fAddr) { | 100 if (NULL == target.fAddr) { |
99 // Space could not be allocated. | 101 // Space could not be allocated. |
100 fCacheId = SkImageCache::UNINITIALIZED_ID; | 102 fCacheId = SkImageCache::UNINITIALIZED_ID; |
(...skipping 15 matching lines...) Expand all Loading... |
116 } | 118 } |
117 if (fCacheId != SkImageCache::UNINITIALIZED_ID) { | 119 if (fCacheId != SkImageCache::UNINITIALIZED_ID) { |
118 fImageCache->releaseCache(fCacheId); | 120 fImageCache->releaseCache(fCacheId); |
119 } | 121 } |
120 } | 122 } |
121 | 123 |
122 SkData* SkLazyPixelRef::onRefEncodedData() { | 124 SkData* SkLazyPixelRef::onRefEncodedData() { |
123 fData->ref(); | 125 fData->ref(); |
124 return fData; | 126 return fData; |
125 } | 127 } |
OLD | NEW |