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

Side by Side Diff: src/gpu/gl/GrGLProgramEffects.h

Issue 491673002: Initial refactor of shaderbuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months 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/GrGLProgramDesc.cpp ('k') | src/gpu/gl/GrGLProgramEffects.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 2013 Google Inc. 2 * Copyright 2013 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 GrGLProgramEffects_DEFINED 8 #ifndef GrGLProgramEffects_DEFINED
9 #define GrGLProgramEffects_DEFINED 9 #define GrGLProgramEffects_DEFINED
10 10
11 #include "GrBackendEffectFactory.h" 11 #include "GrBackendEffectFactory.h"
12 #include "GrGLProgramDataManager.h" 12 #include "GrGLProgramDataManager.h"
13 #include "GrTexture.h" 13 #include "GrTexture.h"
14 #include "GrTextureAccess.h" 14 #include "GrTextureAccess.h"
15 15
16 class GrEffect; 16 class GrEffect;
17 class GrEffectStage; 17 class GrEffectStage;
18 class GrGLVertexProgramEffectsBuilder; 18 class GrGLVertexProgramEffectsBuilder;
19 class GrGLShaderBuilder; 19 class GrGLProgramBuilder;
20 class GrGLFullShaderBuilder; 20 class GrGLFullProgramBuilder;
21 class GrGLFragmentOnlyShaderBuilder; 21 class GrGLFragmentOnlyProgramBuilder;
22 22
23 /** 23 /**
24 * This class encapsulates an array of GrGLEffects and their supporting data (co ord transforms 24 * This class encapsulates an array of GrGLEffects and their supporting data (co ord transforms
25 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag e the necessary GL 25 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag e the necessary GL
26 * state and shader uniforms. 26 * state and shader uniforms.
27 */ 27 */
28 class GrGLProgramEffects : public SkRefCnt { 28 class GrGLProgramEffects : public SkRefCnt {
29 public: 29 public:
30 typedef GrGLProgramDataManager::UniformHandle UniformHandle; 30 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
31 31
(...skipping 15 matching lines...) Expand all
47 */ 47 */
48 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx); 48 void initSamplers(const GrGLProgramDataManager&, int* texUnitIdx);
49 49
50 /** 50 /**
51 * Calls setData() on each effect, and sets their transformation matrices an d texture bindings. 51 * Calls setData() on each effect, and sets their transformation matrices an d texture bindings.
52 */ 52 */
53 virtual void setData(GrGpuGL*, 53 virtual void setData(GrGpuGL*,
54 const GrGLProgramDataManager&, 54 const GrGLProgramDataManager&,
55 const GrEffectStage* effectStages[]) = 0; 55 const GrEffectStage* effectStages[]) = 0;
56 56
57 void addEffect(GrGLEffect* effect) { fGLEffects.push_back(effect); }
58
57 /** 59 /**
58 * Passed to GrGLEffects so they can add transformed coordinates to their sh ader code. 60 * Passed to GrGLEffects so they can add transformed coordinates to their sh ader code.
59 */ 61 */
60 class TransformedCoords { 62 class TransformedCoords {
61 public: 63 public:
62 TransformedCoords(const SkString& name, GrSLType type) 64 TransformedCoords(const SkString& name, GrSLType type)
63 : fName(name), fType(type) { 65 : fName(name), fType(type) {
64 } 66 }
65 67
66 const char* c_str() const { return fName.c_str(); } 68 const char* c_str() const { return fName.c_str(); }
(...skipping 26 matching lines...) Expand all
93 95
94 private: 96 private:
95 UniformHandle fSamplerUniform; 97 UniformHandle fSamplerUniform;
96 uint32_t fConfigComponentMask; 98 uint32_t fConfigComponentMask;
97 char fSwizzle[5]; 99 char fSwizzle[5];
98 }; 100 };
99 101
100 typedef SkTArray<TextureSampler> TextureSamplerArray; 102 typedef SkTArray<TextureSampler> TextureSamplerArray;
101 103
102 protected: 104 protected:
105
103 /** 106 /**
104 * Helpers for GenEffectMetaKey. 107 * Helpers for GenEffectMetaKey.
105 */ 108 */
106 static uint32_t GenAttribKey(const GrDrawEffect&); 109 static uint32_t GenAttribKey(const GrDrawEffect&);
107 static uint32_t GenTransformKey(const GrDrawEffect&); 110 static uint32_t GenTransformKey(const GrDrawEffect&);
108 static uint32_t GenTextureKey(const GrDrawEffect&, const GrGLCaps&); 111 static uint32_t GenTextureKey(const GrDrawEffect&, const GrGLCaps&);
109 112
110 GrGLProgramEffects(int reserveCount) 113 GrGLProgramEffects(int reserveCount)
111 : fGLEffects(reserveCount) 114 : fGLEffects(reserveCount)
112 , fSamplers(reserveCount) { 115 , fSamplers(reserveCount) {
113 } 116 }
114 117
115 /** 118 /**
116 * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's t exture accesses and 119 * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's t exture accesses and
117 * appends the necessary data to the TextureSamplerArray* object so effects can add texture 120 * appends the necessary data to the TextureSamplerArray* object so effects can add texture
118 * lookups to their code. This method is only meant to be called during the construction phase. 121 * lookups to their code. This method is only meant to be called during the construction phase.
119 */ 122 */
120 void emitSamplers(GrGLShaderBuilder*, const GrEffect*, TextureSamplerArray*) ; 123 void emitSamplers(GrGLProgramBuilder*, const GrEffect*, TextureSamplerArray* );
121 124
122 /** 125 /**
123 * Helper for setData(). Binds all the textures for an effect. 126 * Helper for setData(). Binds all the textures for an effect.
124 */ 127 */
125 void bindTextures(GrGpuGL*, const GrEffect*, int effectIdx); 128 void bindTextures(GrGpuGL*, const GrEffect*, int effectIdx);
126 129
127 struct Sampler { 130 struct Sampler {
128 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {}) 131 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {})
129 UniformHandle fUniform; 132 UniformHandle fUniform;
130 int fTextureUnit; 133 int fTextureUnit;
131 }; 134 };
132 135
133 SkTArray<GrGLEffect*> fGLEffects; 136 SkTArray<GrGLEffect*> fGLEffects;
134 SkTArray<SkSTArray<4, Sampler, true> > fSamplers; 137 SkTArray<SkSTArray<4, Sampler, true> > fSamplers;
135 138
136 private: 139 private:
140 friend class GrGLFragmentO;
137 typedef SkRefCnt INHERITED; 141 typedef SkRefCnt INHERITED;
138 }; 142 };
139 143
140 /** 144 /**
141 * This is an abstract base class for constructing different types of GrGLProgra mEffects objects. 145 * This is an abstract base class for constructing different types of GrGLProgra mEffects objects.
142 */ 146 */
143 class GrGLProgramEffectsBuilder { 147 class GrGLProgramEffectsBuilder {
144 public: 148 public:
145 virtual ~GrGLProgramEffectsBuilder() { } 149 virtual ~GrGLProgramEffectsBuilder() { }
146
147 /** 150 /**
148 * Emits the effect's shader code, and stores the necessary uniforms interna lly. 151 * Emits the effect's shader code, and stores the necessary uniforms interna lly.
149 */ 152 */
150 virtual void emitEffect(const GrEffectStage&, 153 virtual void emitEffect(const GrEffectStage&,
151 const GrEffectKey&, 154 const GrEffectKey&,
152 const char* outColor, 155 const char* outColor,
153 const char* inColor, 156 const char* inColor,
154 int stageIndex) = 0; 157 int stageIndex) = 0;
155 }; 158 };
156 159
157 //////////////////////////////////////////////////////////////////////////////// 160 ////////////////////////////////////////////////////////////////////////////////
158 161
159 /** 162 /**
160 * This is a GrGLProgramEffects implementation that does coord transforms with t he vertex shader. 163 * This is a GrGLProgramEffects implementation that does coord transforms with t he vertex shader.
161 */ 164 */
162 class GrGLVertexProgramEffects : public GrGLProgramEffects { 165 class GrGLVertexProgramEffects : public GrGLProgramEffects {
163 public: 166 public:
164 virtual void setData(GrGpuGL*, 167 virtual void setData(GrGpuGL*,
165 const GrGLProgramDataManager&, 168 const GrGLProgramDataManager&,
166 const GrEffectStage* effectStages[]) SK_OVERRIDE; 169 const GrEffectStage* effectStages[]) SK_OVERRIDE;
167 170
168 private: 171 private:
169 friend class GrGLVertexProgramEffectsBuilder; 172 friend class GrGLFullProgramBuilder;
170 173
171 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) 174 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords)
172 : INHERITED(reserveCount) 175 : INHERITED(reserveCount)
173 , fTransforms(reserveCount) 176 , fTransforms(reserveCount)
174 , fHasExplicitLocalCoords(explicitLocalCoords) { 177 , fHasExplicitLocalCoords(explicitLocalCoords) {
175 } 178 }
176
177 /** 179 /**
178 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant to only be called 180 * This method is meant to only be called during the construction phase.
179 * during the construction phase.
180 */ 181 */
181 void emitEffect(GrGLFullShaderBuilder*, 182 void emitEffect(GrGLFullProgramBuilder*,
182 const GrEffectStage&, 183 const GrEffectStage&,
183 const GrEffectKey&, 184 const GrEffectKey&,
184 const char* outColor, 185 const char* outColor,
185 const char* inColor, 186 const char* inColor,
186 int stageIndex); 187 int stageIndex);
187 188
188 /** 189 /**
189 * Helper for emitEffect(). Emits any attributes an effect may have. 190 * Helper for emitEffect(). Emits any attributes an effect may have.
190 */ 191 */
191 void emitAttributes(GrGLFullShaderBuilder*, const GrEffectStage&); 192 void emitAttributes(GrGLFullProgramBuilder*, const GrEffectStage&);
192 193
193 /** 194 /**
194 * Helper for emitEffect(). Emits code to implement an effect's coord transf orms in the VS. 195 * Helper for emitEffect(). Emits code to implement an effect's coord transf orms in the VS.
195 * Varyings are added as an outputs of the VS and inputs to the FS. The vary ings may be either a 196 * Varyings are added as an outputs of the VS and inputs to the FS. The vary ings may be either a
196 * vec2f or vec3f depending upon whether perspective interpolation is requir ed or not. The names 197 * vec2f or vec3f depending upon whether perspective interpolation is requir ed or not. The names
197 * of the varyings in the VS and FS as well their types are appended to the 198 * of the varyings in the VS and FS as well their types are appended to the
198 * TransformedCoordsArray* object, which is in turn passed to the effect's e mitCode() function. 199 * TransformedCoordsArray* object, which is in turn passed to the effect's e mitCode() function.
199 */ 200 */
200 void emitTransforms(GrGLFullShaderBuilder*, 201 void emitTransforms(GrGLFullProgramBuilder*,
201 const GrDrawEffect&, 202 const GrDrawEffect&,
202 TransformedCoordsArray*); 203 TransformedCoordsArray*);
203 204
204 /** 205 /**
205 * Helper for setData(). Sets all the transform matrices for an effect. 206 * Helper for setData(). Sets all the transform matrices for an effect.
206 */ 207 */
207 void setTransformData(const GrGLProgramDataManager&, const GrDrawEffect&, in t effectIdx); 208 void setTransformData(const GrGLProgramDataManager&, const GrDrawEffect&, in t effectIdx);
208 209
209 struct Transform { 210 struct Transform {
210 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } 211 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); }
211 UniformHandle fHandle; 212 UniformHandle fHandle;
212 SkMatrix fCurrentValue; 213 SkMatrix fCurrentValue;
213 }; 214 };
214 215
215 SkTArray<SkSTArray<2, Transform, true> > fTransforms; 216 SkTArray<SkSTArray<2, Transform, true> > fTransforms;
216 bool fHasExplicitLocalCoords; 217 bool fHasExplicitLocalCoords;
217 218
219 friend class GrGLVertexProgramEffectsBuilder;
220
218 typedef GrGLProgramEffects INHERITED; 221 typedef GrGLProgramEffects INHERITED;
219 }; 222 };
220 223
221 /** 224 /**
222 * This class is used to construct a GrGLVertexProgramEffects* object. 225 * This class is used to construct a GrGLVertexProgramEffects* object.
223 */ 226 */
224 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder { 227 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder {
225 public: 228 public:
226 GrGLVertexProgramEffectsBuilder(GrGLFullShaderBuilder*, int reserveCount); 229 GrGLVertexProgramEffectsBuilder(GrGLFullProgramBuilder*, int reserveCount);
227 virtual ~GrGLVertexProgramEffectsBuilder() { } 230 virtual ~GrGLVertexProgramEffectsBuilder() { }
228
229 virtual void emitEffect(const GrEffectStage&, 231 virtual void emitEffect(const GrEffectStage&,
230 const GrEffectKey&, 232 const GrEffectKey&,
231 const char* outColor, 233 const char* outColor,
232 const char* inColor, 234 const char* inColor,
233 int stageIndex) SK_OVERRIDE; 235 int stageIndex) SK_OVERRIDE;
234
235 /** 236 /**
236 * Finalizes the building process and returns the effect array. After this c all, the builder 237 * Finalizes the building process and returns the effect array. After this c all, the builder
237 * becomes invalid. 238 * becomes invalid.
238 */ 239 */
239 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } 240 GrGLProgramEffects* finish() { return fProgramEffects.detach(); }
240
241 private: 241 private:
242 GrGLFullShaderBuilder* fBuilder; 242 GrGLFullProgramBuilder* fBuilder;
243 SkAutoTDelete<GrGLVertexProgramEffects> fProgramEffects; 243 SkAutoTDelete<GrGLVertexProgramEffects> fProgramEffects;
244
245 typedef GrGLProgramEffectsBuilder INHERITED; 244 typedef GrGLProgramEffectsBuilder INHERITED;
246 }; 245 };
247 246
248 //////////////////////////////////////////////////////////////////////////////// 247 ////////////////////////////////////////////////////////////////////////////////
249 248
250 /** 249 /**
251 * This is a GrGLProgramEffects implementation that does coord transforms with 250 * This is a GrGLProgramEffects implementation that does coord transforms with
252 * the the NV_path_rendering PathTexGen functionality. 251 * the the NV_path_rendering PathTexGen functionality.
253 */ 252 */
254 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects { 253 class GrGLPathTexGenProgramEffects : public GrGLProgramEffects {
255 public: 254 public:
256 virtual void setData(GrGpuGL*, 255 virtual void setData(GrGpuGL*,
257 const GrGLProgramDataManager&, 256 const GrGLProgramDataManager&,
258 const GrEffectStage* effectStages[]) SK_OVERRIDE; 257 const GrEffectStage* effectStages[]) SK_OVERRIDE;
259 258
260 private: 259 private:
261 friend class GrGLPathTexGenProgramEffectsBuilder; 260 friend class GrGLFragmentOnlyProgramBuilder;
262 261
263 GrGLPathTexGenProgramEffects(int reserveCount) 262 GrGLPathTexGenProgramEffects(int reserveCount)
264 : INHERITED(reserveCount) 263 : INHERITED(reserveCount)
265 , fTransforms(reserveCount) { 264 , fTransforms(reserveCount) {
266 } 265 }
267 266
268 /** 267 /**
269 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant to only be called 268 * This method is meant to only be called during the construction phase.
270 * during the construction phase.
271 */ 269 */
272 void emitEffect(GrGLFragmentOnlyShaderBuilder*, 270 void emitEffect(GrGLFragmentOnlyProgramBuilder*,
273 const GrEffectStage&, 271 const GrEffectStage&,
274 const GrEffectKey&, 272 const GrEffectKey&,
275 const char* outColor, 273 const char* outColor,
276 const char* inColor, 274 const char* inColor,
277 int stageIndex); 275 int stageIndex);
278 276
279 /** 277 /**
280 * Helper for emitEffect(). Allocates texture units from the builder for eac h transform in an 278 * Helper for emitEffect(). Allocates texture units from the builder for eac h transform in an
281 * effect. The transforms all use adjacent texture units. They either use tw o or three of the 279 * effect. The transforms all use adjacent texture units. They either use tw o or three of the
282 * coordinates at a given texture unit, depending on if they need perspectiv e interpolation. 280 * coordinates at a given texture unit, depending on if they need perspectiv e interpolation.
283 * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[ 0])') as well as the 281 * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[ 0])') as well as the
284 * types are appended to the TransformedCoordsArray* object, which is in tur n passed to the 282 * types are appended to the TransformedCoordsArray* object, which is in tur n passed to the
285 * effect's emitCode() function. 283 * effect's emitCode() function.
286 */ 284 */
287 void setupPathTexGen(GrGLFragmentOnlyShaderBuilder*, 285 void setupPathTexGen(GrGLFragmentOnlyProgramBuilder*,
288 const GrDrawEffect&, 286 const GrDrawEffect&,
289 TransformedCoordsArray*); 287 TransformedCoordsArray*);
290 288
291 /** 289 /**
292 * Helper for setData(). Sets the PathTexGen state for each transform in an effect. 290 * Helper for setData(). Sets the PathTexGen state for each transform in an effect.
293 */ 291 */
294 void setPathTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx); 292 void setPathTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx);
295 293
296 struct Transforms { 294 struct Transforms {
297 Transforms(uint32_t transformKey, int texCoordIndex) 295 Transforms(uint32_t transformKey, int texCoordIndex)
298 : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {} 296 : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {}
299 uint32_t fTransformKey; 297 uint32_t fTransformKey;
300 int fTexCoordIndex; 298 int fTexCoordIndex;
301 }; 299 };
302 300
303 SkTArray<Transforms> fTransforms; 301 SkTArray<Transforms> fTransforms;
304 302
303 friend class GrGLPathTexGenProgramEffectsBuilder;
305 typedef GrGLProgramEffects INHERITED; 304 typedef GrGLProgramEffects INHERITED;
306 }; 305 };
307 306
308 /** 307 /**
309 * This class is used to construct a GrGLPathTexGenProgramEffects* object. 308 * This class is used to construct a GrGLPathTexGenProgramEffects* object.
310 */ 309 */
311 class GrGLPathTexGenProgramEffectsBuilder : public GrGLProgramEffectsBuilder { 310 class GrGLPathTexGenProgramEffectsBuilder : public GrGLProgramEffectsBuilder {
312 public: 311 public:
313 GrGLPathTexGenProgramEffectsBuilder(GrGLFragmentOnlyShaderBuilder*, int rese rveCount); 312 GrGLPathTexGenProgramEffectsBuilder(GrGLFragmentOnlyProgramBuilder*, int res erveCount);
314 virtual ~GrGLPathTexGenProgramEffectsBuilder() { } 313 virtual ~GrGLPathTexGenProgramEffectsBuilder() { }
315
316 virtual void emitEffect(const GrEffectStage&, 314 virtual void emitEffect(const GrEffectStage&,
317 const GrEffectKey&, 315 const GrEffectKey&,
318 const char* outColor, 316 const char* outColor,
319 const char* inColor, 317 const char* inColor,
320 int stageIndex) SK_OVERRIDE; 318 int stageIndex) SK_OVERRIDE;
321
322 /** 319 /**
323 * Finalizes the building process and returns the effect array. After this c all, the builder 320 * Finalizes the building process and returns the effect array. After this c all, the builder
324 * becomes invalid. 321 * becomes invalid.
325 */ 322 */
326 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } 323 GrGLProgramEffects* finish() { return fProgramEffects.detach(); }
327
328 private: 324 private:
329 GrGLFragmentOnlyShaderBuilder* fBuilder; 325 GrGLFragmentOnlyProgramBuilder* fBuilder;
330 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects; 326 SkAutoTDelete<GrGLPathTexGenProgramEffects> fProgramEffects;
331
332 typedef GrGLProgramEffectsBuilder INHERITED; 327 typedef GrGLProgramEffectsBuilder INHERITED;
333 }; 328 };
334 329
330
335 #endif 331 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramDesc.cpp ('k') | src/gpu/gl/GrGLProgramEffects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698