OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef GrPathRenderer_DEFINED | 9 #ifndef GrPathRenderer_DEFINED |
10 #define GrPathRenderer_DEFINED | 10 #define GrPathRenderer_DEFINED |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 * @param stroke the stroke information (width, join, cap). | 82 * @param stroke the stroke information (width, join, cap). |
83 */ | 83 */ |
84 StencilSupport getStencilSupport(const GrDrawTarget* target, | 84 StencilSupport getStencilSupport(const GrDrawTarget* target, |
85 const GrPipelineBuilder* pipelineBuilder, | 85 const GrPipelineBuilder* pipelineBuilder, |
86 const SkPath& path, | 86 const SkPath& path, |
87 const GrStrokeInfo& stroke) const { | 87 const GrStrokeInfo& stroke) const { |
88 SkASSERT(!path.isInverseFillType()); | 88 SkASSERT(!path.isInverseFillType()); |
89 return this->onGetStencilSupport(target, pipelineBuilder, path, stroke); | 89 return this->onGetStencilSupport(target, pipelineBuilder, path, stroke); |
90 } | 90 } |
91 | 91 |
| 92 /** Args to canDrawPath() |
| 93 * |
| 94 * fTarget The target that the path will be rendered to |
| 95 * fPipelineBuilder The pipelineBuilder |
| 96 * fViewMatrix The viewMatrix |
| 97 * fPath The path to draw |
| 98 * fStroke The stroke information (width, join, cap) |
| 99 * fAntiAlias True if anti-aliasing is required. |
| 100 */ |
| 101 struct CanDrawPathArgs { |
| 102 const GrDrawTarget* fTarget; |
| 103 const GrPipelineBuilder* fPipelineBuilder; |
| 104 const SkMatrix* fViewMatrix; |
| 105 const SkPath* fPath; |
| 106 const GrStrokeInfo* fStroke; |
| 107 bool fAntiAlias; |
| 108 }; |
| 109 |
92 /** | 110 /** |
93 * Returns true if this path renderer is able to render the path. Returning
false allows the | 111 * Returns true if this path renderer is able to render the path. Returning
false allows the |
94 * caller to fallback to another path renderer This function is called when
searching for a path | 112 * caller to fallback to another path renderer This function is called when
searching for a path |
95 * renderer capable of rendering a path. | 113 * renderer capable of rendering a path. |
96 * | 114 * |
97 * @param target The target that the path will be rendered to | |
98 * @param pipelineBuilder The pipelineBuilder | |
99 * @param viewMatrix The viewMatrix | |
100 * @param path The path to draw | |
101 * @param stroke The stroke information (width, join, cap) | |
102 * @param antiAlias True if anti-aliasing is required. | |
103 * | |
104 * @return true if the path can be drawn by this object, false otherwise. | 115 * @return true if the path can be drawn by this object, false otherwise. |
105 */ | 116 */ |
106 virtual bool canDrawPath(const GrDrawTarget* target, | 117 bool canDrawPath(const CanDrawPathArgs& args) const { |
107 const GrPipelineBuilder* pipelineBuilder, | 118 SkASSERT(args.fTarget); |
108 const SkMatrix& viewMatrix, | 119 SkASSERT(args.fPipelineBuilder); |
109 const SkPath& path, | 120 SkASSERT(args.fViewMatrix); |
110 const GrStrokeInfo& rec, | 121 SkASSERT(args.fPath); |
111 bool antiAlias) const = 0; | 122 SkASSERT(args.fStroke); |
| 123 SkASSERT(!args.fPath->isEmpty()); |
| 124 return this->onCanDrawPath(args); |
| 125 } |
| 126 |
| 127 /** |
| 128 * Args to drawPath() |
| 129 * |
| 130 * fTarget The target that the path will be rendered to |
| 131 * fResourceProvider The resource provider for creating gpu resources t
o render the path |
| 132 * fPipelineBuilder The pipelineBuilder |
| 133 * fViewMatrix The viewMatrix |
| 134 * fPath the path to draw. |
| 135 * fStroke the stroke information (width, join, cap) |
| 136 * fAntiAlias true if anti-aliasing is required. |
| 137 */ |
| 138 struct DrawPathArgs { |
| 139 GrDrawTarget* fTarget; |
| 140 GrResourceProvider* fResourceProvider; |
| 141 GrPipelineBuilder* fPipelineBuilder; |
| 142 GrColor fColor; |
| 143 const SkMatrix* fViewMatrix; |
| 144 const SkPath* fPath; |
| 145 const GrStrokeInfo* fStroke; |
| 146 bool fAntiAlias; |
| 147 }; |
| 148 |
112 /** | 149 /** |
113 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then | 150 * Draws the path into the draw target. If getStencilSupport() would return
kNoRestriction then |
114 * the subclass must respect the stencil settings of the target's draw state
. | 151 * the subclass must respect the stencil settings of the GrPipelineBuilder. |
| 152 */ |
| 153 bool drawPath(const DrawPathArgs& args) { |
| 154 SkASSERT(args.fTarget); |
| 155 SkASSERT(args.fPipelineBuilder); |
| 156 SkASSERT(args.fViewMatrix); |
| 157 SkASSERT(args.fPath); |
| 158 SkASSERT(args.fStroke); |
| 159 |
| 160 SkASSERT(!args.fPath->isEmpty()); |
| 161 #ifdef SK_DEBUG |
| 162 CanDrawPathArgs canArgs; |
| 163 canArgs.fTarget = args.fTarget; |
| 164 canArgs.fPipelineBuilder = args.fPipelineBuilder; |
| 165 canArgs.fViewMatrix = args.fViewMatrix; |
| 166 canArgs.fPath = args.fPath; |
| 167 canArgs.fStroke = args.fStroke; |
| 168 canArgs.fAntiAlias = args.fAntiAlias; |
| 169 SkASSERT(this->canDrawPath(canArgs)); |
| 170 SkASSERT(args.fPipelineBuilder->getStencil().isDisabled() || |
| 171 kNoRestriction_StencilSupport == this->getStencilSupport(args.f
Target, |
| 172 args.f
PipelineBuilder, |
| 173 *args.
fPath, |
| 174 *args.
fStroke)); |
| 175 #endif |
| 176 return this->onDrawPath(args); |
| 177 } |
| 178 |
| 179 /* Args to stencilPath(). |
115 * | 180 * |
116 * @param target The target that the path will be rendered to | 181 * fTarget The target that the path will be rendered to. |
117 * @param pipelineBuilder The pipelineBuilder | 182 * fPipelineBuilder The pipeline builder. |
118 * @param viewMatrix The viewMatrix | 183 * fViewMatrix Matrix applied to the path. |
119 * @param path the path to draw. | 184 * fPath The path to draw. |
120 * @param stroke the stroke information (width, join, cap) | 185 * fStroke The stroke information (width, join, cap) |
121 * @param antiAlias true if anti-aliasing is required. | |
122 */ | 186 */ |
123 bool drawPath(GrDrawTarget* target, | 187 struct StencilPathArgs { |
124 GrPipelineBuilder* ds, | 188 GrDrawTarget* fTarget; |
125 GrColor color, | 189 GrPipelineBuilder* fPipelineBuilder; |
126 const SkMatrix& viewMatrix, | 190 GrResourceProvider* fResourceProvider; |
127 const SkPath& path, | 191 const SkMatrix* fViewMatrix; |
128 const GrStrokeInfo& stroke, | 192 const SkPath* fPath; |
129 bool antiAlias) { | 193 const GrStrokeInfo* fStroke; |
130 SkASSERT(!path.isEmpty()); | 194 }; |
131 SkASSERT(this->canDrawPath(target, ds, viewMatrix, path, stroke, antiAli
as)); | |
132 SkASSERT(ds->getStencil().isDisabled() || | |
133 kNoRestriction_StencilSupport == this->getStencilSupport(target
, ds, path, | |
134 stroke
)); | |
135 return this->onDrawPath(target, ds, color, viewMatrix, path, stroke, ant
iAlias); | |
136 } | |
137 | 195 |
138 /** | 196 /** |
139 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already | 197 * Draws the path to the stencil buffer. Assume the writable stencil bits ar
e already |
140 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. | 198 * initialized to zero. The pixels inside the path will have non-zero stenci
l values afterwards. |
141 * | 199 * |
142 * @param path the path to draw. | |
143 * @param stroke the stroke information (width, join, cap) | |
144 * @param target target that the path will be rendered to | |
145 */ | 200 */ |
146 void stencilPath(GrDrawTarget* target, | 201 void stencilPath(const StencilPathArgs& args) { |
147 GrPipelineBuilder* ds, | 202 SkASSERT(args.fTarget); |
148 const SkMatrix& viewMatrix, | 203 SkASSERT(args.fPipelineBuilder); |
149 const SkPath& path, | 204 SkASSERT(args.fResourceProvider); |
150 const GrStrokeInfo& stroke) { | 205 SkASSERT(args.fViewMatrix); |
151 SkASSERT(!path.isEmpty()); | 206 SkASSERT(args.fPath); |
152 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(target, ds
, path, stroke)); | 207 SkASSERT(args.fStroke); |
153 this->onStencilPath(target, ds, viewMatrix, path, stroke); | 208 SkASSERT(!args.fPath->isEmpty()); |
| 209 SkASSERT(kNoSupport_StencilSupport != |
| 210 this->getStencilSupport(args.fTarget, args.fPipelineBuilder, *a
rgs.fPath, |
| 211 *args.fStroke)); |
| 212 this->onStencilPath(args); |
154 } | 213 } |
155 | 214 |
156 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. | 215 // Helper for determining if we can treat a thin stroke as a hairline w/ cov
erage. |
157 // If we can, we draw lots faster (raster device does this same test). | 216 // If we can, we draw lots faster (raster device does this same test). |
158 static bool IsStrokeHairlineOrEquivalent(const GrStrokeInfo& stroke, const S
kMatrix& matrix, | 217 static bool IsStrokeHairlineOrEquivalent(const GrStrokeInfo& stroke, const S
kMatrix& matrix, |
159 SkScalar* outCoverage) { | 218 SkScalar* outCoverage) { |
160 if (stroke.isDashed()) { | 219 if (stroke.isDashed()) { |
161 return false; | 220 return false; |
162 } | 221 } |
163 if (stroke.isHairlineStyle()) { | 222 if (stroke.isHairlineStyle()) { |
164 if (outCoverage) { | 223 if (outCoverage) { |
165 *outCoverage = SK_Scalar1; | 224 *outCoverage = SK_Scalar1; |
166 } | 225 } |
167 return true; | 226 return true; |
168 } | 227 } |
169 return stroke.getStyle() == SkStrokeRec::kStroke_Style && | 228 return stroke.getStyle() == SkStrokeRec::kStroke_Style && |
170 SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage
); | 229 SkDrawTreatAAStrokeAsHairline(stroke.getWidth(), matrix, outCoverage
); |
171 } | 230 } |
172 | 231 |
173 protected: | 232 protected: |
| 233 // Helper for getting the device bounds of a path. Inverse filled paths will
have bounds set |
| 234 // by devSize. Non-inverse path bounds will not necessarily be clipped to de
vSize. |
| 235 static void GetPathDevBounds(const SkPath& path, |
| 236 int devW, |
| 237 int devH, |
| 238 const SkMatrix& matrix, |
| 239 SkRect* bounds); |
| 240 |
| 241 // Helper version that gets the dev width and height from a GrSurface. |
| 242 static void GetPathDevBounds(const SkPath& path, |
| 243 const GrSurface* device, |
| 244 const SkMatrix& matrix, |
| 245 SkRect* bounds) { |
| 246 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds
); |
| 247 } |
| 248 |
| 249 private: |
174 /** | 250 /** |
175 * Subclass overrides if it has any limitations of stenciling support. | 251 * Subclass overrides if it has any limitations of stenciling support. |
176 */ | 252 */ |
177 virtual StencilSupport onGetStencilSupport(const GrDrawTarget*, | 253 virtual StencilSupport onGetStencilSupport(const GrDrawTarget*, |
178 const GrPipelineBuilder*, | 254 const GrPipelineBuilder*, |
179 const SkPath&, | 255 const SkPath&, |
180 const GrStrokeInfo&) const { | 256 const GrStrokeInfo&) const { |
181 return kNoRestriction_StencilSupport; | 257 return kNoRestriction_StencilSupport; |
182 } | 258 } |
183 | 259 |
184 /** | 260 /** |
185 * Subclass implementation of drawPath() | 261 * Subclass implementation of drawPath() |
186 */ | 262 */ |
187 virtual bool onDrawPath(GrDrawTarget*, | 263 virtual bool onDrawPath(const DrawPathArgs& args) = 0; |
188 GrPipelineBuilder*, | 264 |
189 GrColor, | 265 /** |
190 const SkMatrix& viewMatrix, | 266 * Subclass implementation of canDrawPath() |
191 const SkPath&, | 267 */ |
192 const GrStrokeInfo&, | 268 virtual bool onCanDrawPath(const CanDrawPathArgs& args) const = 0; |
193 bool antiAlias) = 0; | |
194 | 269 |
195 /** | 270 /** |
196 * Subclass implementation of stencilPath(). Subclass must override iff it e
ver returns | 271 * Subclass implementation of stencilPath(). Subclass must override iff it e
ver returns |
197 * kStencilOnly in onGetStencilSupport(). | 272 * kStencilOnly in onGetStencilSupport(). |
198 */ | 273 */ |
199 virtual void onStencilPath(GrDrawTarget* target, | 274 virtual void onStencilPath(const StencilPathArgs& args) { |
200 GrPipelineBuilder* pipelineBuilder, | |
201 const SkMatrix& viewMatrix, | |
202 const SkPath& path, | |
203 const GrStrokeInfo& stroke) { | |
204 GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil, | 275 GR_STATIC_CONST_SAME_STENCIL(kIncrementStencil, |
205 kReplace_StencilOp, | 276 kReplace_StencilOp, |
206 kReplace_StencilOp, | 277 kReplace_StencilOp, |
207 kAlways_StencilFunc, | 278 kAlways_StencilFunc, |
208 0xffff, | 279 0xffff, |
209 0xffff, | 280 0xffff, |
210 0xffff); | 281 0xffff); |
211 pipelineBuilder->setStencil(kIncrementStencil); | 282 args.fPipelineBuilder->setStencil(kIncrementStencil); |
212 pipelineBuilder->setDisableColorXPFactory(); | 283 args.fPipelineBuilder->setDisableColorXPFactory(); |
213 this->drawPath(target, pipelineBuilder, GrColor_WHITE, viewMatrix, path,
stroke, false); | 284 DrawPathArgs drawArgs; |
| 285 drawArgs.fTarget = args.fTarget; |
| 286 drawArgs.fResourceProvider = args.fResourceProvider; |
| 287 drawArgs.fPipelineBuilder = args.fPipelineBuilder; |
| 288 drawArgs.fColor = 0xFFFFFFFF; |
| 289 drawArgs.fViewMatrix = args.fViewMatrix; |
| 290 drawArgs.fPath = args.fPath; |
| 291 drawArgs.fStroke = args.fStroke; |
| 292 drawArgs.fAntiAlias = false; |
| 293 this->drawPath(drawArgs); |
214 } | 294 } |
215 | 295 |
216 // Helper for getting the device bounds of a path. Inverse filled paths will
have bounds set | |
217 // by devSize. Non-inverse path bounds will not necessarily be clipped to de
vSize. | |
218 static void GetPathDevBounds(const SkPath& path, | |
219 int devW, | |
220 int devH, | |
221 const SkMatrix& matrix, | |
222 SkRect* bounds); | |
223 | |
224 // Helper version that gets the dev width and height from a GrSurface. | |
225 static void GetPathDevBounds(const SkPath& path, | |
226 const GrSurface* device, | |
227 const SkMatrix& matrix, | |
228 SkRect* bounds) { | |
229 GetPathDevBounds(path, device->width(), device->height(), matrix, bounds
); | |
230 } | |
231 | |
232 private: | |
233 | 296 |
234 typedef SkRefCnt INHERITED; | 297 typedef SkRefCnt INHERITED; |
235 }; | 298 }; |
236 | 299 |
237 #endif | 300 #endif |
OLD | NEW |