Flutter Engine
The Flutter Engine
PathTessellator.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
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 PathTessellator_DEFINED
9#define PathTessellator_DEFINED
10
17
19class GrOpFlushState;
20class SkPath;
21
22namespace skgpu::ganesh {
23
24// Prepares GPU data for, and then draws a path's tessellated geometry. Depending on the subclass,
25// the caller may or may not be required to draw the path's inner fan separately.
27public:
29
30 struct PathDrawList {
31 PathDrawList(const SkMatrix& pathMatrix,
32 const SkPath& path,
33 const SkPMColor4f& color,
34 PathDrawList* next = nullptr)
35 : fPathMatrix(pathMatrix), fPath(path), fColor(color), fNext(next) {}
36
41
42 struct Iter {
43 void operator++() { fHead = fHead->fNext; }
44 bool operator!=(const Iter& b) const { return fHead != b.fHead; }
45 std::tuple<const SkMatrix&, const SkPath&, const SkPMColor4f&> operator*() const {
47 }
49 };
50 Iter begin() const { return {this}; }
51 Iter end() const { return {nullptr}; }
52 };
53
54 virtual ~PathTessellator() {}
55
57
58 // Called before draw(). Prepares GPU buffers containing the geometry to tessellate.
60 const SkMatrix& shaderMatrix,
61 const PathDrawList& pathDrawList,
62 int totalCombinedPathVerbCnt) = 0;
63
64 // Issues fixed-count instanced draw calls over the patches. The caller is responsible for
65 // binding its desired pipeline ahead of time.
66 virtual void draw(GrOpFlushState* flushState) const = 0;
67
68protected:
69 PathTessellator(bool infinitySupport, PatchAttribs attribs) : fAttribs(attribs) {
70 if (!infinitySupport) {
71 fAttribs |= PatchAttribs::kExplicitCurveType;
72 }
73 }
74
76
78 // The max number of vertices that must be drawn to account for the accumulated tessellation
79 // levels of the written patches.
81
84};
85
86// Draws an array of "outer curve" patches. Each patch is an independent 4-point curve, representing
87// either a cubic or a conic. Quadratics are converted to cubics and triangles are converted to
88// conics with w=Inf.
90public:
92 bool infinitySupport,
94 return arena->make<PathCurveTessellator>(infinitySupport, attribs);
95 }
96
97 PathCurveTessellator(bool infinitySupport,
99 : PathTessellator(infinitySupport, attribs) {}
100
102 const SkMatrix& shaderMatrix,
104 const PathDrawList& pathDrawList,
105 int totalCombinedPathVerbCnt);
106
108 const SkMatrix& shaderMatrix,
109 const PathDrawList& pathDrawList,
110 int totalCombinedPathVerbCnt) final {
112 shaderMatrix,
113 nullptr, // no extra triangles by default
114 pathDrawList,
115 totalCombinedPathVerbCnt);
116 }
117
118 void draw(GrOpFlushState*) const final;
119
120 // Draws a 4-point instance for each patch. This method is used for drawing convex hulls over
121 // each cubic with GrFillCubicHullShader. The caller is responsible for binding its desired
122 // pipeline ahead of time.
123 void drawHullInstances(GrOpFlushState*, sk_sp<const GrGpuBuffer> vertexBufferIfNeeded) const;
124};
125
126// Prepares an array of "wedge" patches. A wedge is an independent, 5-point closed contour
127// consisting of 4 control points plus an anchor point fanning from the center of the curve's
128// resident contour. A wedge can be either a cubic or a conic. Quadratics and lines are converted to
129// cubics. Once stencilled, these wedges alone define the complete path.
131public:
133 bool infinitySupport,
135 return arena->make<PathWedgeTessellator>(infinitySupport, attribs);
136 }
137
139 : PathTessellator(infinitySupport, attribs) {
140 fAttribs |= PatchAttribs::kFanPoint;
141 }
142
144 const SkMatrix& shaderMatrix,
145 const PathDrawList& pathDrawList,
146 int totalCombinedPathVerbCnt) final;
147
148 void draw(GrOpFlushState*) const final;
149};
150
151} // namespace skgpu::ganesh
152
153#endif // PathTessellator_DEFINED
static float next(float f)
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
Definition: SkPath.h:59
static PathCurveTessellator * Make(SkArenaAlloc *arena, bool infinitySupport, PatchAttribs attribs=PatchAttribs::kNone)
PathCurveTessellator(bool infinitySupport, PatchAttribs attribs=PatchAttribs::kNone)
void prepare(GrMeshDrawTarget *target, const SkMatrix &shaderMatrix, const PathDrawList &pathDrawList, int totalCombinedPathVerbCnt) final
void drawHullInstances(GrOpFlushState *, sk_sp< const GrGpuBuffer > vertexBufferIfNeeded) const
void prepareWithTriangles(GrMeshDrawTarget *target, const SkMatrix &shaderMatrix, GrInnerFanTriangulator::BreadcrumbTriangleList *extraTriangles, const PathDrawList &pathDrawList, int totalCombinedPathVerbCnt)
void draw(GrOpFlushState *) const final
GrVertexChunkArray fVertexChunkArray
virtual void prepare(GrMeshDrawTarget *target, const SkMatrix &shaderMatrix, const PathDrawList &pathDrawList, int totalCombinedPathVerbCnt)=0
sk_sp< const GrGpuBuffer > fFixedIndexBuffer
virtual void draw(GrOpFlushState *flushState) const =0
sk_sp< const GrGpuBuffer > fFixedVertexBuffer
PatchAttribs patchAttribs() const
PathTessellator(bool infinitySupport, PatchAttribs attribs)
void prepare(GrMeshDrawTarget *target, const SkMatrix &shaderMatrix, const PathDrawList &pathDrawList, int totalCombinedPathVerbCnt) final
PathWedgeTessellator(bool infinitySupport, PatchAttribs attribs=PatchAttribs::kNone)
void draw(GrOpFlushState *) const final
static PathWedgeTessellator * Make(SkArenaAlloc *arena, bool infinitySupport, PatchAttribs attribs=PatchAttribs::kNone)
DlColor color
static bool b
uint32_t * target
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
std::tuple< const SkMatrix &, const SkPath &, const SkPMColor4f & > operator*() const
PathDrawList(const SkMatrix &pathMatrix, const SkPath &path, const SkPMColor4f &color, PathDrawList *next=nullptr)