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

Unified Diff: src/core/SkBitmapCache.cpp

Issue 576763002: allow SkBitmapCache to operate on a local instance, for testability (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use __VA_ARGS__ explicitly to make MSVC happy 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 | « src/core/SkBitmapCache.h ('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 84f10363f02aac1bd9b62e9f0c7db7f401e29af7..5044d305186bfc00ef24a197defe42e94b2ec8be 100644
--- a/src/core/SkBitmapCache.cpp
+++ b/src/core/SkBitmapCache.cpp
@@ -70,33 +70,41 @@ struct BitmapRec : public SkResourceCache::Rec {
}
};
-bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
- SkBitmap* result) {
+#define CHECK_LOCAL(localCache, localName, globalName, ...) \
+ (localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::globalName(__VA_ARGS__)
+
+bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result,
+ SkResourceCache* localCache) {
if (0 == invScaleX || 0 == invScaleY) {
// degenerate, and the key we use for mipmaps
return false;
}
BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_bitmap(src));
- return SkResourceCache::Find(key, BitmapRec::Visitor, result);
+
+ return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Visitor, result);
}
void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
- const SkBitmap& result) {
+ const SkBitmap& result, SkResourceCache* localCache) {
if (0 == invScaleX || 0 == invScaleY) {
// degenerate, and the key we use for mipmaps
return;
}
SkASSERT(result.isImmutable());
- SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX, invScaleY,
- get_bounds_from_bitmap(src), result)));
+ BitmapRec* rec = SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX, invScaleY,
+ get_bounds_from_bitmap(src), result));
+ CHECK_LOCAL(localCache, add, Add, rec);
}
-bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result) {
+bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result,
+ SkResourceCache* localCache) {
BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset);
- return SkResourceCache::Find(key, BitmapRec::Visitor, result);
+
+ return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Visitor, result);
}
-bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result) {
+bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result,
+ SkResourceCache* localCache) {
SkASSERT(result.isImmutable());
if (subset.isEmpty()
@@ -106,9 +114,9 @@ bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& r
|| result.height() != subset.height()) {
return false;
} else {
- SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1,
- subset, result)));
+ BitmapRec* rec = SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1, subset, result));
+ CHECK_LOCAL(localCache, add, Add, rec);
return true;
}
}
« no previous file with comments | « src/core/SkBitmapCache.h ('k') | src/core/SkResourceCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698