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

Side by Side Diff: src/gpu/batches/GrDefaultPathRenderer.cpp

Issue 2035823002: Make GrClipMaskManager stateless and push GrPipelineBuilder construction downstack (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address code review comments Created 4 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 7
8 #include "GrDefaultPathRenderer.h" 8 #include "GrDefaultPathRenderer.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 bool fCoverageIgnored; 410 bool fCoverageIgnored;
411 bool fIsHairline; 411 bool fIsHairline;
412 }; 412 };
413 413
414 BatchTracker fBatch; 414 BatchTracker fBatch;
415 SkSTArray<1, Geometry, true> fGeoData; 415 SkSTArray<1, Geometry, true> fGeoData;
416 416
417 typedef GrVertexBatch INHERITED; 417 typedef GrVertexBatch INHERITED;
418 }; 418 };
419 419
420 bool GrDefaultPathRenderer::internalDrawPath(GrDrawTarget* target, 420 bool GrDefaultPathRenderer::internalDrawPath(GrDrawContext* drawContext,
421 GrPipelineBuilder* pipelineBuilder, 421 const GrPaint& paint,
422 const GrUserStencilSettings* userSt encilSettings,
422 const GrClip& clip, 423 const GrClip& clip,
423 GrColor color, 424 GrColor color,
424 const SkMatrix& viewMatrix, 425 const SkMatrix& viewMatrix,
425 const SkPath& path, 426 const SkPath& path,
426 const GrStyle& origStyle, 427 const GrStyle& origStyle,
427 bool stencilOnly) { 428 bool stencilOnly) {
428 const GrStyle* style = &origStyle; 429 const GrStyle* style = &origStyle;
429 430
430 SkScalar hairlineCoverage; 431 SkScalar hairlineCoverage;
431 uint8_t newCoverage = 0xff; 432 uint8_t newCoverage = 0xff;
432 bool isHairline = false; 433 bool isHairline = false;
433 if (IsStrokeHairlineOrEquivalent(*style, viewMatrix, &hairlineCoverage)) { 434 if (IsStrokeHairlineOrEquivalent(*style, viewMatrix, &hairlineCoverage)) {
434 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); 435 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff);
435 style = &GrStyle::SimpleHairline(); 436 style = &GrStyle::SimpleHairline();
436 isHairline = true; 437 isHairline = true;
437 } else { 438 } else {
438 SkASSERT(style->isSimpleFill()); 439 SkASSERT(style->isSimpleFill());
439 } 440 }
440 441
441 // Save the current xp on the draw state so we can reset it if needed
442 const GrXPFactory* xpFactory = pipelineBuilder->getXPFactory();
443 SkAutoTUnref<const GrXPFactory> backupXPFactory(SkSafeRef(xpFactory));
444 // face culling doesn't make sense here
445 SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace() );
446
447 int passCount = 0; 442 int passCount = 0;
448 const GrUserStencilSettings* passes[3]; 443 const GrUserStencilSettings* passes[3];
449 GrPipelineBuilder::DrawFace drawFace[3]; 444 GrPipelineBuilder::DrawFace drawFace[3];
450 bool reverse = false; 445 bool reverse = false;
451 bool lastPassIsBounds; 446 bool lastPassIsBounds;
452 447
453 if (isHairline) { 448 if (isHairline) {
454 passCount = 1; 449 passCount = 1;
455 if (stencilOnly) { 450 if (stencilOnly) {
456 passes[0] = &gDirectToStencil; 451 passes[0] = &gDirectToStencil;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 SkDEBUGFAIL("Unknown path fFill!"); 528 SkDEBUGFAIL("Unknown path fFill!");
534 return false; 529 return false;
535 } 530 }
536 } 531 }
537 } 532 }
538 533
539 SkScalar tol = GrPathUtils::kDefaultTolerance; 534 SkScalar tol = GrPathUtils::kDefaultTolerance;
540 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, pat h.getBounds()); 535 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, pat h.getBounds());
541 536
542 SkRect devBounds; 537 SkRect devBounds;
543 GetPathDevBounds(path, pipelineBuilder->getRenderTarget(), viewMatrix, &devB ounds); 538 GetPathDevBounds(path, drawContext->width(), drawContext->height(), viewMatr ix, &devBounds);
544 539
545 for (int p = 0; p < passCount; ++p) { 540 for (int p = 0; p < passCount; ++p) {
546 pipelineBuilder->setDrawFace(drawFace[p]);
547 if (passes[p]) {
548 pipelineBuilder->setUserStencil(passes[p]);
549 }
550
551 if (lastPassIsBounds && (p == passCount-1)) { 541 if (lastPassIsBounds && (p == passCount-1)) {
552 // Reset the XP Factory on pipelineBuilder
553 pipelineBuilder->setXPFactory(backupXPFactory);
554 SkRect bounds; 542 SkRect bounds;
555 SkMatrix localMatrix = SkMatrix::I(); 543 SkMatrix localMatrix = SkMatrix::I();
556 if (reverse) { 544 if (reverse) {
557 SkASSERT(pipelineBuilder->getRenderTarget());
558 // draw over the dev bounds (which will be the whole dst surface for inv fill). 545 // draw over the dev bounds (which will be the whole dst surface for inv fill).
559 bounds = devBounds; 546 bounds = devBounds;
560 SkMatrix vmi; 547 SkMatrix vmi;
561 // mapRect through persp matrix may not be correct 548 // mapRect through persp matrix may not be correct
562 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { 549 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) {
563 vmi.mapRect(&bounds); 550 vmi.mapRect(&bounds);
564 } else { 551 } else {
565 if (!viewMatrix.invert(&localMatrix)) { 552 if (!viewMatrix.invert(&localMatrix)) {
566 return false; 553 return false;
567 } 554 }
568 } 555 }
569 } else { 556 } else {
570 bounds = path.getBounds(); 557 bounds = path.getBounds();
571 } 558 }
572 const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? S kMatrix::I() : 559 const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? S kMatrix::I() :
573 v iewMatrix; 560 v iewMatrix;
574 SkAutoTUnref<GrDrawBatch> batch( 561 SkAutoTUnref<GrDrawBatch> batch(
575 GrRectBatchFactory::CreateNonAAFill(color, viewM, bounds, nu llptr, 562 GrRectBatchFactory::CreateNonAAFill(color, viewM, bounds, nu llptr,
576 &localMatrix)); 563 &localMatrix));
577 target->drawBatch(*pipelineBuilder, clip, batch); 564
578 } else { 565 GrPipelineBuilder pipelineBuilder(paint, drawContext->isUnifiedMulti sampled());
579 if (passCount > 1) { 566 pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget());
580 pipelineBuilder->setDisableColorXPFactory(); 567 pipelineBuilder.setDrawFace(drawFace[p]);
568 if (passes[p]) {
569 pipelineBuilder.setUserStencil(passes[p]);
570 } else {
571 pipelineBuilder.setUserStencil(userStencilSettings);
581 } 572 }
582 573
574 drawContext->drawBatch(pipelineBuilder, clip, batch);
575 } else {
583 DefaultPathBatch::Geometry geometry; 576 DefaultPathBatch::Geometry geometry;
584 geometry.fColor = color; 577 geometry.fColor = color;
585 geometry.fPath = path; 578 geometry.fPath = path;
586 geometry.fTolerance = srcSpaceTol; 579 geometry.fTolerance = srcSpaceTol;
587 580
588 SkAutoTUnref<GrDrawBatch> batch(DefaultPathBatch::Create(geometry, n ewCoverage, 581 SkAutoTUnref<GrDrawBatch> batch(DefaultPathBatch::Create(geometry, n ewCoverage,
589 viewMatrix, isHairline, 582 viewMatrix, isHairline,
590 devBounds)) ; 583 devBounds)) ;
591 584
592 target->drawBatch(*pipelineBuilder, clip, batch); 585 GrPipelineBuilder pipelineBuilder(paint, drawContext->isUnifiedMulti sampled());
586 pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget());
587 pipelineBuilder.setDrawFace(drawFace[p]);
588 if (passes[p]) {
589 pipelineBuilder.setUserStencil(passes[p]);
590 } else {
591 pipelineBuilder.setUserStencil(userStencilSettings);
592 }
593 if (passCount > 1) {
594 pipelineBuilder.setDisableColorXPFactory();
595 }
596
597 drawContext->drawBatch(pipelineBuilder, clip, batch);
593 } 598 }
594 } 599 }
595 return true; 600 return true;
596 } 601 }
597 602
598 bool GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { 603 bool GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
599 // this class can draw any path with any simple fill style but doesn't do an y anti-aliasing. 604 // this class can draw any path with any simple fill style but doesn't do an y anti-aliasing.
600 return !args.fAntiAlias && 605 return !args.fAntiAlias &&
601 (args.fStyle->isSimpleFill() || IsStrokeHairlineOrEquivalent(*args.fS tyle, 606 (args.fStyle->isSimpleFill() || IsStrokeHairlineOrEquivalent(*args.fS tyle,
602 *args.fV iewMatrix, 607 *args.fV iewMatrix,
603 nullptr) ); 608 nullptr) );
604 } 609 }
605 610
606 bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) { 611 bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) {
607 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrDefaultPathRende rer::onDrawPath"); 612 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(),
608 return this->internalDrawPath(args.fTarget, 613 "GrDefaultPathRenderer::onDrawPath");
609 args.fPipelineBuilder, 614 return this->internalDrawPath(args.fDrawContext,
615 *args.fPaint,
616 args.fUserStencilSettings,
610 *args.fClip, 617 *args.fClip,
611 args.fColor, 618 args.fColor,
612 *args.fViewMatrix, 619 *args.fViewMatrix,
613 *args.fPath, 620 *args.fPath,
614 *args.fStyle, 621 *args.fStyle,
615 false); 622 false);
616 } 623 }
617 624
618 void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) { 625 void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
619 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(),"GrDefaultPathRender er::onStencilPath"); 626 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(),
627 "GrDefaultPathRenderer::onStencilPath");
620 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType()); 628 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType());
621 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType()); 629 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType());
622 this->internalDrawPath(args.fTarget, args.fPipelineBuilder, *args.fClip, GrC olor_WHITE, 630
623 *args.fViewMatrix, *args.fPath, GrStyle::SimpleFill() , true); 631 GrPaint paint;
632 paint.setXPFactory(GrDisableColorXPFactory::Create());
bungeman-skia 2016/06/03 23:57:03 leak
633 paint.setAntiAlias(args.fIsAA);
634
635 this->internalDrawPath(args.fDrawContext,
636 paint,
637 &GrUserStencilSettings::kUnused,
638 *args.fClip,
639 GrColor_WHITE,
640 *args.fViewMatrix,
641 *args.fPath,
642 GrStyle::SimpleFill(),
643 true);
624 } 644 }
625 645
626 //////////////////////////////////////////////////////////////////////////////// /////////////////// 646 //////////////////////////////////////////////////////////////////////////////// ///////////////////
627 647
628 #ifdef GR_TEST_UTILS 648 #ifdef GR_TEST_UTILS
629 649
630 DRAW_BATCH_TEST_DEFINE(DefaultPathBatch) { 650 DRAW_BATCH_TEST_DEFINE(DefaultPathBatch) {
631 GrColor color = GrRandomColor(random); 651 GrColor color = GrRandomColor(random);
632 SkMatrix viewMatrix = GrTest::TestMatrix(random); 652 SkMatrix viewMatrix = GrTest::TestMatrix(random);
633 653
(...skipping 11 matching lines...) Expand all
645 geometry.fColor = color; 665 geometry.fColor = color;
646 geometry.fPath = path; 666 geometry.fPath = path;
647 geometry.fTolerance = srcSpaceTol; 667 geometry.fTolerance = srcSpaceTol;
648 668
649 viewMatrix.mapRect(&bounds); 669 viewMatrix.mapRect(&bounds);
650 uint8_t coverage = GrRandomCoverage(random); 670 uint8_t coverage = GrRandomCoverage(random);
651 return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds ); 671 return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds );
652 } 672 }
653 673
654 #endif 674 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698