Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
StrokeTessellateOp.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 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 StrokeTessellateOp_DEFINED
9#define StrokeTessellateOp_DEFINED
10
15
18
19namespace skgpu::ganesh {
20
21// Renders strokes by linearizing them into sorted "parametric" and "radial" edges. See
22// GrStrokeTessellationShader.
23class StrokeTessellateOp final : public GrDrawOp {
24public:
26
27private:
30
32
33 SkStrokeRec& headStroke() { return fPathStrokeList.fStroke; }
34 SkPMColor4f& headColor() { return fPathStrokeList.fColor; }
35
36 // Returns whether it is a good tradeoff to use the dynamic states flagged in the given
37 // bitfield. Dynamic states improve batching, but if they aren't already enabled, they come at
38 // the cost of having to write out more data with each patch or instance.
39 bool shouldUseDynamicStates(PatchAttribs neededDynamicStates) const {
40 // Use the dynamic states if either (1) they are all already enabled anyway, or (2) we don't
41 // have many verbs.
42 constexpr static int kMaxVerbsToEnableDynamicState = 50;
43 bool anyStateDisabled = (bool)(~fPatchAttribs & neededDynamicStates);
44 bool allStatesEnabled = !anyStateDisabled;
45 return allStatesEnabled || (fTotalCombinedVerbCnt <= kMaxVerbsToEnableDynamicState);
46 }
47
48 const char* name() const override { return "StrokeTessellateOp"; }
49 void visitProxies(const GrVisitProxyFunc&) const override;
50 bool usesMSAA() const override { return fAAType == GrAAType::kMSAA; }
52 bool usesStencil() const override {
53 // This must be called after finalize(). fNeedsStencil can change in finalize().
54 SkASSERT(fProcessors.isFinalized());
55 return fNeedsStencil;
56 }
58
59 // Creates the tessellator and the stencil/fill program(s) we will use with it.
60 void prePrepareTessellator(GrTessellationShader::ProgramArgs&&, GrAppliedClip&&);
61
63 const GrDstProxyView&, GrXferBarrierFlags, GrLoadOp colorLoadOp) override;
64
65 void onPrepare(GrOpFlushState*) override;
66
67 void onExecute(GrOpFlushState*, const SkRect& chainBounds) override;
68
69 const GrAAType fAAType;
70 const SkMatrix fViewMatrix;
71 PatchAttribs fPatchAttribs = PatchAttribs::kNone;
72 PathStrokeList fPathStrokeList;
73 PathStrokeList** fPathStrokeTail = &fPathStrokeList.fNext;
74 int fTotalCombinedVerbCnt = 0;
75 GrProcessorSet fProcessors;
76 bool fNeedsStencil;
77
78 StrokeTessellator* fTessellator = nullptr;
79 GrStrokeTessellationShader* fTessellationShader;
80 const GrProgramInfo* fStencilProgram = nullptr; // Only used if the stroke has transparency.
81 const GrProgramInfo* fFillProgram = nullptr;
82};
83
84} // namespace skgpu::ganesh
85
86#endif // StrokeTessellateOp_DEFINED
#define DEFINE_OP_CLASS_ID
Definition GrOp.h:64
GrClampType
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
GrAAType
GrLoadOp
GrXferBarrierFlags
#define SkASSERT(cond)
Definition SkAssert.h:116
Definition GrOp.h:70
CombineResult
Definition GrOp.h:99
bool isFinalized() const
void onPrePrepare(GrRecordingContext *, const GrSurfaceProxyView &, GrAppliedClip *, const GrDstProxyView &, GrXferBarrierFlags, GrLoadOp colorLoadOp) override
void onExecute(GrOpFlushState *, const SkRect &chainBounds) override
CombineResult onCombineIfPossible(GrOp *, SkArenaAlloc *, const GrCaps &) override
const char * name() const override
void onPrepare(GrOpFlushState *) override
void visitProxies(const GrVisitProxyFunc &) const override
GrProcessorSet::Analysis finalize(const GrCaps &, const GrAppliedClip *, GrClampType) override