remove purge more interface from GrTextBlobCache
Change-Id: Ice1b7593ebf9cf38191c180eb56183ffc6167f0b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299293
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index 798f778..bcbdba4 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -160,10 +160,6 @@
}
/////////////////////////////////////////////////
-void GrContextPriv::testingOnly_setTextBlobCacheLimit(size_t bytes) {
- fContext->priv().getTextBlobCache()->setBudget(bytes);
-}
-
sk_sp<SkImage> GrContextPriv::testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index) {
auto atlasManager = this->getAtlasManager();
if (!atlasManager) {
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index ea43a13..b06bb9c 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -158,10 +158,6 @@
void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
void printContextStats() const;
- /** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge.
- this is for testing only */
- void testingOnly_setTextBlobCacheLimit(size_t bytes);
-
/** Get pointer to atlas texture for given mask format. Note that this wraps an
actively mutating texture in an SkImage. This could yield unexpected results
if it gets cached or used more generally. */
diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp
index 67093c6..d17de23 100644
--- a/src/gpu/GrRecordingContext.cpp
+++ b/src/gpu/GrRecordingContext.cpp
@@ -49,19 +49,7 @@
return false;
}
- auto overBudget = [this]() {
- if (GrContext* direct = this->priv().asDirectContext(); direct != nullptr) {
-
- // TODO: move text blob draw calls below context
- // TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on
- // GrRenderTargetContext to perform a necessary flush. The solution is to move drawText
- // calls to below the GrContext level, but this is not trivial because they call
- // drawPath on SkGpuDevice.
- direct->flushAndSubmit();
- }
- };
-
- fTextBlobCache.reset(new GrTextBlobCache(overBudget, this->contextID()));
+ fTextBlobCache.reset(new GrTextBlobCache(this->contextID()));
return true;
}
diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp
index 8a329c4..988ef81 100644
--- a/src/gpu/text/GrTextBlobCache.cpp
+++ b/src/gpu/text/GrTextBlobCache.cpp
@@ -15,9 +15,8 @@
return msg.fContextID == msgBusUniqueID;
}
-GrTextBlobCache::GrTextBlobCache(PurgeMore purgeMore, uint32_t messageBusID)
- : fPurgeMore(purgeMore)
- , fSizeBudget(kDefaultBudget)
+GrTextBlobCache::GrTextBlobCache(uint32_t messageBusID)
+ : fSizeBudget(kDefaultBudget)
, fMessageBusID(messageBusID)
, fPurgeBlobInbox(messageBusID) { }
@@ -74,12 +73,6 @@
fCurrentSize = 0;
}
-void GrTextBlobCache::setBudget(size_t budget) {
- SkAutoMutexExclusive lock{fMutex};
- fSizeBudget = budget;
- this->internalCheckPurge();
-}
-
void GrTextBlobCache::PostPurgeBlobMessage(uint32_t blobID, uint32_t cacheID) {
SkASSERT(blobID != SK_InvalidGenID);
SkMessageBus<PurgeBlobMessage>::Post(PurgeBlobMessage(blobID, cacheID));
@@ -117,6 +110,11 @@
return fCurrentSize;
}
+bool GrTextBlobCache::isOverBudget() const {
+ SkAutoMutexExclusive lock{fMutex};
+ return fCurrentSize > fSizeBudget;
+}
+
void GrTextBlobCache::internalCheckPurge(GrTextBlob* blob) {
// First, purge all stale blob IDs.
this->internalPurgeStaleBlobs();
@@ -133,13 +131,6 @@
this->internalRemove(lruBlob);
}
- // 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 (blob && lruBlob == blob) {
- fPurgeMore();
- }
-
#ifdef SPEW_BUDGET_MESSAGE
if (fCurrentSize > fSizeBudget) {
SkDebugf("Single textblob is larger than our whole budget");
diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h
index b4df670..3b25886 100644
--- a/src/gpu/text/GrTextBlobCache.h
+++ b/src/gpu/text/GrTextBlobCache.h
@@ -20,10 +20,7 @@
class GrTextBlobCache {
public:
- // The callback function used by the cache when it is still over budget after a purge.
- using PurgeMore = std::function<void()>;
-
- GrTextBlobCache(PurgeMore purgeMore, uint32_t messageBusID);
+ GrTextBlobCache(uint32_t messageBusID);
sk_sp<GrTextBlob> makeCachedBlob(const SkGlyphRunList& glyphRunList,
const GrTextBlob::Key& key,
@@ -38,8 +35,6 @@
void freeAll() SK_EXCLUDES(fMutex);
- void setBudget(size_t budget) SK_EXCLUDES(fMutex);
-
struct PurgeBlobMessage {
PurgeBlobMessage(uint32_t blobID, uint32_t contextUniqueID)
: fBlobID(blobID), fContextID(contextUniqueID) {}
@@ -54,7 +49,10 @@
size_t usedBytes() const SK_EXCLUDES(fMutex);
+ bool isOverBudget() const SK_EXCLUDES(fMutex);
+
private:
+ friend class GrTextBlobTestingPeer;
using TextBlobList = SkTInternalLList<GrTextBlob>;
struct BlobIDCacheEntry {
@@ -89,7 +87,6 @@
mutable SkMutex fMutex;
TextBlobList fBlobList SK_GUARDED_BY(fMutex);
SkTHashMap<uint32_t, BlobIDCacheEntry> fBlobIDCache SK_GUARDED_BY(fMutex);
- PurgeMore fPurgeMore SK_GUARDED_BY(fMutex);
size_t fSizeBudget SK_GUARDED_BY(fMutex);
size_t fCurrentSize SK_GUARDED_BY(fMutex) {0};