Flutter Engine
The Flutter Engine
PathTessellateOp.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 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
9
15
16namespace skgpu::ganesh {
17
18void PathTessellateOp::visitProxies(const GrVisitProxyFunc& func) const {
19 if (fTessellationProgram) {
20 fTessellationProgram->pipeline().visitProxies(func);
21 } else {
22 fProcessors.visitProxies(func);
23 }
24}
25
26GrProcessorSet::Analysis PathTessellateOp::finalize(const GrCaps& caps,
27 const GrAppliedClip* clip,
28 GrClampType clampType) {
29 auto analysis = fProcessors.finalize(this->headDraw().fColor,
31 clip,
32 nullptr,
33 caps,
34 clampType,
35 &this->headDraw().fColor);
36 if (!analysis.usesLocalCoords()) {
37 // Since we don't need local coords, we can transform on CPU instead of in the shader. This
38 // gives us better batching potential.
39 this->headDraw().fPathMatrix = fShaderMatrix;
40 fShaderMatrix = SkMatrix::I();
41 }
42 return analysis;
43}
44
45GrDrawOp::CombineResult PathTessellateOp::onCombineIfPossible(GrOp* grOp,
47 const GrCaps&) {
48 auto* op = grOp->cast<PathTessellateOp>();
49 bool canMerge = fAAType == op->fAAType &&
50 fStencil == op->fStencil &&
51 fProcessors == op->fProcessors &&
52 fShaderMatrix == op->fShaderMatrix;
53 if (canMerge) {
54 fTotalCombinedPathVerbCnt += op->fTotalCombinedPathVerbCnt;
55 fPatchAttribs |= op->fPatchAttribs;
56
57 if (!(fPatchAttribs & PatchAttribs::kColor) &&
58 this->headDraw().fColor != op->headDraw().fColor) {
59 // Color is no longer uniform. Move it into patch attribs.
60 fPatchAttribs |= PatchAttribs::kColor;
61 }
62
63 *fPathDrawTail = op->fPathDrawList;
64 fPathDrawTail = op->fPathDrawTail;
66 }
67
69}
70
71void PathTessellateOp::prepareTessellator(const GrTessellationShader::ProgramArgs& args,
72 GrAppliedClip&& appliedClip) {
73 SkASSERT(!fTessellator);
74 SkASSERT(!fTessellationProgram);
75 auto* pipeline = GrTessellationShader::MakePipeline(args, fAAType, std::move(appliedClip),
76 std::move(fProcessors));
77 fTessellator = PathWedgeTessellator::Make(args.fArena,
78 args.fCaps->shaderCaps()->fInfinitySupport,
79 fPatchAttribs);
80 auto* tessShader = GrPathTessellationShader::Make(*args.fCaps->shaderCaps(),
81 args.fArena,
82 fShaderMatrix,
83 this->headDraw().fColor,
84 fTessellator->patchAttribs());
85 fTessellationProgram = GrTessellationShader::MakeProgram(args, tessShader, pipeline, fStencil);
86}
87
88void PathTessellateOp::onPrePrepare(GrRecordingContext* context,
89 const GrSurfaceProxyView& writeView, GrAppliedClip* clip,
90 const GrDstProxyView& dstProxyView,
91 GrXferBarrierFlags renderPassXferBarriers,
92 GrLoadOp colorLoadOp) {
93 // DMSAA is not supported on DDL.
94 bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1;
95 this->prepareTessellator({context->priv().recordTimeAllocator(), writeView, usesMSAASurface,
96 &dstProxyView, renderPassXferBarriers, colorLoadOp,
97 context->priv().caps()},
98 (clip) ? std::move(*clip) : GrAppliedClip::Disabled());
99 SkASSERT(fTessellationProgram);
100 context->priv().recordProgramInfo(fTessellationProgram);
101}
102
103void PathTessellateOp::onPrepare(GrOpFlushState* flushState) {
104 if (!fTessellator) {
105 this->prepareTessellator({flushState->allocator(), flushState->writeView(),
106 flushState->usesMSAASurface(), &flushState->dstProxyView(),
107 flushState->renderPassBarriers(), flushState->colorLoadOp(),
108 &flushState->caps()}, flushState->detachAppliedClip());
109 SkASSERT(fTessellator);
110 }
111 fTessellator->prepare(flushState,
112 fShaderMatrix,
113 *fPathDrawList,
114 fTotalCombinedPathVerbCnt);
115}
116
117void PathTessellateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
118 SkASSERT(fTessellator);
119 SkASSERT(fTessellationProgram);
120 flushState->bindPipelineAndScissorClip(*fTessellationProgram, this->bounds());
121 flushState->bindTextures(fTessellationProgram->geomProc(), nullptr,
122 fTessellationProgram->pipeline());
123 fTessellator->draw(flushState);
124}
125
126} // namespace skgpu::ganesh
GrClampType
Definition: GrTypesPriv.h:228
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
Definition: GrTypesPriv.h:943
GrLoadOp
Definition: GrTypesPriv.h:155
GrXferBarrierFlags
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
static GrAppliedClip Disabled()
Definition: GrAppliedClip.h:96
const GrCaps * caps() const
Definition: GrCaps.h:57
GrLoadOp colorLoadOp() const final
const GrDstProxyView & dstProxyView() const final
GrXferBarrierFlags renderPassBarriers() const final
SkArenaAlloc * allocator() override
void bindPipelineAndScissorClip(const GrProgramInfo &programInfo, const SkRect &drawBounds)
const GrSurfaceProxyView & writeView() const final
GrAppliedClip detachAppliedClip() final
const GrCaps & caps() const final
void bindTextures(const GrGeometryProcessor &geomProc, const GrSurfaceProxy &singleGeomProcTexture, const GrPipeline &pipeline)
bool usesMSAASurface() const final
Definition: GrOp.h:70
CombineResult
Definition: GrOp.h:99
const T & cast() const
Definition: GrOp.h:148
const SkRect & bounds() const
Definition: GrOp.h:122
static GrPathTessellationShader * Make(const GrShaderCaps &, SkArenaAlloc *, const SkMatrix &viewMatrix, const SkPMColor4f &, PatchAttribs)
void visitProxies(const GrVisitProxyFunc &) const
Definition: GrPipeline.cpp:105
void visitProxies(const GrVisitProxyFunc &) const
Analysis finalize(const GrProcessorAnalysisColor &, const GrProcessorAnalysisCoverage, const GrAppliedClip *, const GrUserStencilSettings *, const GrCaps &, GrClampType, SkPMColor4f *inputColorOverride)
const GrPipeline & pipeline() const
Definition: GrProgramInfo.h:39
const GrGeometryProcessor & geomProc() const
Definition: GrProgramInfo.h:40
void recordProgramInfo(const GrProgramInfo *programInfo)
GrRecordingContextPriv priv()
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()
Definition: SkMatrix.cpp:1544
virtual void prepare(GrMeshDrawTarget *target, const SkMatrix &shaderMatrix, const PathDrawList &pathDrawList, int totalCombinedPathVerbCnt)=0
virtual void draw(GrOpFlushState *flushState) const =0
PatchAttribs patchAttribs() const
static PathWedgeTessellator * Make(SkArenaAlloc *arena, bool infinitySupport, PatchAttribs attribs=PatchAttribs::kNone)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args