OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkBitmapCache.h" | 8 #include "SkBitmapCache.h" |
9 #include "SkResourceCache.h" | 9 #include "SkResourceCache.h" |
10 #include "SkMipMap.h" | 10 #include "SkMipMap.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 static bool find_and_return(const BitmapKey& key, SkBitmap* result) { | 64 static bool find_and_return(const BitmapKey& key, SkBitmap* result) { |
65 const BitmapRec* rec = (BitmapRec*)SkResourceCache::FindAndLock(key); | 65 const BitmapRec* rec = (BitmapRec*)SkResourceCache::FindAndLock(key); |
66 if (rec) { | 66 if (rec) { |
67 *result = rec->fBitmap; | 67 *result = rec->fBitmap; |
68 SkResourceCache::Unlock(rec); | 68 SkResourceCache::Unlock(rec); |
69 | 69 |
70 result->lockPixels(); | 70 result->lockPixels(); |
71 if (result->getPixels()) { | 71 if (result->getPixels()) { |
72 return true; | 72 return true; |
73 } | 73 } |
74 // todo: we should explicitly purge rec from the cache at this point, si
nce | 74 |
75 // it is effectively purged already (has no memory behind it) | 75 SkResourceCache::Remove(rec); |
76 result->reset(); | 76 result->reset(); |
77 // fall-through to false | 77 // fall-through to false |
78 } | 78 } |
79 return false; | 79 return false; |
80 } | 80 } |
81 | 81 |
82 bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc
aleY, | 82 bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc
aleY, |
83 SkBitmap* result) { | 83 SkBitmap* result) { |
84 if (0 == invScaleX || 0 == invScaleY) { | 84 if (0 == invScaleX || 0 == invScaleY) { |
85 // degenerate, and the key we use for mipmaps | 85 // degenerate, and the key we use for mipmaps |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 151 } |
152 return result; | 152 return result; |
153 } | 153 } |
154 | 154 |
155 void SkMipMapCache::Add(const SkBitmap& src, const SkMipMap* result) { | 155 void SkMipMapCache::Add(const SkBitmap& src, const SkMipMap* result) { |
156 if (result) { | 156 if (result) { |
157 SkResourceCache::Add(SkNEW_ARGS(MipMapRec, (src, result))); | 157 SkResourceCache::Add(SkNEW_ARGS(MipMapRec, (src, result))); |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
OLD | NEW |