[CSS Shaders] u_textureSize uniform should be set to the size of the texture.

https://bugs.webkit.org/show_bug.cgi?id=95914

Reviewed by Dean Jackson.

Source/WebCore:

This adds support for the following shader uniform variables:

    uniform vec2 u_textureSize
    uniform vec4 u_meshBox
    uniform vec2 u_tileSize
    uniform vec2 u_meshSize

The relevant section of the specification is:
http://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#shader-uniform-variables

Tests: css3/filters/custom/custom-filter-u-mesh-box.html
       css3/filters/custom/custom-filter-u-mesh-size.html
       css3/filters/custom/custom-filter-u-texture-size.html
       css3/filters/custom/custom-filter-u-tile-size.html

* platform/graphics/filters/FECustomFilter.cpp:
(WebCore::FECustomFilter::bindProgramAndBuffers):

LayoutTests:

Tests for the following uniform variables:
    uniform vec2 u_textureSize
    uniform vec4 u_meshBox
    uniform vec2 u_tileSize
    uniform vec2 u_meshSize

The relevant section of the specification is:
http://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#shader-uniform-variables

* css3/filters/custom/custom-filter-u-mesh-box-expected.html: Added.
* css3/filters/custom/custom-filter-u-mesh-box.html: Added.
* css3/filters/custom/custom-filter-u-mesh-size-expected.html: Added.
* css3/filters/custom/custom-filter-u-mesh-size.html: Added.
* css3/filters/custom/custom-filter-u-texture-size-expected.html: Added.
* css3/filters/custom/custom-filter-u-texture-size.html: Added.
* css3/filters/custom/custom-filter-u-tile-size-expected.html: Added.
* css3/filters/custom/custom-filter-u-tile-size.html: Added.
* css3/filters/resources/u-mesh-box-is-unit-square.fs: Added.
* css3/filters/resources/u-mesh-size.fs: Added.
* css3/filters/resources/u-texture-size.fs: Added.
* css3/filters/resources/u-tile-size.fs: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@128666 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 59de8d92
2012-09-14 Michelangelo De Simone <michelangelo@webkit.org>
[CSS Shaders] u_textureSize uniform should be set to the size of the texture.
https://bugs.webkit.org/show_bug.cgi?id=95914
Reviewed by Dean Jackson.
Tests for the following uniform variables:
uniform vec2 u_textureSize
uniform vec4 u_meshBox
uniform vec2 u_tileSize
uniform vec2 u_meshSize
The relevant section of the specification is:
http://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#shader-uniform-variables
* css3/filters/custom/custom-filter-u-mesh-box-expected.html: Added.
* css3/filters/custom/custom-filter-u-mesh-box.html: Added.
* css3/filters/custom/custom-filter-u-mesh-size-expected.html: Added.
* css3/filters/custom/custom-filter-u-mesh-size.html: Added.
* css3/filters/custom/custom-filter-u-texture-size-expected.html: Added.
* css3/filters/custom/custom-filter-u-texture-size.html: Added.
* css3/filters/custom/custom-filter-u-tile-size-expected.html: Added.
* css3/filters/custom/custom-filter-u-tile-size.html: Added.
* css3/filters/resources/u-mesh-box-is-unit-square.fs: Added.
* css3/filters/resources/u-mesh-size.fs: Added.
* css3/filters/resources/u-texture-size.fs: Added.
* css3/filters/resources/u-tile-size.fs: Added.
2012-09-14 Alexey Proskuryakov <ap@apple.com>
Unreviewed.
<!doctype html>
<html>
<head>
<title>Test u_meshSize</title>
<style>
#filtertestbox {
height: 100px;
width: 100px;
background-color: rgb(0, 255, 0);
}
</style>
</head>
<body onload="runTest()">
<div id="filtertestbox"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Test u_meshBox</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>
#filtertestbox {
height: 100px;
width: 100px;
background-color: red;
-webkit-filter: custom(none url('../resources/u-mesh-box-is-unit-square.fs'));
}
</style>
</head>
<body onload="runTest()">
<!--
A 100x100px red div is coloured green if u_meshBox is correctly set and
passed to the shader.
As of now u_meshBox always returns (-0.5, -0.5, 1, 1); this shall change
when filter margins will be implemented, see:
https://bugs.webkit.org/show_bug.cgi?id=71400
Fails if the div stays red.
-->
<div id="filtertestbox"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Test u_meshBox</title>
<style>
#filtertestbox {
height: 100px;
width: 100px;
background-color: rgb(0, 255, 0);
}
</style>
</head>
<body onload="runTest()">
<div id="filtertestbox"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Test u_meshSize</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>
#filtertestbox {
height: 100px;
width: 100px;
background-color: red;
-webkit-filter: custom(none url('../resources/u-mesh-size.fs'), 10 20);
}
</style>
</head>
<body onload="runTest()">
<!--
A 100x100px red div is coloured green if u_meshSize is correctly set and
passed to the shader.
Fails if the div stays red.
-->
<div id="filtertestbox"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Test u_textureSize</title>
<style>
#filtertestbox {
height: 100px;
width: 100px;
background-color: rgb(0, 255, 0);
}
</style>
</head>
<body onload="runTest()">
<div id="filtertestbox"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Test u_textureSize</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>
#filtertestbox {
height: 100px;
width: 100px;
background-color: red;
-webkit-filter: custom(none url('../resources/u-texture-size.fs'));
}
</style>
</head>
<body onload="runTest()">
<!--
A 100x100px red div is coloured green if u_textureSize is correctly set and
passed to the shader.
Fails if the div stays red.
-->
<div id="filtertestbox"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Test u_tileSize</title>
<style>
#filtertestbox {
height: 100px;
width: 100px;
background-color: rgb(0, 255, 0);
}
</style>
</head>
<body onload="runTest()">
<div id="filtertestbox"></div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Test u_tileSize</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>
#filtertestbox {
height: 100px;
width: 100px;
background-color: red;
-webkit-filter: custom(none url('../resources/u-tile-size.fs'), 10 20);
}
</style>
</head>
<body onload="runTest()">
<!--
A 100x100px red div is coloured green if u_tileSize is correctly set and
passed to the shader.
Fails if the div stays red.
-->
<div id="filtertestbox"></div>
</body>
</html>
// Test whether u_meshBox is correctly set; change fragment color to green if yes.
precision mediump float;
uniform vec4 u_meshBox;
bool areFloatsEqual(float a, float b)
{
const float epsilon = 0.001;
return (a > (b - epsilon)) && (a < (b + epsilon));
}
bool areVectorsEqual(vec4 a, vec4 b)
{
return areFloatsEqual(a.x, b.x) && areFloatsEqual(a.y, b.y) && areFloatsEqual(a.z, b.z) && areFloatsEqual(a.w, b.w);
}
void main()
{
gl_FragColor = areVectorsEqual(u_meshBox, vec4(-0.5, -0.5, 1.0, 1.0)) ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
}
// Test whether u_meshSize is correctly set; change fragment to color green if yes.
precision mediump float;
uniform vec2 u_meshSize;
bool areFloatsEqual(float a, float b)
{
const float epsilon = 0.001;
return (a > (b - epsilon)) && (a < (b + epsilon));
}
bool areVectorsEqual(vec2 a, vec2 b)
{
return areFloatsEqual(a.x, b.x) && areFloatsEqual(a.y, b.y);
}
void main()
{
gl_FragColor = areVectorsEqual(u_meshSize, vec2(20.0, 10.0)) ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
}
// Test whether u_textureSize is correctly set; change fragment color to green if yes.
precision mediump float;
uniform vec2 u_textureSize;
bool areFloatsEqual(float a, float b)
{
const float epsilon = 0.001;
return (a > (b - epsilon)) && (a < (b + epsilon));
}
bool areVectorsEqual(vec2 a, vec2 b)
{
return areFloatsEqual(a.x, b.x) && areFloatsEqual(a.y, b.y);
}
void main()
{
gl_FragColor = areVectorsEqual(u_textureSize, vec2(100.0, 100.0)) ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
}
// Test whether u_tileSize is correctly set; change fragment color to green if yes.
precision mediump float;
uniform vec2 u_tileSize;
bool areFloatsEqual(float a, float b)
{
const float epsilon = 0.001;
return (a > (b - epsilon)) && (a < (b + epsilon));
}
bool areVectorsEqual(vec2 a, vec2 b)
{
return areFloatsEqual(a.x, b.x) && areFloatsEqual(a.y, b.y);
}
void main()
{
gl_FragColor = areVectorsEqual(u_tileSize, vec2(0.05, 0.10)) ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
}
2012-09-14 Michelangelo De Simone <michelangelo@webkit.org>
[CSS Shaders] u_textureSize uniform should be set to the size of the texture.
https://bugs.webkit.org/show_bug.cgi?id=95914
Reviewed by Dean Jackson.
This adds support for the following shader uniform variables:
uniform vec2 u_textureSize
uniform vec4 u_meshBox
uniform vec2 u_tileSize
uniform vec2 u_meshSize
The relevant section of the specification is:
http://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#shader-uniform-variables
Tests: css3/filters/custom/custom-filter-u-mesh-box.html
css3/filters/custom/custom-filter-u-mesh-size.html
css3/filters/custom/custom-filter-u-texture-size.html
css3/filters/custom/custom-filter-u-tile-size.html
* platform/graphics/filters/FECustomFilter.cpp:
(WebCore::FECustomFilter::bindProgramAndBuffers):
2012-09-14 Ojan Vafai <ojan@chromium.org>
Provide a runtime setting to disable position:sticky
......@@ -547,6 +547,24 @@ void FECustomFilter::bindProgramAndBuffers(Platform3DObject inputTexture)
projectionMatrix.toColumnMajorFloatArray(glProjectionMatrix);
m_context->uniformMatrix4fv(m_compiledProgram->projectionMatrixLocation(), 1, false, &glProjectionMatrix[0]);
}
ASSERT(m_meshColumns);
ASSERT(m_meshRows);
if (m_compiledProgram->meshSizeLocation() != -1)
m_context->uniform2f(m_compiledProgram->meshSizeLocation(), m_meshColumns, m_meshRows);
if (m_compiledProgram->tileSizeLocation() != -1)
m_context->uniform2f(m_compiledProgram->tileSizeLocation(), 1.0 / m_meshColumns, 1.0 / m_meshRows);
if (m_compiledProgram->meshBoxLocation() != -1) {
// FIXME: This will change when filter margins will be implemented,
// see https://bugs.webkit.org/show_bug.cgi?id=71400
m_context->uniform4f(m_compiledProgram->meshBoxLocation(), -0.5, -0.5, 1.0, 1.0);
}
if (m_compiledProgram->samplerSizeLocation() != -1)
m_context->uniform2f(m_compiledProgram->samplerSizeLocation(), m_contextSize.width(), m_contextSize.height());
m_context->bindBuffer(GraphicsContext3D::ARRAY_BUFFER, m_mesh->verticesBufferObject());
m_context->bindBuffer(GraphicsContext3D::ELEMENT_ARRAY_BUFFER, m_mesh->elementsBufferObject());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment