OLD | NEW |
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 Loading... |
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 GrStyle& origStyle, | 425 const GrStrokeInfo& origStroke, |
426 bool stencilOnly) { | 426 bool stencilOnly) { |
427 const GrStyle* style = &origStyle; | 427 SkTCopyOnFirstWrite<GrStrokeInfo> stroke(origStroke); |
428 | 428 |
429 SkScalar hairlineCoverage; | 429 SkScalar hairlineCoverage; |
430 uint8_t newCoverage = 0xff; | 430 uint8_t newCoverage = 0xff; |
431 bool isHairline = false; | 431 if (IsStrokeHairlineOrEquivalent(*stroke, viewMatrix, &hairlineCoverage)) { |
432 if (IsStrokeHairlineOrEquivalent(*style, viewMatrix, &hairlineCoverage)) { | |
433 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); | 432 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
434 style = &GrStyle::SimpleHairline(); | 433 |
435 isHairline = true; | 434 if (!stroke->isHairlineStyle()) { |
436 } else { | 435 stroke.writable()->setHairlineStyle(); |
437 SkASSERT(style->isSimpleFill()); | 436 } |
438 } | 437 } |
439 | 438 |
| 439 const bool isHairline = stroke->isHairlineStyle(); |
| 440 |
440 // Save the current xp on the draw state so we can reset it if needed | 441 // Save the current xp on the draw state so we can reset it if needed |
441 const GrXPFactory* xpFactory = pipelineBuilder->getXPFactory(); | 442 const GrXPFactory* xpFactory = pipelineBuilder->getXPFactory(); |
442 SkAutoTUnref<const GrXPFactory> backupXPFactory(SkSafeRef(xpFactory)); | 443 SkAutoTUnref<const GrXPFactory> backupXPFactory(SkSafeRef(xpFactory)); |
443 // face culling doesn't make sense here | 444 // face culling doesn't make sense here |
444 SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace()
); | 445 SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace()
); |
445 | 446 |
446 int passCount = 0; | 447 int passCount = 0; |
447 const GrStencilSettings* passes[3]; | 448 const GrStencilSettings* passes[3]; |
448 GrPipelineBuilder::DrawFace drawFace[3]; | 449 GrPipelineBuilder::DrawFace drawFace[3]; |
449 bool reverse = false; | 450 bool reverse = false; |
450 bool lastPassIsBounds; | 451 bool lastPassIsBounds; |
451 | 452 |
452 if (isHairline) { | 453 if (isHairline) { |
453 passCount = 1; | 454 passCount = 1; |
454 if (stencilOnly) { | 455 if (stencilOnly) { |
455 passes[0] = &gDirectToStencil; | 456 passes[0] = &gDirectToStencil; |
456 } else { | 457 } else { |
457 passes[0] = nullptr; | 458 passes[0] = nullptr; |
458 } | 459 } |
459 lastPassIsBounds = false; | 460 lastPassIsBounds = false; |
460 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; | 461 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; |
461 } else { | 462 } else { |
462 if (single_pass_path(path, style->strokeRec())) { | 463 if (single_pass_path(path, *stroke)) { |
463 passCount = 1; | 464 passCount = 1; |
464 if (stencilOnly) { | 465 if (stencilOnly) { |
465 passes[0] = &gDirectToStencil; | 466 passes[0] = &gDirectToStencil; |
466 } else { | 467 } else { |
467 passes[0] = nullptr; | 468 passes[0] = nullptr; |
468 } | 469 } |
469 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; | 470 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; |
470 lastPassIsBounds = false; | 471 lastPassIsBounds = false; |
471 } else { | 472 } else { |
472 switch (path.getFillType()) { | 473 switch (path.getFillType()) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 viewMatrix,
isHairline, | 589 viewMatrix,
isHairline, |
589 devBounds))
; | 590 devBounds))
; |
590 | 591 |
591 target->drawBatch(*pipelineBuilder, batch); | 592 target->drawBatch(*pipelineBuilder, batch); |
592 } | 593 } |
593 } | 594 } |
594 return true; | 595 return true; |
595 } | 596 } |
596 | 597 |
597 bool GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { | 598 bool GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
598 // this class can draw any path with any simple fill style but doesn't do an
y anti-aliasing. | 599 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. |
599 return !args.fAntiAlias && | 600 return !args.fAntiAlias && (args.fStroke->isFillStyle() || |
600 (args.fStyle->isSimpleFill() || IsStrokeHairlineOrEquivalent(*args.fS
tyle, | 601 IsStrokeHairlineOrEquivalent(*args.fStroke, *arg
s.fViewMatrix, |
601 *args.fV
iewMatrix, | 602 nullptr)); |
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.fStyle, | 612 *args.fStroke, |
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, GrStyle::SimpleFill(), true); | 621 *args.fPath, GrStrokeInfo::FillInfo(), 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 GrStyle style(SkStrokeRec::kHairline_InitStyle); | 634 GrStrokeInfo stroke(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 |
OLD | NEW |