aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-29 12:43:38 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-29 12:43:38 +0000
commitf78df33efc72167f94da1b0476c9a86ba18a5f2c (patch)
treea48497f2ed0a3e6086a7b4f3c5e78cd82d2ae772
parentee2ef02d3dc1bf0573d660d34b0b4612de5cc314 (diff)
Make GrGLGradientEffect derive directly from GrGLEffect.
Review URL: https://codereview.appspot.com/6784053 git-svn-id: http://skia.googlecode.com/svn/branches/gpu_dev@6163 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--src/effects/gradients/SkGradientShader.cpp2
-rw-r--r--src/effects/gradients/SkGradientShaderPriv.h17
-rw-r--r--src/effects/gradients/SkLinearGradient.cpp26
-rw-r--r--src/effects/gradients/SkRadialGradient.cpp25
-rw-r--r--src/effects/gradients/SkSweepGradient.cpp25
-rw-r--r--src/effects/gradients/SkTwoPointConicalGradient.cpp294
-rw-r--r--src/effects/gradients/SkTwoPointRadialGradient.cpp183
7 files changed, 300 insertions, 272 deletions
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index 04e301929a..d71195c623 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -682,7 +682,7 @@ GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
GrGLGradientEffect::~GrGLGradientEffect() { }
-void GrGLGradientEffect::setupVariables(GrGLShaderBuilder* builder) {
+void GrGLGradientEffect::emitYCoordUniform(GrGLShaderBuilder* builder) {
fFSYUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kFloat_GrSLType, "GradientYCoordFS");
}
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 435e69d004..9f14e7f727 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -271,17 +271,21 @@ private:
///////////////////////////////////////////////////////////////////////////////
// Base class for GL gradient effects
-class GrGLGradientEffect : public GrGLLegacyEffect {
+class GrGLGradientEffect : public GrGLEffect {
public:
-
GrGLGradientEffect(const GrBackendEffectFactory& factory);
virtual ~GrGLGradientEffect();
- virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
- // emit code that gets a fragment's color from an expression for t; for now
- // this always uses the texture, but for simpler cases we'll be able to lerp
+protected:
+ // Emits the uniform used as the y-coord to texture samples in derived classes. Subclasses
+ // should call this method from their emitCode().
+ void emitYCoordUniform(GrGLShaderBuilder* builder);
+
+ // emit code that gets a fragment's color from an expression for t; for now this always uses the
+ // texture, but for simpler cases we'll be able to lerp. Subclasses should call this method from
+ // their emitCode().
void emitColorLookup(GrGLShaderBuilder* builder,
const char* gradientTValue,
const char* outputColor,
@@ -289,11 +293,10 @@ public:
const GrGLShaderBuilder::TextureSampler&);
private:
-
GrScalar fCachedYCoord;
GrGLUniformManager::UniformHandle fFSYUni;
- typedef GrGLLegacyEffect INHERITED;
+ typedef GrGLEffect INHERITED;
};
#endif
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 61824a042e..0e08ec067d 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -485,12 +485,14 @@ public:
virtual ~GrGLLinearGradient() { }
- virtual void emitVS(GrGLShaderBuilder* builder,
- const char* vertexCoords) SK_OVERRIDE { }
- virtual void emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray&) SK_OVERRIDE;
+ virtual void emitCode(GrGLShaderBuilder*,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray&) SK_OVERRIDE;
+
static EffectKey GenKey(const GrEffect& s, const GrGLCaps& caps) { return 0; }
private:
@@ -548,10 +550,14 @@ GrEffect* GrLinearGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
-void GrGLLinearGradient::emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray& samplers) {
+void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray& samplers) {
+ this->emitYCoordUniform(builder);
SkString t;
t.printf("%s.x", builder->defaultTexCoordsName());
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 6b9a678df7..6fa29a79c5 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -480,12 +480,13 @@ public:
const GrEffect&) : INHERITED (factory) { }
virtual ~GrGLRadialGradient() { }
- virtual void emitVS(GrGLShaderBuilder* builder,
- const char* vertexCoords) SK_OVERRIDE { }
- virtual void emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray&) SK_OVERRIDE;
+ virtual void emitCode(GrGLShaderBuilder*,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray&) SK_OVERRIDE;
static EffectKey GenKey(const GrEffect& s, const GrGLCaps& caps) { return 0; }
@@ -547,10 +548,14 @@ GrEffect* GrRadialGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
-void GrGLRadialGradient::emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray& samplers) {
+void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray& samplers) {
+ this->emitYCoordUniform(builder);
SkString t;
t.printf("length(%s.xy)", builder->defaultTexCoordsName());
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index c606bbaca6..b264075c12 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -389,12 +389,13 @@ public:
const GrEffect&) : INHERITED (factory) { }
virtual ~GrGLSweepGradient() { }
- virtual void emitVS(GrGLShaderBuilder* builder,
- const char* vertexCoords) SK_OVERRIDE { }
- virtual void emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray&) SK_OVERRIDE;
+ virtual void emitCode(GrGLShaderBuilder*,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray&) SK_OVERRIDE;
static EffectKey GenKey(const GrEffect& s, const GrGLCaps& caps) { return 0; }
@@ -453,10 +454,14 @@ GrEffect* GrSweepGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
-void GrGLSweepGradient::emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray& samplers) {
+void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray& samplers) {
+ this->emitYCoordUniform(builder);
SkString t;
t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5",
builder->defaultTexCoordsName(), builder->defaultTexCoordsName());
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index 5305b44b49..396981f598 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -326,13 +326,13 @@ public:
const GrEffect&);
virtual ~GrGLConical2Gradient() { }
- virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
- virtual void emitVS(GrGLShaderBuilder* builder,
- const char* vertexCoords) SK_OVERRIDE;
- virtual void emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray&) SK_OVERRIDE;
+ virtual void emitCode(GrGLShaderBuilder*,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
static EffectKey GenKey(const GrEffect& s, const GrGLCaps& caps);
@@ -465,8 +465,14 @@ GrGLConical2Gradient::GrGLConical2Gradient(
fIsDegenerate = data.isDegenerate();
}
-void GrGLConical2Gradient::setupVariables(GrGLShaderBuilder* builder) {
- INHERITED::setupVariables(builder);
+void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray& samplers) {
+ this->emitYCoordUniform(builder);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
// in test apps, but need to keep an eye on it.
@@ -481,148 +487,146 @@ void GrGLConical2Gradient::setupVariables(GrGLShaderBuilder* builder) {
builder->addVarying(kFloat_GrSLType, "Conical2BCoeff",
&fVSVaryingName, &fFSVaryingName);
}
-}
-
-void GrGLConical2Gradient::emitVS(GrGLShaderBuilder* builder,
- const char* vertexCoords) {
- SkString* code = &builder->fVSCode;
- SkString p2; // distance between centers
- SkString p3; // start radius
- SkString p5; // difference in radii (r1 - r0)
- builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2);
- builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3);
- builder->getUniformVariable(fVSParamUni).appendArrayAccess(5, &p5);
- // For radial gradients without perspective we can pass the linear
- // part of the quadratic as a varying.
- if (!builder->defaultTextureMatrixIsPerspective()) {
- // 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(),
- vertexCoords, p3.c_str(), p5.c_str());
+ // VS
+ {
+ SkString* code = &builder->fVSCode;
+ SkString p2; // distance between centers
+ SkString p3; // start radius
+ SkString p5; // difference in radii (r1 - r0)
+ builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2);
+ builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3);
+ builder->getUniformVariable(fVSParamUni).appendArrayAccess(5, &p5);
+
+ // For radial gradients without perspective we can pass the linear
+ // part of the quadratic as a varying.
+ if (!builder->defaultTextureMatrixIsPerspective()) {
+ // 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(),
+ vertexCoords, p3.c_str(), p5.c_str());
+ }
}
-}
-void GrGLConical2Gradient::emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray& samplers) {
- SkString* code = &builder->fFSCode;
-
- SkString cName("c");
- SkString ac4Name("ac4");
- SkString dName("d");
- SkString qName("q");
- SkString r0Name("r0");
- SkString r1Name("r1");
- SkString tName("t");
- SkString p0; // 4a
- SkString p1; // 1/a
- SkString p2; // distance between centers
- SkString p3; // start radius
- SkString p4; // start radius squared
- SkString p5; // difference in radii (r1 - r0)
-
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5);
-
- // If we we're able to interpolate the linear component,
- // bVar is the varying; otherwise compute it
- SkString bVar;
- if (!builder->defaultTextureMatrixIsPerspective()) {
- bVar = fFSVaryingName;
- } else {
- bVar = "b";
- code->appendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n",
- bVar.c_str(), p2.c_str(), builder->defaultTexCoordsName(),
- p3.c_str(), p5.c_str());
- }
+ // FS
+ {
+ SkString* code = &builder->fFSCode;
+
+ SkString cName("c");
+ SkString ac4Name("ac4");
+ SkString dName("d");
+ SkString qName("q");
+ SkString r0Name("r0");
+ SkString r1Name("r1");
+ SkString tName("t");
+ SkString p0; // 4a
+ SkString p1; // 1/a
+ SkString p2; // distance between centers
+ SkString p3; // start radius
+ SkString p4; // start radius squared
+ SkString p5; // difference in radii (r1 - r0)
+
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5);
+
+ // If we we're able to interpolate the linear component,
+ // bVar is the varying; otherwise compute it
+ SkString bVar;
+ if (!builder->defaultTextureMatrixIsPerspective()) {
+ bVar = fFSVaryingName;
+ } else {
+ bVar = "b";
+ code->appendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n",
+ bVar.c_str(), p2.c_str(), builder->defaultTexCoordsName(),
+ 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);
-
- // c = (x^2)+(y^2) - params[4]
- code->appendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str(),
- builder->defaultTexCoordsName(), builder->defaultTexCoordsName(),
- 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());
-
- // d = b^2 - ac4
- code->appendf("\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());
-
- // 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());
-
- // compute both roots
- // r0 = q * params[1]
- code->appendf("\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());
-
- // 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());
-
- // 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());
-
- code->appendf("\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());
-
- // 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());
-
- code->appendf("\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");
- // end if (r(t) > 0), else, for larger root
- code->appendf("\t\t}\n");
- // end if (discriminant >= 0)
- code->appendf("\t}\n");
- } else {
+ // 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);
+
+ // c = (x^2)+(y^2) - params[4]
+ code->appendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str(),
+ builder->defaultTexCoordsName(), builder->defaultTexCoordsName(),
+ 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());
+
+ // d = b^2 - ac4
+ code->appendf("\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());
+
+ // 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());
+
+ // compute both roots
+ // r0 = q * params[1]
+ code->appendf("\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());
+
+ // 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());
+
+ // 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());
+
+ code->appendf("\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());
+
+ // 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());
+
+ code->appendf("\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");
+ // end if (r(t) > 0), else, for larger root
+ code->appendf("\t\t}\n");
+ // end if (discriminant >= 0)
+ code->appendf("\t}\n");
+ } else {
- // linear case: t = -c/b
- code->appendf("\tfloat %s = -(%s / %s);\n", tName.c_str(),
- cName.c_str(), bVar.c_str());
+ // linear case: t = -c/b
+ code->appendf("\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");
- this->emitColorLookup(builder, tName.c_str(), outputColor, inputColor, samplers[0]);
- code->appendf("\t}\n");
+ // 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");
+ this->emitColorLookup(builder, tName.c_str(), outputColor, inputColor, samplers[0]);
+ code->appendf("\t}\n");
+ }
}
}
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp
index 1758b451d8..2aac6677f4 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.cpp
+++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp
@@ -361,13 +361,13 @@ public:
const GrEffect&);
virtual ~GrGLRadial2Gradient() { }
- virtual void setupVariables(GrGLShaderBuilder* builder) SK_OVERRIDE;
- virtual void emitVS(GrGLShaderBuilder* builder,
- const char* vertexCoords) SK_OVERRIDE;
- virtual void emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray&) SK_OVERRIDE;
+ virtual void emitCode(GrGLShaderBuilder*,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
static EffectKey GenKey(const GrEffect& s, const GrGLCaps& caps);
@@ -498,8 +498,15 @@ GrGLRadial2Gradient::GrGLRadial2Gradient(
fIsDegenerate = data.isDegenerate();
}
-void GrGLRadial2Gradient::setupVariables(GrGLShaderBuilder* builder) {
- INHERITED::setupVariables(builder);
+void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
+ const GrEffect&,
+ EffectKey,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray& samplers) {
+
+ this->emitYCoordUniform(builder);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
// in test apps, but need to keep an eye on it.
@@ -514,91 +521,89 @@ void GrGLRadial2Gradient::setupVariables(GrGLShaderBuilder* builder) {
builder->addVarying(kFloat_GrSLType, "Radial2BCoeff",
&fVSVaryingName, &fFSVaryingName);
}
-}
-
-void GrGLRadial2Gradient::emitVS(GrGLShaderBuilder* builder,
- const char* vertexCoords) {
- SkString* code = &builder->fVSCode;
- SkString p2;
- SkString p3;
- builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2);
- builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3);
- // For radial gradients without perspective we can pass the linear
- // part of the quadratic as a varying.
- if (!builder->defaultTextureMatrixIsPerspective()) {
- // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
- code->appendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
- fVSVaryingName, p2.c_str(),
- vertexCoords, p3.c_str());
+ // VS
+ {
+ SkString* code = &builder->fVSCode;
+ SkString p2;
+ SkString p3;
+ builder->getUniformVariable(fVSParamUni).appendArrayAccess(2, &p2);
+ builder->getUniformVariable(fVSParamUni).appendArrayAccess(3, &p3);
+
+ // For radial gradients without perspective we can pass the linear
+ // part of the quadratic as a varying.
+ if (!builder->defaultTextureMatrixIsPerspective()) {
+ // r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
+ code->appendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
+ fVSVaryingName, p2.c_str(),
+ vertexCoords, p3.c_str());
+ }
}
-}
-void GrGLRadial2Gradient::emitFS(GrGLShaderBuilder* builder,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray& samplers) {
- SkString* code = &builder->fFSCode;
- SkString cName("c");
- SkString ac4Name("ac4");
- SkString rootName("root");
- SkString t;
- SkString p0;
- SkString p1;
- SkString p2;
- SkString p3;
- SkString p4;
- SkString p5;
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4);
- builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5);
-
- // If we we're able to interpolate the linear component,
- // bVar is the varying; otherwise compute it
- SkString bVar;
- if (!builder->defaultTextureMatrixIsPerspective()) {
- bVar = fFSVaryingName;
- } else {
- bVar = "b";
- code->appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
- bVar.c_str(), p2.c_str(),
- builder->defaultTexCoordsName(), p3.c_str());
- }
+ // FS
+ {
+ SkString* code = &builder->fFSCode;
+ SkString cName("c");
+ SkString ac4Name("ac4");
+ SkString rootName("root");
+ SkString t;
+ SkString p0;
+ SkString p1;
+ SkString p2;
+ SkString p3;
+ SkString p4;
+ SkString p5;
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(0, &p0);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(1, &p1);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(2, &p2);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(3, &p3);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(4, &p4);
+ builder->getUniformVariable(fFSParamUni).appendArrayAccess(5, &p5);
+
+ // If we we're able to interpolate the linear component,
+ // bVar is the varying; otherwise compute it
+ SkString bVar;
+ if (!builder->defaultTextureMatrixIsPerspective()) {
+ bVar = fFSVaryingName;
+ } else {
+ bVar = "b";
+ code->appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
+ bVar.c_str(), p2.c_str(),
+ builder->defaultTexCoordsName(), p3.c_str());
+ }
- // c = (x^2)+(y^2) - params[4]
- code->appendf("\tfloat %s = dot(%s, %s) - %s;\n",
- cName.c_str(),
- builder->defaultTexCoordsName(),
- builder->defaultTexCoordsName(),
- 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());
-
- // 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());
-
- // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1]
- t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(),
- rootName.c_str(), p1.c_str());
- } else {
- // t is: -c/b
- t.printf("-%s / %s", cName.c_str(), bVar.c_str());
- }
+ // c = (x^2)+(y^2) - params[4]
+ code->appendf("\tfloat %s = dot(%s, %s) - %s;\n",
+ cName.c_str(),
+ builder->defaultTexCoordsName(),
+ builder->defaultTexCoordsName(),
+ 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());
+
+ // 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());
+
+ // t is: (-b + params[5] * sqrt(b^2-4ac)) * params[1]
+ t.printf("(-%s + %s * %s) * %s", bVar.c_str(), p5.c_str(),
+ rootName.c_str(), p1.c_str());
+ } else {
+ // t is: -c/b
+ t.printf("-%s / %s", cName.c_str(), bVar.c_str());
+ }
- this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
+ this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
+ }
}
void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {