aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkScaledImageCache.h
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-09 22:29:30 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-09 22:29:30 +0000
commite4eb122a61d7c29f1dd979a41d90524fd249db3f (patch)
tree6897bcca0f1b470d435f70f54cdd8c04a2bc29c4 /src/core/SkScaledImageCache.h
parentf309dbcf2a8084afc44774a675c68756993acbc3 (diff)
support scaledimagecache instantiable using discardablememory
Add this to your build/gyp system to use discardable instead of malloc+budget #define SK_USE_DISCARDABLE_SCALEDIMAGECACHE R=halcanary@google.com Review URL: https://codereview.chromium.org/105933003 git-svn-id: http://skia.googlecode.com/svn/trunk@12588 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkScaledImageCache.h')
-rw-r--r--src/core/SkScaledImageCache.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/core/SkScaledImageCache.h b/src/core/SkScaledImageCache.h
index 44ef1f8a2c..311db325be 100644
--- a/src/core/SkScaledImageCache.h
+++ b/src/core/SkScaledImageCache.h
@@ -10,6 +10,7 @@
#include "SkBitmap.h"
+class SkDiscardableMemory;
class SkMipMap;
/**
@@ -26,6 +27,12 @@ class SkScaledImageCache {
public:
struct ID;
+ /**
+ * Returns a locked/pinned SkDiscardableMemory instance for the specified
+ * number of bytes, or NULL on failure.
+ */
+ typedef SkDiscardableMemory* (*DiscardableFactory)(size_t bytes);
+
/*
* The following static methods are thread-safe wrappers around a global
* instance of this cache.
@@ -57,9 +64,27 @@ public:
static size_t GetByteLimit();
static size_t SetByteLimit(size_t newLimit);
+ static SkBitmap::Allocator* GetAllocator();
+
///////////////////////////////////////////////////////////////////////////
+ /**
+ * Construct the cache to call DiscardableFactory when it
+ * allocates memory for the pixels. In this mode, the cache has
+ * not explicit budget, and so methods like getBytesUsed() and
+ * getByteLimit() will return 0, and setByteLimit will ignore its argument
+ * and return 0.
+ */
+ SkScaledImageCache(DiscardableFactory);
+
+ /**
+ * Construct the cache, allocating memory with malloc, and respect the
+ * byteLimit, purging automatically when a new image is added to the cache
+ * that pushes the total bytesUsed over the limit. Note: The limit can be
+ * changed at runtime with setByteLimit.
+ */
SkScaledImageCache(size_t byteLimit);
+
~SkScaledImageCache();
/**
@@ -124,6 +149,8 @@ public:
*/
size_t setByteLimit(size_t newLimit);
+ SkBitmap::Allocator* allocator() const { return fAllocator; };
+
public:
struct Rec;
struct Key;
@@ -134,6 +161,10 @@ private:
class Hash;
Hash* fHash;
+ DiscardableFactory fDiscardableFactory;
+ // the allocator is NULL or one that matches discardables
+ SkBitmap::Allocator* fAllocator;
+
size_t fBytesUsed;
size_t fByteLimit;
int fCount;
@@ -149,6 +180,9 @@ private:
void moveToHead(Rec*);
void addToHead(Rec*);
void detach(Rec*);
+
+ void init(); // called by constructors
+
#ifdef SK_DEBUG
void validate() const;
#else