Chromium Code Reviews| 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(); } |
| }; |