Fix case where GrGLEffectMatrix gives back a dangling ptr for the coords var name.
R=robertphillips@google.com
Author: bsalomon@google.com
Review URL: https://chromiumcodereview.appspot.com/23706003
git-svn-id: http://skia.googlecode.com/svn/trunk@10982 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index 2c554dc..329e6c7 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -857,8 +857,8 @@
void GrGLGradientEffect::setupMatrix(GrGLShaderBuilder* builder,
EffectKey key,
- const char** fsCoordName,
- const char** vsVaryingName,
+ SkString* fsCoordName,
+ SkString* vsVaryingName,
GrSLType* vsVaryingType) {
fEffectMatrix.emitCodeMakeFSCoords2D(builder,
key & kMatrixKeyMask,
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 31cc9f2..8e93604 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -317,8 +317,8 @@
*/
void setupMatrix(GrGLShaderBuilder* builder,
EffectKey key,
- const char** fsCoordName,
- const char** vsVaryingName = NULL,
+ SkString* fsCoordName,
+ SkString* vsVaryingName = NULL,
GrSLType* vsVaryingType = NULL);
// Emits the uniform used as the y-coord to texture samples in derived classes. Subclasses
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 2f56cb4..76a44a2 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -525,7 +525,7 @@
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
- const char* coords;
+ SkString coords;
this->setupMatrix(builder, key, &coords);
SkString t;
t.append(coords);
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index ca65969..9fcce68 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -559,7 +559,7 @@
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
- const char* coords;
+ SkString coords;
this->setupMatrix(builder, key, &coords);
SkString t("length(");
t.append(coords);
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index f975a18..2af20b0 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -473,10 +473,10 @@
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
- const char* coords;
+ SkString coords;
this->setupMatrix(builder, key, &coords);
SkString t;
- t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", coords, coords);
+ t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", coords.c_str(), coords.c_str());
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
}
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index ee6e25a..6926c2d 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -490,8 +490,8 @@
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
- const char* fsCoords;
- const char* vsCoordsVarying;
+ SkString fsCoords;
+ SkString vsCoordsVarying;
GrSLType coordsVaryingType;
this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
@@ -526,7 +526,7 @@
// r2Var = -2 * (r2Parm[2] * varCoord.x - r2Param[3] * r2Param[5])
builder->vsCodeAppendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n",
fVSVaryingName, p2.c_str(),
- vsCoordsVarying, p3.c_str(), p5.c_str());
+ vsCoordsVarying.c_str(), p3.c_str(), p5.c_str());
}
}
@@ -562,7 +562,7 @@
} else {
bVar = "b";
builder->fsCodeAppendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n",
- bVar.c_str(), p2.c_str(), fsCoords,
+ bVar.c_str(), p2.c_str(), fsCoords.c_str(),
p3.c_str(), p5.c_str());
}
@@ -572,7 +572,7 @@
// c = (x^2)+(y^2) - params[4]
builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str(),
- fsCoords, fsCoords,
+ fsCoords.c_str(), fsCoords.c_str(),
p4.c_str());
// Non-degenerate case (quadratic)
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp
index 46724cb..4c85758 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.cpp
+++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp
@@ -533,8 +533,8 @@
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
- const char* fsCoords;
- const char* vsCoordsVarying;
+ SkString fsCoords;
+ SkString vsCoordsVarying;
GrSLType coordsVaryingType;
this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
@@ -565,7 +565,7 @@
// r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
builder->vsCodeAppendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
fVSVaryingName, p2.c_str(),
- vsCoordsVarying, p3.c_str());
+ vsCoordsVarying.c_str(), p3.c_str());
}
}
@@ -596,14 +596,14 @@
} else {
bVar = "b";
builder->fsCodeAppendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
- bVar.c_str(), p2.c_str(), fsCoords, p3.c_str());
+ bVar.c_str(), p2.c_str(), fsCoords.c_str(), p3.c_str());
}
// c = (x^2)+(y^2) - params[4]
builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n",
cName.c_str(),
- fsCoords,
- fsCoords,
+ fsCoords.c_str(),
+ fsCoords.c_str(),
p4.c_str());
// If we aren't degenerate, emit some extra code, and accept a slightly