diff options
author | 2013-10-10 06:30:18 +0000 | |
---|---|---|
committer | 2013-10-10 06:30:18 +0000 | |
commit | 824c346b6e0e114063c1a8ad4ba7c3a669ee2cff (patch) | |
tree | 746fca51437b25e3a6e851a42ec40ec3d5ac6ee0 /src/effects | |
parent | ab9d30cb01d0c8401537dc115aba2842b0f4f27f (diff) |
Express (GLSL expression, possibly known value) pairs as a class
Express (GLSL expression, possibly known value) pairs as a class
instead of two variables Introduces GrGLSLExpr<N> to encapsulate
the expression and possibly constant-folded value of the expression.
This simplifies passing of the expressions to functions.
Changes the shaders with following patterns:
{ // Stage 0: Linear Gradient
vec4 colorTemp = mix(uGradientStartColor_Stage0, uGradientEndColor_Stage0, clamp(vMatrixCoord_Stage0.x, 0.0, 1
colorTemp.rgb *= colorTemp.a;
- output_Stage0 = vec4((vColor) * (colorTemp));
+ output_Stage0 = (vColor * colorTemp);
+ }
Previously the vector cast was always added if constant folding was
effective, regardless of the term dimensions. Now the vector upcast is
not inserted in places where it is not needed, ie. when the binary
operator term is of the target dimension.
Also, some parentheses can be omitted. It is assumed that
GrGLSLExpr<N>("string") constructors construct a simple expression or
parenthesized expression.
Otherwise the shader code remains identical.
R=jvanverth@google.com, bsalomon@google.com, robertphillips@google.com
Author: kkinnunen@nvidia.com
Review URL: https://codereview.chromium.org/25048002
git-svn-id: http://skia.googlecode.com/svn/trunk@11690 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/SkArithmeticMode.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkBitmapAlphaThresholdShader.cpp | 8 | ||||
-rw-r--r-- | src/effects/SkColorMatrixFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkLumaColorFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkLumaXfermode.cpp | 2 | ||||
-rw-r--r-- | src/effects/gradients/SkGradientShader.cpp | 14 |
6 files changed, 10 insertions, 20 deletions
diff --git a/src/effects/SkArithmeticMode.cpp b/src/effects/SkArithmeticMode.cpp index d746ecbc31..fff03c291f 100644 --- a/src/effects/SkArithmeticMode.cpp +++ b/src/effects/SkArithmeticMode.cpp @@ -366,7 +366,7 @@ void GrGLArithmeticEffect::emitCode(GrGLShaderBuilder* builder, // We don't try to optimize for this case at all if (NULL == inputColor) { - builder->fsCodeAppendf("\t\tconst vec4 src = %s;\n", GrGLSLOnesVecf(4)); + builder->fsCodeAppendf("\t\tconst vec4 src = vec4(1);\n"); } else { builder->fsCodeAppendf("\t\tvec4 src = %s;\n", inputColor); if (gUseUnpremul) { diff --git a/src/effects/SkBitmapAlphaThresholdShader.cpp b/src/effects/SkBitmapAlphaThresholdShader.cpp index c8db3a56ca..69e22c9608 100644 --- a/src/effects/SkBitmapAlphaThresholdShader.cpp +++ b/src/effects/SkBitmapAlphaThresholdShader.cpp @@ -149,12 +149,8 @@ public: "\t\t\tcolor.a = thresh;\n" "\t\t}\n"); - builder->fsCodeAppend("color = "); - SkString outStr; - outStr.appendf("\t\t%s = ", outputColor); - GrGLSLModulatef<4>(&outStr, inputColor, "color"); - outStr.append(";\n"); - builder->fsCodeAppend(outStr.c_str()); + builder->fsCodeAppendf("color = %s = %s;\n", outputColor, + (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<4>("color")).c_str()); } virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& e) SK_OVERRIDE { diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index 484836a5b3..1e3c779ec6 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -410,7 +410,7 @@ public: if (NULL == inputColor) { // could optimize this case, but we aren't for now. - inputColor = GrGLSLOnesVecf(4); + inputColor = "vec4(1)"; } // The max() is to guard against 0 / 0 during unpremul when the incoming color is // transparent black. diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp index c9f1fb02c3..eff1645d27 100644 --- a/src/effects/SkLumaColorFilter.cpp +++ b/src/effects/SkLumaColorFilter.cpp @@ -120,7 +120,7 @@ public: const TransformedCoordsArray&, const TextureSamplerArray&) SK_OVERRIDE { if (NULL == inputColor) { - inputColor = GrGLSLOnesVecf(4); + inputColor = "vec4(1)"; } // The max() is to guard against 0 / 0 during unpremul when the incoming color is diff --git a/src/effects/SkLumaXfermode.cpp b/src/effects/SkLumaXfermode.cpp index 3ecb0bec4a..aa3d780aa0 100644 --- a/src/effects/SkLumaXfermode.cpp +++ b/src/effects/SkLumaXfermode.cpp @@ -214,7 +214,7 @@ void GrGLLumaMaskEffect::emitCode(GrGLShaderBuilder* builder, const char* dstColor = builder->dstColor(); SkASSERT(NULL != dstColor); if (NULL == inputColor) { - inputColor = GrGLSLOnesVecf(4); + inputColor = "vec4(1)"; } const char *opA = lumaOpA<char>(lumaEffect.getMode(), inputColor, dstColor); diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index dff2d8cd43..9360ba920e 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -950,11 +950,8 @@ void GrGLGradientEffect::emitColor(GrGLShaderBuilder* builder, builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); } - SkString output; - builder->fsCodeAppendf("\t%s = ", outputColor); - GrGLSLModulatef<4>(&output, inputColor, "colorTemp"); - builder->fsCodeAppend(output.c_str()); - builder->fsCodeAppend(";\n"); + builder->fsCodeAppendf("\t%s = %s;\n", outputColor, + (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<4>("colorTemp")).c_str()); } else if (GrGradientEffect::kThree_ColorType == ColorTypeFromKey(key)){ builder->fsCodeAppendf("\tfloat oneMinus2t = 1.0 - (2.0 * (%s));\n", gradientTValue); @@ -977,11 +974,8 @@ void GrGLGradientEffect::emitColor(GrGLShaderBuilder* builder, builder->fsCodeAppend("\tcolorTemp.rgb *= colorTemp.a;\n"); } - SkString output; - builder->fsCodeAppendf("\t%s = ", outputColor); - GrGLSLModulatef<4>(&output, inputColor, "colorTemp"); - builder->fsCodeAppend(output.c_str()); - builder->fsCodeAppend(";\n"); + builder->fsCodeAppendf("\t%s = %s;\n", outputColor, + (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<4>("colorTemp")).c_str()); } else { builder->fsCodeAppendf("\tvec2 coord = vec2(%s, %s);\n", gradientTValue, |