Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: src/core/SkScaledImageCache.h

Issue 105933003: support scaledimagecache instantiable using discardablememory (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkBitmapProcState.cpp ('k') | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkScaledImageCache.h
diff --git a/src/core/SkScaledImageCache.h b/src/core/SkScaledImageCache.h
index 44ef1f8a2cb8e19369452ae191514eb0cdf3b98c..311db325be887ccddfa36b6790c0639387271786 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
« no previous file with comments | « src/core/SkBitmapProcState.cpp ('k') | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698