Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: src/core/SkBitmapCache.cpp

Issue 567393002: Change SkResourceCache to take a Visitor inside its find(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: document Find and Visitor, cast directly between ref types Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/ImageCacheBench.cpp ('k') | src/core/SkResourceCache.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmapCache.cpp
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
index 6d4f4b4cc7d7349173f34048e9ba36a16cd1c508..84f10363f02aac1bd9b62e9f0c7db7f401e29af7 100644
--- a/src/core/SkBitmapCache.cpp
+++ b/src/core/SkBitmapCache.cpp
@@ -59,25 +59,16 @@ struct BitmapRec : public SkResourceCache::Rec {
virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fBitmap.getSize(); }
-};
-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);
+ static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextBitmap) {
+ const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec);
+ SkBitmap* result = (SkBitmap*)contextBitmap;
+ *result = rec.fBitmap;
result->lockPixels();
- if (result->getPixels()) {
- return true;
- }
-
- SkResourceCache::Remove(rec);
- result->reset();
- // fall-through to false
+ return SkToBool(result->getPixels());
}
- return false;
-}
+};
bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
SkBitmap* result) {
@@ -86,7 +77,7 @@ bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc
return false;
}
BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_bitmap(src));
- return find_and_return(key, result);
+ return SkResourceCache::Find(key, BitmapRec::Visitor, result);
}
void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
@@ -102,7 +93,7 @@ void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca
bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result) {
BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset);
- return find_and_return(key, result);
+ return SkResourceCache::Find(key, BitmapRec::Visitor, result);
}
bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result) {
@@ -138,16 +129,22 @@ struct MipMapRec : public SkResourceCache::Rec {
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 MipMapRec* rec = (MipMapRec*)SkResourceCache::FindAndLock(key);
- const SkMipMap* result = NULL;
- if (rec) {
- result = SkRef(rec->fMipMap);
- SkResourceCache::Unlock(rec);
+ const SkMipMap* result;
+ if (!SkResourceCache::Find(key, MipMapRec::Visitor, &result)) {
+ result = NULL;
}
return result;
}
« no previous file with comments | « bench/ImageCacheBench.cpp ('k') | src/core/SkResourceCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698