aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text/GrTextBlobCache.h
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-03-13 16:45:28 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-14 14:00:13 +0000
commit4a01ac9e410e7b78fb04c8632e0676082b9408aa (patch)
tree6a834475439e681020026500b3c7f6c13cb7bfef /src/gpu/text/GrTextBlobCache.h
parentb66b42f1749a7a23fd610d90605978537bf4fbb7 (diff)
Purge GrTextBlobCache entries on SkTextBlob deletion
Similar to the SkImage purge mechanism. Change-Id: I0b7fb1bad507a3c7f30a4f7514bedd894d1748ac Reviewed-on: https://skia-review.googlesource.com/9631 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'src/gpu/text/GrTextBlobCache.h')
-rw-r--r--src/gpu/text/GrTextBlobCache.h34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h
index af6c7926fa..bf0e6d1245 100644
--- a/src/gpu/text/GrTextBlobCache.h
+++ b/src/gpu/text/GrTextBlobCache.h
@@ -9,6 +9,7 @@
#define GrTextBlobCache_DEFINED
#include "GrAtlasTextContext.h"
+#include "SkMessageBus.h"
#include "SkRefCnt.h"
#include "SkTArray.h"
#include "SkTextBlobRunIterator.h"
@@ -50,6 +51,7 @@ public:
sk_sp<GrAtlasTextBlob> cacheBlob(this->makeBlob(blob));
cacheBlob->setupKey(key, blurRec, paint);
this->add(cacheBlob);
+ blob->notifyAddedToCache();
return cacheBlob;
}
@@ -94,6 +96,12 @@ public:
this->checkPurge();
}
+ struct PurgeBlobMessage {
+ uint32_t fID;
+ };
+
+ static void PostPurgeBlobMessage(uint32_t);
+
private:
using BitmapBlobList = SkTInternalLList<GrAtlasTextBlob>;
@@ -159,7 +167,30 @@ private:
}
void checkPurge(GrAtlasTextBlob* blob = nullptr) {
- // If we are overbudget, then unref until we are below budget again
+ // First, purge all stale blob IDs.
+ {
+ // TODO: tweak poll to allow mem-movable arrays, and update.
+ SkSTArray<128, PurgeBlobMessage, false> msgs;
+ fPurgeBlobInbox.poll(&msgs);
+
+ for (const auto& msg : msgs) {
+ auto* idEntry = fBlobIDCache.find(msg.fID);
+ if (!idEntry) {
+ // no cache entries for id
+ continue;
+ }
+
+ // remove all blob entries from the LRU list
+ for (const auto& blob : idEntry->fBlobs) {
+ fBlobList.remove(blob.get());
+ }
+
+ // drop the idEntry itself (unrefs all blobs)
+ fBlobIDCache.remove(msg.fID);
+ }
+ }
+
+ // If we are still overbudget, then unref until we are below budget again
if (fPool.size() > fBudget) {
BitmapBlobList::Iter iter;
iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart);
@@ -197,6 +228,7 @@ private:
PFOverBudgetCB fCallback;
void* fData;
size_t fBudget;
+ SkMessageBus<PurgeBlobMessage>::Inbox fPurgeBlobInbox;
};
#endif