Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: src/gpu/gl/builders/GrGLFragmentShaderBuilder.h

Issue 1416423003: Make GrGLSLProgramBuilder base class for ProgramBuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLXferProcessor.h ('k') | src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrGLFragmentShaderBuilder_DEFINED 8 #ifndef GrGLFragmentShaderBuilder_DEFINED
9 #define GrGLFragmentShaderBuilder_DEFINED 9 #define GrGLFragmentShaderBuilder_DEFINED
10 10
11 #include "GrGLShaderBuilder.h" 11 #include "GrGLShaderBuilder.h"
12 12
13 #include "gl/GrGLTypes.h"
14 #include "glsl/GrGLSLProcessorTypes.h" 13 #include "glsl/GrGLSLProcessorTypes.h"
15 14
16 class GrRenderTarget; 15 class GrRenderTarget;
17 class GrGLVarying; 16 class GrGLSLVarying;
18 17
19 /* 18 /*
20 * This base class encapsulates the functionality which the GP uses to build fra gment shaders 19 * This base class encapsulates the functionality which the GP uses to build fra gment shaders
21 */ 20 */
22 class GrGLFragmentBuilder : public GrGLShaderBuilder { 21 class GrGLFragmentBuilder : public GrGLShaderBuilder {
23 public: 22 public:
24 GrGLFragmentBuilder(GrGLProgramBuilder* program) 23 GrGLFragmentBuilder(GrGLSLProgramBuilder* program)
25 : INHERITED(program) { 24 : INHERITED(program)
25 , fHasCustomColorOutput(false)
26 , fHasSecondaryOutput(false) {
26 fSubstageIndices.push_back(0); 27 fSubstageIndices.push_back(0);
27 } 28 }
28 virtual ~GrGLFragmentBuilder() {} 29 virtual ~GrGLFragmentBuilder() {}
29 /** 30 /**
30 * Use of these features may require a GLSL extension to be enabled. Shaders may not compile 31 * Use of these features may require a GLSL extension to be enabled. Shaders may not compile
31 * if code is added that uses one of these features without calling enableFe ature() 32 * if code is added that uses one of these features without calling enableFe ature()
32 */ 33 */
33 enum GLSLFeature { 34 enum GLSLFeature {
34 kStandardDerivatives_GLSLFeature = 0, 35 kStandardDerivatives_GLSLFeature = 0,
35 kLastGLSLFeature = kStandardDerivatives_GLSLFeature 36 kLastGLSLFeature = kStandardDerivatives_GLSLFeature
(...skipping 19 matching lines...) Expand all
55 56
56 /** 57 /**
57 * Fragment procs with child procs should call these functions before/after calling emitCode 58 * Fragment procs with child procs should call these functions before/after calling emitCode
58 * on a child proc. 59 * on a child proc.
59 */ 60 */
60 void onBeforeChildProcEmitCode(); 61 void onBeforeChildProcEmitCode();
61 void onAfterChildProcEmitCode(); 62 void onAfterChildProcEmitCode();
62 63
63 const SkString& getMangleString() const { return fMangleString; } 64 const SkString& getMangleString() const { return fMangleString; }
64 65
66 bool hasCustomColorOutput() const { return fHasCustomColorOutput; }
67 bool hasSecondaryOutput() const { return fHasSecondaryOutput; }
68
69 protected:
70 bool fHasCustomColorOutput;
71 bool fHasSecondaryOutput;
72
65 private: 73 private:
66 /* 74 /*
67 * State that tracks which child proc in the proc tree is currently emitting code. This is 75 * State that tracks which child proc in the proc tree is currently emitting code. This is
68 * used to update the fMangleString, which is used to mangle the names of un iforms and functions 76 * used to update the fMangleString, which is used to mangle the names of un iforms and functions
69 * emitted by the proc. fSubstageIndices is a stack: its count indicates ho w many levels deep 77 * emitted by the proc. fSubstageIndices is a stack: its count indicates ho w many levels deep
70 * we are in the tree, and its second-to-last value is the index of the chil d proc at that 78 * we are in the tree, and its second-to-last value is the index of the chil d proc at that
71 * level which is currently emitting code. For example, if fSubstageIndices = [3, 1, 2, 0], that 79 * level which is currently emitting code. For example, if fSubstageIndices = [3, 1, 2, 0], that
72 * means we're currently emitting code for the base proc's 3rd child's 1st c hild's 2nd child. 80 * means we're currently emitting code for the base proc's 3rd child's 1st c hild's 2nd child.
73 */ 81 */
74 SkTArray<int> fSubstageIndices; 82 SkTArray<int> fSubstageIndices;
(...skipping 13 matching lines...) Expand all
88 typedef GrGLShaderBuilder INHERITED; 96 typedef GrGLShaderBuilder INHERITED;
89 }; 97 };
90 98
91 /* 99 /*
92 * Fragment processor's, in addition to all of the above, may need to use dst co lor so they use 100 * Fragment processor's, in addition to all of the above, may need to use dst co lor so they use
93 * this builder to create their shader. Because this is the only shader builder the FP sees, we 101 * this builder to create their shader. Because this is the only shader builder the FP sees, we
94 * just call it FPShaderBuilder 102 * just call it FPShaderBuilder
95 */ 103 */
96 class GrGLXPFragmentBuilder : public GrGLFragmentBuilder { 104 class GrGLXPFragmentBuilder : public GrGLFragmentBuilder {
97 public: 105 public:
98 GrGLXPFragmentBuilder(GrGLProgramBuilder* program) : INHERITED(program) {} 106 GrGLXPFragmentBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
99 107
100 /** Returns the variable name that holds the color of the destination pixel. This may be nullptr if 108 /** Returns the variable name that holds the color of the destination pixel. This may be nullptr if
101 no effect advertised that it will read the destination. */ 109 no effect advertised that it will read the destination. */
102 virtual const char* dstColor() = 0; 110 virtual const char* dstColor() = 0;
103 111
104 /** Adds any necessary layout qualifiers in order to legalize the supplied b lend equation with 112 /** Adds any necessary layout qualifiers in order to legalize the supplied b lend equation with
105 this shader. It is only legal to call this method with an advanced blend equation, and only 113 this shader. It is only legal to call this method with an advanced blend equation, and only
106 if these equations are supported. */ 114 if these equations are supported. */
107 virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0; 115 virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0;
108 116
109 private: 117 private:
110 typedef GrGLFragmentBuilder INHERITED; 118 typedef GrGLFragmentBuilder INHERITED;
111 }; 119 };
112 120
113 // TODO rename to Fragment Builder 121 // TODO rename to Fragment Builder
114 class GrGLFragmentShaderBuilder : public GrGLXPFragmentBuilder { 122 class GrGLFragmentShaderBuilder : public GrGLXPFragmentBuilder {
115 public: 123 public:
116 typedef uint8_t FragPosKey; 124 typedef uint8_t FragPosKey;
117 125
118 /** Returns a key for reading the fragment location. This should only be cal led if there is an 126 /** Returns a key for reading the fragment location. This should only be cal led if there is an
119 effect that will requires the fragment position. If the fragment position is not required, 127 effect that will requires the fragment position. If the fragment position is not required,
120 the key is 0. */ 128 the key is 0. */
121 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst); 129 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst);
122 130
123 GrGLFragmentShaderBuilder(GrGLProgramBuilder* program, uint8_t fragPosKey); 131 GrGLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKey) ;
124 132
125 // true public interface, defined explicitly in the abstract interfaces abov e 133 // true public interface, defined explicitly in the abstract interfaces abov e
126 bool enableFeature(GLSLFeature) override; 134 bool enableFeature(GLSLFeature) override;
127 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords , 135 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords ,
128 int index) override; 136 int index) override;
129 const char* fragmentPosition() override; 137 const char* fragmentPosition() override;
130 const char* dstColor() override; 138 const char* dstColor() override;
131 139
132 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override; 140 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override;
133 141
134 private: 142 private:
135 // Private public interface, used by GrGLProgramBuilder to build a fragment shader 143 // Private public interface, used by GrGLProgramBuilder to build a fragment shader
136 void enableCustomOutput(); 144 void enableCustomOutput();
137 void enableSecondaryOutput(); 145 void enableSecondaryOutput();
138 const char* getPrimaryColorOutputName() const; 146 const char* getPrimaryColorOutputName() const;
139 const char* getSecondaryColorOutputName() const; 147 const char* getSecondaryColorOutputName() const;
140 void bindFragmentShaderLocations(GrGLuint programID);
141 148
142 // As GLProcessors emit code, there are some conditions we need to verify. We use the below 149 // As GLProcessors emit code, there are some conditions we need to verify. We use the below
143 // state to track this. The reset call is called per processor emitted. 150 // state to track this. The reset call is called per processor emitted.
144 bool hasReadDstColor() const { return fHasReadDstColor; } 151 bool hasReadDstColor() const { return fHasReadDstColor; }
145 bool hasReadFragmentPosition() const { return fHasReadFragmentPosition; } 152 bool hasReadFragmentPosition() const { return fHasReadFragmentPosition; }
146 void reset() { 153 void reset() {
147 fHasReadDstColor = false; 154 fHasReadDstColor = false;
148 fHasReadFragmentPosition = false; 155 fHasReadFragmentPosition = false;
149 } 156 }
150 157
158 static const char* DeclaredColorOutputName() { return "fsColorOut"; }
159 static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryC olorOut"; }
160
151 /* 161 /*
152 * An internal call for GrGLProgramBuilder to use to add varyings to the ver tex shader 162 * An internal call for GrGLProgramBuilder to use to add varyings to the ver tex shader
153 */ 163 */
154 void addVarying(GrGLVarying*, GrSLPrecision); 164 void addVarying(GrGLSLVarying*, GrSLPrecision);
155 165
156 void onFinalize() override; 166 void onFinalize() override;
157 167
158 /** 168 /**
159 * Features that should only be enabled by GrGLFragmentShaderBuilder itself. 169 * Features that should only be enabled by GrGLFragmentShaderBuilder itself.
160 */ 170 */
161 enum GLSLPrivateFeature { 171 enum GLSLPrivateFeature {
162 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, 172 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1,
163 kBlendEquationAdvanced_GLSLPrivateFeature, 173 kBlendEquationAdvanced_GLSLPrivateFeature,
164 kBlendFuncExtended_GLSLPrivateFeature, 174 kBlendFuncExtended_GLSLPrivateFeature,
165 kLastGLSLPrivateFeature = kBlendFuncExtended_GLSLPrivateFeature 175 kLastGLSLPrivateFeature = kBlendFuncExtended_GLSLPrivateFeature
166 }; 176 };
167 177
168 // Interpretation of FragPosKey when generating code 178 // Interpretation of FragPosKey when generating code
169 enum { 179 enum {
170 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil l not be needed. 180 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil l not be needed.
171 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t op-left. 181 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t op-left.
172 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b ottom-left. 182 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b ottom-left.
173 }; 183 };
174 184
175 static const char* kDstTextureColorName; 185 static const char* kDstTextureColorName;
176 186
177 bool fHasCustomColorOutput;
178 bool fHasSecondaryOutput;
179 bool fSetupFragPosition; 187 bool fSetupFragPosition;
180 bool fTopLeftFragPosRead; 188 bool fTopLeftFragPosRead;
181 int fCustomColorOutputIndex; 189 int fCustomColorOutputIndex;
182 190
183 // some state to verify shaders and effects are consistent, this is reset be tween effects by 191 // some state to verify shaders and effects are consistent, this is reset be tween effects by
184 // the program creator 192 // the program creator
185 bool fHasReadDstColor; 193 bool fHasReadDstColor;
186 bool fHasReadFragmentPosition; 194 bool fHasReadFragmentPosition;
187 195
188 friend class GrGLProgramBuilder; 196 friend class GrGLProgramBuilder;
189 197
190 typedef GrGLXPFragmentBuilder INHERITED; 198 typedef GrGLXPFragmentBuilder INHERITED;
191 }; 199 };
192 200
193 #endif 201 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLXferProcessor.h ('k') | src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698