Flutter Engine
The Flutter Engine
GrSimpleMeshDrawOpHelper.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
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 GrSimpleMeshDrawOpHelper_DEFINED
9#define GrSimpleMeshDrawOpHelper_DEFINED
10
18#include <new>
19
20struct SkRect;
21
22/**
23 * This class can be used to help implement simple mesh draw ops. It reduces the amount of
24 * boilerplate code to type and also provides a mechanism for optionally allocating space for a
25 * GrProcessorSet based on a GrPaint. It is intended to be used by ops that construct a single
26 * GrPipeline for a uniform primitive color and a GrPaint.
27 */
29public:
30 /**
31 * This can be used by a Op class to perform allocation and initialization such that a
32 * GrProcessorSet (if required) is allocated as part of the the same allocation that as
33 * the Op instance. It requires that Op implements a constructor of the form:
34 * Op(ProcessorSet*, GrColor, OpArgs...).
35 */
36 template <typename Op, typename... OpArgs>
38
39 // Here we allow callers to specify a subset of the GrPipeline::InputFlags upon creation.
40 enum class InputFlags : uint8_t {
41 kNone = 0,
42 kSnapVerticesToPixelCenters = (uint8_t)GrPipeline::InputFlags::kSnapVerticesToPixelCenters,
43 kConservativeRaster = (uint8_t)GrPipeline::InputFlags::kConservativeRaster,
44 };
46
49
53
55
56 // ignoreAAType should be set to true if the op already knows the AA settings are acceptible
57 bool isCompatible(const GrSimpleMeshDrawOpHelper& that, const GrCaps&, const SkRect& thisBounds,
58 const SkRect& thatBounds, bool ignoreAAType = false) const;
59
60 /**
61 * Finalizes the processor set and determines whether the destination must be provided
62 * to the fragment shader as a texture for blending.
63 *
64 * @param geometryCoverage Describes the coverage output of the op's geometry processor
65 * @param geometryColor An in/out param. As input this informs processor analysis about the
66 * color the op expects to output from its geometry processor. As output
67 * this may be set to a known color in which case the op must output this
68 * color from its geometry processor instead.
69 */
71 GrClampType clampType,
72 GrProcessorAnalysisCoverage geometryCoverage,
73 GrProcessorAnalysisColor* geometryColor) {
74 return this->finalizeProcessors(caps, clip, &GrUserStencilSettings::kUnused, clampType,
75 geometryCoverage, geometryColor);
76 }
77
78 /**
79 * Version of above that can be used by ops that have a constant color geometry processor
80 * output. The op passes this color as 'geometryColor' and after return if 'geometryColor' has
81 * changed the op must override its geometry processor color output with the new color.
82 */
84 GrProcessorAnalysisCoverage geometryCoverage,
85 SkPMColor4f* geometryColor, bool* wideColor);
86
87 bool isTrivial() const {
88 return fProcessors == nullptr;
89 }
90
91 bool usesLocalCoords() const {
92 SkASSERT(fDidAnalysis);
93 return fUsesLocalCoords;
94 }
95
97
98 void visitProxies(const GrVisitProxyFunc& func) const {
99 if (fProcessors) {
101 }
102 }
103
104#if defined(GR_TEST_UTILS)
105 SkString dumpInfo() const;
106#endif
107 GrAAType aaType() const { return static_cast<GrAAType>(fAAType); }
108
110 fAAType = static_cast<unsigned>(aaType);
111 }
112
113 static const GrPipeline* CreatePipeline(const GrCaps*,
115 skgpu::Swizzle writeViewSwizzle,
117 const GrDstProxyView&,
120
124
125 const GrPipeline* createPipeline(GrOpFlushState* flushState);
126
127 const GrPipeline* createPipeline(const GrCaps*,
129 skgpu::Swizzle writeViewSwizzle,
131 const GrDstProxyView&);
132
135 const GrPipeline*,
136 const GrSurfaceProxyView& writeView,
137 bool usesMSAASurface,
140 GrXferBarrierFlags renderPassXferBarriers,
141 GrLoadOp colorLoadOp,
144
145 // Create a programInfo with the following properties:
146 // its primitive processor uses no textures
147 // it has no dynamic state besides the scissor clip
150 const GrSurfaceProxyView& writeView,
151 bool usesMSAASurface,
153 const GrDstProxyView&,
157 GrXferBarrierFlags renderPassXferBarriers,
158 GrLoadOp colorLoadOp,
163
166 const GrSurfaceProxyView& writeView,
167 bool usesMSAASurface,
169 const GrDstProxyView&,
172 GrXferBarrierFlags renderPassXferBarriers,
173 GrLoadOp colorLoadOp);
174
177 }
178
180
181protected:
184 GrProcessorAnalysisCoverage geometryCoverage,
185 GrProcessorAnalysisColor* geometryColor);
186
189 unsigned fAAType : 2;
190 unsigned fUsesLocalCoords : 1;
192 SkDEBUGCODE(unsigned fMadePipeline : 1;)
193 SkDEBUGCODE(unsigned fDidAnalysis : 1;)
194};
195
196template<typename Op, typename... Args>
198 GrRecordingContext* context, const SkPMColor4f& color,
199 GrPaint&& paint, Args&&... args) {
200 char* bytes = (char*)::operator new(sizeof(Op) + sizeof(GrProcessorSet));
201 char* setMem = bytes + sizeof(Op);
202 GrProcessorSet* processorSet = new (setMem) GrProcessorSet{std::move(paint)};
203 return Owner{new (bytes) Op(processorSet, color, std::forward<Args>(args)...)};
204}
205
206template <typename Op, typename... OpArgs>
208 GrPaint&& paint,
209 OpArgs&& ... opArgs) {
210 auto color = paint.getColor4f();
211 if (paint.isTrivial()) {
212 return GrOp::Make<Op>(context, nullptr, color, std::forward<OpArgs>(opArgs)...);
213 } else {
214 return GrOp::MakeWithProcessorSet<Op>(
215 context, color, std::move(paint), std::forward<OpArgs>(opArgs)...);
216 }
217}
218
220
221#endif
GrProcessorAnalysisCoverage
GrClampType
Definition: GrTypesPriv.h:228
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
Definition: GrTypesPriv.h:943
GrPrimitiveType
Definition: GrTypesPriv.h:43
GrAAType
Definition: GrTypesPriv.h:200
GrLoadOp
Definition: GrTypesPriv.h:155
#define GR_MAKE_BITFIELD_CLASS_OPS(X)
Definition: GrTypes.h:42
GrXferBarrierFlags
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
Definition: GrCaps.h:57
FixedFunctionFlags
Definition: GrDrawOp.h:104
std::unique_ptr< GrOp > Owner
Definition: GrOp.h:72
static Owner MakeWithProcessorSet(GrRecordingContext *context, const SkPMColor4f &color, GrPaint &&paint, Args &&... args)
void visitProxies(const GrVisitProxyFunc &) const
static GrProcessorSet MakeEmptySet()
GrPipeline::InputFlags fPipelineFlags
void visitProxies(const GrVisitProxyFunc &func) const
GrDrawOp::FixedFunctionFlags fixedFunctionFlags() const
GrSimpleMeshDrawOpHelper(const GrSimpleMeshDrawOpHelper &)=delete
GrSimpleMeshDrawOpHelper & operator=(const GrSimpleMeshDrawOpHelper &)=delete
static GrOp::Owner FactoryHelper(GrRecordingContext *, GrPaint &&, OpArgs &&...)
GrProgramInfo * createProgramInfo(const GrCaps *, SkArenaAlloc *, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrAppliedClip &&, const GrDstProxyView &, GrGeometryProcessor *, GrPrimitiveType, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp)
GrPipeline::InputFlags pipelineFlags() const
static const GrPipeline * CreatePipeline(const GrCaps *, SkArenaAlloc *, skgpu::Swizzle writeViewSwizzle, GrAppliedClip &&, const GrDstProxyView &, GrProcessorSet &&, GrPipeline::InputFlags pipelineFlags)
GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(InputFlags)
GrProcessorSet::Analysis finalizeProcessors(const GrCaps &caps, const GrAppliedClip *clip, GrClampType clampType, GrProcessorAnalysisCoverage geometryCoverage, GrProcessorAnalysisColor *geometryColor)
static GrProgramInfo * CreateProgramInfo(const GrCaps *, SkArenaAlloc *, const GrPipeline *, const GrSurfaceProxyView &writeView, bool usesMSAASurface, GrGeometryProcessor *, GrPrimitiveType, GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp, const GrUserStencilSettings *=&GrUserStencilSettings::kUnused)
const GrPipeline * createPipeline(GrOpFlushState *flushState)
bool isCompatible(const GrSimpleMeshDrawOpHelper &that, const GrCaps &, const SkRect &thisBounds, const SkRect &thatBounds, bool ignoreAAType=false) const
const Paint & paint
Definition: color_source.cc:38
DlColor color
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static const GrUserStencilSettings & kUnused