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 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 * 3) kNoSupport: This path renderer cannot be used to stencil the path. | 50 * 3) kNoSupport: This path renderer cannot be used to stencil the path. |
51 */ | 51 */ |
52 enum StencilSupport { | 52 enum StencilSupport { |
53 kNoSupport_StencilSupport, | 53 kNoSupport_StencilSupport, |
54 kStencilOnly_StencilSupport, | 54 kStencilOnly_StencilSupport, |
55 kNoRestriction_StencilSupport, | 55 kNoRestriction_StencilSupport, |
56 }; | 56 }; |
57 | 57 |
58 /** | 58 /** |
59 * This function is to get the stencil support for a particular path. The pa
th's fill must | 59 * This function is to get the stencil support for a particular path. The pa
th's fill must |
60 * not be an inverse type. | 60 * not be an inverse type. The path will always be filled and not stroked. |
61 * | 61 * |
62 * @param path the path that will be drawn | 62 * @param path the path that will be drawn |
63 * @param stroke the stroke information (width, join, cap). | |
64 */ | 63 */ |
65 StencilSupport getStencilSupport(const SkPath& path, const GrStrokeInfo& str
oke) const { | 64 StencilSupport getStencilSupport(const SkPath& path) const { |
66 SkASSERT(!path.isInverseFillType()); | 65 SkASSERT(!path.isInverseFillType()); |
67 return this->onGetStencilSupport(path, stroke); | 66 return this->onGetStencilSupport(path); |
68 } | 67 } |
69 | 68 |
70 /** Args to canDrawPath() | 69 /** Args to canDrawPath() |
71 * | 70 * |
72 * fShaderCaps The shader caps | 71 * fShaderCaps The shader caps |
73 * fPipelineBuilder The pipelineBuilder | 72 * fPipelineBuilder The pipelineBuilder |
74 * fViewMatrix The viewMatrix | 73 * fViewMatrix The viewMatrix |
75 * fPath The path to draw | 74 * fPath The path to draw |
76 * fStroke The stroke information (width, join, cap) | 75 * fStroke The stroke information (width, join, cap) |
77 * fAntiAlias True if anti-aliasing is required. | 76 * fAntiAlias True if anti-aliasing is required. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 canArgs.fShaderCaps = args.fTarget->caps()->shaderCaps(); | 153 canArgs.fShaderCaps = args.fTarget->caps()->shaderCaps(); |
155 canArgs.fViewMatrix = args.fViewMatrix; | 154 canArgs.fViewMatrix = args.fViewMatrix; |
156 canArgs.fPath = args.fPath; | 155 canArgs.fPath = args.fPath; |
157 canArgs.fStroke = args.fStroke; | 156 canArgs.fStroke = args.fStroke; |
158 canArgs.fAntiAlias = args.fAntiAlias; | 157 canArgs.fAntiAlias = args.fAntiAlias; |
159 | 158 |
160 canArgs.fIsStencilDisabled = args.fPipelineBuilder->getStencil().isDisab
led(); | 159 canArgs.fIsStencilDisabled = args.fPipelineBuilder->getStencil().isDisab
led(); |
161 canArgs.fIsStencilBufferMSAA = | 160 canArgs.fIsStencilBufferMSAA = |
162 args.fPipelineBuilder->getRenderTarget()->isStencilBuf
ferMultisampled(); | 161 args.fPipelineBuilder->getRenderTarget()->isStencilBuf
ferMultisampled(); |
163 SkASSERT(this->canDrawPath(canArgs)); | 162 SkASSERT(this->canDrawPath(canArgs)); |
164 SkASSERT(args.fPipelineBuilder->getStencil().isDisabled() || | 163 if (!args.fPipelineBuilder->getStencil().isDisabled()) { |
165 kNoRestriction_StencilSupport == this->getStencilSupport(*args.
fPath, | 164 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*a
rgs.fPath)); |
166 *args.
fStroke)); | 165 SkASSERT(!args.fStroke->isDashed()); |
| 166 SkASSERT(args.fStroke->isFillStyle()); |
| 167 } |
167 #endif | 168 #endif |
168 return this->onDrawPath(args); | 169 return this->onDrawPath(args); |
169 } | 170 } |
170 | 171 |
171 /* Args to stencilPath(). | 172 /* Args to stencilPath(). |
172 * | 173 * |
173 * fTarget The target that the path will be rendered to. | 174 * fTarget The target that the path will be rendered to. |
174 * fResourceProvider The resource provider for creating gpu resources t
o render the path | 175 * fResourceProvider The resource provider for creating gpu resources t
o render the path |
175 * fPipelineBuilder The pipeline builder. | 176 * fPipelineBuilder The pipeline builder. |
176 * fViewMatrix Matrix applied to the path. | 177 * fViewMatrix Matrix applied to the path. |
177 * fPath The path to draw. | 178 * fPath The path to draw. |
178 * fStroke The stroke information (width, join, cap) | |
179 */ | 179 */ |
180 struct StencilPathArgs { | 180 struct StencilPathArgs { |
181 GrDrawTarget* fTarget; | 181 GrDrawTarget* fTarget; |
182 GrResourceProvider* fResourceProvider; | 182 GrResourceProvider* fResourceProvider; |
183 GrPipelineBuilder* fPipelineBuilder; | 183 GrPipelineBuilder* fPipelineBuilder; |
184 const SkMatrix* fViewMatrix; | 184 const SkMatrix* fViewMatrix; |
185 const SkPath* fPath; | 185 const SkPath* fPath; |
186 const GrStrokeInfo* fStroke; | |
187 | 186 |
188 void validate() const { | 187 void validate() const { |
189 SkASSERT(fTarget); | 188 SkASSERT(fTarget); |
190 SkASSERT(fResourceProvider); | 189 SkASSERT(fResourceProvider); |
191 SkASSERT(fPipelineBuilder); | 190 SkASSERT(fPipelineBuilder); |
192 SkASSERT(fViewMatrix); | 191 SkASSERT(fViewMatrix); |
193 SkASSERT(fPath); | 192 SkASSERT(fPath); |
194 SkASSERT(fStroke); | |
195 SkASSERT(!fPath->isEmpty()); | 193 SkASSERT(!fPath->isEmpty()); |
196 } | 194 } |
197 }; | 195 }; |
198 | 196 |
199 /** | 197 /** |
200 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already | 198 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already |
201 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. | 199 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. |
202 * | 200 * |
203 */ | 201 */ |
204 void stencilPath(const StencilPathArgs& args) { | 202 void stencilPath(const StencilPathArgs& args) { |
205 SkDEBUGCODE(args.validate();) | 203 SkDEBUGCODE(args.validate();) |
206 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fPat
h, *args.fStroke)); | 204 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fPat
h)); |
207 | 205 |
208 this->onStencilPath(args); | 206 this->onStencilPath(args); |
209 } | 207 } |
210 | 208 |
211 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. | 209 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. |
212 // If we can, we draw lots faster (raster device does this same test). | 210 // If we can, we draw lots faster (raster device does this same test). |
213 static bool IsStrokeHairlineOrEquivalent(const GrStrokeInfo& stroke, const S
kMatrix& matrix, | 211 static bool IsStrokeHairlineOrEquivalent(const GrStrokeInfo& stroke, const S
kMatrix& matrix, |
214 SkScalar* outCoverage) { | 212 SkScalar* outCoverage) { |
215 if (stroke.isDashed()) { | 213 if (stroke.isDashed()) { |
216 return false; | 214 return false; |
(...skipping 22 matching lines...) Expand all Loading... |
239 const GrSurface* device, | 237 const GrSurface* device, |
240 const SkMatrix& matrix, | 238 const SkMatrix& matrix, |
241 SkRect* bounds) { | 239 SkRect* bounds) { |
242 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds
); | 240 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds
); |
243 } | 241 } |
244 | 242 |
245 private: | 243 private: |
246 /** | 244 /** |
247 * Subclass overrides if it has any limitations of stenciling support. | 245 * Subclass overrides if it has any limitations of stenciling support. |
248 */ | 246 */ |
249 virtual StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo
&) const { | 247 virtual StencilSupport onGetStencilSupport(const SkPath&) const { |
250 return kNoRestriction_StencilSupport; | 248 return kNoRestriction_StencilSupport; |
251 } | 249 } |
252 | 250 |
253 /** | 251 /** |
254 * Subclass implementation of drawPath() | 252 * Subclass implementation of drawPath() |
255 */ | 253 */ |
256 virtual bool onDrawPath(const DrawPathArgs& args) = 0; | 254 virtual bool onDrawPath(const DrawPathArgs& args) = 0; |
257 | 255 |
258 /** | 256 /** |
259 * Subclass implementation of canDrawPath() | 257 * Subclass implementation of canDrawPath() |
(...skipping 14 matching lines...) Expand all Loading... |
274 0xffff); | 272 0xffff); |
275 args.fPipelineBuilder->setStencil(kIncrementStencil); | 273 args.fPipelineBuilder->setStencil(kIncrementStencil); |
276 args.fPipelineBuilder->setDisableColorXPFactory(); | 274 args.fPipelineBuilder->setDisableColorXPFactory(); |
277 DrawPathArgs drawArgs; | 275 DrawPathArgs drawArgs; |
278 drawArgs.fTarget = args.fTarget; | 276 drawArgs.fTarget = args.fTarget; |
279 drawArgs.fResourceProvider = args.fResourceProvider; | 277 drawArgs.fResourceProvider = args.fResourceProvider; |
280 drawArgs.fPipelineBuilder = args.fPipelineBuilder; | 278 drawArgs.fPipelineBuilder = args.fPipelineBuilder; |
281 drawArgs.fColor = 0xFFFFFFFF; | 279 drawArgs.fColor = 0xFFFFFFFF; |
282 drawArgs.fViewMatrix = args.fViewMatrix; | 280 drawArgs.fViewMatrix = args.fViewMatrix; |
283 drawArgs.fPath = args.fPath; | 281 drawArgs.fPath = args.fPath; |
284 drawArgs.fStroke = args.fStroke; | 282 drawArgs.fStroke = &GrStrokeInfo::FillInfo(); |
285 drawArgs.fAntiAlias = false; | 283 drawArgs.fAntiAlias = false; |
286 drawArgs.fGammaCorrect = false; | 284 drawArgs.fGammaCorrect = false; |
287 this->drawPath(drawArgs); | 285 this->drawPath(drawArgs); |
288 } | 286 } |
289 | 287 |
290 | 288 |
291 typedef SkRefCnt INHERITED; | 289 typedef SkRefCnt INHERITED; |
292 }; | 290 }; |
293 | 291 |
294 #endif | 292 #endif |
OLD | NEW |