aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/ImageCacheBench.cpp16
-rw-r--r--gyp/core.gypi2
-rw-r--r--gyp/skia_for_chromium_defines.gypi1
-rw-r--r--include/core/SkGraphics.h57
-rw-r--r--src/core/SkBitmapCache.cpp27
-rw-r--r--src/core/SkBitmapProcState.cpp26
-rw-r--r--src/core/SkBitmapProcState.h3
-rw-r--r--src/core/SkResourceCache.cpp (renamed from src/core/SkScaledImageCache.cpp)122
-rw-r--r--src/core/SkResourceCache.h (renamed from src/core/SkScaledImageCache.h)16
-rw-r--r--tests/CachedDecodingPixelRefTest.cpp4
-rw-r--r--tests/ImageCacheTest.cpp24
-rw-r--r--tests/ScaledImageCache.cpp28
12 files changed, 155 insertions, 171 deletions
diff --git a/bench/ImageCacheBench.cpp b/bench/ImageCacheBench.cpp
index f4d88da042..ca2b9342d5 100644
--- a/bench/ImageCacheBench.cpp
+++ b/bench/ImageCacheBench.cpp
@@ -6,11 +6,11 @@
*/
#include "Benchmark.h"
-#include "SkScaledImageCache.h"
+#include "SkResourceCache.h"
namespace {
static void* gGlobalAddress;
-class TestKey : public SkScaledImageCache::Key {
+class TestKey : public SkResourceCache::Key {
public:
void* fPtr;
intptr_t fValue;
@@ -19,7 +19,7 @@ public:
this->init(sizeof(fPtr) + sizeof(fValue));
}
};
-struct TestRec : public SkScaledImageCache::Rec {
+struct TestRec : public SkResourceCache::Rec {
TestKey fKey;
intptr_t fValue;
@@ -31,17 +31,13 @@ struct TestRec : public SkScaledImageCache::Rec {
}
class ImageCacheBench : public Benchmark {
- SkScaledImageCache fCache;
- SkBitmap fBM;
+ SkResourceCache fCache;
enum {
- DIM = 1,
CACHE_COUNT = 500
};
public:
- ImageCacheBench() : fCache(CACHE_COUNT * 100) {
- fBM.allocN32Pixels(DIM, DIM);
- }
+ ImageCacheBench() : fCache(CACHE_COUNT * 100) {}
void populateCache() {
for (int i = 0; i < CACHE_COUNT; ++i) {
@@ -62,7 +58,7 @@ protected:
TestKey key(-1);
// search for a miss (-1)
for (int i = 0; i < loops; ++i) {
- SkDEBUGCODE(SkScaledImageCache::ID id =) fCache.findAndLock(key);
+ SkDEBUGCODE(SkResourceCache::ID id =) fCache.findAndLock(key);
SkASSERT(NULL == id);
}
}
diff --git a/gyp/core.gypi b/gyp/core.gypi
index dc72853510..308cc6e8f4 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -167,10 +167,10 @@
'<(skia_src_path)/core/SkRegion.cpp',
'<(skia_src_path)/core/SkRegionPriv.h',
'<(skia_src_path)/core/SkRegion_path.cpp',
+ '<(skia_src_path)/core/SkResourceCache.cpp',
'<(skia_src_path)/core/SkRRect.cpp',
'<(skia_src_path)/core/SkRTree.h',
'<(skia_src_path)/core/SkRTree.cpp',
- '<(skia_src_path)/core/SkScaledImageCache.cpp',
'<(skia_src_path)/core/SkScalar.cpp',
'<(skia_src_path)/core/SkScalerContext.cpp',
'<(skia_src_path)/core/SkScalerContext.h',
diff --git a/gyp/skia_for_chromium_defines.gypi b/gyp/skia_for_chromium_defines.gypi
index 93674ef8f5..25c44804df 100644
--- a/gyp/skia_for_chromium_defines.gypi
+++ b/gyp/skia_for_chromium_defines.gypi
@@ -17,6 +17,7 @@
'SK_SUPPORT_LEGACY_GETDEVICE',
'SK_IGNORE_ETC1_SUPPORT',
'SK_IGNORE_GPU_DITHER',
+ 'SK_SUPPORT_LEGACY_IMAGECACHE_NAME',
],
},
}
diff --git a/include/core/SkGraphics.h b/include/core/SkGraphics.h
index e7865ca5af..a796a671e7 100644
--- a/include/core/SkGraphics.h
+++ b/include/core/SkGraphics.h
@@ -86,40 +86,53 @@ public:
*
* This function returns the memory usage of the Scaled Image Cache.
*/
- static size_t GetImageCacheTotalBytesUsed();
+ static size_t GetResourceCacheTotalBytesUsed();
+
+ /**
+ * These functions get/set the memory usage limit for the resource cache, used for temporary
+ * bitmaps and other resources. Entries are purged from the cache when the memory useage
+ * exceeds this limit.
+ */
+ static size_t GetResourceCacheTotalByteLimit();
+ static size_t SetResourceCacheTotalByteLimit(size_t newLimit);
+
/**
- * These functions get/set the memory usage limit for the Scaled
- * Image Cache. Bitmaps are purged from the cache when the
- * memory useage exceeds this limit.
+ * When the cachable entry is very lage (e.g. a large scaled bitmap), adding it to the cache
+ * can cause most/all of the existing entries to be purged. To avoid the, the client can set
+ * a limit for a single allocation. If a cacheable entry would have been cached, but its size
+ * exceeds this limit, then we do not attempt to cache it at all.
+ *
+ * Zero is the default value, meaning we always attempt to cache entries.
*/
- static size_t GetImageCacheTotalByteLimit();
- static size_t SetImageCacheTotalByteLimit(size_t newLimit);
+ static size_t GetResourceCacheSingleAllocationByteLimit();
+ static size_t SetResourceCacheSingleAllocationByteLimit(size_t newLimit);
- // DEPRECATED
+#ifdef SK_SUPPORT_LEGACY_IMAGECACHE_NAME
static size_t GetImageCacheBytesUsed() {
return GetImageCacheTotalBytesUsed();
}
- // DEPRECATED
static size_t GetImageCacheByteLimit() {
return GetImageCacheTotalByteLimit();
}
- // DEPRECATED
static size_t SetImageCacheByteLimit(size_t newLimit) {
return SetImageCacheTotalByteLimit(newLimit);
}
-
- /**
- * Scaling bitmaps with the SkPaint::kHigh_FilterLevel setting is
- * expensive, so the result is saved in the global Scaled Image
- * Cache. When the resulting bitmap is too large, this can
- * overload the cache. If the ImageCacheSingleAllocationByteLimit
- * is set to a non-zero number, and the resulting bitmap would be
- * larger than that value, the bitmap scaling algorithm falls
- * back onto a cheaper algorithm and does not cache the result.
- * Zero is the default value.
- */
- static size_t GetImageCacheSingleAllocationByteLimit();
- static size_t SetImageCacheSingleAllocationByteLimit(size_t newLimit);
+ static size_t GetImageCacheTotalBytesUsed() {
+ return GetResourceCacheTotalBytesUsed();
+ }
+ static size_t GetImageCacheTotalByteLimit() {
+ return GetResourceCacheTotalByteLimit();
+ }
+ static size_t SetImageCacheTotalByteLimit(size_t newLimit) {
+ return SetResourceCacheTotalByteLimit(newLimit);
+ }
+ static size_t GetImageCacheSingleAllocationByteLimit() {
+ return GetResourceCacheSingleAllocationByteLimit();
+ }
+ static size_t SetImageCacheSingleAllocationByteLimit(size_t newLimit) {
+ return SetResourceCacheSingleAllocationByteLimit(newLimit);
+ }
+#endif
/**
* Applications with command line options may pass optional state, such
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
index c0ce0e6369..99e2f5c503 100644
--- a/src/core/SkBitmapCache.cpp
+++ b/src/core/SkBitmapCache.cpp
@@ -6,7 +6,7 @@
*/
#include "SkBitmapCache.h"
-#include "SkScaledImageCache.h"
+#include "SkResourceCache.h"
#include "SkMipMap.h"
#include "SkRect.h"
@@ -24,7 +24,7 @@ static SkIRect get_bounds_from_bitmap(const SkBitmap& bm) {
return SkIRect::MakeXYWH(origin.fX, origin.fY, bm.width(), bm.height());
}
-struct BitmapKey : public SkScaledImageCache::Key {
+struct BitmapKey : public SkResourceCache::Key {
public:
BitmapKey(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& bounds)
: fGenID(genID)
@@ -43,7 +43,7 @@ public:
//////////////////////////////////////////////////////////////////////////////////////////
-struct BitmapRec : public SkScaledImageCache::Rec {
+struct BitmapRec : public SkResourceCache::Rec {
BitmapRec(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& bounds,
const SkBitmap& result)
: fKey(genID, scaleX, scaleY, bounds)
@@ -58,10 +58,10 @@ struct BitmapRec : public SkScaledImageCache::Rec {
};
static bool find_and_return(const BitmapKey& key, SkBitmap* result) {
- const BitmapRec* rec = (BitmapRec*)SkScaledImageCache::FindAndLock(key);
+ const BitmapRec* rec = (BitmapRec*)SkResourceCache::FindAndLock(key);
if (rec) {
*result = rec->fBitmap;
- SkScaledImageCache::Unlock(rec);
+ SkResourceCache::Unlock(rec);
result->lockPixels();
if (result->getPixels()) {
@@ -91,9 +91,8 @@ void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca
// degenerate, and the key we use for mipmaps
return;
}
- SkScaledImageCache::Add(SkNEW_ARGS(BitmapRec,
- (src.getGenerationID(), invScaleX, invScaleY,
- get_bounds_from_bitmap(src), result)));
+ SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX, invScaleY,
+ get_bounds_from_bitmap(src), result)));
}
bool SkBitmapCache::Find(uint32_t genID, int width, int height, SkBitmap* result) {
@@ -102,13 +101,13 @@ bool SkBitmapCache::Find(uint32_t genID, int width, int height, SkBitmap* result
}
void SkBitmapCache::Add(uint32_t genID, int width, int height, const SkBitmap& result) {
- SkScaledImageCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1,
- SkIRect::MakeWH(width, height), result)));
+ SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1,
+ SkIRect::MakeWH(width, height), result)));
}
//////////////////////////////////////////////////////////////////////////////////////////
-struct MipMapRec : public SkScaledImageCache::Rec {
+struct MipMapRec : public SkResourceCache::Rec {
MipMapRec(const SkBitmap& src, const SkMipMap* result)
: fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src))
, fMipMap(SkRef(result))
@@ -128,18 +127,18 @@ struct MipMapRec : public SkScaledImageCache::Rec {
const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src) {
BitmapKey key(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src));
- const MipMapRec* rec = (MipMapRec*)SkScaledImageCache::FindAndLock(key);
+ const MipMapRec* rec = (MipMapRec*)SkResourceCache::FindAndLock(key);
const SkMipMap* result = NULL;
if (rec) {
result = SkRef(rec->fMipMap);
- SkScaledImageCache::Unlock(rec);
+ SkResourceCache::Unlock(rec);
}
return result;
}
void SkMipMapCache::Add(const SkBitmap& src, const SkMipMap* result) {
if (result) {
- SkScaledImageCache::Add(SkNEW_ARGS(MipMapRec, (src, result)));
+ SkResourceCache::Add(SkNEW_ARGS(MipMapRec, (src, result)));
}
}
diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp
index 7640573596..52a2ecf25c 100644
--- a/src/core/SkBitmapProcState.cpp
+++ b/src/core/SkBitmapProcState.cpp
@@ -16,6 +16,7 @@
#include "SkMipMap.h"
#include "SkPixelRef.h"
#include "SkImageEncoder.h"
+#include "SkResourceCache.h"
#if !SK_ARM_NEON_IS_NONE
// These are defined in src/opts/SkBitmapProcState_arm_neon.cpp
@@ -107,31 +108,10 @@ static SkScalar effective_matrix_scale_sqrd(const SkMatrix& mat) {
return SkMaxScalar(v1.lengthSqd(), v2.lengthSqd());
}
-class AutoScaledCacheUnlocker {
-public:
- AutoScaledCacheUnlocker(SkScaledImageCache::ID* idPtr) : fIDPtr(idPtr) {}
- ~AutoScaledCacheUnlocker() {
- if (fIDPtr && *fIDPtr) {
- SkScaledImageCache::Unlock(*fIDPtr);
- *fIDPtr = NULL;
- }
- }
-
- // forgets the ID, so it won't call Unlock
- void release() {
- fIDPtr = NULL;
- }
-
-private:
- SkScaledImageCache::ID* fIDPtr;
-};
-#define AutoScaledCacheUnlocker(...) SK_REQUIRE_LOCAL_VAR(AutoScaledCacheUnlocker)
-
// Check to see that the size of the bitmap that would be produced by
// scaling by the given inverted matrix is less than the maximum allowed.
static inline bool cache_size_okay(const SkBitmap& bm, const SkMatrix& invMat) {
- size_t maximumAllocation
- = SkScaledImageCache::GetSingleAllocationByteLimit();
+ size_t maximumAllocation = SkResourceCache::GetSingleAllocationByteLimit();
if (0 == maximumAllocation) {
return true;
}
@@ -191,7 +171,7 @@ bool SkBitmapProcState::possiblyScaleImage() {
SkBitmapScaler::RESIZE_BEST,
dest_width,
dest_height,
- SkScaledImageCache::GetAllocator())) {
+ SkResourceCache::GetAllocator())) {
// we failed to create fScaledBitmap, so just return and let
// the scanline proc handle it.
return false;
diff --git a/src/core/SkBitmapProcState.h b/src/core/SkBitmapProcState.h
index 64dda2ecb3..289e308eed 100644
--- a/src/core/SkBitmapProcState.h
+++ b/src/core/SkBitmapProcState.h
@@ -1,4 +1,3 @@
-
/*
* Copyright 2007 The Android Open Source Project
*
@@ -6,7 +5,6 @@
* found in the LICENSE file.
*/
-
#ifndef SkBitmapProcState_DEFINED
#define SkBitmapProcState_DEFINED
@@ -15,7 +13,6 @@
#include "SkMatrix.h"
#include "SkMipMap.h"
#include "SkPaint.h"
-#include "SkScaledImageCache.h"
#define FractionalInt_IS_64BIT
diff --git a/src/core/SkScaledImageCache.cpp b/src/core/SkResourceCache.cpp
index 9d15422300..7ffdfffbaf 100644
--- a/src/core/SkScaledImageCache.cpp
+++ b/src/core/SkResourceCache.cpp
@@ -6,7 +6,7 @@
*/
#include "SkChecksum.h"
-#include "SkScaledImageCache.h"
+#include "SkResourceCache.h"
#include "SkMipMap.h"
#include "SkPixelRef.h"
@@ -21,7 +21,7 @@
#define SK_DEFAULT_IMAGE_CACHE_LIMIT (2 * 1024 * 1024)
#endif
-void SkScaledImageCache::Key::init(size_t length) {
+void SkResourceCache::Key::init(size_t length) {
SkASSERT(SkAlign4(length) == length);
// 2 is fCount32 and fHash
fCount32 = SkToS32(2 + (length >> 2));
@@ -31,8 +31,8 @@ void SkScaledImageCache::Key::init(size_t length) {
#include "SkTDynamicHash.h"
-class SkScaledImageCache::Hash :
- public SkTDynamicHash<SkScaledImageCache::Rec, SkScaledImageCache::Key> {};
+class SkResourceCache::Hash :
+ public SkTDynamicHash<SkResourceCache::Rec, SkResourceCache::Key> {};
///////////////////////////////////////////////////////////////////////////////
@@ -41,9 +41,9 @@ class SkScaledImageCache::Hash :
#define USE_HASH
#if !defined(USE_HASH)
-static inline SkScaledImageCache::Rec* find_rec_in_list(
- SkScaledImageCache::Rec* head, const Key & key) {
- SkScaledImageCache::Rec* rec = head;
+static inline SkResourceCache::Rec* find_rec_in_list(
+ SkResourceCache::Rec* head, const Key & key) {
+ SkResourceCache::Rec* rec = head;
while ((rec != NULL) && (rec->fKey != key)) {
rec = rec->fNext;
}
@@ -51,7 +51,7 @@ static inline SkScaledImageCache::Rec* find_rec_in_list(
}
#endif
-void SkScaledImageCache::init() {
+void SkResourceCache::init() {
fHead = NULL;
fTail = NULL;
#ifdef USE_HASH
@@ -142,10 +142,9 @@ size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const {
return this->info().getSafeSize(fRB);
}
-class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator {
+class SkResourceCacheDiscardableAllocator : public SkBitmap::Allocator {
public:
- SkScaledImageCacheDiscardableAllocator(
- SkScaledImageCache::DiscardableFactory factory) {
+ SkResourceCacheDiscardableAllocator(SkResourceCache::DiscardableFactory factory) {
SkASSERT(factory);
fFactory = factory;
}
@@ -153,11 +152,10 @@ public:
virtual bool allocPixelRef(SkBitmap*, SkColorTable*) SK_OVERRIDE;
private:
- SkScaledImageCache::DiscardableFactory fFactory;
+ SkResourceCache::DiscardableFactory fFactory;
};
-bool SkScaledImageCacheDiscardableAllocator::allocPixelRef(SkBitmap* bitmap,
- SkColorTable* ctable) {
+bool SkResourceCacheDiscardableAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
size_t size = bitmap->getSize();
uint64_t size64 = bitmap->computeSize64();
if (0 == size || size64 > (uint64_t)size) {
@@ -181,19 +179,19 @@ bool SkScaledImageCacheDiscardableAllocator::allocPixelRef(SkBitmap* bitmap,
return bitmap->readyToDraw();
}
-SkScaledImageCache::SkScaledImageCache(DiscardableFactory factory) {
+SkResourceCache::SkResourceCache(DiscardableFactory factory) {
this->init();
fDiscardableFactory = factory;
- fAllocator = SkNEW_ARGS(SkScaledImageCacheDiscardableAllocator, (factory));
+ fAllocator = SkNEW_ARGS(SkResourceCacheDiscardableAllocator, (factory));
}
-SkScaledImageCache::SkScaledImageCache(size_t byteLimit) {
+SkResourceCache::SkResourceCache(size_t byteLimit) {
this->init();
fTotalByteLimit = byteLimit;
}
-SkScaledImageCache::~SkScaledImageCache() {
+SkResourceCache::~SkResourceCache() {
SkSafeUnref(fAllocator);
Rec* rec = fHead;
@@ -207,7 +205,7 @@ SkScaledImageCache::~SkScaledImageCache() {
////////////////////////////////////////////////////////////////////////////////
-const SkScaledImageCache::Rec* SkScaledImageCache::findAndLock(const Key& key) {
+const SkResourceCache::Rec* SkResourceCache::findAndLock(const Key& key) {
#ifdef USE_HASH
Rec* rec = fHash->find(key);
#else
@@ -220,7 +218,7 @@ const SkScaledImageCache::Rec* SkScaledImageCache::findAndLock(const Key& key) {
return rec;
}
-const SkScaledImageCache::Rec* SkScaledImageCache::addAndLock(Rec* rec) {
+const SkResourceCache::Rec* SkResourceCache::addAndLock(Rec* rec) {
SkASSERT(rec);
// See if we already have this key (racy inserts, etc.)
const Rec* existing = this->findAndLock(rec->getKey());
@@ -240,7 +238,7 @@ const SkScaledImageCache::Rec* SkScaledImageCache::addAndLock(Rec* rec) {
return rec;
}
-void SkScaledImageCache::add(Rec* rec) {
+void SkResourceCache::add(Rec* rec) {
SkASSERT(rec);
// See if we already have this key (racy inserts, etc.)
const Rec* existing = this->findAndLock(rec->getKey());
@@ -259,7 +257,7 @@ void SkScaledImageCache::add(Rec* rec) {
this->unlock(rec);
}
-void SkScaledImageCache::unlock(SkScaledImageCache::ID id) {
+void SkResourceCache::unlock(SkResourceCache::ID id) {
SkASSERT(id);
#ifdef SK_DEBUG
@@ -288,7 +286,7 @@ void SkScaledImageCache::unlock(SkScaledImageCache::ID id) {
}
}
-void SkScaledImageCache::purgeAsNeeded() {
+void SkResourceCache::purgeAsNeeded() {
size_t byteLimit;
int countLimit;
@@ -330,7 +328,7 @@ void SkScaledImageCache::purgeAsNeeded() {
fCount = countUsed;
}
-size_t SkScaledImageCache::setTotalByteLimit(size_t newLimit) {
+size_t SkResourceCache::setTotalByteLimit(size_t newLimit) {
size_t prevLimit = fTotalByteLimit;
fTotalByteLimit = newLimit;
if (newLimit < prevLimit) {
@@ -341,7 +339,7 @@ size_t SkScaledImageCache::setTotalByteLimit(size_t newLimit) {
///////////////////////////////////////////////////////////////////////////////
-void SkScaledImageCache::detach(Rec* rec) {
+void SkResourceCache::detach(Rec* rec) {
Rec* prev = rec->fPrev;
Rec* next = rec->fNext;
@@ -361,7 +359,7 @@ void SkScaledImageCache::detach(Rec* rec) {
rec->fNext = rec->fPrev = NULL;
}
-void SkScaledImageCache::moveToHead(Rec* rec) {
+void SkResourceCache::moveToHead(Rec* rec) {
if (fHead == rec) {
return;
}
@@ -380,7 +378,7 @@ void SkScaledImageCache::moveToHead(Rec* rec) {
this->validate();
}
-void SkScaledImageCache::addToHead(Rec* rec) {
+void SkResourceCache::addToHead(Rec* rec) {
this->validate();
rec->fPrev = NULL;
@@ -401,7 +399,7 @@ void SkScaledImageCache::addToHead(Rec* rec) {
///////////////////////////////////////////////////////////////////////////////
#ifdef SK_DEBUG
-void SkScaledImageCache::validate() const {
+void SkResourceCache::validate() const {
if (NULL == fHead) {
SkASSERT(NULL == fTail);
SkASSERT(0 == fTotalBytesUsed);
@@ -445,7 +443,7 @@ void SkScaledImageCache::validate() const {
}
#endif
-void SkScaledImageCache::dump() const {
+void SkResourceCache::dump() const {
this->validate();
const Rec* rec = fHead;
@@ -455,18 +453,18 @@ void SkScaledImageCache::dump() const {
rec = rec->fNext;
}
- SkDebugf("SkScaledImageCache: count=%d bytes=%d locked=%d %s\n",
+ SkDebugf("SkResourceCache: count=%d bytes=%d locked=%d %s\n",
fCount, fTotalBytesUsed, locked,
fDiscardableFactory ? "discardable" : "malloc");
}
-size_t SkScaledImageCache::setSingleAllocationByteLimit(size_t newLimit) {
+size_t SkResourceCache::setSingleAllocationByteLimit(size_t newLimit) {
size_t oldLimit = fSingleAllocationByteLimit;
fSingleAllocationByteLimit = newLimit;
return oldLimit;
}
-size_t SkScaledImageCache::getSingleAllocationByteLimit() const {
+size_t SkResourceCache::getSingleAllocationByteLimit() const {
return fSingleAllocationByteLimit;
}
@@ -475,85 +473,85 @@ size_t SkScaledImageCache::getSingleAllocationByteLimit() const {
#include "SkThread.h"
SK_DECLARE_STATIC_MUTEX(gMutex);
-static SkScaledImageCache* gScaledImageCache = NULL;
-static void cleanup_gScaledImageCache() {
+static SkResourceCache* gResourceCache = NULL;
+static void cleanup_gResourceCache() {
// We'll clean this up in our own tests, but disable for clients.
// Chrome seems to have funky multi-process things going on in unit tests that
// makes this unsafe to delete when the main process atexit()s.
// SkLazyPtr does the same sort of thing.
#if SK_DEVELOPER
- SkDELETE(gScaledImageCache);
+ SkDELETE(gResourceCache);
#endif
}
/** Must hold gMutex when calling. */
-static SkScaledImageCache* get_cache() {
+static SkResourceCache* get_cache() {
// gMutex is always held when this is called, so we don't need to be fancy in here.
gMutex.assertHeld();
- if (NULL == gScaledImageCache) {
+ if (NULL == gResourceCache) {
#ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE
- gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SkDiscardableMemory::Create));
+ gResourceCache = SkNEW_ARGS(SkResourceCache, (SkDiscardableMemory::Create));
#else
- gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SK_DEFAULT_IMAGE_CACHE_LIMIT));
+ gResourceCache = SkNEW_ARGS(SkResourceCache, (SK_DEFAULT_IMAGE_CACHE_LIMIT));
#endif
- atexit(cleanup_gScaledImageCache);
+ atexit(cleanup_gResourceCache);
}
- return gScaledImageCache;
+ return gResourceCache;
}
-void SkScaledImageCache::Unlock(SkScaledImageCache::ID id) {
+void SkResourceCache::Unlock(SkResourceCache::ID id) {
SkAutoMutexAcquire am(gMutex);
get_cache()->unlock(id);
// get_cache()->dump();
}
-size_t SkScaledImageCache::GetTotalBytesUsed() {
+size_t SkResourceCache::GetTotalBytesUsed() {
SkAutoMutexAcquire am(gMutex);
return get_cache()->getTotalBytesUsed();
}
-size_t SkScaledImageCache::GetTotalByteLimit() {
+size_t SkResourceCache::GetTotalByteLimit() {
SkAutoMutexAcquire am(gMutex);
return get_cache()->getTotalByteLimit();
}
-size_t SkScaledImageCache::SetTotalByteLimit(size_t newLimit) {
+size_t SkResourceCache::SetTotalByteLimit(size_t newLimit) {
SkAutoMutexAcquire am(gMutex);
return get_cache()->setTotalByteLimit(newLimit);
}
-SkBitmap::Allocator* SkScaledImageCache::GetAllocator() {
+SkBitmap::Allocator* SkResourceCache::GetAllocator() {
SkAutoMutexAcquire am(gMutex);
return get_cache()->allocator();
}
-void SkScaledImageCache::Dump() {
+void SkResourceCache::Dump() {
SkAutoMutexAcquire am(gMutex);
get_cache()->dump();
}
-size_t SkScaledImageCache::SetSingleAllocationByteLimit(size_t size) {
+size_t SkResourceCache::SetSingleAllocationByteLimit(size_t size) {
SkAutoMutexAcquire am(gMutex);
return get_cache()->setSingleAllocationByteLimit(size);
}
-size_t SkScaledImageCache::GetSingleAllocationByteLimit() {
+size_t SkResourceCache::GetSingleAllocationByteLimit() {
SkAutoMutexAcquire am(gMutex);
return get_cache()->getSingleAllocationByteLimit();
}
-const SkScaledImageCache::Rec* SkScaledImageCache::FindAndLock(const Key& key) {
+const SkResourceCache::Rec* SkResourceCache::FindAndLock(const Key& key) {
SkAutoMutexAcquire am(gMutex);
return get_cache()->findAndLock(key);
}
-const SkScaledImageCache::Rec* SkScaledImageCache::AddAndLock(Rec* rec) {
+const SkResourceCache::Rec* SkResourceCache::AddAndLock(Rec* rec) {
SkAutoMutexAcquire am(gMutex);
return get_cache()->addAndLock(rec);
}
-void SkScaledImageCache::Add(Rec* rec) {
+void SkResourceCache::Add(Rec* rec) {
SkAutoMutexAcquire am(gMutex);
get_cache()->add(rec);
}
@@ -562,23 +560,23 @@ void SkScaledImageCache::Add(Rec* rec) {
#include "SkGraphics.h"
-size_t SkGraphics::GetImageCacheTotalBytesUsed() {
- return SkScaledImageCache::GetTotalBytesUsed();
+size_t SkGraphics::GetResourceCacheTotalBytesUsed() {
+ return SkResourceCache::GetTotalBytesUsed();
}
-size_t SkGraphics::GetImageCacheTotalByteLimit() {
- return SkScaledImageCache::GetTotalByteLimit();
+size_t SkGraphics::GetResourceCacheTotalByteLimit() {
+ return SkResourceCache::GetTotalByteLimit();
}
-size_t SkGraphics::SetImageCacheTotalByteLimit(size_t newLimit) {
- return SkScaledImageCache::SetTotalByteLimit(newLimit);
+size_t SkGraphics::SetResourceCacheTotalByteLimit(size_t newLimit) {
+ return SkResourceCache::SetTotalByteLimit(newLimit);
}
-size_t SkGraphics::GetImageCacheSingleAllocationByteLimit() {
- return SkScaledImageCache::GetSingleAllocationByteLimit();
+size_t SkGraphics::GetResourceCacheSingleAllocationByteLimit() {
+ return SkResourceCache::GetSingleAllocationByteLimit();
}
-size_t SkGraphics::SetImageCacheSingleAllocationByteLimit(size_t newLimit) {
- return SkScaledImageCache::SetSingleAllocationByteLimit(newLimit);
+size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) {
+ return SkResourceCache::SetSingleAllocationByteLimit(newLimit);
}
diff --git a/src/core/SkScaledImageCache.h b/src/core/SkResourceCache.h
index c31f8ffed9..0873bd4c2e 100644
--- a/src/core/SkScaledImageCache.h
+++ b/src/core/SkResourceCache.h
@@ -5,8 +5,8 @@
* found in the LICENSE file.
*/
-#ifndef SkScaledImageCache_DEFINED
-#define SkScaledImageCache_DEFINED
+#ifndef SkResourceCache_DEFINED
+#define SkResourceCache_DEFINED
#include "SkBitmap.h"
@@ -23,7 +23,7 @@ class SkMipMap;
* As a convenience, a global instance is also defined, which can be safely
* access across threads via the static methods (e.g. FindAndLock, etc.).
*/
-class SkScaledImageCache {
+class SkResourceCache {
public:
struct Key {
// Call this to access your private contents. Must not use the address after calling init()
@@ -58,7 +58,7 @@ public:
};
struct Rec {
- typedef SkScaledImageCache::Key Key;
+ typedef SkResourceCache::Key Key;
Rec() : fLockCount(1) {}
virtual ~Rec() {}
@@ -78,7 +78,7 @@ public:
int32_t fLockCount;
int32_t fPad;
- friend class SkScaledImageCache;
+ friend class SkResourceCache;
};
typedef const Rec* ID;
@@ -122,7 +122,7 @@ public:
* and getTotalByteLimit() will return 0, and setTotalByteLimit
* will ignore its argument and return 0.
*/
- SkScaledImageCache(DiscardableFactory);
+ SkResourceCache(DiscardableFactory);
/**
* Construct the cache, allocating memory with malloc, and respect the
@@ -130,8 +130,8 @@ public:
* that pushes the total bytesUsed over the limit. Note: The limit can be
* changed at runtime with setTotalByteLimit.
*/
- explicit SkScaledImageCache(size_t byteLimit);
- ~SkScaledImageCache();
+ explicit SkResourceCache(size_t byteLimit);
+ ~SkResourceCache();
const Rec* findAndLock(const Key& key);
const Rec* addAndLock(Rec*);
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp
index e9ee622764..65623d0e4f 100644
--- a/tests/CachedDecodingPixelRefTest.cpp
+++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -13,7 +13,7 @@
#include "SkDiscardableMemoryPool.h"
#include "SkImageDecoder.h"
#include "SkImageGeneratorPriv.h"
-#include "SkScaledImageCache.h"
+#include "SkResourceCache.h"
#include "SkStream.h"
#include "SkUtils.h"
@@ -257,7 +257,7 @@ static void check_pixelref(TestImageGenerator::TestType type,
SkBitmap lazy;
bool success;
if (kSkCaching_PixelRefType == pixelRefType) {
- // Ignore factory; use global SkScaledImageCache.
+ // Ignore factory; use global cache.
success = SkCachingPixelRef::Install(gen.detach(), &lazy);
} else {
success = SkInstallDiscardablePixelRef(gen.detach(), &lazy, factory);
diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp
index 28cda94000..bda10a040a 100644
--- a/tests/ImageCacheTest.cpp
+++ b/tests/ImageCacheTest.cpp
@@ -6,12 +6,12 @@
*/
#include "SkDiscardableMemory.h"
-#include "SkScaledImageCache.h"
+#include "SkResourceCache.h"
#include "Test.h"
namespace {
static void* gGlobalAddress;
-struct TestingKey : public SkScaledImageCache::Key {
+struct TestingKey : public SkResourceCache::Key {
void* fPtr;
intptr_t fValue;
@@ -19,7 +19,7 @@ struct TestingKey : public SkScaledImageCache::Key {
this->init(sizeof(fPtr) + sizeof(fValue));
}
};
-struct TestingRec : public SkScaledImageCache::Rec {
+struct TestingRec : public SkResourceCache::Rec {
TestingRec(const TestingKey& key, uint32_t value) : fKey(key), fValue(value) {}
TestingKey fKey;
@@ -33,9 +33,9 @@ struct TestingRec : public SkScaledImageCache::Rec {
static const int COUNT = 10;
static const int DIM = 256;
-static void test_cache(skiatest::Reporter* reporter, SkScaledImageCache& cache,
+static void test_cache(skiatest::Reporter* reporter, SkResourceCache& cache,
bool testPurge) {
- SkScaledImageCache::ID id;
+ SkResourceCache::ID id;
for (int i = 0; i < COUNT; ++i) {
TestingKey key(i);
@@ -58,7 +58,7 @@ static void test_cache(skiatest::Reporter* reporter, SkScaledImageCache& cache,
// stress test, should trigger purges
for (size_t i = 0; i < COUNT * 100; ++i) {
TestingKey key(i);
- SkScaledImageCache::ID id = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, i)));
+ SkResourceCache::ID id = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, i)));
REPORTER_ASSERT(reporter, NULL != id);
cache.unlock(id);
}
@@ -87,30 +87,30 @@ DEF_TEST(ImageCache, reporter) {
static const size_t defLimit = DIM * DIM * 4 * COUNT + 1024; // 1K slop
{
- SkScaledImageCache cache(defLimit);
+ SkResourceCache cache(defLimit);
test_cache(reporter, cache, true);
}
{
SkAutoTUnref<SkDiscardableMemoryPool> pool(
SkDiscardableMemoryPool::Create(defLimit, NULL));
gPool = pool.get();
- SkScaledImageCache cache(pool_factory);
+ SkResourceCache cache(pool_factory);
test_cache(reporter, cache, true);
}
{
- SkScaledImageCache cache(SkDiscardableMemory::Create);
+ SkResourceCache cache(SkDiscardableMemory::Create);
test_cache(reporter, cache, false);
}
}
DEF_TEST(ImageCache_doubleAdd, r) {
// Adding the same key twice should be safe.
- SkScaledImageCache cache(4096);
+ SkResourceCache cache(4096);
TestingKey key(1);
- SkScaledImageCache::ID id1 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 2)));
- SkScaledImageCache::ID id2 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 3)));
+ SkResourceCache::ID id1 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 2)));
+ SkResourceCache::ID id2 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 3)));
// We don't really care if id1 == id2 as long as unlocking both works.
cache.unlock(id1);
cache.unlock(id2);
diff --git a/tests/ScaledImageCache.cpp b/tests/ScaledImageCache.cpp
index 276a3cc17a..8088d093d3 100644
--- a/tests/ScaledImageCache.cpp
+++ b/tests/ScaledImageCache.cpp
@@ -41,32 +41,32 @@ static bool test_scaled_image_cache_useage() {
}
// http://crbug.com/389439
-DEF_TEST(ScaledImageCache_SingleAllocationByteLimit, reporter) {
- size_t originalByteLimit = SkGraphics::GetImageCacheTotalByteLimit();
+DEF_TEST(ResourceCache_SingleAllocationByteLimit, reporter) {
+ size_t originalByteLimit = SkGraphics::GetResourceCacheTotalByteLimit();
size_t originalAllocationLimit =
- SkGraphics::GetImageCacheSingleAllocationByteLimit();
+ SkGraphics::GetResourceCacheSingleAllocationByteLimit();
size_t size = kBitmapSize * kScale * kBitmapSize * kScale
* SkColorTypeBytesPerPixel(kN32_SkColorType);
- SkGraphics::SetImageCacheTotalByteLimit(0); // clear cache
- SkGraphics::SetImageCacheTotalByteLimit(2 * size);
- SkGraphics::SetImageCacheSingleAllocationByteLimit(0); // No limit
+ SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache
+ SkGraphics::SetResourceCacheTotalByteLimit(2 * size);
+ SkGraphics::SetResourceCacheSingleAllocationByteLimit(0); // No limit
REPORTER_ASSERT(reporter, test_scaled_image_cache_useage());
- SkGraphics::SetImageCacheTotalByteLimit(0); // clear cache
- SkGraphics::SetImageCacheTotalByteLimit(2 * size);
- SkGraphics::SetImageCacheSingleAllocationByteLimit(size * 2); // big enough
+ SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache
+ SkGraphics::SetResourceCacheTotalByteLimit(2 * size);
+ SkGraphics::SetResourceCacheSingleAllocationByteLimit(size * 2); // big enough
REPORTER_ASSERT(reporter, test_scaled_image_cache_useage());
- SkGraphics::SetImageCacheTotalByteLimit(0); // clear cache
- SkGraphics::SetImageCacheTotalByteLimit(2 * size);
- SkGraphics::SetImageCacheSingleAllocationByteLimit(size / 2); // too small
+ SkGraphics::SetResourceCacheTotalByteLimit(0); // clear cache
+ SkGraphics::SetResourceCacheTotalByteLimit(2 * size);
+ SkGraphics::SetResourceCacheSingleAllocationByteLimit(size / 2); // too small
REPORTER_ASSERT(reporter, !test_scaled_image_cache_useage());
- SkGraphics::SetImageCacheSingleAllocationByteLimit(originalAllocationLimit);
- SkGraphics::SetImageCacheTotalByteLimit(originalByteLimit);
+ SkGraphics::SetResourceCacheSingleAllocationByteLimit(originalAllocationLimit);
+ SkGraphics::SetResourceCacheTotalByteLimit(originalByteLimit);
}