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

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

Issue 1494083003: Reduce calls sites where both the GrDrawContext & GrRenderTarget are both passed (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years 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 | « src/gpu/GrAtlasTextContext.h ('k') | src/gpu/GrDrawContext.cpp » ('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 "GrBlurUtils.h" 9 #include "GrBlurUtils.h"
10 #include "GrDrawContext.h" 10 #include "GrDrawContext.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 283
284 inline SkGlyphCache* GrAtlasTextContext::setupCache(GrAtlasTextBlob::Run* run, 284 inline SkGlyphCache* GrAtlasTextContext::setupCache(GrAtlasTextBlob::Run* run,
285 const SkPaint& skPaint, 285 const SkPaint& skPaint,
286 const SkMatrix* viewMatrix, 286 const SkMatrix* viewMatrix,
287 bool noGamma) { 287 bool noGamma) {
288 skPaint.getScalerContextDescriptor(&run->fDescriptor, fSurfaceProps, viewMat rix, noGamma); 288 skPaint.getScalerContextDescriptor(&run->fDescriptor, fSurfaceProps, viewMat rix, noGamma);
289 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); 289 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface()));
290 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc()) ; 290 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc()) ;
291 } 291 }
292 292
293 void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc, GrRenderTarget* rt, 293 void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc,
294 const GrClip& clip, const SkPaint& skPaint , 294 const GrClip& clip, const SkPaint& skPaint ,
295 const SkMatrix& viewMatrix, const SkTextBl ob* blob, 295 const SkMatrix& viewMatrix, const SkTextBl ob* blob,
296 SkScalar x, SkScalar y, 296 SkScalar x, SkScalar y,
297 SkDrawFilter* drawFilter, const SkIRect& c lipBounds) { 297 SkDrawFilter* drawFilter, const SkIRect& c lipBounds) {
298 // If we have been abandoned, then don't draw 298 // If we have been abandoned, then don't draw
299 if (fContext->abandoned()) { 299 if (fContext->abandoned()) {
300 return; 300 return;
301 } 301 }
302 302
303 SkAutoTUnref<GrAtlasTextBlob> cacheBlob; 303 SkAutoTUnref<GrAtlasTextBlob> cacheBlob;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 if (canCache) { 378 if (canCache) {
379 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s kPaint, 379 cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, s kPaint,
380 GrAtlasTextBatch::kGr ayTextVASize))); 380 GrAtlasTextBatch::kGr ayTextVASize)));
381 } else { 381 } else {
382 cacheBlob.reset(fCache->createBlob(blob, GrAtlasTextBatch::kGrayText VASize)); 382 cacheBlob.reset(fCache->createBlob(blob, GrAtlasTextBatch::kGrayText VASize));
383 } 383 }
384 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat rix, 384 this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMat rix,
385 blob, x, y, drawFilter, clip); 385 blob, x, y, drawFilter, clip);
386 } 386 }
387 387
388 this->flush(blob, cacheBlob, dc, rt, skPaint, grPaint, drawFilter, 388 this->flush(blob, cacheBlob, dc, skPaint, grPaint, drawFilter,
389 clip, viewMatrix, clipBounds, x, y, transX, transY); 389 clip, viewMatrix, clipBounds, x, y, transX, transY);
390 } 390 }
391 391
392 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint, 392 inline bool GrAtlasTextContext::canDrawAsDistanceFields(const SkPaint& skPaint,
393 const SkMatrix& viewMatr ix) { 393 const SkMatrix& viewMatr ix) {
394 // TODO: support perspective (need getMaxScale replacement) 394 // TODO: support perspective (need getMaxScale replacement)
395 if (viewMatrix.hasPerspective()) { 395 if (viewMatrix.hasPerspective()) {
396 return false; 396 return false;
397 } 397 }
398 398
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBatch::kGrayTextVASi ze); 711 blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBatch::kGrayTextVASi ze);
712 blob->fViewMatrix = viewMatrix; 712 blob->fViewMatrix = viewMatrix;
713 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false); 713 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, &viewMa trix, false);
714 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text, 714 this->internalDrawBMPPosText(blob, 0, cache, skPaint, paint.getColor(), viewMatrix, text,
715 byteLength, pos, scalarsPerPosition, offset ); 715 byteLength, pos, scalarsPerPosition, offset );
716 SkGlyphCache::AttachCache(cache); 716 SkGlyphCache::AttachCache(cache);
717 } 717 }
718 return blob; 718 return blob;
719 } 719 }
720 720
721 void GrAtlasTextContext::onDrawText(GrDrawContext* dc, GrRenderTarget* rt, 721 void GrAtlasTextContext::onDrawText(GrDrawContext* dc,
722 const GrClip& clip, 722 const GrClip& clip,
723 const GrPaint& paint, const SkPaint& skPaint , 723 const GrPaint& paint, const SkPaint& skPaint ,
724 const SkMatrix& viewMatrix, 724 const SkMatrix& viewMatrix,
725 const char text[], size_t byteLength, 725 const char text[], size_t byteLength,
726 SkScalar x, SkScalar y, const SkIRect& regio nClipBounds) { 726 SkScalar x, SkScalar y, const SkIRect& regio nClipBounds) {
727 SkAutoTUnref<GrAtlasTextBlob> blob( 727 SkAutoTUnref<GrAtlasTextBlob> blob(
728 this->createDrawTextBlob(clip, paint, skPaint, viewMatrix, 728 this->createDrawTextBlob(clip, paint, skPaint, viewMatrix,
729 text, byteLength, x, y, regionClipBounds)); 729 text, byteLength, x, y, regionClipBounds));
730 this->flush(blob, dc, rt, skPaint, paint, clip, regionClipBounds); 730 this->flush(blob, dc, skPaint, paint, clip, regionClipBounds);
731 } 731 }
732 732
733 void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc, GrRenderTarget* rt, 733 void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc,
734 const GrClip& clip, 734 const GrClip& clip,
735 const GrPaint& paint, const SkPaint& skPa int, 735 const GrPaint& paint, const SkPaint& skPa int,
736 const SkMatrix& viewMatrix, 736 const SkMatrix& viewMatrix,
737 const char text[], size_t byteLength, 737 const char text[], size_t byteLength,
738 const SkScalar pos[], int scalarsPerPosit ion, 738 const SkScalar pos[], int scalarsPerPosit ion,
739 const SkPoint& offset, const SkIRect& reg ionClipBounds) { 739 const SkPoint& offset, const SkIRect& reg ionClipBounds) {
740 SkAutoTUnref<GrAtlasTextBlob> blob( 740 SkAutoTUnref<GrAtlasTextBlob> blob(
741 this->createDrawPosTextBlob(clip, paint, skPaint, viewMatrix, 741 this->createDrawPosTextBlob(clip, paint, skPaint, viewMatrix,
742 text, byteLength, 742 text, byteLength,
743 pos, scalarsPerPosition, 743 pos, scalarsPerPosition,
744 offset, regionClipBounds)); 744 offset, regionClipBounds));
745 745
746 this->flush(blob, dc, rt, skPaint, paint, clip, regionClipBounds); 746 this->flush(blob, dc, skPaint, paint, clip, regionClipBounds);
747 } 747 }
748 748
749 void GrAtlasTextContext::internalDrawBMPText(GrAtlasTextBlob* blob, int runIndex , 749 void GrAtlasTextContext::internalDrawBMPText(GrAtlasTextBlob* blob, int runIndex ,
750 SkGlyphCache* cache, const SkPaint& skPaint, 750 SkGlyphCache* cache, const SkPaint& skPaint,
751 GrColor color, 751 GrColor color,
752 const SkMatrix& viewMatrix, 752 const SkMatrix& viewMatrix,
753 const char text[], size_t byteLengt h, 753 const char text[], size_t byteLengt h,
754 SkScalar x, SkScalar y) { 754 SkScalar x, SkScalar y) {
755 SkASSERT(byteLength == 0 || text != nullptr); 755 SkASSERT(byteLength == 0 || text != nullptr);
756 756
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 } 1287 }
1288 1288
1289 GrBlurUtils::drawPathWithMaskFilter(fContext, dc, clip, bigGlyph.fPath, 1289 GrBlurUtils::drawPathWithMaskFilter(fContext, dc, clip, bigGlyph.fPath,
1290 skPaint, ctm, nullptr, clipBounds, f alse); 1290 skPaint, ctm, nullptr, clipBounds, f alse);
1291 } 1291 }
1292 } 1292 }
1293 1293
1294 void GrAtlasTextContext::flush(const SkTextBlob* blob, 1294 void GrAtlasTextContext::flush(const SkTextBlob* blob,
1295 GrAtlasTextBlob* cacheBlob, 1295 GrAtlasTextBlob* cacheBlob,
1296 GrDrawContext* dc, 1296 GrDrawContext* dc,
1297 GrRenderTarget* rt,
1298 const SkPaint& skPaint, 1297 const SkPaint& skPaint,
1299 const GrPaint& grPaint, 1298 const GrPaint& grPaint,
1300 SkDrawFilter* drawFilter, 1299 SkDrawFilter* drawFilter,
1301 const GrClip& clip, 1300 const GrClip& clip,
1302 const SkMatrix& viewMatrix, 1301 const SkMatrix& viewMatrix,
1303 const SkIRect& clipBounds, 1302 const SkIRect& clipBounds,
1304 SkScalar x, SkScalar y, 1303 SkScalar x, SkScalar y,
1305 SkScalar transX, SkScalar transY) { 1304 SkScalar transX, SkScalar transY) {
1306 // We loop through the runs of the blob, flushing each. If any run is too l arge, then we flush 1305 // We loop through the runs of the blob, flushing each. If any run is too l arge, then we flush
1307 // it as paths 1306 // it as paths
1308 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); 1307 GrPipelineBuilder pipelineBuilder(grPaint, dc->accessRenderTarget(), clip);
1309 1308
1310 GrColor color = grPaint.getColor(); 1309 GrColor color = grPaint.getColor();
1311 1310
1312 SkTextBlobRunIterator it(blob); 1311 SkTextBlobRunIterator it(blob);
1313 for (int run = 0; !it.done(); it.next(), run++) { 1312 for (int run = 0; !it.done(); it.next(), run++) {
1314 if (cacheBlob->fRuns[run].fDrawAsPaths) { 1313 if (cacheBlob->fRuns[run].fDrawAsPaths) {
1315 this->flushRunAsPaths(dc, it, clip, skPaint, 1314 this->flushRunAsPaths(dc, it, clip, skPaint,
1316 drawFilter, viewMatrix, clipBounds, x, y); 1315 drawFilter, viewMatrix, clipBounds, x, y);
1317 continue; 1316 continue;
1318 } 1317 }
1319 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY); 1318 cacheBlob->fRuns[run].fVertexBounds.offset(transX, transY);
1320 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, 1319 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color,
1321 transX, transY, skPaint); 1320 transX, transY, skPaint);
1322 } 1321 }
1323 1322
1324 // Now flush big glyphs 1323 // Now flush big glyphs
1325 this->flushBigGlyphs(cacheBlob, dc, clip, skPaint, transX, transY, clipBound s); 1324 this->flushBigGlyphs(cacheBlob, dc, clip, skPaint, transX, transY, clipBound s);
1326 } 1325 }
1327 1326
1328 void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob, 1327 void GrAtlasTextContext::flush(GrAtlasTextBlob* cacheBlob,
1329 GrDrawContext* dc, 1328 GrDrawContext* dc,
1330 GrRenderTarget* rt,
1331 const SkPaint& skPaint, 1329 const SkPaint& skPaint,
1332 const GrPaint& grPaint, 1330 const GrPaint& grPaint,
1333 const GrClip& clip, 1331 const GrClip& clip,
1334 const SkIRect& clipBounds) { 1332 const SkIRect& clipBounds) {
1335 GrPipelineBuilder pipelineBuilder(grPaint, rt, clip); 1333 GrPipelineBuilder pipelineBuilder(grPaint, dc->accessRenderTarget(), clip);
1336 1334
1337 GrColor color = grPaint.getColor(); 1335 GrColor color = grPaint.getColor();
1338 for (int run = 0; run < cacheBlob->fRunCount; run++) { 1336 for (int run = 0; run < cacheBlob->fRunCount; run++) {
1339 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPain t); 1337 this->flushRun(dc, &pipelineBuilder, cacheBlob, run, color, 0, 0, skPain t);
1340 } 1338 }
1341 1339
1342 // Now flush big glyphs 1340 // Now flush big glyphs
1343 this->flushBigGlyphs(cacheBlob, dc, clip, skPaint, 0, 0, clipBounds); 1341 this->flushBigGlyphs(cacheBlob, dc, clip, skPaint, 0, 0, clipBounds);
1344 } 1342 }
1345 1343
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 gTextContext->createDrawTextBlob(clip, grPaint, skPaint, viewMatrix, text, 1387 gTextContext->createDrawTextBlob(clip, grPaint, skPaint, viewMatrix, text,
1390 static_cast<size_t>(textLen), 0, 0, noClip)); 1388 static_cast<size_t>(textLen), 0, 0, noClip));
1391 1389
1392 SkScalar transX = static_cast<SkScalar>(random->nextU()); 1390 SkScalar transX = static_cast<SkScalar>(random->nextU());
1393 SkScalar transY = static_cast<SkScalar>(random->nextU()); 1391 SkScalar transY = static_cast<SkScalar>(random->nextU());
1394 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ; 1392 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0] ;
1395 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint); 1393 return gTextContext->createBatch(blob, info, textLen, 0, 0, color, transX, t ransY, skPaint);
1396 } 1394 }
1397 1395
1398 #endif 1396 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | src/gpu/GrDrawContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698