Simplify subrun atlas generation tracking

The atlas generation's tracking was in two places. Gather
all into regenerate.

Gather more of the bulk use tracking into regenerate, and
cleanup some of the bulk use comments.

Change-Id: I87727b087d4605de9fa4684f4662fa49dc424863
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/268164
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Herb Derby 2020-01-31 16:59:29 -05:00 committed by Skia Commit-Bot
parent 5d92ae2b56
commit 3d05192abe
2 changed files with 18 additions and 24 deletions

View File

@ -785,9 +785,8 @@ GrTextBlob::VertexRegenerator::VertexRegenerator(GrResourceProvider* resourcePro
, fFullAtlasManager(fullAtlasManager)
, fSubRun(subRun) { }
std::tuple<bool, int> GrTextBlob::VertexRegenerator::updateTextureCoordinatesMaybeStrike(
std::tuple<bool, int> GrTextBlob::VertexRegenerator::updateTextureCoordinates(
const int begin, const int end) {
fSubRun->resetBulkUseToken();
const SkStrikeSpec& strikeSpec = fSubRun->strikeSpec();
@ -821,34 +820,30 @@ std::tuple<bool, int> GrTextBlob::VertexRegenerator::updateTextureCoordinatesMay
// Update the quads with the new atlas coordinates.
fSubRun->updateTexCoords(begin, begin + glyphsPlacedInAtlas);
if (code == GrDrawOpAtlas::ErrorCode::kSucceeded) {
// If we reach here with begin > 0, some earlier call to regenerate() exhausted the atlas
// before it could place all its glyphs and returned kTryAgain. Invalidate texture
// coordinates, forcing them to be regenerated, minding the atlas flush between.
fSubRun->fAtlasGeneration =
begin > 0 ? GrDrawOpAtlas::kInvalidAtlasGeneration
: fFullAtlasManager->atlasGeneration(fSubRun->maskFormat());
}
return {code != GrDrawOpAtlas::ErrorCode::kError, glyphsPlacedInAtlas};
}
std::tuple<bool, int> GrTextBlob::VertexRegenerator::regenerate(int begin, int end) {
uint64_t currentAtlasGen = fFullAtlasManager->atlasGeneration(fSubRun->maskFormat());
// If regenerate() is called multiple times then the atlas gen may have changed. So we check
// this each time.
// TODO: figure out why this needs to latch true instead of maintaining the invariant with
// the atlas generation.
fRegenerateTextureCoordinates =
fRegenerateTextureCoordinates || fSubRun->fAtlasGeneration != currentAtlasGen;
if (fRegenerateTextureCoordinates) {
return this->updateTextureCoordinatesMaybeStrike(begin, end);
if (fSubRun->fAtlasGeneration != currentAtlasGen) {
// Calculate the texture coordinates for the vertexes during first use (fAtlasGeneration
// is set to kInvalidAtlasGeneration) or the atlas has changed in subsequent calls..
fSubRun->resetBulkUseToken();
auto [success, glyphsPlacedInAtlas] = this->updateTextureCoordinates(begin, end);
// Update atlas generation if there are no more glyphs to put in the atlas.
if (success && begin + glyphsPlacedInAtlas == (int)fSubRun->fGlyphs.size()) {
// Need to get the freshest value of the atlas' generation because
// updateTextureCoordinates may have changed it.
fSubRun->fAtlasGeneration = fFullAtlasManager->atlasGeneration(fSubRun->maskFormat());
}
return {success, glyphsPlacedInAtlas};
} else {
// All glyphs are inserted into the atlas if fCurrGlyph is at the end of fGlyphs.
// The atlas hasn't changed, so our texture coordinates are still valid.
if (end == (int)fSubRun->fGlyphs.size()) {
// Set use tokens for all of the glyphs in our SubRun. This is only valid if we
// have a valid atlas generation
// The atlas hasn't changed and the texture coordinates are all still valid. Update
// all the plots used to the new use token.
fFullAtlasManager->setUseTokenBulk(*fSubRun->bulkUseToken(),
fUploadTarget->tokenTracker()->nextDrawToken(),
fSubRun->maskFormat());

View File

@ -304,7 +304,7 @@ public:
private:
// Return {success, number of glyphs regenerated}
std::tuple<bool, int> updateTextureCoordinatesMaybeStrike(int begin, int end);
std::tuple<bool, int> updateTextureCoordinates(int begin, int end);
GrResourceProvider* fResourceProvider;
GrDeferredUploadTarget* fUploadTarget;
@ -312,7 +312,6 @@ private:
GrAtlasManager* fFullAtlasManager;
SkTLazy<SkBulkGlyphMetricsAndImages> fMetricsAndImages;
SubRun* fSubRun;
bool fRegenerateTextureCoordinates{false};
};
// -- GrTextBlob::SubRun ---------------------------------------------------------------------------