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

Side by Side Diff: src/gpu/GrAtlasTextContext.cpp

Issue 1093083003: Some simple optimizations for improving GrAtlasTextContext perf (Closed) Base URL: https://skia.googlesource.com/skia.git@atdfregen
Patch Set: simple optimizations 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrBatchAtlas.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "GrAtlasTextContext.h" 7 #include "GrAtlasTextContext.h"
8 8
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrBatch.h" 10 #include "GrBatch.h"
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 GrGlyph::PackedID packed, 1194 GrGlyph::PackedID packed,
1195 int vx, int vy, GrColor color, GrFontSca ler* scaler, 1195 int vx, int vy, GrColor color, GrFontSca ler* scaler,
1196 const SkIRect& clipRect) { 1196 const SkIRect& clipRect) {
1197 Run& run = blob->fRuns[runIndex]; 1197 Run& run = blob->fRuns[runIndex];
1198 if (!fCurrStrike) { 1198 if (!fCurrStrike) {
1199 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); 1199 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
1200 run.fStrike.reset(SkRef(fCurrStrike)); 1200 run.fStrike.reset(SkRef(fCurrStrike));
1201 } 1201 }
1202 1202
1203 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); 1203 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler);
1204 if (!glyph || glyph->fBounds.isEmpty()) { 1204 if (!glyph) {
1205 return; 1205 return;
1206 } 1206 }
1207 1207
1208 int x = vx + glyph->fBounds.fLeft; 1208 int x = vx + glyph->fBounds.fLeft;
1209 int y = vy + glyph->fBounds.fTop; 1209 int y = vy + glyph->fBounds.fTop;
1210 1210
1211 // keep them as ints until we've done the clip-test 1211 // keep them as ints until we've done the clip-test
1212 int width = glyph->fBounds.width(); 1212 int width = glyph->fBounds.width();
1213 int height = glyph->fBounds.height(); 1213 int height = glyph->fBounds.height();
1214 1214
1215 #if 0 1215 #if 0
1216 // Not checking the clip bounds might introduce a performance regression. H owever, its not 1216 // Not checking the clip bounds might introduce a performance regression. H owever, its not
1217 // clear if this is still true today with the larger tiles we use in Chrome. For repositionable 1217 // clear if this is still true today with the larger tiles we use in Chrome. For repositionable
1218 // blobs, we want to make sure we have all of the glyphs, so clipping them o ut is not ideal. 1218 // blobs, we want to make sure we have all of the glyphs, so clipping them o ut is not ideal.
1219 // We could store the cliprect in the key, but then we'd lose the ability to do integer scrolls 1219 // We could store the cliprect in the key, but then we'd lose the ability to do integer scrolls
1220 // TODO verify this 1220 // TODO verify this
1221 // check if we clipped out 1221 // check if we clipped out
1222 if (clipRect.quickReject(x, y, x + width, y + height)) { 1222 if (clipRect.quickReject(x, y, x + width, y + height)) {
1223 return; 1223 return;
1224 } 1224 }
1225 #endif 1225 #endif
1226 1226
1227 // If the glyph is too large we fall back to paths 1227 // If the glyph is too large we fall back to paths
1228 if (fCurrStrike->glyphTooLargeForAtlas(glyph)) { 1228 if (glyph->fTooLargeForAtlas) {
1229 this->appendGlyphPath(blob, glyph, scaler, vx, vy); 1229 this->appendGlyphPath(blob, glyph, scaler, vx, vy);
1230 return; 1230 return;
1231 } 1231 }
1232 1232
1233 GrMaskFormat format = glyph->fMaskFormat; 1233 GrMaskFormat format = glyph->fMaskFormat;
1234 1234
1235 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); 1235 PerSubRunInfo* subRun = &run.fSubRunInfo.back();
1236 if (run.fInitialized && subRun->fMaskFormat != format) { 1236 if (run.fInitialized && subRun->fMaskFormat != format) {
1237 subRun = &run.fSubRunInfo.push_back(); 1237 subRun = &run.fSubRunInfo.push_back();
1238 } 1238 }
(...skipping 18 matching lines...) Expand all
1257 GrFontScaler* scaler, 1257 GrFontScaler* scaler,
1258 const SkIRect& clipRect, 1258 const SkIRect& clipRect,
1259 SkScalar textRatio, const SkMatrix& viewM atrix) { 1259 SkScalar textRatio, const SkMatrix& viewM atrix) {
1260 Run& run = blob->fRuns[runIndex]; 1260 Run& run = blob->fRuns[runIndex];
1261 if (!fCurrStrike) { 1261 if (!fCurrStrike) {
1262 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); 1262 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler);
1263 run.fStrike.reset(SkRef(fCurrStrike)); 1263 run.fStrike.reset(SkRef(fCurrStrike));
1264 } 1264 }
1265 1265
1266 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); 1266 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler);
1267 if (!glyph || glyph->fBounds.isEmpty()) { 1267 if (!glyph) {
1268 return true; 1268 return true;
1269 } 1269 }
1270 1270
1271 // fallback to color glyph support 1271 // fallback to color glyph support
1272 if (kA8_GrMaskFormat != glyph->fMaskFormat) { 1272 if (kA8_GrMaskFormat != glyph->fMaskFormat) {
1273 return false; 1273 return false;
1274 } 1274 }
1275 1275
1276 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset); 1276 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft + SK_DistanceFieldInset);
1277 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset); 1277 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop + SK_DistanceFieldInset);
(...skipping 16 matching lines...) Expand all
1294 if (clipRect.quickReject(SkScalarTruncToInt(dstRect.left()), 1294 if (clipRect.quickReject(SkScalarTruncToInt(dstRect.left()),
1295 SkScalarTruncToInt(dstRect.top()), 1295 SkScalarTruncToInt(dstRect.top()),
1296 SkScalarTruncToInt(dstRect.right()), 1296 SkScalarTruncToInt(dstRect.right()),
1297 SkScalarTruncToInt(dstRect.bottom()))) { 1297 SkScalarTruncToInt(dstRect.bottom()))) {
1298 return true; 1298 return true;
1299 } 1299 }
1300 #endif 1300 #endif
1301 1301
1302 // TODO combine with the above 1302 // TODO combine with the above
1303 // If the glyph is too large we fall back to paths 1303 // If the glyph is too large we fall back to paths
1304 if (fCurrStrike->glyphTooLargeForAtlas(glyph)) { 1304 if (glyph->fTooLargeForAtlas) {
1305 this->appendGlyphPath(blob, glyph, scaler, SkScalarRoundToInt(sx - dx), 1305 this->appendGlyphPath(blob, glyph, scaler, SkScalarRoundToInt(sx - dx),
1306 SkScalarRoundToInt(sy - dy)); 1306 SkScalarRoundToInt(sy - dy));
1307 return true; 1307 return true;
1308 } 1308 }
1309 1309
1310 PerSubRunInfo* subRun = &run.fSubRunInfo.back(); 1310 PerSubRunInfo* subRun = &run.fSubRunInfo.back();
1311 SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat); 1311 SkASSERT(glyph->fMaskFormat == kA8_GrMaskFormat);
1312 subRun->fMaskFormat = kA8_GrMaskFormat; 1312 subRun->fMaskFormat = kA8_GrMaskFormat;
1313 1313
1314 size_t vertexStride = get_vertex_stride_df(kA8_GrMaskFormat, subRun->fUseLCD Text); 1314 size_t vertexStride = get_vertex_stride_df(kA8_GrMaskFormat, subRun->fUseLCD Text);
(...skipping 23 matching lines...) Expand all
1338 Run::SubRunInfo* subRun, 1338 Run::SubRunInfo* subRun,
1339 const SkRect& positions, GrCol or color, 1339 const SkRect& positions, GrCol or color,
1340 size_t vertexStride, bool useV ertexColor, 1340 size_t vertexStride, bool useV ertexColor,
1341 GrGlyph* glyph) { 1341 GrGlyph* glyph) {
1342 blob->fGlyphs[subRun->fGlyphEndIndex] = glyph; 1342 blob->fGlyphs[subRun->fGlyphEndIndex] = glyph;
1343 run->fVertexBounds.joinNonEmptyArg(positions); 1343 run->fVertexBounds.joinNonEmptyArg(positions);
1344 run->fColor = color; 1344 run->fColor = color;
1345 1345
1346 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->fVert exEndIndex); 1346 intptr_t vertex = reinterpret_cast<intptr_t>(blob->fVertices + subRun->fVert exEndIndex);
1347 1347
1348 // V0
1349 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
1350 position->set(positions.fLeft, positions.fTop);
1351 if (useVertexColor) { 1348 if (useVertexColor) {
1349 // V0
1350 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
1351 position->set(positions.fLeft, positions.fTop);
1352 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)) ; 1352 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)) ;
1353 *colorPtr = color; 1353 *colorPtr = color;
1354 } 1354 vertex += vertexStride;
1355 vertex += vertexStride;
1356 1355
1357 // V1 1356 // V1
1358 position = reinterpret_cast<SkPoint*>(vertex); 1357 position = reinterpret_cast<SkPoint*>(vertex);
1359 position->set(positions.fLeft, positions.fBottom); 1358 position->set(positions.fLeft, positions.fBottom);
1360 if (useVertexColor) { 1359 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
1361 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)) ;
1362 *colorPtr = color; 1360 *colorPtr = color;
1363 } 1361 vertex += vertexStride;
1364 vertex += vertexStride;
1365 1362
1366 // V2 1363 // V2
1367 position = reinterpret_cast<SkPoint*>(vertex); 1364 position = reinterpret_cast<SkPoint*>(vertex);
1368 position->set(positions.fRight, positions.fBottom); 1365 position->set(positions.fRight, positions.fBottom);
1369 if (useVertexColor) { 1366 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
1370 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)) ;
1371 *colorPtr = color; 1367 *colorPtr = color;
1372 } 1368 vertex += vertexStride;
1373 vertex += vertexStride;
1374 1369
1375 // V3 1370 // V3
1376 position = reinterpret_cast<SkPoint*>(vertex); 1371 position = reinterpret_cast<SkPoint*>(vertex);
1377 position->set(positions.fRight, positions.fTop); 1372 position->set(positions.fRight, positions.fTop);
1378 if (useVertexColor) { 1373 colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint));
1379 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint)) ;
1380 *colorPtr = color; 1374 *colorPtr = color;
1375 } else {
1376 // V0
1377 SkPoint* position = reinterpret_cast<SkPoint*>(vertex);
1378 position->set(positions.fLeft, positions.fTop);
1379 vertex += vertexStride;
1380
1381 // V1
1382 position = reinterpret_cast<SkPoint*>(vertex);
1383 position->set(positions.fLeft, positions.fBottom);
1384 vertex += vertexStride;
1385
1386 // V2
1387 position = reinterpret_cast<SkPoint*>(vertex);
1388 position->set(positions.fRight, positions.fBottom);
1389 vertex += vertexStride;
1390
1391 // V3
1392 position = reinterpret_cast<SkPoint*>(vertex);
1393 position->set(positions.fRight, positions.fTop);
1381 } 1394 }
1382 1395
1383 subRun->fGlyphEndIndex++; 1396 subRun->fGlyphEndIndex++;
1384 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; 1397 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph;
1385 } 1398 }
1386 1399
1387 class BitmapTextBatch : public GrBatch { 1400 class BitmapTextBatch : public GrBatch {
1388 public: 1401 public:
1389 typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable; 1402 typedef GrAtlasTextContext::DistanceAdjustTable DistanceAdjustTable;
1390 typedef GrAtlasTextContext::BitmapTextBlob Blob; 1403 typedef GrAtlasTextContext::BitmapTextBlob Blob;
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
2147 pipelineBuilder.setFromPaint(grPaint, rt, clip); 2160 pipelineBuilder.setFromPaint(grPaint, rt, clip);
2148 2161
2149 GrColor color = grPaint.getColor(); 2162 GrColor color = grPaint.getColor();
2150 for (int run = 0; run < cacheBlob->fRunCount; run++) { 2163 for (int run = 0; run < cacheBlob->fRunCount; run++) {
2151 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, 0, 0, sk Paint); 2164 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, 0, 0, sk Paint);
2152 } 2165 }
2153 2166
2154 // Now flush big glyphs 2167 // Now flush big glyphs
2155 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); 2168 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0);
2156 } 2169 }
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrBatchAtlas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698