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