aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkResourceCache.h
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2015-02-24 13:54:23 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-02-24 13:54:23 -0800
commit7eeba2587760a0802fd2b90765b4fd0e5e895375 (patch)
treedad9caa7dde038c52728034710c3d6d4926bfff2 /src/core/SkResourceCache.h
parent4b583ac54b92ad6e7685bdfa2b68e7dd11ba0d28 (diff)
Notify resource caches when pixelref genID goes stale
patch from issue 954443002 at patchset 40001 (http://crrev.com/954443002#ps40001) BUG=skia: Review URL: https://codereview.chromium.org/950363002
Diffstat (limited to 'src/core/SkResourceCache.h')
-rw-r--r--src/core/SkResourceCache.h35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/core/SkResourceCache.h b/src/core/SkResourceCache.h
index 88ccb87ed8..b43572f4be 100644
--- a/src/core/SkResourceCache.h
+++ b/src/core/SkResourceCache.h
@@ -9,6 +9,8 @@
#define SkResourceCache_DEFINED
#include "SkBitmap.h"
+#include "SkMessageBus.h"
+#include "SkTDArray.h"
class SkCachedData;
class SkDiscardableMemory;
@@ -32,8 +34,12 @@ public:
// must call this after your private data has been written.
// nameSpace must be unique per Key subclass.
+ // sharedID == 0 means ignore this field : does not support group purging.
// length must be a multiple of 4
- void init(void* nameSpace, size_t length);
+ void init(void* nameSpace, uint64_t sharedID, size_t length);
+
+ void* getNamespace() const { return fNamespace; }
+ uint64_t getSharedID() const { return ((uint64_t)fSharedID_hi << 32) | fSharedID_lo; }
// This is only valid after having called init().
uint32_t hash() const { return fHash; }
@@ -52,6 +58,9 @@ public:
private:
int32_t fCount32; // local + user contents count32
uint32_t fHash;
+ // split uint64_t into hi and lo so we don't force ourselves to pad on 32bit machines.
+ uint32_t fSharedID_lo;
+ uint32_t fSharedID_hi;
void* fNamespace; // A unique namespace tag. This is hashed.
/* uint32_t fContents32[] */
@@ -80,6 +89,13 @@ public:
friend class SkResourceCache;
};
+ // Used with SkMessageBus
+ struct PurgeSharedIDMessage {
+ PurgeSharedIDMessage(uint64_t sharedID) : fSharedID(sharedID) {}
+
+ uint64_t fSharedID;
+ };
+
typedef const Rec* ID;
/**
@@ -92,7 +108,7 @@ public:
* true, then the Rec is considered "valid". If false is returned, the Rec will be considered
* "stale" and will be purged from the cache.
*/
- typedef bool (*VisitorProc)(const Rec&, void* context);
+ typedef bool (*FindVisitor)(const Rec&, void* context);
/**
* Returns a locked/pinned SkDiscardableMemory instance for the specified
@@ -109,12 +125,12 @@ public:
* Returns true if the visitor was called on a matching Key, and the visitor returned true.
*
* Find() will search the cache for the specified Key. If no match is found, return false and
- * do not call the VisitorProc. If a match is found, return whatever the visitor returns.
+ * do not call the FindVisitor. If a match is found, return whatever the visitor returns.
* Its return value is interpreted to mean:
* true : Rec is valid
* false : Rec is "stale" -- the cache will purge it.
*/
- static bool Find(const Key& key, VisitorProc, void* context);
+ static bool Find(const Key& key, FindVisitor, void* context);
static void Add(Rec*);
static size_t GetTotalBytesUsed();
@@ -140,6 +156,8 @@ public:
static SkCachedData* NewCachedData(size_t bytes);
+ static void PostPurgeSharedID(uint64_t sharedID);
+
/**
* Call SkDebugf() with diagnostic information about the state of the cache
*/
@@ -169,12 +187,12 @@ public:
* Returns true if the visitor was called on a matching Key, and the visitor returned true.
*
* find() will search the cache for the specified Key. If no match is found, return false and
- * do not call the VisitorProc. If a match is found, return whatever the visitor returns.
+ * do not call the FindVisitor. If a match is found, return whatever the visitor returns.
* Its return value is interpreted to mean:
* true : Rec is valid
* false : Rec is "stale" -- the cache will purge it.
*/
- bool find(const Key&, VisitorProc, void* context);
+ bool find(const Key&, FindVisitor, void* context);
void add(Rec*);
size_t getTotalBytesUsed() const { return fTotalBytesUsed; }
@@ -198,6 +216,8 @@ public:
*/
size_t setTotalByteLimit(size_t newLimit);
+ void purgeSharedID(uint64_t sharedID);
+
void purgeAll() {
this->purgeAsNeeded(true);
}
@@ -228,6 +248,9 @@ private:
size_t fSingleAllocationByteLimit;
int fCount;
+ SkMessageBus<PurgeSharedIDMessage>::Inbox fPurgeSharedIDInbox;
+
+ void checkMessages();
void purgeAsNeeded(bool forcePurge = false);
// linklist management