aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBitmapCache.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@google.com>2015-02-19 08:53:52 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-19 08:53:52 -0800
commit90c6bc4e85df2da37f436ea1da203e194c4740e2 (patch)
treebc71dc3d3a7160bb8118a1e349e11a6e58a4b8cb /src/core/SkBitmapCache.cpp
parentcabc08c4296e1ce6c6d9d84cf702361cf439c1bc (diff)
Revert of notify resource caches when pixelref genID goes stale (patchset #4 id:60001 of https://codereview.chromium.org/825263005/)
Reason for revert: Crazy failures. http://build.chromium.org/p/client.skia/builders/Test-Mac10.8-MacMini4.1-GeForce320M-x86_64-Debug/builds/1428/steps/dm/logs/stdio Original issue's description: > notify resource caches when pixelref genID goes stale > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/4675819b9dbb3ad71ec851776e5de26d342f29fe TBR=bsalomon@google.com,reed@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/936423002
Diffstat (limited to 'src/core/SkBitmapCache.cpp')
-rw-r--r--src/core/SkBitmapCache.cpp84
1 files changed, 18 insertions, 66 deletions
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
index 9929080164..3af582232b 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 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 @@ public:
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 @@ struct BitmapRec : public SkResourceCache::Rec {
, 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 @@ struct BitmapRec : public SkResourceCache::Rec {
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 @@ bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc
}
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 @@ bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result
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 @@ bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& r
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 @@ struct MipMapRec : public SkResourceCache::Rec {
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 @@ struct MipMapRec : public SkResourceCache::Rec {
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 @@ const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l
return mipmap;
}
-void SkMipMapCache::NotifyGenIDStale(uint32_t genID) {
- SkResourceCache::Purge(&gMipMapKeyNamespaceLabel, MipMapRec::PurgeGenID,
- (void*)((uintptr_t)genID));
-}