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

Unified Diff: src/core/SkBitmapCache.cpp

Issue 518983002: The key for SkBitmapCache can now be genID+SkIRect (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add checks on SkBitmapCache::Add 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') | tests/SkResourceCacheTest.cpp » ('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 8de8ab79edac2d8b0224bb3a0e140b81551964cc..d8e775c883a071ad9f4a24a3c71f45144be05edd 100644
--- a/src/core/SkBitmapCache.cpp
+++ b/src/core/SkBitmapCache.cpp
@@ -56,7 +56,7 @@ struct BitmapRec : public SkResourceCache::Rec {
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(); }
};
@@ -101,16 +101,31 @@ void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca
}
bool SkBitmapCache::Find(uint32_t genID, int width, int height, SkBitmap* result) {
- BitmapKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeWH(width, height));
+ return Find(genID, SkIRect::MakeWH(width, height), result);
+}
+
+bool SkBitmapCache::Add(uint32_t genID, int width, int height, const SkBitmap& result) {
+ return Add(genID, SkIRect::MakeWH(width, height), result);
Rémi Piotaix 2014/09/02 19:20:58 Because width and height must be the ones of 'resu
+}
+
+bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result) {
+ BitmapKey key(genID, SK_Scalar1, SK_Scalar1, subset);
Rémi Piotaix 2014/09/02 19:20:58 Do we need to add the check on the Find methods? (
return find_and_return(key, result);
}
-void SkBitmapCache::Add(uint32_t genID, int width, int height, const SkBitmap& result) {
+bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result) {
SkASSERT(result.isImmutable());
- SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1,
- SkIRect::MakeWH(width, height), result)));
-}
+ if (subset.isEmpty()
+ || result.width() != subset.width()
+ || result.height() != subset.height()) {
+ return false;
+ } else {
+ SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1,
+ subset, result)));
+ return true;
+ }
+}
//////////////////////////////////////////////////////////////////////////////////////////
struct MipMapRec : public SkResourceCache::Rec {
@@ -125,7 +140,7 @@ struct MipMapRec : public SkResourceCache::Rec {
BitmapKey fKey;
const SkMipMap* fMipMap;
-
+
virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fMipMap->getSize(); }
};
« no previous file with comments | « src/core/SkBitmapCache.h ('k') | tests/SkResourceCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698