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. |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 24 | * Paths may be drawn multiple times as when tiling for supersampling. The |
| 25 | * calls on GrPathRenderer to draw a path will look like this: |
| 26 | * |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 27 | * pr->setPath(target, path, fill, aa, translate); // sets the path to draw |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 28 | * pr->drawPath(...); // draw the path |
| 29 | * pr->drawPath(...); |
| 30 | * ... |
| 31 | * pr->clearPath(); // finished with the path |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 32 | */ |
bsalomon@google.com | 67dc548 | 2011-04-04 18:45:32 +0000 | [diff] [blame] | 33 | class GR_API GrPathRenderer : public GrRefCnt { |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 34 | public: |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * This is called to install custom path renderers in every GrContext at |
| 38 | * create time. The default implementation in GrCreatePathRenderer_none.cpp |
| 39 | * does not add any additional renderers. Link against another |
bsalomon@google.com | 181e9bd | 2011-09-07 18:42:30 +0000 | [diff] [blame] | 40 | * implementation to install your own. The first added is the most preferred |
| 41 | * path renderer, second is second most preferred, etc. |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 42 | * |
| 43 | * @param context the context that will use the path renderer |
| 44 | * @param flags flags indicating how path renderers will be used |
| 45 | * @param prChain the chain to add path renderers to. |
| 46 | */ |
| 47 | static void AddPathRenderers(GrContext* context, |
| 48 | GrPathRendererChain::UsageFlags flags, |
| 49 | GrPathRendererChain* prChain); |
| 50 | |
| 51 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 52 | GrPathRenderer(); |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * For complex clips Gr uses the stencil buffer. The path renderer must be |
| 56 | * 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] | 57 | * itself may require the stencil buffer to resolve the path fill rule. |
| 58 | * This function queries whether the path render needs its own stencil |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 59 | * pass. If this returns false then drawPath() should not modify the |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 60 | * the target's stencil settings but use those already set on target. The |
| 61 | * target is passed as a param in case the answer depends upon draw state. |
| 62 | * The view matrix and render target set on the draw target may change |
| 63 | * before setPath/drawPath is called and so shouldn't be considered. |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 64 | * |
| 65 | * @param target target that the path will be rendered to |
| 66 | * @param path the path that will be drawn |
| 67 | * @param fill the fill rule that will be used, will never be an inverse |
| 68 | * rule. |
| 69 | * |
| 70 | * @return false if this path renderer can generate interior-only fragments |
| 71 | * without changing the stencil settings on the target. If it |
| 72 | * returns true the drawPathToStencil will be used when rendering |
| 73 | * clips. |
| 74 | */ |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 75 | virtual bool requiresStencilPass(const SkPath& path, |
| 76 | GrPathFill fill, |
| 77 | const GrDrawTarget* target) const { |
| 78 | return false; |
| 79 | } |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 80 | |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 81 | virtual bool canDrawPath(const SkPath& path, |
| 82 | GrPathFill fill, |
| 83 | const GrDrawTarget* target, |
| 84 | bool antiAlias) const = 0; |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 85 | /** |
| 86 | * Draws the path into the draw target. If requiresStencilBuffer returned |
| 87 | * false then the target may be setup for stencil rendering (since the |
| 88 | * path renderer didn't claim that it needs to use the stencil internally). |
| 89 | * |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 90 | * @param stages bitfield that indicates which stages are |
| 91 | * in use. All enabled stages expect positions |
| 92 | * as texture coordinates. The path renderer |
| 93 | * use the remaining stages for its path |
| 94 | * filling algorithm. |
| 95 | */ |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 96 | virtual bool drawPath(const SkPath& path, |
| 97 | GrPathFill fill, |
| 98 | const GrVec* translate, |
| 99 | GrDrawTarget* target, |
| 100 | GrDrawState::StageMask stageMask, |
| 101 | bool antiAlias) { |
| 102 | GrAssert(this->canDrawPath(path, fill, target, antiAlias)); |
| 103 | return this->onDrawPath(path, fill, translate, |
| 104 | target, stageMask, antiAlias); |
| 105 | } |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * 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] | 109 | * are already initialized to zero. Fill will always be either |
| 110 | * kWinding_PathFill or kEvenOdd_PathFill. |
| 111 | * |
| 112 | * Only called if requiresStencilPass returns true for the same combo of |
| 113 | * target, path, and fill. Never called with an inverse fill. |
| 114 | * |
| 115 | * The default implementation assumes the path filling algorithm doesn't |
| 116 | * require a separate stencil pass and so crashes. |
| 117 | * |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 118 | */ |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 119 | virtual void drawPathToStencil(const SkPath& path, |
| 120 | GrPathFill fill, |
| 121 | GrDrawTarget* target) { |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 122 | GrCrash("Unexpected call to drawPathToStencil."); |
| 123 | } |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 124 | |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 125 | protected: |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 126 | virtual bool onDrawPath(const SkPath& path, |
| 127 | GrPathFill fill, |
| 128 | const GrVec* translate, |
| 129 | GrDrawTarget* target, |
| 130 | GrDrawState::StageMask stageMask, |
| 131 | bool antiAlias) = 0; |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 132 | |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 133 | private: |
| 134 | |
| 135 | typedef GrRefCnt INHERITED; |
| 136 | }; |
| 137 | |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 138 | #endif |
bsalomon@google.com | ee43512 | 2011-07-01 14:57:55 +0000 | [diff] [blame] | 139 | |