Fix case where GrGLEffectMatrix gives back a dangling ptr for the coords var name.
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 28 Aug 2013 15:59:13 +0000 (15:59 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 28 Aug 2013 15:59:13 +0000 (15:59 +0000)
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

22 files changed:
src/core/SkXfermode.cpp
src/effects/SkArithmeticMode.cpp
src/effects/SkBicubicImageFilter.cpp
src/effects/SkDisplacementMapEffect.cpp
src/effects/SkLightingImageFilter.cpp
src/effects/SkMagnifierImageFilter.cpp
src/effects/SkMatrixConvolutionImageFilter.cpp
src/effects/SkMorphologyImageFilter.cpp
src/effects/SkPerlinNoiseShader.cpp
src/effects/gradients/SkGradientShader.cpp
src/effects/gradients/SkGradientShaderPriv.h
src/effects/gradients/SkLinearGradient.cpp
src/effects/gradients/SkRadialGradient.cpp
src/effects/gradients/SkSweepGradient.cpp
src/effects/gradients/SkTwoPointConicalGradient.cpp
src/effects/gradients/SkTwoPointRadialGradient.cpp
src/gpu/effects/GrConfigConversionEffect.cpp
src/gpu/effects/GrConvolutionEffect.cpp
src/gpu/effects/GrSimpleTextureEffect.cpp
src/gpu/effects/GrTextureDomainEffect.cpp
src/gpu/gl/GrGLEffectMatrix.cpp
src/gpu/gl/GrGLEffectMatrix.h

index 587b0b98aa433bf787843ce51172501b1138ac36..c9b3f39c8d391f1482cb29b742ea7eb91f8414a0 100644 (file)
@@ -948,13 +948,13 @@ public:
             const GrTexture* backgroundTex = drawEffect.castEffect<XferEffect>().backgroundAccess().getTexture();
             const char* dstColor;
             if (backgroundTex) {
-                const char* bgCoords;
+                SkString bgCoords;
                 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCoords, NULL, "BG");
                 dstColor = "bgColor";
                 builder->fsCodeAppendf("\t\tvec4 %s = ", dstColor);
                 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
                                              samplers[0],
-                                             bgCoords,
+                                             bgCoords.c_str(),
                                              bgCoordsType);
                 builder->fsCodeAppendf(";\n");
             } else {
index ed29130369e9c71fdde912e10ff0a1142336cc4e..1efa11510609dbd802aaa53158411672f58f09ee 100644 (file)
@@ -351,12 +351,12 @@ void GrGLArithmeticEffect::emitCode(GrGLShaderBuilder* builder,
     GrTexture* backgroundTex = drawEffect.castEffect<GrArithmeticEffect>().backgroundTexture();
     const char* dstColor;
     if (backgroundTex) {
-        const char* bgCoords;
+        SkString bgCoords;
         GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCoords, NULL, "BG");
         builder->fsCodeAppend("\t\tvec4 bgColor = ");
         builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
                                      samplers[0],
-                                     bgCoords,
+                                     bgCoords.c_str(),
                                      bgCoordsType);
         builder->fsCodeAppendf(";\n");
         dstColor = "bgColor";
index 26d4b2eda79cfb7af8001de6e880a4d44ad8d878..56d9eba7549ec009389ae04a962ff1a03bf94638 100644 (file)
@@ -224,7 +224,7 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
                                  const char* outputColor,
                                  const char* inputColor,
                                  const TextureSamplerArray& samplers) {
-    const char* coords;
+    SkString coords;
     fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
     fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
                                            kMat44f_GrSLType, "Coefficients");
@@ -253,7 +253,7 @@ 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);
-    builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords, imgInc);
+    builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords.c_str(), imgInc);
     builder->fsCodeAppendf("\tvec2 f = fract(coord / %s);\n", imgInc);
     for (int y = 0; y < 4; ++y) {
         for (int x = 0; x < 4; ++x) {
index 6a3abb5a3c5e28547eb5bdbb2bece4eafeb077e2..4dfb754190d78f12289682dcbafd282d89b849ec 100644 (file)
@@ -413,10 +413,10 @@ void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
                                     kVec2f_GrSLType, "Scale");
     const char* scaleUni = builder->getUniformCStr(fScaleUni);
 
-    const char* dCoordsIn;
+    SkString dCoordsIn;
     GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode(
                                 builder, key, &dCoordsIn, NULL, "DISPL");
-    const char* cCoordsIn;
+    SkString cCoordsIn;
     GrSLType cCoordsType = fColorEffectMatrix.emitCode(
                                 builder, key, &cCoordsIn, NULL, "COLOR");
 
@@ -430,7 +430,7 @@ void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
     builder->fsCodeAppendf("\t\tvec4 %s = ", dColor);
     builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
                                  samplers[0],
-                                 dCoordsIn,
+                                 dCoordsIn.c_str(),
                                  dCoordsType);
     builder->fsCodeAppend(";\n");
 
@@ -439,7 +439,7 @@ void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
                            dColor, dColor, nearZero, dColor, dColor);
 
     builder->fsCodeAppendf("\t\tvec2 %s = %s + %s*(%s.",
-                           cCoords, cCoordsIn, scaleUni, dColor);
+                           cCoords, cCoordsIn.c_str(), scaleUni, dColor);
 
     switch (fXChannelSelector) {
       case SkDisplacementMapEffect::kR_ChannelSelectorType:
index e71df66e6c6888432d1a1094b20f140a2c058112..f907a199b810b44a8019bb3fd1f7b20f9b1e5306 100644 (file)
@@ -1204,7 +1204,7 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
                                   const char* outputColor,
                                   const char* inputColor,
                                   const TextureSamplerArray& samplers) {
-    const char* coords;
+    SkString coords;
     fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
 
     fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
@@ -1267,7 +1267,7 @@ void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
                           interiorNormalBody.c_str(),
                           &interiorNormalName);
 
-    builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords);
+    builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords.c_str());
     builder->fsCodeAppend("\t\tfloat m[9];\n");
 
     const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
index aa91b1c9804e20f68059e6bf125b048d925a6c9b..f6b70fc524cba6e0dc76fb190cf4fcc07ca90bb9 100644 (file)
@@ -127,7 +127,7 @@ void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
                                    const char* outputColor,
                                    const char* inputColor,
                                    const TextureSamplerArray& samplers) {
-    const char* coords;
+    SkString coords;
     fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
     fOffsetVar = builder->addUniform(
         GrGLShaderBuilder::kFragment_ShaderType |
@@ -142,10 +142,10 @@ void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
         GrGLShaderBuilder::kVertex_ShaderType,
         kVec2f_GrSLType, "uInset");
 
-    builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords);
+    builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords.c_str());
     builder->fsCodeAppendf("\t\tvec2 zoom_coord = %s + %s / %s;\n",
                            builder->getUniformCStr(fOffsetVar),
-                            coords,
+                           coords.c_str(),
                            builder->getUniformCStr(fZoomVar));
 
     builder->fsCodeAppend("\t\tvec2 delta = min(coord, vec2(1.0, 1.0) - coord);\n");
index 37ca2fa141cae500dc19809c28ecd1e2dc6273ae..00bb6ec4bb474166f5ad7e62b69a72b83868e5ec 100644 (file)
@@ -385,7 +385,7 @@ void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
                                            const char* outputColor,
                                            const char* inputColor,
                                            const TextureSamplerArray& samplers) {
-    const char* coords;
+    SkString coords;
     fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
     fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
                                              kVec2f_GrSLType, "ImageIncrement");
@@ -407,7 +407,7 @@ void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
     int kHeight = fKernelSize.height();
 
     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\tvec2 coord = %s - %s * %s;\n", coords.c_str(), 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);
@@ -426,7 +426,7 @@ void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
         builder->fsCodeAppendf("\t\t%s.rgb = clamp(%s.rgb, 0.0, %s.a);\n", outputColor, outputColor, outputColor);
     } else {
         builder->fsCodeAppend("\t\tvec4 c = ");
-        appendTextureLookup(builder, samplers[0], coords, fTileMode);
+        appendTextureLookup(builder, samplers[0], coords.c_str(), fTileMode);
         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);
index 33dd2e6ce8b21601d099ebd43c9cda4d69befbbf..6d15d4e2db80896772dc2e2346a218aac36b3540 100644 (file)
@@ -324,7 +324,7 @@ void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder,
                                     const char* outputColor,
                                     const char* inputColor,
                                     const TextureSamplerArray& samplers) {
-    const char* coords;
+    SkString coords;
     fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
     fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
                                              kVec2f_GrSLType, "ImageIncrement");
@@ -346,7 +346,7 @@ void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder,
     }
     const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
 
-    builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords, fRadius, imgInc);
+    builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords.c_str(), 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");
index 1d26920c501db288e86babd562c02f34616630c5..720fcf27ededdf3841a933d6e3b35d17cd0cff19 100644 (file)
@@ -749,7 +749,7 @@ void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder,
                                 const TextureSamplerArray&) {
     sk_ignore_unused_variable(inputColor);
 
-    const char* vCoords;
+    SkString vCoords;
     fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
 
     fSeedUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
@@ -904,7 +904,7 @@ void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder,
     // There are rounding errors if the floor operation is not performed here
     builder->fsCodeAppendf(
         "\t\tvec3 %s = vec3(floor((%s*vec3(%s, 1.0)).xy) * vec2(0.66) * %s, 0.0);\n",
-        noiseVecIni, invMatrixUni, vCoords, baseFrequencyUni);
+        noiseVecIni, invMatrixUni, vCoords.c_str(), baseFrequencyUni);
 
     // Perturb the texcoords with three components of noise
     builder->fsCodeAppendf("\t\t%s += 0.1 * vec3(%s(%s + vec3(  0.0,   0.0, %s)),"
@@ -965,7 +965,7 @@ void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder,
                                const TextureSamplerArray& samplers) {
     sk_ignore_unused_variable(inputColor);
 
-    const char* vCoords;
+    SkString vCoords;
     fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
 
     fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
@@ -1148,7 +1148,7 @@ void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder,
 
     // There are rounding errors if the floor operation is not performed here
     builder->fsCodeAppendf("\n\t\tvec2 %s = floor((%s * vec3(%s, 1.0)).xy) * %s;",
-                           noiseVec, invMatrixUni, vCoords, baseFrequencyUni);
+                           noiseVec, invMatrixUni, vCoords.c_str(), baseFrequencyUni);
 
     // Clear the color accumulator
     builder->fsCodeAppendf("\n\t\t%s = vec4(0.0);", outputColor);
index 2c554dc37605ad6a24b5a281523094f2b4e13b61..329e6c76cedd020ae3e77f95ee267efbe7de1f4c 100644 (file)
@@ -857,8 +857,8 @@ GrGLEffect::EffectKey GrGLGradientEffect::GenMatrixKey(const GrDrawEffect& drawE
 
 void GrGLGradientEffect::setupMatrix(GrGLShaderBuilder* builder,
                                      EffectKey key,
-                                     const char** fsCoordName,
-                                     const char** vsVaryingName,
+                                     SkString* fsCoordName,
+                                     SkString* vsVaryingName,
                                      GrSLType* vsVaryingType) {
     fEffectMatrix.emitCodeMakeFSCoords2D(builder,
                                          key & kMatrixKeyMask,
index 31cc9f26171c6184b4535004ea1388d2de024bc4..8e9360429fea3c0fac6146a1dc8d0123ba3b90d5 100644 (file)
@@ -317,8 +317,8 @@ protected:
      */
     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
index 2f56cb49ca21c2b4443663a5259def64bf31f24d..76a44a26955b719bef8518281500338487d4f420 100644 (file)
@@ -525,7 +525,7 @@ void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
                                   const char* inputColor,
                                   const TextureSamplerArray& samplers) {
     this->emitYCoordUniform(builder);
-    const char* coords;
+    SkString coords;
     this->setupMatrix(builder, key, &coords);
     SkString t;
     t.append(coords);
index ca659699950f791935605bb50309ee4d3335aa8f..9fcce68fa3a1b9e2ccfb91786388e61e9face951 100644 (file)
@@ -559,7 +559,7 @@ void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
                                   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);
index f975a1887ead036816bd2f190fd36cb8f76a6c5e..2af20b0bf6ce84b12350df9a4966df2a1be051b6 100644 (file)
@@ -473,10 +473,10 @@ void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
                                  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]);
 }
 
index ee6e25a88eb5a0bbddfa15494651d0a154fa394b..6926c2d2ec040a628769fa6208bef87976795653 100644 (file)
@@ -490,8 +490,8 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
                                     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 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
             // 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 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
         } 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 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
 
         // 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)
index 46724cb45b38e27e3509595dd918da89ae42ba99..4c8575844cd6b7e5b078a680833caa896c8c07fd 100644 (file)
@@ -533,8 +533,8 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
                                    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 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
             // 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 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
         } 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
index 2290cb930e750600acd241368de5ce38c20bb362..8f58feff79ba0d3d20c0dde4dab531c109657304 100644 (file)
@@ -30,12 +30,12 @@ public:
                           const char* outputColor,
                           const char* inputColor,
                           const TextureSamplerArray& samplers) SK_OVERRIDE {
-        const char* coords;
+        SkString coords;
         GrSLType coordsType = fEffectMatrix.emitCode(builder, key, &coords);
         builder->fsCodeAppendf("\t\t%s = ", outputColor);
         builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
                                      samplers[0],
-                                     coords,
+                                     coords.c_str(),
                                      coordsType);
         builder->fsCodeAppend(";\n");
         if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) {
index 925a8188f6828117081ab25bc80ebb09c4e67b6a..d3d18409ea943c8452064e3ca767306b5e3ae58b 100644 (file)
@@ -62,7 +62,7 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
                                      const char* outputColor,
                                      const char* inputColor,
                                      const TextureSamplerArray& samplers) {
-    const char* coords;
+    SkString coords;
     fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
     fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
                                              kVec2f_GrSLType, "ImageIncrement");
@@ -79,7 +79,7 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
     const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni);
     const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
 
-    builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords, fRadius, imgInc);
+    builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords.c_str(), fRadius, imgInc);
 
     // Manually unroll loop because some drivers don't; yields 20-30% speedup.
     for (int i = 0; i < width; i++) {
index 598c6ee6bf87886f001c60164a11c03736ac6c10..6a85e4780eb82b937d161cabbc3410f7e83ab0a0 100644 (file)
@@ -31,14 +31,16 @@ public:
                           const char* inputColor,
                           const TextureSamplerArray& samplers) SK_OVERRIDE {
         const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
-        const char* fsCoordName;
+        SkString fsCoordName;
         GrSLType fsCoordSLType;
         if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
             SkASSERT(ste.getMatrix().isIdentity());
             SkASSERT(1 == ste.numVertexAttribs());
             fsCoordSLType = kVec2f_GrSLType;
             const char* vsVaryingName;
-            builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &fsCoordName);
+            const char* fsVaryingNamePtr;
+            builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &fsVaryingNamePtr);
+            fsCoordName = fsVaryingNamePtr;
             const char* attrName =
                 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0])->c_str();
             builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, attrName);
@@ -49,7 +51,7 @@ public:
         builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
                                                 inputColor,
                                                 samplers[0],
-                                                fsCoordName,
+                                                fsCoordName.c_str(),
                                                 fsCoordSLType);
         builder->fsCodeAppend(";\n");
     }
index cf100d738867d7643e7885916f4fafd48b62c1a7..6f400cf3c1c5c30f68f8fb75c18914cefe8672df 100644 (file)
@@ -50,7 +50,7 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
                                        const TextureSamplerArray& samplers) {
     const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>();
 
-    const char* coords;
+    SkString coords;
     fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
     const char* domain;
     fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
@@ -58,7 +58,7 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
     if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) {
 
         builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n",
-                                coords, domain, domain);
+                                coords.c_str(), domain, domain);
 
         builder->fsCodeAppendf("\t%s = ", outputColor);
         builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
@@ -81,24 +81,24 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
             builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
                                                     inputColor,
                                                     samplers[0],
-                                                    coords);
+                                                    coords.c_str());
             builder->fsCodeAppend(";\n");
 
             builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n",
-                                   coords, domain, domain, domain);
+                                   coords.c_str(), domain, domain, domain);
             builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s.y) - 1.0);\n",
-                                   coords, domain, domain, domain);
+                                   coords.c_str(), domain, domain, domain);
             builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n");
             builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outputColor);
         } else {
             builder->fsCodeAppend("\tbvec4 outside;\n");
-            builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coords, domain);
-            builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", coords, domain);
+            builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coords.c_str(), domain);
+            builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", coords.c_str(), domain);
             builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", outputColor);
             builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
                                                     inputColor,
                                                     samplers[0],
-                                                    coords);
+                                                    coords.c_str());
             builder->fsCodeAppend(";\n");
         }
     }
index 8c8dcce2934932948df6b280f2586826f1823d80..58fcfeaa4ab3706cf6b9040def176f6e38937066 100644 (file)
@@ -45,8 +45,8 @@ GrGLEffect::EffectKey GrGLEffectMatrix::GenKey(const SkMatrix& effectMatrix,
 
 GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder,
                                     EffectKey key,
-                                    const char** fsCoordName,
-                                    const char** vsCoordName,
+                                    SkString* fsCoordName,
+                                    SkString* vsCoordName,
                                     const char* suffix) {
     GrSLType varyingType = kVoid_GrSLType;
     const char* uniName;
@@ -152,11 +152,11 @@ GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder,
     */
 void GrGLEffectMatrix::emitCodeMakeFSCoords2D(GrGLShaderBuilder* builder,
                                               EffectKey key,
-                                              const char** fsCoordName,
-                                              const char** vsVaryingName,
+                                              SkString* fsCoordName,
+                                              SkString* vsVaryingName,
                                               GrSLType* vsVaryingType,
                                               const char* suffix) {
-    const char* fsVaryingName;
+    SkString fsVaryingName;
 
     GrSLType varyingType = this->emitCode(builder,
                                           key,
@@ -173,7 +173,7 @@ void GrGLEffectMatrix::emitCodeMakeFSCoords2D(GrGLShaderBuilder* builder,
             coordName = suffixedCoordName.c_str();
         }
         builder->fsCodeAppendf("\tvec2 %s = %s.xy / %s.z;",
-                               coordName, fsVaryingName, fsVaryingName);
+                               coordName, fsVaryingName.c_str(), fsVaryingName.c_str());
         if (NULL != fsCoordName) {
             *fsCoordName = coordName;
         }
index 974e001e6203671482d1ec7a402940f493376085..56dda4563b6384d5f1c0fc0dbf31ab7dc7b53fd2 100644 (file)
@@ -84,12 +84,12 @@ public:
      * are returned as output parameters and the type of the varying is the return value. The suffix
      * is an optional parameter that can be used to make all variables emitted by the object
      * unique within a stage. It is only necessary if multiple GrGLEffectMatrix objects are used by
-     * a GrGLEffect.
+     * a single GrGLEffect.
      */
     GrSLType emitCode(GrGLShaderBuilder*,
                       EffectKey,
-                      const char** fsCoordName, /* optional */
-                      const char** vsCoordName = NULL,
+                      SkString* fsCoordName, /* optional */
+                      SkString* vsCoordName = NULL,
                       const char* suffix = NULL);
 
     /**
@@ -98,8 +98,8 @@ public:
      */
     void emitCodeMakeFSCoords2D(GrGLShaderBuilder*,
                                 EffectKey,
-                                const char** fsCoordName, /* optional */
-                                const char** vsVaryingName = NULL,
+                                SkString* fsCoordName, /* optional */
+                                SkString* vsVaryingName = NULL,
                                 GrSLType* vsVaryingType = NULL,
                                 const char* suffix = NULL);
     /**