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

Unified Diff: src/gpu/gl/GrGLShaderBuilder.cpp

Issue 25048002: Express (GLSL expression, possibly known value) pairs as a class (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
« src/gpu/gl/GrGLSL.h ('K') | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/GrGLShaderBuilder.cpp
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index 00fefe1305a675bddd8ed146fb03cf937b180967..91e3d679afaf1e42ce56c513a4122f6c466fea72 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -99,8 +99,6 @@ GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu,
, fFSOutputs(kMaxFSOutputs)
, fUniforms(kVarsPerBlock)
, fSetupFragPosition(false)
- , fKnownColorValue(GrGLProgramDesc::KnownColorInputValue(desc.getHeader().fColorInput))
- , fKnownCoverageValue(GrGLProgramDesc::KnownColorInputValue(desc.getHeader().fCoverageInput))
, fHasCustomColorOutput(false)
, fHasSecondaryOutput(false)
, fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == desc.getHeader().fFragPosKey) {
@@ -152,6 +150,10 @@ GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu,
fColorUniform = this->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType, "Color", &name);
fInputColor = name;
+ } else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fColorInput) {
+ fInputColor = GrGLSLExpr<4>(1);
+ } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fColorInput) {
+ fInputColor = GrGLSLExpr<4>(0);
}
if (GrGLProgramDesc::kUniform_ColorInput == header.fCoverageInput) {
@@ -159,6 +161,10 @@ GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu,
fCoverageUniform = this->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType, "Coverage", &name);
fInputCoverage = name;
+ } else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fCoverageInput) {
+ fInputCoverage = GrGLSLExpr<4>(1);
+ } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fCoverageInput) {
+ fInputCoverage = GrGLSLExpr<4>(0);
}
if (k110_GrGLSLGeneration != fGpu->glslGeneration()) {
@@ -289,7 +295,7 @@ void GrGLShaderBuilder::fsAppendTextureLookupAndModulate(
GrSLType varyingType) {
SkString lookup;
this->appendTextureLookup(&lookup, sampler, coordName, varyingType);
- GrGLSLModulatef<4>(&fFSCode, modulation, lookup.c_str());
+ fFSCode.append((GrGLSLExpr<4>(modulation) * GrGLSLExpr<4>(lookup)).c_str());
}
GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture* dstCopy,
@@ -509,12 +515,11 @@ void GrGLShaderBuilder::createAndEmitEffects(GrGLProgramEffectsBuilder* programE
const GrEffectStage* effectStages[],
const EffectKey effectKeys[],
int effectCnt,
- SkString* fsInOutColor,
- GrSLConstantVec* fsInOutColorKnownValue) {
+ GrGLSLExpr<4>* fsInOutColor) {
bool effectEmitted = false;
- SkString inColor = *fsInOutColor;
- SkString outColor;
+ GrGLSLExpr<4> inColor = *fsInOutColor;
+ GrGLSLExpr<4> outColor;
for (int e = 0; e < effectCnt; ++e) {
SkASSERT(NULL != effectStages[e] && NULL != effectStages[e]->getEffect());
@@ -522,24 +527,29 @@ void GrGLShaderBuilder::createAndEmitEffects(GrGLProgramEffectsBuilder* programE
CodeStage::AutoStageRestore csar(&fCodeStage, &stage);
- if (kZeros_GrSLConstantVec == *fsInOutColorKnownValue) {
+ if (inColor.isZeros()) {
+ SkString inColorName;
+
// Effects have no way to communicate zeros, they treat an empty string as ones.
- this->nameVariable(&inColor, '\0', "input");
- this->fsCodeAppendf("\tvec4 %s = %s;\n", inColor.c_str(), GrGLSLZerosVecf(4));
+ this->nameVariable(&inColorName, '\0', "input");
+ this->fsCodeAppendf("\tvec4 %s = %s;\n", inColorName.c_str(), inColor.c_str());
+ inColor = inColorName;
}
// create var to hold stage result
- this->nameVariable(&outColor, '\0', "output");
- this->fsCodeAppendf("\tvec4 %s;\n", outColor.c_str());
+ SkString outColorName;
+ this->nameVariable(&outColorName, '\0', "output");
+ this->fsCodeAppendf("\tvec4 %s;\n", outColorName.c_str());
+ outColor = outColorName;
+
programEffectsBuilder->emitEffect(stage,
effectKeys[e],
outColor.c_str(),
- inColor.isEmpty() ? NULL : inColor.c_str(),
+ inColor.isOnes() ? NULL : inColor.c_str(),
fCodeStage.stageIndex());
inColor = outColor;
- *fsInOutColorKnownValue = kNone_GrSLConstantVec;
effectEmitted = true;
}
@@ -829,16 +839,14 @@ GrGLProgramEffects* GrGLFullShaderBuilder::createAndEmitEffects(
const GrEffectStage* effectStages[],
const EffectKey effectKeys[],
int effectCnt,
- SkString* inOutFSColor,
- GrSLConstantVec* fsInOutColorKnownValue) {
+ GrGLSLExpr<4>* inOutFSColor) {
GrGLVertexProgramEffectsBuilder programEffectsBuilder(this, effectCnt);
this->INHERITED::createAndEmitEffects(&programEffectsBuilder,
effectStages,
effectKeys,
effectCnt,
- inOutFSColor,
- fsInOutColorKnownValue);
+ inOutFSColor);
return programEffectsBuilder.finish();
}
@@ -939,15 +947,13 @@ GrGLProgramEffects* GrGLFragmentOnlyShaderBuilder::createAndEmitEffects(
const GrEffectStage* effectStages[],
const EffectKey effectKeys[],
int effectCnt,
- SkString* inOutFSColor,
- GrSLConstantVec* fsInOutColorKnownValue) {
+ GrGLSLExpr<4>* inOutFSColor) {
GrGLTexGenProgramEffectsBuilder texGenEffectsBuilder(this, effectCnt);
this->INHERITED::createAndEmitEffects(&texGenEffectsBuilder,
effectStages,
effectKeys,
effectCnt,
- inOutFSColor,
- fsInOutColorKnownValue);
+ inOutFSColor);
return texGenEffectsBuilder.finish();
}
« src/gpu/gl/GrGLSL.h ('K') | « src/gpu/gl/GrGLShaderBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698