Diff
Modified: trunk/LayoutTests/ChangeLog (133082 => 133083)
--- trunk/LayoutTests/ChangeLog 2012-10-31 22:10:57 UTC (rev 133082)
+++ trunk/LayoutTests/ChangeLog 2012-10-31 22:13:57 UTC (rev 133083)
@@ -1,3 +1,25 @@
+2012-10-31 Max Vujovic <[email protected]>
+
+ [CSS Shaders] Validate types of built-in uniforms
+ https://bugs.webkit.org/show_bug.cgi?id=98974
+
+ Reviewed by Dean Jackson.
+
+ Add a test to verify that shaders which define built-in uniforms with the wrong type do not
+ execute. Add shaders for each built-in uniform in CSS Custom Filters.
+
+ Relevant Spec Section:
+ https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#shader-uniform-variables
+
+ * css3/filters/custom/invalid-custom-filter-uniform-types-expected.html: Added.
+ * css3/filters/custom/invalid-custom-filter-uniform-types.html: Added.
+ * css3/filters/resources/invalid-type-u-mesh-box.fs: Added.
+ * css3/filters/resources/invalid-type-u-mesh-size.fs: Added.
+ * css3/filters/resources/invalid-type-u-projection-matrix.fs: Added.
+ * css3/filters/resources/invalid-type-u-texture-size.fs: Added.
+ * css3/filters/resources/invalid-type-u-tile-size.fs: Added.
+ * css3/filters/resources/invalid-type-uniform-array.fs: Added.
+
2012-10-31 Terry Anderson <[email protected]>
[touchadjustment] touch-links-two-finger-tap test pass incorrectly
Added: trunk/LayoutTests/css3/filters/custom/invalid-custom-filter-uniform-types-expected.html (0 => 133083)
--- trunk/LayoutTests/css3/filters/custom/invalid-custom-filter-uniform-types-expected.html (rev 0)
+++ trunk/LayoutTests/css3/filters/custom/invalid-custom-filter-uniform-types-expected.html 2012-10-31 22:13:57 UTC (rev 133083)
@@ -0,0 +1,26 @@
+<!doctype html>
+<html>
+<head>
+ <title>Tests that custom filters do not execute if the author defines built-in uniforms with the wrong type.</title>
+ <!--
+ This is the reference file for the test.
+ If the test passes, you should see 6 vertically-stacked green boxes.
+ -->
+ <style>
+ div {
+ background-color: rgb(0, 255, 0);
+ width: 50px;
+ height: 50px;
+ margin: 10px;
+ }
+ </style>
+</head>
+<body>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+ <div></div>
+</body>
+</html>
Added: trunk/LayoutTests/css3/filters/custom/invalid-custom-filter-uniform-types.html (0 => 133083)
--- trunk/LayoutTests/css3/filters/custom/invalid-custom-filter-uniform-types.html (rev 0)
+++ trunk/LayoutTests/css3/filters/custom/invalid-custom-filter-uniform-types.html 2012-10-31 22:13:57 UTC (rev 133083)
@@ -0,0 +1,56 @@
+<!doctype html>
+<html>
+<head>
+ <title>Tests that custom filters do not execute if the author defines built-in uniforms with the wrong type.</title>
+ <!-- If the test passes, you should see 6 vertically-stacked green boxes. -->
+ <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 shaders download.
+ if (window.testRunner)
+ window.testRunner.notifyDone();
+ }
+ </script>
+ <style>
+ div {
+ /* If the shaders execute, they will turn the element's color from green to red. */
+ background-color: rgb(0, 255, 0);
+ width: 50px;
+ height: 50px;
+ margin: 10px;
+ }
+ .invalid-type-u-mesh-box {
+ -webkit-filter: custom(none mix(url('../resources/invalid-type-u-mesh-box.fs') normal source-atop));
+ }
+ .invalid-type-u-mesh-size {
+ -webkit-filter: custom(none mix(url('../resources/invalid-type-u-mesh-size.fs') normal source-atop));
+ }
+ .invalid-type-u-projection-matrix {
+ -webkit-filter: custom(none mix(url('../resources/invalid-type-u-projection-matrix.fs') normal source-atop));
+ }
+ .invalid-type-u-texture-size {
+ -webkit-filter: custom(none mix(url('../resources/invalid-type-u-texture-size.fs') normal source-atop));
+ }
+ .invalid-type-u-tile-size {
+ -webkit-filter: custom(none mix(url('../resources/invalid-type-u-tile-size.fs') normal source-atop));
+ }
+ .invalid-type-uniform-array {
+ -webkit-filter: custom(none mix(url('../resources/invalid-type-uniform-array.fs') normal source-atop));
+ }
+ </style>
+</head>
+<body _onload_="runTest()">
+ <div class="invalid-type-u-mesh-box"></div>
+ <div class="invalid-type-u-mesh-size"></div>
+ <div class="invalid-type-u-projection-matrix"></div>
+ <div class="invalid-type-u-texture-size"></div>
+ <div class="invalid-type-u-tile-size"></div>
+ <div class="invalid-type-uniform-array"></div>
+</body>
+</html>
Added: trunk/LayoutTests/css3/filters/resources/invalid-type-u-mesh-box.fs (0 => 133083)
--- trunk/LayoutTests/css3/filters/resources/invalid-type-u-mesh-box.fs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/invalid-type-u-mesh-box.fs 2012-10-31 22:13:57 UTC (rev 133083)
@@ -0,0 +1,11 @@
+// If this shader's related test passes, the custom filter does not execute because u_meshBox's type is invalid.
+
+precision mediump float;
+
+// u_meshBox should be a vec4, not a vec3.
+uniform vec3 u_meshBox;
+
+void main()
+{
+ css_MixColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
Added: trunk/LayoutTests/css3/filters/resources/invalid-type-u-mesh-size.fs (0 => 133083)
--- trunk/LayoutTests/css3/filters/resources/invalid-type-u-mesh-size.fs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/invalid-type-u-mesh-size.fs 2012-10-31 22:13:57 UTC (rev 133083)
@@ -0,0 +1,11 @@
+// If this shader's related test passes, the custom filter does not execute because u_meshSize's type is invalid.
+
+precision mediump float;
+
+// u_meshSize should be a vec2, not a float.
+uniform float u_meshSize;
+
+void main()
+{
+ css_MixColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
Added: trunk/LayoutTests/css3/filters/resources/invalid-type-u-projection-matrix.fs (0 => 133083)
--- trunk/LayoutTests/css3/filters/resources/invalid-type-u-projection-matrix.fs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/invalid-type-u-projection-matrix.fs 2012-10-31 22:13:57 UTC (rev 133083)
@@ -0,0 +1,11 @@
+// If this shader's related test passes, the custom filter does not execute because u_projectionMatrix's type is invalid.
+
+precision mediump float;
+
+// u_projectionMatrix should be a mat4, not a mat3.
+uniform mat3 u_projectionMatrix;
+
+void main()
+{
+ css_MixColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
Added: trunk/LayoutTests/css3/filters/resources/invalid-type-u-texture-size.fs (0 => 133083)
--- trunk/LayoutTests/css3/filters/resources/invalid-type-u-texture-size.fs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/invalid-type-u-texture-size.fs 2012-10-31 22:13:57 UTC (rev 133083)
@@ -0,0 +1,11 @@
+// If this shader's related test passes, the custom filter does not execute because u_textureSize's type is invalid.
+
+precision mediump float;
+
+// u_textureSize should be a vec2, not a vec3.
+uniform vec3 u_textureSize;
+
+void main()
+{
+ css_MixColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
Added: trunk/LayoutTests/css3/filters/resources/invalid-type-u-tile-size.fs (0 => 133083)
--- trunk/LayoutTests/css3/filters/resources/invalid-type-u-tile-size.fs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/invalid-type-u-tile-size.fs 2012-10-31 22:13:57 UTC (rev 133083)
@@ -0,0 +1,11 @@
+// If this shader's related test passes, the custom filter does not execute because u_tileSize's type is invalid.
+
+precision mediump float;
+
+// u_tileSize should be a vec2, not a mat2.
+uniform mat2 u_tileSize;
+
+void main()
+{
+ css_MixColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
Added: trunk/LayoutTests/css3/filters/resources/invalid-type-uniform-array.fs (0 => 133083)
--- trunk/LayoutTests/css3/filters/resources/invalid-type-uniform-array.fs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/invalid-type-uniform-array.fs 2012-10-31 22:13:57 UTC (rev 133083)
@@ -0,0 +1,11 @@
+// If this shader's related test passes, the custom filter does not execute because u_meshBox's type is invalid.
+
+precision mediump float;
+
+// u_meshBox should be a vec4, not an array of vec4.
+uniform vec4 u_meshBox[1];
+
+void main()
+{
+ css_MixColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
Modified: trunk/Source/WebCore/ChangeLog (133082 => 133083)
--- trunk/Source/WebCore/ChangeLog 2012-10-31 22:10:57 UTC (rev 133082)
+++ trunk/Source/WebCore/ChangeLog 2012-10-31 22:13:57 UTC (rev 133083)
@@ -1,3 +1,24 @@
+2012-10-31 Max Vujovic <[email protected]>
+
+ [CSS Shaders] Validate types of built-in uniforms
+ https://bugs.webkit.org/show_bug.cgi?id=98974
+
+ Reviewed by Dean Jackson.
+
+ Reject shaders which define built-in uniforms with the wrong type. For example, we reject a
+ shader with the GLSL code "uniform float u_textureSize;" because u_textureSize should be a
+ vec2, not a float.
+
+ Relevant Spec Section:
+ https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#shader-uniform-variables
+
+ Test: css3/filters/custom/invalid-custom-filter-uniform-types.html
+
+ * platform/graphics/filters/CustomFilterValidatedProgram.cpp:
+ (WebCore):
+ (WebCore::builtInUniformNameToTypeMap):
+ (WebCore::validateSymbols):
+
2012-10-31 Sheriff Bot <[email protected]>
Unreviewed, rolling out r133044.
Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp (133082 => 133083)
--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp 2012-10-31 22:10:57 UTC (rev 133082)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp 2012-10-31 22:13:57 UTC (rev 133083)
@@ -46,8 +46,6 @@
#define SHADER(Src) (#Src)
-// FIXME: Reuse this type when we validate the types of built-in uniforms.
-// https://bugs.webkit.org/show_bug.cgi?id=98974
typedef HashMap<String, ShDataType> SymbolNameToTypeMap;
static SymbolNameToTypeMap* builtInAttributeNameToTypeMap()
@@ -63,6 +61,20 @@
return nameToTypeMap;
}
+static SymbolNameToTypeMap* builtInUniformNameToTypeMap()
+{
+ static SymbolNameToTypeMap* nameToTypeMap = 0;
+ if (!nameToTypeMap) {
+ nameToTypeMap = new SymbolNameToTypeMap;
+ nameToTypeMap->set("u_meshBox", SH_FLOAT_VEC4);
+ nameToTypeMap->set("u_meshSize", SH_FLOAT_VEC2);
+ nameToTypeMap->set("u_projectionMatrix", SH_FLOAT_MAT4);
+ nameToTypeMap->set("u_textureSize", SH_FLOAT_VEC2);
+ nameToTypeMap->set("u_tileSize", SH_FLOAT_VEC2);
+ }
+ return nameToTypeMap;
+}
+
static bool validateSymbols(const Vector<ANGLEShaderSymbol>& symbols, CustomFilterMeshType meshType)
{
for (size_t i = 0; i < symbols.size(); ++i) {
@@ -91,7 +103,7 @@
}
break;
}
- case SHADER_SYMBOL_TYPE_UNIFORM:
+ case SHADER_SYMBOL_TYPE_UNIFORM: {
if (symbol.isSampler()) {
// FIXME: For now, we restrict shaders with any sampler defined.
// When we implement texture parameters, we will allow shaders whose samplers are bound to valid textures.
@@ -101,9 +113,16 @@
return false;
}
- // FIXME: Validate the types of built-in uniforms.
- // https://bugs.webkit.org/show_bug.cgi?id=98974
+ SymbolNameToTypeMap* uniformNameToTypeMap = builtInUniformNameToTypeMap();
+ SymbolNameToTypeMap::iterator builtInUniform = uniformNameToTypeMap->find(symbol.name);
+ if (builtInUniform != uniformNameToTypeMap->end() && (symbol.isArray || symbol.dataType != builtInUniform->value)) {
+ // The author defined one of the built-in uniforms with the wrong type.
+ // FIXME: Report the validation error.
+ // https://bugs.webkit.org/show_bug.cgi?id=74416
+ return false;
+ }
break;
+ }
default:
ASSERT_NOT_REACHED();
break;