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 #ifndef GrPathRenderer_DEFINED | 8 #ifndef GrPathRenderer_DEFINED |
9 #define GrPathRenderer_DEFINED | 9 #define GrPathRenderer_DEFINED |
10 | 10 |
11 #include "GrDrawTarget.h" | 11 #include "GrDrawContext.h" |
| 12 #include "GrPaint.h" |
| 13 #include "GrResourceProvider.h" |
12 #include "GrStyle.h" | 14 #include "GrStyle.h" |
13 | 15 |
14 #include "SkDrawProcs.h" | 16 #include "SkDrawProcs.h" |
15 #include "SkTArray.h" | 17 #include "SkTArray.h" |
16 | 18 |
17 class SkPath; | 19 class SkPath; |
| 20 class GrFixedClip; |
18 struct GrPoint; | 21 struct GrPoint; |
19 | 22 |
20 /** | 23 /** |
21 * Base class for drawing paths into a GrDrawTarget. | 24 * Base class for drawing paths into a GrDrawTarget. |
22 * | 25 * |
23 * Derived classes can use stages GrPaint::kTotalStages through GrPipelineBuild
er::kNumStages-1. | 26 * Derived classes can use stages GrPaint::kTotalStages through GrPipelineBuild
er::kNumStages-1. |
24 * The stages before GrPaint::kTotalStages are reserved for setting up the draw
(i.e., textures and | 27 * The stages before GrPaint::kTotalStages are reserved for setting up the draw
(i.e., textures and |
25 * filter masks). | 28 * filter masks). |
26 */ | 29 */ |
27 class SK_API GrPathRenderer : public SkRefCnt { | 30 class SK_API GrPathRenderer : public SkRefCnt { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 * fPipelineBuilder The pipelineBuilder | 116 * fPipelineBuilder The pipelineBuilder |
114 * fClip The clip | 117 * fClip The clip |
115 * fColor Color to render with | 118 * fColor Color to render with |
116 * fViewMatrix The viewMatrix | 119 * fViewMatrix The viewMatrix |
117 * fPath the path to draw. | 120 * fPath the path to draw. |
118 * fStyle the style information (path effect, stroke info) | 121 * fStyle the style information (path effect, stroke info) |
119 * fAntiAlias true if anti-aliasing is required. | 122 * fAntiAlias true if anti-aliasing is required. |
120 * fGammaCorrect true if gamma-correct rendering is to be used. | 123 * fGammaCorrect true if gamma-correct rendering is to be used. |
121 */ | 124 */ |
122 struct DrawPathArgs { | 125 struct DrawPathArgs { |
123 GrDrawTarget* fTarget; | |
124 GrResourceProvider* fResourceProvider; | 126 GrResourceProvider* fResourceProvider; |
125 GrPipelineBuilder* fPipelineBuilder; | 127 const GrPaint* fPaint; |
| 128 const GrUserStencilSettings*fUserStencilSettings; |
| 129 |
| 130 GrDrawContext* fDrawContext; |
126 const GrClip* fClip; | 131 const GrClip* fClip; |
127 GrColor fColor; | 132 GrColor fColor; |
128 const SkMatrix* fViewMatrix; | 133 const SkMatrix* fViewMatrix; |
129 const SkPath* fPath; | 134 const SkPath* fPath; |
130 const GrStyle* fStyle; | 135 const GrStyle* fStyle; |
131 bool fAntiAlias; | 136 bool fAntiAlias; |
132 bool fGammaCorrect; | 137 bool fGammaCorrect; |
133 | 138 |
134 void validate() const { | 139 void validate() const { |
135 SkASSERT(fTarget); | |
136 SkASSERT(fResourceProvider); | 140 SkASSERT(fResourceProvider); |
137 SkASSERT(fPipelineBuilder); | 141 SkASSERT(fPaint); |
| 142 SkASSERT(fUserStencilSettings); |
| 143 SkASSERT(fDrawContext); |
138 SkASSERT(fClip); | 144 SkASSERT(fClip); |
139 SkASSERT(fViewMatrix); | 145 SkASSERT(fViewMatrix); |
140 SkASSERT(fPath); | 146 SkASSERT(fPath); |
141 SkASSERT(fStyle); | 147 SkASSERT(fStyle); |
142 SkASSERT(!fPath->isEmpty()); | 148 SkASSERT(!fPath->isEmpty()); |
143 } | 149 } |
144 }; | 150 }; |
145 | 151 |
146 /** | 152 /** |
147 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then | 153 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then |
148 * the subclass must respect the stencil settings of the GrPipelineBuilder. | 154 * the subclass must respect the stencil settings of the GrPipelineBuilder. |
149 */ | 155 */ |
150 bool drawPath(const DrawPathArgs& args) { | 156 bool drawPath(const DrawPathArgs& args) { |
151 SkDEBUGCODE(args.validate();) | 157 SkDEBUGCODE(args.validate();) |
152 #ifdef SK_DEBUG | 158 #ifdef SK_DEBUG |
153 CanDrawPathArgs canArgs; | 159 CanDrawPathArgs canArgs; |
154 canArgs.fShaderCaps = args.fTarget->caps()->shaderCaps(); | 160 canArgs.fShaderCaps = args.fResourceProvider->caps()->shaderCaps(); |
155 canArgs.fViewMatrix = args.fViewMatrix; | 161 canArgs.fViewMatrix = args.fViewMatrix; |
156 canArgs.fPath = args.fPath; | 162 canArgs.fPath = args.fPath; |
157 canArgs.fStyle = args.fStyle; | 163 canArgs.fStyle = args.fStyle; |
158 canArgs.fAntiAlias = args.fAntiAlias; | 164 canArgs.fAntiAlias = args.fAntiAlias; |
159 | 165 |
160 canArgs.fHasUserStencilSettings = args.fPipelineBuilder->hasUserStencilS
ettings(); | 166 canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused()
; |
161 canArgs.fIsStencilBufferMSAA = | 167 canArgs.fIsStencilBufferMSAA = args.fDrawContext->isStencilBufferMultisa
mpled(); |
162 args.fPipelineBuilder->getRenderTarget()->isStencilBuf
ferMultisampled(); | |
163 SkASSERT(this->canDrawPath(canArgs)); | 168 SkASSERT(this->canDrawPath(canArgs)); |
164 if (args.fPipelineBuilder->hasUserStencilSettings()) { | 169 if (!args.fUserStencilSettings->isUnused()) { |
165 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*a
rgs.fPath)); | 170 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*a
rgs.fPath)); |
166 SkASSERT(args.fStyle->isSimpleFill()); | 171 SkASSERT(args.fStyle->isSimpleFill()); |
167 } | 172 } |
168 #endif | 173 #endif |
169 return this->onDrawPath(args); | 174 return this->onDrawPath(args); |
170 } | 175 } |
171 | 176 |
172 /* Args to stencilPath(). | 177 /* Args to stencilPath(). |
173 * | 178 * |
174 * fTarget The target that the path will be rendered to. | |
175 * fResourceProvider The resource provider for creating gpu resources t
o render the path | 179 * fResourceProvider The resource provider for creating gpu resources t
o render the path |
176 * fPipelineBuilder The pipeline builder. | 180 * fDrawContext The target of the draws |
177 * fViewMatrix Matrix applied to the path. | 181 * fViewMatrix Matrix applied to the path. |
178 * fPath The path to draw. | 182 * fPath The path to draw. |
| 183 * fIsAA Is the path to be drawn AA (only set when MSAA is
available) |
179 */ | 184 */ |
180 struct StencilPathArgs { | 185 struct StencilPathArgs { |
181 GrDrawTarget* fTarget; | |
182 GrResourceProvider* fResourceProvider; | 186 GrResourceProvider* fResourceProvider; |
183 GrPipelineBuilder* fPipelineBuilder; | 187 GrDrawContext* fDrawContext; |
184 const GrClip* fClip; | 188 const GrFixedClip* fClip; |
185 const SkMatrix* fViewMatrix; | 189 const SkMatrix* fViewMatrix; |
186 const SkPath* fPath; | 190 const SkPath* fPath; |
| 191 bool fIsAA; |
187 | 192 |
188 void validate() const { | 193 void validate() const { |
189 SkASSERT(fTarget); | |
190 SkASSERT(fResourceProvider); | 194 SkASSERT(fResourceProvider); |
191 SkASSERT(fPipelineBuilder); | 195 SkASSERT(fDrawContext); |
192 SkASSERT(fViewMatrix); | 196 SkASSERT(fViewMatrix); |
193 SkASSERT(fPath); | 197 SkASSERT(fPath); |
194 SkASSERT(!fPath->isEmpty()); | 198 SkASSERT(!fPath->isEmpty()); |
195 } | 199 } |
196 }; | 200 }; |
197 | 201 |
198 /** | 202 /** |
199 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already | 203 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already |
200 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. | 204 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. |
201 */ | 205 */ |
(...skipping 23 matching lines...) Expand all Loading... |
225 | 229 |
226 protected: | 230 protected: |
227 // Helper for getting the device bounds of a path. Inverse filled paths will
have bounds set | 231 // Helper for getting the device bounds of a path. Inverse filled paths will
have bounds set |
228 // by devSize. Non-inverse path bounds will not necessarily be clipped to de
vSize. | 232 // by devSize. Non-inverse path bounds will not necessarily be clipped to de
vSize. |
229 static void GetPathDevBounds(const SkPath& path, | 233 static void GetPathDevBounds(const SkPath& path, |
230 int devW, | 234 int devW, |
231 int devH, | 235 int devH, |
232 const SkMatrix& matrix, | 236 const SkMatrix& matrix, |
233 SkRect* bounds); | 237 SkRect* bounds); |
234 | 238 |
235 // Helper version that gets the dev width and height from a GrSurface. | |
236 static void GetPathDevBounds(const SkPath& path, | |
237 const GrSurface* device, | |
238 const SkMatrix& matrix, | |
239 SkRect* bounds) { | |
240 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds
); | |
241 } | |
242 | |
243 private: | 239 private: |
244 /** | 240 /** |
245 * Subclass overrides if it has any limitations of stenciling support. | 241 * Subclass overrides if it has any limitations of stenciling support. |
246 */ | 242 */ |
247 virtual StencilSupport onGetStencilSupport(const SkPath&) const { | 243 virtual StencilSupport onGetStencilSupport(const SkPath&) const { |
248 return kNoRestriction_StencilSupport; | 244 return kNoRestriction_StencilSupport; |
249 } | 245 } |
250 | 246 |
251 /** | 247 /** |
252 * Subclass implementation of drawPath() | 248 * Subclass implementation of drawPath() |
(...skipping 12 matching lines...) Expand all Loading... |
265 virtual void onStencilPath(const StencilPathArgs& args) { | 261 virtual void onStencilPath(const StencilPathArgs& args) { |
266 static constexpr GrUserStencilSettings kIncrementStencil( | 262 static constexpr GrUserStencilSettings kIncrementStencil( |
267 GrUserStencilSettings::StaticInit< | 263 GrUserStencilSettings::StaticInit< |
268 0xffff, | 264 0xffff, |
269 GrUserStencilTest::kAlways, | 265 GrUserStencilTest::kAlways, |
270 0xffff, | 266 0xffff, |
271 GrUserStencilOp::kReplace, | 267 GrUserStencilOp::kReplace, |
272 GrUserStencilOp::kReplace, | 268 GrUserStencilOp::kReplace, |
273 0xffff>() | 269 0xffff>() |
274 ); | 270 ); |
275 args.fPipelineBuilder->setUserStencil(&kIncrementStencil); | 271 |
276 args.fPipelineBuilder->setDisableColorXPFactory(); | 272 GrPaint paint; |
| 273 |
277 DrawPathArgs drawArgs; | 274 DrawPathArgs drawArgs; |
278 drawArgs.fTarget = args.fTarget; | |
279 drawArgs.fResourceProvider = args.fResourceProvider; | 275 drawArgs.fResourceProvider = args.fResourceProvider; |
280 drawArgs.fPipelineBuilder = args.fPipelineBuilder; | 276 drawArgs.fPaint = &paint; |
281 drawArgs.fColor = 0xFFFFFFFF; | 277 drawArgs.fUserStencilSettings = &kIncrementStencil; |
| 278 drawArgs.fDrawContext = args.fDrawContext; |
| 279 drawArgs.fColor = GrColor_WHITE; |
282 drawArgs.fViewMatrix = args.fViewMatrix; | 280 drawArgs.fViewMatrix = args.fViewMatrix; |
283 drawArgs.fPath = args.fPath; | 281 drawArgs.fPath = args.fPath; |
284 drawArgs.fStyle = &GrStyle::SimpleFill(); | 282 drawArgs.fStyle = &GrStyle::SimpleFill(); |
285 drawArgs.fAntiAlias = false; | 283 drawArgs.fAntiAlias = false; // In this case the MSAA handles the AA so
we want to draw BW |
286 drawArgs.fGammaCorrect = false; | 284 drawArgs.fGammaCorrect = false; |
287 this->drawPath(drawArgs); | 285 this->drawPath(drawArgs); |
288 } | 286 } |
289 | 287 |
290 typedef SkRefCnt INHERITED; | 288 typedef SkRefCnt INHERITED; |
291 }; | 289 }; |
292 | 290 |
293 #endif | 291 #endif |
OLD | NEW |