blob: 6a6cea6a3f52179abc4803396a5a1fc6729bcbbf [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comdfe75bc2011-03-25 12:31:16 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +000010#ifndef GrPathRenderer_DEFINED
11#define GrPathRenderer_DEFINED
12
13#include "GrDrawTarget.h"
bsalomon@google.com30085192011-08-19 15:42:31 +000014#include "GrPathRendererChain.h"
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +000015
bsalomon@google.com49313f62011-09-14 13:54:05 +000016#include "SkTArray.h"
17
reed@google.com07f3ee12011-05-16 17:21:57 +000018class SkPath;
bsalomon@google.com30085192011-08-19 15:42:31 +000019
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +000020struct GrPoint;
21
22/**
23 * Base class for drawing paths into a GrDrawTarget.
24 */
bsalomon@google.com67dc5482011-04-04 18:45:32 +000025class GR_API GrPathRenderer : public GrRefCnt {
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +000026public:
bsalomon@google.com30085192011-08-19 15:42:31 +000027
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.com181e9bd2011-09-07 18:42:30 +000032 * implementation to install your own. The first added is the most preferred
33 * path renderer, second is second most preferred, etc.
bsalomon@google.com30085192011-08-19 15:42:31 +000034 *
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.comc2099d22012-03-02 21:26:50 +000044 GrPathRenderer();
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +000045
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.comee435122011-07-01 14:57:55 +000049 * 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.comdfe75bc2011-03-25 12:31:16 +000051 * pass. If this returns false then drawPath() should not modify the
bsalomon@google.comee435122011-07-01 14:57:55 +000052 * 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.comdfe75bc2011-03-25 12:31:16 +000054 *
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.comc2099d22012-03-02 21:26:50 +000065 virtual bool requiresStencilPass(const SkPath& path,
66 GrPathFill fill,
67 const GrDrawTarget* target) const {
68 return false;
69 }
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +000070
bsalomon@google.com208236d2012-03-12 13:15:33 +000071 /**
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.comc2099d22012-03-02 21:26:50 +000084 virtual bool canDrawPath(const SkPath& path,
85 GrPathFill fill,
86 const GrDrawTarget* target,
87 bool antiAlias) const = 0;
bsalomon@google.comee435122011-07-01 14:57:55 +000088 /**
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.com208236d2012-03-12 13:15:33 +000093 * @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.comee435122011-07-01 14:57:55 +000099 * in use. All enabled stages expect positions
100 * as texture coordinates. The path renderer
bsalomon@google.com208236d2012-03-12 13:15:33 +0000101 * can use the remaining stages for its path
bsalomon@google.comee435122011-07-01 14:57:55 +0000102 * filling algorithm.
bsalomon@google.com208236d2012-03-12 13:15:33 +0000103 * @param antiAlias true if anti-aliasing is required.
bsalomon@google.comee435122011-07-01 14:57:55 +0000104 */
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000105 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.comee435122011-07-01 14:57:55 +0000115
116 /**
117 * Draws the path to the stencil buffer. Assume the writable stencil bits
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000118 * 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.comdfe75bc2011-03-25 12:31:16 +0000127 */
bsalomon@google.comc2099d22012-03-02 21:26:50 +0000128 virtual void drawPathToStencil(const SkPath& path,
129 GrPathFill fill,
130 GrDrawTarget* target) {
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000131 GrCrash("Unexpected call to drawPathToStencil.");
132 }
bsalomon@google.com06afe7b2011-04-26 15:31:40 +0000133
tomhudson@google.comd22b6e42011-06-24 15:53:40 +0000134protected:
bsalomon@google.com208236d2012-03-12 13:15:33 +0000135 /**
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.comc2099d22012-03-02 21:26:50 +0000150 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.comd22b6e42011-06-24 15:53:40 +0000156
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000157private:
158
159 typedef GrRefCnt INHERITED;
160};
161
bsalomon@google.comdfe75bc2011-03-25 12:31:16 +0000162#endif
bsalomon@google.comee435122011-07-01 14:57:55 +0000163