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

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

Issue 1957363002: Replace GrStrokeInfo with GrStyle. (Closed) Base URL: https://chromium.googlesource.com/skia.git@resscale
Patch Set: Fix issue where hairlines were going to MSAAPathRenderer Created 4 years, 7 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(GrDrawTarget* target,
421 GrPipelineBuilder* pipelineBuilder, 421 GrPipelineBuilder* pipelineBuilder,
422 GrColor color, 422 GrColor color,
423 const SkMatrix& viewMatrix, 423 const SkMatrix& viewMatrix,
424 const SkPath& path, 424 const SkPath& path,
425 const GrStrokeInfo& origStroke, 425 const GrStyle& origStyle,
426 bool stencilOnly) { 426 bool stencilOnly) {
427 SkTCopyOnFirstWrite<GrStrokeInfo> stroke(origStroke); 427 const GrStyle* style = &origStyle;
428 428
429 SkScalar hairlineCoverage; 429 SkScalar hairlineCoverage;
430 uint8_t newCoverage = 0xff; 430 uint8_t newCoverage = 0xff;
431 if (IsStrokeHairlineOrEquivalent(*stroke, viewMatrix, &hairlineCoverage)) { 431 bool isHairline = false;
432 if (IsStrokeHairlineOrEquivalent(*style, viewMatrix, &hairlineCoverage)) {
432 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); 433 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff);
433 434 style = &GrStyle::SimpleHairline();
434 if (!stroke->isHairlineStyle()) { 435 isHairline = true;
435 stroke.writable()->setHairlineStyle(); 436 } else {
436 } 437 SkASSERT(style->isSimpleFill());
437 } 438 }
438 439
439 const bool isHairline = stroke->isHairlineStyle();
440
441 // Save the current xp on the draw state so we can reset it if needed 440 // Save the current xp on the draw state so we can reset it if needed
442 const GrXPFactory* xpFactory = pipelineBuilder->getXPFactory(); 441 const GrXPFactory* xpFactory = pipelineBuilder->getXPFactory();
443 SkAutoTUnref<const GrXPFactory> backupXPFactory(SkSafeRef(xpFactory)); 442 SkAutoTUnref<const GrXPFactory> backupXPFactory(SkSafeRef(xpFactory));
444 // face culling doesn't make sense here 443 // face culling doesn't make sense here
445 SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace() ); 444 SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace() );
446 445
447 int passCount = 0; 446 int passCount = 0;
448 const GrStencilSettings* passes[3]; 447 const GrStencilSettings* passes[3];
449 GrPipelineBuilder::DrawFace drawFace[3]; 448 GrPipelineBuilder::DrawFace drawFace[3];
450 bool reverse = false; 449 bool reverse = false;
451 bool lastPassIsBounds; 450 bool lastPassIsBounds;
452 451
453 if (isHairline) { 452 if (isHairline) {
454 passCount = 1; 453 passCount = 1;
455 if (stencilOnly) { 454 if (stencilOnly) {
456 passes[0] = &gDirectToStencil; 455 passes[0] = &gDirectToStencil;
457 } else { 456 } else {
458 passes[0] = nullptr; 457 passes[0] = nullptr;
459 } 458 }
460 lastPassIsBounds = false; 459 lastPassIsBounds = false;
461 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; 460 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace;
462 } else { 461 } else {
463 if (single_pass_path(path, *stroke)) { 462 if (single_pass_path(path, style->strokeRec())) {
464 passCount = 1; 463 passCount = 1;
465 if (stencilOnly) { 464 if (stencilOnly) {
466 passes[0] = &gDirectToStencil; 465 passes[0] = &gDirectToStencil;
467 } else { 466 } else {
468 passes[0] = nullptr; 467 passes[0] = nullptr;
469 } 468 }
470 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; 469 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace;
471 lastPassIsBounds = false; 470 lastPassIsBounds = false;
472 } else { 471 } else {
473 switch (path.getFillType()) { 472 switch (path.getFillType()) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 viewMatrix, isHairline, 588 viewMatrix, isHairline,
590 devBounds)) ; 589 devBounds)) ;
591 590
592 target->drawBatch(*pipelineBuilder, batch); 591 target->drawBatch(*pipelineBuilder, batch);
593 } 592 }
594 } 593 }
595 return true; 594 return true;
596 } 595 }
597 596
598 bool GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { 597 bool GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const {
599 // this class can draw any path with any fill but doesn't do any anti-aliasi ng. 598 // this class can draw any path with any simple fill style but doesn't do an y anti-aliasing.
600 return !args.fAntiAlias && (args.fStroke->isFillStyle() || 599 return !args.fAntiAlias &&
601 IsStrokeHairlineOrEquivalent(*args.fStroke, *arg s.fViewMatrix, 600 (args.fStyle->isSimpleFill() || IsStrokeHairlineOrEquivalent(*args.fS tyle,
602 nullptr)); 601 *args.fV iewMatrix,
602 nullptr) );
603 } 603 }
604 604
605 bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) { 605 bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) {
606 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrDefaultPathRende rer::onDrawPath"); 606 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrDefaultPathRende rer::onDrawPath");
607 return this->internalDrawPath(args.fTarget, 607 return this->internalDrawPath(args.fTarget,
608 args.fPipelineBuilder, 608 args.fPipelineBuilder,
609 args.fColor, 609 args.fColor,
610 *args.fViewMatrix, 610 *args.fViewMatrix,
611 *args.fPath, 611 *args.fPath,
612 *args.fStroke, 612 *args.fStyle,
613 false); 613 false);
614 } 614 }
615 615
616 void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) { 616 void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
617 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(),"GrDefaultPathRender er::onStencilPath"); 617 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(),"GrDefaultPathRender er::onStencilPath");
618 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType()); 618 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType());
619 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType()); 619 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType());
620 this->internalDrawPath(args.fTarget, args.fPipelineBuilder, GrColor_WHITE, * args.fViewMatrix, 620 this->internalDrawPath(args.fTarget, args.fPipelineBuilder, GrColor_WHITE, * args.fViewMatrix,
621 *args.fPath, GrStrokeInfo::FillInfo(), true); 621 *args.fPath, GrStyle::SimpleFill(), true);
622 } 622 }
623 623
624 //////////////////////////////////////////////////////////////////////////////// /////////////////// 624 //////////////////////////////////////////////////////////////////////////////// ///////////////////
625 625
626 #ifdef GR_TEST_UTILS 626 #ifdef GR_TEST_UTILS
627 627
628 DRAW_BATCH_TEST_DEFINE(DefaultPathBatch) { 628 DRAW_BATCH_TEST_DEFINE(DefaultPathBatch) {
629 GrColor color = GrRandomColor(random); 629 GrColor color = GrRandomColor(random);
630 SkMatrix viewMatrix = GrTest::TestMatrix(random); 630 SkMatrix viewMatrix = GrTest::TestMatrix(random);
631 631
632 // For now just hairlines because the other types of draws require two batch es. 632 // For now just hairlines because the other types of draws require two batch es.
633 // TODO we should figure out a way to combine the stencil and cover steps in to one batch 633 // TODO we should figure out a way to combine the stencil and cover steps in to one batch
634 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); 634 GrStyle style(SkStrokeRec::kHairline_InitStyle);
635 SkPath path = GrTest::TestPath(random); 635 SkPath path = GrTest::TestPath(random);
636 636
637 // Compute srcSpaceTol 637 // Compute srcSpaceTol
638 SkRect bounds = path.getBounds(); 638 SkRect bounds = path.getBounds();
639 SkScalar tol = GrPathUtils::kDefaultTolerance; 639 SkScalar tol = GrPathUtils::kDefaultTolerance;
640 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bou nds); 640 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bou nds);
641 641
642 DefaultPathBatch::Geometry geometry; 642 DefaultPathBatch::Geometry geometry;
643 geometry.fColor = color; 643 geometry.fColor = color;
644 geometry.fPath = path; 644 geometry.fPath = path;
645 geometry.fTolerance = srcSpaceTol; 645 geometry.fTolerance = srcSpaceTol;
646 646
647 viewMatrix.mapRect(&bounds); 647 viewMatrix.mapRect(&bounds);
648 uint8_t coverage = GrRandomCoverage(random); 648 uint8_t coverage = GrRandomCoverage(random);
649 return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds ); 649 return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds );
650 } 650 }
651 651
652 #endif 652 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698