epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 10 | #ifndef GrPathRenderer_DEFINED |
| 11 | #define GrPathRenderer_DEFINED |
| 12 | |
| 13 | #include "GrDrawTarget.h" |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 14 | #include "GrPathRendererChain.h" |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 15 | |
bsalomon@google.com | 49313f6 | 2011-09-14 13:54:05 +0000 | [diff] [blame] | 16 | #include "SkTArray.h" |
| 17 | |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 18 | class SkPath; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 19 | |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 20 | struct GrPoint; |
| 21 | |
| 22 | /** |
| 23 | * Base class for drawing paths into a GrDrawTarget. |
| 24 | */ |
bsalomon@google.com | 67dc548 | 2011-04-04 18:45:32 +0000 | [diff] [blame] | 25 | class GR_API GrPathRenderer : public GrRefCnt { |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 26 | public: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * This is called to install custom path renderers in every GrContext at |
| 30 | * create time. The default implementation in GrCreatePathRenderer_none.cpp |
| 31 | * does not add any additional renderers. Link against another |
bsalomon@google.com | 181e9bd | 2011-09-07 18:42:30 +0000 | [diff] [blame] | 32 | * implementation to install your own. The first added is the most preferred |
| 33 | * path renderer, second is second most preferred, etc. |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 34 | * |
| 35 | * @param context the context that will use the path renderer |
| 36 | * @param flags flags indicating how path renderers will be used |
| 37 | * @param prChain the chain to add path renderers to. |
| 38 | */ |
| 39 | static void AddPathRenderers(GrContext* context, |
| 40 | GrPathRendererChain::UsageFlags flags, |
| 41 | GrPathRendererChain* prChain); |
| 42 | |
| 43 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 44 | GrPathRenderer(); |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * For complex clips Gr uses the stencil buffer. The path renderer must be |
| 48 | * able to render paths into the stencil buffer. However, the path renderer |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 49 | * itself may require the stencil buffer to resolve the path fill rule. |
| 50 | * This function queries whether the path render needs its own stencil |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 51 | * pass. If this returns false then drawPath() should not modify the |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 52 | * the target's stencil settings but use those already set on target. The |
| 53 | * target is passed as a param in case the answer depends upon draw state. |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 54 | * |
| 55 | * @param target target that the path will be rendered to |
| 56 | * @param path the path that will be drawn |
| 57 | * @param fill the fill rule that will be used, will never be an inverse |
| 58 | * rule. |
| 59 | * |
| 60 | * @return false if this path renderer can generate interior-only fragments |
| 61 | * without changing the stencil settings on the target. If it |
| 62 | * returns true the drawPathToStencil will be used when rendering |
| 63 | * clips. |
| 64 | */ |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 65 | virtual bool requiresStencilPass(const SkPath& path, |
| 66 | GrPathFill fill, |
| 67 | const GrDrawTarget* target) const { |
| 68 | return false; |
| 69 | } |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 70 | |
bsalomon@google.com | 208236d | 2012-03-12 13:15:33 +0000 | [diff] [blame^] | 71 | /** |
| 72 | * Returns true if this path renderer is able to render the path. |
| 73 | * Returning false allows the caller to fallback to another path renderer |
| 74 | * This function is called when searching for a path renderer capable of |
| 75 | * rendering a path. |
| 76 | * |
| 77 | * @param path The path to draw |
| 78 | * @param fill The fill rule to use |
| 79 | * @param target The target that the path will be rendered to |
| 80 | * @param antiAlias True if anti-aliasing is required. |
| 81 | * |
| 82 | * @return true if the path can be drawn by this object, false otherwise. |
| 83 | */ |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 84 | virtual bool canDrawPath(const SkPath& path, |
| 85 | GrPathFill fill, |
| 86 | const GrDrawTarget* target, |
| 87 | bool antiAlias) const = 0; |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 88 | /** |
| 89 | * Draws the path into the draw target. If requiresStencilBuffer returned |
| 90 | * false then the target may be setup for stencil rendering (since the |
| 91 | * path renderer didn't claim that it needs to use the stencil internally). |
| 92 | * |
bsalomon@google.com | 208236d | 2012-03-12 13:15:33 +0000 | [diff] [blame^] | 93 | * @param path the path to draw. |
| 94 | * @param fill the path filling rule to use. |
| 95 | * @param translate optional additional translation applied to |
| 96 | * the path (can be NULL) |
| 97 | * @param target target that the path will be rendered to |
| 98 | * @param stageMask bitfield that indicates which stages are |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 99 | * in use. All enabled stages expect positions |
| 100 | * as texture coordinates. The path renderer |
bsalomon@google.com | 208236d | 2012-03-12 13:15:33 +0000 | [diff] [blame^] | 101 | * can use the remaining stages for its path |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 102 | * filling algorithm. |
bsalomon@google.com | 208236d | 2012-03-12 13:15:33 +0000 | [diff] [blame^] | 103 | * @param antiAlias true if anti-aliasing is required. |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 104 | */ |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 105 | virtual bool drawPath(const SkPath& path, |
| 106 | GrPathFill fill, |
| 107 | const GrVec* translate, |
| 108 | GrDrawTarget* target, |
| 109 | GrDrawState::StageMask stageMask, |
| 110 | bool antiAlias) { |
| 111 | GrAssert(this->canDrawPath(path, fill, target, antiAlias)); |
| 112 | return this->onDrawPath(path, fill, translate, |
| 113 | target, stageMask, antiAlias); |
| 114 | } |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * Draws the path to the stencil buffer. Assume the writable stencil bits |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 118 | * are already initialized to zero. Fill will always be either |
| 119 | * kWinding_PathFill or kEvenOdd_PathFill. |
| 120 | * |
| 121 | * Only called if requiresStencilPass returns true for the same combo of |
| 122 | * target, path, and fill. Never called with an inverse fill. |
| 123 | * |
| 124 | * The default implementation assumes the path filling algorithm doesn't |
| 125 | * require a separate stencil pass and so crashes. |
| 126 | * |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 127 | */ |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 128 | virtual void drawPathToStencil(const SkPath& path, |
| 129 | GrPathFill fill, |
| 130 | GrDrawTarget* target) { |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 131 | GrCrash("Unexpected call to drawPathToStencil."); |
| 132 | } |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 133 | |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 134 | protected: |
bsalomon@google.com | 208236d | 2012-03-12 13:15:33 +0000 | [diff] [blame^] | 135 | /** |
| 136 | * Draws the path into the draw target. |
| 137 | * |
| 138 | * @param path the path to draw. |
| 139 | * @param fill the path filling rule to use. |
| 140 | * @param translate optional additional translation applied to |
| 141 | * the path |
| 142 | * @param target target that the path will be rendered to |
| 143 | * @param stageMask bitfield that indicates which stages are |
| 144 | * in use. All enabled stages expect positions |
| 145 | * as texture coordinates. The path renderer |
| 146 | * use the remaining stages for its path |
| 147 | * filling algorithm. |
| 148 | * @param antiAlias whether antialiasing is enabled or not. |
| 149 | */ |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 150 | virtual bool onDrawPath(const SkPath& path, |
| 151 | GrPathFill fill, |
| 152 | const GrVec* translate, |
| 153 | GrDrawTarget* target, |
| 154 | GrDrawState::StageMask stageMask, |
| 155 | bool antiAlias) = 0; |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 156 | |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 157 | private: |
| 158 | |
| 159 | typedef GrRefCnt INHERITED; |
| 160 | }; |
| 161 | |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 162 | #endif |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 163 | |