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>
This commit is contained in:
Herb Derby 2019-11-13 15:09:32 -05:00 committed by Skia Commit-Bot
parent c95e54b558
commit 3a4f22787a
2 changed files with 25 additions and 22 deletions

View File

@ -623,7 +623,7 @@ private:
const SkMatrix& fViewMatrix;
GrTextBlob* fBlob;
GrDeferredUploadTarget* fUploadTarget;
GrStrikeCache* fGlyphCache;
GrStrikeCache* fGrStrikeCache;
GrAtlasManager* fFullAtlasManager;
SkTLazy<SkBulkGlyphMetricsAndImages> fMetricsAndImages;
SubRun* fSubRun;

View File

@ -121,13 +121,13 @@ GrTextBlob::VertexRegenerator::VertexRegenerator(GrResourceProvider* resourcePro
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 GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
bool regenPos, bool regenCol, bool regenTexCoords,
bool regenGlyphs) {
SkASSERT(!regenGlyphs || regenTexCoords);
sk_sp<GrTextStrike> strike;
if (regenTexCoords) {
fSubRun->resetBulkUseToken();
@ -170,12 +169,27 @@ bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
}
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 @@ bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
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 @@ bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
// 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()));