Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PathRenderer.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef PathRenderer_DEFINED
9#define PathRenderer_DEFINED
10
14
15class GrCaps;
16class GrClip;
17class GrHardClip;
18class GrPaint;
21class GrStyledShape;
22class GrStyle;
24struct SkIRect;
25class SkMatrix;
26class SkPath;
27class SkSurfaceProps;
28
29namespace skgpu::ganesh {
30
32
33/**
34 * Base class for drawing paths into a OpsTask.
35 */
36class PathRenderer : public SkRefCnt {
37public:
38 PathRenderer() = default;
39
40 virtual const char* name() const = 0;
41
42 /**
43 * A caller may wish to use a path renderer to draw a path into the stencil buffer. However,
44 * the path renderer itself may require use of the stencil buffer. Also a path renderer may
45 * use a GrProcessor coverage stage that sets coverage to zero to eliminate pixels that are
46 * covered by bounding geometry but outside the path. These exterior pixels would still be
47 * rendered into the stencil.
48 *
49 * A PathRenderer can provide three levels of support for stenciling paths:
50 * 1) kNoRestriction: This is the most general. The caller passes a GrPaint and calls drawPath().
51 * The path is rendered exactly as the draw state indicates including support
52 * for simultaneous color and stenciling with arbitrary stenciling rules.
53 * Pixels partially covered by AA paths are affected by the stencil settings.
54 * 2) kStencilOnly: The path renderer cannot apply arbitrary stencil rules nor shade and stencil
55 * simultaneously. The path renderer does support the stencilPath() function
56 * which performs no color writes and writes a non-zero stencil value to pixels
57 * covered by the path.
58 * 3) kNoSupport: This path renderer cannot be used to stencil the path.
59 */
65
66 /**
67 * This function is to get the stencil support for a particular path. The path's fill must
68 * not be an inverse type. The path will always be filled and not stroked.
69 *
70 * @param shape the shape that will be drawn. Must be simple fill styled and non-inverse
71 * filled.
72 */
74
75 enum class CanDrawPath {
76 kNo,
77 kAsBackup, // i.e. This renderer is better than SW fallback if no others can draw the path.
78 kYes
79 };
80
82 SkDEBUGCODE(CanDrawPathArgs() { memset(this, 0, sizeof(*this)); }) // For validation.
83
84 const GrCaps* fCaps;
92
93 // This is only used by TessellationPathRenderer
95
96#ifdef SK_DEBUG
97 void validate() const {
98 SkASSERT(fCaps);
104 }
105#endif
106 };
107
108 /**
109 * Returns how well this path renderer is able to render the given path. Returning kNo or
110 * kAsBackup allows the caller to keep searching for a better path renderer. This function is
111 * called when searching for the best path renderer to draw a path.
112 */
114 SkDEBUGCODE(args.validate();)
115 return this->onCanDrawPath(args);
116 }
117
140
141 /**
142 * Draws the path into the draw target. If getStencilSupport() would return kNoRestriction then
143 * the subclass must respect the stencil settings.
144 */
145 bool drawPath(const DrawPathArgs& args);
146 /**
147 * Args to stencilPath(). fAAType cannot be kCoverage.
148 */
150 SkDEBUGCODE(StencilPathArgs() { memset(this, 0, sizeof(*this)); }) // For validation.
151
159
160 SkDEBUGCODE(void validate() const;)
161 };
162
163 /**
164 * Draws the path to the stencil buffer. Assume the writable stencil bits are already
165 * initialized to zero. The pixels inside the path will have non-zero stencil values afterwards.
166 */
168 SkDEBUGCODE(args.validate();)
170 this->onStencilPath(args);
171 }
172
173protected:
174 // Helper for getting the device bounds of a path. Inverse filled paths will have bounds set
175 // by devSize. Non-inverse path bounds will not necessarily be clipped to devSize.
176 static void GetPathDevBounds(const SkPath& path,
177 SkISize devSize,
178 const SkMatrix& matrix,
179 SkRect* bounds);
180
181private:
182 /**
183 * Subclass overrides if it has any limitations of stenciling support.
184 */
188
189 /**
190 * Subclass implementation of drawPath()
191 */
192 virtual bool onDrawPath(const DrawPathArgs& args) = 0;
193
194 /**
195 * Subclass implementation of canDrawPath()
196 */
198
199 /**
200 * Subclass implementation of stencilPath(). Subclass must override iff it ever returns
201 * kStencilOnly in onGetStencilSupport().
202 */
203 virtual void onStencilPath(const StencilPathArgs&);
204
205 using INHERITED = SkRefCnt;
206};
207
208} // namespace skgpu::ganesh
209
210#endif // PathRenderer_DEFINED
GrAAType
GrAA
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
const Context & fContext
bool drawPath(const DrawPathArgs &args)
virtual void onStencilPath(const StencilPathArgs &)
virtual StencilSupport onGetStencilSupport(const GrStyledShape &) const
virtual const char * name() const =0
CanDrawPath canDrawPath(const CanDrawPathArgs &args) const
virtual CanDrawPath onCanDrawPath(const CanDrawPathArgs &args) const =0
StencilSupport getStencilSupport(const GrStyledShape &shape) const
static void GetPathDevBounds(const SkPath &path, SkISize devSize, const SkMatrix &matrix, SkRect *bounds)
virtual bool onDrawPath(const DrawPathArgs &args)=0
void stencilPath(const StencilPathArgs &args)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
SkDEBUGCODE(CanDrawPathArgs() { memset(this, 0, sizeof(*this));}) const GrCaps *fCaps
const GrUserStencilSettings * fUserStencilSettings
SkDEBUGCODE(StencilPathArgs() { memset(this, 0, sizeof(*this));}) GrRecordingContext *fContext