Pointer to GrStrikeCache on GrTextBlob
This will allow all the glyph drawing closures to live on the
GrTextBlob.
Other cleanup
* Rename glyphCache things to grStrikeCache.
Change-Id: I03e0353a1434230086a08184221272f1e5751ae6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/197244
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 4b5f1bb..05b0239 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -72,7 +72,7 @@
SkASSERT(this->drawingManager());
SkASSERT(this->caps());
- SkASSERT(this->getGlyphCache());
+ SkASSERT(this->getGrStrikeCache());
SkASSERT(this->getTextBlobCache());
if (fGpu) {
@@ -160,7 +160,7 @@
// TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here.
// Some slack in the GrTextBlob's implementation requires it though. That could be fixed.
- this->getGlyphCache()->freeAll();
+ this->getGrStrikeCache()->freeAll();
this->drawingManager()->freeGpuResources();
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 24f3e2a..374e049 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -66,7 +66,7 @@
sk_sp<GrOpMemoryPool> refOpMemoryPool();
GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); }
- GrStrikeCache* getGlyphCache() { return fContext->getGlyphCache(); }
+ GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); }
GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
/**
diff --git a/src/gpu/GrLegacyDirectContext.cpp b/src/gpu/GrLegacyDirectContext.cpp
index 490b62b..e580ac8 100644
--- a/src/gpu/GrLegacyDirectContext.cpp
+++ b/src/gpu/GrLegacyDirectContext.cpp
@@ -85,7 +85,7 @@
allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes;
}
- GrStrikeCache* glyphCache = this->priv().getGlyphCache();
+ GrStrikeCache* glyphCache = this->priv().getGrStrikeCache();
GrProxyProvider* proxyProvider = this->priv().proxyProvider();
fAtlasManager = new GrAtlasManager(proxyProvider, glyphCache,
diff --git a/src/gpu/GrOpFlushState.cpp b/src/gpu/GrOpFlushState.cpp
index a02b2f4..7a6aa18 100644
--- a/src/gpu/GrOpFlushState.cpp
+++ b/src/gpu/GrOpFlushState.cpp
@@ -178,7 +178,7 @@
}
GrStrikeCache* GrOpFlushState::glyphCache() const {
- return fGpu->getContext()->priv().getGlyphCache();
+ return fGpu->getContext()->priv().getGrStrikeCache();
}
GrAtlasManager* GrOpFlushState::atlasManager() const {
diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp
index 553fc7d..23f25cd 100644
--- a/src/gpu/GrRecordingContext.cpp
+++ b/src/gpu/GrRecordingContext.cpp
@@ -55,7 +55,7 @@
return false;
}
- fGlyphCache.reset(new GrStrikeCache(this->caps(),
+ fStrikeCache.reset(new GrStrikeCache(this->caps(),
this->options().fGlyphCacheTextureMaximumBytes));
fTextBlobCache.reset(new GrTextBlobCache(textblobcache_overbudget_CB, this,
@@ -102,7 +102,7 @@
void GrRecordingContext::abandonContext() {
INHERITED::abandonContext();
- fGlyphCache->freeAll();
+ fStrikeCache->freeAll();
fTextBlobCache->freeAll();
}
diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h
index 879b56e..46f13f2 100644
--- a/src/gpu/GrRecordingContextPriv.h
+++ b/src/gpu/GrRecordingContextPriv.h
@@ -50,7 +50,7 @@
sk_sp<GrOpMemoryPool> refOpMemoryPool();
GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); }
- GrStrikeCache* getGlyphCache() { return fContext->getGlyphCache(); }
+ GrStrikeCache* getGrStrikeCache() { return fContext->getGrStrikeCache(); }
GrTextBlobCache* getTextBlobCache() { return fContext->getTextBlobCache(); }
/**
diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp
index 8feaa1a..0ab8f6d 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -23,7 +23,10 @@
return ((s + (N-1)) / N) * N;
}
-sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount, int runCount, GrColor color) {
+sk_sp<GrTextBlob> GrTextBlob::Make(int glyphCount,
+ int runCount,
+ GrColor color,
+ GrStrikeCache* strikeCache) {
// We allocate size for the GrTextBlob itself, plus size for the vertices array,
// and size for the glyphIds array.
size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
@@ -40,7 +43,7 @@
sk_bzero(allocation, size);
}
- sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{}};
+ sk_sp<GrTextBlob> blob{new (allocation) GrTextBlob{strikeCache}};
blob->fSize = size;
// setup offsets for vertices / glyphs
diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h
index 7861439..36ec39e 100644
--- a/src/gpu/text/GrTextBlob.h
+++ b/src/gpu/text/GrTextBlob.h
@@ -55,8 +55,7 @@
class VertexRegenerator;
- void generateFromGlyphRunList(GrStrikeCache* glyphCache,
- const GrShaderCaps& shaderCaps,
+ void generateFromGlyphRunList(const GrShaderCaps& shaderCaps,
const GrTextContext::Options& options,
const SkPaint& paint,
SkScalerContextFlags scalerContextFlags,
@@ -65,7 +64,11 @@
const SkGlyphRunList& glyphRunList,
SkGlyphRunListPainter* glyphPainter);
- static sk_sp<GrTextBlob> Make(int glyphCount, int runCount, GrColor color);
+ static sk_sp<GrTextBlob> Make(
+ int glyphCount,
+ int runCount,
+ GrColor color,
+ GrStrikeCache* strikeCache);
/**
* We currently force regeneration of a blob if old or new matrix differ in having perspective.
@@ -250,10 +253,7 @@
GrTextTarget*);
private:
- GrTextBlob()
- : fMaxMinScale(-SK_ScalarMax)
- , fMinMaxScale(SK_ScalarMax)
- , fTextType(0) {}
+ GrTextBlob(GrStrikeCache* strikeCache) : fStrikeCache{strikeCache} { }
// This function will only be called when we are generating a blob from scratch. We record the
// initial view matrix and initial offsets(x,y), because we record vertex bounds relative to
@@ -532,6 +532,10 @@
char* fVertices;
GrGlyph** fGlyphs;
Run* fRuns;
+
+ // Lifetime: The GrStrikeCache is owned by and has the same lifetime as the GrRecordingContext.
+ // The GrRecordingContext also owns the GrTextBlob cache which owns this GrTextBlob.
+ GrStrikeCache* const fStrikeCache;
SkMaskFilterBase::BlurRec fBlurRec;
StrokeInfo fStrokeInfo;
Key fKey;
@@ -545,11 +549,11 @@
// We can reuse distance field text, but only if the new viewmatrix would not result in
// a mip change. Because there can be multiple runs in a blob, we track the overall
// maximum minimum scale, and minimum maximum scale, we can support before we need to regen
- SkScalar fMaxMinScale;
- SkScalar fMinMaxScale;
+ SkScalar fMaxMinScale{-SK_ScalarMax};
+ SkScalar fMinMaxScale{SK_ScalarMax};
int fRunCount{0};
int fRunCountLimit;
- uint8_t fTextType;
+ uint8_t fTextType{0};
};
/**
diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h
index 4e9b5ce..03d48ad 100644
--- a/src/gpu/text/GrTextBlobCache.h
+++ b/src/gpu/text/GrTextBlobCache.h
@@ -33,16 +33,20 @@
}
~GrTextBlobCache();
- sk_sp<GrTextBlob> makeBlob(const SkGlyphRunList& glyphRunList, GrColor color) {
- return GrTextBlob::Make(glyphRunList.totalGlyphCount(), glyphRunList.size(), color);
+ sk_sp<GrTextBlob> makeBlob(const SkGlyphRunList& glyphRunList,
+ GrColor color,
+ GrStrikeCache* strikeCache) {
+ return GrTextBlob::Make(
+ glyphRunList.totalGlyphCount(), glyphRunList.size(), color, strikeCache);
}
sk_sp<GrTextBlob> makeCachedBlob(const SkGlyphRunList& glyphRunList,
const GrTextBlob::Key& key,
const SkMaskFilterBase::BlurRec& blurRec,
const SkPaint& paint,
- GrColor color) {
- sk_sp<GrTextBlob> cacheBlob(makeBlob(glyphRunList, color));
+ GrColor color,
+ GrStrikeCache* strikeCache) {
+ sk_sp<GrTextBlob> cacheBlob(makeBlob(glyphRunList, color, strikeCache));
cacheBlob->setupKey(key, blurRec, paint);
this->add(cacheBlob);
glyphRunList.temporaryShuntBlobNotifyAddedToCache(fUniqueID);