Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: src/gpu/GrAtlasTextContext.cpp

Issue 1091313002: reuse scaler across consecutive textbatch flushes (Closed) Base URL: https://skia.googlesource.com/skia.git@atdfnow3
Patch Set: tweak Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAtlasTextContext.cpp
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index a841fccddd7b4a74c790466532d9b15c348560a2..5fbb6a998360205a3de7e5666f4c39ec7682240d 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -1504,6 +1504,14 @@ public:
drawInfo.setVertexBuffer(vertexBuffer);
drawInfo.setIndexBuffer(quadIndexBuffer);
+ // We cache some values to avoid going to the glyphcache for the same fontScaler twice
+ // in a row
+ const SkDescriptor* desc = NULL;
+ SkGlyphCache* cache = NULL;
+ GrFontScaler* scaler = NULL;
+ GrBatchTextStrike* strike = NULL;
+ SkTypeface* typeface = NULL;
+
int instancesToFlush = 0;
for (int i = 0; i < instanceCount; i++) {
Geometry& args = fGeoData[i];
@@ -1532,18 +1540,26 @@ public:
// should be pretty rare, so we just always regenerate in those cases
if (regenerateTextureCoords || regenerateColors || regeneratePositions) {
// first regenerate texture coordinates / colors if need be
- const SkDescriptor* desc = NULL;
- SkGlyphCache* cache = NULL;
- GrFontScaler* scaler = NULL;
- GrBatchTextStrike* strike = NULL;
bool brokenRun = false;
if (regenerateTextureCoords) {
info.fBulkUseToken.reset();
- desc = info.fOverrideDescriptor ? info.fOverrideDescriptor->getDesc() :
- run.fDescriptor.getDesc();
- cache = SkGlyphCache::DetachCache(run.fTypeface, desc);
- scaler = GrTextContext::GetGrFontScaler(cache);
- strike = fFontCache->getStrike(scaler);
+
+ // We can reuse if we have a valid strike and our descriptors / typeface are the
+ // same
+ const SkDescriptor* newDesc = info.fOverrideDescriptor ?
+ info.fOverrideDescriptor->getDesc() :
+ run.fDescriptor.getDesc();
+ if (!cache || !SkTypeface::Equal(typeface, run.fTypeface) ||
+ !(desc->equals(*newDesc))) {
+ if (cache) {
+ SkGlyphCache::AttachCache(cache);
+ }
+ desc = newDesc;
+ cache = SkGlyphCache::DetachCache(run.fTypeface, desc);
+ scaler = GrTextContext::GetGrFontScaler(cache);
+ strike = fFontCache->getStrike(scaler);
+ typeface = run.fTypeface;
+ }
}
for (int glyphIdx = 0; glyphIdx < glyphCount; glyphIdx++) {
GrGlyph::PackedID glyphID = blob->fGlyphIDs[glyphIdx + info.fGlyphStartIndex];
@@ -1599,7 +1615,6 @@ public:
// We my have changed the color so update it here
run.fColor = args.fColor;
if (regenerateTextureCoords) {
- SkGlyphCache::AttachCache(cache);
info.fAtlasGeneration = brokenRun ? GrBatchAtlas::kInvalidAtlasGeneration :
fFontCache->atlasGeneration(fMaskFormat);
}
@@ -1619,7 +1634,10 @@ public:
currVertex += byteCount;
}
-
+ // Make sure to attach the last cache if applicable
+ if (cache) {
+ SkGlyphCache::AttachCache(cache);
+ }
this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDraw);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698