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

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

Issue 25048002: Express (GLSL expression, possibly known value) pairs as a class (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: addressing review comments 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/GrGLSL_impl.h ('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
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 /** Returns a variable name that represents the position of the fragment in the FS. The position 160 /** Returns a variable name that represents the position of the fragment in the FS. The position
161 is in device space (e.g. 0,0 is the top left and pixel centers are at ha lf-integers). */ 161 is in device space (e.g. 0,0 is the top left and pixel centers are at ha lf-integers). */
162 const char* fragmentPosition(); 162 const char* fragmentPosition();
163 163
164 /** Returns the color of the destination pixel. This may be NULL if no effec t advertised 164 /** Returns the color of the destination pixel. This may be NULL if no effec t advertised
165 that it will read the destination. */ 165 that it will read the destination. */
166 const char* dstColor(); 166 const char* dstColor();
167 167
168 /** 168 /**
169 * Interfaces used by GrGLProgram. 169 * Interfaces used by GrGLProgram.
170 * TODO: These are used by GrGLProgram to insert a mode color filter. Remove these when the
171 * color filter is expressed as a GrEffect.
172 */ 170 */
173 const SkString& getInputColor() const { 171 const GrGLSLExpr<4>& getInputColor() const {
174 SkASSERT(fInputColor.isEmpty() != (kNone_GrSLConstantVec == fKnownColorV alue));
175 return fInputColor; 172 return fInputColor;
176 } 173 }
177 GrSLConstantVec getKnownColorValue() const { 174 const GrGLSLExpr<4>& getInputCoverage() const {
178 SkASSERT(fInputColor.isEmpty() != (kNone_GrSLConstantVec == fKnownColorV alue));
179 return fKnownColorValue;
180 }
181 const SkString& getInputCoverage() const {
182 SkASSERT(fInputCoverage.isEmpty() != (kNone_GrSLConstantVec == fKnownCov erageValue));
183 return fInputCoverage; 175 return fInputCoverage;
184 } 176 }
185 GrSLConstantVec getKnownCoverageValue() const {
186 SkASSERT(fInputCoverage.isEmpty() != (kNone_GrSLConstantVec == fKnownCov erageValue));
187 return fKnownCoverageValue;
188 }
189 177
190 /** 178 /**
191 * Adds code for effects and returns a GrGLProgramEffects* object. The calle r is responsible for 179 * Adds code for effects and returns a GrGLProgramEffects* object. The calle r is responsible for
192 * deleting it when finished. effectStages contains the effects to add. effe ctKeys[i] is the key 180 * deleting it when finished. effectStages contains the effects to add. effe ctKeys[i] is the key
193 * generated from effectStages[i]. inOutFSColor specifies the input color to the first stage and 181 * generated from effectStages[i]. inOutFSColor specifies the input color to the first stage and
194 * is updated to be the output color of the last stage. fsInOutColorKnownVal ue specifies whether 182 * is updated to be the output color of the last stage.
195 * the input color has a known constant value and is updated to refer to the status of the 183 * The handles to texture samplers for effectStage[i] are added to
196 * output color. The handles to texture samplers for effectStage[i] are adde d to
197 * effectSamplerHandles[i]. 184 * effectSamplerHandles[i].
198 */ 185 */
199 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect Stages[], 186 virtual GrGLProgramEffects* createAndEmitEffects(const GrEffectStage* effect Stages[],
200 const EffectKey effectKeys[ ], 187 const EffectKey effectKeys[ ],
201 int effectCnt, 188 int effectCnt,
202 SkString* inOutFSColor, 189 GrGLSLExpr<4>* inOutFSColor ) = 0;
203 GrSLConstantVec* fsInOutCol orKnownValue) = 0;
204 190
205 const char* getColorOutputName() const; 191 const char* getColorOutputName() const;
206 const char* enableSecondaryOutput(); 192 const char* enableSecondaryOutput();
207 193
208 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei ghtUniform; } 194 GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHei ghtUniform; }
209 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const { 195 GrGLUniformManager::UniformHandle getDstCopyTopLeftUniform() const {
210 return fDstCopyTopLeftUniform; 196 return fDstCopyTopLeftUniform;
211 } 197 }
212 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const { 198 GrGLUniformManager::UniformHandle getDstCopyScaleUniform() const {
213 return fDstCopyScaleUniform; 199 return fDstCopyScaleUniform;
214 } 200 }
215 GrGLUniformManager::UniformHandle getColorUniform() const { return fColorUni form; } 201 GrGLUniformManager::UniformHandle getColorUniform() const { return fColorUni form; }
216 GrGLUniformManager::UniformHandle getCoverageUniform() const { return fCover ageUniform; } 202 GrGLUniformManager::UniformHandle getCoverageUniform() const { return fCover ageUniform; }
217 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const { 203 GrGLUniformManager::UniformHandle getDstCopySamplerUniform() const {
218 return fDstCopySamplerUniform; 204 return fDstCopySamplerUniform;
219 } 205 }
220 206
221 bool finish(GrGLuint* outProgramId); 207 bool finish(GrGLuint* outProgramId);
222 208
223 const GrGLContextInfo& ctxInfo() const; 209 const GrGLContextInfo& ctxInfo() const;
224 210
225 protected: 211 protected:
226 GrGpuGL* gpu() const { return fGpu; } 212 GrGpuGL* gpu() const { return fGpu; }
227 213
228 void setInputColor(const char* inputColor) { fInputColor = inputColor; } 214 void setInputColor(const GrGLSLExpr<4>& inputColor) { fInputColor = inputCol or; }
229 void setInputCoverage(const char* inputCoverage) { fInputCoverage = inputCov erage; } 215 void setInputCoverage(const GrGLSLExpr<4>& inputCoverage) { fInputCoverage = inputCoverage; }
230 216
231 /** Add input/output variable declarations (i.e. 'varying') to the fragment shader. */ 217 /** Add input/output variable declarations (i.e. 'varying') to the fragment shader. */
232 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); } 218 GrGLShaderVar& fsInputAppend() { return fFSInputs.push_back(); }
233 219
234 // Generates a name for a variable. The generated string will be name prefix ed by the prefix 220 // Generates a name for a variable. The generated string will be name prefix ed by the prefix
235 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp ecific if we're 221 // char (unless the prefix is '\0'). It also mangles the name to be stage-sp ecific if we're
236 // generating stage code. 222 // generating stage code.
237 void nameVariable(SkString* out, char prefix, const char* name); 223 void nameVariable(SkString* out, char prefix, const char* name);
238 224
239 // Helper for emitEffects(). 225 // Helper for emitEffects().
240 void createAndEmitEffects(GrGLProgramEffectsBuilder*, 226 void createAndEmitEffects(GrGLProgramEffectsBuilder*,
241 const GrEffectStage* effectStages[], 227 const GrEffectStage* effectStages[],
242 const EffectKey effectKeys[], 228 const EffectKey effectKeys[],
243 int effectCnt, 229 int effectCnt,
244 SkString* inOutFSColor, 230 GrGLSLExpr<4>* inOutFSColor);
245 GrSLConstantVec* fsInOutColorKnownValue);
246 231
247 virtual bool compileAndAttachShaders(GrGLuint programId) const; 232 virtual bool compileAndAttachShaders(GrGLuint programId) const;
248 virtual void bindProgramLocations(GrGLuint programId) const; 233 virtual void bindProgramLocations(GrGLuint programId) const;
249 234
250 void appendDecls(const VarArray&, SkString*) const; 235 void appendDecls(const VarArray&, SkString*) const;
251 void appendUniformDecls(ShaderVisibility, SkString*) const; 236 void appendUniformDecls(ShaderVisibility, SkString*) const;
252 237
253 private: 238 private:
254 class CodeStage : public SkNoncopyable { 239 class CodeStage : public SkNoncopyable {
255 public: 240 public:
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 SkString fFSExtensions; 322 SkString fFSExtensions;
338 VarArray fFSInputs; 323 VarArray fFSInputs;
339 VarArray fFSOutputs; 324 VarArray fFSOutputs;
340 GrGLUniformManager::BuilderUniformArray fUniforms; 325 GrGLUniformManager::BuilderUniformArray fUniforms;
341 326
342 SkString fFSCode; 327 SkString fFSCode;
343 328
344 bool fSetupFragPosition; 329 bool fSetupFragPosition;
345 GrGLUniformManager::UniformHandle fDstCopySamplerUniform; 330 GrGLUniformManager::UniformHandle fDstCopySamplerUniform;
346 331
347 SkString fInputColor; 332 GrGLSLExpr<4> fInputColor;
348 GrSLConstantVec fKnownColorValue; 333 GrGLSLExpr<4> fInputCoverage;
349 SkString fInputCoverage;
350 GrSLConstantVec fKnownCoverageValue;
351 334
352 bool fHasCustomColorOutput; 335 bool fHasCustomColorOutput;
353 bool fHasSecondaryOutput; 336 bool fHasSecondaryOutput;
354 337
355 GrGLUniformManager::UniformHandle fRTHeightUniform; 338 GrGLUniformManager::UniformHandle fRTHeightUniform;
356 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform; 339 GrGLUniformManager::UniformHandle fDstCopyTopLeftUniform;
357 GrGLUniformManager::UniformHandle fDstCopyScaleUniform; 340 GrGLUniformManager::UniformHandle fDstCopyScaleUniform;
358 GrGLUniformManager::UniformHandle fColorUniform; 341 GrGLUniformManager::UniformHandle fColorUniform;
359 GrGLUniformManager::UniformHandle fCoverageUniform; 342 GrGLUniformManager::UniformHandle fCoverageUniform;
360 343
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 */ 389 */
407 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa r); } 390 bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVa r); }
408 391
409 bool addEffectAttribute(int attributeIndex, GrSLType type, const SkString& n ame); 392 bool addEffectAttribute(int attributeIndex, GrSLType type, const SkString& n ame);
410 const SkString* getEffectAttributeName(int attributeIndex) const; 393 const SkString* getEffectAttributeName(int attributeIndex) const;
411 394
412 virtual GrGLProgramEffects* createAndEmitEffects( 395 virtual GrGLProgramEffects* createAndEmitEffects(
413 const GrEffectStage* effectStages[], 396 const GrEffectStage* effectStages[],
414 const EffectKey effectKeys[], 397 const EffectKey effectKeys[],
415 int effectCnt, 398 int effectCnt,
416 SkString* inOutFSColor, 399 GrGLSLExpr<4>* inOutFSColor) SK_OVERRIDE;
417 GrSLConstantVec* fsInOutColorKnownValue) SK_OVERRIDE;
418 400
419 GrGLUniformManager::UniformHandle getViewMatrixUniform() const { 401 GrGLUniformManager::UniformHandle getViewMatrixUniform() const {
420 return fViewMatrixUniform; 402 return fViewMatrixUniform;
421 } 403 }
422 404
423 protected: 405 protected:
424 virtual bool compileAndAttachShaders(GrGLuint programId) const SK_OVERRIDE; 406 virtual bool compileAndAttachShaders(GrGLuint programId) const SK_OVERRIDE;
425 virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE; 407 virtual void bindProgramLocations(GrGLuint programId) const SK_OVERRIDE;
426 408
427 private: 409 private:
(...skipping 28 matching lines...) Expand all
456 public: 438 public:
457 GrGLFragmentOnlyShaderBuilder(GrGpuGL*, GrGLUniformManager&, const GrGLProgr amDesc&); 439 GrGLFragmentOnlyShaderBuilder(GrGpuGL*, GrGLUniformManager&, const GrGLProgr amDesc&);
458 440
459 int getNumTexCoordSets() const { return fNumTexCoordSets; } 441 int getNumTexCoordSets() const { return fNumTexCoordSets; }
460 int addTexCoordSets(int count) { return (fNumTexCoordSets += count) - count; } 442 int addTexCoordSets(int count) { return (fNumTexCoordSets += count) - count; }
461 443
462 virtual GrGLProgramEffects* createAndEmitEffects( 444 virtual GrGLProgramEffects* createAndEmitEffects(
463 const GrEffectStage* effectStages[], 445 const GrEffectStage* effectStages[],
464 const EffectKey effectKeys[], 446 const EffectKey effectKeys[],
465 int effectCnt, 447 int effectCnt,
466 SkString* inOutFSColor, 448 GrGLSLExpr<4>* inOutFSColor) SK_OVERRIDE;
467 GrSLConstantVec* fsInOutColorKnownValue) SK_OVERRIDE;
468 449
469 private: 450 private:
470 int fNumTexCoordSets; 451 int fNumTexCoordSets;
471 452
472 typedef GrGLShaderBuilder INHERITED; 453 typedef GrGLShaderBuilder INHERITED;
473 }; 454 };
474 455
475 #endif 456 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLSL_impl.h ('k') | src/gpu/gl/GrGLShaderBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698