| Index: src/core/SkBitmapCache.cpp
|
| diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
|
| index 193a5ae53627fffc223b563a23a34c01b3ae9004..4f2654925ef3741bfec53e4db40433db8f9caca1 100644
|
| --- a/src/core/SkBitmapCache.cpp
|
| +++ b/src/core/SkBitmapCache.cpp
|
| @@ -33,11 +33,11 @@ static unsigned gBitmapKeyNamespaceLabel;
|
|
|
| struct BitmapKey : public SkResourceCache::Key {
|
| public:
|
| - BitmapKey(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& bounds)
|
| - : fGenID(genID)
|
| - , fScaleX(scaleX)
|
| - , fScaleY(scaleY)
|
| - , fBounds(bounds)
|
| + BitmapKey(uint32_t genID, SkScalar sx, SkScalar sy, const SkIRect& bounds)
|
| + : fGenID(genID)
|
| + , fScaleX(sx)
|
| + , fScaleY(sy)
|
| + , fBounds(bounds)
|
| {
|
| this->init(&gBitmapKeyNamespaceLabel,
|
| sizeof(fGenID) + sizeof(fScaleX) + sizeof(fScaleY) + sizeof(fBounds));
|
| @@ -49,8 +49,6 @@ public:
|
| SkIRect fBounds;
|
| };
|
|
|
| -//////////////////////////////////////////////////////////////////////////////////////////
|
| -
|
| struct BitmapRec : public SkResourceCache::Rec {
|
| BitmapRec(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& bounds,
|
| const SkBitmap& result)
|
| @@ -58,9 +56,6 @@ struct BitmapRec : public SkResourceCache::Rec {
|
| , fBitmap(result)
|
| {}
|
|
|
| - BitmapKey fKey;
|
| - SkBitmap fBitmap;
|
| -
|
| virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
|
| virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fBitmap.getSize(); }
|
|
|
| @@ -72,6 +67,18 @@ struct BitmapRec : public SkResourceCache::Rec {
|
| result->lockPixels();
|
| return SkToBool(result->getPixels());
|
| }
|
| +
|
| + // Given a genID, return true if this rec does NOT match that genID
|
| + // Caller will purge the rec if we return false (when our genID matches)
|
| + static bool NotGenID(const SkResourceCache::Rec& baseRec, void* contextGenID) {
|
| + const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec);
|
| + uintptr_t genID = (uintptr_t)contextGenID;
|
| + return rec.fKey.fGenID != genID;
|
| + }
|
| +
|
| +private:
|
| + BitmapKey fKey;
|
| + SkBitmap fBitmap;
|
| };
|
| } // namespace
|
|
|
| @@ -125,11 +132,31 @@ bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& r
|
| return true;
|
| }
|
| }
|
| +
|
| +void SkBitmapCache::NotifyGenIDStale(uint32_t genID) {
|
| + SkResourceCache::PurgeVisitor(&gBitmapKeyNamespaceLabel, BitmapRec::NotGenID,
|
| + (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(), 0, 0, get_bounds_from_bitmap(src))
|
| + : fKey(src.getGenerationID(), get_bounds_from_bitmap(src))
|
| , fMipMap(result)
|
| {
|
| fMipMap->attachToCacheAndRef();
|
| @@ -156,10 +183,19 @@ struct MipMapRec : public SkResourceCache::Rec {
|
| return true;
|
| }
|
|
|
| + // Given a genID, return true if this rec does NOT match that genID
|
| + // Caller will purge the rec if we return false (when our genID matches)
|
| + static bool NotGenID(const SkResourceCache::Rec& baseRec, void* contextGenID) {
|
| + const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec);
|
| + uintptr_t genID = (uintptr_t)contextGenID;
|
| + return rec.fKey.fGenID != genID;
|
| + }
|
| +
|
| private:
|
| - BitmapKey fKey;
|
| + MipMapKey fKey;
|
| const SkMipMap* fMipMap;
|
| };
|
| +}
|
|
|
| const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src, SkResourceCache* localCache) {
|
| BitmapKey key(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src));
|
| @@ -185,3 +221,7 @@ const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
|
| return mipmap;
|
| }
|
|
|
| +void SkMipMapCache::NotifyGenIDStale(uint32_t genID) {
|
| + SkResourceCache::PurgeVisitor(&gMipMapKeyNamespaceLabel, MipMapRec::NotGenID,
|
| + (void*)((uintptr_t)genID));
|
| +}
|
|
|