Hoist regenGlyphs out of per glyph loop
This positions to loop to be converted to
a bulk loop over the glyphs.
* rename fGlyphCache->fGrStrikeCache
Change-Id: Ie77d761905721cbdb52171117bac951cbca47af6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/254425
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h
index 5f6b800..05e5d21 100644
--- a/src/gpu/text/GrTextBlob.h
+++ b/src/gpu/text/GrTextBlob.h
@@ -623,7 +623,7 @@
const SkMatrix& fViewMatrix;
GrTextBlob* fBlob;
GrDeferredUploadTarget* fUploadTarget;
- GrStrikeCache* fGlyphCache;
+ GrStrikeCache* fGrStrikeCache;
GrAtlasManager* fFullAtlasManager;
SkTLazy<SkBulkGlyphMetricsAndImages> fMetricsAndImages;
SubRun* fSubRun;
diff --git a/src/gpu/text/GrTextBlobVertexRegenerator.cpp b/src/gpu/text/GrTextBlobVertexRegenerator.cpp
index c28a0a1..d20040d 100644
--- a/src/gpu/text/GrTextBlobVertexRegenerator.cpp
+++ b/src/gpu/text/GrTextBlobVertexRegenerator.cpp
@@ -121,13 +121,13 @@
const SkMatrix& viewMatrix, SkScalar x, SkScalar y,
GrColor color,
GrDeferredUploadTarget* uploadTarget,
- GrStrikeCache* glyphCache,
+ GrStrikeCache* grStrikeCache,
GrAtlasManager* fullAtlasManager)
: fResourceProvider(resourceProvider)
, fViewMatrix(viewMatrix)
, fBlob(blob)
, fUploadTarget(uploadTarget)
- , fGlyphCache(glyphCache)
+ , fGrStrikeCache(grStrikeCache)
, fFullAtlasManager(fullAtlasManager)
, fSubRun(&blob->fRuns[runIdx].fSubRunInfo[subRunIdx])
, fColor(color) {
@@ -158,7 +158,6 @@
bool regenPos, bool regenCol, bool regenTexCoords,
bool regenGlyphs) {
SkASSERT(!regenGlyphs || regenTexCoords);
- sk_sp<GrTextStrike> strike;
if (regenTexCoords) {
fSubRun->resetBulkUseToken();
@@ -170,12 +169,27 @@
}
if (regenGlyphs) {
- strike = strikeSpec.findOrCreateGrStrike(fGlyphCache);
- } else {
- strike = fSubRun->refStrike();
+ // Take the glyphs from the old strike, and translate them a new strike.
+ sk_sp<GrTextStrike> newStrike = strikeSpec.findOrCreateGrStrike(fGrStrikeCache);
+
+ // Start this batch at the start of the subRun plus any glyphs that were previously
+ // processed.
+ size_t glyphStart = fSubRun->glyphStartIndex() + fCurrGlyph;
+ SkSpan<GrGlyph*> glyphs{&(fBlob->fGlyphs[glyphStart]),
+ fSubRun->glyphCount() - fCurrGlyph};
+
+ // Convert old glyphs to newStrike.
+ for (auto& glyph : glyphs) {
+ SkPackedGlyphID id = glyph->fPackedID;
+ glyph = newStrike->getGlyph(id, fMetricsAndImages.get());
+ SkASSERT(id == glyph->fPackedID);
+ }
+
+ fSubRun->setStrike(newStrike);
}
}
+ sk_sp<GrTextStrike> grStrike = fSubRun->refStrike();
bool hasW = fSubRun->hasWCoord();
auto vertexStride = GetVertexStride(fSubRun->maskFormat(), hasW);
char* currVertex = fBlob->fVertices + fSubRun->vertexStartIndex() +
@@ -186,23 +200,15 @@
GrGlyph* glyph = nullptr;
if (regenTexCoords) {
size_t glyphOffset = glyphIdx + fSubRun->glyphStartIndex();
-
- if (regenGlyphs) {
- // Get the id from the old glyph, and use the new strike to lookup
- // the glyph.
- SkPackedGlyphID id = fBlob->fGlyphs[glyphOffset]->fPackedID;
- fBlob->fGlyphs[glyphOffset] = strike->getGlyph(id, fMetricsAndImages.get());
- SkASSERT(id == fBlob->fGlyphs[glyphOffset]->fPackedID);
- }
glyph = fBlob->fGlyphs[glyphOffset];
SkASSERT(glyph && glyph->fMaskFormat == fSubRun->maskFormat());
if (!fFullAtlasManager->hasGlyph(glyph)) {
GrDrawOpAtlas::ErrorCode code;
- code = strike->addGlyphToAtlas(fResourceProvider, fUploadTarget, fGlyphCache,
- fFullAtlasManager, glyph,
- fMetricsAndImages.get(), fSubRun->maskFormat(),
- fSubRun->needsTransform());
+ code = grStrike->addGlyphToAtlas(fResourceProvider, fUploadTarget, fGrStrikeCache,
+ fFullAtlasManager, glyph,
+ fMetricsAndImages.get(), fSubRun->maskFormat(),
+ fSubRun->needsTransform());
if (GrDrawOpAtlas::ErrorCode::kError == code) {
// Something horrible has happened - drop the op
return false;
@@ -236,9 +242,6 @@
// We may have changed the color so update it here
fSubRun->setColor(fColor);
if (regenTexCoords) {
- if (regenGlyphs) {
- fSubRun->setStrike(std::move(strike));
- }
fSubRun->setAtlasGeneration(fBrokenRun
? GrDrawOpAtlas::kInvalidAtlasGeneration
: fFullAtlasManager->atlasGeneration(fSubRun->maskFormat()));