remove one place we read from gpu key in effects

BUG=skia:

Review URL: https://codereview.chromium.org/761643002
This commit is contained in:
joshualitt 2014-11-25 14:21:55 -08:00 committed by Commit bot
parent f3ca41c723
commit 60030bc2e1
7 changed files with 46 additions and 62 deletions

View File

@ -957,15 +957,15 @@ GrGLGradientEffect::GrGLGradientEffect(const GrBackendProcessorFactory& factory)
GrGLGradientEffect::~GrGLGradientEffect() { }
void GrGLGradientEffect::emitUniforms(GrGLFPBuilder* builder, uint32_t baseKey) {
void GrGLGradientEffect::emitUniforms(GrGLFPBuilder* builder, const GrGradientEffect& ge) {
if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(baseKey)) { // 2 Color case
if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()) { // 2 Color case
fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, "GradientStartColor");
fColorEndUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, "GradientEndColor");
} else if (SkGradientShaderBase::kThree_GpuColorType == ColorTypeFromKey(baseKey)){ // 3 Color Case
} else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { // 3 Color Case
fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, "GradientStartColor");
fColorMidUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
@ -1058,13 +1058,13 @@ uint32_t GrGLGradientEffect::GenBaseGradientKey(const GrProcessor& processor) {
}
void GrGLGradientEffect::emitColor(GrGLFPBuilder* builder,
const GrGradientEffect& ge,
const char* gradientTValue,
uint32_t baseKey,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
if (SkGradientShaderBase::kTwo_GpuColorType == ColorTypeFromKey(baseKey)){
if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){
fsBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1.0));\n",
builder->getUniformVariable(fColorStartUni).c_str(),
builder->getUniformVariable(fColorEndUni).c_str(),
@ -1074,13 +1074,13 @@ void GrGLGradientEffect::emitColor(GrGLFPBuilder* builder,
// The gradient SkShader reporting opaque is more restrictive than necessary in the two pt
// case. Make sure the key reflects this optimization (and note that it can use the same
// shader as thekBeforeIterp case). This same optimization applies to the 3 color case below.
if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(baseKey)) {
if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) {
fsBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
}
fsBuilder->codeAppendf("\t%s = %s;\n", outputColor,
(GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
} else if (SkGradientShaderBase::kThree_GpuColorType == ColorTypeFromKey(baseKey)){
} else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) {
fsBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n",
gradientTValue);
fsBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n",
@ -1098,7 +1098,7 @@ void GrGLGradientEffect::emitColor(GrGLFPBuilder* builder,
}
fsBuilder->codeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s;\n",
builder->getUniformVariable(fColorEndUni).c_str());
if (GrGradientEffect::kAfterInterp_PremulType == PremulTypeFromKey(baseKey)) {
if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) {
fsBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
}

View File

@ -417,15 +417,15 @@ protected:
// Emits the uniform used as the y-coord to texture samples in derived classes. Subclasses
// should call this method from their emitCode().
void emitUniforms(GrGLFPBuilder* builder, uint32_t baseKey);
void emitUniforms(GrGLFPBuilder* builder, const GrGradientEffect&);
// emit code that gets a fragment's color from an expression for t; Has branches for 3 separate
// control flows inside -- 2 color gradients, 3 color symmetric gradients (both using
// native GLSL mix), and 4+ color gradients that use the traditional texture lookup.
void emitColor(GrGLFPBuilder* builder,
const GrGradientEffect&,
const char* gradientTValue,
uint32_t baseKey,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers);
@ -447,22 +447,6 @@ private:
};
GR_STATIC_ASSERT(kBaseKeyBitCnt <= 32);
static SkGradientShaderBase::GpuColorType ColorTypeFromKey(uint32_t baseKey){
if (kTwoColorKey == (baseKey & kColorKeyMask)) {
return SkGradientShaderBase::kTwo_GpuColorType;
} else if (kThreeColorKey == (baseKey & kColorKeyMask)) {
return SkGradientShaderBase::kThree_GpuColorType;
} else {return SkGradientShaderBase::kTexture_GpuColorType;}
}
static GrGradientEffect::PremulType PremulTypeFromKey(uint32_t baseKey){
if (kPremulBeforeInterpKey == (baseKey & kPremulTypeMask)) {
return GrGradientEffect::kBeforeInterp_PremulType;
} else {
return GrGradientEffect::kAfterInterp_PremulType;
}
}
SkScalar fCachedYCoord;
GrGLProgramDataManager::UniformHandle fFSYUni;
GrGLProgramDataManager::UniformHandle fColorStartUni;

View File

@ -551,17 +551,17 @@ GrFragmentProcessor* GrLinearGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLLinearGradient::emitCode(GrGLFPBuilder* builder,
const GrFragmentProcessor&,
const GrFragmentProcessor& fp,
const GrProcessorKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
uint32_t baseKey = key.get32(0);
this->emitUniforms(builder, baseKey);
const GrGradientEffect& ge = fp.cast<GrGradientEffect>();
this->emitUniforms(builder, ge);
SkString t = builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0);
t.append(".x");
this->emitColor(builder, t.c_str(), baseKey, outputColor, inputColor, samplers);
this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers);
}
/////////////////////////////////////////////////////////////////////

View File

@ -560,18 +560,18 @@ GrFragmentProcessor* GrRadialGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLRadialGradient::emitCode(GrGLFPBuilder* builder,
const GrFragmentProcessor&,
const GrFragmentProcessor& fp,
const GrProcessorKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
uint32_t baseKey = key.get32(0);
this->emitUniforms(builder, baseKey);
const GrGradientEffect& ge = fp.cast<GrGradientEffect>();
this->emitUniforms(builder, ge);
SkString t("length(");
t.append(builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0));
t.append(")");
this->emitColor(builder, t.c_str(), baseKey, outputColor, inputColor, samplers);
this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers);
}
/////////////////////////////////////////////////////////////////////

View File

@ -267,14 +267,14 @@ GrFragmentProcessor* GrSweepGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLSweepGradient::emitCode(GrGLFPBuilder* builder,
const GrFragmentProcessor&,
const GrFragmentProcessor& fp,
const GrProcessorKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
uint32_t baseKey = key.get32(0);
this->emitUniforms(builder, baseKey);
const GrGradientEffect& ge = fp.cast<GrGradientEffect>();
this->emitUniforms(builder, ge);
SkString coords2D = builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0);
const GrGLContextInfo ctxInfo = builder->ctxInfo();
SkString t;
@ -288,7 +288,7 @@ void GrGLSweepGradient::emitCode(GrGLFPBuilder* builder,
t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5",
coords2D.c_str(), coords2D.c_str());
}
this->emitColor(builder, t.c_str(), baseKey, outputColor, inputColor, samplers);
this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers);
}
/////////////////////////////////////////////////////////////////////

View File

@ -224,14 +224,14 @@ GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrBackendProcessorFactory&
, fCachedDiffRadius(-SK_ScalarMax) {}
void GLEdge2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
const GrFragmentProcessor&,
const GrFragmentProcessor& fp,
const GrProcessorKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
uint32_t baseKey = key.get32(0);
this->emitUniforms(builder, baseKey);
const GrGradientEffect& ge = fp.cast<GrGradientEffect>();
this->emitUniforms(builder, ge);
fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, "Conical2FSParams", 3);
@ -277,7 +277,7 @@ void GLEdge2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
fsBuilder->codeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
p2.c_str(), p0.c_str());
fsBuilder->codeAppend("\t");
this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, samplers);
this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, samplers);
fsBuilder->codeAppend("\t}\n");
}
@ -505,14 +505,14 @@ GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrBackendPr
}
void GLFocalOutside2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
const GrFragmentProcessor&,
const GrFragmentProcessor& fp,
const GrProcessorKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
uint32_t baseKey = key.get32(0);
this->emitUniforms(builder, baseKey);
const GrGradientEffect& ge = fp.cast<GrGradientEffect>();
this->emitUniforms(builder, ge);
fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, "Conical2FSParams", 2);
SkString tName("t");
@ -549,7 +549,7 @@ void GLFocalOutside2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
fsBuilder->codeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str());
fsBuilder->codeAppend("\t\t");
this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, samplers);
this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, samplers);
fsBuilder->codeAppend("\t}\n");
}
@ -711,14 +711,14 @@ GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrBackendProc
, fCachedFocal(SK_ScalarMax) {}
void GLFocalInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
const GrFragmentProcessor&,
const GrFragmentProcessor& fp,
const GrProcessorKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
uint32_t baseKey = key.get32(0);
this->emitUniforms(builder, baseKey);
const GrGradientEffect& ge = fp.cast<GrGradientEffect>();
this->emitUniforms(builder, ge);
fFocalUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, "Conical2FSParams");
SkString tName("t");
@ -736,7 +736,7 @@ void GLFocalInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_str(),
coords2D, focal.c_str(), coords2D);
this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, samplers);
this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, samplers);
}
void GLFocalInside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman,
@ -964,14 +964,14 @@ GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrBackendPr
, fCachedC(SK_ScalarMax) {}
void GLCircleInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
const GrFragmentProcessor&,
const GrFragmentProcessor& fp,
const GrProcessorKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
uint32_t baseKey = key.get32(0);
this->emitUniforms(builder, baseKey);
const GrGradientEffect& ge = fp.cast<GrGradientEffect>();
this->emitUniforms(builder, ge);
fCenterUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, "Conical2FSCenter");
fParamUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
@ -1003,7 +1003,7 @@ void GLCircleInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
fsBuilder->codeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\n",
tName.c_str(), params.c_str(), params.c_str());
this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, samplers);
this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, samplers);
}
void GLCircleInside2PtConicalEffect::setData(const GrGLProgramDataManager& pdman,
@ -1204,14 +1204,14 @@ GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrBackend
}
void GLCircleOutside2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
const GrFragmentProcessor&,
const GrFragmentProcessor& fp,
const GrProcessorKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
uint32_t baseKey = key.get32(0);
this->emitUniforms(builder, baseKey);
const GrGradientEffect& ge = fp.cast<GrGradientEffect>();
this->emitUniforms(builder, ge);
fCenterUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, "Conical2FSCenter");
fParamUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
@ -1258,7 +1258,7 @@ void GLCircleOutside2PtConicalEffect::emitCode(GrGLFPBuilder* builder,
fsBuilder->codeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str(), params.c_str());
fsBuilder->codeAppend("\t\t");
this->emitColor(builder, tName.c_str(), baseKey, outputColor, inputColor, samplers);
this->emitColor(builder, ge, tName.c_str(), outputColor, inputColor, samplers);
fsBuilder->codeAppend("\t}\n");
}

View File

@ -568,14 +568,14 @@ GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendProcessorFactory& factor
}
void GrGLRadial2Gradient::emitCode(GrGLFPBuilder* builder,
const GrFragmentProcessor&,
const GrFragmentProcessor& fp,
const GrProcessorKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
uint32_t baseKey = key.get32(0);
this->emitUniforms(builder, baseKey);
const GrGradientEffect& ge = fp.cast<GrGradientEffect>();
this->emitUniforms(builder, ge);
fParamUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, "Radial2FSParams", 6);
@ -638,7 +638,7 @@ void GrGLRadial2Gradient::emitCode(GrGLFPBuilder* builder,
t.printf("-%s / %s", cName.c_str(), bVar.c_str());
}
this->emitColor(builder, t.c_str(), baseKey, outputColor, inputColor, samplers);
this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers);
}
void GrGLRadial2Gradient::setData(const GrGLProgramDataManager& pdman,