Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Unified Diff: src/gpu/GrTextBlobCache.h

Issue 1071333002: Added ability to flush context to GrTextBlobCache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: feedback inc Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrTextBlobCache.h
diff --git a/src/gpu/GrTextBlobCache.h b/src/gpu/GrTextBlobCache.h
index 7a2b2a79a17ade040c3c93106b5b22cf8c590015..9ce4ec7af2553c0b291eee588aad44be91f9ffe9 100644
--- a/src/gpu/GrTextBlobCache.h
+++ b/src/gpu/GrTextBlobCache.h
@@ -16,7 +16,18 @@ class GrTextBlobCache {
public:
typedef GrAtlasTextContext::BitmapTextBlob BitmapTextBlob;
- GrTextBlobCache() : fPool(kPreAllocSize, kMinGrowthSize) {}
+ /**
+ * The callback function used by the cache when it is still over budget after a purge. The
+ * passed in 'data' is the same 'data' handed to setOverbudgetCallback.
+ */
+ typedef void (*PFOverBudgetCB)(void* data);
+
+ GrTextBlobCache(PFOverBudgetCB cb, void* data)
+ : fPool(kPreAllocSize, kMinGrowthSize)
+ , fCallback(cb)
+ , fData(data) {
+ SkASSERT(cb && data);
+ }
~GrTextBlobCache();
// creates an uncached blob
@@ -52,12 +63,25 @@ public:
iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart);
BitmapTextBlob* lruBlob = iter.get();
SkASSERT(lruBlob);
- do {
+ while (fPool.size() > kBudget && (lruBlob = iter.get()) && lruBlob != blob) {
fCache.remove(lruBlob->fUniqueID);
fBlobList.remove(lruBlob);
- lruBlob->unref();
iter.prev();
- } while (fPool.size() > kBudget && (lruBlob = iter.get()));
+ lruBlob->unref();
+ }
+
+ // If we break out of the loop with lruBlob == blob, then we haven't purged enough
+ // use the call back and try to free some more. If we are still overbudget after this,
+ // then this single textblob is over our budget
+ if (lruBlob == blob) {
+ (*fCallback)(fData);
+ }
+
+#ifdef SK_DEBUG
+ if (fPool.size() > kBudget) {
+ SkDebugf("Single textblob is larger than our whole budget");
+ }
+#endif
}
}
@@ -85,10 +109,12 @@ private:
// based off of the largest cached textblob I have seen in the skps(a couple of kilobytes).
static const int kPreAllocSize = 1 << 17;
static const int kMinGrowthSize = 1 << 17;
- static const int kBudget = 1 << 20;
+ static const int kBudget = 1 << 22;
BitmapBlobList fBlobList;
SkTDynamicHash<BitmapTextBlob, uint32_t> fCache;
GrMemoryPool fPool;
+ PFOverBudgetCB fCallback;
+ void* fData;
};
#endif
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698