Chromium Code Reviews| Index: src/core/SkResourceCache.h |
| diff --git a/src/core/SkResourceCache.h b/src/core/SkResourceCache.h |
| index 88ccb87ed88443ece5f5b6113fe737f142935713..a3c52df422781c113b33a6c39451df85b9783094 100644 |
| --- a/src/core/SkResourceCache.h |
| +++ b/src/core/SkResourceCache.h |
| @@ -9,6 +9,7 @@ |
| #define SkResourceCache_DEFINED |
| #include "SkBitmap.h" |
| +#include "SkTDArray.h" |
| class SkCachedData; |
| class SkDiscardableMemory; |
| @@ -33,7 +34,10 @@ public: |
| // must call this after your private data has been written. |
| // nameSpace must be unique per Key subclass. |
| // length must be a multiple of 4 |
| - void init(void* nameSpace, size_t length); |
| + void init(void* nameSpace, uint64_t sharedID, size_t length); |
|
mtklein
2015/02/24 16:43:39
Why don't we call this uniqueID? I hate to add an
reed2
2015/02/24 17:44:52
I don't think its unique, since it may appear in s
|
| + |
| + void* getNamespace() const { return fNamespace; } |
| + uint64_t getSharedID() const { return fSharedID; } |
| // This is only valid after having called init(). |
| uint32_t hash() const { return fHash; } |
| @@ -52,6 +56,7 @@ public: |
| private: |
| int32_t fCount32; // local + user contents count32 |
| uint32_t fHash; |
| + uint64_t fSharedID; // 0 means ignore (nothing is shared) |
| void* fNamespace; // A unique namespace tag. This is hashed. |
| /* uint32_t fContents32[] */ |
| @@ -92,7 +97,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 |
| @@ -114,7 +119,7 @@ public: |
| * 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(); |
| @@ -125,6 +130,11 @@ public: |
| static size_t GetSingleAllocationByteLimit(); |
| static size_t GetEffectiveSingleAllocationByteLimit(); |
| + /** |
| + * Purge all Recs that match the specified sharedID. Passing 0 does nothing. |
| + */ |
| + static void PurgeSharedID(uint64_t sharedID); |
|
mtklein
2015/02/24 16:43:39
Seems like we don't need both PurgeSharedID and Po
reed2
2015/02/24 17:44:52
Ah, good point. Don't need the purger, just the po
|
| + |
| static void PurgeAll(); |
| /** |
| @@ -140,6 +150,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 |
| */ |
| @@ -174,7 +186,7 @@ public: |
| * 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 +210,8 @@ public: |
| */ |
| size_t setTotalByteLimit(size_t newLimit); |
| + void purgeSharedID(uint64_t sharedID); |
|
mtklein
2015/02/24 16:43:39
Probably can be private?
reed2
2015/02/24 17:44:52
public like the others for testing. (which I need
|
| + |
| void purgeAll() { |
| this->purgeAsNeeded(true); |
| } |
| @@ -228,6 +242,7 @@ private: |
| size_t fSingleAllocationByteLimit; |
| int fCount; |
| + void checkMessages(); |
| void purgeAsNeeded(bool forcePurge = false); |
| // linklist management |
| @@ -238,6 +253,8 @@ private: |
| void init(); // called by constructors |
| + static SkTDArray<uint64_t>* DetachPurgeMessages(); |
| + |
| #ifdef SK_DEBUG |
| void validate() const; |
| #else |