OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 | 8 |
9 #include "GrStencilAndCoverPathRenderer.h" | 9 #include "GrStencilAndCoverPathRenderer.h" |
10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrResourceProvider*
resourceProvider) | 29 GrStencilAndCoverPathRenderer::GrStencilAndCoverPathRenderer(GrResourceProvider*
resourceProvider) |
30 : fResourceProvider(resourceProvider) { | 30 : fResourceProvider(resourceProvider) { |
31 } | 31 } |
32 | 32 |
33 bool GrStencilAndCoverPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c
onst { | 33 bool GrStencilAndCoverPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c
onst { |
34 if (args.fStroke->isHairlineStyle()) { | 34 if (args.fStroke->isHairlineStyle()) { |
35 return false; | 35 return false; |
36 } | 36 } |
37 if (!args.fIsStencilDisabled) { | 37 if (args.fHasUserStencilSettings) { |
38 return false; | 38 return false; |
39 } | 39 } |
40 if (args.fAntiAlias) { | 40 if (args.fAntiAlias) { |
41 return args.fIsStencilBufferMSAA; | 41 return args.fIsStencilBufferMSAA; |
42 } else { | 42 } else { |
43 return true; // doesn't do per-path AA, relies on the target having MSAA | 43 return true; // doesn't do per-path AA, relies on the target having MSAA |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const SkPath& s
kPath, | 47 static GrPath* get_gr_path(GrResourceProvider* resourceProvider, const SkPath& s
kPath, |
(...skipping 23 matching lines...) Expand all Loading... |
71 } | 71 } |
72 | 72 |
73 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { | 73 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { |
74 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), | 74 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), |
75 "GrStencilAndCoverPathRenderer::onDrawPath"); | 75 "GrStencilAndCoverPathRenderer::onDrawPath"); |
76 SkASSERT(!args.fStroke->isHairlineStyle()); | 76 SkASSERT(!args.fStroke->isHairlineStyle()); |
77 const SkPath& path = *args.fPath; | 77 const SkPath& path = *args.fPath; |
78 GrPipelineBuilder* pipelineBuilder = args.fPipelineBuilder; | 78 GrPipelineBuilder* pipelineBuilder = args.fPipelineBuilder; |
79 const SkMatrix& viewMatrix = *args.fViewMatrix; | 79 const SkMatrix& viewMatrix = *args.fViewMatrix; |
80 | 80 |
81 SkASSERT(pipelineBuilder->getStencil().isDisabled()); | 81 SkASSERT(!pipelineBuilder->hasUserStencilSettings()); |
82 | 82 |
83 if (args.fAntiAlias) { | 83 if (args.fAntiAlias) { |
84 SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled
()); | 84 SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled
()); |
85 pipelineBuilder->enableState(GrPipelineBuilder::kHWAntialias_Flag); | 85 pipelineBuilder->enableState(GrPipelineBuilder::kHWAntialias_Flag); |
86 } | 86 } |
87 | 87 |
88 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStroke)); | 88 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStroke)); |
89 | 89 |
90 if (path.isInverseFillType()) { | 90 if (path.isInverseFillType()) { |
91 static constexpr GrStencilSettings kInvertedStencilPass( | 91 static constexpr GrUserStencilSettings kInvertedCoverPass( |
92 kKeep_StencilOp, | 92 GrUserStencilSettings::StaticInit< |
93 kZero_StencilOp, | 93 0x0000, |
94 // We know our rect will hit pixels outside the clip and the user bi
ts will be 0 | 94 // We know our rect will hit pixels outside the clip and the use
r bits will be 0 |
95 // outside the clip. So we can't just fill where the user bits are 0
. We also need to | 95 // outside the clip. So we can't just fill where the user bits a
re 0. We also need |
96 // check that the clip bit is set. | 96 // to check that the clip bit is set. |
97 kEqualIfInClip_StencilFunc, | 97 GrUserStencilTest::kEqualIfInClip, |
98 0xffff, | 98 0xffff, |
99 0x0000, | 99 GrUserStencilOp::kKeep, |
100 0xffff); | 100 GrUserStencilOp::kZero, |
| 101 0xffff>() |
| 102 ); |
101 | 103 |
102 pipelineBuilder->setStencil(kInvertedStencilPass); | 104 |
| 105 pipelineBuilder->setUserStencil(&kInvertedCoverPass); |
103 | 106 |
104 // fake inverse with a stencil and cover | 107 // fake inverse with a stencil and cover |
105 args.fTarget->stencilPath(*pipelineBuilder, viewMatrix, p, p->getFillTyp
e()); | 108 args.fTarget->stencilPath(*pipelineBuilder, viewMatrix, p, p->getFillTyp
e()); |
106 | 109 |
107 SkMatrix invert = SkMatrix::I(); | 110 SkMatrix invert = SkMatrix::I(); |
108 SkRect bounds = | 111 SkRect bounds = |
109 SkRect::MakeLTRB(0, 0, SkIntToScalar(pipelineBuilder->getRenderTarge
t()->width()), | 112 SkRect::MakeLTRB(0, 0, SkIntToScalar(pipelineBuilder->getRenderTarge
t()->width()), |
110 SkIntToScalar(pipelineBuilder->getRenderTarget()->h
eight())); | 113 SkIntToScalar(pipelineBuilder->getRenderTarget()->h
eight())); |
111 SkMatrix vmi; | 114 SkMatrix vmi; |
112 // mapRect through persp matrix may not be correct | 115 // mapRect through persp matrix may not be correct |
(...skipping 11 matching lines...) Expand all Loading... |
124 const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : vi
ewMatrix; | 127 const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : vi
ewMatrix; |
125 if (pipelineBuilder->getRenderTarget()->hasMixedSamples()) { | 128 if (pipelineBuilder->getRenderTarget()->hasMixedSamples()) { |
126 pipelineBuilder->disableState(GrPipelineBuilder::kHWAntialias_Flag); | 129 pipelineBuilder->disableState(GrPipelineBuilder::kHWAntialias_Flag); |
127 } | 130 } |
128 | 131 |
129 SkAutoTUnref<GrDrawBatch> batch( | 132 SkAutoTUnref<GrDrawBatch> batch( |
130 GrRectBatchFactory::CreateNonAAFill(args.fColor, viewM, bounds,
nullptr, | 133 GrRectBatchFactory::CreateNonAAFill(args.fColor, viewM, bounds,
nullptr, |
131 &invert)); | 134 &invert)); |
132 args.fTarget->drawBatch(*pipelineBuilder, batch); | 135 args.fTarget->drawBatch(*pipelineBuilder, batch); |
133 } else { | 136 } else { |
134 static constexpr GrStencilSettings kStencilPass( | 137 static constexpr GrUserStencilSettings kCoverPass( |
135 kZero_StencilOp, | 138 GrUserStencilSettings::StaticInit< |
136 kKeep_StencilOp, | 139 0x0000, |
137 kNotEqual_StencilFunc, | 140 GrUserStencilTest::kNotEqual, |
138 0xffff, | 141 0xffff, |
139 0x0000, | 142 GrUserStencilOp::kZero, |
140 0xffff); | 143 GrUserStencilOp::kKeep, |
| 144 0xffff>() |
| 145 ); |
141 | 146 |
142 pipelineBuilder->setStencil(kStencilPass); | 147 pipelineBuilder->setUserStencil(&kCoverPass); |
143 SkAutoTUnref<GrDrawPathBatchBase> batch( | 148 SkAutoTUnref<GrDrawPathBatchBase> batch( |
144 GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType(
), p)); | 149 GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType(
), p)); |
145 args.fTarget->drawPathBatch(*pipelineBuilder, batch); | 150 args.fTarget->drawPathBatch(*pipelineBuilder, batch); |
146 } | 151 } |
147 | 152 |
148 pipelineBuilder->stencil()->setDisabled(); | 153 pipelineBuilder->disableUserStencil(); |
149 return true; | 154 return true; |
150 } | 155 } |
OLD | NEW |