diff options
Diffstat (limited to 'src/core/SkResourceCache.h')
-rw-r--r-- | src/core/SkResourceCache.h | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/core/SkResourceCache.h b/src/core/SkResourceCache.h index 0ff627196e..6087be7824 100644 --- a/src/core/SkResourceCache.h +++ b/src/core/SkResourceCache.h @@ -82,6 +82,22 @@ public: virtual const Key& getKey() const = 0; virtual size_t bytesUsed() const = 0; + // Called if the cache needs to purge/remove/delete the Rec. Default returns true. + // Subclass may return false if there are outstanding references to it (e.g. bitmaps). + // Will only be deleted/removed-from-the-cache when this returns true. + virtual bool canBePurged() { return true; } + + // A rec is first created/initialized, and then added to the cache. As part of the add(), + // the cache will callback into the rec with postAddInstall, passing in whatever payload + // was passed to add/Add. + // + // This late-install callback exists because the process of add-ing might end up deleting + // the new rec (if an existing rec in the cache has the same key and cannot be purged). + // If the new rec will be deleted during add, the pre-existing one (with the same key) + // will have postAddInstall() called on it instead, so that either way an "install" will + // happen during the add. + virtual void postAddInstall(void*) {} + // for memory usage diagnostics virtual const char* getCategory() const = 0; virtual SkDiscardableMemory* diagnostic_only_getDiscardable() const { return nullptr; } @@ -135,7 +151,7 @@ public: * false : Rec is "stale" -- the cache will purge it. */ static bool Find(const Key& key, FindVisitor, void* context); - static void Add(Rec*); + static void Add(Rec*, void* payload = nullptr); typedef void (*Visitor)(const Rec&, void* context); // Call the visitor for every Rec in the cache. @@ -163,12 +179,6 @@ public: */ static DiscardableFactory GetDiscardableFactory(); - /** - * Use this allocator for bitmaps, so they can use ashmem when available. - * Returns nullptr if the ResourceCache has not been initialized with a DiscardableFactory. - */ - static SkBitmap::Allocator* GetAllocator(); - static SkCachedData* NewCachedData(size_t bytes); static void PostPurgeSharedID(uint64_t sharedID); @@ -208,7 +218,7 @@ public: * false : Rec is "stale" -- the cache will purge it. */ bool find(const Key&, FindVisitor, void* context); - void add(Rec*); + void add(Rec*, void* payload = nullptr); void visitAll(Visitor, void* context); size_t getTotalBytesUsed() const { return fTotalBytesUsed; } @@ -239,7 +249,6 @@ public: } DiscardableFactory discardableFactory() const { return fDiscardableFactory; } - SkBitmap::Allocator* allocator() const { return fAllocator; } SkCachedData* newCachedData(size_t bytes); @@ -256,8 +265,6 @@ private: Hash* fHash; DiscardableFactory fDiscardableFactory; - // the allocator is nullptr or one that matches discardables - SkBitmap::Allocator* fAllocator; size_t fTotalBytesUsed; size_t fTotalByteLimit; |