Index: src/core/SkBitmapCache.cpp |
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp |
index 8de8ab79edac2d8b0224bb3a0e140b81551964cc..a84ab97c4592bcf6f79f6028988088f075587943 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,30 @@ 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_and_return(key, result); |
+ return Find(genID, SkIRect::MakeWH(width, height), result); |
} |
void SkBitmapCache::Add(uint32_t genID, int width, int height, const SkBitmap& result) { |
- SkASSERT(result.isImmutable()); |
- SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1, |
- SkIRect::MakeWH(width, height), result))); |
+ Add(genID, SkIRect::MakeWH(width, height), result); |
+} |
+ |
+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); |
} |
+void SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& result) { |
+ SkASSERT(result.isImmutable()); |
+ |
+ // We need to take only the width and height of 'subset' to compute the intersection |
reed1
2014/09/02 20:38:45
Actually the subset rect is very interesting becau
Rémi Piotaix
2014/09/02 20:48:44
Because the given subset is relative to the origin
|
+ SkIRect localSubset = SkIRect::MakeWH(subset.width(), subset.height()); |
+ SkIRect bitmapBounds = SkIRect::MakeWH(result.width(), result.height()); |
+ |
+ if (localSubset.intersect(bitmapBounds)) { |
+ SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1, |
+ localSubset, result))); |
+ } |
+} |
////////////////////////////////////////////////////////////////////////////////////////// |
struct MipMapRec : public SkResourceCache::Rec { |
@@ -125,7 +139,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(); } |
}; |