blob: f99b92259c94c31c7c4ea6065092b3f7fc67b202 [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
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000063 * function queries whether the path render needs its own stencil
bsalomon@google.comd302f142011-03-03 13:54:13 +000064 * pass. If this returns false then drawPath() should not modify the
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000065 * the target's stencil settings but use those already set on target.
66 *
67 * @param target target that the path will be rendered to
68 * @param path the path that will be drawn
69 * @param fill the fill rule that will be used
bsalomon@google.comd302f142011-03-03 13:54:13 +000070 *
71 * @return false if this path renderer can generate interior-only fragments
72 * without changing the stencil settings on the target. If it
73 * returns true the drawPathToStencil will be used when rendering
74 * clips.
75 */
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000076 virtual bool requiresStencilPass(const GrDrawTarget* target,
77 GrPathIter* path,
78 GrPathFill fill) const { return false; }
bsalomon@google.comd302f142011-03-03 13:54:13 +000079
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000080 bool requiresStencilPass(const GrDrawTarget* target,
81 const GrPath& path,
82 GrPathFill fill) const {
bsalomon@google.comd302f142011-03-03 13:54:13 +000083 GrPath::Iter iter(path);
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000084 return requiresStencilPass(target, &iter, fill);
bsalomon@google.comd302f142011-03-03 13:54:13 +000085 }
86
87 /**
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000088 * Draws a path to the stencil buffer. Assume the writable stencil bits
89 * are already initialized to zero. Fill will always be either
90 * kWinding_PathFill or kEvenOdd_PathFill.
bsalomon@google.comd302f142011-03-03 13:54:13 +000091 *
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +000092 * Only called if requiresStencilPass returns true for the same combo of
93 * target, path, and fill (or inverse of the fill).
94 *
95 * The default implementation assumes the path filling algorithm doesn't
96 * require a separate stencil pass and so crashes.
97 *
bsalomon@google.comd302f142011-03-03 13:54:13 +000098 *
99 * @param target the target to draw into.
100 * @param path the path to draw.
101 * @param fill the fill rule to apply.
102 * @param translate optional additional translation to apply to
103 * the path. NULL means (0,0).
104 */
105 virtual void drawPathToStencil(GrDrawTarget* target,
106 GrPathIter* path,
107 GrPathFill fill,
108 const GrPoint* translate) {
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000109 GrCrash("Unexpected call to drawPathToStencil.");
bsalomon@google.comd302f142011-03-03 13:54:13 +0000110 }
111
112 void drawPathToStencil(GrDrawTarget* target,
113 const GrPath& path,
114 GrPathFill fill,
115 const GrPoint* translate) {
116 GrPath::Iter iter(path);
117 this->drawPathToStencil(target, &iter, fill, translate);
118 }
bsalomon@google.comffca4002011-02-22 20:34:01 +0000119};
120
121class GrDefaultPathRenderer : public GrPathRenderer {
122public:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000123 GrDefaultPathRenderer(bool separateStencilSupport,
124 bool stencilWrapOpsSupport);
bsalomon@google.comffca4002011-02-22 20:34:01 +0000125
126 virtual void drawPath(GrDrawTarget* target,
127 GrDrawTarget::StageBitfield stages,
128 GrPathIter* path,
129 GrPathFill fill,
130 const GrPoint* translate);
bsalomon@google.com5aaa69e2011-03-04 20:29:08 +0000131 virtual bool requiresStencilPass(const GrDrawTarget* target,
132 GrPathIter* path,
133 GrPathFill fill) const;
bsalomon@google.comd302f142011-03-03 13:54:13 +0000134 virtual void drawPathToStencil(GrDrawTarget* target,
135 GrPathIter* path,
136 GrPathFill fill,
137 const GrPoint* translate);
bsalomon@google.comffca4002011-02-22 20:34:01 +0000138private:
bsalomon@google.comd302f142011-03-03 13:54:13 +0000139
140 void drawPathHelper(GrDrawTarget* target,
141 GrDrawTarget::StageBitfield stages,
142 GrPathIter* path,
143 GrPathFill fill,
144 const GrPoint* translate,
145 bool stencilOnly);
146
147 bool fSeparateStencil;
148 bool fStencilWrapOps;
bsalomon@google.comffca4002011-02-22 20:34:01 +0000149};
150
151#endif