aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkResourceCache.h
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-04-11 12:03:44 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-11 16:38:17 +0000
commit7a542c559a6e584107b94e6254ac3c7f9f24b591 (patch)
tree9186b5ae154b580e20b3dc40f437e44f546c467b /src/core/SkResourceCache.h
parent77443974ea96912fa39079a4bf82ab791ec3c922 (diff)
Change bitmapcache to not rely on lockpixels.
The Rec in the cache is the owner of the pixel memory - discardable or - malloc Each external client has a pixelref that just points to those pixels, and whose destructor will notify the rec. This eliminates the dependency on lockPixels in pixelref, freeing us to remove that entirely from pixelref. Bug: skia: Change-Id: If45ed0ae202a1211336626364235215253e8aa7c Reviewed-on: https://skia-review.googlesource.com/10300 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Matt Sarett <msarett@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/core/SkResourceCache.h')
-rw-r--r--src/core/SkResourceCache.h29
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;