Index: src/core/SkBitmapCache.cpp |
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp |
index 99290801647f8108b8764df5bc83afe68403907e..3af582232ba9b8eb0b0014874c015d7eaa2d0c96 100644 |
--- a/src/core/SkBitmapCache.cpp |
+++ b/src/core/SkBitmapCache.cpp |
@@ -33,11 +33,11 @@ |
struct BitmapKey : public SkResourceCache::Key { |
public: |
- BitmapKey(uint32_t genID, SkScalar sx, SkScalar sy, const SkIRect& bounds) |
- : fGenID(genID) |
- , fScaleX(sx) |
- , fScaleY(sy) |
- , fBounds(bounds) |
+ BitmapKey(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& bounds) |
+ : fGenID(genID) |
+ , fScaleX(scaleX) |
+ , fScaleY(scaleY) |
+ , fBounds(bounds) |
{ |
this->init(&gBitmapKeyNamespaceLabel, |
sizeof(fGenID) + sizeof(fScaleX) + sizeof(fScaleY) + sizeof(fBounds)); |
@@ -49,6 +49,8 @@ |
SkIRect fBounds; |
}; |
+////////////////////////////////////////////////////////////////////////////////////////// |
+ |
struct BitmapRec : public SkResourceCache::Rec { |
BitmapRec(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& bounds, |
const SkBitmap& result) |
@@ -56,10 +58,13 @@ |
, fBitmap(result) |
{} |
+ BitmapKey fKey; |
+ SkBitmap fBitmap; |
+ |
const Key& getKey() const SK_OVERRIDE { return fKey; } |
size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fBitmap.getSize(); } |
- static bool Finder(const SkResourceCache::Rec& baseRec, void* contextBitmap) { |
+ static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextBitmap) { |
const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); |
SkBitmap* result = (SkBitmap*)contextBitmap; |
@@ -67,22 +72,6 @@ |
result->lockPixels(); |
return SkToBool(result->getPixels()); |
} |
- |
- static SkResourceCache::PurgeVisitorResult PurgeGenID(const SkResourceCache::Rec& baseRec, |
- void* contextGenID) { |
- const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); |
- uintptr_t genID = (uintptr_t)contextGenID; |
- if (rec.fKey.fGenID == genID) { |
-// SkDebugf("BitmapRec purging genID %d\n", genID); |
- return SkResourceCache::kPurgeAndContinue_PurgeVisitorResult; |
- } else { |
- return SkResourceCache::kRetainAndContinue_PurgeVisitorResult; |
- } |
- } |
- |
-private: |
- BitmapKey fKey; |
- SkBitmap fBitmap; |
}; |
} // namespace |
@@ -97,7 +86,7 @@ |
} |
BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_bitmap(src)); |
- return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); |
+ return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Visitor, result); |
} |
void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, |
@@ -116,7 +105,7 @@ |
SkResourceCache* localCache) { |
BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset); |
- return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result); |
+ return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Visitor, result); |
} |
bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result, |
@@ -136,31 +125,11 @@ |
return true; |
} |
} |
- |
-void SkBitmapCache::NotifyGenIDStale(uint32_t genID) { |
- SkResourceCache::Purge(&gBitmapKeyNamespaceLabel, BitmapRec::PurgeGenID, |
- (void*)((uintptr_t)genID)); |
-} |
- |
////////////////////////////////////////////////////////////////////////////////////////// |
-////////////////////////////////////////////////////////////////////////////////////////// |
- |
-namespace { |
-static unsigned gMipMapKeyNamespaceLabel; |
- |
-struct MipMapKey : public SkResourceCache::Key { |
-public: |
- MipMapKey(uint32_t genID, const SkIRect& bounds) : fGenID(genID), fBounds(bounds) { |
- this->init(&gMipMapKeyNamespaceLabel, sizeof(fGenID) + sizeof(fBounds)); |
- } |
- |
- uint32_t fGenID; |
- SkIRect fBounds; |
-}; |
struct MipMapRec : public SkResourceCache::Rec { |
MipMapRec(const SkBitmap& src, const SkMipMap* result) |
- : fKey(src.getGenerationID(), get_bounds_from_bitmap(src)) |
+ : fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)) |
, fMipMap(result) |
{ |
fMipMap->attachToCacheAndRef(); |
@@ -173,7 +142,7 @@ |
const Key& getKey() const SK_OVERRIDE { return fKey; } |
size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fMipMap->size(); } |
- static bool Finder(const SkResourceCache::Rec& baseRec, void* contextMip) { |
+ static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextMip) { |
const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); |
const SkMipMap* mm = SkRef(rec.fMipMap); |
// the call to ref() above triggers a "lock" in the case of discardable memory, |
@@ -187,29 +156,16 @@ |
return true; |
} |
- static SkResourceCache::PurgeVisitorResult PurgeGenID(const SkResourceCache::Rec& baseRec, |
- void* contextGenID) { |
- const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); |
- uintptr_t genID = (uintptr_t)contextGenID; |
- if (rec.fKey.fGenID == genID) { |
-// SkDebugf("MipMapRec purging genID %d\n", genID); |
- return SkResourceCache::kPurgeAndContinue_PurgeVisitorResult; |
- } else { |
- return SkResourceCache::kRetainAndContinue_PurgeVisitorResult; |
- } |
- } |
- |
private: |
- MipMapKey fKey; |
+ BitmapKey fKey; |
const SkMipMap* fMipMap; |
}; |
-} |
const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src, SkResourceCache* localCache) { |
- MipMapKey key(src.getGenerationID(), get_bounds_from_bitmap(src)); |
+ BitmapKey key(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)); |
const SkMipMap* result; |
- if (!CHECK_LOCAL(localCache, find, Find, key, MipMapRec::Finder, &result)) { |
+ if (!CHECK_LOCAL(localCache, find, Find, key, MipMapRec::Visitor, &result)) { |
result = NULL; |
} |
return result; |
@@ -229,7 +185,3 @@ |
return mipmap; |
} |
-void SkMipMapCache::NotifyGenIDStale(uint32_t genID) { |
- SkResourceCache::Purge(&gMipMapKeyNamespaceLabel, MipMapRec::PurgeGenID, |
- (void*)((uintptr_t)genID)); |
-} |