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

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

Issue 25605008: Repurpose GrGLCoordTransform as GrGLEffectArray (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/GrGLProgramEffects.cpp ('k') | src/gpu/gl/GrGLShaderBuilder.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 2012 Google Inc. 2 * Copyright 2012 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 GrGLShaderBuilder_DEFINED 8 #ifndef GrGLShaderBuilder_DEFINED
9 #define GrGLShaderBuilder_DEFINED 9 #define GrGLShaderBuilder_DEFINED
10 10
11 #include "GrAllocator.h" 11 #include "GrAllocator.h"
12 #include "GrBackendEffectFactory.h" 12 #include "GrBackendEffectFactory.h"
13 #include "GrColor.h" 13 #include "GrColor.h"
14 #include "GrEffect.h" 14 #include "GrEffect.h"
15 #include "SkTypes.h" 15 #include "SkTypes.h"
16 #include "gl/GrGLCoordTransform.h" 16 #include "gl/GrGLProgramEffects.h"
17 #include "gl/GrGLSL.h" 17 #include "gl/GrGLSL.h"
18 #include "gl/GrGLUniformManager.h" 18 #include "gl/GrGLUniformManager.h"
19 19
20 #include <stdarg.h> 20 #include <stdarg.h>
21 21
22 class GrGLContextInfo; 22 class GrGLContextInfo;
23 class GrEffectStage; 23 class GrEffectStage;
24 class GrGLProgramDesc; 24 class GrGLProgramDesc;
25 25
26 /** 26 /**
27 Contains all the incremental state of a shader as it is being built,as well as helpers to 27 Contains all the incremental state of a shader as it is being built,as well as helpers to
28 manipulate that state. 28 manipulate that state.
29 */ 29 */
30 class GrGLShaderBuilder { 30 class GrGLShaderBuilder {
31 public: 31 public:
32 /**
33 * Passed to GrGLEffects to add texture reads to their shader code.
34 */
35 class TextureSampler {
36 public:
37 TextureSampler()
38 : fConfigComponentMask(0) {
39 // we will memcpy the first 4 bytes from passed in swizzle. This ens ures the string is
40 // terminated.
41 fSwizzle[4] = '\0';
42 }
43
44 TextureSampler(const TextureSampler& other) { *this = other; }
45
46 TextureSampler& operator= (const TextureSampler& other) {
47 SkASSERT(0 == fConfigComponentMask);
48 SkASSERT(!fSamplerUniform.isValid());
49
50 fConfigComponentMask = other.fConfigComponentMask;
51 fSamplerUniform = other.fSamplerUniform;
52 return *this;
53 }
54
55 // bitfield of GrColorComponentFlags present in the texture's config.
56 uint32_t configComponentMask() const { return fConfigComponentMask; }
57
58 const char* swizzle() const { return fSwizzle; }
59
60 bool isInitialized() const { return 0 != fConfigComponentMask; }
61
62 private:
63 // The idx param is used to ensure multiple samplers within a single eff ect have unique
64 // uniform names. swizzle is a four char max string made up of chars 'r' , 'g', 'b', and 'a'.
65 void init(GrGLShaderBuilder* builder,
66 uint32_t configComponentMask,
67 const char* swizzle,
68 int idx) {
69 SkASSERT(!this->isInitialized());
70 SkASSERT(0 != configComponentMask);
71 SkASSERT(!fSamplerUniform.isValid());
72
73 SkASSERT(NULL != builder);
74 SkString name;
75 name.printf("Sampler%d", idx);
76 fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_V isibility,
77 kSampler2D_GrSLType,
78 name.c_str());
79 SkASSERT(fSamplerUniform.isValid());
80
81 fConfigComponentMask = configComponentMask;
82 memcpy(fSwizzle, swizzle, 4);
83 }
84
85 void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) {
86 SkASSERT(NULL != access);
87 this->init(builder,
88 GrPixelConfigComponentMask(access->getTexture()->config() ),
89 access->getSwizzle(),
90 idx);
91 }
92
93 uint32_t fConfigComponentMask;
94 char fSwizzle[5];
95 GrGLUniformManager::UniformHandle fSamplerUniform;
96
97 friend class GrGLShaderBuilder; // to call init().
98 };
99
100 typedef SkTArray<GrGLCoordTransform::TransformedCoords> TransformedCoordsArr ay;
101 typedef SkTArray<TextureSampler> TextureSamplerArray;
102 typedef GrTAllocator<GrGLShaderVar> VarArray; 32 typedef GrTAllocator<GrGLShaderVar> VarArray;
103 typedef GrBackendEffectFactory::EffectKey EffectKey; 33 typedef GrBackendEffectFactory::EffectKey EffectKey;
34 typedef GrGLProgramEffects::TextureSampler TextureSampler;
35 typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
104 36
105 enum ShaderVisibility { 37 enum ShaderVisibility {
106 kVertex_Visibility = 0x1, 38 kVertex_Visibility = 0x1,
107 kGeometry_Visibility = 0x2, 39 kGeometry_Visibility = 0x2,
108 kFragment_Visibility = 0x4, 40 kFragment_Visibility = 0x4,
109 }; 41 };
110 42
111 GrGLShaderBuilder(GrGpuGL*, 43 GrGLShaderBuilder(GrGpuGL*,
112 GrGLUniformManager&, 44 GrGLUniformManager&,
113 const GrGLProgramDesc&, 45 const GrGLProgramDesc&,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 void fsEmitFunction(GrSLType returnType, 100 void fsEmitFunction(GrSLType returnType,
169 const char* name, 101 const char* name,
170 int argCnt, 102 int argCnt,
171 const GrGLShaderVar* args, 103 const GrGLShaderVar* args,
172 const char* body, 104 const char* body,
173 SkString* outName); 105 SkString* outName);
174 106
175 /** Add input/output variable declarations (i.e. 'varying') to the fragment shader. */ 107 /** Add input/output variable declarations (i.e. 'varying') to the fragment shader. */
176 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } 108 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); }
177 109
178 /** Generates a EffectKey for the shader code based on the texture access pa rameters and the
179 capabilities of the GL context. This is useful for keying the shader pr ograms that may
180 have multiple representations, based on the type/format of textures used . */
181 static EffectKey KeyForTextureAccess(const GrTextureAccess&, const GrGLCaps& );
182
183 typedef uint8_t DstReadKey; 110 typedef uint8_t DstReadKey;
184 typedef uint8_t FragPosKey; 111 typedef uint8_t FragPosKey;
185 112
186 /** Returns a key for adding code to read the copy-of-dst color in service of effects that 113 /** Returns a key for adding code to read the copy-of-dst color in service of effects that
187 require reading the dst. It must not return 0 because 0 indicates that there is no dst 114 require reading the dst. It must not return 0 because 0 indicates that there is no dst
188 copy read at all (in which case this function should not be called). */ 115 copy read at all (in which case this function should not be called). */
189 static DstReadKey KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps&); 116 static DstReadKey KeyForDstRead(const GrTexture* dstCopy, const GrGLCaps&);
190 117
191 /** Returns a key for reading the fragment location. This should only be cal led if there is an 118 /** Returns a key for reading the fragment location. This should only be cal led if there is an
192 effect that will requires the fragment position. If the fragment positio n is not required, 119 effect that will requires the fragment position. If the fragment positio n is not required,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 * Interfaces used by GrGLProgram. 173 * Interfaces used by GrGLProgram.
247 * TODO: These are used by GrGLProgram to insert a mode color filter. Remove these when the 174 * TODO: These are used by GrGLProgram to insert a mode color filter. Remove these when the
248 * color filter is expressed as a GrEffect. 175 * color filter is expressed as a GrEffect.
249 */ 176 */
250 const SkString& getInputColor() const { return fInputColor; } 177 const SkString& getInputColor() const { return fInputColor; }
251 GrSLConstantVec getKnownColorValue() const { return fKnownColorValue; } 178 GrSLConstantVec getKnownColorValue() const { return fKnownColorValue; }
252 const SkString& getInputCoverage() const { return fInputCoverage; } 179 const SkString& getInputCoverage() const { return fInputCoverage; }
253 GrSLConstantVec getKnownCoverageValue() const { return fKnownCoverageValue; } 180 GrSLConstantVec getKnownCoverageValue() const { return fKnownCoverageValue; }
254 181
255 /** 182 /**
256 * Adds code for effects. effectStages contains the effects to add. effectKe ys[i] is the key 183 * Adds code for effects and returns a GrGLProgramEffects* object. The calle r is responsible for
257 * generated from effectStages[i]. An entry in effectStages can be NULL, in which case it is 184 * deleting it when finished. effectStages contains the effects to add. effe ctKeys[i] is the key
258 * skipped. Moreover, if the corresponding key is GrGLEffect::NoEffectKey th en it is skipped. 185 * generated from effectStages[i]. inOutFSColor specifies the input color to the first stage and
259 * inOutFSColor specifies the input color to the first stage and is updated to be the 186 * is updated to be the output color of the last stage. fsInOutColorKnownVal ue specifies whether
260 * output color of the last stage. fsInOutColorKnownValue specifies whether the input color 187 * the input color has a known constant value and is updated to refer to the status of the
261 * has a known constant value and is updated to refer to the status of the o utput color. 188 * output color. The handles to texture samplers for effectStage[i] are adde d to
262 * The handles to texture samplers for effectStage[i] are added to effectSam plerHandles[i]. The 189 * effectSamplerHandles[i].
263 * glEffects array is updated to contain the GrGLEffect generated for each e ntry in
264 * effectStages.
265 */ 190 */
266 void emitEffects(const GrEffectStage* effectStages[], 191 GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effectStages[] ,
267 const EffectKey effectKeys[], 192 const EffectKey effectKeys[],
268 int effectCnt, 193 int effectCnt,
269 SkString* inOutFSColor, 194 SkString* inOutFSColor,
270 GrSLConstantVec* fsInOutColorKnownValue, 195 GrSLConstantVec* fsInOutColorKnownV alue);
271 SkTArray<GrGLCoordTransform, false>* effectCoordTransformAr rays[],
272 SkTArray<GrGLUniformManager::UniformHandle, true>* effectSa mplerHandles[],
273 GrGLEffect* glEffects[]);
274 196
275 const char* getColorOutputName() const; 197 const char* getColorOutputName() const;
276 const char* enableSecondaryOutput(); 198 const char* enableSecondaryOutput();
277 199
278 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei ghtUniform; } 200 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei ghtUniform; }
279 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const { 201 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const {
280 return fDstCopyTopLeftUniform; 202 return fDstCopyTopLeftUniform;
281 } 203 }
282 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const { 204 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const {
283 return fDstCopyScaleUniform; 205 return fDstCopyScaleUniform;
284 } 206 }
285 GrGLUniformManager::UniformHandle getColorUniform() const { return fColorUni form; } 207 GrGLUniformManager::UniformHandle getColorUniform() const { return fColorUni form; }
286 GrGLUniformManager::UniformHandle getCoverageUniform() const { return fCover ageUniform; } 208 GrGLUniformManager::UniformHandle getCoverageUniform() const { return fCover ageUniform; }
287 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const { 209 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const {
288 return fDstCopySampler.fSamplerUniform; 210 return fDstCopySamplerUniform;
289 } 211 }
290 212
291 /** Helper class used to build the vertex and geometry shaders. This functio nality 213 /** Helper class used to build the vertex and geometry shaders. This functio nality
292 is kept separate from the rest of GrGLShaderBuilder to allow for shaders programs 214 is kept separate from the rest of GrGLShaderBuilder to allow for shaders programs
293 that only use the fragment shader. */ 215 that only use the fragment shader. */
294 class VertexBuilder { 216 class VertexBuilder {
295 public: 217 public:
296 VertexBuilder(GrGLShaderBuilder* parent, GrGpuGL* gpu, const GrGLProgram Desc&); 218 VertexBuilder(GrGLShaderBuilder* parent, GrGpuGL* gpu, const GrGLProgram Desc&);
297 219
298 /** 220 /**
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 GrGLUniformManager& fUniformManager; 399 GrGLUniformManager& fUniformManager;
478 uint32_t fFSFeaturesAddedMask; 400 uint32_t fFSFeaturesAddedMask;
479 SkString fFSFunctions; 401 SkString fFSFunctions;
480 SkString fFSExtensions; 402 SkString fFSExtensions;
481 VarArray fFSInputs; 403 VarArray fFSInputs;
482 VarArray fFSOutputs; 404 VarArray fFSOutputs;
483 405
484 SkString fFSCode; 406 SkString fFSCode;
485 407
486 bool fSetupFragPosition; 408 bool fSetupFragPosition;
487 TextureSampler fDstCopySampler; 409 GrGLUniformManager::UniformHandle fDstCopySamplerUniform;
488 410
489 SkString fInputColor; 411 SkString fInputColor;
490 GrSLConstantVec fKnownColorValue; 412 GrSLConstantVec fKnownColorValue;
491 SkString fInputCoverage; 413 SkString fInputCoverage;
492 GrSLConstantVec fKnownCoverageValue; 414 GrSLConstantVec fKnownCoverageValue;
493 415
494 bool fHasCustomColorOutput; 416 bool fHasCustomColorOutput;
495 bool fHasSecondaryOutput; 417 bool fHasSecondaryOutput;
496 418
497 GrGLUniformManager::UniformHandle fRTHeightUniform; 419 GrGLUniformManager::UniformHandle fRTHeightUniform;
498 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform; 420 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform;
499 GrGLUniformManager::UniformHandle fDstCopyScaleUniform; 421 GrGLUniformManager::UniformHandle fDstCopyScaleUniform;
500 GrGLUniformManager::UniformHandle fColorUniform; 422 GrGLUniformManager::UniformHandle fColorUniform;
501 GrGLUniformManager::UniformHandle fCoverageUniform; 423 GrGLUniformManager::UniformHandle fCoverageUniform;
502 424
503 bool fTopLeftFragPosRead; 425 bool fTopLeftFragPosRead;
504 426
505 SkAutoTDelete<VertexBuilder> fVertexBuilder; 427 SkAutoTDelete<VertexBuilder> fVertexBuilder;
506 }; 428 };
507 429
508 #endif 430 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramEffects.cpp ('k') | src/gpu/gl/GrGLShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698