xref: /aosp_15_r20/external/skia/src/gpu/ganesh/ops/PathInnerTriangulateOp.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2019 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 #include "src/gpu/ganesh/ops/PathInnerTriangulateOp.h"
8 
9 #include "include/core/SkPathTypes.h"
10 #include "include/core/SkString.h"
11 #include "include/gpu/ganesh/GrRecordingContext.h"
12 #include "include/private/base/SkAlignedStorage.h"
13 #include "include/private/base/SkOnce.h"
14 #include "src/base/SkArenaAlloc.h"
15 #include "src/core/SkSLTypeShared.h"
16 #include "src/gpu/ResourceKey.h"
17 #include "src/gpu/ganesh/GrAppliedClip.h"
18 #include "src/gpu/ganesh/GrEagerVertexAllocator.h"
19 #include "src/gpu/ganesh/GrGeometryProcessor.h"
20 #include "src/gpu/ganesh/GrOpFlushState.h"
21 #include "src/gpu/ganesh/GrPipeline.h"
22 #include "src/gpu/ganesh/GrProcessorAnalysis.h"
23 #include "src/gpu/ganesh/GrProgramInfo.h"
24 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
25 #include "src/gpu/ganesh/GrRenderTargetProxy.h"
26 #include "src/gpu/ganesh/GrResourceProvider.h"
27 #include "src/gpu/ganesh/GrShaderCaps.h"
28 #include "src/gpu/ganesh/GrShaderVar.h"
29 #include "src/gpu/ganesh/GrSurfaceProxyView.h"
30 #include "src/gpu/ganesh/GrUserStencilSettings.h"
31 #include "src/gpu/ganesh/glsl/GrGLSLVertexGeoBuilder.h"
32 #include "src/gpu/ganesh/ops/FillPathFlags.h"
33 #include "src/gpu/ganesh/tessellate/GrPathTessellationShader.h"
34 #include "src/gpu/ganesh/tessellate/PathTessellator.h"
35 #include "src/gpu/tessellate/Tessellation.h"
36 
37 #include <memory>
38 
39 class GrGLSLVaryingHandler;
40 
41 namespace skgpu {
42 class KeyBuilder;
43 }
44 
45 using namespace skia_private;
46 
47 #if !defined(SK_ENABLE_OPTIMIZE_SIZE)
48 
49 namespace skgpu::ganesh {
50 
51 namespace {
52 
53 // Fills an array of convex hulls surrounding 4-point cubic or conic instances. This shader is used
54 // for the "cover" pass after the curves have been fully stencilled.
55 class HullShader : public GrPathTessellationShader {
56 public:
HullShader(const SkMatrix & viewMatrix,SkPMColor4f color,const GrShaderCaps & shaderCaps)57     HullShader(const SkMatrix& viewMatrix, SkPMColor4f color, const GrShaderCaps& shaderCaps)
58             : GrPathTessellationShader(kTessellate_HullShader_ClassID,
59                                        GrPrimitiveType::kTriangleStrip,
60                                        viewMatrix,
61                                        color,
62                                        PatchAttribs::kNone) {
63         fInstanceAttribs.emplace_back("p01", kFloat4_GrVertexAttribType, SkSLType::kFloat4);
64         fInstanceAttribs.emplace_back("p23", kFloat4_GrVertexAttribType, SkSLType::kFloat4);
65         if (!shaderCaps.fInfinitySupport) {
66             // A conic curve is written out with p3=[w,Infinity], but GPUs that don't support
67             // infinity can't detect this. On these platforms we also write out an extra float with
68             // each patch that explicitly tells the shader what type of curve it is.
69             fInstanceAttribs.emplace_back("curveType", kFloat_GrVertexAttribType, SkSLType::kFloat);
70         }
71         this->setInstanceAttributesWithImplicitOffsets(fInstanceAttribs.data(),
72                                                        fInstanceAttribs.size());
73         SkASSERT(fInstanceAttribs.size() <= kMaxInstanceAttribCount);
74 
75         if (!shaderCaps.fVertexIDSupport) {
76             constexpr static Attribute kVertexIdxAttrib("vertexidx", kFloat_GrVertexAttribType,
77                                                         SkSLType::kFloat);
78             this->setVertexAttributesWithImplicitOffsets(&kVertexIdxAttrib, 1);
79         }
80     }
81 
82 private:
name() const83     const char* name() const final { return "tessellate_HullShader"; }
addToKey(const GrShaderCaps &,KeyBuilder *) const84     void addToKey(const GrShaderCaps&, KeyBuilder*) const final {}
85     std::unique_ptr<ProgramImpl> makeProgramImpl(const GrShaderCaps&) const final;
86 
87     constexpr static int kMaxInstanceAttribCount = 3;
88     STArray<kMaxInstanceAttribCount, Attribute> fInstanceAttribs;
89 };
90 
makeProgramImpl(const GrShaderCaps &) const91 std::unique_ptr<GrGeometryProcessor::ProgramImpl> HullShader::makeProgramImpl(
92         const GrShaderCaps&) const {
93     class Impl : public GrPathTessellationShader::Impl {
94         void emitVertexCode(const GrShaderCaps& shaderCaps,
95                             const GrPathTessellationShader&,
96                             GrGLSLVertexBuilder* v,
97                             GrGLSLVaryingHandler*,
98                             GrGPArgs* gpArgs) override {
99             if (shaderCaps.fInfinitySupport) {
100                 v->insertFunction(
101                 "bool is_conic_curve() { return isinf(p23.w); }"
102                 "bool is_non_triangular_conic_curve() {"
103                     // We consider a conic non-triangular as long as its weight isn't infinity.
104                     // NOTE: "isinf == false" works on Mac Radeon GLSL; "!isinf" can get the wrong
105                     // answer.
106                     "return isinf(p23.z) == false;"
107                 "}"
108                 );
109             } else {
110                 v->insertFunction(SkStringPrintf(
111                 "bool is_conic_curve() { return curveType != %g; }",
112                         tess::kCubicCurveType).c_str());
113                 v->insertFunction(SkStringPrintf(
114                 "bool is_non_triangular_conic_curve() {"
115                     "return curveType == %g;"
116                 "}", tess::kConicCurveType).c_str());
117             }
118             v->codeAppend(
119             "float2 p0=p01.xy, p1=p01.zw, p2=p23.xy, p3=p23.zw;"
120             "if (is_conic_curve()) {"
121                 // Conics are 3 points, with the weight in p3.
122                 "float w = p3.x;"
123                 "p3 = p2;"  // Duplicate the endpoint for shared code that also runs on cubics.
124                 "if (is_non_triangular_conic_curve()) {"
125                     // Convert the points to a trapeziodal hull that circumcscribes the conic.
126                     "float2 p1w = p1 * w;"
127                     "float T = .51;"  // Bias outward a bit to ensure we cover the outermost samples.
128                     "float2 c1 = mix(p0, p1w, T);"
129                     "float2 c2 = mix(p2, p1w, T);"
130                     "float iw = 1 / mix(1, w, T);"
131                     "p2 = c2 * iw;"
132                     "p1 = c1 * iw;"
133                 "}"
134             "}"
135 
136             // Translate the points to v0..3 where v0=0.
137             "float2 v1 = p1 - p0;"
138             "float2 v2 = p2 - p0;"
139             "float2 v3 = p3 - p0;"
140 
141             // Reorder the points so v2 bisects v1 and v3.
142             "if (sign(cross_length_2d(v2, v1)) == sign(cross_length_2d(v2, v3))) {"
143                 "float2 tmp = p2;"
144                 "if (sign(cross_length_2d(v1, v2)) != sign(cross_length_2d(v1, v3))) {"
145                     "p2 = p1;"  // swap(p2, p1)
146                     "p1 = tmp;"
147                 "} else {"
148                     "p2 = p3;"  // swap(p2, p3)
149                     "p3 = tmp;"
150                 "}"
151             "}"
152             );
153 
154             if (shaderCaps.fVertexIDSupport) {
155                 // If we don't have sk_VertexID support then "vertexidx" already came in as a
156                 // vertex attrib.
157                 v->codeAppend(
158                 // sk_VertexID comes in fan order. Convert to strip order.
159                 "int vertexidx = sk_VertexID;"
160                 "vertexidx ^= vertexidx >> 1;");
161             }
162 
163             v->codeAppend(
164             // Find the "turn direction" of each corner and net turn direction.
165             "float vertexdir = 0;"
166             "float netdir = 0;"
167             "float2 prev, next;"
168             "float dir;"
169             "float2 localcoord;"
170             "float2 nextcoord;"
171             );
172 
173             for (int i = 0; i < 4; ++i) {
174                 v->codeAppendf(
175                 "prev = p%i - p%i;", i, (i + 3) % 4);
176                 v->codeAppendf(
177                 "next = p%i - p%i;", (i + 1) % 4, i);
178                 v->codeAppendf(
179                 "dir = sign(cross_length_2d(prev, next));"
180                 "if (vertexidx == %i) {"
181                     "vertexdir = dir;"
182                     "localcoord = p%i;"
183                     "nextcoord = p%i;"
184                 "}"
185                 "netdir += dir;", i, i, (i + 1) % 4);
186             }
187 
188             v->codeAppend(
189             // Remove the non-convex vertex, if any.
190             "if (vertexdir != sign(netdir)) {"
191                 "localcoord = nextcoord;"
192             "}"
193 
194             "float2 vertexpos = AFFINE_MATRIX * localcoord + TRANSLATE;");
195             gpArgs->fLocalCoordVar.set(SkSLType::kFloat2, "localcoord");
196             gpArgs->fPositionVar.set(SkSLType::kFloat2, "vertexpos");
197         }
198     };
199     return std::make_unique<Impl>();
200 }
201 
202 }  // anonymous namespace
203 
visitProxies(const GrVisitProxyFunc & func) const204 void PathInnerTriangulateOp::visitProxies(const GrVisitProxyFunc& func) const {
205     if (fPipelineForFills) {
206         fPipelineForFills->visitProxies(func);
207     } else {
208         fProcessors.visitProxies(func);
209     }
210 }
211 
fixedFunctionFlags() const212 GrDrawOp::FixedFunctionFlags PathInnerTriangulateOp::fixedFunctionFlags() const {
213     auto flags = FixedFunctionFlags::kUsesStencil;
214     if (GrAAType::kNone != fAAType) {
215         flags |= FixedFunctionFlags::kUsesHWAA;
216     }
217     return flags;
218 }
219 
finalize(const GrCaps & caps,const GrAppliedClip * clip,GrClampType clampType)220 GrProcessorSet::Analysis PathInnerTriangulateOp::finalize(const GrCaps& caps,
221                                                           const GrAppliedClip* clip,
222                                                           GrClampType clampType) {
223     return fProcessors.finalize(fColor, GrProcessorAnalysisCoverage::kNone, clip, nullptr, caps,
224                                 clampType, &fColor);
225 }
226 
pushFanStencilProgram(const GrTessellationShader::ProgramArgs & args,const GrPipeline * pipelineForStencils,const GrUserStencilSettings * stencil)227 void PathInnerTriangulateOp::pushFanStencilProgram(const GrTessellationShader::ProgramArgs& args,
228                                                    const GrPipeline* pipelineForStencils,
229                                                    const GrUserStencilSettings* stencil) {
230     SkASSERT(pipelineForStencils);
231     auto shader = GrPathTessellationShader::MakeSimpleTriangleShader(args.fArena, fViewMatrix,
232                                                                      SK_PMColor4fTRANSPARENT);
233     fFanPrograms.push_back(GrTessellationShader::MakeProgram(args, shader, pipelineForStencils,
234                                                              stencil)); }
235 
pushFanFillProgram(const GrTessellationShader::ProgramArgs & args,const GrUserStencilSettings * stencil)236 void PathInnerTriangulateOp::pushFanFillProgram(const GrTessellationShader::ProgramArgs& args,
237                                                 const GrUserStencilSettings* stencil) {
238     SkASSERT(fPipelineForFills);
239     auto shader = GrPathTessellationShader::MakeSimpleTriangleShader(args.fArena, fViewMatrix,
240                                                                      fColor);
241     fFanPrograms.push_back(GrTessellationShader::MakeProgram(args, shader, fPipelineForFills,
242                                                              stencil));
243 }
244 
prePreparePrograms(const GrTessellationShader::ProgramArgs & args,GrAppliedClip && appliedClip)245 void PathInnerTriangulateOp::prePreparePrograms(const GrTessellationShader::ProgramArgs& args,
246                                                 GrAppliedClip&& appliedClip) {
247     SkASSERT(!fFanTriangulator);
248     SkASSERT(!fFanPolys);
249     SkASSERT(!fPipelineForFills);
250     SkASSERT(!fTessellator);
251     SkASSERT(!fStencilCurvesProgram);
252     SkASSERT(fFanPrograms.empty());
253     SkASSERT(!fCoverHullsProgram);
254 
255     if (fPath.countVerbs() <= 0) {
256         return;
257     }
258 
259     // If using wireframe, we have to fall back on a standard Redbook "stencil then cover" algorithm
260     // instead of bypassing the stencil buffer to fill the fan directly.
261     bool forceRedbookStencilPass =
262             (fPathFlags & (FillPathFlags::kStencilOnly | FillPathFlags::kWireframe));
263     bool doFill = !(fPathFlags & FillPathFlags::kStencilOnly);
264 
265     bool isLinear;
266     fFanTriangulator = args.fArena->make<GrInnerFanTriangulator>(fPath, args.fArena);
267     fFanPolys = fFanTriangulator->pathToPolys(&fFanBreadcrumbs, &isLinear);
268 
269     // Create a pipeline for stencil passes if needed.
270     const GrPipeline* pipelineForStencils = nullptr;
271     if (forceRedbookStencilPass || !isLinear) {  // Curves always get stencilled.
272         auto pipelineFlags = (fPathFlags & FillPathFlags::kWireframe)
273                 ? GrPipeline::InputFlags::kWireframe
274                 : GrPipeline::InputFlags::kNone;
275         pipelineForStencils = GrPathTessellationShader::MakeStencilOnlyPipeline(
276                 args, fAAType, appliedClip.hardClip(), pipelineFlags);
277     }
278 
279     // Create a pipeline for fill passes if needed.
280     if (doFill) {
281         fPipelineForFills = GrTessellationShader::MakePipeline(args, fAAType,
282                                                                std::move(appliedClip),
283                                                                std::move(fProcessors));
284     }
285 
286     // Pass 1: Tessellate the outer curves into the stencil buffer.
287     if (!isLinear) {
288         fTessellator = PathCurveTessellator::Make(args.fArena,
289                                                   args.fCaps->shaderCaps()->fInfinitySupport);
290         auto* tessShader = GrPathTessellationShader::Make(*args.fCaps->shaderCaps(),
291                                                           args.fArena,
292                                                           fViewMatrix,
293                                                           SK_PMColor4fTRANSPARENT,
294                                                           fTessellator->patchAttribs());
295         const GrUserStencilSettings* stencilPathSettings =
296                 GrPathTessellationShader::StencilPathSettings(GrFillRuleForSkPath(fPath));
297         fStencilCurvesProgram = GrTessellationShader::MakeProgram(args,
298                                                                   tessShader,
299                                                                   pipelineForStencils,
300                                                                   stencilPathSettings);
301     }
302 
303     // Pass 2: Fill the path's inner fan with a stencil test against the curves.
304     if (fFanPolys) {
305         if (forceRedbookStencilPass) {
306             // Use a standard Redbook "stencil then cover" algorithm instead of bypassing the
307             // stencil buffer to fill the fan directly.
308             const GrUserStencilSettings* stencilPathSettings =
309                     GrPathTessellationShader::StencilPathSettings(GrFillRuleForSkPath(fPath));
310             this->pushFanStencilProgram(args, pipelineForStencils, stencilPathSettings);
311             if (doFill) {
312                 this->pushFanFillProgram(args,
313                                          GrPathTessellationShader::TestAndResetStencilSettings());
314             }
315         } else if (isLinear) {
316             // There are no outer curves! Ignore stencil and fill the path directly.
317             SkASSERT(!pipelineForStencils);
318             this->pushFanFillProgram(args, &GrUserStencilSettings::kUnused);
319         } else if (!fPipelineForFills->hasStencilClip()) {
320             // These are a twist on the standard Redbook stencil settings that allow us to fill the
321             // inner polygon directly to the final render target. By the time these programs
322             // execute, the outer curves will already be stencilled in. So if the stencil value is
323             // zero, then it means the sample in question is not affected by any curves and we can
324             // fill it in directly. If the stencil value is nonzero, then we don't fill and instead
325             // continue the standard Redbook counting process.
326             constexpr static GrUserStencilSettings kFillOrIncrDecrStencil(
327                 GrUserStencilSettings::StaticInitSeparate<
328                     0x0000,                       0x0000,
329                     GrUserStencilTest::kEqual,    GrUserStencilTest::kEqual,
330                     0xffff,                       0xffff,
331                     GrUserStencilOp::kKeep,       GrUserStencilOp::kKeep,
332                     GrUserStencilOp::kIncWrap,    GrUserStencilOp::kDecWrap,
333                     0xffff,                       0xffff>());
334 
335             constexpr static GrUserStencilSettings kFillOrInvertStencil(
336                 GrUserStencilSettings::StaticInit<
337                     0x0000,
338                     GrUserStencilTest::kEqual,
339                     0xffff,
340                     GrUserStencilOp::kKeep,
341                     // "Zero" instead of "Invert" because the fan only touches any given pixel once.
342                     GrUserStencilOp::kZero,
343                     0xffff>());
344 
345             auto* stencil = (fPath.getFillType() == SkPathFillType::kWinding)
346                     ? &kFillOrIncrDecrStencil
347                     : &kFillOrInvertStencil;
348             this->pushFanFillProgram(args, stencil);
349         } else {
350             // This is the same idea as above, but we use two passes instead of one because there is
351             // a stencil clip. The stencil test isn't expressive enough to do the above tests and
352             // also check the clip bit in a single pass.
353             constexpr static GrUserStencilSettings kFillIfZeroAndInClip(
354                 GrUserStencilSettings::StaticInit<
355                     0x0000,
356                     GrUserStencilTest::kEqualIfInClip,
357                     0xffff,
358                     GrUserStencilOp::kKeep,
359                     GrUserStencilOp::kKeep,
360                     0xffff>());
361 
362             constexpr static GrUserStencilSettings kIncrDecrStencilIfNonzero(
363                 GrUserStencilSettings::StaticInitSeparate<
364                     0x0000,                         0x0000,
365                     // No need to check the clip because the previous stencil pass will have only
366                     // written to samples already inside the clip.
367                     GrUserStencilTest::kNotEqual,   GrUserStencilTest::kNotEqual,
368                     0xffff,                         0xffff,
369                     GrUserStencilOp::kIncWrap,      GrUserStencilOp::kDecWrap,
370                     GrUserStencilOp::kKeep,         GrUserStencilOp::kKeep,
371                     0xffff,                         0xffff>());
372 
373             constexpr static GrUserStencilSettings kInvertStencilIfNonZero(
374                 GrUserStencilSettings::StaticInit<
375                     0x0000,
376                     // No need to check the clip because the previous stencil pass will have only
377                     // written to samples already inside the clip.
378                     GrUserStencilTest::kNotEqual,
379                     0xffff,
380                     // "Zero" instead of "Invert" because the fan only touches any given pixel once.
381                     GrUserStencilOp::kZero,
382                     GrUserStencilOp::kKeep,
383                     0xffff>());
384 
385             // Pass 2a: Directly fill fan samples whose stencil values (from curves) are zero.
386             this->pushFanFillProgram(args, &kFillIfZeroAndInClip);
387 
388             // Pass 2b: Redbook counting on fan samples whose stencil values (from curves) != 0.
389             auto* stencil = (fPath.getFillType() == SkPathFillType::kWinding)
390                     ? &kIncrDecrStencilIfNonzero
391                     : &kInvertStencilIfNonZero;
392             this->pushFanStencilProgram(args, pipelineForStencils, stencil);
393         }
394     }
395 
396     // Pass 3: Draw convex hulls around each curve.
397     if (doFill && !isLinear) {
398         // By the time this program executes, every pixel will be filled in except the ones touched
399         // by curves. We issue a final cover pass over the curves by drawing their convex hulls.
400         // This will fill in any remaining samples and reset the stencil values back to zero.
401         SkASSERT(fTessellator);
402         auto* hullShader = args.fArena->make<HullShader>(fViewMatrix, fColor,
403                                                          *args.fCaps->shaderCaps());
404         fCoverHullsProgram = GrTessellationShader::MakeProgram(
405                 args, hullShader, fPipelineForFills,
406                 GrPathTessellationShader::TestAndResetStencilSettings());
407     }
408 }
409 
onPrePrepare(GrRecordingContext * context,const GrSurfaceProxyView & writeView,GrAppliedClip * clip,const GrDstProxyView & dstProxyView,GrXferBarrierFlags renderPassXferBarriers,GrLoadOp colorLoadOp)410 void PathInnerTriangulateOp::onPrePrepare(GrRecordingContext* context,
411                                           const GrSurfaceProxyView& writeView,
412                                           GrAppliedClip* clip,
413                                           const GrDstProxyView& dstProxyView,
414                                           GrXferBarrierFlags renderPassXferBarriers,
415                                           GrLoadOp colorLoadOp) {
416     // DMSAA is not supported on DDL.
417     bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1;
418     this->prePreparePrograms({context->priv().recordTimeAllocator(), writeView, usesMSAASurface,
419                              &dstProxyView, renderPassXferBarriers, colorLoadOp,
420                              context->priv().caps()},
421                              (clip) ? std::move(*clip) : GrAppliedClip::Disabled());
422     if (fStencilCurvesProgram) {
423         context->priv().recordProgramInfo(fStencilCurvesProgram);
424     }
425     for (const GrProgramInfo* fanProgram : fFanPrograms) {
426         context->priv().recordProgramInfo(fanProgram);
427     }
428     if (fCoverHullsProgram) {
429         context->priv().recordProgramInfo(fCoverHullsProgram);
430     }
431 }
432 
433 SKGPU_DECLARE_STATIC_UNIQUE_KEY(gHullVertexBufferKey);
434 
onPrepare(GrOpFlushState * flushState)435 void PathInnerTriangulateOp::onPrepare(GrOpFlushState* flushState) {
436     const GrCaps& caps = flushState->caps();
437 
438     if (!fFanTriangulator) {
439         this->prePreparePrograms({flushState->allocator(), flushState->writeView(),
440                                  flushState->usesMSAASurface(), &flushState->dstProxyView(),
441                                  flushState->renderPassBarriers(), flushState->colorLoadOp(),
442                                  &caps}, flushState->detachAppliedClip());
443         if (!fFanTriangulator) {
444             return;
445         }
446     }
447 
448     if (fFanPolys) {
449         GrEagerDynamicVertexAllocator alloc(flushState, &fFanBuffer, &fBaseFanVertex);
450         fFanVertexCount = fFanTriangulator->polysToTriangles(fFanPolys, &alloc, &fFanBreadcrumbs);
451     }
452 
453     if (fTessellator) {
454         auto tessShader = &fStencilCurvesProgram->geomProc().cast<GrPathTessellationShader>();
455         fTessellator->prepareWithTriangles(flushState,
456                                            tessShader->viewMatrix(),
457                                            &fFanBreadcrumbs,
458                                            {SkMatrix::I(), fPath, SK_PMColor4fTRANSPARENT},
459                                            fPath.countVerbs());
460     }
461 
462     if (!caps.shaderCaps()->fVertexIDSupport) {
463         constexpr static float kStripOrderIDs[4] = {0, 1, 3, 2};
464 
465         SKGPU_DEFINE_STATIC_UNIQUE_KEY(gHullVertexBufferKey);
466 
467         fHullVertexBufferIfNoIDSupport = flushState->resourceProvider()->findOrMakeStaticBuffer(
468                 GrGpuBufferType::kVertex, sizeof(kStripOrderIDs), kStripOrderIDs,
469                 gHullVertexBufferKey);
470     }
471 }
472 
onExecute(GrOpFlushState * flushState,const SkRect & chainBounds)473 void PathInnerTriangulateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
474     if (fCoverHullsProgram &&
475         fCoverHullsProgram->geomProc().hasVertexAttributes() &&
476         !fHullVertexBufferIfNoIDSupport) {
477         return;
478     }
479 
480     if (fStencilCurvesProgram) {
481         SkASSERT(fTessellator);
482         flushState->bindPipelineAndScissorClip(*fStencilCurvesProgram, this->bounds());
483         fTessellator->draw(flushState);
484     }
485 
486     // Allocation of the fan vertex buffer may have failed but we already pushed back fan programs.
487     if (fFanBuffer) {
488         for (const GrProgramInfo* fanProgram : fFanPrograms) {
489             flushState->bindPipelineAndScissorClip(*fanProgram, this->bounds());
490             flushState->bindTextures(fanProgram->geomProc(), nullptr, fanProgram->pipeline());
491             flushState->bindBuffers(nullptr, nullptr, fFanBuffer);
492             flushState->draw(fFanVertexCount, fBaseFanVertex);
493         }
494     }
495 
496     if (fCoverHullsProgram) {
497         SkASSERT(fTessellator);
498         flushState->bindPipelineAndScissorClip(*fCoverHullsProgram, this->bounds());
499         flushState->bindTextures(fCoverHullsProgram->geomProc(), nullptr, *fPipelineForFills);
500         fTessellator->drawHullInstances(flushState, fHullVertexBufferIfNoIDSupport);
501     }
502 }
503 
504 }  // namespace skgpu::ganesh
505 
506 #endif // SK_ENABLE_OPTIMIZE_SIZE
507