rename ScaledImageCache to ResourceCache

BUG=skia:
R=bsalomon@google.com, mtklein@google.com

Author: reed@google.com

Review URL: https://codereview.chromium.org/511283002
diff --git a/bench/ImageCacheBench.cpp b/bench/ImageCacheBench.cpp
index f4d88da..ca2b934 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 @@
         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 @@
 }
 
 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 @@
         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 dc72853..308cc6e 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 93674ef..25c4480 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 e7865ca..a796a67 100644
--- a/include/core/SkGraphics.h
+++ b/include/core/SkGraphics.h
@@ -86,40 +86,53 @@
      *
      *  This function returns the memory usage of the Scaled Image Cache.
      */
-    static size_t GetImageCacheTotalBytesUsed();
-    /**
-     *  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.
-     */
-    static size_t GetImageCacheTotalByteLimit();
-    static size_t SetImageCacheTotalByteLimit(size_t newLimit);
+    static size_t GetResourceCacheTotalBytesUsed();
 
-    // DEPRECATED
+    /**
+     *  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);
+
+    /**
+     *  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 GetResourceCacheSingleAllocationByteLimit();
+    static size_t SetResourceCacheSingleAllocationByteLimit(size_t newLimit);
+
+#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 c0ce0e6..99e2f5c 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 @@
     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 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
-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 @@
 };
 
 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 @@
         // 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 @@
 }
 
 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 @@
 
 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 7640573..52a2ecf 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 @@
     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 @@
                                         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 64dda2e..289e308 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
similarity index 76%
rename from src/core/SkScaledImageCache.cpp
rename to src/core/SkResourceCache.cpp
index 9d15422..7ffdfff 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 @@
 
 #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 @@
 #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 @@
 }
 #endif
 
-void SkScaledImageCache::init() {
+void SkResourceCache::init() {
     fHead = NULL;
     fTail = NULL;
 #ifdef USE_HASH
@@ -142,10 +142,9 @@
     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 @@
     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 @@
     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 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-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 @@
     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 @@
     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 @@
     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::purgeAsNeeded() {
+void SkResourceCache::purgeAsNeeded() {
     size_t byteLimit;
     int    countLimit;
 
@@ -330,7 +328,7 @@
     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 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-void SkScaledImageCache::detach(Rec* rec) {
+void SkResourceCache::detach(Rec* rec) {
     Rec* prev = rec->fPrev;
     Rec* next = rec->fNext;
 
@@ -361,7 +359,7 @@
     rec->fNext = rec->fPrev = NULL;
 }
 
-void SkScaledImageCache::moveToHead(Rec* rec) {
+void SkResourceCache::moveToHead(Rec* rec) {
     if (fHead == rec) {
         return;
     }
@@ -380,7 +378,7 @@
     this->validate();
 }
 
-void SkScaledImageCache::addToHead(Rec* rec) {
+void SkResourceCache::addToHead(Rec* rec) {
     this->validate();
 
     rec->fPrev = NULL;
@@ -401,7 +399,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 #ifdef SK_DEBUG
-void SkScaledImageCache::validate() const {
+void SkResourceCache::validate() const {
     if (NULL == fHead) {
         SkASSERT(NULL == fTail);
         SkASSERT(0 == fTotalBytesUsed);
@@ -445,7 +443,7 @@
 }
 #endif
 
-void SkScaledImageCache::dump() const {
+void SkResourceCache::dump() const {
     this->validate();
 
     const Rec* rec = fHead;
@@ -455,18 +453,18 @@
         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 @@
 #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 @@
 
 #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
similarity index 94%
rename from src/core/SkScaledImageCache.h
rename to src/core/SkResourceCache.h
index c31f8ff..0873bd4 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 @@
  *  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 @@
     };
 
     struct Rec {
-        typedef SkScaledImageCache::Key Key;
+        typedef SkResourceCache::Key Key;
 
         Rec() : fLockCount(1) {}
         virtual ~Rec() {}
@@ -78,7 +78,7 @@
         int32_t fLockCount;
         int32_t fPad;
         
-        friend class SkScaledImageCache;
+        friend class SkResourceCache;
     };
 
     typedef const Rec* ID;
@@ -122,7 +122,7 @@
      *  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 @@
      *  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 e9ee622..65623d0 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 @@
     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 28cda94..bda10a0 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 @@
         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 @@
 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 @@
         // 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 @@
     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 276a3cc..8088d09 100644
--- a/tests/ScaledImageCache.cpp
+++ b/tests/ScaledImageCache.cpp
@@ -41,32 +41,32 @@
 }
 
 // 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);
 }