21#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
45 this->setInstanceAttributesWithImplicitOffsets(fInstanceAttribs.data(),
46 fInstanceAttribs.size());
47 SkASSERT(fInstanceAttribs.size() <= kMaxInstanceAttribCount);
52 this->setVertexAttributesWithImplicitOffsets(&kVertexIdxAttrib, 1);
57 const char*
name() const final {
return "tessellate_HullShader"; }
58 void addToKey(
const GrShaderCaps&, KeyBuilder*)
const final {}
59 std::unique_ptr<ProgramImpl> makeProgramImpl(
const GrShaderCaps&)
const final;
61 constexpr static int kMaxInstanceAttribCount = 3;
65std::unique_ptr<GrGeometryProcessor::ProgramImpl> HullShader::makeProgramImpl(
72 GrGPArgs* gpArgs)
override {
75 "bool is_conic_curve() { return isinf(p23.w); }"
76 "bool is_non_triangular_conic_curve() {"
80 "return isinf(p23.z) == false;"
85 "bool is_conic_curve() { return curveType != %g; }",
88 "bool is_non_triangular_conic_curve() {"
89 "return curveType == %g;"
93 "float2 p0=p01.xy, p1=p01.zw, p2=p23.xy, p3=p23.zw;"
94 "if (is_conic_curve()) {"
98 "if (is_non_triangular_conic_curve()) {"
100 "float2 p1w = p1 * w;"
102 "float2 c1 = mix(p0, p1w, T);"
103 "float2 c2 = mix(p2, p1w, T);"
104 "float iw = 1 / mix(1, w, T);"
111 "float2 v1 = p1 - p0;"
112 "float2 v2 = p2 - p0;"
113 "float2 v3 = p3 - p0;"
116 "if (sign(cross_length_2d(v2, v1)) == sign(cross_length_2d(v2, v3))) {"
118 "if (sign(cross_length_2d(v1, v2)) != sign(cross_length_2d(v1, v3))) {"
133 "int vertexidx = sk_VertexID;"
134 "vertexidx ^= vertexidx >> 1;");
139 "float vertexdir = 0;"
147 for (
int i = 0;
i < 4; ++
i) {
149 "prev = p%i - p%i;",
i, (
i + 3) % 4);
151 "next = p%i - p%i;", (
i + 1) % 4,
i);
153 "dir = sign(cross_length_2d(prev, next));"
154 "if (vertexidx == %i) {"
159 "netdir += dir;",
i,
i, (
i + 1) % 4);
164 "if (vertexdir != sign(netdir)) {"
165 "localcoord = nextcoord;"
168 "float2 vertexpos = AFFINE_MATRIX * localcoord + TRANSLATE;");
173 return std::make_unique<Impl>();
178void PathInnerTriangulateOp::visitProxies(
const GrVisitProxyFunc& func)
const {
179 if (fPipelineForFills) {
235 bool forceRedbookStencilPass =
241 fFanPolys = fFanTriangulator->
pathToPolys(&fFanBreadcrumbs, &isLinear);
244 const GrPipeline* pipelineForStencils =
nullptr;
245 if (forceRedbookStencilPass || !isLinear) {
250 args, fAAType, appliedClip.hardClip(), pipelineFlags);
256 std::move(appliedClip),
257 std::move(fProcessors));
263 args.fCaps->shaderCaps()->fInfinitySupport);
274 stencilPathSettings);
279 if (forceRedbookStencilPass) {
284 this->pushFanStencilProgram(
args, pipelineForStencils, stencilPathSettings);
286 this->pushFanFillProgram(
args,
289 }
else if (isLinear) {
320 ? &kFillOrIncrDecrStencil
321 : &kFillOrInvertStencil;
322 this->pushFanFillProgram(
args, stencil);
360 this->pushFanFillProgram(
args, &kFillIfZeroAndInClip);
364 ? &kIncrDecrStencilIfNonzero
365 : &kInvertStencilIfNonZero;
366 this->pushFanStencilProgram(
args, pipelineForStencils, stencil);
371 if (doFill && !isLinear) {
376 auto* hullShader =
args.fArena->make<HullShader>(fViewMatrix, fColor,
377 *
args.fCaps->shaderCaps());
379 args, hullShader, fPipelineForFills,
392 this->prePreparePrograms({context->
priv().recordTimeAllocator(), writeView, usesMSAASurface,
393 &dstProxyView, renderPassXferBarriers, colorLoadOp,
396 if (fStencilCurvesProgram) {
402 if (fCoverHullsProgram) {
409void PathInnerTriangulateOp::onPrepare(
GrOpFlushState* flushState) {
412 if (!fFanTriangulator) {
417 if (!fFanTriangulator) {
424 fFanVertexCount = fFanTriangulator->
polysToTriangles(fFanPolys, &alloc, &fFanBreadcrumbs);
430 tessShader->viewMatrix(),
437 constexpr static float kStripOrderIDs[4] = {0, 1, 3, 2};
443 gHullVertexBufferKey);
448 if (fCoverHullsProgram &&
450 !fHullVertexBufferIfNoIDSupport) {
454 if (fStencilCurvesProgram) {
457 fTessellator->
draw(flushState);
464 flushState->
bindTextures(fanProgram->geomProc(),
nullptr, fanProgram->pipeline());
465 flushState->
bindBuffers(
nullptr,
nullptr, fFanBuffer);
466 flushState->
draw(fFanVertexCount, fBaseFanVertex);
470 if (fCoverHullsProgram) {
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
GrFillRule GrFillRuleForSkPath(const SkPath &path)
@ kFloat_GrVertexAttribType
@ kFloat4_GrVertexAttribType
#define SKGPU_DEFINE_STATIC_UNIQUE_KEY(name)
constexpr SkPMColor4f SK_PMColor4fTRANSPARENT
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static GrAppliedClip Disabled()
const GrCaps * caps() const
const GrShaderCaps * shaderCaps() const
void codeAppend(const char *str)
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
void insertFunction(const char *functionDefinition)
bool hasVertexAttributes() const
Poly * pathToPolys(BreadcrumbTriangleList *breadcrumbList, bool *isLinear)
int polysToTriangles(Poly *polys, GrEagerVertexAllocator *vertexAlloc, BreadcrumbTriangleList *breadcrumbList) const
GrLoadOp colorLoadOp() const final
const GrDstProxyView & dstProxyView() const final
GrXferBarrierFlags renderPassBarriers() const final
SkArenaAlloc * allocator() override
void bindPipelineAndScissorClip(const GrProgramInfo &programInfo, const SkRect &drawBounds)
void bindBuffers(sk_sp< const GrBuffer > indexBuffer, sk_sp< const GrBuffer > instanceBuffer, sk_sp< const GrBuffer > vertexBuffer, GrPrimitiveRestart primitiveRestart=GrPrimitiveRestart::kNo)
const GrSurfaceProxyView & writeView() const final
GrResourceProvider * resourceProvider() const final
GrAppliedClip detachAppliedClip() final
const GrCaps & caps() const final
void bindTextures(const GrGeometryProcessor &geomProc, const GrSurfaceProxy &singleGeomProcTexture, const GrPipeline &pipeline)
void draw(int vertexCount, int baseVertex)
bool usesMSAASurface() const final
const SkRect & bounds() const
static const GrUserStencilSettings * StencilPathSettings(GrFillRule fillRule)
static GrPathTessellationShader * MakeSimpleTriangleShader(SkArenaAlloc *, const SkMatrix &viewMatrix, const SkPMColor4f &)
static const GrPipeline * MakeStencilOnlyPipeline(const ProgramArgs &, GrAAType, const GrAppliedHardClip &, GrPipeline::InputFlags=GrPipeline::InputFlags::kNone)
static GrPathTessellationShader * Make(const GrShaderCaps &, SkArenaAlloc *, const SkMatrix &viewMatrix, const SkPMColor4f &, PatchAttribs)
static const GrUserStencilSettings * TestAndResetStencilSettings(bool isInverseFill=false)
bool hasStencilClip() const
void visitProxies(const GrVisitProxyFunc &) const
void visitProxies(const GrVisitProxyFunc &) const
Analysis finalize(const GrProcessorAnalysisColor &, const GrProcessorAnalysisCoverage, const GrAppliedClip *, const GrUserStencilSettings *, const GrCaps &, GrClampType, SkPMColor4f *inputColorOverride)
const GrGeometryProcessor & geomProc() const
void recordProgramInfo(const GrProgramInfo *programInfo)
GrRecordingContextPriv priv()
sk_sp< const GrGpuBuffer > findOrMakeStaticBuffer(GrGpuBufferType intendedType, size_t size, const skgpu::UniqueKey &key, InitializeBufferFn)
GrRenderTargetProxy * asRenderTargetProxy() const
static const GrPipeline * MakePipeline(const ProgramArgs &, GrAAType, GrAppliedClip &&, GrProcessorSet &&)
static GrProgramInfo * MakeProgram(const ProgramArgs &args, const GrTessellationShader *shader, const GrPipeline *pipeline, const GrUserStencilSettings *stencil)
static const SkMatrix & I()
SkPathFillType getFillType() const
static PathCurveTessellator * Make(SkArenaAlloc *arena, bool infinitySupport, PatchAttribs attribs=PatchAttribs::kNone)
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
PatchAttribs patchAttribs() const
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
DEF_SWITCHES_START aot vmservice shared library name
tess::PatchAttribs PatchAttribs
SKGPU_DECLARE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey)
static constexpr float kCubicCurveType
static constexpr float kConicCurveType
static constexpr Init< Ref, Test, TestMask, PassOp, FailOp, WriteMask > StaticInit()
static constexpr InitSeparate< CWRef, CCWRef, CWTest, CCWTest, CWTestMask, CCWTestMask, CWPassOp, CCWPassOp, CWFailOp, CCWFailOp, CWWriteMask, CCWWriteMask > StaticInitSeparate()
static const GrUserStencilSettings & kUnused