xref: /aosp_15_r20/external/skia/src/gpu/ganesh/ops/PathTessellateOp.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 
8 #ifndef PathTessellateOp_DEFINED
9 #define PathTessellateOp_DEFINED
10 
11 #include "include/core/SkMatrix.h"
12 #include "include/core/SkPath.h"
13 #include "include/private/SkColorData.h"
14 #include "include/private/base/SkAssert.h"
15 #include "include/private/gpu/ganesh/GrTypesPriv.h"
16 #include "src/base/SkArenaAlloc.h"
17 #include "src/gpu/ganesh/GrCaps.h"
18 #include "src/gpu/ganesh/GrPaint.h"
19 #include "src/gpu/ganesh/GrProcessorSet.h"
20 #include "src/gpu/ganesh/GrUserStencilSettings.h"
21 #include "src/gpu/ganesh/ops/GrDrawOp.h"
22 #include "src/gpu/ganesh/ops/GrOp.h"
23 #include "src/gpu/ganesh/tessellate/GrTessellationShader.h"
24 #include "src/gpu/ganesh/tessellate/PathTessellator.h"
25 #include "src/gpu/tessellate/Tessellation.h"
26 
27 #include <utility>
28 
29 class GrAppliedClip;
30 class GrDstProxyView;
31 class GrOpFlushState;
32 class GrProgramInfo;
33 class GrRecordingContext;
34 class GrSurfaceProxyView;
35 enum class GrXferBarrierFlags;
36 struct SkRect;
37 
38 namespace skgpu::ganesh {
39 
40 // Tessellates a path directly to the color buffer, using one single render pass. This currently
41 // only works for convex paths.
42 class PathTessellateOp final : public GrDrawOp {
43 private:
44     DEFINE_OP_CLASS_ID
45 
46     using PatchAttribs = PathTessellator::PatchAttribs;
47     using PathDrawList = PathTessellator::PathDrawList;
48 
PathTessellateOp(SkArenaAlloc * arena,GrAAType aaType,const GrUserStencilSettings * stencil,const SkMatrix & viewMatrix,const SkPath & path,GrPaint && paint,const SkRect & drawBounds)49     PathTessellateOp(SkArenaAlloc* arena,
50                      GrAAType aaType,
51                      const GrUserStencilSettings* stencil,
52                      const SkMatrix& viewMatrix,
53                      const SkPath& path,
54                      GrPaint&& paint,
55                      const SkRect& drawBounds)
56             : GrDrawOp(ClassID())
57             , fAAType(aaType)
58             , fStencil(stencil)
59             , fTotalCombinedPathVerbCnt(path.countVerbs())
60             , fPathDrawList(arena->make<PathDrawList>(SkMatrix::I(), path, paint.getColor4f()))
61             , fPathDrawTail(&fPathDrawList->fNext)
62             , fProcessors(std::move(paint))
63             , fShaderMatrix(viewMatrix) {
64         SkASSERT(!path.isInverseFillType());
65         if (!this->headDraw().fColor.fitsInBytes()) {
66             fPatchAttribs |= PatchAttribs::kWideColorIfEnabled;
67         }
68         this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo);
69     }
70 
headDraw()71     PathDrawList& headDraw() { return *fPathDrawList; }
72 
73     void prepareTessellator(const GrTessellationShader::ProgramArgs&, GrAppliedClip&& clip);
74 
75     // GrDrawOp overrides.
name()76     const char* name() const override { return "PathTessellateOp"; }
usesMSAA()77     bool usesMSAA() const override { return fAAType == GrAAType::kMSAA; }
78     void visitProxies(const GrVisitProxyFunc&) const override;
79     GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override;
usesStencil()80     bool usesStencil() const override { return !fStencil->isUnused(); }
81     CombineResult onCombineIfPossible(GrOp*, SkArenaAlloc*, const GrCaps&) override;
82     void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView&, GrAppliedClip*,
83                       const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override;
84     void onPrepare(GrOpFlushState*) override;
85     void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
86 
87     const GrAAType fAAType;
88     const GrUserStencilSettings* const fStencil;
89     int fTotalCombinedPathVerbCnt;
90     PatchAttribs fPatchAttribs = PatchAttribs::kNone;
91     PathDrawList* const fPathDrawList;
92     PathDrawList** fPathDrawTail;
93     GrProcessorSet fProcessors;
94     SkMatrix fShaderMatrix;
95 
96     // Decided during prepareTessellator.
97     PathTessellator* fTessellator = nullptr;
98     const GrProgramInfo* fTessellationProgram = nullptr;
99 
100     friend class GrOp;  // For ctor.
101 };
102 
103 }  // namespace skgpu::ganesh
104 
105 #endif // PathTessellateOp_DEFINED
106