Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PathStencilCoverOp.h
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
8#ifndef PathStencilCoverOp_DEFINED
9#define PathStencilCoverOp_DEFINED
10
15
16namespace skgpu::ganesh {
17
18// Draws paths using a standard Redbook "stencil then cover" method. Curves get linearized by either
19// GPU tessellation shaders or indirect draws. This Op doesn't apply analytic AA, so it requires
20// MSAA if AA is desired.
21class PathStencilCoverOp final : public GrDrawOp {
22private:
24
26
27 // If the path is inverse filled, drawBounds must be the entire backing store dimensions of the
28 // render target.
30 const SkMatrix& viewMatrix,
31 const SkPath& path,
32 GrPaint&& paint,
33 GrAAType aaType,
34 FillPathFlags pathFlags,
35 const SkRect& drawBounds)
36 : GrDrawOp(ClassID())
37 , fPathDrawList(arena->make<PathDrawList>(viewMatrix, path, SK_PMColor4fTRANSPARENT))
38 , fTotalCombinedPathVerbCnt(path.countVerbs())
39 , fPathCount(1)
40 , fPathFlags(pathFlags)
41 , fAAType(aaType)
42 , fColor(paint.getColor4f())
43 , fProcessors(std::move(paint)) {
44 this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo);
45 SkDEBUGCODE(fOriginalDrawBounds = drawBounds;)
46 }
47
48 // Constructs a PathStencilCoverOp from an existing draw list.
49 // FIXME: The only user of this method is the atlas. We should move the GrProgramInfos into
50 // PathTessellator so the atlas can use that directly instead of going through this class.
51 PathStencilCoverOp(const PathDrawList* pathDrawList,
52 int totalCombinedVerbCnt,
53 int pathCount,
54 GrPaint&& paint,
55 GrAAType aaType,
56 FillPathFlags pathFlags,
57 const SkRect& drawBounds)
58 : GrDrawOp(ClassID())
59 , fPathDrawList(pathDrawList)
60 , fTotalCombinedPathVerbCnt(totalCombinedVerbCnt)
61 , fPathCount(pathCount)
62 , fPathFlags(pathFlags)
63 , fAAType(aaType)
64 , fColor(paint.getColor4f())
65 , fProcessors(std::move(paint)) {
66 this->setBounds(drawBounds, HasAABloat::kNo, IsHairline::kNo);
67 SkDEBUGCODE(fOriginalDrawBounds = drawBounds;)
68 }
69
70 const char* name() const override { return "PathStencilCoverOp"; }
71 void visitProxies(const GrVisitProxyFunc&) const override;
74
75 // All paths in fPathDrawList are required to have the same fill type.
76 SkPathFillType pathFillType() const {
77 return fPathDrawList->fPath.getFillType();
78 }
79
80 // Chooses the rendering method we will use and creates the corresponding tessellator and
81 // stencil/cover programs.
82 void prePreparePrograms(const GrTessellationShader::ProgramArgs&, GrAppliedClip&& clip);
83
85 const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override;
86 void onPrepare(GrOpFlushState*) override;
87 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
88
89 const PathDrawList* fPathDrawList;
90 const int fTotalCombinedPathVerbCnt;
91 const int fPathCount;
92 const FillPathFlags fPathFlags;
93 const GrAAType fAAType;
94 SkPMColor4f fColor;
95 GrProcessorSet fProcessors;
96 SkDEBUGCODE(SkRect fOriginalDrawBounds;)
97
98 // Decided during prePreparePrograms.
99 PathTessellator* fTessellator = nullptr;
100 const GrProgramInfo* fStencilFanProgram = nullptr;
101 const GrProgramInfo* fStencilPathProgram = nullptr;
102 const GrProgramInfo* fCoverBBoxProgram = nullptr;
103
104 // Filled during onPrepare.
105 sk_sp<const GrBuffer> fFanBuffer;
106 int fFanBaseVertex = 0;
107 int fFanVertexCount = 0;
108
109 sk_sp<const GrBuffer> fBBoxBuffer;
110 int fBBoxBaseInstance = 0;
111
112 // Only used if sk_VertexID is not supported.
113 sk_sp<const GrGpuBuffer> fBBoxVertexBufferIfNoIDSupport;
114
115 friend class GrOp; // For ctor.
116};
117
118} // namespace skgpu::ganesh
119
120#endif // PathStencilCoverOp_DEFINED
#define DEFINE_OP_CLASS_ID
Definition GrOp.h:64
GrClampType
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
GrAAType
GrLoadOp
GrXferBarrierFlags
constexpr SkPMColor4f SK_PMColor4fTRANSPARENT
SkPathFillType
Definition SkPathTypes.h:11
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
FixedFunctionFlags
Definition GrDrawOp.h:104
Definition GrOp.h:70
void setBounds(const SkRect &newBounds, HasAABloat aabloat, IsHairline zeroArea)
Definition GrOp.h:279
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
SkPathFillType getFillType() const
Definition SkPath.h:230
void onPrepare(GrOpFlushState *) override
const char * name() const override
GrProcessorSet::Analysis finalize(const GrCaps &, const GrAppliedClip *, GrClampType) override
void onExecute(GrOpFlushState *, const SkRect &chainBounds) override
FixedFunctionFlags fixedFunctionFlags() const override
void onPrePrepare(GrRecordingContext *, const GrSurfaceProxyView &, GrAppliedClip *, const GrDstProxyView &, GrXferBarrierFlags, GrLoadOp colorLoadOp) override
void visitProxies(const GrVisitProxyFunc &) const override
const Paint & paint