blob: 467b0a04d3a8c4ea35f60532078b101403b04d70 [file] [log] [blame]
bsalomon@google.comffca4002011-02-22 20:34:01 +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 * A path renderer.
27 */
28class GrPathRenderer {
29public:
30 /**
31 * Draws a path into the draw target. The target will already have its draw
32 * state configured for the draw.
33 * @param target the target to draw into.
34 * @param stages indicates which stages the are already
35 * in use. All enabled stages expect positions
36 * as texture coordinates. The path renderer
bsalomon@google.comd302f142011-03-03 13:54:13 +000037 * use the remaining stages for its path
bsalomon@google.comffca4002011-02-22 20:34:01 +000038 * filling algorithm.
39 * @param path the path to draw.
40 * @param fill the fill rule to apply.
41 * @param translate optional additional translation to apply to
bsalomon@google.comd302f142011-03-03 13:54:13 +000042 * the path. NULL means (0,0).
bsalomon@google.comffca4002011-02-22 20:34:01 +000043 */
44 virtual void drawPath(GrDrawTarget* target,
45 GrDrawTarget::StageBitfield stages,
46 GrPathIter* path,
47 GrPathFill fill,
48 const GrPoint* translate) = 0;
bsalomon@google.comd302f142011-03-03 13:54:13 +000049
50 void drawPath(GrDrawTarget* target,
51 GrDrawTarget::StageBitfield stages,
52 const GrPath& path,
53 GrPathFill fill,
54 const GrPoint* translate) {
55 GrPath::Iter iter(path);
56 this->drawPath(target, stages, &iter, fill, translate);
57 }
58
59 /**
60 * For complex clips Gr uses the stencil buffer. The path renderer must be
61 * able to render paths into the stencil buffer. However, the path renderer
62 * itself may require the stencil buffer to resolve the path fill rule. This
63 * function queries whether the path render requires its own stencil
64 * pass. If this returns false then drawPath() should not modify the
65 * the target's stencil settings.
66 *
67 * @return false if this path renderer can generate interior-only fragments
68 * without changing the stencil settings on the target. If it
69 * returns true the drawPathToStencil will be used when rendering
70 * clips.
71 */
72 virtual bool requiresStencilPass(GrPathIter*) const { return false; }
73
74 bool requiresStencilPass(const GrPath& path) const {
75 GrPath::Iter iter(path);
76 return requiresStencilPass(&iter);
77 }
78
79 /**
80 * Draws a path to the stencil buffer. Assume the writable bits are zero
81 * prior and write a nonzero value in interior samples. The default
82 * implementation assumes the path filling algorithm doesn't require a
83 * separate stencil pass and so just calls drawPath.
84 *
85 * Fill will never be an inverse fill rule.
86 *
87 * @param target the target to draw into.
88 * @param path the path to draw.
89 * @param fill the fill rule to apply.
90 * @param translate optional additional translation to apply to
91 * the path. NULL means (0,0).
92 */
93 virtual void drawPathToStencil(GrDrawTarget* target,
94 GrPathIter* path,
95 GrPathFill fill,
96 const GrPoint* translate) {
97 GrAssert(kInverseEvenOdd_PathFill != fill);
98 GrAssert(kInverseWinding_PathFill != fill);
99
100 this->drawPath(target, 0, path, fill, translate);
101 }
102
103 void drawPathToStencil(GrDrawTarget* target,
104 const GrPath& path,
105 GrPathFill fill,
106 const GrPoint* translate) {
107 GrPath::Iter iter(path);
108 this->drawPathToStencil(target, &iter, fill, translate);
109 }
bsalomon@google.comffca4002011-02-22 20:34:01 +0000110};
111
112class GrDefaultPathRenderer : public GrPathRenderer {
113public:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000114 GrDefaultPathRenderer(bool separateStencilSupport,
115 bool stencilWrapOpsSupport);
bsalomon@google.comffca4002011-02-22 20:34:01 +0000116
117 virtual void drawPath(GrDrawTarget* target,
118 GrDrawTarget::StageBitfield stages,
119 GrPathIter* path,
120 GrPathFill fill,
121 const GrPoint* translate);
bsalomon@google.comd302f142011-03-03 13:54:13 +0000122 virtual bool requiresStencilPass(GrPath&) const { return true; }
123 virtual void drawPathToStencil(GrDrawTarget* target,
124 GrPathIter* path,
125 GrPathFill fill,
126 const GrPoint* translate);
bsalomon@google.comffca4002011-02-22 20:34:01 +0000127private:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000128
129 void drawPathHelper(GrDrawTarget* target,
130 GrDrawTarget::StageBitfield stages,
131 GrPathIter* path,
132 GrPathFill fill,
133 const GrPoint* translate,
134 bool stencilOnly);
135
136 bool fSeparateStencil;
137 bool fStencilWrapOps;
bsalomon@google.comffca4002011-02-22 20:34:01 +0000138};
139
140#endif