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: |
djsollen@google.com | cd9d69b | 2011-03-14 20:30:14 +0000 | [diff] [blame^] | 30 | virtual ~GrPathRenderer() { }; |
| 31 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 32 | /** |
| 33 | * Draws a path into the draw target. The target will already have its draw |
| 34 | * state configured for the draw. |
| 35 | * @param target the target to draw into. |
| 36 | * @param stages indicates which stages the are already |
| 37 | * in use. All enabled stages expect positions |
| 38 | * as texture coordinates. The path renderer |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 39 | * use the remaining stages for its path |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 40 | * filling algorithm. |
| 41 | * @param path the path to draw. |
| 42 | * @param fill the fill rule to apply. |
| 43 | * @param translate optional additional translation to apply to |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 44 | * the path. NULL means (0,0). |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 45 | */ |
| 46 | virtual void drawPath(GrDrawTarget* target, |
| 47 | GrDrawTarget::StageBitfield stages, |
| 48 | GrPathIter* path, |
| 49 | GrPathFill fill, |
| 50 | const GrPoint* translate) = 0; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 51 | |
| 52 | void drawPath(GrDrawTarget* target, |
| 53 | GrDrawTarget::StageBitfield stages, |
| 54 | const GrPath& path, |
| 55 | GrPathFill fill, |
| 56 | const GrPoint* translate) { |
| 57 | GrPath::Iter iter(path); |
| 58 | this->drawPath(target, stages, &iter, fill, translate); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * For complex clips Gr uses the stencil buffer. The path renderer must be |
| 63 | * able to render paths into the stencil buffer. However, the path renderer |
| 64 | * 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] | 65 | * function queries whether the path render needs its own stencil |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 66 | * pass. If this returns false then drawPath() should not modify the |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 67 | * the target's stencil settings but use those already set on target. |
| 68 | * |
| 69 | * @param target target that the path will be rendered to |
| 70 | * @param path the path that will be drawn |
| 71 | * @param fill the fill rule that will be used |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 72 | * |
| 73 | * @return false if this path renderer can generate interior-only fragments |
| 74 | * without changing the stencil settings on the target. If it |
| 75 | * returns true the drawPathToStencil will be used when rendering |
| 76 | * clips. |
| 77 | */ |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 78 | virtual bool requiresStencilPass(const GrDrawTarget* target, |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 79 | GrPathIter* path, |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 80 | GrPathFill fill) const { return false; } |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 81 | |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 82 | bool requiresStencilPass(const GrDrawTarget* target, |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 83 | const GrPath& path, |
| 84 | GrPathFill fill) const { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 85 | GrPath::Iter iter(path); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 86 | return requiresStencilPass(target, &iter, fill); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 90 | * 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] | 91 | * are already initialized to zero. Fill will always be either |
| 92 | * kWinding_PathFill or kEvenOdd_PathFill. |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 93 | * |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 94 | * Only called if requiresStencilPass returns true for the same combo of |
| 95 | * target, path, and fill (or inverse of the fill). |
| 96 | * |
| 97 | * The default implementation assumes the path filling algorithm doesn't |
| 98 | * require a separate stencil pass and so crashes. |
| 99 | * |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 100 | * |
| 101 | * @param target the target to draw into. |
| 102 | * @param path the path to draw. |
| 103 | * @param fill the fill rule to apply. |
| 104 | * @param translate optional additional translation to apply to |
| 105 | * the path. NULL means (0,0). |
| 106 | */ |
| 107 | virtual void drawPathToStencil(GrDrawTarget* target, |
| 108 | GrPathIter* path, |
| 109 | GrPathFill fill, |
| 110 | const GrPoint* translate) { |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 111 | GrCrash("Unexpected call to drawPathToStencil."); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | void drawPathToStencil(GrDrawTarget* target, |
| 115 | const GrPath& path, |
| 116 | GrPathFill fill, |
| 117 | const GrPoint* translate) { |
| 118 | GrPath::Iter iter(path); |
| 119 | this->drawPathToStencil(target, &iter, fill, translate); |
| 120 | } |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 123 | /** |
| 124 | * Subclass that renders the path using the stencil buffer to resolve fill |
| 125 | * rules (e.g. winding, even-odd) |
| 126 | */ |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 127 | class GrDefaultPathRenderer : public GrPathRenderer { |
| 128 | public: |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 129 | GrDefaultPathRenderer(bool separateStencilSupport, |
| 130 | bool stencilWrapOpsSupport); |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 131 | |
| 132 | virtual void drawPath(GrDrawTarget* target, |
| 133 | GrDrawTarget::StageBitfield stages, |
| 134 | GrPathIter* path, |
| 135 | GrPathFill fill, |
| 136 | const GrPoint* translate); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 137 | virtual bool requiresStencilPass(const GrDrawTarget* target, |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 138 | GrPathIter* path, |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 139 | GrPathFill fill) const; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 140 | virtual void drawPathToStencil(GrDrawTarget* target, |
| 141 | GrPathIter* path, |
| 142 | GrPathFill fill, |
| 143 | const GrPoint* translate); |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 144 | private: |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 145 | |
| 146 | void drawPathHelper(GrDrawTarget* target, |
| 147 | GrDrawTarget::StageBitfield stages, |
| 148 | GrPathIter* path, |
| 149 | GrPathFill fill, |
| 150 | const GrPoint* translate, |
| 151 | bool stencilOnly); |
| 152 | |
| 153 | bool fSeparateStencil; |
| 154 | bool fStencilWrapOps; |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 155 | }; |
| 156 | |
reed@google.com | 480ab7d | 2011-03-08 15:36:57 +0000 | [diff] [blame] | 157 | #endif |