Simplify the atlas update inner loop

Try to move calculations out of the main atlas update loop.

Simplify expressions involving the result values. Invert the if-statement
and for-loop to do even less work.

Change-Id: Ibef88e65fb5bb8eeeaec13f0ae0ba1acb4d2d87d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/262926
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2020-01-07 13:51:14 -05:00 committed by Skia Commit-Bot
parent f01813ec5f
commit 511124e5a8

View File

@ -904,24 +904,19 @@ bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
}
}
GrTextStrike* grStrike = fSubRun->strike();
auto vertexStride = fSubRun->vertexStride();
char* currVertex = fSubRun->fVertexData.data() + fCurrGlyph * kVerticesPerGlyph * vertexStride;
result->fFirstVertex = currVertex;
int glyphLimit = (int)fSubRun->fGlyphs.size();
if (glyphLimit > fCurrGlyph + maxGlyphs) {
glyphLimit = fCurrGlyph + maxGlyphs;
result->fFinished = false;
}
int glyphLimit = std::min((int)fSubRun->fGlyphs.size(), fCurrGlyph + maxGlyphs);
// If we reach here with fCurrGlyph > 0, some earlier call to regenerate() exhausted the atlas
// before it could place all its glyphs and returned kTryAgain. We'll use brokenRun below to
// invalidate texture coordinates, forcing them to be regenerated, minding the atlas
// flush between.
const bool brokenRun = fCurrGlyph > 0;
auto code = GrDrawOpAtlas::ErrorCode::kSucceeded;
for (; fCurrGlyph < glyphLimit; fCurrGlyph++) {
if (fActions.regenTextureCoordinates) {
int startingGlyph = fCurrGlyph;
if (fActions.regenTextureCoordinates) {
GrTextStrike* grStrike = fSubRun->strike();
for (; fCurrGlyph < glyphLimit; fCurrGlyph++) {
GrGlyph* glyph = fSubRun->fGlyphs[fCurrGlyph];
SkASSERT(glyph && glyph->fMaskFormat == fSubRun->maskFormat());
@ -934,25 +929,24 @@ bool GrTextBlob::VertexRegenerator::doRegen(GrTextBlob::VertexRegenerator::Resul
}
}
auto tokenTracker = fUploadTarget->tokenTracker();
fFullAtlasManager->addGlyphToBulkAndSetUseToken(fSubRun->bulkUseToken(), glyph,
tokenTracker->nextDrawToken());
}
if (fActions.regenTextureCoordinates) {
fFullAtlasManager->addGlyphToBulkAndSetUseToken(
fSubRun->bulkUseToken(), glyph, tokenTracker->nextDrawToken());
fSubRun->updateTexCoord(fCurrGlyph);
}
currVertex += vertexStride * GrAtlasTextOp::kVerticesPerGlyph;
++result->fGlyphsRegenerated;
} else {
fCurrGlyph = glyphLimit;
}
result->fFinished = fCurrGlyph == (int)fSubRun->fGlyphs.size();
result->fGlyphsRegenerated += fCurrGlyph - startingGlyph;
result->fFirstVertex = fSubRun->quadStart(startingGlyph);
switch (code) {
case GrDrawOpAtlas::ErrorCode::kError: {
// Something horrible has happened - drop the op
return false;
}
case GrDrawOpAtlas::ErrorCode::kTryAgain: {
result->fFinished = false;
return true;
}
case GrDrawOpAtlas::ErrorCode::kSucceeded: {