Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1ca54d4

Browse files
herbderbySkia Commit-Bot
authored and
Skia Commit-Bot
committed
remove purge more interface from GrTextBlobCache
Change-Id: Ice1b7593ebf9cf38191c180eb56183ffc6167f0b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299293 Reviewed-by: Brian Salomon <[email protected]> Commit-Queue: Herb Derby <[email protected]>
1 parent 439fe60 commit 1ca54d4

6 files changed

+23
-45
lines changed

src/gpu/GrContextPriv.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ void GrContextPriv::printContextStats() const {
160160
}
161161

162162
/////////////////////////////////////////////////
163-
void GrContextPriv::testingOnly_setTextBlobCacheLimit(size_t bytes) {
164-
fContext->priv().getTextBlobCache()->setBudget(bytes);
165-
}
166-
167163
sk_sp<SkImage> GrContextPriv::testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index) {
168164
auto atlasManager = this->getAtlasManager();
169165
if (!atlasManager) {

src/gpu/GrContextPriv.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ class GrContextPriv {
158158
void dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
159159
void printContextStats() const;
160160

161-
/** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge.
162-
this is for testing only */
163-
void testingOnly_setTextBlobCacheLimit(size_t bytes);
164-
165161
/** Get pointer to atlas texture for given mask format. Note that this wraps an
166162
actively mutating texture in an SkImage. This could yield unexpected results
167163
if it gets cached or used more generally. */

src/gpu/GrRecordingContext.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,7 @@ bool GrRecordingContext::init() {
4949
return false;
5050
}
5151

52-
auto overBudget = [this]() {
53-
if (GrContext* direct = this->priv().asDirectContext(); direct != nullptr) {
54-
55-
// TODO: move text blob draw calls below context
56-
// TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on
57-
// GrRenderTargetContext to perform a necessary flush. The solution is to move drawText
58-
// calls to below the GrContext level, but this is not trivial because they call
59-
// drawPath on SkGpuDevice.
60-
direct->flushAndSubmit();
61-
}
62-
};
63-
64-
fTextBlobCache.reset(new GrTextBlobCache(overBudget, this->contextID()));
52+
fTextBlobCache.reset(new GrTextBlobCache(this->contextID()));
6553

6654
return true;
6755
}

src/gpu/text/GrTextBlobCache.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ static inline bool SkShouldPostMessageToBus(
1515
return msg.fContextID == msgBusUniqueID;
1616
}
1717

18-
GrTextBlobCache::GrTextBlobCache(PurgeMore purgeMore, uint32_t messageBusID)
19-
: fPurgeMore(purgeMore)
20-
, fSizeBudget(kDefaultBudget)
18+
GrTextBlobCache::GrTextBlobCache(uint32_t messageBusID)
19+
: fSizeBudget(kDefaultBudget)
2120
, fMessageBusID(messageBusID)
2221
, fPurgeBlobInbox(messageBusID) { }
2322

@@ -74,12 +73,6 @@ void GrTextBlobCache::freeAll() {
7473
fCurrentSize = 0;
7574
}
7675

77-
void GrTextBlobCache::setBudget(size_t budget) {
78-
SkAutoMutexExclusive lock{fMutex};
79-
fSizeBudget = budget;
80-
this->internalCheckPurge();
81-
}
82-
8376
void GrTextBlobCache::PostPurgeBlobMessage(uint32_t blobID, uint32_t cacheID) {
8477
SkASSERT(blobID != SK_InvalidGenID);
8578
SkMessageBus<PurgeBlobMessage>::Post(PurgeBlobMessage(blobID, cacheID));
@@ -117,6 +110,11 @@ size_t GrTextBlobCache::usedBytes() const {
117110
return fCurrentSize;
118111
}
119112

113+
bool GrTextBlobCache::isOverBudget() const {
114+
SkAutoMutexExclusive lock{fMutex};
115+
return fCurrentSize > fSizeBudget;
116+
}
117+
120118
void GrTextBlobCache::internalCheckPurge(GrTextBlob* blob) {
121119
// First, purge all stale blob IDs.
122120
this->internalPurgeStaleBlobs();
@@ -133,13 +131,6 @@ void GrTextBlobCache::internalCheckPurge(GrTextBlob* blob) {
133131
this->internalRemove(lruBlob);
134132
}
135133

136-
// If we break out of the loop with lruBlob == blob, then we haven't purged enough
137-
// use the call back and try to free some more. If we are still overbudget after this,
138-
// then this single textblob is over our budget
139-
if (blob && lruBlob == blob) {
140-
fPurgeMore();
141-
}
142-
143134
#ifdef SPEW_BUDGET_MESSAGE
144135
if (fCurrentSize > fSizeBudget) {
145136
SkDebugf("Single textblob is larger than our whole budget");

src/gpu/text/GrTextBlobCache.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020

2121
class GrTextBlobCache {
2222
public:
23-
// The callback function used by the cache when it is still over budget after a purge.
24-
using PurgeMore = std::function<void()>;
25-
26-
GrTextBlobCache(PurgeMore purgeMore, uint32_t messageBusID);
23+
GrTextBlobCache(uint32_t messageBusID);
2724

2825
sk_sp<GrTextBlob> makeCachedBlob(const SkGlyphRunList& glyphRunList,
2926
const GrTextBlob::Key& key,
@@ -38,8 +35,6 @@ class GrTextBlobCache {
3835

3936
void freeAll() SK_EXCLUDES(fMutex);
4037

41-
void setBudget(size_t budget) SK_EXCLUDES(fMutex);
42-
4338
struct PurgeBlobMessage {
4439
PurgeBlobMessage(uint32_t blobID, uint32_t contextUniqueID)
4540
: fBlobID(blobID), fContextID(contextUniqueID) {}
@@ -54,7 +49,10 @@ class GrTextBlobCache {
5449

5550
size_t usedBytes() const SK_EXCLUDES(fMutex);
5651

52+
bool isOverBudget() const SK_EXCLUDES(fMutex);
53+
5754
private:
55+
friend class GrTextBlobTestingPeer;
5856
using TextBlobList = SkTInternalLList<GrTextBlob>;
5957

6058
struct BlobIDCacheEntry {
@@ -89,7 +87,6 @@ class GrTextBlobCache {
8987
mutable SkMutex fMutex;
9088
TextBlobList fBlobList SK_GUARDED_BY(fMutex);
9189
SkTHashMap<uint32_t, BlobIDCacheEntry> fBlobIDCache SK_GUARDED_BY(fMutex);
92-
PurgeMore fPurgeMore SK_GUARDED_BY(fMutex);
9390
size_t fSizeBudget SK_GUARDED_BY(fMutex);
9491
size_t fCurrentSize SK_GUARDED_BY(fMutex) {0};
9592

tests/TextBlobCacheTest.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "include/gpu/GrContext.h"
3030
#include "src/gpu/GrContextPriv.h"
3131
#include "src/gpu/text/GrAtlasManager.h"
32+
#include "src/gpu/text/GrTextBlobCache.h"
3233

3334
static void draw(SkCanvas* canvas, int redraw, const SkTArray<sk_sp<SkTextBlob>>& blobs) {
3435
int yOffset = 0;
@@ -50,6 +51,15 @@ static void setup_always_evict_atlas(GrContext* context) {
5051
context->priv().getAtlasManager()->setAtlasDimensionsToMinimum_ForTesting();
5152
}
5253

54+
class GrTextBlobTestingPeer {
55+
public:
56+
static void SetBudget(GrTextBlobCache* cache, size_t budget) {
57+
SkAutoMutexExclusive lock{cache->fMutex};
58+
cache->fSizeBudget = budget;
59+
cache->internalCheckPurge();
60+
}
61+
};
62+
5363
// This test hammers the GPU textblobcache and font atlas
5464
static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* context,
5565
int maxTotalText, int maxGlyphID, int maxFamilies, bool normal,
@@ -61,7 +71,7 @@ static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* conte
6171
// configure our context for maximum stressing of cache and atlas
6272
if (stressTest) {
6373
setup_always_evict_atlas(context);
64-
context->priv().testingOnly_setTextBlobCacheLimit(0);
74+
GrTextBlobTestingPeer::SetBudget(context->priv().getTextBlobCache(), 0);
6575
}
6676

6777
SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kRGBA_8888_SkColorType,

0 commit comments

Comments
 (0)