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" |
11 #include "GrContext.h" | 11 #include "GrContext.h" |
12 #include "GrDrawContextPriv.h" | |
12 #include "GrDrawPathBatch.h" | 13 #include "GrDrawPathBatch.h" |
13 #include "GrGpu.h" | 14 #include "GrGpu.h" |
14 #include "GrPath.h" | 15 #include "GrPath.h" |
15 #include "GrRenderTarget.h" | 16 #include "GrRenderTarget.h" |
16 #include "GrResourceProvider.h" | 17 #include "GrResourceProvider.h" |
18 #include "GrStencilPathBatch.h" | |
17 #include "GrStyle.h" | 19 #include "GrStyle.h" |
18 #include "batches/GrRectBatchFactory.h" | 20 #include "batches/GrRectBatchFactory.h" |
19 | 21 |
20 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrResourceProvider* resour ceProvider, | 22 GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrResourceProvider* resour ceProvider, |
21 const GrCaps& caps) { | 23 const GrCaps& caps) { |
22 if (caps.shaderCaps()->pathRenderingSupport()) { | 24 if (caps.shaderCaps()->pathRenderingSupport()) { |
23 return new GrStencilAndCoverPathRenderer(resourceProvider); | 25 return new GrStencilAndCoverPathRenderer(resourceProvider); |
24 } else { | 26 } else { |
25 return nullptr; | 27 return nullptr; |
26 } | 28 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 if (!isVolatile) { | 60 if (!isVolatile) { |
59 resourceProvider->assignUniqueKeyToResource(key, path); | 61 resourceProvider->assignUniqueKeyToResource(key, path); |
60 } | 62 } |
61 } else { | 63 } else { |
62 SkASSERT(path->isEqualTo(skPath, style)); | 64 SkASSERT(path->isEqualTo(skPath, style)); |
63 } | 65 } |
64 return path.release(); | 66 return path.release(); |
65 } | 67 } |
66 | 68 |
67 void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { | 69 void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { |
68 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), | 70 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), |
69 "GrStencilAndCoverPathRenderer::onStencilPath"); | 71 "GrStencilAndCoverPathRenderer::onStencilPath"); |
72 | |
73 GrPaint paint; | |
74 paint.setXPFactory(GrDisableColorXPFactory::Create()); | |
bungeman-skia
2016/06/03 23:57:03
leak
| |
75 paint.setAntiAlias(args.fIsAA); | |
76 | |
77 GrPipelineBuilder pipelineBuilder(paint, args.fDrawContext->isUnifiedMultisa mpled()); | |
78 pipelineBuilder.setRenderTarget(args.fDrawContext->accessRenderTarget()); | |
79 | |
70 SkASSERT(!args.fPath->isInverseFillType()); | 80 SkASSERT(!args.fPath->isInverseFillType()); |
71 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fPath, GrStyle:: SimpleFill())); | 81 SkAutoTUnref<GrPath> path(get_gr_path(fResourceProvider, *args.fPath, GrStyl e::SimpleFill())); |
72 args.fTarget->stencilPath(*args.fPipelineBuilder, *args.fClip, *args.fViewMa trix, p, | 82 args.fDrawContext->drawContextPriv().stencilPath(pipelineBuilder, |
73 p->getFillType()); | 83 *args.fClip, |
84 *args.fViewMatrix, | |
85 path, | |
86 path->getFillType()); | |
74 } | 87 } |
75 | 88 |
76 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { | 89 bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { |
77 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), | 90 GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(), |
78 "GrStencilAndCoverPathRenderer::onDrawPath"); | 91 "GrStencilAndCoverPathRenderer::onDrawPath"); |
79 SkASSERT(!args.fStyle->strokeRec().isHairlineStyle()); | 92 SkASSERT(!args.fStyle->strokeRec().isHairlineStyle()); |
80 const SkPath& path = *args.fPath; | 93 const SkPath& path = *args.fPath; |
81 GrPipelineBuilder* pipelineBuilder = args.fPipelineBuilder; | |
82 const SkMatrix& viewMatrix = *args.fViewMatrix; | 94 const SkMatrix& viewMatrix = *args.fViewMatrix; |
83 | 95 |
84 SkASSERT(!pipelineBuilder->hasUserStencilSettings()); | |
85 | |
86 if (args.fAntiAlias) { | |
87 SkASSERT(pipelineBuilder->getRenderTarget()->isStencilBufferMultisampled ()); | |
88 pipelineBuilder->enableState(GrPipelineBuilder::kHWAntialias_Flag); | |
89 } | |
90 | |
91 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStyle)); | 96 SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, path, *args.fStyle)); |
92 | 97 |
93 if (path.isInverseFillType()) { | 98 if (path.isInverseFillType()) { |
94 static constexpr GrUserStencilSettings kInvertedCoverPass( | 99 static constexpr GrUserStencilSettings kInvertedCoverPass( |
95 GrUserStencilSettings::StaticInit< | 100 GrUserStencilSettings::StaticInit< |
96 0x0000, | 101 0x0000, |
97 // We know our rect will hit pixels outside the clip and the use r bits will be 0 | 102 // We know our rect will hit pixels outside the clip and the use r bits will be 0 |
98 // outside the clip. So we can't just fill where the user bits a re 0. We also need | 103 // outside the clip. So we can't just fill where the user bits a re 0. We also need |
99 // to check that the clip bit is set. | 104 // to check that the clip bit is set. |
100 GrUserStencilTest::kEqualIfInClip, | 105 GrUserStencilTest::kEqualIfInClip, |
101 0xffff, | 106 0xffff, |
102 GrUserStencilOp::kKeep, | 107 GrUserStencilOp::kKeep, |
103 GrUserStencilOp::kZero, | 108 GrUserStencilOp::kZero, |
104 0xffff>() | 109 0xffff>() |
105 ); | 110 ); |
106 | 111 |
112 // fake inverse with a stencil and cover | |
113 { | |
114 GrPipelineBuilder pipelineBuilder(*args.fPaint, | |
115 args.fDrawContext->isUnifiedMultis ampled()); | |
116 pipelineBuilder.setRenderTarget(args.fDrawContext->accessRenderTarge t()); | |
117 pipelineBuilder.setUserStencil(&kInvertedCoverPass); | |
118 if (args.fAntiAlias) { | |
119 SkASSERT(args.fDrawContext->isStencilBufferMultisampled()); | |
120 pipelineBuilder.enableState(GrPipelineBuilder::kHWAntialias_Flag ); | |
121 } | |
107 | 122 |
108 pipelineBuilder->setUserStencil(&kInvertedCoverPass); | 123 args.fDrawContext->drawContextPriv().stencilPath(pipelineBuilder, *a rgs.fClip, |
109 | 124 viewMatrix, p, p->g etFillType()); |
110 // fake inverse with a stencil and cover | 125 } |
111 args.fTarget->stencilPath(*pipelineBuilder, *args.fClip, viewMatrix, p, p->getFillType()); | |
112 | 126 |
113 SkMatrix invert = SkMatrix::I(); | 127 SkMatrix invert = SkMatrix::I(); |
114 SkRect bounds = | 128 SkRect bounds = |
115 SkRect::MakeLTRB(0, 0, SkIntToScalar(pipelineBuilder->getRenderTarge t()->width()), | 129 SkRect::MakeLTRB(0, 0, |
116 SkIntToScalar(pipelineBuilder->getRenderTarget()->h eight())); | 130 SkIntToScalar(args.fDrawContext->width()), |
131 SkIntToScalar(args.fDrawContext->height())); | |
117 SkMatrix vmi; | 132 SkMatrix vmi; |
118 // mapRect through persp matrix may not be correct | 133 // mapRect through persp matrix may not be correct |
119 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { | 134 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
120 vmi.mapRect(&bounds); | 135 vmi.mapRect(&bounds); |
121 // theoretically could set bloat = 0, instead leave it because of ma trix inversion | 136 // theoretically could set bloat = 0, instead leave it because of ma trix inversion |
122 // precision. | 137 // precision. |
123 SkScalar bloat = viewMatrix.getMaxScale() * SK_ScalarHalf; | 138 SkScalar bloat = viewMatrix.getMaxScale() * SK_ScalarHalf; |
124 bounds.outset(bloat, bloat); | 139 bounds.outset(bloat, bloat); |
125 } else { | 140 } else { |
126 if (!viewMatrix.invert(&invert)) { | 141 if (!viewMatrix.invert(&invert)) { |
127 return false; | 142 return false; |
128 } | 143 } |
129 } | 144 } |
130 const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : vi ewMatrix; | 145 const SkMatrix& viewM = viewMatrix.hasPerspective() ? SkMatrix::I() : vi ewMatrix; |
131 if (pipelineBuilder->getRenderTarget()->hasMixedSamples()) { | |
132 pipelineBuilder->disableState(GrPipelineBuilder::kHWAntialias_Flag); | |
133 } | |
134 | 146 |
135 SkAutoTUnref<GrDrawBatch> batch( | 147 SkAutoTUnref<GrDrawBatch> batch( |
136 GrRectBatchFactory::CreateNonAAFill(args.fColor, viewM, bounds, nullptr, | 148 GrRectBatchFactory::CreateNonAAFill(args.fColor, viewM, bounds, nullptr, |
137 &invert)); | 149 &invert)); |
138 args.fTarget->drawBatch(*pipelineBuilder, *args.fClip, batch); | 150 |
151 { | |
152 GrPipelineBuilder pipelineBuilder(*args.fPaint, | |
153 args.fDrawContext->isUnifiedMultis ampled()); | |
154 pipelineBuilder.setRenderTarget(args.fDrawContext->accessRenderTarge t()); | |
155 pipelineBuilder.setUserStencil(&kInvertedCoverPass); | |
156 if (args.fAntiAlias) { | |
157 SkASSERT(args.fDrawContext->isStencilBufferMultisampled()); | |
158 pipelineBuilder.enableState(GrPipelineBuilder::kHWAntialias_Flag ); | |
159 } | |
160 if (args.fDrawContext->hasMixedSamples()) { | |
161 pipelineBuilder.disableState(GrPipelineBuilder::kHWAntialias_Fla g); | |
162 } | |
163 | |
164 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); | |
165 } | |
139 } else { | 166 } else { |
140 static constexpr GrUserStencilSettings kCoverPass( | 167 static constexpr GrUserStencilSettings kCoverPass( |
141 GrUserStencilSettings::StaticInit< | 168 GrUserStencilSettings::StaticInit< |
142 0x0000, | 169 0x0000, |
143 GrUserStencilTest::kNotEqual, | 170 GrUserStencilTest::kNotEqual, |
144 0xffff, | 171 0xffff, |
145 GrUserStencilOp::kZero, | 172 GrUserStencilOp::kZero, |
146 GrUserStencilOp::kKeep, | 173 GrUserStencilOp::kKeep, |
147 0xffff>() | 174 0xffff>() |
148 ); | 175 ); |
149 | 176 |
150 pipelineBuilder->setUserStencil(&kCoverPass); | |
151 SkAutoTUnref<GrDrawBatch> batch( | 177 SkAutoTUnref<GrDrawBatch> batch( |
152 GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType( ), p)); | 178 GrDrawPathBatch::Create(viewMatrix, args.fColor, p->getFillType( ), p)); |
153 args.fTarget->drawBatch(*pipelineBuilder, *args.fClip, batch); | 179 |
180 GrPipelineBuilder pipelineBuilder(*args.fPaint, | |
181 args.fDrawContext->isUnifiedMultisampl ed()); | |
182 pipelineBuilder.setRenderTarget(args.fDrawContext->accessRenderTarget()) ; | |
183 pipelineBuilder.setUserStencil(&kCoverPass); | |
184 if (args.fAntiAlias) { | |
185 SkASSERT(args.fDrawContext->isStencilBufferMultisampled()); | |
186 pipelineBuilder.enableState(GrPipelineBuilder::kHWAntialias_Flag); | |
187 } | |
188 | |
189 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); | |
154 } | 190 } |
155 | 191 |
156 pipelineBuilder->disableUserStencil(); | |
157 return true; | 192 return true; |
158 } | 193 } |
OLD | NEW |