aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-07 17:06:57 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-03-07 17:06:57 +0000
commitf910d3b23bcf590ee937628dbab8e39a98ee5860 (patch)
treef7c0ac02776334b23bf2765d1885dcd45ba398c0 /src/effects
parent327b9b205a4f11d91778c7083f0117d86fb7e780 (diff)
Make GrGLEffects use an interface to append their code.
A small step towards encapsulating GrGLShaderBuilder. Review URL: https://codereview.chromium.org/12547012 git-svn-id: http://skia.googlecode.com/svn/trunk@8018 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/SkBicubicImageFilter.cpp17
-rw-r--r--src/effects/SkBlendImageFilter.cpp35
-rw-r--r--src/effects/SkColorMatrixFilter.cpp14
-rw-r--r--src/effects/SkDisplacementMapEffect.cpp45
-rw-r--r--src/effects/SkLightingImageFilter.cpp60
-rw-r--r--src/effects/SkMagnifierImageFilter.cpp60
-rw-r--r--src/effects/SkMatrixConvolutionImageFilter.cpp45
-rw-r--r--src/effects/SkMorphologyImageFilter.cpp24
-rw-r--r--src/effects/SkTableColorFilter.cpp43
-rw-r--r--src/effects/gradients/SkGradientShader.cpp16
-rw-r--r--src/effects/gradients/SkTwoPointConicalGradient.cpp86
-rw-r--r--src/effects/gradients/SkTwoPointRadialGradient.cpp34
12 files changed, 241 insertions, 238 deletions
diff --git a/src/effects/SkBicubicImageFilter.cpp b/src/effects/SkBicubicImageFilter.cpp
index 992060c642..8de68aee11 100644
--- a/src/effects/SkBicubicImageFilter.cpp
+++ b/src/effects/SkBicubicImageFilter.cpp
@@ -226,7 +226,6 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
kMat44f_GrSLType, "Coefficients");
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType, "ImageIncrement");
- SkString* code = &builder->fFSCode;
const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
const char* coeff = builder->getUniformCStr(fCoefficientsUni);
@@ -250,19 +249,21 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
"\tvec4 c = coefficients * ts;\n"
"\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;\n",
&cubicBlendName);
- code->appendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords, imgInc);
- code->appendf("\tvec2 f = fract(coord / %s);\n", imgInc);
+ builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords, imgInc);
+ builder->fsCodeAppendf("\tvec2 f = fract(coord / %s);\n", imgInc);
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
SkString coord;
coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1);
- code->appendf("\tvec4 s%d%d = ", x, y);
- builder->appendTextureLookup(&builder->fFSCode, samplers[0], coord.c_str());
- code->appendf(";\n");
+ builder->fsCodeAppendf("\tvec4 s%d%d = ", x, y);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
+ samplers[0],
+ coord.c_str());
+ builder->fsCodeAppend(";\n");
}
- code->appendf("\tvec4 s%d = %s(%s, f.x, s0%d, s1%d, s2%d, s3%d);\n", y, cubicBlendName.c_str(), coeff, y, y, y, y);
+ builder->fsCodeAppendf("\tvec4 s%d = %s(%s, f.x, s0%d, s1%d, s2%d, s3%d);\n", y, cubicBlendName.c_str(), coeff, y, y, y, y);
}
- code->appendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor, cubicBlendName.c_str(), coeff);
+ builder->fsCodeAppendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor, cubicBlendName.c_str(), coeff);
}
GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
diff --git a/src/effects/SkBlendImageFilter.cpp b/src/effects/SkBlendImageFilter.cpp
index c8c4c1bbf2..ae129eb08e 100644
--- a/src/effects/SkBlendImageFilter.cpp
+++ b/src/effects/SkBlendImageFilter.cpp
@@ -246,34 +246,39 @@ void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder,
GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(
builder, key, vertexCoords, &bgCoords, NULL, "BG");
- SkString* code = &builder->fFSCode;
const char* bgColor = "bgColor";
const char* fgColor = "fgColor";
- code->appendf("\t\tvec4 %s = ", fgColor);
- builder->appendTextureLookup(code, samplers[0], fgCoords, fgCoordsType);
- code->append(";\n");
-
- code->appendf("\t\tvec4 %s = ", bgColor);
- builder->appendTextureLookup(code, samplers[1], bgCoords, bgCoordsType);
- code->append(";\n");
-
- code->appendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.b);\n", outputColor, bgColor, fgColor);
+ builder->fsCodeAppendf("\t\tvec4 %s = ", fgColor);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
+ samplers[0],
+ fgCoords,
+ fgCoordsType);
+ builder->fsCodeAppend(";\n");
+
+ builder->fsCodeAppendf("\t\tvec4 %s = ", bgColor);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
+ samplers[1],
+ bgCoords,
+ bgCoordsType);
+ builder->fsCodeAppendf(";\n");
+
+ builder->fsCodeAppendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.b);\n", outputColor, bgColor, fgColor);
switch (fMode) {
case SkBlendImageFilter::kNormal_Mode:
- code->appendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + %s.rgb;\n", outputColor, fgColor, bgColor, fgColor);
+ builder->fsCodeAppendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + %s.rgb;\n", outputColor, fgColor, bgColor, fgColor);
break;
case SkBlendImageFilter::kMultiply_Mode:
- code->appendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + (1.0 - %s.a) * %s.rgb + %s.rgb * %s.rgb;\n", outputColor, fgColor, bgColor, bgColor, fgColor, fgColor, bgColor);
+ builder->fsCodeAppendf("\t\t%s.rgb = (1.0 - %s.a) * %s.rgb + (1.0 - %s.a) * %s.rgb + %s.rgb * %s.rgb;\n", outputColor, fgColor, bgColor, bgColor, fgColor, fgColor, bgColor);
break;
case SkBlendImageFilter::kScreen_Mode:
- code->appendf("\t\t%s.rgb = %s.rgb + %s.rgb - %s.rgb * %s.rgb;\n", outputColor, bgColor, fgColor, fgColor, bgColor);
+ builder->fsCodeAppendf("\t\t%s.rgb = %s.rgb + %s.rgb - %s.rgb * %s.rgb;\n", outputColor, bgColor, fgColor, fgColor, bgColor);
break;
case SkBlendImageFilter::kDarken_Mode:
- code->appendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bgColor, fgColor, bgColor);
+ builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bgColor, fgColor, bgColor);
break;
case SkBlendImageFilter::kLighten_Mode:
- code->appendf("\t\t%s.rgb = max((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bgColor, fgColor, bgColor);
+ builder->fsCodeAppendf("\t\t%s.rgb = max((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bgColor, fgColor, bgColor);
break;
}
}
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index 73e96167ce..b39c5f863f 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -414,13 +414,13 @@ public:
}
// The max() is to guard against 0 / 0 during unpremul when the incoming color is
// transparent black.
- builder->fFSCode.appendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n", inputColor);
- builder->fFSCode.appendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha) + %s;\n",
- outputColor,
- builder->getUniformCStr(fMatrixHandle),
- inputColor,
- builder->getUniformCStr(fVectorHandle));
- builder->fFSCode.appendf("\t%s.rgb *= %s.a;\n", outputColor, outputColor);
+ builder->fsCodeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n", inputColor);
+ builder->fsCodeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha) + %s;\n",
+ outputColor,
+ builder->getUniformCStr(fMatrixHandle),
+ inputColor,
+ builder->getUniformCStr(fVectorHandle));
+ builder->fsCodeAppendf("\t%s.rgb *= %s.a;\n", outputColor, outputColor);
}
virtual void setData(const GrGLUniformManager& uniManager,
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index ee0906c67d..b270501d4b 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -409,36 +409,38 @@ void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
GrSLType cCoordsType = fColorEffectMatrix.emitCode(
builder, key, vertexCoords, &cCoordsIn, NULL, "COLOR");
- SkString* code = &builder->fFSCode;
const char* dColor = "dColor";
const char* cCoords = "cCoords";
const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half float, use
// a number smaller than that to approximate 0, but
// leave room for 32-bit float GPU rounding errors.
- code->appendf("\t\tvec4 %s = ", dColor);
- builder->appendTextureLookup(code, samplers[0], dCoordsIn, dCoordsType);
- code->append(";\n");
+ builder->fsCodeAppendf("\t\tvec4 %s = ", dColor);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
+ samplers[0],
+ dCoordsIn,
+ dCoordsType);
+ builder->fsCodeAppend(";\n");
// Unpremultiply the displacement
- code->appendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
- dColor, dColor, nearZero, dColor, dColor);
+ builder->fsCodeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
+ dColor, dColor, nearZero, dColor, dColor);
- code->appendf("\t\tvec2 %s = %s + %s*(%s.",
- cCoords, cCoordsIn, scaleUni, dColor);
+ builder->fsCodeAppendf("\t\tvec2 %s = %s + %s*(%s.",
+ cCoords, cCoordsIn, scaleUni, dColor);
switch (fXChannelSelector) {
case SkDisplacementMapEffect::kR_ChannelSelectorType:
- code->append("r");
+ builder->fsCodeAppend("r");
break;
case SkDisplacementMapEffect::kG_ChannelSelectorType:
- code->append("g");
+ builder->fsCodeAppend("g");
break;
case SkDisplacementMapEffect::kB_ChannelSelectorType:
- code->append("b");
+ builder->fsCodeAppend("b");
break;
case SkDisplacementMapEffect::kA_ChannelSelectorType:
- code->append("a");
+ builder->fsCodeAppend("a");
break;
case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
default:
@@ -447,30 +449,33 @@ void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
switch (fYChannelSelector) {
case SkDisplacementMapEffect::kR_ChannelSelectorType:
- code->append("r");
+ builder->fsCodeAppend("r");
break;
case SkDisplacementMapEffect::kG_ChannelSelectorType:
- code->append("g");
+ builder->fsCodeAppend("g");
break;
case SkDisplacementMapEffect::kB_ChannelSelectorType:
- code->append("b");
+ builder->fsCodeAppend("b");
break;
case SkDisplacementMapEffect::kA_ChannelSelectorType:
- code->append("a");
+ builder->fsCodeAppend("a");
break;
case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
default:
SkASSERT(!"Unknown Y channel selector");
}
- code->append("-vec2(0.5));\t\t");
+ builder->fsCodeAppend("-vec2(0.5));\t\t");
// FIXME : This can be achieved with a "clamp to border" texture repeat mode and
// a 0 border color instead of computing if cCoords is out of bounds here.
- code->appendf(
+ builder->fsCodeAppendf(
"%s = any(greaterThan(vec4(vec2(0.0), %s), vec4(%s, vec2(1.0)))) ? vec4(0.0) : ",
outputColor, cCoords, cCoords);
- builder->appendTextureLookup(code, samplers[1], cCoords, cCoordsType);
- code->append(";\n");
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
+ samplers[1],
+ cCoords,
+ cCoordsType);
+ builder->fsCodeAppend(";\n");
}
void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index e1952628ab..177ba09c8e 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -415,7 +415,7 @@ public:
* the FS. The default of emitLightColor appends the name of the constant light color uniform
* and so this function only needs to be overridden if the light color varies spatially.
*/
- virtual void emitSurfaceToLight(GrGLShaderBuilder*, SkString* out, const char* z) = 0;
+ virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) = 0;
virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight);
// This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLight must call
@@ -441,7 +441,7 @@ class GrGLDistantLight : public GrGLLight {
public:
virtual ~GrGLDistantLight() {}
virtual void setData(const GrGLUniformManager&, const SkLight* light) const SK_OVERRIDE;
- virtual void emitSurfaceToLight(GrGLShaderBuilder*, SkString* out, const char* z) SK_OVERRIDE;
+ virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRIDE;
private:
typedef GrGLLight INHERITED;
UniformHandle fDirectionUni;
@@ -453,7 +453,7 @@ class GrGLPointLight : public GrGLLight {
public:
virtual ~GrGLPointLight() {}
virtual void setData(const GrGLUniformManager&, const SkLight* light) const SK_OVERRIDE;
- virtual void emitSurfaceToLight(GrGLShaderBuilder*, SkString* out, const char* z) SK_OVERRIDE;
+ virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRIDE;
private:
typedef GrGLLight INHERITED;
SkPoint3 fLocation;
@@ -466,7 +466,7 @@ class GrGLSpotLight : public GrGLLight {
public:
virtual ~GrGLSpotLight() {}
virtual void setData(const GrGLUniformManager&, const SkLight* light) const SK_OVERRIDE;
- virtual void emitSurfaceToLight(GrGLShaderBuilder*, SkString* out, const char* z) SK_OVERRIDE;
+ virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRIDE;
virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight) SK_OVERRIDE;
private:
typedef GrGLLight INHERITED;
@@ -1122,7 +1122,6 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
kFloat_GrSLType,
"SurfaceScale");
fLight->emitLightColorUniform(builder);
- SkString* code = &builder->fFSCode;
SkString lightFunc;
this->emitLightFunc(builder, &lightFunc);
static const GrGLShaderVar gSobelArgs[] = {
@@ -1176,8 +1175,8 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
interiorNormalBody.c_str(),
&interiorNormalName);
- code->appendf("\t\tvec2 coord = %s;\n", coords);
- code->appendf("\t\tfloat m[9];\n");
+ builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords);
+ builder->fsCodeAppend("\t\tfloat m[9];\n");
const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
const char* surfScale = builder->getUniformCStr(fSurfaceScaleUni);
@@ -1187,21 +1186,25 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
for (int dx = -1; dx <= 1; dx++) {
SkString texCoords;
texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc);
- code->appendf("\t\tm[%d] = ", index++);
- builder->appendTextureLookup(code, samplers[0], texCoords.c_str());
- code->appendf(".a;\n");
+ builder->fsCodeAppendf("\t\tm[%d] = ", index++);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
+ samplers[0],
+ texCoords.c_str());
+ builder->fsCodeAppend(".a;\n");
}
}
- code->appendf("\t\tvec3 surfaceToLight = ");
+ builder->fsCodeAppend("\t\tvec3 surfaceToLight = ");
SkString arg;
arg.appendf("%s * m[4]", surfScale);
- fLight->emitSurfaceToLight(builder, code, arg.c_str());
- code->append(";\n");
- code->appendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
- outputColor, lightFunc.c_str(), interiorNormalName.c_str(), surfScale);
+ fLight->emitSurfaceToLight(builder, arg.c_str());
+ builder->fsCodeAppend(";\n");
+ builder->fsCodeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
+ outputColor, lightFunc.c_str(), interiorNormalName.c_str(), surfScale);
fLight->emitLightColor(builder, "surfaceToLight");
- code->append(");\n");
- GrGLSLMulVarBy4f(code, 2, outputColor, inputColor);
+ builder->fsCodeAppend(");\n");
+ SkString modulate;
+ GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor);
+ builder->fsCodeAppend(modulate.c_str());
}
GrGLEffect::EffectKey GrGLLightingEffect::GenKey(const GrEffectStage& s,
@@ -1354,7 +1357,7 @@ void GrGLLight::emitLightColorUniform(GrGLShaderBuilder* builder) {
void GrGLLight::emitLightColor(GrGLShaderBuilder* builder,
const char *surfaceToLight) {
- builder->fFSCode.append(builder->getUniformCStr(this->lightColorUni()));
+ builder->fsCodeAppend(builder->getUniformCStr(this->lightColorUni()));
}
void GrGLLight::setData(const GrGLUniformManager& uman,
@@ -1371,13 +1374,11 @@ void GrGLDistantLight::setData(const GrGLUniformManager& uman, const SkLight* li
setUniformNormal3(uman, fDirectionUni, distantLight->direction());
}
-void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder,
- SkString* out,
- const char* z) {
+void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z) {
const char* dir;
fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType,
"LightDirection", &dir);
- out->append(dir);
+ builder->fsCodeAppend(dir);
}
///////////////////////////////////////////////////////////////////////////////
@@ -1390,13 +1391,11 @@ void GrGLPointLight::setData(const GrGLUniformManager& uman,
setUniformPoint3(uman, fLocationUni, pointLight->location());
}
-void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder,
- SkString* out,
- const char* z) {
+void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z) {
const char* loc;
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType,
"LightLocation", &loc);
- out->appendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->fragmentPosition(), z);
+ builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->fragmentPosition(), z);
}
///////////////////////////////////////////////////////////////////////////////
@@ -1414,13 +1413,12 @@ void GrGLSpotLight::setData(const GrGLUniformManager& uman,
setUniformNormal3(uman, fSUni, spotLight->s());
}
-void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder,
- SkString* out,
- const char* z) {
+void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z) {
const char* location;
fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType, "LightLocation", &location);
- out->appendf("normalize(%s - vec3(%s.xy, %s))", location, builder->fragmentPosition(), z);
+ builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))",
+ location, builder->fragmentPosition(), z);
}
void GrGLSpotLight::emitLightColor(GrGLShaderBuilder* builder,
@@ -1466,7 +1464,7 @@ void GrGLSpotLight::emitLightColor(GrGLShaderBuilder* builder,
lightColorBody.c_str(),
&fLightColorFunc);
- builder->fFSCode.appendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
+ builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
}
#endif
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index b577a1d8fe..d8455ad2fd 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -148,36 +148,36 @@ void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
GrGLShaderBuilder::kVertex_ShaderType,
kVec2f_GrSLType, "uInset");
- SkString* code = &builder->fFSCode;
-
- code->appendf("\t\tvec2 coord = %s;\n", coords);
- code->appendf("\t\tvec2 zoom_coord = %s + %s / %s;\n",
- builder->getUniformCStr(fOffsetVar),
- coords,
- builder->getUniformCStr(fZoomVar));
-
- code->appendf("\t\tvec2 delta = min(coord, vec2(1.0, 1.0) - coord);\n");
-
- code->appendf("\t\tdelta = delta / %s;\n", builder->getUniformCStr(fInsetVar));
-
- code->appendf("\t\tfloat weight = 0.0;\n");
- code->appendf("\t\tif (delta.s < 2.0 && delta.t < 2.0) {\n");
- code->appendf("\t\t\tdelta = vec2(2.0, 2.0) - delta;\n");
- code->appendf("\t\t\tfloat dist = length(delta);\n");
- code->appendf("\t\t\tdist = max(2.0 - dist, 0.0);\n");
- code->appendf("\t\t\tweight = min(dist * dist, 1.0);\n");
- code->appendf("\t\t} else {\n");
- code->appendf("\t\t\tvec2 delta_squared = delta * delta;\n");
- code->appendf("\t\t\tweight = min(min(delta_squared.s, delta_squared.y), 1.0);\n");
- code->appendf("\t\t}\n");
-
- code->appendf("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\n");
- code->appendf("\t\tvec4 output_color = ");
- builder->appendTextureLookup(code, samplers[0], "mix_coord");
- code->append(";\n");
-
- code->appendf("\t\t%s = output_color;", outputColor);
- GrGLSLMulVarBy4f(code, 2, outputColor, inputColor);
+ builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords);
+ builder->fsCodeAppendf("\t\tvec2 zoom_coord = %s + %s / %s;\n",
+ builder->getUniformCStr(fOffsetVar),
+ coords,
+ builder->getUniformCStr(fZoomVar));
+
+ builder->fsCodeAppend("\t\tvec2 delta = min(coord, vec2(1.0, 1.0) - coord);\n");
+
+ builder->fsCodeAppendf("\t\tdelta = delta / %s;\n", builder->getUniformCStr(fInsetVar));
+
+ builder->fsCodeAppend("\t\tfloat weight = 0.0;\n");
+ builder->fsCodeAppend("\t\tif (delta.s < 2.0 && delta.t < 2.0) {\n");
+ builder->fsCodeAppend("\t\t\tdelta = vec2(2.0, 2.0) - delta;\n");
+ builder->fsCodeAppend("\t\t\tfloat dist = length(delta);\n");
+ builder->fsCodeAppend("\t\t\tdist = max(2.0 - dist, 0.0);\n");
+ builder->fsCodeAppend("\t\t\tweight = min(dist * dist, 1.0);\n");
+ builder->fsCodeAppend("\t\t} else {\n");
+ builder->fsCodeAppend("\t\t\tvec2 delta_squared = delta * delta;\n");
+ builder->fsCodeAppend("\t\t\tweight = min(min(delta_squared.s, delta_squared.y), 1.0);\n");
+ builder->fsCodeAppend("\t\t}\n");
+
+ builder->fsCodeAppend("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\n");
+ builder->fsCodeAppend("\t\tvec4 output_color = ");
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "mix_coord");
+ builder->fsCodeAppend(";\n");
+
+ builder->fsCodeAppendf("\t\t%s = output_color;", outputColor);
+ SkString modulate;
+ GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor);
+ builder->fsCodeAppend(modulate.c_str());
}
void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman,
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index 0addc237a5..cda4f28081 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -365,7 +365,6 @@ static void appendTextureLookup(GrGLShaderBuilder* builder,
const GrGLShaderBuilder::TextureSampler& sampler,
const char* coord,
SkMatrixConvolutionImageFilter::TileMode tileMode) {
- SkString* code = &builder->fFSCode;
SkString clampedCoord;
switch (tileMode) {
case SkMatrixConvolutionImageFilter::kClamp_TileMode:
@@ -377,10 +376,10 @@ static void appendTextureLookup(GrGLShaderBuilder* builder,
coord = clampedCoord.c_str();
break;
case SkMatrixConvolutionImageFilter::kClampToBlack_TileMode:
- code->appendf("clamp(%s, 0.0, 1.0) != %s ? vec4(0, 0, 0, 0) : ", coord, coord);
+ builder->fsCodeAppendf("clamp(%s, 0.0, 1.0) != %s ? vec4(0, 0, 0, 0) : ", coord, coord);
break;
}
- builder->appendTextureLookup(code, sampler, coord);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, sampler, coord);
}
void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
@@ -403,8 +402,6 @@ void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
fBiasUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType, "Bias");
- SkString* code = &builder->fFSCode;
-
const char* target = builder->getUniformCStr(fTargetUni);
const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
const char* kernel = builder->getUniformCStr(fKernelUni);
@@ -413,31 +410,31 @@ void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
int kWidth = fKernelSize.width();
int kHeight = fKernelSize.height();
- code->appendf("\t\tvec4 sum = vec4(0, 0, 0, 0);\n");
- code->appendf("\t\tvec2 coord = %s - %s * %s;\n", coords, target, imgInc);
- code->appendf("\t\tfor (int y = 0; y < %d; y++) {\n", kHeight);
- code->appendf("\t\t\tfor (int x = 0; x < %d; x++) {\n", kWidth);
- code->appendf("\t\t\t\tfloat k = %s[y * %d + x];\n", kernel, kWidth);
- code->appendf("\t\t\t\tvec2 coord2 = coord + vec2(x, y) * %s;\n", imgInc);
- code->appendf("\t\t\t\tvec4 c = ");
+ builder->fsCodeAppend("\t\tvec4 sum = vec4(0, 0, 0, 0);\n");
+ builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords, target, imgInc);
+ builder->fsCodeAppendf("\t\tfor (int y = 0; y < %d; y++) {\n", kHeight);
+ builder->fsCodeAppendf("\t\t\tfor (int x = 0; x < %d; x++) {\n", kWidth);
+ builder->fsCodeAppendf("\t\t\t\tfloat k = %s[y * %d + x];\n", kernel, kWidth);
+ builder->fsCodeAppendf("\t\t\t\tvec2 coord2 = coord + vec2(x, y) * %s;\n", imgInc);
+ builder->fsCodeAppend("\t\t\t\tvec4 c = ");
appendTextureLookup(builder, samplers[0], "coord2", fTileMode);
- code->appendf(";\n");
+ builder->fsCodeAppend(";\n");
if (!fConvolveAlpha) {
- code->appendf("\t\t\t\tc.rgb /= c.a;\n");
+ builder->fsCodeAppend("\t\t\t\tc.rgb /= c.a;\n");
}
- code->appendf("\t\t\t\tsum += c * k;\n");
- code->appendf("\t\t\t}\n");
- code->appendf("\t\t}\n");
+ builder->fsCodeAppend("\t\t\t\tsum += c * k;\n");
+ builder->fsCodeAppend("\t\t\t}\n");
+ builder->fsCodeAppend("\t\t}\n");
if (fConvolveAlpha) {
- code->appendf("\t\t%s = sum * %s + %s;\n", outputColor, gain, bias);
- code->appendf("\t\t%s.rgb = clamp(%s.rgb, 0.0, %s.a);\n", outputColor, outputColor, outputColor);
+ builder->fsCodeAppendf("\t\t%s = sum * %s + %s;\n", outputColor, gain, bias);
+ builder->fsCodeAppendf("\t\t%s.rgb = clamp(%s.rgb, 0.0, %s.a);\n", outputColor, outputColor, outputColor);
} else {
- code->appendf("\t\tvec4 c = ");
+ builder->fsCodeAppend("\t\tvec4 c = ");
appendTextureLookup(builder, samplers[0], coords, fTileMode);
- code->appendf(";\n");
- code->appendf("\t\t%s.a = c.a;\n", outputColor);
- code->appendf("\t\t%s.rgb = sum.rgb * %s + %s;\n", outputColor, gain, bias);
- code->appendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor);
+ builder->fsCodeAppend(";\n");
+ builder->fsCodeAppendf("\t\t%s.a = c.a;\n", outputColor);
+ builder->fsCodeAppendf("\t\t%s.rgb = sum.rgb * %s + %s;\n", outputColor, gain, bias);
+ builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor);
}
}
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index b40130bfe0..7bb4c93886 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -324,16 +324,14 @@ void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder,
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType, "ImageIncrement");
- SkString* code = &builder->fFSCode;
-
const char* func;
switch (fType) {
case GrMorphologyEffect::kErode_MorphologyType:
- code->appendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor);
+ builder->fsCodeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", outputColor);
func = "min";
break;
case GrMorphologyEffect::kDilate_MorphologyType:
- code->appendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor);
+ builder->fsCodeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor);
func = "max";
break;
default:
@@ -343,14 +341,16 @@ void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder,
}
const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
- code->appendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords, fRadius, imgInc);
- code->appendf("\t\tfor (int i = 0; i < %d; i++) {\n", this->width());
- code->appendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor);
- builder->appendTextureLookup(&builder->fFSCode, samplers[0], "coord");
- code->appendf(");\n");
- code->appendf("\t\t\tcoord += %s;\n", imgInc);
- code->appendf("\t\t}\n");
- GrGLSLMulVarBy4f(code, 2, outputColor, inputColor);
+ builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords, fRadius, imgInc);
+ builder->fsCodeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", this->width());
+ builder->fsCodeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "coord");
+ builder->fsCodeAppend(");\n");
+ builder->fsCodeAppendf("\t\t\tcoord += %s;\n", imgInc);
+ builder->fsCodeAppend("\t\t}\n");
+ SkString modulate;
+ GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor);
+ builder->fsCodeAppend(modulate.c_str());
}
GrGLEffect::EffectKey GrGLMorphologyEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index cf7ddc5295..16f2876af0 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -289,39 +289,38 @@ void GLColorTableEffect::emitCode(GrGLShaderBuilder* builder,
static const float kColorScaleFactor = 255.0f / 256.0f;
static const float kColorOffsetFactor = 1.0f / 512.0f;
- SkString* code = &builder->fFSCode;
if (NULL == inputColor) {
// the input color is solid white (all ones).
static const float kMaxValue = kColorScaleFactor + kColorOffsetFactor;
- code->appendf("\t\tvec4 coord = vec4(%f, %f, %f, %f);\n",
- kMaxValue, kMaxValue, kMaxValue, kMaxValue);
+ builder->fsCodeAppendf("\t\tvec4 coord = vec4(%f, %f, %f, %f);\n",
+ kMaxValue, kMaxValue, kMaxValue, kMaxValue);
} else {
- code->appendf("\t\tfloat nonZeroAlpha = max(%s.a, .0001);\n", inputColor);
- code->appendf("\t\tvec4 coord = vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha);\n", inputColor);
- code->appendf("\t\tcoord = coord * %f + vec4(%f, %f, %f, %f);\n",
- kColorScaleFactor,
- kColorOffsetFactor, kColorOffsetFactor,
- kColorOffsetFactor, kColorOffsetFactor);
+ builder->fsCodeAppendf("\t\tfloat nonZeroAlpha = max(%s.a, .0001);\n", inputColor);
+ builder->fsCodeAppendf("\t\tvec4 coord = vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha);\n", inputColor);
+ builder->fsCodeAppendf("\t\tcoord = coord * %f + vec4(%f, %f, %f, %f);\n",
+ kColorScaleFactor,
+ kColorOffsetFactor, kColorOffsetFactor,
+ kColorOffsetFactor, kColorOffsetFactor);
}
- code->appendf("\t\t%s.a = ", outputColor);
- builder->appendTextureLookup(code, samplers[0], "vec2(coord.a, 0.125)");
- code->append(";\n");
+ builder->fsCodeAppendf("\t\t%s.a = ", outputColor);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "vec2(coord.a, 0.125)");
+ builder->fsCodeAppend(";\n");
- code->appendf("\t\t%s.r = ", outputColor);
- builder->appendTextureLookup(code, samplers[0], "vec2(coord.r, 0.375)");
- code->append(";\n");
+ builder->fsCodeAppendf("\t\t%s.r = ", outputColor);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "vec2(coord.r, 0.375)");
+ builder->fsCodeAppend(";\n");
- code->appendf("\t\t%s.g = ", outputColor);
- builder->appendTextureLookup(code, samplers[0], "vec2(coord.g, 0.625)");
- code->append(";\n");
+ builder->fsCodeAppendf("\t\t%s.g = ", outputColor);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "vec2(coord.g, 0.625)");
+ builder->fsCodeAppend(";\n");
- code->appendf("\t\t%s.b = ", outputColor);
- builder->appendTextureLookup(code, samplers[0], "vec2(coord.b, 0.875)");
- code->append(";\n");
+ builder->fsCodeAppendf("\t\t%s.b = ", outputColor);
+ builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "vec2(coord.b, 0.875)");
+ builder->fsCodeAppend(";\n");
- code->appendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor);
+ builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor);
}
GrGLEffect::EffectKey GLColorTableEffect::GenKey(const GrEffectStage&, const GrGLCaps&) {
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index 261ad8ff13..1158dcf92a 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -787,13 +787,15 @@ void GrGLGradientEffect::emitColorLookup(GrGLShaderBuilder* builder,
const char* inputColor,
const GrGLShaderBuilder::TextureSampler& sampler) {
- SkString* code = &builder->fFSCode;
- code->appendf("\tvec2 coord = vec2(%s, %s);\n",
- gradientTValue,
- builder->getUniformVariable(fFSYUni).c_str());
- code->appendf("\t%s = ", outputColor);
- builder->appendTextureLookupAndModulate(code, inputColor, sampler, "coord");
- code->append(";\n");
+ builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n",
+ gradientTValue,
+ builder->getUniformVariable(fFSYUni).c_str());
+ builder->fsCodeAppendf("\t%s = ", outputColor);
+ builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
+ inputColor,
+ sampler,
+ "coord");
+ builder->fsCodeAppend(";\n");
}
/////////////////////////////////////////////////////////////////////
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index 1496033941..f56e7b429e 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -513,7 +513,6 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
// VS
{
- SkString* code = &builder->fVSCode;
SkString p2; // distance between centers
SkString p3; // start radius
SkString p5; // difference in radii (r1 - r0)
@@ -525,15 +524,14 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
// part of the quadratic as a varying.
if (kVec2f_GrSLType == coordsVaryingType) {
// r2Var = -2 * (r2Parm[2] * varCoord.x - r2Param[3] * r2Param[5])
- code->appendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n",
- fVSVaryingName, p2.c_str(),
- vsCoordsVarying, p3.c_str(), p5.c_str());
+ builder->vsCodeAppendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n",
+ fVSVaryingName, p2.c_str(),
+ vsCoordsVarying, p3.c_str(), p5.c_str());
}
}
// FS
{
- SkString* code = &builder->fFSCode;
SkString cName("c");
SkString ac4Name("ac4");
@@ -563,92 +561,92 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
bVar = fFSVaryingName;
} else {
bVar = "b";
- code->appendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n",
- bVar.c_str(), p2.c_str(), fsCoords,
- p3.c_str(), p5.c_str());
+ builder->fsCodeAppendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n",
+ bVar.c_str(), p2.c_str(), fsCoords,
+ p3.c_str(), p5.c_str());
}
// output will default to transparent black (we simply won't write anything
// else to it if invalid, instead of discarding or returning prematurely)
- code->appendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor);
+ builder->fsCodeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", outputColor);
// c = (x^2)+(y^2) - params[4]
- code->appendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str(),
- fsCoords, fsCoords,
- p4.c_str());
+ builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str(),
+ fsCoords, fsCoords,
+ p4.c_str());
// Non-degenerate case (quadratic)
if (!fIsDegenerate) {
// ac4 = params[0] * c
- code->appendf("\tfloat %s = %s * %s;\n", ac4Name.c_str(), p0.c_str(),
- cName.c_str());
+ builder->fsCodeAppendf("\tfloat %s = %s * %s;\n", ac4Name.c_str(), p0.c_str(),
+ cName.c_str());
// d = b^2 - ac4
- code->appendf("\tfloat %s = %s * %s - %s;\n", dName.c_str(),
- bVar.c_str(), bVar.c_str(), ac4Name.c_str());
+ builder->fsCodeAppendf("\tfloat %s = %s * %s - %s;\n", dName.c_str(),
+ bVar.c_str(), bVar.c_str(), ac4Name.c_str());
// only proceed if discriminant is >= 0
- code->appendf("\tif (%s >= 0.0) {\n", dName.c_str());
+ builder->fsCodeAppendf("\tif (%s >= 0.0) {\n", dName.c_str());
// intermediate value we'll use to compute the roots
// q = -0.5 * (b +/- sqrt(d))
- code->appendf("\t\tfloat %s = -0.5 * (%s + (%s < 0.0 ? -1.0 : 1.0)"
- " * sqrt(%s));\n", qName.c_str(), bVar.c_str(),
- bVar.c_str(), dName.c_str());
+ builder->fsCodeAppendf("\t\tfloat %s = -0.5 * (%s + (%s < 0.0 ? -1.0 : 1.0)"
+ " * sqrt(%s));\n", qName.c_str(), bVar.c_str(),
+ bVar.c_str(), dName.c_str());
// compute both roots
// r0 = q * params[1]
- code->appendf("\t\tfloat %s = %s * %s;\n", r0Name.c_str(),
- qName.c_str(), p1.c_str());
+ builder->fsCodeAppendf("\t\tfloat %s = %s * %s;\n", r0Name.c_str(),
+ qName.c_str(), p1.c_str());
// r1 = c / q
- code->appendf("\t\tfloat %s = %s / %s;\n", r1Name.c_str(),
- cName.c_str(), qName.c_str());
+ builder->fsCodeAppendf("\t\tfloat %s = %s / %s;\n", r1Name.c_str(),
+ cName.c_str(), qName.c_str());
// Note: If there are two roots that both generate radius(t) > 0, the
// Canvas spec says to choose the larger t.
// so we'll look at the larger one first:
- code->appendf("\t\tfloat %s = max(%s, %s);\n", tName.c_str(),
- r0Name.c_str(), r1Name.c_str());
+ builder->fsCodeAppendf("\t\tfloat %s = max(%s, %s);\n", tName.c_str(),
+ r0Name.c_str(), r1Name.c_str());
// if r(t) > 0, then we're done; t will be our x coordinate
- code->appendf("\t\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
- p5.c_str(), p3.c_str());
+ builder->fsCodeAppendf("\t\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
+ p5.c_str(), p3.c_str());
- code->appendf("\t\t");
+ builder->fsCodeAppend("\t\t");
this->emitColorLookup(builder, tName.c_str(), outputColor, inputColor, samplers[0]);
// otherwise, if r(t) for the larger root was <= 0, try the other root
- code->appendf("\t\t} else {\n");
- code->appendf("\t\t\t%s = min(%s, %s);\n", tName.c_str(),
- r0Name.c_str(), r1Name.c_str());
+ builder->fsCodeAppend("\t\t} else {\n");
+ builder->fsCodeAppendf("\t\t\t%s = min(%s, %s);\n", tName.c_str(),
+ r0Name.c_str(), r1Name.c_str());
// if r(t) > 0 for the smaller root, then t will be our x coordinate
- code->appendf("\t\t\tif (%s * %s + %s > 0.0) {\n",
- tName.c_str(), p5.c_str(), p3.c_str());
+ builder->fsCodeAppendf("\t\t\tif (%s * %s + %s > 0.0) {\n",
+ tName.c_str(), p5.c_str(), p3.c_str());
- code->appendf("\t\t\t");
+ builder->fsCodeAppend("\t\t\t");
this->emitColorLookup(builder, tName.c_str(), outputColor, inputColor, samplers[0]);
// end if (r(t) > 0) for smaller root
- code->appendf("\t\t\t}\n");
+ builder->fsCodeAppend("\t\t\t}\n");
// end if (r(t) > 0), else, for larger root
- code->appendf("\t\t}\n");
+ builder->fsCodeAppend("\t\t}\n");
// end if (discriminant >= 0)
- code->appendf("\t}\n");
+ builder->fsCodeAppend("\t}\n");
} else {
// linear case: t = -c/b
- code->appendf("\tfloat %s = -(%s / %s);\n", tName.c_str(),
- cName.c_str(), bVar.c_str());
+ builder->fsCodeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(),
+ cName.c_str(), bVar.c_str());
// if r(t) > 0, then t will be the x coordinate
- code->appendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
- p5.c_str(), p3.c_str());
- code->appendf("\t");
+ builder->fsCodeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
+ p5.c_str(), p3.c_str());
+ builder->fsCodeAppend("\t");
this->emitColorLookup(builder, tName.c_str(), outputColor, inputColor, samplers[0]);
- code->appendf("\t}\n");
+ builder->fsCodeAppend("\t}\n");
}
}
}
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp
index 6bb475a3fe..40e2ac3275 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.cpp
+++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp
@@ -560,7 +560,6 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
// VS
{
- SkString* code = &builder->fVSCode;
SkString p2;
SkString p3;
builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2);
@@ -570,15 +569,14 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
// part of the quadratic as a varying.
if (kVec2f_GrSLType == coordsVaryingType) {
// r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
- code->appendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
- fVSVaryingName, p2.c_str(),
- vsCoordsVarying, p3.c_str());
+ builder->vsCodeAppendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
+ fVSVaryingName, p2.c_str(),
+ vsCoordsVarying, p3.c_str());
}
}
// FS
{
- SkString* code = &builder->fFSCode;
SkString cName("c");
SkString ac4Name("ac4");
SkString rootName("root");
@@ -603,31 +601,31 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
bVar = fFSVaryingName;
} else {
bVar = "b";
- code->appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
- bVar.c_str(), p2.c_str(), fsCoords, p3.c_str());
+ builder->fsCodeAppendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
+ bVar.c_str(), p2.c_str(), fsCoords, p3.c_str());
}
// c = (x^2)+(y^2) - params[4]
- code->appendf("\tfloat %s = dot(%s, %s) - %s;\n",
- cName.c_str(),
- fsCoords,
- fsCoords,
- p4.c_str());
+ builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n",
+ cName.c_str(),
+ fsCoords,
+ fsCoords,
+ p4.c_str());
// If we aren't degenerate, emit some extra code, and accept a slightly
// more complex coord.
if (!fIsDegenerate) {
// ac4 = 4.0 * params[0] * c
- code->appendf("\tfloat %s = %s * 4.0 * %s;\n",
- ac4Name.c_str(), p0.c_str(),
- cName.c_str());
+ builder->fsCodeAppendf("\tfloat %s = %s * 4.0 * %s;\n",
+ ac4Name.c_str(), p0.c_str(),
+ cName.c_str());
// root = sqrt(b^2-4ac)
// (abs to avoid exception due to fp precision)
- code->appendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n",
- rootName.c_str(), bVar.c_str(), bVar.c_str(),
- ac4Name.c_str());
+ builder->fsCodeAppendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n",
+ rootName.c_str(), bVar.c_str(), bVar.c_str(),
+ ac4Name.c_str());
// t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1]
t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(),