Flutter Engine
The Flutter Engine
GrGLSLFragmentShaderBuilder.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 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 GrGLSLFragmentShaderBuilder_DEFINED
9#define GrGLSLFragmentShaderBuilder_DEFINED
10
11#include "include/gpu/GrTypes.h"
14
15#include <cstdint>
16
18
19namespace skgpu { enum class BlendEquation : uint8_t; }
20
21/*
22 * This class is used by fragment processors to build their fragment code.
23 */
25public:
26 /** Appease the compiler; the derived class initializes GrGLSLShaderBuilder. */
28 // Suppress unused warning error
29 (void) fPadding;
30 }
31
32 enum class ScopeFlags {
33 // Every fragment will always execute this code, and will do it exactly once.
34 kTopLevel = 0,
35 // Either all fragments in a given primitive, or none, will execute this code.
36 kInsidePerPrimitiveBranch = (1 << 0),
37 // Any given fragment may or may not execute this code.
38 kInsidePerPixelBranch = (1 << 1),
39 // This code will be executed more than once.
40 kInsideLoop = (1 << 2)
41 };
42
43 virtual void forceHighPrecision() = 0;
44
45 /** Returns the variable name that holds the color of the destination pixel. This may be nullptr
46 * if no effect advertised that it will read the destination. */
47 virtual const char* dstColor() = 0;
48
49private:
50 // WARNING: LIke GrRenderTargetProxy, changes to this can cause issues in ASAN. This is caused
51 // by GrGLSLProgramBuilder's SkTBlockLists requiring 16 byte alignment, but since
52 // GrGLSLFragmentShaderBuilder has a virtual diamond hierarchy, ASAN requires all this pointers
53 // to start aligned, even though clang is already correctly offsetting the individual fields
54 // that require the larger alignment. In the current world, this extra padding is sufficient to
55 // correctly initialize GrGLSLXPFragmentBuilder second.
56 char fPadding[4] = {};
57};
58
60
61/*
62 * This class is used by Xfer processors to build their fragment code.
63 */
65public:
66 /** Appease the compiler; the derived class initializes GrGLSLShaderBuilder. */
68
69 virtual bool hasSecondaryOutput() const = 0;
70
71 /** Returns the variable name that holds the color of the destination pixel. This may be nullptr
72 * if no effect advertised that it will read the destination. */
73 virtual const char* dstColor() = 0;
74
75 /** Adds any necessary layout qualifiers in order to legalize the supplied blend equation with
76 this shader. It is only legal to call this method with an advanced blend equation, and only
77 if these equations are supported. */
79};
80
81/*
82 * This class implements the various fragment builder interfaces.
83 */
85public:
87
88 // Shared FP/XP interface.
89 const char* dstColor() override;
90
91 // GrGLSLFPFragmentBuilder interface.
92 void forceHighPrecision() override { fForceHighPrecision = true; }
93
94 // GrGLSLXPFragmentBuilder interface.
95 bool hasSecondaryOutput() const override { return fHasSecondaryOutput; }
97
98private:
99 // Private public interface, used by GrGLProgramBuilder to build a fragment shader
100 void enableSecondaryOutput();
101 const char* getPrimaryColorOutputName() const;
102 const char* getSecondaryColorOutputName() const;
103 bool primaryColorOutputIsInOut() const;
104
105#ifdef SK_DEBUG
106 // As GLSLProcessors emit code, there are some conditions we need to verify. We use the below
107 // state to track this. The reset call is called per processor emitted.
108 bool fHasReadDstColorThisStage_DebugOnly = false;
109
110 void debugOnly_resetPerStageVerification() {
111 fHasReadDstColorThisStage_DebugOnly = false;
112 }
113#endif
114
115 static const char* DeclaredColorOutputName() { return "sk_FragColor"; }
116 static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryColorOut"; }
117
118 GrSurfaceOrigin getSurfaceOrigin() const;
119
120 void onFinalize() override;
121
122 inline static constexpr const char kDstColorName[] = "_dstColor";
123
124 bool fPrimaryColorIsInOut = false;
125 bool fSetupFragPosition = false;
126 bool fHasSecondaryOutput = false;
127 bool fHasModifiedSampleMask = false;
128 bool fForceHighPrecision = false;
129
131 friend class GrGLProgramBuilder;
133};
134
135#endif
#define GR_MAKE_BITFIELD_CLASS_OPS(X)
Definition: GrTypes.h:42
GrSurfaceOrigin
Definition: GrTypes.h:147
virtual const char * dstColor()=0
virtual void forceHighPrecision()=0
void enableAdvancedBlendEquationIfNeeded(skgpu::BlendEquation) override
GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder *program)
virtual bool hasSecondaryOutput() const =0
virtual const char * dstColor()=0
virtual void enableAdvancedBlendEquationIfNeeded(skgpu::BlendEquation)=0
Definition: GpuTools.h:21
BlendEquation
Definition: Blend.h:26