aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/GrCircleBlurFragmentProcessor.cpp20
-rw-r--r--src/effects/SkAlphaThresholdFilter.cpp68
-rw-r--r--src/effects/SkArithmeticMode_gpu.cpp44
-rw-r--r--src/effects/SkBlurMaskFilter.cpp102
-rw-r--r--src/effects/SkColorCubeFilter.cpp30
-rw-r--r--src/effects/SkColorMatrixFilter.cpp22
-rw-r--r--src/effects/SkDisplacementMapEffect.cpp41
-rw-r--r--src/effects/SkLightingImageFilter.cpp172
-rw-r--r--src/effects/SkLumaColorFilter.cpp16
-rw-r--r--src/effects/SkMagnifierImageFilter.cpp60
-rw-r--r--src/effects/SkMorphologyImageFilter.cpp34
-rw-r--r--src/effects/SkPerlinNoiseShader.cpp102
-rw-r--r--src/effects/SkTableColorFilter.cpp46
-rw-r--r--src/effects/gradients/SkGradientShader.cpp62
-rw-r--r--src/effects/gradients/SkGradientShaderPriv.h1
-rw-r--r--src/effects/gradients/SkLinearGradient.cpp8
-rw-r--r--src/effects/gradients/SkRadialGradient.cpp8
-rw-r--r--src/effects/gradients/SkSweepGradient.cpp9
-rw-r--r--src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp125
19 files changed, 515 insertions, 455 deletions
diff --git a/src/effects/GrCircleBlurFragmentProcessor.cpp b/src/effects/GrCircleBlurFragmentProcessor.cpp
index 7c87ca4007..8c9d204928 100644
--- a/src/effects/GrCircleBlurFragmentProcessor.cpp
+++ b/src/effects/GrCircleBlurFragmentProcessor.cpp
@@ -46,23 +46,23 @@ void GrGLCircleBlurFragmentProcessor::emitCode(EmitArgs& args) {
"data",
&dataName);
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- const char *fragmentPos = fsBuilder->fragmentPosition();
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ const char *fragmentPos = fragBuilder->fragmentPosition();
if (args.fInputColor) {
- fsBuilder->codeAppendf("vec4 src=%s;", args.fInputColor);
+ fragBuilder->codeAppendf("vec4 src=%s;", args.fInputColor);
} else {
- fsBuilder->codeAppendf("vec4 src=vec4(1);");
+ fragBuilder->codeAppendf("vec4 src=vec4(1);");
}
- fsBuilder->codeAppendf("vec2 vec = %s.xy - %s.xy;", fragmentPos, dataName);
- fsBuilder->codeAppendf("float dist = (length(vec) - %s.z + 0.5) / %s.w;", dataName, dataName);
+ fragBuilder->codeAppendf("vec2 vec = %s.xy - %s.xy;", fragmentPos, dataName);
+ fragBuilder->codeAppendf("float dist = (length(vec) - %s.z + 0.5) / %s.w;", dataName, dataName);
- fsBuilder->codeAppendf("float intensity = ");
- fsBuilder->appendTextureLookup(args.fSamplers[0], "vec2(dist, 0.5)");
- fsBuilder->codeAppend(".a;");
+ fragBuilder->codeAppendf("float intensity = ");
+ fragBuilder->appendTextureLookup(args.fSamplers[0], "vec2(dist, 0.5)");
+ fragBuilder->codeAppend(".a;");
- fsBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor );
+ fragBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor );
}
void GrGLCircleBlurFragmentProcessor::onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index ff5e93e036..e6f1f088cb 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -146,40 +146,40 @@ void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) {
kFloat_GrSLType, kDefault_GrSLPrecision,
"outer_threshold");
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
- SkString maskCoords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 1);
-
- fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
- fsBuilder->codeAppendf("\t\tvec2 mask_coord = %s;\n", maskCoords2D.c_str());
- fsBuilder->codeAppend("\t\tvec4 input_color = ");
- fsBuilder->appendTextureLookup(args.fSamplers[0], "coord");
- fsBuilder->codeAppend(";\n");
- fsBuilder->codeAppend("\t\tvec4 mask_color = ");
- fsBuilder->appendTextureLookup(args.fSamplers[1], "mask_coord");
- fsBuilder->codeAppend(";\n");
-
- fsBuilder->codeAppendf("\t\tfloat inner_thresh = %s;\n",
- args.fBuilder->getUniformCStr(fInnerThresholdVar));
- fsBuilder->codeAppendf("\t\tfloat outer_thresh = %s;\n",
- args.fBuilder->getUniformCStr(fOuterThresholdVar));
- fsBuilder->codeAppend("\t\tfloat mask = mask_color.a;\n");
-
- fsBuilder->codeAppend("vec4 color = input_color;\n");
- fsBuilder->codeAppend("\t\tif (mask < 0.5) {\n"
- "\t\t\tif (color.a > outer_thresh) {\n"
- "\t\t\t\tfloat scale = outer_thresh / color.a;\n"
- "\t\t\t\tcolor.rgb *= scale;\n"
- "\t\t\t\tcolor.a = outer_thresh;\n"
- "\t\t\t}\n"
- "\t\t} else if (color.a < inner_thresh) {\n"
- "\t\t\tfloat scale = inner_thresh / max(0.001, color.a);\n"
- "\t\t\tcolor.rgb *= scale;\n"
- "\t\t\tcolor.a = inner_thresh;\n"
- "\t\t}\n");
-
- fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor,
- (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color")).c_str());
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString maskCoords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1);
+
+ fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
+ fragBuilder->codeAppendf("\t\tvec2 mask_coord = %s;\n", maskCoords2D.c_str());
+ fragBuilder->codeAppend("\t\tvec4 input_color = ");
+ fragBuilder->appendTextureLookup(args.fSamplers[0], "coord");
+ fragBuilder->codeAppend(";\n");
+ fragBuilder->codeAppend("\t\tvec4 mask_color = ");
+ fragBuilder->appendTextureLookup(args.fSamplers[1], "mask_coord");
+ fragBuilder->codeAppend(";\n");
+
+ fragBuilder->codeAppendf("\t\tfloat inner_thresh = %s;\n",
+ args.fBuilder->getUniformCStr(fInnerThresholdVar));
+ fragBuilder->codeAppendf("\t\tfloat outer_thresh = %s;\n",
+ args.fBuilder->getUniformCStr(fOuterThresholdVar));
+ fragBuilder->codeAppend("\t\tfloat mask = mask_color.a;\n");
+
+ fragBuilder->codeAppend("vec4 color = input_color;\n");
+ fragBuilder->codeAppend("\t\tif (mask < 0.5) {\n"
+ "\t\t\tif (color.a > outer_thresh) {\n"
+ "\t\t\t\tfloat scale = outer_thresh / color.a;\n"
+ "\t\t\t\tcolor.rgb *= scale;\n"
+ "\t\t\t\tcolor.a = outer_thresh;\n"
+ "\t\t\t}\n"
+ "\t\t} else if (color.a < inner_thresh) {\n"
+ "\t\t\tfloat scale = inner_thresh / max(0.001, color.a);\n"
+ "\t\t\tcolor.rgb *= scale;\n"
+ "\t\t\tcolor.a = inner_thresh;\n"
+ "\t\t}\n");
+
+ fragBuilder->codeAppendf("%s = %s;\n", args.fOutputColor,
+ (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color")).c_str());
}
void GrGLAlphaThresholdEffect::onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/effects/SkArithmeticMode_gpu.cpp b/src/effects/SkArithmeticMode_gpu.cpp
index 076610b66c..4d74082fb3 100644
--- a/src/effects/SkArithmeticMode_gpu.cpp
+++ b/src/effects/SkArithmeticMode_gpu.cpp
@@ -21,7 +21,7 @@
static const bool gUseUnpremul = false;
-static void add_arithmetic_code(GrGLSLFragmentBuilder* fsBuilder,
+static void add_arithmetic_code(GrGLSLFragmentBuilder* fragBuilder,
const char* srcColor,
const char* dstColor,
const char* outputColor,
@@ -29,27 +29,27 @@ static void add_arithmetic_code(GrGLSLFragmentBuilder* fsBuilder,
bool enforcePMColor) {
// We don't try to optimize for this case at all
if (nullptr == srcColor) {
- fsBuilder->codeAppend("const vec4 src = vec4(1);");
+ fragBuilder->codeAppend("const vec4 src = vec4(1);");
} else {
- fsBuilder->codeAppendf("vec4 src = %s;", srcColor);
+ fragBuilder->codeAppendf("vec4 src = %s;", srcColor);
if (gUseUnpremul) {
- fsBuilder->codeAppend("src.rgb = clamp(src.rgb / src.a, 0.0, 1.0);");
+ fragBuilder->codeAppend("src.rgb = clamp(src.rgb / src.a, 0.0, 1.0);");
}
}
- fsBuilder->codeAppendf("vec4 dst = %s;", dstColor);
+ fragBuilder->codeAppendf("vec4 dst = %s;", dstColor);
if (gUseUnpremul) {
- fsBuilder->codeAppend("dst.rgb = clamp(dst.rgb / dst.a, 0.0, 1.0);");
+ fragBuilder->codeAppend("dst.rgb = clamp(dst.rgb / dst.a, 0.0, 1.0);");
}
- fsBuilder->codeAppendf("%s = %s.x * src * dst + %s.y * src + %s.z * dst + %s.w;",
- outputColor, kUni, kUni, kUni, kUni);
- fsBuilder->codeAppendf("%s = clamp(%s, 0.0, 1.0);\n", outputColor, outputColor);
+ fragBuilder->codeAppendf("%s = %s.x * src * dst + %s.y * src + %s.z * dst + %s.w;",
+ outputColor, kUni, kUni, kUni, kUni);
+ fragBuilder->codeAppendf("%s = clamp(%s, 0.0, 1.0);\n", outputColor, outputColor);
if (gUseUnpremul) {
- fsBuilder->codeAppendf("%s.rgb *= %s.a;", outputColor, outputColor);
+ fragBuilder->codeAppendf("%s.rgb *= %s.a;", outputColor, outputColor);
} else if (enforcePMColor) {
- fsBuilder->codeAppendf("%s.rgb = min(%s.rgb, %s.a);",
- outputColor, outputColor, outputColor);
+ fragBuilder->codeAppendf("%s.rgb = min(%s.rgb, %s.a);",
+ outputColor, outputColor, outputColor);
}
}
@@ -61,7 +61,7 @@ public:
~GLArithmeticFP() override {}
void emitCode(EmitArgs& args) override {
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString dstColor("dstColor");
this->emitChild(0, nullptr, &dstColor, args);
@@ -70,7 +70,11 @@ public:
"k");
const char* kUni = args.fBuilder->getUniformCStr(fKUni);
- add_arithmetic_code(fsBuilder, args.fInputColor, dstColor.c_str(), args.fOutputColor, kUni,
+ add_arithmetic_code(fragBuilder,
+ args.fInputColor,
+ dstColor.c_str(),
+ args.fOutputColor,
+ kUni,
fEnforcePMColor);
}
@@ -207,16 +211,18 @@ public:
}
private:
- void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, const char* srcColor, const char* dstColor,
- const char* outColor, const GrXferProcessor& proc) override {
- GrGLSLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
-
+ void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb,
+ GrGLSLXPFragmentBuilder* fragBuilder,
+ const char* srcColor,
+ const char* dstColor,
+ const char* outColor,
+ const GrXferProcessor& proc) override {
fKUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"k");
const char* kUni = pb->getUniformCStr(fKUni);
- add_arithmetic_code(fsBuilder, srcColor, dstColor, outColor, kUni, fEnforcePMColor);
+ add_arithmetic_code(fragBuilder, srcColor, dstColor, outColor, kUni, fEnforcePMColor);
}
void onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index ac10a8bd80..a44563ea08 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -697,20 +697,20 @@ private:
typedef GrGLSLFragmentProcessor INHERITED;
};
-void OutputRectBlurProfileLookup(GrGLSLFragmentBuilder* fsBuilder,
+void OutputRectBlurProfileLookup(GrGLSLFragmentBuilder* fragBuilder,
const GrGLSLTextureSampler& sampler,
const char *output,
const char *profileSize, const char *loc,
const char *blurred_width,
const char *sharp_width) {
- fsBuilder->codeAppendf("float %s;", output);
- fsBuilder->codeAppendf("{");
- fsBuilder->codeAppendf("float coord = ((abs(%s - 0.5 * %s) - 0.5 * %s)) / %s;",
+ fragBuilder->codeAppendf("float %s;", output);
+ fragBuilder->codeAppendf("{");
+ fragBuilder->codeAppendf("float coord = ((abs(%s - 0.5 * %s) - 0.5 * %s)) / %s;",
loc, blurred_width, sharp_width, profileSize);
- fsBuilder->codeAppendf("%s = ", output);
- fsBuilder->appendTextureLookup(sampler, "vec2(coord,0.5)");
- fsBuilder->codeAppend(".a;");
- fsBuilder->codeAppendf("}");
+ fragBuilder->codeAppendf("%s = ", output);
+ fragBuilder->appendTextureLookup(sampler, "vec2(coord,0.5)");
+ fragBuilder->codeAppend(".a;");
+ fragBuilder->codeAppendf("}");
}
@@ -737,33 +737,33 @@ void GrGLRectBlurEffect::emitCode(EmitArgs& args) {
"profileSize",
&profileSizeName);
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- const char *fragmentPos = fsBuilder->fragmentPosition();
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ const char *fragmentPos = fragBuilder->fragmentPosition();
if (args.fInputColor) {
- fsBuilder->codeAppendf("vec4 src=%s;", args.fInputColor);
+ fragBuilder->codeAppendf("vec4 src=%s;", args.fInputColor);
} else {
- fsBuilder->codeAppendf("vec4 src=vec4(1);");
+ fragBuilder->codeAppendf("vec4 src=vec4(1);");
}
- fsBuilder->codeAppendf("%s vec2 translatedPos = %s.xy - %s.xy;", precisionString, fragmentPos,
- rectName);
- fsBuilder->codeAppendf("%s float width = %s.z - %s.x;", precisionString, rectName, rectName);
- fsBuilder->codeAppendf("%s float height = %s.w - %s.y;", precisionString, rectName, rectName);
+ fragBuilder->codeAppendf("%s vec2 translatedPos = %s.xy - %s.xy;", precisionString, fragmentPos,
+ rectName);
+ fragBuilder->codeAppendf("%s float width = %s.z - %s.x;", precisionString, rectName, rectName);
+ fragBuilder->codeAppendf("%s float height = %s.w - %s.y;", precisionString, rectName, rectName);
- fsBuilder->codeAppendf("%s vec2 smallDims = vec2(width - %s, height - %s);", precisionString,
- profileSizeName, profileSizeName);
- fsBuilder->codeAppendf("%s float center = 2.0 * floor(%s/2.0 + .25) - 1.0;", precisionString,
- profileSizeName);
- fsBuilder->codeAppendf("%s vec2 wh = smallDims - vec2(center,center);", precisionString);
+ fragBuilder->codeAppendf("%s vec2 smallDims = vec2(width - %s, height - %s);", precisionString,
+ profileSizeName, profileSizeName);
+ fragBuilder->codeAppendf("%s float center = 2.0 * floor(%s/2.0 + .25) - 1.0;", precisionString,
+ profileSizeName);
+ fragBuilder->codeAppendf("%s vec2 wh = smallDims - vec2(center,center);", precisionString);
- OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "horiz_lookup", profileSizeName,
+ OutputRectBlurProfileLookup(fragBuilder, args.fSamplers[0], "horiz_lookup", profileSizeName,
"translatedPos.x", "width", "wh.x");
- OutputRectBlurProfileLookup(fsBuilder, args.fSamplers[0], "vert_lookup", profileSizeName,
+ OutputRectBlurProfileLookup(fragBuilder, args.fSamplers[0], "vert_lookup", profileSizeName,
"translatedPos.y", "height", "wh.y");
- fsBuilder->codeAppendf("float final = horiz_lookup * vert_lookup;");
- fsBuilder->codeAppendf("%s = src * final;", args.fOutputColor);
+ fragBuilder->codeAppendf("float final = horiz_lookup * vert_lookup;");
+ fragBuilder->codeAppendf("%s = src * final;", args.fOutputColor);
}
void GrGLRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman,
@@ -1083,34 +1083,36 @@ void GrGLRRectBlurEffect::emitCode(EmitArgs& args) {
"blurRadius",
&blurRadiusName);
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- const char* fragmentPos = fsBuilder->fragmentPosition();
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ const char* fragmentPos = fragBuilder->fragmentPosition();
// warp the fragment position to the appropriate part of the 9patch blur texture
- fsBuilder->codeAppendf("vec2 rectCenter = (%s.xy + %s.zw)/2.0;", rectName, rectName);
- fsBuilder->codeAppendf("vec2 translatedFragPos = %s.xy - %s.xy;", fragmentPos, rectName);
- fsBuilder->codeAppendf("float threshold = %s + 2.0*%s;", cornerRadiusName, blurRadiusName);
- fsBuilder->codeAppendf("vec2 middle = %s.zw - %s.xy - 2.0*threshold;", rectName, rectName);
-
- fsBuilder->codeAppendf("if (translatedFragPos.x >= threshold && translatedFragPos.x < (middle.x+threshold)) {");
- fsBuilder->codeAppendf("translatedFragPos.x = threshold;\n");
- fsBuilder->codeAppendf("} else if (translatedFragPos.x >= (middle.x + threshold)) {");
- fsBuilder->codeAppendf("translatedFragPos.x -= middle.x - 1.0;");
- fsBuilder->codeAppendf("}");
-
- fsBuilder->codeAppendf("if (translatedFragPos.y > threshold && translatedFragPos.y < (middle.y+threshold)) {");
- fsBuilder->codeAppendf("translatedFragPos.y = threshold;");
- fsBuilder->codeAppendf("} else if (translatedFragPos.y >= (middle.y + threshold)) {");
- fsBuilder->codeAppendf("translatedFragPos.y -= middle.y - 1.0;");
- fsBuilder->codeAppendf("}");
-
- fsBuilder->codeAppendf("vec2 proxyDims = vec2(2.0*threshold+1.0);");
- fsBuilder->codeAppendf("vec2 texCoord = translatedFragPos / proxyDims;");
-
- fsBuilder->codeAppendf("%s = ", args.fOutputColor);
- fsBuilder->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers[0], "texCoord");
- fsBuilder->codeAppend(";");
+ fragBuilder->codeAppendf("vec2 rectCenter = (%s.xy + %s.zw)/2.0;", rectName, rectName);
+ fragBuilder->codeAppendf("vec2 translatedFragPos = %s.xy - %s.xy;", fragmentPos, rectName);
+ fragBuilder->codeAppendf("float threshold = %s + 2.0*%s;", cornerRadiusName, blurRadiusName);
+ fragBuilder->codeAppendf("vec2 middle = %s.zw - %s.xy - 2.0*threshold;", rectName, rectName);
+
+ fragBuilder->codeAppendf(
+ "if (translatedFragPos.x >= threshold && translatedFragPos.x < (middle.x+threshold)) {");
+ fragBuilder->codeAppendf("translatedFragPos.x = threshold;\n");
+ fragBuilder->codeAppendf("} else if (translatedFragPos.x >= (middle.x + threshold)) {");
+ fragBuilder->codeAppendf("translatedFragPos.x -= middle.x - 1.0;");
+ fragBuilder->codeAppendf("}");
+
+ fragBuilder->codeAppendf(
+ "if (translatedFragPos.y > threshold && translatedFragPos.y < (middle.y+threshold)) {");
+ fragBuilder->codeAppendf("translatedFragPos.y = threshold;");
+ fragBuilder->codeAppendf("} else if (translatedFragPos.y >= (middle.y + threshold)) {");
+ fragBuilder->codeAppendf("translatedFragPos.y -= middle.y - 1.0;");
+ fragBuilder->codeAppendf("}");
+
+ fragBuilder->codeAppendf("vec2 proxyDims = vec2(2.0*threshold+1.0);");
+ fragBuilder->codeAppendf("vec2 texCoord = translatedFragPos / proxyDims;");
+
+ fragBuilder->codeAppendf("%s = ", args.fOutputColor);
+ fragBuilder->appendTextureLookupAndModulate(args.fInputColor, args.fSamplers[0], "texCoord");
+ fragBuilder->codeAppend(";");
}
void GrGLRRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/effects/SkColorCubeFilter.cpp b/src/effects/SkColorCubeFilter.cpp
index 87746e03e0..a6f8e78e6e 100644
--- a/src/effects/SkColorCubeFilter.cpp
+++ b/src/effects/SkColorCubeFilter.cpp
@@ -264,34 +264,34 @@ void GrColorCubeEffect::GLSLProcessor::emitCode(EmitArgs& args) {
// Note: if implemented using texture3D in OpenGL ES older than OpenGL ES 3.0,
// the shader might need "#extension GL_OES_texture_3D : enable".
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// Unpremultiply color
- fsBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha, args.fInputColor);
- fsBuilder->codeAppendf("\tvec4 %s = vec4(%s.rgb / %s, %s);\n",
- unPMColor, args.fInputColor, nonZeroAlpha, nonZeroAlpha);
+ fragBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha, args.fInputColor);
+ fragBuilder->codeAppendf("\tvec4 %s = vec4(%s.rgb / %s, %s);\n",
+ unPMColor, args.fInputColor, nonZeroAlpha, nonZeroAlpha);
// Fit input color into the cube.
- fsBuilder->codeAppendf(
+ fragBuilder->codeAppendf(
"vec3 %s = vec3(%s.rg * vec2((%s - 1.0) * %s) + vec2(0.5 * %s), %s.b * (%s - 1.0));\n",
cubeIdx, unPMColor, colorCubeSizeUni, colorCubeInvSizeUni, colorCubeInvSizeUni,
unPMColor, colorCubeSizeUni);
// Compute y coord for for texture fetches.
- fsBuilder->codeAppendf("vec2 %s = vec2(%s.r, (floor(%s.b) + %s.g) * %s);\n",
- cCoords1, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSizeUni);
- fsBuilder->codeAppendf("vec2 %s = vec2(%s.r, (ceil(%s.b) + %s.g) * %s);\n",
- cCoords2, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSizeUni);
+ fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (floor(%s.b) + %s.g) * %s);\n",
+ cCoords1, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSizeUni);
+ fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (ceil(%s.b) + %s.g) * %s);\n",
+ cCoords2, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSizeUni);
// Apply the cube.
- fsBuilder->codeAppendf("%s = vec4(mix(", args.fOutputColor);
- fsBuilder->appendTextureLookup(args.fSamplers[0], cCoords1);
- fsBuilder->codeAppend(".rgb, ");
- fsBuilder->appendTextureLookup(args.fSamplers[0], cCoords2);
+ fragBuilder->codeAppendf("%s = vec4(mix(", args.fOutputColor);
+ fragBuilder->appendTextureLookup(args.fSamplers[0], cCoords1);
+ fragBuilder->codeAppend(".rgb, ");
+ fragBuilder->appendTextureLookup(args.fSamplers[0], cCoords2);
// Premultiply color by alpha. Note that the input alpha is not modified by this shader.
- fsBuilder->codeAppendf(".rgb, fract(%s.b)) * vec3(%s), %s.a);\n",
- cubeIdx, nonZeroAlpha, args.fInputColor);
+ fragBuilder->codeAppendf(".rgb, fract(%s.b)) * vec3(%s), %s.a);\n",
+ cubeIdx, nonZeroAlpha, args.fInputColor);
}
void GrColorCubeEffect::GLSLProcessor::onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index bb7dd94910..6e1c8ddb81 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -419,19 +419,19 @@ public:
// could optimize this case, but we aren't for now.
args.fInputColor = "vec4(1)";
}
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// The max() is to guard against 0 / 0 during unpremul when the incoming color is
// transparent black.
- fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n",
- args.fInputColor);
- fsBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha) + %s;\n",
- args.fOutputColor,
- args.fBuilder->getUniformCStr(fMatrixHandle),
- args.fInputColor,
- args.fBuilder->getUniformCStr(fVectorHandle));
- fsBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n",
- args.fOutputColor, args.fOutputColor);
- fsBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fOutputColor);
+ fragBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n",
+ args.fInputColor);
+ fragBuilder->codeAppendf("\t%s = %s * vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha) + %s;\n",
+ args.fOutputColor,
+ args.fBuilder->getUniformCStr(fMatrixHandle),
+ args.fInputColor,
+ args.fBuilder->getUniformCStr(fVectorHandle));
+ fragBuilder->codeAppendf("\t%s = clamp(%s, 0.0, 1.0);\n",
+ args.fOutputColor, args.fOutputColor);
+ fragBuilder->codeAppendf("\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fOutputColor);
}
protected:
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index 715391cf82..cd8b741d3d 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -557,31 +557,32 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
// a number smaller than that to approximate 0, but
// leave room for 32-bit float GPU rounding errors.
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- fsBuilder->codeAppendf("\t\tvec4 %s = ", dColor);
- fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(),
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor);
+ fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(),
args.fCoords[0].getType());
- fsBuilder->codeAppend(";\n");
+ fragBuilder->codeAppend(";\n");
// Unpremultiply the displacement
- fsBuilder->codeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
- dColor, dColor, nearZero, dColor, dColor);
- SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 1);
- fsBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.",
- cCoords, coords2D.c_str(), scaleUni, dColor);
+ fragBuilder->codeAppendf(
+ "\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
+ dColor, dColor, nearZero, dColor, dColor);
+ SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1);
+ fragBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.",
+ cCoords, coords2D.c_str(), scaleUni, dColor);
switch (fXChannelSelector) {
case SkDisplacementMapEffect::kR_ChannelSelectorType:
- fsBuilder->codeAppend("r");
+ fragBuilder->codeAppend("r");
break;
case SkDisplacementMapEffect::kG_ChannelSelectorType:
- fsBuilder->codeAppend("g");
+ fragBuilder->codeAppend("g");
break;
case SkDisplacementMapEffect::kB_ChannelSelectorType:
- fsBuilder->codeAppend("b");
+ fragBuilder->codeAppend("b");
break;
case SkDisplacementMapEffect::kA_ChannelSelectorType:
- fsBuilder->codeAppend("a");
+ fragBuilder->codeAppend("a");
break;
case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
default:
@@ -590,26 +591,26 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
switch (fYChannelSelector) {
case SkDisplacementMapEffect::kR_ChannelSelectorType:
- fsBuilder->codeAppend("r");
+ fragBuilder->codeAppend("r");
break;
case SkDisplacementMapEffect::kG_ChannelSelectorType:
- fsBuilder->codeAppend("g");
+ fragBuilder->codeAppend("g");
break;
case SkDisplacementMapEffect::kB_ChannelSelectorType:
- fsBuilder->codeAppend("b");
+ fragBuilder->codeAppend("b");
break;
case SkDisplacementMapEffect::kA_ChannelSelectorType:
- fsBuilder->codeAppend("a");
+ fragBuilder->codeAppend("a");
break;
case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
default:
SkDEBUGFAIL("Unknown Y channel selector");
}
- fsBuilder->codeAppend("-vec2(0.5));\t\t");
+ fragBuilder->codeAppend("-vec2(0.5));\t\t");
- fGLDomain.sampleTexture(fsBuilder, domain, args.fOutputColor, SkString(cCoords),
+ fGLDomain.sampleTexture(fragBuilder, domain, args.fOutputColor, SkString(cCoords),
args.fSamplers[1]);
- fsBuilder->codeAppend(";\n");
+ fragBuilder->codeAppend(";\n");
}
void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 9fda787d2c..4bb755e3ed 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -608,8 +608,10 @@ 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(GrGLSLFPBuilder*, const char* z) = 0;
- virtual void emitLightColor(GrGLSLFPBuilder*, const char *surfaceToLight);
+ virtual void emitSurfaceToLight(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, const char* z) = 0;
+ virtual void emitLightColor(GrGLSLFPBuilder*,
+ GrGLSLFragmentBuilder*,
+ const char *surfaceToLight);
// This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLight must call
// INHERITED::setData().
@@ -634,7 +636,7 @@ class GrGLDistantLight : public GrGLLight {
public:
virtual ~GrGLDistantLight() {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
- void emitSurfaceToLight(GrGLSLFPBuilder*, const char* z) override;
+ void emitSurfaceToLight(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, const char* z) override;
private:
typedef GrGLLight INHERITED;
@@ -647,7 +649,7 @@ class GrGLPointLight : public GrGLLight {
public:
virtual ~GrGLPointLight() {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
- void emitSurfaceToLight(GrGLSLFPBuilder*, const char* z) override;
+ void emitSurfaceToLight(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, const char* z) override;
private:
typedef GrGLLight INHERITED;
@@ -660,8 +662,10 @@ class GrGLSpotLight : public GrGLLight {
public:
virtual ~GrGLSpotLight() {}
void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override;
- void emitSurfaceToLight(GrGLSLFPBuilder*, const char* z) override;
- void emitLightColor(GrGLSLFPBuilder*, const char *surfaceToLight) override;
+ void emitSurfaceToLight(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, const char* z) override;
+ void emitLightColor(GrGLSLFPBuilder*,
+ GrGLSLFragmentBuilder*,
+ const char *surfaceToLight) override;
private:
typedef GrGLLight INHERITED;
@@ -1523,7 +1527,7 @@ protected:
*/
void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override;
- virtual void emitLightFunc(GrGLSLFPBuilder*, SkString* funcName) = 0;
+ virtual void emitLightFunc(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, SkString* funcName) = 0;
private:
typedef GrGLSLFragmentProcessor INHERITED;
@@ -1539,7 +1543,7 @@ private:
class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
public:
GrGLDiffuseLightingEffect(const GrProcessor&);
- void emitLightFunc(GrGLSLFPBuilder*, SkString* funcName) override;
+ void emitLightFunc(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, SkString* funcName) override;
protected:
void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override;
@@ -1555,7 +1559,7 @@ private:
class GrGLSpecularLightingEffect : public GrGLLightingEffect {
public:
GrGLSpecularLightingEffect(const GrProcessor&);
- void emitLightFunc(GrGLSLFPBuilder*, SkString* funcName) override;
+ void emitLightFunc(GrGLSLFPBuilder*, GrGLSLFragmentBuilder*, SkString* funcName) override;
protected:
void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override;
@@ -1659,8 +1663,9 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
kFloat_GrSLType, kDefault_GrSLPrecision,
"SurfaceScale");
fLight->emitLightColorUniform(args.fBuilder);
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString lightFunc;
- this->emitLightFunc(args.fBuilder, &lightFunc);
+ this->emitLightFunc(args.fBuilder, fragBuilder, &lightFunc);
static const GrGLSLShaderVar gSobelArgs[] = {
GrGLSLShaderVar("a", kFloat_GrSLType),
GrGLSLShaderVar("b", kFloat_GrSLType),
@@ -1671,27 +1676,26 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
GrGLSLShaderVar("scale", kFloat_GrSLType),
};
SkString sobelFuncName;
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
-
- fsBuilder->emitFunction(kFloat_GrSLType,
- "sobel",
- SK_ARRAY_COUNT(gSobelArgs),
- gSobelArgs,
- "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scale;\n",
- &sobelFuncName);
+ SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+
+ fragBuilder->emitFunction(kFloat_GrSLType,
+ "sobel",
+ SK_ARRAY_COUNT(gSobelArgs),
+ gSobelArgs,
+ "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scale;\n",
+ &sobelFuncName);
static const GrGLSLShaderVar gPointToNormalArgs[] = {
GrGLSLShaderVar("x", kFloat_GrSLType),
GrGLSLShaderVar("y", kFloat_GrSLType),
GrGLSLShaderVar("scale", kFloat_GrSLType),
};
SkString pointToNormalName;
- fsBuilder->emitFunction(kVec3f_GrSLType,
- "pointToNormal",
- SK_ARRAY_COUNT(gPointToNormalArgs),
- gPointToNormalArgs,
- "\treturn normalize(vec3(-x * scale, -y * scale, 1));\n",
- &pointToNormalName);
+ fragBuilder->emitFunction(kVec3f_GrSLType,
+ "pointToNormal",
+ SK_ARRAY_COUNT(gPointToNormalArgs),
+ gPointToNormalArgs,
+ "\treturn normalize(vec3(-x * scale, -y * scale, 1));\n",
+ &pointToNormalName);
static const GrGLSLShaderVar gInteriorNormalArgs[] = {
GrGLSLShaderVar("m", kFloat_GrSLType, 9),
@@ -1701,15 +1705,15 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
pointToNormalName.c_str(),
sobelFuncName.c_str());
SkString normalName;
- fsBuilder->emitFunction(kVec3f_GrSLType,
- "normal",
- SK_ARRAY_COUNT(gInteriorNormalArgs),
- gInteriorNormalArgs,
- normalBody.c_str(),
- &normalName);
+ fragBuilder->emitFunction(kVec3f_GrSLType,
+ "normal",
+ SK_ARRAY_COUNT(gInteriorNormalArgs),
+ gInteriorNormalArgs,
+ normalBody.c_str(),
+ &normalName);
- fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
- fsBuilder->codeAppend("\t\tfloat m[9];\n");
+ fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
+ fragBuilder->codeAppend("\t\tfloat m[9];\n");
const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni);
const char* surfScale = args.fBuilder->getUniformCStr(fSurfaceScaleUni);
@@ -1719,23 +1723,23 @@ void GrGLLightingEffect::emitCode(EmitArgs& args) {
for (int dx = -1; dx <= 1; dx++) {
SkString texCoords;
texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc);
- fsBuilder->codeAppendf("\t\tm[%d] = ", index++);
- fsBuilder->appendTextureLookup(args.fSamplers[0], texCoords.c_str());
- fsBuilder->codeAppend(".a;\n");
+ fragBuilder->codeAppendf("\t\tm[%d] = ", index++);
+ fragBuilder->appendTextureLookup(args.fSamplers[0], texCoords.c_str());
+ fragBuilder->codeAppend(".a;\n");
}
}
- fsBuilder->codeAppend("\t\tvec3 surfaceToLight = ");
+ fragBuilder->codeAppend("\t\tvec3 surfaceToLight = ");
SkString arg;
arg.appendf("%s * m[4]", surfScale);
- fLight->emitSurfaceToLight(args.fBuilder, arg.c_str());
- fsBuilder->codeAppend(";\n");
- fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
- args.fOutputColor, lightFunc.c_str(), normalName.c_str(), surfScale);
- fLight->emitLightColor(args.fBuilder, "surfaceToLight");
- fsBuilder->codeAppend(");\n");
+ fLight->emitSurfaceToLight(args.fBuilder, fragBuilder, arg.c_str());
+ fragBuilder->codeAppend(";\n");
+ fragBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
+ args.fOutputColor, lightFunc.c_str(), normalName.c_str(), surfScale);
+ fLight->emitLightColor(args.fBuilder, fragBuilder, "surfaceToLight");
+ fragBuilder->codeAppend(");\n");
SkString modulate;
GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
- fsBuilder->codeAppend(modulate.c_str());
+ fragBuilder->codeAppend(modulate.c_str());
}
void GrGLLightingEffect::GenKey(const GrProcessor& proc,
@@ -1764,7 +1768,9 @@ GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrProcessor& proc)
: INHERITED(proc) {
}
-void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder, SkString* funcName) {
+void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder,
+ GrGLSLFragmentBuilder* fragBuilder,
+ SkString* funcName) {
const char* kd;
fKDUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
@@ -1778,12 +1784,12 @@ void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder, SkString
SkString lightBody;
lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n", kd);
lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1.0);\n");
- builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType,
- "light",
- SK_ARRAY_COUNT(gLightArgs),
- gLightArgs,
- lightBody.c_str(),
- funcName);
+ fragBuilder->emitFunction(kVec4f_GrSLType,
+ "light",
+ SK_ARRAY_COUNT(gLightArgs),
+ gLightArgs,
+ lightBody.c_str(),
+ funcName);
}
void GrGLDiffuseLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
@@ -1846,7 +1852,9 @@ GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrProcessor& proc)
: INHERITED(proc) {
}
-void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder, SkString* funcName) {
+void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder,
+ GrGLSLFragmentBuilder* fragBuilder,
+ SkString* funcName) {
const char* ks;
const char* shininess;
@@ -1868,12 +1876,12 @@ void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder, SkStrin
lightBody.appendf("\tfloat colorScale = %s * pow(dot(normal, halfDir), %s);\n", ks, shininess);
lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\n");
lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b));\n");
- builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType,
- "light",
- SK_ARRAY_COUNT(gLightArgs),
- gLightArgs,
- lightBody.c_str(),
- funcName);
+ fragBuilder->emitFunction(kVec4f_GrSLType,
+ "light",
+ SK_ARRAY_COUNT(gLightArgs),
+ gLightArgs,
+ lightBody.c_str(),
+ funcName);
}
void GrGLSpecularLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman,
@@ -1891,8 +1899,10 @@ void GrGLLight::emitLightColorUniform(GrGLSLFPBuilder* builder) {
"LightColor");
}
-void GrGLLight::emitLightColor(GrGLSLFPBuilder* builder, const char *surfaceToLight) {
- builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this->lightColorUni()));
+void GrGLLight::emitLightColor(GrGLSLFPBuilder* builder,
+ GrGLSLFragmentBuilder* fragBuilder,
+ const char *surfaceToLight) {
+ fragBuilder->codeAppend(builder->getUniformCStr(this->lightColorUni()));
}
void GrGLLight::setData(const GrGLSLProgramDataManager& pdman,
@@ -1911,12 +1921,14 @@ void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman,
setUniformNormal3(pdman, fDirectionUni, distantLight->direction());
}
-void GrGLDistantLight::emitSurfaceToLight(GrGLSLFPBuilder* builder, const char* z) {
+void GrGLDistantLight::emitSurfaceToLight(GrGLSLFPBuilder* builder,
+ GrGLSLFragmentBuilder* fragBuilder,
+ const char* z) {
const char* dir;
fDirectionUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"LightDirection", &dir);
- builder->getFragmentShaderBuilder()->codeAppend(dir);
+ fragBuilder->codeAppend(dir);
}
///////////////////////////////////////////////////////////////////////////////
@@ -1929,14 +1941,15 @@ void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman,
setUniformPoint3(pdman, fLocationUni, pointLight->location());
}
-void GrGLPointLight::emitSurfaceToLight(GrGLSLFPBuilder* builder, const char* z) {
+void GrGLPointLight::emitSurfaceToLight(GrGLSLFPBuilder* builder,
+ GrGLSLFragmentBuilder* fragBuilder,
+ const char* z) {
const char* loc;
fLocationUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"LightLocation", &loc);
- GrGLSLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
- fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))",
- loc, fsBuilder->fragmentPosition(), z);
+ fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))",
+ loc, fragBuilder->fragmentPosition(), z);
}
///////////////////////////////////////////////////////////////////////////////
@@ -1954,18 +1967,20 @@ void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman,
setUniformNormal3(pdman, fSUni, spotLight->s());
}
-void GrGLSpotLight::emitSurfaceToLight(GrGLSLFPBuilder* builder, const char* z) {
+void GrGLSpotLight::emitSurfaceToLight(GrGLSLFPBuilder* builder,
+ GrGLSLFragmentBuilder* fragBuilder,
+ const char* z) {
const char* location;
fLocationUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"LightLocation", &location);
- GrGLSLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
- fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))",
- location, fsBuilder->fragmentPosition(), z);
+ fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))",
+ location, fragBuilder->fragmentPosition(), z);
}
void GrGLSpotLight::emitLightColor(GrGLSLFPBuilder* builder,
+ GrGLSLFragmentBuilder* fragBuilder,
const char *surfaceToLight) {
const char* color = builder->getUniformCStr(this->lightColorUni()); // created by parent class.
@@ -2004,15 +2019,14 @@ void GrGLSpotLight::emitLightColor(GrGLSLFPBuilder* builder,
color, cosOuter, coneScale);
lightColorBody.appendf("\t}\n");
lightColorBody.appendf("\treturn %s;\n", color);
- GrGLSLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
- fsBuilder->emitFunction(kVec3f_GrSLType,
- "lightColor",
- SK_ARRAY_COUNT(gLightColorArgs),
- gLightColorArgs,
- lightColorBody.c_str(),
- &fLightColorFunc);
-
- fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
+ fragBuilder->emitFunction(kVec3f_GrSLType,
+ "lightColor",
+ SK_ARRAY_COUNT(gLightColorArgs),
+ gLightColorArgs,
+ lightColorBody.c_str(),
+ &fLightColorFunc);
+
+ fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
}
#endif
diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp
index 7f6dd1b551..a131b0f434 100644
--- a/src/effects/SkLumaColorFilter.cpp
+++ b/src/effects/SkLumaColorFilter.cpp
@@ -72,14 +72,14 @@ public:
args.fInputColor = "vec4(1)";
}
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- fsBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb);\n",
- SK_ITU_BT709_LUM_COEFF_R,
- SK_ITU_BT709_LUM_COEFF_G,
- SK_ITU_BT709_LUM_COEFF_B,
- args.fInputColor);
- fsBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n",
- args.fOutputColor);
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ fragBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb);\n",
+ SK_ITU_BT709_LUM_COEFF_R,
+ SK_ITU_BT709_LUM_COEFF_G,
+ SK_ITU_BT709_LUM_COEFF_B,
+ args.fInputColor);
+ fragBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n",
+ args.fOutputColor);
}
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 61118f502c..911294444a 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -133,39 +133,39 @@ void GrGLMagnifierEffect::emitCode(EmitArgs& args) {
GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision, "Bounds");
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
- fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
- fsBuilder->codeAppendf("\t\tvec2 zoom_coord = %s + %s * %s;\n",
- args.fBuilder->getUniformCStr(fOffsetVar),
- coords2D.c_str(),
- args.fBuilder->getUniformCStr(fInvZoomVar));
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
+ fragBuilder->codeAppendf("\t\tvec2 zoom_coord = %s + %s * %s;\n",
+ args.fBuilder->getUniformCStr(fOffsetVar),
+ coords2D.c_str(),
+ args.fBuilder->getUniformCStr(fInvZoomVar));
const char* bounds = args.fBuilder->getUniformCStr(fBoundsVar);
- fsBuilder->codeAppendf("\t\tvec2 delta = (coord - %s.xy) * %s.zw;\n", bounds, bounds);
- fsBuilder->codeAppendf("\t\tdelta = min(delta, vec2(1.0, 1.0) - delta);\n");
- fsBuilder->codeAppendf("\t\tdelta = delta * %s;\n",
- args.fBuilder->getUniformCStr(fInvInsetVar));
-
- fsBuilder->codeAppend("\t\tfloat weight = 0.0;\n");
- fsBuilder->codeAppend("\t\tif (delta.s < 2.0 && delta.t < 2.0) {\n");
- fsBuilder->codeAppend("\t\t\tdelta = vec2(2.0, 2.0) - delta;\n");
- fsBuilder->codeAppend("\t\t\tfloat dist = length(delta);\n");
- fsBuilder->codeAppend("\t\t\tdist = max(2.0 - dist, 0.0);\n");
- fsBuilder->codeAppend("\t\t\tweight = min(dist * dist, 1.0);\n");
- fsBuilder->codeAppend("\t\t} else {\n");
- fsBuilder->codeAppend("\t\t\tvec2 delta_squared = delta * delta;\n");
- fsBuilder->codeAppend("\t\t\tweight = min(min(delta_squared.x, delta_squared.y), 1.0);\n");
- fsBuilder->codeAppend("\t\t}\n");
-
- fsBuilder->codeAppend("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\n");
- fsBuilder->codeAppend("\t\tvec4 output_color = ");
- fsBuilder->appendTextureLookup(args.fSamplers[0], "mix_coord");
- fsBuilder->codeAppend(";\n");
-
- fsBuilder->codeAppendf("\t\t%s = output_color;", args.fOutputColor);
+ fragBuilder->codeAppendf("\t\tvec2 delta = (coord - %s.xy) * %s.zw;\n", bounds, bounds);
+ fragBuilder->codeAppendf("\t\tdelta = min(delta, vec2(1.0, 1.0) - delta);\n");
+ fragBuilder->codeAppendf("\t\tdelta = delta * %s;\n",
+ args.fBuilder->getUniformCStr(fInvInsetVar));
+
+ fragBuilder->codeAppend("\t\tfloat weight = 0.0;\n");
+ fragBuilder->codeAppend("\t\tif (delta.s < 2.0 && delta.t < 2.0) {\n");
+ fragBuilder->codeAppend("\t\t\tdelta = vec2(2.0, 2.0) - delta;\n");
+ fragBuilder->codeAppend("\t\t\tfloat dist = length(delta);\n");
+ fragBuilder->codeAppend("\t\t\tdist = max(2.0 - dist, 0.0);\n");
+ fragBuilder->codeAppend("\t\t\tweight = min(dist * dist, 1.0);\n");
+ fragBuilder->codeAppend("\t\t} else {\n");
+ fragBuilder->codeAppend("\t\t\tvec2 delta_squared = delta * delta;\n");
+ fragBuilder->codeAppend("\t\t\tweight = min(min(delta_squared.x, delta_squared.y), 1.0);\n");
+ fragBuilder->codeAppend("\t\t}\n");
+
+ fragBuilder->codeAppend("\t\tvec2 mix_coord = mix(coord, zoom_coord, weight);\n");
+ fragBuilder->codeAppend("\t\tvec4 output_color = ");
+ fragBuilder->appendTextureLookup(args.fSamplers[0], "mix_coord");
+ fragBuilder->codeAppend(";\n");
+
+ fragBuilder->codeAppendf("\t\t%s = output_color;", args.fOutputColor);
SkString modulate;
GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
- fsBuilder->codeAppend(modulate.c_str());
+ fragBuilder->codeAppend(modulate.c_str());
}
void GrGLMagnifierEffect::onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 251938e500..fbc071fe58 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -297,16 +297,16 @@ void GrGLMorphologyEffect::emitCode(EmitArgs& args) {
"Range");
const char* range = args.fBuilder->getUniformCStr(fRangeUni);
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* func;
switch (fType) {
case GrMorphologyEffect::kErode_MorphologyType:
- fsBuilder->codeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", args.fOutputColor);
+ fragBuilder->codeAppendf("\t\t%s = vec4(1, 1, 1, 1);\n", args.fOutputColor);
func = "min";
break;
case GrMorphologyEffect::kDilate_MorphologyType:
- fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor);
+ fragBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor);
func = "max";
break;
default:
@@ -329,30 +329,30 @@ void GrGLMorphologyEffect::emitCode(EmitArgs& args) {
}
// vec2 coord = coord2D;
- fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
+ fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
// coord.x -= radius * pixelSize;
- fsBuilder->codeAppendf("\t\tcoord.%s -= %d.0 * %s; \n", dir, fRadius, pixelSizeInc);
+ fragBuilder->codeAppendf("\t\tcoord.%s -= %d.0 * %s; \n", dir, fRadius, pixelSizeInc);
if (fUseRange) {
// highBound = min(highBound, coord.x + (width-1) * pixelSize);
- fsBuilder->codeAppendf("\t\tfloat highBound = min(%s.y, coord.%s + %f * %s);",
- range, dir, float(width() - 1), pixelSizeInc);
+ fragBuilder->codeAppendf("\t\tfloat highBound = min(%s.y, coord.%s + %f * %s);",
+ range, dir, float(width() - 1), pixelSizeInc);
// coord.x = max(lowBound, coord.x);
- fsBuilder->codeAppendf("\t\tcoord.%s = max(%s.x, coord.%s);", dir, range, dir);
+ fragBuilder->codeAppendf("\t\tcoord.%s = max(%s.x, coord.%s);", dir, range, dir);
}
- fsBuilder->codeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", width());
- fsBuilder->codeAppendf("\t\t\t%s = %s(%s, ", args.fOutputColor, func, args.fOutputColor);
- fsBuilder->appendTextureLookup(args.fSamplers[0], "coord");
- fsBuilder->codeAppend(");\n");
+ fragBuilder->codeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", width());
+ fragBuilder->codeAppendf("\t\t\t%s = %s(%s, ", args.fOutputColor, func, args.fOutputColor);
+ fragBuilder->appendTextureLookup(args.fSamplers[0], "coord");
+ fragBuilder->codeAppend(");\n");
// coord.x += pixelSize;
- fsBuilder->codeAppendf("\t\t\tcoord.%s += %s;\n", dir, pixelSizeInc);
+ fragBuilder->codeAppendf("\t\t\tcoord.%s += %s;\n", dir, pixelSizeInc);
if (fUseRange) {
// coord.x = min(highBound, coord.x);
- fsBuilder->codeAppendf("\t\t\tcoord.%s = min(highBound, coord.%s);", dir, dir);
+ fragBuilder->codeAppendf("\t\t\tcoord.%s = min(highBound, coord.%s);", dir, dir);
}
- fsBuilder->codeAppend("\t\t}\n");
+ fragBuilder->codeAppend("\t\t}\n");
SkString modulate;
GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
- fsBuilder->codeAppend(modulate.c_str());
+ fragBuilder->codeAppend(modulate.c_str());
}
void GrGLMorphologyEffect::GenKey(const GrProcessor& proc,
diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp
index 914c534dfa..c1a6f701d7 100644
--- a/src/effects/SkPerlinNoiseShader.cpp
+++ b/src/effects/SkPerlinNoiseShader.cpp
@@ -621,19 +621,19 @@ GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor)
}
void GrGLPerlinNoise::emitCode(EmitArgs& args) {
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ SkString vCoords = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
fBaseFrequencyUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision,
- "baseFrequency");
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "baseFrequency");
const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyUni);
const char* stitchDataUni = nullptr;
if (fStitchTiles) {
fStitchDataUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision,
- "stitchData");
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "stitchData");
stitchDataUni = args.fBuilder->getUniformCStr(fStitchDataUni);
}
@@ -685,18 +685,18 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
// Adjust frequencies if we're stitching tiles
if (fStitchTiles) {
noiseCode.appendf("\n\tif(%s.x >= %s.x) { %s.x -= %s.x; }",
- floorVal, stitchData, floorVal, stitchData);
+ floorVal, stitchData, floorVal, stitchData);
noiseCode.appendf("\n\tif(%s.y >= %s.y) { %s.y -= %s.y; }",
- floorVal, stitchData, floorVal, stitchData);
+ floorVal, stitchData, floorVal, stitchData);
noiseCode.appendf("\n\tif(%s.z >= %s.x) { %s.z -= %s.x; }",
- floorVal, stitchData, floorVal, stitchData);
+ floorVal, stitchData, floorVal, stitchData);
noiseCode.appendf("\n\tif(%s.w >= %s.y) { %s.w -= %s.y; }",
- floorVal, stitchData, floorVal, stitchData);
+ floorVal, stitchData, floorVal, stitchData);
}
// Get texture coordinates and normalize
noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n",
- floorVal, floorVal);
+ floorVal, floorVal);
// Get permutation for x
{
@@ -704,8 +704,8 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
xCoords.appendf("vec2(%s.x, 0.5)", floorVal);
noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx);
- fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.c_str(),
- kVec2f_GrSLType);
+ fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.c_str(),
+ kVec2f_GrSLType);
noiseCode.append(".r;");
}
@@ -715,8 +715,8 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
xCoords.appendf("vec2(%s.z, 0.5)", floorVal);
noiseCode.appendf("\n\t%s.y = ", latticeIdx);
- fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.c_str(),
- kVec2f_GrSLType);
+ fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.c_str(),
+ kVec2f_GrSLType);
noiseCode.append(".r;");
}
@@ -740,8 +740,8 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
SkString latticeCoords("");
latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord);
noiseCode.appendf("\n\tvec4 %s = ", lattice);
- fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoords.c_str(),
- kVec2f_GrSLType);
+ fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoords.c_str(),
+ kVec2f_GrSLType);
noiseCode.appendf(".bgra;\n\t%s.x = ", uv);
noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
}
@@ -752,8 +752,8 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
SkString latticeCoords("");
latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord);
noiseCode.append("\n\tlattice = ");
- fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoords.c_str(),
- kVec2f_GrSLType);
+ fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoords.c_str(),
+ kVec2f_GrSLType);
noiseCode.appendf(".bgra;\n\t%s.y = ", uv);
noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
}
@@ -768,8 +768,8 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
SkString latticeCoords("");
latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord);
noiseCode.append("\n\tlattice = ");
- fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoords.c_str(),
- kVec2f_GrSLType);
+ fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoords.c_str(),
+ kVec2f_GrSLType);
noiseCode.appendf(".bgra;\n\t%s.y = ", uv);
noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
}
@@ -780,8 +780,8 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
SkString latticeCoords("");
latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord);
noiseCode.append("\n\tlattice = ");
- fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoords.c_str(),
- kVec2f_GrSLType);
+ fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoords.c_str(),
+ kVec2f_GrSLType);
noiseCode.appendf(".bgra;\n\t%s.x = ", uv);
noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
}
@@ -793,38 +793,38 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
SkString noiseFuncName;
if (fStitchTiles) {
- fsBuilder->emitFunction(kFloat_GrSLType,
- "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitchArgs),
- gPerlinNoiseStitchArgs, noiseCode.c_str(), &noiseFuncName);
+ fragBuilder->emitFunction(kFloat_GrSLType,
+ "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitchArgs),
+ gPerlinNoiseStitchArgs, noiseCode.c_str(), &noiseFuncName);
} else {
- fsBuilder->emitFunction(kFloat_GrSLType,
- "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs),
- gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncName);
+ fragBuilder->emitFunction(kFloat_GrSLType,
+ "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs),
+ gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncName);
}
// There are rounding errors if the floor operation is not performed here
- fsBuilder->codeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;",
- noiseVec, vCoords.c_str(), baseFrequencyUni);
+ fragBuilder->codeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;",
+ noiseVec, vCoords.c_str(), baseFrequencyUni);
// Clear the color accumulator
- fsBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", args.fOutputColor);
+ fragBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", args.fOutputColor);
if (fStitchTiles) {
// Set up TurbulenceInitial stitch values.
- fsBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni);
+ fragBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni);
}
- fsBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio);
+ fragBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio);
// Loop over all octaves
- fsBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {", fNumOctaves);
+ fragBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {", fNumOctaves);
- fsBuilder->codeAppendf("\n\t\t\t%s += ", args.fOutputColor);
+ fragBuilder->codeAppendf("\n\t\t\t%s += ", args.fOutputColor);
if (fType != SkPerlinNoiseShader::kFractalNoise_Type) {
- fsBuilder->codeAppend("abs(");
+ fragBuilder->codeAppend("abs(");
}
if (fStitchTiles) {
- fsBuilder->codeAppendf(
+ fragBuilder->codeAppendf(
"vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s),"
"\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))",
noiseFuncName.c_str(), chanCoordR, noiseVec, stitchData,
@@ -832,7 +832,7 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
noiseFuncName.c_str(), chanCoordB, noiseVec, stitchData,
noiseFuncName.c_str(), chanCoordA, noiseVec, stitchData);
} else {
- fsBuilder->codeAppendf(
+ fragBuilder->codeAppendf(
"vec4(\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s),"
"\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s))",
noiseFuncName.c_str(), chanCoordR, noiseVec,
@@ -841,32 +841,32 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) {
noiseFuncName.c_str(), chanCoordA, noiseVec);
}
if (fType != SkPerlinNoiseShader::kFractalNoise_Type) {
- fsBuilder->codeAppendf(")"); // end of "abs("
+ fragBuilder->codeAppendf(")"); // end of "abs("
}
- fsBuilder->codeAppendf(" * %s;", ratio);
+ fragBuilder->codeAppendf(" * %s;", ratio);
- fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec);
- fsBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio);
+ fragBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec);
+ fragBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio);
if (fStitchTiles) {
- fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData);
+ fragBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData);
}
- fsBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves
+ fragBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves
if (fType == SkPerlinNoiseShader::kFractalNoise_Type) {
// The value of turbulenceFunctionResult comes from ((turbulenceFunctionResult) + 1) / 2
// by fractalNoise and (turbulenceFunctionResult) by turbulence.
- fsBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);",
- args.fOutputColor,args.fOutputColor);
+ fragBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);",
+ args.fOutputColor,args.fOutputColor);
}
// Clamp values
- fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", args.fOutputColor, args.fOutputColor);
+ fragBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", args.fOutputColor, args.fOutputColor);
// Pre-multiply the result
- fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n",
- args.fOutputColor, args.fOutputColor,
- args.fOutputColor, args.fOutputColor);
+ fragBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n",
+ args.fOutputColor, args.fOutputColor,
+ args.fOutputColor, args.fOutputColor);
}
void GrGLPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLCaps&,
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 3e4877e89b..9d97411042 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -420,46 +420,46 @@ void GLColorTableEffect::emitCode(EmitArgs& args) {
"yoffsets", &yoffsets);
static const float kColorScaleFactor = 255.0f / 256.0f;
static const float kColorOffsetFactor = 1.0f / 512.0f;
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
if (nullptr == args.fInputColor) {
// the input color is solid white (all ones).
static const float kMaxValue = kColorScaleFactor + kColorOffsetFactor;
- fsBuilder->codeAppendf("\t\tvec4 coord = vec4(%f, %f, %f, %f);\n",
- kMaxValue, kMaxValue, kMaxValue, kMaxValue);
+ fragBuilder->codeAppendf("\t\tvec4 coord = vec4(%f, %f, %f, %f);\n",
+ kMaxValue, kMaxValue, kMaxValue, kMaxValue);
} else {
- fsBuilder->codeAppendf("\t\tfloat nonZeroAlpha = max(%s.a, .0001);\n", args.fInputColor);
- fsBuilder->codeAppendf("\t\tvec4 coord = vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha);\n",
- args.fInputColor);
- fsBuilder->codeAppendf("\t\tcoord = coord * %f + vec4(%f, %f, %f, %f);\n",
- kColorScaleFactor,
- kColorOffsetFactor, kColorOffsetFactor,
- kColorOffsetFactor, kColorOffsetFactor);
+ fragBuilder->codeAppendf("\t\tfloat nonZeroAlpha = max(%s.a, .0001);\n", args.fInputColor);
+ fragBuilder->codeAppendf("\t\tvec4 coord = vec4(%s.rgb / nonZeroAlpha, nonZeroAlpha);\n",
+ args.fInputColor);
+ fragBuilder->codeAppendf("\t\tcoord = coord * %f + vec4(%f, %f, %f, %f);\n",
+ kColorScaleFactor,
+ kColorOffsetFactor, kColorOffsetFactor,
+ kColorOffsetFactor, kColorOffsetFactor);
}
SkString coord;
- fsBuilder->codeAppendf("\t\t%s.a = ", args.fOutputColor);
+ fragBuilder->codeAppendf("\t\t%s.a = ", args.fOutputColor);
coord.printf("vec2(coord.a, %s.a)", yoffsets);
- fsBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str());
- fsBuilder->codeAppend(";\n");
+ fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str());
+ fragBuilder->codeAppend(";\n");
- fsBuilder->codeAppendf("\t\t%s.r = ", args.fOutputColor);
+ fragBuilder->codeAppendf("\t\t%s.r = ", args.fOutputColor);
coord.printf("vec2(coord.r, %s.r)", yoffsets);
- fsBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str());
- fsBuilder->codeAppend(";\n");
+ fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str());
+ fragBuilder->codeAppend(";\n");
- fsBuilder->codeAppendf("\t\t%s.g = ", args.fOutputColor);
+ fragBuilder->codeAppendf("\t\t%s.g = ", args.fOutputColor);
coord.printf("vec2(coord.g, %s.g)", yoffsets);
- fsBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str());
- fsBuilder->codeAppend(";\n");
+ fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str());
+ fragBuilder->codeAppend(";\n");
- fsBuilder->codeAppendf("\t\t%s.b = ", args.fOutputColor);
+ fragBuilder->codeAppendf("\t\t%s.b = ", args.fOutputColor);
coord.printf("vec2(coord.b, %s.b)", yoffsets);
- fsBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str());
- fsBuilder->codeAppend(";\n");
+ fragBuilder->appendTextureLookup(args.fSamplers[0], coord.c_str());
+ fragBuilder->codeAppend(";\n");
- fsBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fOutputColor);
+ fragBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", args.fOutputColor, args.fOutputColor);
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index f11d0787b9..8c944bae55 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -1027,61 +1027,61 @@ uint32_t GrGLGradientEffect::GenBaseGradientKey(const GrProcessor& processor) {
}
void GrGLGradientEffect::emitColor(GrGLSLFPBuilder* builder,
+ GrGLSLFragmentBuilder* fragBuilder,
const GrGradientEffect& ge,
const char* gradientTValue,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
- GrGLSLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){
- fsBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1.0));\n",
- builder->getUniformVariable(fColorStartUni).c_str(),
- builder->getUniformVariable(fColorEndUni).c_str(),
- gradientTValue);
+ fragBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1.0));\n",
+ builder->getUniformVariable(fColorStartUni).c_str(),
+ builder->getUniformVariable(fColorEndUni).c_str(),
+ gradientTValue);
// Note that we could skip this step if both colors are known to be opaque. Two
// considerations:
// The gradient SkShader reporting opaque is more restrictive than necessary in the two pt
// case. Make sure the key reflects this optimization (and note that it can use the same
// shader as thekBeforeIterp case). This same optimization applies to the 3 color case below.
if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) {
- fsBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
+ fragBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
}
- fsBuilder->codeAppendf("\t%s = %s;\n", outputColor,
- (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
+ fragBuilder->codeAppendf("\t%s = %s;\n", outputColor,
+ (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
} else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) {
- fsBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n",
- gradientTValue);
- fsBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n",
- builder->getUniformVariable(fColorStartUni).c_str());
+ fragBuilder->codeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n",
+ gradientTValue);
+ fragBuilder->codeAppendf("\tvec4 colorTemp = clamp(oneMinus2t, 0.0, 1.0) * %s;\n",
+ builder->getUniformVariable(fColorStartUni).c_str());
if (!builder->glslCaps()->canUseMinAndAbsTogether()) {
// The Tegra3 compiler will sometimes never return if we have
// min(abs(oneMinus2t), 1.0), or do the abs first in a separate expression.
- fsBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n");
- fsBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n");
- fsBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n",
- builder->getUniformVariable(fColorMidUni).c_str());
+ fragBuilder->codeAppend("\tfloat minAbs = abs(oneMinus2t);\n");
+ fragBuilder->codeAppend("\tminAbs = minAbs > 1.0 ? 1.0 : minAbs;\n");
+ fragBuilder->codeAppendf("\tcolorTemp += (1.0 - minAbs) * %s;\n",
+ builder->getUniformVariable(fColorMidUni).c_str());
} else {
- fsBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1.0)) * %s;\n",
- builder->getUniformVariable(fColorMidUni).c_str());
+ fragBuilder->codeAppendf("\tcolorTemp += (1.0 - min(abs(oneMinus2t), 1.0)) * %s;\n",
+ builder->getUniformVariable(fColorMidUni).c_str());
}
- fsBuilder->codeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s;\n",
- builder->getUniformVariable(fColorEndUni).c_str());
+ fragBuilder->codeAppendf("\tcolorTemp += clamp(-oneMinus2t, 0.0, 1.0) * %s;\n",
+ builder->getUniformVariable(fColorEndUni).c_str());
if (GrGradientEffect::kAfterInterp_PremulType == ge.getPremulType()) {
- fsBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
+ fragBuilder->codeAppend("\tcolorTemp.rgb *= colorTemp.a;\n");
}
- fsBuilder->codeAppendf("\t%s = %s;\n", outputColor,
- (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
+ fragBuilder->codeAppendf("\t%s = %s;\n", outputColor,
+ (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
} else {
- fsBuilder->codeAppendf("\tvec2 coord = vec2(%s, %s);\n",
- gradientTValue,
- builder->getUniformVariable(fFSYUni).c_str());
- fsBuilder->codeAppendf("\t%s = ", outputColor);
- fsBuilder->appendTextureLookupAndModulate(inputColor,
- samplers[0],
- "coord");
- fsBuilder->codeAppend(";\n");
+ fragBuilder->codeAppendf("\tvec2 coord = vec2(%s, %s);\n",
+ gradientTValue,
+ builder->getUniformVariable(fFSYUni).c_str());
+ fragBuilder->codeAppendf("\t%s = ", outputColor);
+ fragBuilder->appendTextureLookupAndModulate(inputColor,
+ samplers[0],
+ "coord");
+ fragBuilder->codeAppend(";\n");
}
}
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 86f63f9529..8af65a47b7 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -426,6 +426,7 @@ protected:
// control flows inside -- 2 color gradients, 3 color symmetric gradients (both using
// native GLSL mix), and 4+ color gradients that use the traditional texture lookup.
void emitColor(GrGLSLFPBuilder* builder,
+ GrGLSLFragmentBuilder* fragBuilder,
const GrGradientEffect&,
const char* gradientTValue,
const char* outputColor,
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index fdc016c0d2..b60ee971f8 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -604,9 +604,13 @@ const GrFragmentProcessor* GrLinearGradient::TestCreate(GrProcessorTestData* d)
void GrGLLinearGradient::emitCode(EmitArgs& args) {
const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>();
this->emitUniforms(args.fBuilder, ge);
- SkString t = args.fBuilder->getFragmentShaderBuilder()->ensureFSCoords2D(args.fCoords, 0);
+ SkString t = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0);
t.append(".x");
- this->emitColor(args.fBuilder, ge, t.c_str(), args.fOutputColor, args.fInputColor,
+ this->emitColor(args.fBuilder,
+ args.fFragBuilder,
+ ge, t.c_str(),
+ args.fOutputColor,
+ args.fInputColor,
args.fSamplers);
}
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index c9ff20fa92..efd41c4a8a 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -501,9 +501,13 @@ void GrGLRadialGradient::emitCode(EmitArgs& args) {
const GrRadialGradient& ge = args.fFp.cast<GrRadialGradient>();
this->emitUniforms(args.fBuilder, ge);
SkString t("length(");
- t.append(args.fBuilder->getFragmentShaderBuilder()->ensureFSCoords2D(args.fCoords, 0));
+ t.append(args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0));
t.append(")");
- this->emitColor(args.fBuilder, ge, t.c_str(), args.fOutputColor, args.fInputColor,
+ this->emitColor(args.fBuilder,
+ args.fFragBuilder,
+ ge, t.c_str(),
+ args.fOutputColor,
+ args.fInputColor,
args.fSamplers);
}
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index c41c2a37a6..f2f14c4b58 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -248,8 +248,7 @@ const GrFragmentProcessor* GrSweepGradient::TestCreate(GrProcessorTestData* d) {
void GrGLSweepGradient::emitCode(EmitArgs& args) {
const GrSweepGradient& ge = args.fFp.cast<GrSweepGradient>();
this->emitUniforms(args.fBuilder, ge);
- SkString coords2D = args.fBuilder->getFragmentShaderBuilder()
- ->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2D = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0);
SkString t;
// 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi]
// On Intel GPU there is an issue where it reads the second arguement to atan "- %s.x" as an int
@@ -261,7 +260,11 @@ void GrGLSweepGradient::emitCode(EmitArgs& args) {
t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5",
coords2D.c_str(), coords2D.c_str());
}
- this->emitColor(args.fBuilder, ge, t.c_str(), args.fOutputColor, args.fInputColor,
+ this->emitColor(args.fBuilder,
+ args.fFragBuilder,
+ ge, t.c_str(),
+ args.fOutputColor,
+ args.fInputColor,
args.fSamplers);
}
diff --git a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp
index 653aa016a3..4633bc25e1 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp
@@ -242,9 +242,9 @@ void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) {
SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType());
const char* coords2D;
SkString bVar;
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
if (kVec3f_GrSLType == args.fCoords[0].getType()) {
- fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x / %s.z);\n",
+ fragBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x / %s.z);\n",
args.fCoords[0].c_str(), args.fCoords[0].c_str(),
args.fCoords[1].c_str(), args.fCoords[1].c_str());
coords2D = "interpolants.xy";
@@ -256,23 +256,28 @@ void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) {
// output will default to transparent black (we simply won't write anything
// else to it if invalid, instead of discarding or returning prematurely)
- fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor);
+ fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor);
// c = (x^2)+(y^2) - params[1]
- fsBuilder->codeAppendf("\tfloat %s = dot(%s, %s) - %s;\n",
+ fragBuilder->codeAppendf("\tfloat %s = dot(%s, %s) - %s;\n",
cName.c_str(), coords2D, coords2D, p1.c_str());
// linear case: t = -c/b
- fsBuilder->codeAppendf("\tfloat %s = -(%s / %s);\n", tName.c_str(),
+ fragBuilder->codeAppendf("\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
- fsBuilder->codeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
+ fragBuilder->codeAppendf("\tif (%s * %s + %s > 0.0) {\n", tName.c_str(),
p2.c_str(), p0.c_str());
- fsBuilder->codeAppend("\t");
- this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fInputColor,
+ fragBuilder->codeAppend("\t");
+ this->emitColor(args.fBuilder,
+ fragBuilder,
+ ge,
+ tName.c_str(),
+ args.fOutputColor,
+ args.fInputColor,
args.fSamplers);
- fsBuilder->codeAppend("\t}\n");
+ fragBuilder->codeAppend("\t}\n");
}
void GLEdge2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman,
@@ -511,35 +516,40 @@ void GLFocalOutside2PtConicalEffect::emitCode(EmitArgs& args) {
args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1);
// if we have a vec3 from being in perspective, convert it to a vec2 first
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* coords2D = coords2DString.c_str();
// t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2)
// output will default to transparent black (we simply won't write anything
// else to it if invalid, instead of discarding or returning prematurely)
- fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor);
+ fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor);
- fsBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D);
- fsBuilder->codeAppendf("\tfloat ys = %s.y * %s.y;\n", coords2D, coords2D);
- fsBuilder->codeAppendf("\tfloat d = xs + %s * ys;\n", p1.c_str());
+ fragBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D);
+ fragBuilder->codeAppendf("\tfloat ys = %s.y * %s.y;\n", coords2D, coords2D);
+ fragBuilder->codeAppendf("\tfloat d = xs + %s * ys;\n", p1.c_str());
// Must check to see if we flipped the circle order (to make sure start radius < end radius)
// If so we must also flip sign on sqrt
if (!fIsFlipped) {
- fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + sqrt(d);\n", tName.c_str(),
- coords2D, p0.c_str());
+ fragBuilder->codeAppendf("\tfloat %s = %s.x * %s + sqrt(d);\n", tName.c_str(),
+ coords2D, p0.c_str());
} else {
- fsBuilder->codeAppendf("\tfloat %s = %s.x * %s - sqrt(d);\n", tName.c_str(),
- coords2D, p0.c_str());
+ fragBuilder->codeAppendf("\tfloat %s = %s.x * %s - sqrt(d);\n", tName.c_str(),
+ coords2D, p0.c_str());
}
- fsBuilder->codeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str());
- fsBuilder->codeAppend("\t\t");
- this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fInputColor,
+ fragBuilder->codeAppendf("\tif (%s >= 0.0 && d >= 0.0) {\n", tName.c_str());
+ fragBuilder->codeAppend("\t\t");
+ this->emitColor(args.fBuilder,
+ fragBuilder,
+ ge,
+ tName.c_str(),
+ args.fOutputColor,
+ args.fInputColor,
args.fSamplers);
- fsBuilder->codeAppend("\t}\n");
+ fragBuilder->codeAppend("\t}\n");
}
void GLFocalOutside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman,
@@ -713,15 +723,20 @@ void GLFocalInside2PtConicalEffect::emitCode(EmitArgs& args) {
GrGLSLShaderVar focal = args.fBuilder->getUniformVariable(fFocalUni);
// if we have a vec3 from being in perspective, convert it to a vec2 first
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* coords2D = coords2DString.c_str();
// t = p.x * focalX + length(p)
- fsBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_str(),
+ fragBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_str(),
coords2D, focal.c_str(), coords2D);
- this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fInputColor,
+ this->emitColor(args.fBuilder,
+ fragBuilder,
+ ge,
+ tName.c_str(),
+ args.fOutputColor,
+ args.fInputColor,
args.fSamplers);
}
@@ -963,8 +978,8 @@ void GLCircleInside2PtConicalEffect::emitCode(EmitArgs& args) {
GrGLSLShaderVar params = args.fBuilder->getUniformVariable(fParamUni);
// if we have a vec3 from being in perspective, convert it to a vec2 first
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* coords2D = coords2DString.c_str();
// p = coords2D
@@ -975,13 +990,18 @@ void GLCircleInside2PtConicalEffect::emitCode(EmitArgs& args) {
// C = 1 / A
// d = dot(e, p) + B
// t = d +/- sqrt(d^2 - A * dot(p, p) + C)
- fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D);
- fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, center.c_str(),
- params.c_str());
- fsBuilder->codeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\n",
- tName.c_str(), params.c_str(), params.c_str());
-
- this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fInputColor,
+ fragBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D);
+ fragBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, center.c_str(),
+ params.c_str());
+ fragBuilder->codeAppendf("\tfloat %s = d + sqrt(d * d - %s.x * pDotp + %s.z);\n",
+ tName.c_str(), params.c_str(), params.c_str());
+
+ this->emitColor(args.fBuilder,
+ fragBuilder,
+ ge,
+ tName.c_str(),
+ args.fOutputColor,
+ args.fInputColor,
args.fSamplers);
}
@@ -1193,13 +1213,13 @@ void GLCircleOutside2PtConicalEffect::emitCode(EmitArgs& args) {
GrGLSLShaderVar params = args.fBuilder->getUniformVariable(fParamUni);
// if we have a vec3 from being in perspective, convert it to a vec2 first
- GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
- SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
+ GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
+ SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* coords2D = coords2DString.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)
- fsBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor);
+ fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColor);
// p = coords2D
// e = center end
@@ -1210,25 +1230,30 @@ void GLCircleOutside2PtConicalEffect::emitCode(EmitArgs& args) {
// d = dot(e, p) + B
// t = d +/- sqrt(d^2 - A * dot(p, p) + C)
- fsBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D);
- fsBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, center.c_str(),
- params.c_str());
- fsBuilder->codeAppendf("\tfloat deter = d * d - %s.x * pDotp + %s.z;\n", params.c_str(),
- params.c_str());
+ fragBuilder->codeAppendf("\tfloat pDotp = dot(%s, %s);\n", coords2D, coords2D);
+ fragBuilder->codeAppendf("\tfloat d = dot(%s, %s) + %s.y;\n", coords2D, center.c_str(),
+ params.c_str());
+ fragBuilder->codeAppendf("\tfloat deter = d * d - %s.x * pDotp + %s.z;\n", params.c_str(),
+ params.c_str());
// Must check to see if we flipped the circle order (to make sure start radius < end radius)
// If so we must also flip sign on sqrt
if (!fIsFlipped) {
- fsBuilder->codeAppendf("\tfloat %s = d + sqrt(deter);\n", tName.c_str());
+ fragBuilder->codeAppendf("\tfloat %s = d + sqrt(deter);\n", tName.c_str());
} else {
- fsBuilder->codeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str());
+ fragBuilder->codeAppendf("\tfloat %s = d - sqrt(deter);\n", tName.c_str());
}
- fsBuilder->codeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str(), params.c_str());
- fsBuilder->codeAppend("\t\t");
- this->emitColor(args.fBuilder, ge, tName.c_str(), args.fOutputColor, args.fInputColor,
+ fragBuilder->codeAppendf("\tif (%s >= %s.w && deter >= 0.0) {\n", tName.c_str(), params.c_str());
+ fragBuilder->codeAppend("\t\t");
+ this->emitColor(args.fBuilder,
+ fragBuilder,
+ ge,
+ tName.c_str(),
+ args.fOutputColor,
+ args.fInputColor,
args.fSamplers);
- fsBuilder->codeAppend("\t}\n");
+ fragBuilder->codeAppend("\t}\n");
}
void GLCircleOutside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman,