Diff
Modified: trunk/LayoutTests/ChangeLog (136253 => 136254)
--- trunk/LayoutTests/ChangeLog 2012-11-30 18:14:48 UTC (rev 136253)
+++ trunk/LayoutTests/ChangeLog 2012-11-30 18:47:23 UTC (rev 136254)
@@ -1,3 +1,19 @@
+2012-11-30 Michelangelo De Simone <[email protected]>
+
+ [CSS Shaders] Clamp input colors before blending
+ https://bugs.webkit.org/show_bug.cgi?id=98962
+
+ Reviewed by Dean Jackson.
+
+ Test to check the correct clamping of color values.
+
+ * css3/filters/custom/custom-filter-color-clamping-expected.html: Added.
+ * css3/filters/custom/custom-filter-color-clamping-negative-expected.html: Added.
+ * css3/filters/custom/custom-filter-color-clamping-negative.html: Added.
+ * css3/filters/custom/custom-filter-color-clamping.html: Added.
+ * css3/filters/resources/custom-filter-color-clamping-negative.fs: Added.
+ * css3/filters/resources/custom-filter-color-clamping.fs: Added.
+
2012-11-30 Abhishek Arya <[email protected]>
Crash due to intruding float not removed after writing mode changed.
Added: trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix-expected.html (0 => 136254)
--- trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix-expected.html (rev 0)
+++ trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix-expected.html 2012-11-30 18:47:23 UTC (rev 136254)
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Tests that css_colorMatrix multiplication result is clamped to 1</title>
+ <style>
+ #lonelydiv {
+ width: 100px;
+ height: 100px;
+ border: 1px solid black;
+ background: rgb(50%, 50%, 50%);
+ }
+ </style>
+</head>
+<body>
+ <div id="lonelydiv"></div>
+</body>
+</html>
Added: trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix-negative-expected.html (0 => 136254)
--- trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix-negative-expected.html (rev 0)
+++ trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix-negative-expected.html 2012-11-30 18:47:23 UTC (rev 136254)
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Tests that css_colorMatrix multiplication result is clamped to 0</title>
+ <style>
+ #lonelydiv {
+ width: 100px;
+ height: 100px;
+ border: 1px solid black;
+ background: rgb(0, 0, 0);
+ }
+ </style>
+</head>
+<body>
+ <div id="lonelydiv"></div>
+</body>
+</html>
Added: trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix-negative.html (0 => 136254)
--- trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix-negative.html (rev 0)
+++ trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix-negative.html 2012-11-30 18:47:23 UTC (rev 136254)
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Tests that css_colorMatrix multiplication result is clamped to 0</title>
+ <script>
+ if (window.testRunner) {
+ window.testRunner.overridePreference("WebKitCSSCustomFilterEnabled", "1");
+ window.testRunner.overridePreference("WebKitWebGLEnabled", "1");
+ window.testRunner.waitUntilDone();
+ }
+
+ function runTest() {
+ // We need to run the tests after the downloading succeeded.
+ if (window.testRunner)
+ window.testRunner.notifyDone();
+ }
+ </script>
+ <style>
+ #lonelydiv {
+ width: 100px;
+ height: 100px;
+ border: 1px solid black;
+ background: rgb(20%, 20%, 20%);
+ -webkit-filter: custom(none mix(url('../resources/custom-filter-clamp-css-color-matrix-negative.fs') multiply source-atop));
+ }
+ </style>
+</head>
+<body _onload_="runTest()">
+ <!--
+ Let:
+ clamp(value) = A function that clamps values between 0.0 and 1.0
+ elementColor = vec4(0.2, 0.2, 0.2, 1.0)
+ css_ColorMatrix = Matrix with diagonal (-10.0, -10.0, -10.0, 1.0)
+ css_MixColor = vec4(-0.5, -0.5, -0.5, 1.0)
+
+ Correct clamped result:
+ result = clamp(css_ColorMatrix * elementColor) * css_MixColor
+ result.r = clamp(-10.0 * 0.2) * 0.5
+ result.r = clamp(-2.0) * 0.5
+ result.r = 0.0 * -0.5
+ result.r = 0.0
+ result.r = result.g = result.b => black
+
+ Incorrect unclamped result:
+ result = (css_ColorMatrix * elementColor) * css_MixColor
+ result.r = (-10.0 * 0.2) * 0.5
+ result.r = -2.0 * -0.5
+ result.r = 1.0
+ result.r = result.g = result.b => white
+ -->
+ <div id="lonelydiv"></div>
+</body>
+</html>
Added: trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix.html (0 => 136254)
--- trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix.html (rev 0)
+++ trunk/LayoutTests/css3/filters/custom/custom-filter-clamp-css-color-matrix.html 2012-11-30 18:47:23 UTC (rev 136254)
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Tests that css_colorMatrix multiplication result is clamped to 1</title>
+ <script>
+ if (window.testRunner) {
+ window.testRunner.overridePreference("WebKitCSSCustomFilterEnabled", "1");
+ window.testRunner.overridePreference("WebKitWebGLEnabled", "1");
+ window.testRunner.waitUntilDone();
+ }
+
+ function runTest() {
+ // We need to run the tests after the downloading succeeded.
+ if (window.testRunner)
+ window.testRunner.notifyDone();
+ }
+ </script>
+ <style>
+ #lonelydiv {
+ width: 100px;
+ height: 100px;
+ border: 1px solid black;
+ background: rgb(20%, 20%, 20%);
+ -webkit-filter: custom(none mix(url('../resources/custom-filter-clamp-css-color-matrix.fs') multiply source-atop));
+ }
+ </style>
+</head>
+<body _onload_="runTest()">
+ <!--
+ Let:
+ clamp(value) = A function that clamps values between 0.0 and 1.0
+ elementColor = vec4(0.2, 0.2, 0.2, 1.0)
+ css_ColorMatrix = Matrix with diagonal (10.0, 10.0, 10.0, 10.0)
+ css_MixColor = vec4(0.5, 0.5, 0.5, 1.0)
+
+ Correct clamped result:
+ result = clamp(css_ColorMatrix * elementColor) * css_MixColor
+ result.r = clamp(10.0 * 0.2) * 0.5
+ result.r = clamp(2.0) * 0.5
+ result.r = 1.0 * 0.5
+ result.r = 0.5
+ result.r = result.g = result.b => gray
+
+ Incorrect unclamped result:
+ result = (css_ColorMatrix * elementColor) * css_MixColor
+ result.r = (10.0 * 0.2) * 0.5
+ result.r = 2.0 * 0.5
+ result.r = 1.0
+ result.r = result.g = result.b => white
+ -->
+ <div id="lonelydiv"></div>
+</body>
+</html>
Added: trunk/LayoutTests/css3/filters/resources/custom-filter-clamp-css-color-matrix-negative.fs (0 => 136254)
--- trunk/LayoutTests/css3/filters/resources/custom-filter-clamp-css-color-matrix-negative.fs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/custom-filter-clamp-css-color-matrix-negative.fs 2012-11-30 18:47:23 UTC (rev 136254)
@@ -0,0 +1,10 @@
+precision mediump float;
+
+void main(void)
+{
+ css_ColorMatrix = mat4(-10.0, 0.0, 0.0, 0.0,
+ 0.0, -10.0, 0.0, 0.0,
+ 0.0, 0.0, -10.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+ css_MixColor = vec4(-0.5, -0.5, -0.5, 1.0);
+}
Added: trunk/LayoutTests/css3/filters/resources/custom-filter-clamp-css-color-matrix.fs (0 => 136254)
--- trunk/LayoutTests/css3/filters/resources/custom-filter-clamp-css-color-matrix.fs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/custom-filter-clamp-css-color-matrix.fs 2012-11-30 18:47:23 UTC (rev 136254)
@@ -0,0 +1,10 @@
+precision mediump float;
+
+void main(void)
+{
+ css_ColorMatrix = mat4(10.0, 0.0, 0.0, 0.0,
+ 0.0, 10.0, 0.0, 0.0,
+ 0.0, 0.0, 10.0, 0.0,
+ 0.0, 0.0, 0.0, 10.0);
+ css_MixColor = vec4(0.5, 0.5, 0.5, 1.0);
+}
Modified: trunk/Source/WebCore/ChangeLog (136253 => 136254)
--- trunk/Source/WebCore/ChangeLog 2012-11-30 18:14:48 UTC (rev 136253)
+++ trunk/Source/WebCore/ChangeLog 2012-11-30 18:47:23 UTC (rev 136254)
@@ -1,3 +1,23 @@
+2012-11-30 Michelangelo De Simone <[email protected]>
+
+ [CSS Shaders] Clamp input colors before blending
+ https://bugs.webkit.org/show_bug.cgi?id=98962
+
+ Reviewed by Dean Jackson.
+
+ The result of css_ColorMatrix multiplication is now clamped in [0.0, 1.0]
+ before the blending step.
+
+ Relevant spec section is:
+ http://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#shader-processing-model
+
+ Tests: css3/filters/custom/custom-filter-color-clamping-negative.html
+ css3/filters/custom/custom-filter-color-clamping.html
+
+ * platform/graphics/filters/CustomFilterValidatedProgram.cpp:
+ (WebCore::CustomFilterValidatedProgram::rewriteMixFragmentShader): Added clamping
+ code.
+
2012-11-30 Abhishek Arya <[email protected]>
Crash due to intruding float not removed after writing mode changed.
Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp (136253 => 136254)
--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp 2012-11-30 18:14:48 UTC (rev 136253)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp 2012-11-30 18:47:23 UTC (rev 136254)
@@ -273,7 +273,7 @@
{
css_main();
mediump vec4 originalColor = texture2D(css_u_texture, css_v_texCoord);
- mediump vec4 multipliedColor = css_ColorMatrix * originalColor;
+ mediump vec4 multipliedColor = clamp(css_ColorMatrix * originalColor, 0.0, 1.0);
mediump vec3 blendedColor = css_BlendColor(multipliedColor.rgb, css_MixColor.rgb);
gl_FragColor = css_Composite(multipliedColor.rgb, multipliedColor.a, blendedColor.rgb, css_MixColor.a);
}