| Index: src/core/SkBitmapCache.cpp
|
| diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
|
| index 84f10363f02aac1bd9b62e9f0c7db7f401e29af7..6d4f4b4cc7d7349173f34048e9ba36a16cd1c508 100644
|
| --- a/src/core/SkBitmapCache.cpp
|
| +++ b/src/core/SkBitmapCache.cpp
|
| @@ -59,16 +59,25 @@
|
|
|
| virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
|
| virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fBitmap.getSize(); }
|
| +};
|
|
|
| - static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextBitmap) {
|
| - const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec);
|
| - SkBitmap* result = (SkBitmap*)contextBitmap;
|
| +static bool find_and_return(const BitmapKey& key, SkBitmap* result) {
|
| + const BitmapRec* rec = (BitmapRec*)SkResourceCache::FindAndLock(key);
|
| + if (rec) {
|
| + *result = rec->fBitmap;
|
| + SkResourceCache::Unlock(rec);
|
|
|
| - *result = rec.fBitmap;
|
| result->lockPixels();
|
| - return SkToBool(result->getPixels());
|
| + if (result->getPixels()) {
|
| + return true;
|
| + }
|
| +
|
| + SkResourceCache::Remove(rec);
|
| + result->reset();
|
| + // fall-through to false
|
| }
|
| -};
|
| + return false;
|
| +}
|
|
|
| bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
|
| SkBitmap* result) {
|
| @@ -77,7 +86,7 @@
|
| return false;
|
| }
|
| BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_bitmap(src));
|
| - return SkResourceCache::Find(key, BitmapRec::Visitor, result);
|
| + return find_and_return(key, result);
|
| }
|
|
|
| void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
|
| @@ -93,7 +102,7 @@
|
|
|
| bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result) {
|
| BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset);
|
| - return SkResourceCache::Find(key, BitmapRec::Visitor, result);
|
| + return find_and_return(key, result);
|
| }
|
|
|
| bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result) {
|
| @@ -129,22 +138,16 @@
|
|
|
| virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
|
| virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fMipMap->getSize(); }
|
| +};
|
|
|
| - static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextMip) {
|
| - const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec);
|
| - const SkMipMap** result = (const SkMipMap**)contextMip;
|
| -
|
| - *result = SkRef(rec.fMipMap);
|
| - // mipmaps don't use the custom allocator yet, so we don't need to check pixels
|
| - return true;
|
| - }
|
| -};
|
|
|
| const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src) {
|
| BitmapKey key(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src));
|
| - const SkMipMap* result;
|
| - if (!SkResourceCache::Find(key, MipMapRec::Visitor, &result)) {
|
| - result = NULL;
|
| + const MipMapRec* rec = (MipMapRec*)SkResourceCache::FindAndLock(key);
|
| + const SkMipMap* result = NULL;
|
| + if (rec) {
|
| + result = SkRef(rec->fMipMap);
|
| + SkResourceCache::Unlock(rec);
|
| }
|
| return result;
|
| }
|
|
|