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 {
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";
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");
"\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) {
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");
builder->fsCodeAppendf("\t\tvec4 %s = ", dColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
- dCoordsIn,
+ dCoordsIn.c_str(),
dCoordsType);
builder->fsCodeAppend(";\n");
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:
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,
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);
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 |
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");
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");
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);
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);
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");
}
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");
const TextureSamplerArray&) {
sk_ignore_unused_variable(inputColor);
- const char* vCoords;
+ SkString vCoords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
fSeedUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
// 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)),"
const TextureSamplerArray& samplers) {
sk_ignore_unused_variable(inputColor);
- const char* vCoords;
+ SkString vCoords;
fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
// 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);
void GrGLGradientEffect::setupMatrix(GrGLShaderBuilder* builder,
EffectKey key,
- const char** fsCoordName,
- const char** vsVaryingName,
+ SkString* fsCoordName,
+ SkString* vsVaryingName,
GrSLType* vsVaryingType) {
fEffectMatrix.emitCodeMakeFSCoords2D(builder,
key & kMatrixKeyMask,
*/
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
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
- const char* coords;
+ SkString coords;
this->setupMatrix(builder, key, &coords);
SkString t;
t.append(coords);
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);
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]);
}
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);
// 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());
}
}
} 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());
}
// 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)
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);
// 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());
}
}
} 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
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) {
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");
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++) {
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);
builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
inputColor,
samplers[0],
- fsCoordName,
+ fsCoordName.c_str(),
fsCoordSLType);
builder->fsCodeAppend(";\n");
}
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,
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,
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");
}
}
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;
*/
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,
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;
}
* 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);
/**
*/
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);
/**