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 "GrDrawContext.h" | 11 #include "GrDrawContext.h" |
12 #include "GrPaint.h" | 12 #include "GrPaint.h" |
13 #include "GrResourceProvider.h" | 13 #include "GrResourceProvider.h" |
14 #include "GrStyle.h" | 14 #include "GrShape.h" |
15 | 15 |
16 #include "SkDrawProcs.h" | 16 #include "SkDrawProcs.h" |
17 #include "SkTArray.h" | 17 #include "SkTArray.h" |
18 | 18 |
19 class SkPath; | 19 class SkPath; |
20 class GrFixedClip; | 20 class GrFixedClip; |
21 struct GrPoint; | 21 struct GrPoint; |
22 | 22 |
23 /** | 23 /** |
24 * Base class for drawing paths into a GrDrawTarget. | 24 * Base class for drawing paths into a GrDrawTarget. |
(...skipping 28 matching lines...) Expand all Loading... | |
53 enum StencilSupport { | 53 enum StencilSupport { |
54 kNoSupport_StencilSupport, | 54 kNoSupport_StencilSupport, |
55 kStencilOnly_StencilSupport, | 55 kStencilOnly_StencilSupport, |
56 kNoRestriction_StencilSupport, | 56 kNoRestriction_StencilSupport, |
57 }; | 57 }; |
58 | 58 |
59 /** | 59 /** |
60 * This function is to get the stencil support for a particular path. The pa th's fill must | 60 * This function is to get the stencil support for a particular path. The pa th's fill must |
61 * not be an inverse type. The path will always be filled and not stroked. | 61 * not be an inverse type. The path will always be filled and not stroked. |
62 * | 62 * |
63 * @param path the path that will be drawn | 63 * @param shape the shape that will be drawn. Must be simple fill styled a nd non-inverse |
64 * filled. | |
64 */ | 65 */ |
65 StencilSupport getStencilSupport(const SkPath& path) const { | 66 StencilSupport getStencilSupport(const GrShape& shape) const { |
67 SkDEBUGCODE(SkPath path;) | |
68 SkDEBUGCODE(shape.asPath(&path);) | |
69 SkASSERT(shape.style().isSimpleFill()); | |
66 SkASSERT(!path.isInverseFillType()); | 70 SkASSERT(!path.isInverseFillType()); |
67 return this->onGetStencilSupport(path); | 71 return this->onGetStencilSupport(shape); |
68 } | 72 } |
69 | 73 |
70 /** Args to canDrawPath() | 74 /** Args to canDrawPath() |
71 * | 75 * |
72 * fShaderCaps The shader caps | 76 * fShaderCaps The shader caps |
73 * fPipelineBuilder The pipelineBuilder | 77 * fPipelineBuilder The pipelineBuilder |
74 * fViewMatrix The viewMatrix | 78 * fViewMatrix The viewMatrix |
75 * fPath The path to draw | 79 * fShape The shape to draw |
76 * fStyle The styling info (path effect, stroking info) | |
77 * fAntiAlias True if anti-aliasing is required. | 80 * fAntiAlias True if anti-aliasing is required. |
78 */ | 81 */ |
79 struct CanDrawPathArgs { | 82 struct CanDrawPathArgs { |
80 const GrShaderCaps* fShaderCaps; | 83 const GrShaderCaps* fShaderCaps; |
81 const SkMatrix* fViewMatrix; | 84 const SkMatrix* fViewMatrix; |
82 const SkPath* fPath; | 85 const GrShape* fShape; |
83 const GrStyle* fStyle; | |
84 bool fAntiAlias; | 86 bool fAntiAlias; |
85 | 87 |
86 // These next two are only used by GrStencilAndCoverPathRenderer | 88 // These next two are only used by GrStencilAndCoverPathRenderer |
87 bool fHasUserStencilSettings; | 89 bool fHasUserStencilSettings; |
88 bool fIsStencilBufferMSAA; | 90 bool fIsStencilBufferMSAA; |
89 | 91 |
90 void validate() const { | 92 void validate() const { |
91 SkASSERT(fShaderCaps); | 93 SkASSERT(fShaderCaps); |
92 SkASSERT(fViewMatrix); | 94 SkASSERT(fViewMatrix); |
93 SkASSERT(fPath); | 95 SkASSERT(fShape); |
94 SkASSERT(fStyle); | |
95 SkASSERT(!fPath->isEmpty()); | |
96 } | 96 } |
97 }; | 97 }; |
98 | 98 |
99 /** | 99 /** |
100 * Returns true if this path renderer is able to render the path. Returning false allows the | 100 * Returns true if this path renderer is able to render the path. Returning false allows the |
101 * caller to fallback to another path renderer This function is called when searching for a path | 101 * caller to fallback to another path renderer This function is called when searching for a path |
102 * renderer capable of rendering a path. | 102 * renderer capable of rendering a path. |
103 * | 103 * |
104 * @return true if the path can be drawn by this object, false otherwise. | 104 * @return true if the path can be drawn by this object, false otherwise. |
105 */ | 105 */ |
106 bool canDrawPath(const CanDrawPathArgs& args) const { | 106 bool canDrawPath(const CanDrawPathArgs& args) const { |
107 SkDEBUGCODE(args.validate();) | 107 SkDEBUGCODE(args.validate();) |
108 return this->onCanDrawPath(args); | 108 return this->onCanDrawPath(args); |
109 } | 109 } |
110 | 110 |
111 /** | 111 /** |
112 * Args to drawPath() | 112 * Args to drawPath() |
113 * | 113 * |
114 * fTarget The target that the path will be rendered to | 114 * fTarget The target that the path will be rendered to |
115 * fResourceProvider The resource provider for creating gpu resources t o render the path | 115 * fResourceProvider The resource provider for creating gpu resources t o render the path |
116 * fPipelineBuilder The pipelineBuilder | 116 * fPipelineBuilder The pipelineBuilder |
117 * fClip The clip | 117 * fClip The clip |
118 * fColor Color to render with | 118 * fColor Color to render with |
119 * fViewMatrix The viewMatrix | 119 * fViewMatrix The viewMatrix |
120 * fPath the path to draw. | 120 * fShape The shape to draw |
121 * fStyle the style information (path effect, stroke info) | |
122 * fAntiAlias true if anti-aliasing is required. | 121 * fAntiAlias true if anti-aliasing is required. |
123 * fGammaCorrect true if gamma-correct rendering is to be used. | 122 * fGammaCorrect true if gamma-correct rendering is to be used. |
124 */ | 123 */ |
125 struct DrawPathArgs { | 124 struct DrawPathArgs { |
126 GrResourceProvider* fResourceProvider; | 125 GrResourceProvider* fResourceProvider; |
127 const GrPaint* fPaint; | 126 const GrPaint* fPaint; |
128 const GrUserStencilSettings*fUserStencilSettings; | 127 const GrUserStencilSettings*fUserStencilSettings; |
129 | 128 |
130 GrDrawContext* fDrawContext; | 129 GrDrawContext* fDrawContext; |
131 const GrClip* fClip; | 130 const GrClip* fClip; |
132 GrColor fColor; | 131 GrColor fColor; |
133 const SkMatrix* fViewMatrix; | 132 const SkMatrix* fViewMatrix; |
134 const SkPath* fPath; | 133 const GrShape* fShape; |
135 const GrStyle* fStyle; | |
136 bool fAntiAlias; | 134 bool fAntiAlias; |
137 bool fGammaCorrect; | 135 bool fGammaCorrect; |
138 | 136 |
139 void validate() const { | 137 void validate() const { |
140 SkASSERT(fResourceProvider); | 138 SkASSERT(fResourceProvider); |
141 SkASSERT(fPaint); | 139 SkASSERT(fPaint); |
142 SkASSERT(fUserStencilSettings); | 140 SkASSERT(fUserStencilSettings); |
143 SkASSERT(fDrawContext); | 141 SkASSERT(fDrawContext); |
144 SkASSERT(fClip); | 142 SkASSERT(fClip); |
145 SkASSERT(fViewMatrix); | 143 SkASSERT(fViewMatrix); |
146 SkASSERT(fPath); | 144 SkASSERT(fShape); |
147 SkASSERT(fStyle); | |
148 SkASSERT(!fPath->isEmpty()); | |
149 } | 145 } |
150 }; | 146 }; |
151 | 147 |
152 /** | 148 /** |
153 * Draws the path into the draw target. If getStencilSupport() would return kNoRestriction then | 149 * Draws the path into the draw target. If getStencilSupport() would return kNoRestriction then |
154 * the subclass must respect the stencil settings of the GrPipelineBuilder. | 150 * the subclass must respect the stencil settings of the GrPipelineBuilder. |
155 */ | 151 */ |
156 bool drawPath(const DrawPathArgs& args) { | 152 bool drawPath(const DrawPathArgs& args) { |
157 SkDEBUGCODE(args.validate();) | 153 SkDEBUGCODE(args.validate();) |
158 #ifdef SK_DEBUG | 154 #ifdef SK_DEBUG |
159 CanDrawPathArgs canArgs; | 155 CanDrawPathArgs canArgs; |
160 canArgs.fShaderCaps = args.fResourceProvider->caps()->shaderCaps(); | 156 canArgs.fShaderCaps = args.fResourceProvider->caps()->shaderCaps(); |
161 canArgs.fViewMatrix = args.fViewMatrix; | 157 canArgs.fViewMatrix = args.fViewMatrix; |
162 canArgs.fPath = args.fPath; | 158 canArgs.fShape = args.fShape; |
163 canArgs.fStyle = args.fStyle; | |
164 canArgs.fAntiAlias = args.fAntiAlias; | 159 canArgs.fAntiAlias = args.fAntiAlias; |
165 | 160 |
166 canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused() ; | 161 canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused() ; |
167 canArgs.fIsStencilBufferMSAA = args.fDrawContext->isStencilBufferMultisa mpled(); | 162 canArgs.fIsStencilBufferMSAA = args.fDrawContext->isStencilBufferMultisa mpled(); |
168 SkASSERT(this->canDrawPath(canArgs)); | 163 SkASSERT(this->canDrawPath(canArgs)); |
169 if (!args.fUserStencilSettings->isUnused()) { | 164 if (!args.fUserStencilSettings->isUnused()) { |
170 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*a rgs.fPath)); | 165 SkPath path; |
171 SkASSERT(args.fStyle->isSimpleFill()); | 166 args.fShape->asPath(&path); |
167 SkASSERT(args.fShape->style().isSimpleFill()); | |
168 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*a rgs.fShape)); | |
172 } | 169 } |
173 #endif | 170 #endif |
174 return this->onDrawPath(args); | 171 return this->onDrawPath(args); |
175 } | 172 } |
176 | 173 |
177 /* Args to stencilPath(). | 174 /* Args to stencilPath(). |
178 * | 175 * |
179 * fResourceProvider The resource provider for creating gpu resources t o render the path | 176 * fResourceProvider The resource provider for creating gpu resources t o render the path |
180 * fDrawContext The target of the draws | 177 * fDrawContext The target of the draws |
181 * fViewMatrix Matrix applied to the path. | 178 * fViewMatrix Matrix applied to the path. |
182 * fPath The path to draw. | 179 * fPath The path to draw. |
183 * fIsAA Is the path to be drawn AA (only set when MSAA is available) | 180 * fIsAA Is the path to be drawn AA (only set when MSAA is available) |
184 */ | 181 */ |
185 struct StencilPathArgs { | 182 struct StencilPathArgs { |
186 GrResourceProvider* fResourceProvider; | 183 GrResourceProvider* fResourceProvider; |
187 GrDrawContext* fDrawContext; | 184 GrDrawContext* fDrawContext; |
188 const GrFixedClip* fClip; | 185 const GrFixedClip* fClip; |
189 const SkMatrix* fViewMatrix; | 186 const SkMatrix* fViewMatrix; |
190 const SkPath* fPath; | |
191 bool fIsAA; | 187 bool fIsAA; |
188 const GrShape* fShape; | |
192 | 189 |
193 void validate() const { | 190 void validate() const { |
194 SkASSERT(fResourceProvider); | 191 SkASSERT(fResourceProvider); |
195 SkASSERT(fDrawContext); | 192 SkASSERT(fDrawContext); |
196 SkASSERT(fViewMatrix); | 193 SkASSERT(fViewMatrix); |
197 SkASSERT(fPath); | 194 SkASSERT(fShape); |
198 SkASSERT(!fPath->isEmpty()); | 195 SkASSERT(fShape->style().isSimpleFill()) |
robertphillips
2016/06/24 12:43:29
SkDEBUGCODE these next two lines ?
bsalomon
2016/06/24 16:10:23
The calls are in SkDEBUGCODE. I'll put the whole f
| |
196 SkPath path; | |
197 fShape->asPath(&path); | |
198 SkASSERT(!path.isInverseFillType()); | |
199 } | 199 } |
200 }; | 200 }; |
201 | 201 |
202 /** | 202 /** |
203 * 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 |
204 * 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. |
205 */ | 205 */ |
206 void stencilPath(const StencilPathArgs& args) { | 206 void stencilPath(const StencilPathArgs& args) { |
207 SkDEBUGCODE(args.validate();) | 207 SkDEBUGCODE(args.validate();) |
208 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fPat h)); | 208 SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fSha pe)); |
209 this->onStencilPath(args); | 209 this->onStencilPath(args); |
210 } | 210 } |
211 | 211 |
212 // Helper for determining if we can treat a thin stroke as a hairline w/ cov erage. | 212 // Helper for determining if we can treat a thin stroke as a hairline w/ cov erage. |
213 // If we can, we draw lots faster (raster device does this same test). | 213 // If we can, we draw lots faster (raster device does this same test). |
214 static bool IsStrokeHairlineOrEquivalent(const GrStyle& style, const SkMatri x& matrix, | 214 static bool IsStrokeHairlineOrEquivalent(const GrStyle& style, const SkMatri x& matrix, |
215 SkScalar* outCoverage) { | 215 SkScalar* outCoverage) { |
216 if (style.pathEffect()) { | 216 if (style.pathEffect()) { |
217 return false; | 217 return false; |
218 } | 218 } |
(...skipping 14 matching lines...) Expand all Loading... | |
233 static void GetPathDevBounds(const SkPath& path, | 233 static void GetPathDevBounds(const SkPath& path, |
234 int devW, | 234 int devW, |
235 int devH, | 235 int devH, |
236 const SkMatrix& matrix, | 236 const SkMatrix& matrix, |
237 SkRect* bounds); | 237 SkRect* bounds); |
238 | 238 |
239 private: | 239 private: |
240 /** | 240 /** |
241 * Subclass overrides if it has any limitations of stenciling support. | 241 * Subclass overrides if it has any limitations of stenciling support. |
242 */ | 242 */ |
243 virtual StencilSupport onGetStencilSupport(const SkPath&) const { | 243 virtual StencilSupport onGetStencilSupport(const GrShape&) const { |
244 return kNoRestriction_StencilSupport; | 244 return kNoRestriction_StencilSupport; |
245 } | 245 } |
246 | 246 |
247 /** | 247 /** |
248 * Subclass implementation of drawPath() | 248 * Subclass implementation of drawPath() |
249 */ | 249 */ |
250 virtual bool onDrawPath(const DrawPathArgs& args) = 0; | 250 virtual bool onDrawPath(const DrawPathArgs& args) = 0; |
251 | 251 |
252 /** | 252 /** |
253 * Subclass implementation of canDrawPath() | 253 * Subclass implementation of canDrawPath() |
(...skipping 17 matching lines...) Expand all Loading... | |
271 | 271 |
272 GrPaint paint; | 272 GrPaint paint; |
273 | 273 |
274 DrawPathArgs drawArgs; | 274 DrawPathArgs drawArgs; |
275 drawArgs.fResourceProvider = args.fResourceProvider; | 275 drawArgs.fResourceProvider = args.fResourceProvider; |
276 drawArgs.fPaint = &paint; | 276 drawArgs.fPaint = &paint; |
277 drawArgs.fUserStencilSettings = &kIncrementStencil; | 277 drawArgs.fUserStencilSettings = &kIncrementStencil; |
278 drawArgs.fDrawContext = args.fDrawContext; | 278 drawArgs.fDrawContext = args.fDrawContext; |
279 drawArgs.fColor = GrColor_WHITE; | 279 drawArgs.fColor = GrColor_WHITE; |
280 drawArgs.fViewMatrix = args.fViewMatrix; | 280 drawArgs.fViewMatrix = args.fViewMatrix; |
281 drawArgs.fPath = args.fPath; | 281 drawArgs.fShape = args.fShape; |
282 drawArgs.fStyle = &GrStyle::SimpleFill(); | |
283 drawArgs.fAntiAlias = false; // In this case the MSAA handles the AA so we want to draw BW | 282 drawArgs.fAntiAlias = false; // In this case the MSAA handles the AA so we want to draw BW |
284 drawArgs.fGammaCorrect = false; | 283 drawArgs.fGammaCorrect = false; |
285 this->drawPath(drawArgs); | 284 this->drawPath(drawArgs); |
286 } | 285 } |
287 | 286 |
288 typedef SkRefCnt INHERITED; | 287 typedef SkRefCnt INHERITED; |
289 }; | 288 }; |
290 | 289 |
291 #endif | 290 #endif |
OLD | NEW |