OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "GrMSAAPathRenderer.h" | 8 #include "GrMSAAPathRenderer.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "glsl/GrGLSLUtil.h" | 22 #include "glsl/GrGLSLUtil.h" |
23 #include "gl/GrGLVaryingHandler.h" | 23 #include "gl/GrGLVaryingHandler.h" |
24 #include "batches/GrRectBatchFactory.h" | 24 #include "batches/GrRectBatchFactory.h" |
25 #include "batches/GrVertexBatch.h" | 25 #include "batches/GrVertexBatch.h" |
26 | 26 |
27 static const float kTolerance = 0.5f; | 27 static const float kTolerance = 0.5f; |
28 | 28 |
29 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
30 // Helpers for drawPath | 30 // Helpers for drawPath |
31 | 31 |
32 static inline bool single_pass_path(const SkPath& path, const SkStrokeRec& strok
e) { | 32 static inline bool single_pass_path(const SkPath& path) { |
33 if (!path.isInverseFillType()) { | 33 if (!path.isInverseFillType()) { |
34 return path.isConvex(); | 34 return path.isConvex(); |
35 } | 35 } |
36 return false; | 36 return false; |
37 } | 37 } |
38 | 38 |
39 GrPathRenderer::StencilSupport | 39 GrPathRenderer::StencilSupport |
40 GrMSAAPathRenderer::onGetStencilSupport(const SkPath& path) const { | 40 GrMSAAPathRenderer::onGetStencilSupport(const SkPath& path) const { |
41 if (single_pass_path(path, SkStrokeRec(SkStrokeRec::kFill_InitStyle))) { | 41 if (single_pass_path(path)) { |
42 return GrPathRenderer::kNoRestriction_StencilSupport; | 42 return GrPathRenderer::kNoRestriction_StencilSupport; |
43 } else { | 43 } else { |
44 return GrPathRenderer::kStencilOnly_StencilSupport; | 44 return GrPathRenderer::kStencilOnly_StencilSupport; |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 struct MSAALineVertices { | 48 struct MSAALineVertices { |
49 struct Vertex { | 49 struct Vertex { |
50 SkPoint fPosition; | 50 SkPoint fPosition; |
51 SkColor fColor; | 51 SkColor fColor; |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 bool fIsIndexed; | 564 bool fIsIndexed; |
565 | 565 |
566 typedef GrVertexBatch INHERITED; | 566 typedef GrVertexBatch INHERITED; |
567 }; | 567 }; |
568 | 568 |
569 bool GrMSAAPathRenderer::internalDrawPath(GrDrawTarget* target, | 569 bool GrMSAAPathRenderer::internalDrawPath(GrDrawTarget* target, |
570 GrPipelineBuilder* pipelineBuilder, | 570 GrPipelineBuilder* pipelineBuilder, |
571 GrColor color, | 571 GrColor color, |
572 const SkMatrix& viewMatrix, | 572 const SkMatrix& viewMatrix, |
573 const SkPath& path, | 573 const SkPath& path, |
574 const GrStrokeInfo& origStroke, | |
575 bool stencilOnly) { | 574 bool stencilOnly) { |
576 SkTCopyOnFirstWrite<GrStrokeInfo> stroke(origStroke); | |
577 | 575 |
578 const GrXPFactory* xpFactory = pipelineBuilder->getXPFactory(); | 576 const GrXPFactory* xpFactory = pipelineBuilder->getXPFactory(); |
579 SkAutoTUnref<const GrXPFactory> backupXPFactory(SkSafeRef(xpFactory)); | 577 SkAutoTUnref<const GrXPFactory> backupXPFactory(SkSafeRef(xpFactory)); |
580 // face culling doesn't make sense here | 578 // face culling doesn't make sense here |
581 SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace()
); | 579 SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace()
); |
582 | 580 |
583 int passCount = 0; | 581 int passCount = 0; |
584 const GrStencilSettings* passes[3]; | 582 const GrStencilSettings* passes[3]; |
585 GrPipelineBuilder::DrawFace drawFace[3]; | 583 GrPipelineBuilder::DrawFace drawFace[3]; |
586 bool reverse = false; | 584 bool reverse = false; |
587 bool lastPassIsBounds; | 585 bool lastPassIsBounds; |
588 | 586 |
589 if (single_pass_path(path, *stroke)) { | 587 if (single_pass_path(path)) { |
590 passCount = 1; | 588 passCount = 1; |
591 if (stencilOnly) { | 589 if (stencilOnly) { |
592 passes[0] = &gDirectToStencil; | 590 passes[0] = &gDirectToStencil; |
593 } else { | 591 } else { |
594 passes[0] = nullptr; | 592 passes[0] = nullptr; |
595 } | 593 } |
596 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; | 594 drawFace[0] = GrPipelineBuilder::kBoth_DrawFace; |
597 lastPassIsBounds = false; | 595 lastPassIsBounds = false; |
598 } else { | 596 } else { |
599 switch (path.getFillType()) { | 597 switch (path.getFillType()) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 } | 694 } |
697 else { | 695 else { |
698 return false; | 696 return false; |
699 } | 697 } |
700 } | 698 } |
701 } | 699 } |
702 return true; | 700 return true; |
703 } | 701 } |
704 | 702 |
705 bool GrMSAAPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { | 703 bool GrMSAAPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
706 return !IsStrokeHairlineOrEquivalent(*args.fStroke, *args.fViewMatrix, nullp
tr) && | 704 // This path renderer does not support hairlines. We defer on anything that
could be handled |
707 !args.fAntiAlias; | 705 // as a hairline by another path renderer. Also, arbitrary path effects coul
d produce |
| 706 // a hairline result. |
| 707 return !IsStrokeHairlineOrEquivalent(*args.fStyle, *args.fViewMatrix, nullpt
r) && |
| 708 !args.fStyle->strokeRec().isHairlineStyle() && |
| 709 !args.fStyle->hasNonDashPathEffect() && !args.fAntiAlias; |
708 } | 710 } |
709 | 711 |
710 bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) { | 712 bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) { |
711 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrMSAAPathRenderer
::onDrawPath"); | 713 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrMSAAPathRenderer
::onDrawPath"); |
712 SkPath path; | 714 SkPath tmpPath; |
713 GrStrokeInfo stroke(*args.fStroke); | 715 const SkPath* path; |
714 if (stroke.isDashed()) { | 716 if (args.fStyle->applies()) { |
715 if (!stroke.applyDashToPath(&path, &stroke, *args.fPath)) { | 717 SkStrokeRec::InitStyle fill; |
| 718 SkScalar styleScale = GrStyle::MatrixToScaleFactor(*args.fViewMatrix); |
| 719 if (!args.fStyle->applyToPath(&tmpPath, &fill, *args.fPath, styleScale))
{ |
716 return false; | 720 return false; |
717 } | 721 } |
| 722 // We don't accept styles that are hairlines or have path effects that c
ould produce |
| 723 // hairlines. |
| 724 SkASSERT(SkStrokeRec::kFill_InitStyle == fill); |
| 725 path = &tmpPath; |
718 } else { | 726 } else { |
719 path = *args.fPath; | 727 path = args.fPath; |
720 } | |
721 if (!stroke.isFillStyle()) { | |
722 stroke.setResScale(SkScalarAbs(args.fViewMatrix->getMaxScale())); | |
723 if (!stroke.applyToPath(&path, path)) { | |
724 return false; | |
725 } | |
726 stroke.setFillStyle(); | |
727 } | 728 } |
728 return this->internalDrawPath(args.fTarget, | 729 return this->internalDrawPath(args.fTarget, |
729 args.fPipelineBuilder, | 730 args.fPipelineBuilder, |
730 args.fColor, | 731 args.fColor, |
731 *args.fViewMatrix, | 732 *args.fViewMatrix, |
732 path, | 733 *path, |
733 stroke, | |
734 false); | 734 false); |
735 } | 735 } |
736 | 736 |
737 void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) { | 737 void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) { |
738 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(),"GrMSAAPathRenderer:
:onStencilPath"); | 738 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(),"GrMSAAPathRenderer:
:onStencilPath"); |
739 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType()); | 739 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType()); |
740 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType()); | 740 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType()); |
741 this->internalDrawPath(args.fTarget, args.fPipelineBuilder, GrColor_WHITE, *
args.fViewMatrix, | 741 this->internalDrawPath(args.fTarget, args.fPipelineBuilder, GrColor_WHITE, *
args.fViewMatrix, |
742 *args.fPath, GrStrokeInfo::FillInfo(), true); | 742 *args.fPath, true); |
743 } | 743 } |
744 | 744 |
745 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 745 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
OLD | NEW |