| Index: src/core/SkBitmapCache.cpp
|
| diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
|
| index dfa387bb3992e351dd5eba4aa1495c075a98ca3d..83eec1b666b7e2b56a2cd233f87ff470274e3add 100644
|
| --- a/src/core/SkBitmapCache.cpp
|
| +++ b/src/core/SkBitmapCache.cpp
|
| @@ -6,6 +6,7 @@
|
| */
|
|
|
| #include "SkBitmapCache.h"
|
| +#include "SkImage.h"
|
| #include "SkResourceCache.h"
|
| #include "SkMipMap.h"
|
| #include "SkPixelRef.h"
|
| @@ -43,6 +44,41 @@ static SkIRect get_bounds_from_bitmap(const SkBitmap& bm) {
|
| return SkIRect::MakeXYWH(origin.fX, origin.fY, bm.width(), bm.height());
|
| }
|
|
|
| +/**
|
| + * This function finds the bounds of the image. Today this is just the entire bounds,
|
| + * but in the future we may support subsets within an image, in which case this should
|
| + * return that subset (see get_bounds_from_bitmap).
|
| + */
|
| +static SkIRect get_bounds_from_image(const SkImage* image) {
|
| + return SkIRect::MakeWH(image->width(), image->height());
|
| +}
|
| +
|
| +SkBitmapCacheDesc SkBitmapCacheDesc::Make(const SkBitmap& bm, int width, int height) {
|
| + SkBitmapCacheDesc desc;
|
| + desc.fImageID = bm.getGenerationID();
|
| + desc.fWidth = width;
|
| + desc.fHeight = height;
|
| + desc.fBounds = get_bounds_from_bitmap(bm);
|
| + return desc;
|
| +}
|
| +
|
| +SkBitmapCacheDesc SkBitmapCacheDesc::Make(const SkBitmap& bm) {
|
| + return Make(bm, bm.width(), bm.height());
|
| +}
|
| +
|
| +SkBitmapCacheDesc SkBitmapCacheDesc::Make(const SkImage* image, int width, int height) {
|
| + SkBitmapCacheDesc desc;
|
| + desc.fImageID = image->uniqueID();
|
| + desc.fWidth = width;
|
| + desc.fHeight = height;
|
| + desc.fBounds = get_bounds_from_image(image);
|
| + return desc;
|
| +}
|
| +
|
| +SkBitmapCacheDesc SkBitmapCacheDesc::Make(const SkImage* image) {
|
| + return Make(image, image->width(), image->height());
|
| +}
|
| +
|
| namespace {
|
| static unsigned gBitmapKeyNamespaceLabel;
|
|
|
| @@ -54,7 +90,17 @@ public:
|
| , fHeight(height)
|
| , fBounds(bounds)
|
| {
|
| - this->init(&gBitmapKeyNamespaceLabel, SkMakeResourceCacheSharedIDForBitmap(genID),
|
| + this->init(&gBitmapKeyNamespaceLabel, SkMakeResourceCacheSharedIDForBitmap(fGenID),
|
| + sizeof(fGenID) + sizeof(fWidth) + sizeof(fHeight) + sizeof(fBounds));
|
| + }
|
| +
|
| + BitmapKey(const SkBitmapCacheDesc& desc)
|
| + : fGenID(desc.fImageID)
|
| + , fWidth(desc.fWidth)
|
| + , fHeight(desc.fHeight)
|
| + , fBounds(desc.fBounds)
|
| + {
|
| + this->init(&gBitmapKeyNamespaceLabel, SkMakeResourceCacheSharedIDForBitmap(fGenID),
|
| sizeof(fGenID) + sizeof(fWidth) + sizeof(fHeight) + sizeof(fBounds));
|
| }
|
|
|
| @@ -80,6 +126,15 @@ struct BitmapRec : public SkResourceCache::Rec {
|
| #endif
|
| }
|
|
|
| + BitmapRec(const SkBitmapCacheDesc& desc, const SkBitmap& result)
|
| + : fKey(desc)
|
| + , fBitmap(result)
|
| + {
|
| +#ifdef TRACE_NEW_BITMAP_CACHE_RECS
|
| + fKey.dump();
|
| +#endif
|
| + }
|
| +
|
| const Key& getKey() const override { return fKey; }
|
| size_t bytesUsed() const override { return sizeof(fKey) + fBitmap.getSize(); }
|
|
|
| @@ -106,28 +161,25 @@ private:
|
| #define CHECK_LOCAL(localCache, localName, globalName, ...) \
|
| ((localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::globalName(__VA_ARGS__))
|
|
|
| -bool SkBitmapCache::FindWH(const SkBitmap& src, int width, int height, SkBitmap* result,
|
| +bool SkBitmapCache::FindWH(const SkBitmapCacheDesc& desc, SkBitmap* result,
|
| SkResourceCache* localCache) {
|
| - if (0 == width || 0 == height) {
|
| - // degenerate, and the key we use for mipmaps
|
| + if (0 == desc.fWidth || 0 == desc.fHeight) {
|
| + // degenerate
|
| return false;
|
| }
|
| - BitmapKey key(src.getGenerationID(), width, height, get_bounds_from_bitmap(src));
|
| -
|
| - return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Finder, result);
|
| + return CHECK_LOCAL(localCache, find, Find, BitmapKey(desc), BitmapRec::Finder, result);
|
| }
|
|
|
| -void SkBitmapCache::AddWH(const SkBitmap& src, int width, int height,
|
| - const SkBitmap& result, SkResourceCache* localCache) {
|
| - if (0 == width || 0 == height) {
|
| +bool SkBitmapCache::AddWH(const SkBitmapCacheDesc& desc, const SkBitmap& result,
|
| + SkResourceCache* localCache) {
|
| + if (0 == desc.fWidth || 0 == desc.fHeight) {
|
| // degenerate, and the key we use for mipmaps
|
| - return;
|
| + return false;
|
| }
|
| SkASSERT(result.isImmutable());
|
| - BitmapRec* rec = new BitmapRec(src.getGenerationID(), width, height,
|
| - get_bounds_from_bitmap(src), result);
|
| + BitmapRec* rec = new BitmapRec(desc, result);
|
| CHECK_LOCAL(localCache, add, Add, rec);
|
| - src.pixelRef()->notifyAddedToCache();
|
| + return true;
|
| }
|
|
|
| bool SkBitmapCache::Find(uint32_t genID, const SkIRect& subset, SkBitmap* result,
|
| @@ -226,8 +278,10 @@ private:
|
| };
|
| }
|
|
|
| -const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src, SkResourceCache* localCache) {
|
| - MipMapKey key(src.getGenerationID(), get_bounds_from_bitmap(src));
|
| +const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmapCacheDesc& desc,
|
| + SkResourceCache* localCache) {
|
| + // Note: we ignore width/height from desc, just need id and bounds
|
| + MipMapKey key(desc.fImageID, desc.fBounds);
|
| const SkMipMap* result;
|
|
|
| if (!CHECK_LOCAL(localCache, find, Find, key, MipMapRec::Finder, &result)) {
|
|
|