bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 22 | class GrPathIter; |
| 23 | struct GrPoint; |
| 24 | |
| 25 | /** |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 26 | * Base class for drawing paths into a GrDrawTarget. |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 27 | */ |
| 28 | class GrPathRenderer { |
| 29 | public: |
| 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 37 | * use the remaining stages for its path |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 38 | * 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 42 | * the path. NULL means (0,0). |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 43 | */ |
| 44 | virtual void drawPath(GrDrawTarget* target, |
| 45 | GrDrawTarget::StageBitfield stages, |
| 46 | GrPathIter* path, |
| 47 | GrPathFill fill, |
| 48 | const GrPoint* translate) = 0; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 49 | |
| 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.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 63 | * function queries whether the path render needs its own stencil |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 64 | * pass. If this returns false then drawPath() should not modify the |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 65 | * 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 70 | * |
| 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.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 76 | virtual bool requiresStencilPass(const GrDrawTarget* target, |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 77 | GrPathIter* path, |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 78 | GrPathFill fill) const { return false; } |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 79 | |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 80 | bool requiresStencilPass(const GrDrawTarget* target, |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 81 | const GrPath& path, |
| 82 | GrPathFill fill) const { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 83 | GrPath::Iter iter(path); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 84 | return requiresStencilPass(target, &iter, fill); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /** |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 88 | * Draws a path to the stencil buffer. Assume the writable stencil bits |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 89 | * are already initialized to zero. Fill will always be either |
| 90 | * kWinding_PathFill or kEvenOdd_PathFill. |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 91 | * |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 92 | * 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.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 98 | * |
| 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.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 109 | GrCrash("Unexpected call to drawPathToStencil."); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 110 | } |
| 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.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 121 | /** |
| 122 | * Subclass that renders the path using the stencil buffer to resolve fill |
| 123 | * rules (e.g. winding, even-odd) |
| 124 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 125 | class GrDefaultPathRenderer : public GrPathRenderer { |
| 126 | public: |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 127 | GrDefaultPathRenderer(bool separateStencilSupport, |
| 128 | bool stencilWrapOpsSupport); |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 129 | |
| 130 | virtual void drawPath(GrDrawTarget* target, |
| 131 | GrDrawTarget::StageBitfield stages, |
| 132 | GrPathIter* path, |
| 133 | GrPathFill fill, |
| 134 | const GrPoint* translate); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 135 | virtual bool requiresStencilPass(const GrDrawTarget* target, |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 136 | GrPathIter* path, |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 137 | GrPathFill fill) const; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 138 | virtual void drawPathToStencil(GrDrawTarget* target, |
| 139 | GrPathIter* path, |
| 140 | GrPathFill fill, |
| 141 | const GrPoint* translate); |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 142 | private: |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 143 | |
| 144 | void drawPathHelper(GrDrawTarget* target, |
| 145 | GrDrawTarget::StageBitfield stages, |
| 146 | GrPathIter* path, |
| 147 | GrPathFill fill, |
| 148 | const GrPoint* translate, |
| 149 | bool stencilOnly); |
| 150 | |
| 151 | bool fSeparateStencil; |
| 152 | bool fStencilWrapOps; |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 155 | #endif |