Flutter Engine
The Flutter Engine
GrPipeline.h
Go to the documentation of this file.
1/*
2 * Copyright 2015 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 GrPipeline_DEFINED
9#define GrPipeline_DEFINED
10
23
24class GrAppliedClip;
28class GrOp;
29class GrTextureEffect;
30
31/**
32 * This immutable object contains information needed to build a shader program and set API
33 * state for a draw. It is used along with a GrGeometryProcessor and a source of geometric
34 * data to draw.
35 */
37public:
38 ///////////////////////////////////////////////////////////////////////////
39 /// @name Creation
40
41 // Pipeline options that the caller may enable.
42 // NOTE: This enum is extended later by GrPipeline::Flags.
43 enum class InputFlags : uint8_t {
44 kNone = 0,
45 /**
46 * Cause every pixel to be rasterized that is touched by the triangle anywhere (not just at
47 * pixel center). Additionally, if using MSAA, the sample mask will always have 100%
48 * coverage.
49 * NOTE: The primitive type must be a triangle type.
50 */
51 kConservativeRaster = (1 << 1),
52 /**
53 * Draws triangles as outlines.
54 */
55 kWireframe = (1 << 2),
56 /**
57 * Modifies the vertex shader so that vertices will be positioned at pixel centers.
58 */
59 kSnapVerticesToPixelCenters = (1 << 3), // This value must be last. (See kLastInputFlag.)
60 };
61
62 struct InitArgs {
64 const GrCaps* fCaps = nullptr;
67 };
68
69 /**
70 * Creates a simple pipeline with default settings and no processors. The provided blend mode
71 * must be "Porter Duff" (<= kLastCoeffMode). If using GrScissorTest::kEnabled, the caller must
72 * specify a scissor rectangle through the DynamicState struct.
73 **/
78 : GrPipeline(scissor,
79 GrPorterDuffXPFactory::MakeNoCoverageXP(blend),
81 flags) {}
82
87
89 GrPipeline(const InitArgs&, GrProcessorSet&&, GrAppliedClip&&);
90
91 GrPipeline(const GrPipeline&) = delete;
92 GrPipeline& operator=(const GrPipeline&) = delete;
93
94 /// @}
95
96 ///////////////////////////////////////////////////////////////////////////
97 /// @name GrFragmentProcessors
98
99 int numFragmentProcessors() const { return fFragmentProcessors.count(); }
100 int numColorFragmentProcessors() const { return fNumColorProcessors; }
101 bool isColorFragmentProcessor(int idx) const { return idx < fNumColorProcessors; }
102 bool isCoverageFragmentProcessor(int idx) const { return idx >= fNumColorProcessors; }
103
104 bool usesLocalCoords() const {
105 // The sample coords for the top level FPs are implicitly the GP's local coords.
106 for (const auto& fp : fFragmentProcessors) {
107 if (fp->usesSampleCoords()) {
108 return true;
109 }
110 }
111 return false;
112 }
113
114 void visitTextureEffects(const std::function<void(const GrTextureEffect&)>&) const;
115
117 if (fXferProcessor) {
118 return *fXferProcessor;
119 } else {
120 // A null xp member means the common src-over case. GrXferProcessor's ref'ing
121 // mechanism is not thread safe so we do not hold a ref on this global.
123 }
124 }
125
126 // Helper functions to quickly know if this GrPipeline will access the dst as a texture or an
127 // input attachment.
128 bool usesDstTexture() const { return this->dstProxyView() && !this->usesDstInputAttachment(); }
131 }
132
133 /**
134 * This returns the GrSurfaceProxyView for the texture used to access the dst color. If the
135 * GrXferProcessor does not use the dst color then the proxy on the GrSurfaceProxyView will be
136 * nullptr.
137 */
138 const GrSurfaceProxyView& dstProxyView() const { return fDstProxy.proxyView(); }
139
140 SkIPoint dstTextureOffset() const { return fDstProxy.offset(); }
141
142 GrDstSampleFlags dstSampleFlags() const { return fDstProxy.dstSampleFlags(); }
143
144 /** If this GrXferProcessor uses a texture to access the dst color, returns that texture. */
146 if (!this->usesDstTexture()) {
147 return nullptr;
148 }
149
150 if (GrTextureProxy* dstProxy = this->dstProxyView().asTextureProxy()) {
151 return dstProxy->peekTexture();
152 }
153
154 return nullptr;
155 }
156
158 return *fFragmentProcessors[idx];
159 }
160
161 /// @}
162
163 bool isScissorTestEnabled() const {
164 return SkToBool(fFlags & Flags::kScissorTestEnabled);
165 }
166
167 const GrWindowRectsState& getWindowRectsState() const { return fWindowRectsState; }
168
170 bool isWireframe() const { return fFlags & InputFlags::kWireframe; }
173 }
174 bool hasStencilClip() const {
175 return SkToBool(fFlags & Flags::kHasStencilClip);
176 }
177#ifdef SK_DEBUG
178 bool allProxiesInstantiated() const {
179 for (int i = 0; i < fFragmentProcessors.count(); ++i) {
180 if (!fFragmentProcessors[i]->isInstantiated()) {
181 return false;
182 }
183 }
184 if (this->dstProxyView().proxy()) {
185 return this->dstProxyView().proxy()->isInstantiated();
186 }
187
188 return true;
189 }
190#endif
191
193
194 // Used by Vulkan and Metal to cache their respective pipeline objects
195 void genKey(skgpu::KeyBuilder*, const GrCaps&) const;
196
197 const skgpu::Swizzle& writeSwizzle() const { return fWriteSwizzle; }
198
199 void visitProxies(const GrVisitProxyFunc&) const;
200
202 GrGLSLBuiltinUniformHandles* fBuiltinUniformHandles) const;
203
204private:
205 inline static constexpr uint8_t kLastInputFlag =
207
208 /** This is a continuation of the public "InputFlags" enum. */
209 enum class Flags : uint8_t {
210 kHasStencilClip = (kLastInputFlag << 1),
211 kScissorTestEnabled = (kLastInputFlag << 2),
212 };
213
214 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags);
215
216 friend bool operator&(Flags, InputFlags);
217
218 // A pipeline can contain up to three processors: color, paint coverage, and clip coverage.
219 using FragmentProcessorArray =
221
222 GrDstProxyView fDstProxy;
223 GrWindowRectsState fWindowRectsState;
224 Flags fFlags;
225 sk_sp<const GrXferProcessor> fXferProcessor;
226 FragmentProcessorArray fFragmentProcessors;
227
228 // This value is also the index in fFragmentProcessors where coverage processors begin.
229 int fNumColorProcessors = 0;
230
231 skgpu::Swizzle fWriteSwizzle;
232};
233
235GR_MAKE_BITFIELD_CLASS_OPS(GrPipeline::Flags)
236
237inline bool operator&(GrPipeline::Flags flags, GrPipeline::InputFlags inputFlag) {
238 return (flags & (GrPipeline::Flags)inputFlag);
239}
240
241#endif
std::function< void(GrSurfaceProxy *, skgpu::Mipmapped)> GrVisitProxyFunc
Definition: GrTypesPriv.h:943
GrDstSampleFlags
Definition: GrTypesPriv.h:936
GrScissorTest
Definition: GrTypesPriv.h:115
#define GR_MAKE_BITFIELD_CLASS_OPS(X)
Definition: GrTypes.h:42
GrXferBarrierType
SkBlendMode
Definition: SkBlendMode.h:38
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
Definition: GrCaps.h:57
GrDstSampleFlags dstSampleFlags() const
const SkIPoint & offset() const
const GrSurfaceProxyView & proxyView() const
Definition: GrOp.h:70
const skgpu::Swizzle & writeSwizzle() const
Definition: GrPipeline.h:197
friend bool operator&(Flags, InputFlags)
Definition: GrPipeline.h:237
GrPipeline(const GrPipeline &)=delete
bool snapVerticesToPixelCenters() const
Definition: GrPipeline.h:171
bool hasStencilClip() const
Definition: GrPipeline.h:174
bool isCoverageFragmentProcessor(int idx) const
Definition: GrPipeline.h:102
SkIPoint dstTextureOffset() const
Definition: GrPipeline.h:140
void visitProxies(const GrVisitProxyFunc &) const
Definition: GrPipeline.cpp:105
int numFragmentProcessors() const
Definition: GrPipeline.h:99
bool isColorFragmentProcessor(int idx) const
Definition: GrPipeline.h:101
int numColorFragmentProcessors() const
Definition: GrPipeline.h:100
GrDstSampleFlags dstSampleFlags() const
Definition: GrPipeline.h:142
bool isScissorTestEnabled() const
Definition: GrPipeline.h:163
void setDstTextureUniforms(const GrGLSLProgramDataManager &pdm, GrGLSLBuiltinUniformHandles *fBuiltinUniformHandles) const
Definition: GrPipeline.cpp:115
bool usesDstInputAttachment() const
Definition: GrPipeline.h:129
const GrFragmentProcessor & getFragmentProcessor(int idx) const
Definition: GrPipeline.h:157
GrPipeline(GrScissorTest scissor, SkBlendMode blend, const skgpu::Swizzle &writeSwizzle, InputFlags flags=InputFlags::kNone)
Definition: GrPipeline.h:74
void genKey(skgpu::KeyBuilder *, const GrCaps &) const
Definition: GrPipeline.cpp:79
bool usesLocalCoords() const
Definition: GrPipeline.h:104
void visitTextureEffects(const std::function< void(const GrTextureEffect &)> &) const
Definition: GrPipeline.cpp:98
bool isWireframe() const
Definition: GrPipeline.h:170
GrPipeline & operator=(const GrPipeline &)=delete
const GrSurfaceProxyView & dstProxyView() const
Definition: GrPipeline.h:138
bool usesConservativeRaster() const
Definition: GrPipeline.h:169
bool usesDstTexture() const
Definition: GrPipeline.h:128
GrTexture * peekDstTexture() const
Definition: GrPipeline.h:145
const GrWindowRectsState & getWindowRectsState() const
Definition: GrPipeline.h:167
GrXferBarrierType xferBarrierType(const GrCaps &) const
Definition: GrPipeline.cpp:59
const GrXferProcessor & getXferProcessor() const
Definition: GrPipeline.h:116
static const GrXferProcessor & SimpleSrcOverXP()
GrSurfaceProxy * proxy() const
bool isInstantiated() const
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Dart_NativeFunction function
Definition: fuchsia.cc:51
static SkColor blend(SkColor dst, SkColor src, void(*mode)(float, float, float, float *, float *, float *))
Definition: hsl.cpp:142
const uint32_t fp
skgpu::Swizzle fWriteSwizzle
Definition: GrPipeline.h:66
InputFlags fInputFlags
Definition: GrPipeline.h:63
const GrCaps * fCaps
Definition: GrPipeline.h:64
GrDstProxyView fDstProxyView
Definition: GrPipeline.h:65