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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 const char* getCategory() const override { return "mipmap"; } | 195 const char* getCategory() const override { return "mipmap"; } |
196 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { | 196 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { |
197 return fMipMap->diagnostic_only_getDiscardable(); | 197 return fMipMap->diagnostic_only_getDiscardable(); |
198 } | 198 } |
199 | 199 |
200 static bool Finder(const SkResourceCache::Rec& baseRec, void* contextMip) { | 200 static bool Finder(const SkResourceCache::Rec& baseRec, void* contextMip) { |
201 const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); | 201 const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); |
202 const SkMipMap* mm = SkRef(rec.fMipMap); | 202 const SkMipMap* mm = SkRef(rec.fMipMap); |
203 // the call to ref() above triggers a "lock" in the case of discardable
memory, | 203 // the call to ref() above triggers a "lock" in the case of discardable
memory, |
204 // which means we can now check for null (in case the lock failed). | 204 // which means we can now check for null (in case the lock failed). |
205 if (NULL == mm->data()) { | 205 if (nullptr == mm->data()) { |
206 mm->unref(); // balance our call to ref() | 206 mm->unref(); // balance our call to ref() |
207 return false; | 207 return false; |
208 } | 208 } |
209 // the call must call unref() when they are done. | 209 // the call must call unref() when they are done. |
210 *(const SkMipMap**)contextMip = mm; | 210 *(const SkMipMap**)contextMip = mm; |
211 return true; | 211 return true; |
212 } | 212 } |
213 | 213 |
214 private: | 214 private: |
215 MipMapKey fKey; | 215 MipMapKey fKey; |
216 const SkMipMap* fMipMap; | 216 const SkMipMap* fMipMap; |
217 }; | 217 }; |
218 } | 218 } |
219 | 219 |
220 const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src, SkResourceCache*
localCache) { | 220 const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src, SkResourceCache*
localCache) { |
221 MipMapKey key(src.getGenerationID(), get_bounds_from_bitmap(src)); | 221 MipMapKey key(src.getGenerationID(), get_bounds_from_bitmap(src)); |
222 const SkMipMap* result; | 222 const SkMipMap* result; |
223 | 223 |
224 if (!CHECK_LOCAL(localCache, find, Find, key, MipMapRec::Finder, &result)) { | 224 if (!CHECK_LOCAL(localCache, find, Find, key, MipMapRec::Finder, &result)) { |
225 result = NULL; | 225 result = nullptr; |
226 } | 226 } |
227 return result; | 227 return result; |
228 } | 228 } |
229 | 229 |
230 static SkResourceCache::DiscardableFactory get_fact(SkResourceCache* localCache)
{ | 230 static SkResourceCache::DiscardableFactory get_fact(SkResourceCache* localCache)
{ |
231 return localCache ? localCache->GetDiscardableFactory() | 231 return localCache ? localCache->GetDiscardableFactory() |
232 : SkResourceCache::GetDiscardableFactory(); | 232 : SkResourceCache::GetDiscardableFactory(); |
233 } | 233 } |
234 | 234 |
235 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { | 235 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
ocalCache) { |
236 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); | 236 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); |
237 if (mipmap) { | 237 if (mipmap) { |
238 MipMapRec* rec = new MipMapRec(src, mipmap); | 238 MipMapRec* rec = new MipMapRec(src, mipmap); |
239 CHECK_LOCAL(localCache, add, Add, rec); | 239 CHECK_LOCAL(localCache, add, Add, rec); |
240 src.pixelRef()->notifyAddedToCache(); | 240 src.pixelRef()->notifyAddedToCache(); |
241 } | 241 } |
242 return mipmap; | 242 return mipmap; |
243 } | 243 } |
OLD | NEW |