blob: 2d846c852c08b8110c3296508cd974976d509e03 [file] [log] [blame]
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +00001/*
2 Copyright 2011 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17#ifndef GrPathRenderer_DEFINED
18#define GrPathRenderer_DEFINED
19
20#include "GrDrawTarget.h"
21
22class GrPathIter;
23struct GrPoint;
24
25/**
26 * Base class for drawing paths into a GrDrawTarget.
27 */
28class GrPathRenderer : public GrRefCnt {
29public:
30 /**
31 * Returns true if this path renderer is able to render the path.
32 * Returning false allows the caller to fallback to another path renderer.
33 *
34 * @param target The target to draw into
35 * @param path The path to draw
36 * @param fill The fill rule to use
37 *
38 * @return true if the path can be drawn by this object, false otherwise.
39 */
40 virtual bool canDrawPath(const GrDrawTarget* target,
41 GrPathIter* path,
42 GrPathFill fill) const = 0;
43
44 /**
45 * Draws a path into the draw target. The target will already have its draw
46 * state configured for the draw.
47 * @param target the target to draw into.
48 * @param stages indicates which stages the are already
49 * in use. All enabled stages expect positions
50 * as texture coordinates. The path renderer
51 * use the remaining stages for its path
52 * filling algorithm.
53 * @param path the path to draw.
54 * @param fill the fill rule to apply.
55 * @param translate optional additional translation to apply to
56 * the path. NULL means (0,0).
57 */
58 virtual void drawPath(GrDrawTarget* target,
59 GrDrawTarget::StageBitfield stages,
60 GrPathIter* path,
61 GrPathFill fill,
62 const GrPoint* translate) = 0;
63
64 /**
65 * For complex clips Gr uses the stencil buffer. The path renderer must be
66 * able to render paths into the stencil buffer. However, the path renderer
67 * itself may require the stencil buffer to resolve the path fill rule. This
68 * function queries whether the path render needs its own stencil
69 * pass. If this returns false then drawPath() should not modify the
70 * the target's stencil settings but use those already set on target.
71 *
72 * @param target target that the path will be rendered to
73 * @param path the path that will be drawn
74 * @param fill the fill rule that will be used, will never be an inverse
75 * rule.
76 *
77 * @return false if this path renderer can generate interior-only fragments
78 * without changing the stencil settings on the target. If it
79 * returns true the drawPathToStencil will be used when rendering
80 * clips.
81 */
82 virtual bool requiresStencilPass(const GrDrawTarget* target,
83 GrPathIter* path,
84 GrPathFill fill) const { return false; }
85
86 /**
87 * Draws a path to the stencil buffer. Assume the writable stencil bits
88 * are already initialized to zero. Fill will always be either
89 * kWinding_PathFill or kEvenOdd_PathFill.
90 *
91 * Only called if requiresStencilPass returns true for the same combo of
92 * target, path, and fill. Never called with an inverse fill.
93 *
94 * The default implementation assumes the path filling algorithm doesn't
95 * require a separate stencil pass and so crashes.
96 *
97 *
98 * @param target the target to draw into.
99 * @param path the path to draw.
100 * @param fill the fill rule to apply.
101 * @param translate optional additional translation to apply to
102 * the path. NULL means (0,0).
103 */
104 virtual void drawPathToStencil(GrDrawTarget* target,
105 GrPathIter* path,
106 GrPathFill fill,
107 const GrPoint* translate) {
108 GrCrash("Unexpected call to drawPathToStencil.");
109 }
110
111 /**
112 * This is called to install a custom path renderer in every GrContext at
113 * create time. The default implementation in GrCreatePathRenderer_none.cpp
114 * returns NULL. Link against another implementation to install your own.
115 */
116 static GrPathRenderer* CreatePathRenderer();
117
118private:
119
120 typedef GrRefCnt INHERITED;
121};
122
123/**
124 * Subclass that renders the path using the stencil buffer to resolve fill
125 * rules (e.g. winding, even-odd)
126 */
127class GrDefaultPathRenderer : public GrPathRenderer {
128public:
129 GrDefaultPathRenderer(bool separateStencilSupport,
130 bool stencilWrapOpsSupport);
131
132 virtual bool canDrawPath(const GrDrawTarget* target,
133 GrPathIter* path,
134 GrPathFill fill) const { return true; }
135
136 virtual void drawPath(GrDrawTarget* target,
137 GrDrawTarget::StageBitfield stages,
138 GrPathIter* path,
139 GrPathFill fill,
140 const GrPoint* translate);
141 virtual bool requiresStencilPass(const GrDrawTarget* target,
142 GrPathIter* path,
143 GrPathFill fill) const;
144 virtual void drawPathToStencil(GrDrawTarget* target,
145 GrPathIter* path,
146 GrPathFill fill,
147 const GrPoint* translate);
148private:
149
150 void drawPathHelper(GrDrawTarget* target,
151 GrDrawTarget::StageBitfield stages,
152 GrPathIter* path,
153 GrPathFill fill,
154 const GrPoint* translate,
155 bool stencilOnly);
156
157 bool fSeparateStencil;
158 bool fStencilWrapOps;
159
160 typedef GrPathRenderer INHERITED;
161};
162
163#endif
164/*
165 Copyright 2011 Google Inc.
166
167 Licensed under the Apache License, Version 2.0 (the "License");
168 you may not use this file except in compliance with the License.
169 You may obtain a copy of the License at
170
171 http://www.apache.org/licenses/LICENSE-2.0
172
173 Unless required by applicable law or agreed to in writing, software
174 distributed under the License is distributed on an "AS IS" BASIS,
175 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
176 See the License for the specific language governing permissions and
177 limitations under the License.
178 */
179
180#ifndef GrPathRenderer_DEFINED
181#define GrPathRenderer_DEFINED
182
183#include "GrDrawTarget.h"
184
185class GrPathIter;
186struct GrPoint;
187
188/**
189 * Base class for drawing paths into a GrDrawTarget.
190 */
191class GrPathRenderer : public GrRefCnt {
192public:
193 /**
194 * Returns true if this path renderer is able to render the path.
195 * Returning false allows the caller to fallback to another path renderer.
196 *
197 * @param target The target to draw into
198 * @param path The path to draw
199 * @param fill The fill rule to use
200 *
201 * @return true if the path can be drawn by this object, false otherwise.
202 */
203 virtual bool canDrawPath(const GrDrawTarget* target,
204 GrPathIter* path,
205 GrPathFill fill) const = 0;
206
207 /**
208 * Draws a path into the draw target. The target will already have its draw
209 * state configured for the draw.
210 * @param target the target to draw into.
211 * @param stages indicates which stages the are already
212 * in use. All enabled stages expect positions
213 * as texture coordinates. The path renderer
214 * use the remaining stages for its path
215 * filling algorithm.
216 * @param path the path to draw.
217 * @param fill the fill rule to apply.
218 * @param translate optional additional translation to apply to
219 * the path. NULL means (0,0).
220 */
221 virtual void drawPath(GrDrawTarget* target,
222 GrDrawTarget::StageBitfield stages,
223 GrPathIter* path,
224 GrPathFill fill,
225 const GrPoint* translate) = 0;
226
227 /**
228 * For complex clips Gr uses the stencil buffer. The path renderer must be
229 * able to render paths into the stencil buffer. However, the path renderer
230 * itself may require the stencil buffer to resolve the path fill rule. This
231 * function queries whether the path render needs its own stencil
232 * pass. If this returns false then drawPath() should not modify the
233 * the target's stencil settings but use those already set on target.
234 *
235 * @param target target that the path will be rendered to
236 * @param path the path that will be drawn
237 * @param fill the fill rule that will be used, will never be an inverse
238 * rule.
239 *
240 * @return false if this path renderer can generate interior-only fragments
241 * without changing the stencil settings on the target. If it
242 * returns true the drawPathToStencil will be used when rendering
243 * clips.
244 */
245 virtual bool requiresStencilPass(const GrDrawTarget* target,
246 GrPathIter* path,
247 GrPathFill fill) const { return false; }
248
249 /**
250 * Draws a path to the stencil buffer. Assume the writable stencil bits
251 * are already initialized to zero. Fill will always be either
252 * kWinding_PathFill or kEvenOdd_PathFill.
253 *
254 * Only called if requiresStencilPass returns true for the same combo of
255 * target, path, and fill. Never called with an inverse fill.
256 *
257 * The default implementation assumes the path filling algorithm doesn't
258 * require a separate stencil pass and so crashes.
259 *
260 *
261 * @param target the target to draw into.
262 * @param path the path to draw.
263 * @param fill the fill rule to apply.
264 * @param translate optional additional translation to apply to
265 * the path. NULL means (0,0).
266 */
267 virtual void drawPathToStencil(GrDrawTarget* target,
268 GrPathIter* path,
269 GrPathFill fill,
270 const GrPoint* translate) {
271 GrCrash("Unexpected call to drawPathToStencil.");
272 }
273
274private:
275
276 typedef GrRefCnt INHERITED;
277};
278
279/**
280 * Subclass that renders the path using the stencil buffer to resolve fill
281 * rules (e.g. winding, even-odd)
282 */
283class GrDefaultPathRenderer : public GrPathRenderer {
284public:
285 GrDefaultPathRenderer(bool separateStencilSupport,
286 bool stencilWrapOpsSupport);
287
288 virtual bool canDrawPath(const GrDrawTarget* target,
289 GrPathIter* path,
290 GrPathFill fill) const { return true; }
291
292 virtual void drawPath(GrDrawTarget* target,
293 GrDrawTarget::StageBitfield stages,
294 GrPathIter* path,
295 GrPathFill fill,
296 const GrPoint* translate);
297 virtual bool requiresStencilPass(const GrDrawTarget* target,
298 GrPathIter* path,
299 GrPathFill fill) const;
300 virtual void drawPathToStencil(GrDrawTarget* target,
301 GrPathIter* path,
302 GrPathFill fill,
303 const GrPoint* translate);
304private:
305
306 void drawPathHelper(GrDrawTarget* target,
307 GrDrawTarget::StageBitfield stages,
308 GrPathIter* path,
309 GrPathFill fill,
310 const GrPoint* translate,
311 bool stencilOnly);
312
313 bool fSeparateStencil;
314 bool fStencilWrapOps;
315
316 typedef GrPathRenderer INHERITED;
317};
318
319#endif