2 * Copyright 2021 Google LLC.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef PathTessellateOp_DEFINED
9 #define PathTessellateOp_DEFINED
11 #include "src/gpu/ganesh/ops/GrDrawOp.h"
12 #include "src/gpu/ganesh/tessellate/GrTessellationShader.h"
13 #include "src/gpu/ganesh/tessellate/PathTessellator.h"
14 #include "src/gpu/tessellate/Tessellation.h"
18 // Tessellates a path directly to the color buffer, using one single render pass. This currently
19 // only works for convex paths.
20 class PathTessellateOp final : public GrDrawOp {
24 using PatchAttribs = PathTessellator::PatchAttribs;
25 using PathDrawList = PathTessellator::PathDrawList;
27 PathTessellateOp(SkArenaAlloc* arena,
29 const GrUserStencilSettings* stencil,
30 const SkMatrix& viewMatrix,
33 const SkRect& drawBounds)
37 , fTotalCombinedPathVerbCnt(path.countVerbs())
38 , fPathDrawList(arena->make<PathDrawList>(SkMatrix::I(), path, paint.getColor4f()))
39 , fPathDrawTail(&fPathDrawList->fNext)
40 , fProcessors(std::move(paint))
41 , fShaderMatrix(viewMatrix) {
42 SkASSERT(!path.isInverseFillType());
43 if (!this->headDraw().fColor.fitsInBytes()) {
44 fPatchAttribs |= PatchAttribs::kWideColorIfEnabled;
46 this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo);
49 PathDrawList& headDraw() { return *fPathDrawList; }
51 void prepareTessellator(const GrTessellationShader::ProgramArgs&, GrAppliedClip&& clip);
53 // GrDrawOp overrides.
54 const char* name() const override { return "PathTessellateOp"; }
55 bool usesMSAA() const override { return fAAType == GrAAType::kMSAA; }
56 void visitProxies(const GrVisitProxyFunc&) const override;
57 GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override;
58 bool usesStencil() const override { return !fStencil->isUnused(); }
59 CombineResult onCombineIfPossible(GrOp*, SkArenaAlloc*, const GrCaps&) override;
60 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*,
61 const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override;
62 void onPrepare(GrOpFlushState*) override;
63 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
65 const GrAAType fAAType;
66 const GrUserStencilSettings* const fStencil;
67 int fTotalCombinedPathVerbCnt;
68 PatchAttribs fPatchAttribs = PatchAttribs::kNone;
69 PathDrawList* const fPathDrawList;
70 PathDrawList** fPathDrawTail;
71 GrProcessorSet fProcessors;
72 SkMatrix fShaderMatrix;
74 // Decided during prepareTessellator.
75 PathTessellator* fTessellator = nullptr;
76 const GrProgramInfo* fTessellationProgram = nullptr;
78 friend class GrOp; // For ctor.
81 } // namespace skgpu::v1
83 #endif // PathTessellateOp_DEFINED