Index: src/core/SkBitmapCache.cpp |
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp |
index 5044d305186bfc00ef24a197defe42e94b2ec8be..c1c5d06cae2f418b8ff9a15cadc75a6dc219ee16 100644 |
--- a/src/core/SkBitmapCache.cpp |
+++ b/src/core/SkBitmapCache.cpp |
@@ -71,7 +71,7 @@ struct BitmapRec : public SkResourceCache::Rec { |
}; |
#define CHECK_LOCAL(localCache, localName, globalName, ...) \ |
- (localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::globalName(__VA_ARGS__) |
+ ((localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::globalName(__VA_ARGS__)) |
bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result, |
SkResourceCache* localCache) { |
@@ -125,18 +125,17 @@ bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& r |
struct MipMapRec : public SkResourceCache::Rec { |
MipMapRec(const SkBitmap& src, const SkMipMap* result) |
: fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)) |
- , fMipMap(SkRef(result)) |
- {} |
+ , fMipMap(result) |
+ { |
+ fMipMap->attachToCacheAndRef(); |
+ } |
virtual ~MipMapRec() { |
- fMipMap->unref(); |
+ fMipMap->detachFromCacheAndUnref(); |
} |
- BitmapKey fKey; |
- const SkMipMap* fMipMap; |
- |
virtual const Key& getKey() const SK_OVERRIDE { return fKey; } |
- virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fMipMap->getSize(); } |
+ virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fMipMap->size(); } |
static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextMip) { |
const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); |
@@ -146,20 +145,33 @@ struct MipMapRec : public SkResourceCache::Rec { |
// mipmaps don't use the custom allocator yet, so we don't need to check pixels |
return true; |
} |
+ |
+private: |
+ BitmapKey fKey; |
+ const SkMipMap* fMipMap; |
}; |
-const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src) { |
+const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src, SkResourceCache* localCache) { |
BitmapKey key(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)); |
const SkMipMap* result; |
- if (!SkResourceCache::Find(key, MipMapRec::Visitor, &result)) { |
+ |
+ if (!CHECK_LOCAL(localCache, find, Find, key, MipMapRec::Visitor, &result)) { |
result = NULL; |
} |
return result; |
} |
-void SkMipMapCache::Add(const SkBitmap& src, const SkMipMap* result) { |
- if (result) { |
- SkResourceCache::Add(SkNEW_ARGS(MipMapRec, (src, result))); |
+static SkResourceCache::DiscardableFactory get_fact(SkResourceCache* localCache) { |
+ return localCache ? localCache->GetDiscardableFactory() |
+ : SkResourceCache::GetDiscardableFactory(); |
+} |
+ |
+const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* localCache) { |
+ SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); |
+ if (mipmap) { |
+ MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap)); |
+ CHECK_LOCAL(localCache, add, Add, rec); |
} |
+ return mipmap; |
} |