- Revision
- 133241
- Author
- [email protected]
- Date
- 2012-11-01 16:58:59 -0700 (Thu, 01 Nov 2012)
Log Message
[CSS Shaders] Get rid of internal tex coord attribute
https://bugs.webkit.org/show_bug.cgi?id=94358
Patch by Max Vujovic <[email protected]> on 2012-11-01
Reviewed by Dean Jackson.
Source/WebCore:
Remove the internal css_a_texCoord attribute that WebKit added to shaders in order to
sample the element texture by texture coordinate.
Now, the WebKit-added sampling code can leverage a_texCoord if the author defined it, or
WebKit can add its own a_texCoord definition to the author's shader.
Note that vertex attributes are read-only in GLSL. Also, note that we already reject the
shader if the author did not define a_texCoord with the correct type. Essentially, if
a_texCoord exists in the author's validated shader, we are guaranteed that it's the correct
type and that its value is unmodified.
Test: css3/filters/custom/custom-filter-a-tex-coord-optional.html
* platform/graphics/filters/CustomFilterCompiledProgram.cpp:
(WebCore::CustomFilterCompiledProgram::CustomFilterCompiledProgram):
Remove the references to m_internalTexCoordAttribLocation.
(WebCore::CustomFilterCompiledProgram::initializeParameterLocations): Ditto.
* platform/graphics/filters/CustomFilterCompiledProgram.h: Ditto.
* platform/graphics/filters/CustomFilterRenderer.cpp:
(WebCore::CustomFilterRenderer::bindProgramAndBuffers): Ditto.
(WebCore::CustomFilterRenderer::unbindVertexAttributes): Ditto.
* platform/graphics/filters/CustomFilterValidatedProgram.cpp:
(WebCore::CustomFilterValidatedProgram::CustomFilterValidatedProgram):
Pass the set of symbols found in the author's shaders to the rewriteMixVertexShader
method.
(WebCore::CustomFilterValidatedProgram::rewriteMixVertexShader):
If the author didn't define a_texCoord, add it to the end of the author's vertex
shader, but before the shader's new main function. As before, the new main function
will pass the texture coordinate to the fragment shader via the css_v_texCoord varying.
* platform/graphics/filters/CustomFilterValidatedProgram.h:
(WebCore):
Add a forward declaration for ANGLEShaderSymbol.
(CustomFilterValidatedProgram):
Update the method prototype for rewriteMixVertexShader.
LayoutTests:
Add a test which verifies that a custom filter executes regardless of whether the author
defines a_texCoord in the vertex shader. We check this because the implementation uses
the author's a_texCoord definition if it exists. If it doesn't exist, the implementation
adds its own a_texCoord definition to the author's shader.
* css3/filters/custom/custom-filter-a-tex-coord-optional-expected.html: Added.
* css3/filters/custom/custom-filter-a-tex-coord-optional.html: Added.
* css3/filters/resources/a-tex-coord-defined.vs: Added.
* css3/filters/resources/a-tex-coord-undefined.vs: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (133240 => 133241)
--- trunk/LayoutTests/ChangeLog 2012-11-01 23:36:55 UTC (rev 133240)
+++ trunk/LayoutTests/ChangeLog 2012-11-01 23:58:59 UTC (rev 133241)
@@ -1,3 +1,20 @@
+2012-11-01 Max Vujovic <[email protected]>
+
+ [CSS Shaders] Get rid of internal tex coord attribute
+ https://bugs.webkit.org/show_bug.cgi?id=94358
+
+ Reviewed by Dean Jackson.
+
+ Add a test which verifies that a custom filter executes regardless of whether the author
+ defines a_texCoord in the vertex shader. We check this because the implementation uses
+ the author's a_texCoord definition if it exists. If it doesn't exist, the implementation
+ adds its own a_texCoord definition to the author's shader.
+
+ * css3/filters/custom/custom-filter-a-tex-coord-optional-expected.html: Added.
+ * css3/filters/custom/custom-filter-a-tex-coord-optional.html: Added.
+ * css3/filters/resources/a-tex-coord-defined.vs: Added.
+ * css3/filters/resources/a-tex-coord-undefined.vs: Added.
+
2012-11-01 Stephen White <[email protected]>
[chromium] Unreviewed gardening. Suppressing an image failure after
Added: trunk/LayoutTests/css3/filters/custom/custom-filter-a-tex-coord-optional-expected.html (0 => 133241)
--- trunk/LayoutTests/css3/filters/custom/custom-filter-a-tex-coord-optional-expected.html (rev 0)
+++ trunk/LayoutTests/css3/filters/custom/custom-filter-a-tex-coord-optional-expected.html 2012-11-01 23:58:59 UTC (rev 133241)
@@ -0,0 +1,19 @@
+<!doctype html>
+<html>
+<head>
+ <title>Tests that custom filters with blending and compositing execute whether or not the author defines a_texCoord.</title>
+ <!-- If the test passes, you should see 2 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>
+</body>
+</html>
Added: trunk/LayoutTests/css3/filters/custom/custom-filter-a-tex-coord-optional.html (0 => 133241)
--- trunk/LayoutTests/css3/filters/custom/custom-filter-a-tex-coord-optional.html (rev 0)
+++ trunk/LayoutTests/css3/filters/custom/custom-filter-a-tex-coord-optional.html 2012-11-01 23:58:59 UTC (rev 133241)
@@ -0,0 +1,40 @@
+<!doctype html>
+<html>
+<head>
+ <title>Tests that custom filters with blending and compositing execute whether or not the author defines a_texCoord.</title>
+ <!-- If the test passes, you should see 2 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 red to green. */
+ background-color: rgb(255, 0, 0);
+ width: 50px;
+ height: 50px;
+ margin: 10px;
+ }
+ .a-tex-coord-defined {
+ -webkit-filter: custom(url('../resources/a-tex-coord-defined.vs') mix(url('../resources/mix-color.fs') normal source-atop), mix_color 0.0 1.0 0.0 1.0);
+ }
+ .a-tex-coord-undefined {
+ -webkit-filter: custom(url('../resources/a-tex-coord-undefined.vs') mix(url('../resources/mix-color.fs') normal source-atop), mix_color 0.0 1.0 0.0 1.0);
+ }
+ </style>
+</head>
+<body _onload_="runTest()">
+ <div class="a-tex-coord-defined"></div>
+ <div class="a-tex-coord-undefined"></div>
+</body>
+</html>
Added: trunk/LayoutTests/css3/filters/resources/a-tex-coord-defined.vs (0 => 133241)
--- trunk/LayoutTests/css3/filters/resources/a-tex-coord-defined.vs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/a-tex-coord-defined.vs 2012-11-01 23:58:59 UTC (rev 133241)
@@ -0,0 +1,12 @@
+// This shader defines a_texCoord. Its associated custom filter should execute properly.
+
+precision mediump float;
+
+attribute vec2 a_texCoord;
+attribute vec4 a_position;
+uniform mat4 u_projectionMatrix;
+
+void main()
+{
+ gl_Position = u_projectionMatrix * a_position;
+}
Added: trunk/LayoutTests/css3/filters/resources/a-tex-coord-undefined.vs (0 => 133241)
--- trunk/LayoutTests/css3/filters/resources/a-tex-coord-undefined.vs (rev 0)
+++ trunk/LayoutTests/css3/filters/resources/a-tex-coord-undefined.vs 2012-11-01 23:58:59 UTC (rev 133241)
@@ -0,0 +1,11 @@
+// This shader does not define a_texCoord. Its associated custom filter should execute properly.
+
+precision mediump float;
+
+attribute vec4 a_position;
+uniform mat4 u_projectionMatrix;
+
+void main()
+{
+ gl_Position = u_projectionMatrix * a_position;
+}
Modified: trunk/Source/WebCore/ChangeLog (133240 => 133241)
--- trunk/Source/WebCore/ChangeLog 2012-11-01 23:36:55 UTC (rev 133240)
+++ trunk/Source/WebCore/ChangeLog 2012-11-01 23:58:59 UTC (rev 133241)
@@ -1,3 +1,45 @@
+2012-11-01 Max Vujovic <[email protected]>
+
+ [CSS Shaders] Get rid of internal tex coord attribute
+ https://bugs.webkit.org/show_bug.cgi?id=94358
+
+ Reviewed by Dean Jackson.
+
+ Remove the internal css_a_texCoord attribute that WebKit added to shaders in order to
+ sample the element texture by texture coordinate.
+
+ Now, the WebKit-added sampling code can leverage a_texCoord if the author defined it, or
+ WebKit can add its own a_texCoord definition to the author's shader.
+
+ Note that vertex attributes are read-only in GLSL. Also, note that we already reject the
+ shader if the author did not define a_texCoord with the correct type. Essentially, if
+ a_texCoord exists in the author's validated shader, we are guaranteed that it's the correct
+ type and that its value is unmodified.
+
+ Test: css3/filters/custom/custom-filter-a-tex-coord-optional.html
+
+ * platform/graphics/filters/CustomFilterCompiledProgram.cpp:
+ (WebCore::CustomFilterCompiledProgram::CustomFilterCompiledProgram):
+ Remove the references to m_internalTexCoordAttribLocation.
+ (WebCore::CustomFilterCompiledProgram::initializeParameterLocations): Ditto.
+ * platform/graphics/filters/CustomFilterCompiledProgram.h: Ditto.
+ * platform/graphics/filters/CustomFilterRenderer.cpp:
+ (WebCore::CustomFilterRenderer::bindProgramAndBuffers): Ditto.
+ (WebCore::CustomFilterRenderer::unbindVertexAttributes): Ditto.
+ * platform/graphics/filters/CustomFilterValidatedProgram.cpp:
+ (WebCore::CustomFilterValidatedProgram::CustomFilterValidatedProgram):
+ Pass the set of symbols found in the author's shaders to the rewriteMixVertexShader
+ method.
+ (WebCore::CustomFilterValidatedProgram::rewriteMixVertexShader):
+ If the author didn't define a_texCoord, add it to the end of the author's vertex
+ shader, but before the shader's new main function. As before, the new main function
+ will pass the texture coordinate to the fragment shader via the css_v_texCoord varying.
+ * platform/graphics/filters/CustomFilterValidatedProgram.h:
+ (WebCore):
+ Add a forward declaration for ANGLEShaderSymbol.
+ (CustomFilterValidatedProgram):
+ Update the method prototype for rewriteMixVertexShader.
+
2012-11-01 Chris Rogers <[email protected]>
Ensure that AudioNode deletion is synchronized with a stable state of the rendering graph
Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.cpp (133240 => 133241)
--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.cpp 2012-11-01 23:36:55 UTC (rev 133240)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.cpp 2012-11-01 23:58:59 UTC (rev 133241)
@@ -50,7 +50,6 @@
, m_samplerLocation(-1)
, m_samplerSizeLocation(-1)
, m_contentSamplerLocation(-1)
- , m_internalTexCoordAttribLocation(-1)
, m_isInitialized(false)
{
m_context->makeContextCurrent();
@@ -130,10 +129,9 @@
m_samplerSizeLocation = m_context->getUniformLocation(m_program, "u_textureSize");
m_contentSamplerLocation = m_context->getUniformLocation(m_program, "u_contentTexture");
if (programType == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE) {
- // When the author uses the CSS mix function in a custom filter, we add internal symbols to the shader code.
- // One of them, css_u_texture, references the texture of the element.
+ // When the author uses the CSS mix function in a custom filter, WebKit adds the internal
+ // symbol css_u_texture to the shader code, which references the texture of the element.
m_samplerLocation = m_context->getUniformLocation(m_program, "css_u_texture");
- m_internalTexCoordAttribLocation = m_context->getAttribLocation(m_program, "css_a_texCoord");
}
}
Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.h (133240 => 133241)
--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.h 2012-11-01 23:36:55 UTC (rev 133240)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.h 2012-11-01 23:58:59 UTC (rev 133241)
@@ -61,12 +61,6 @@
int samplerLocation() const { return m_samplerLocation; }
int contentSamplerLocation() const { return m_contentSamplerLocation; }
int samplerSizeLocation() const { return m_samplerSizeLocation; }
- // FIXME: Get rid of the internal tex coord attribute "css_a_texCoord".
- // If the author defined "a_texCoord", we should leverage that.
- // If not, we should write "a_texCoord" in the shader.
- // This requires us to first get the list of attributes from the vertex shader using ANGLE.
- // https://bugs.webkit.org/show_bug.cgi?id=94358
- int internalTexCoordAttribLocation() const { return m_internalTexCoordAttribLocation; }
int uniformLocationByName(const String&);
@@ -94,9 +88,6 @@
int m_samplerLocation;
int m_samplerSizeLocation;
int m_contentSamplerLocation;
- // FIXME: Get rid of the internal tex coord attribute "css_a_texCoord".
- // https://bugs.webkit.org/show_bug.cgi?id=94358
- int m_internalTexCoordAttribLocation;
bool m_isInitialized;
};
Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterRenderer.cpp (133240 => 133241)
--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterRenderer.cpp 2012-11-01 23:36:55 UTC (rev 133240)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterRenderer.cpp 2012-11-01 23:58:59 UTC (rev 133241)
@@ -284,9 +284,6 @@
bindVertexAttribute(m_compiledProgram->positionAttribLocation(), PositionAttribSize, PositionAttribOffset);
bindVertexAttribute(m_compiledProgram->texAttribLocation(), TexAttribSize, TexAttribOffset);
- // FIXME: Get rid of the internal tex coord attribute "css_a_texCoord".
- // https://bugs.webkit.org/show_bug.cgi?id=94358
- bindVertexAttribute(m_compiledProgram->internalTexCoordAttribLocation(), TexAttribSize, TexAttribOffset);
bindVertexAttribute(m_compiledProgram->meshAttribLocation(), MeshAttribSize, MeshAttribOffset);
if (m_meshType == MeshTypeDetached)
bindVertexAttribute(m_compiledProgram->triangleAttribLocation(), TriangleAttribSize, TriangleAttribOffset);
@@ -298,7 +295,6 @@
{
unbindVertexAttribute(m_compiledProgram->positionAttribLocation());
unbindVertexAttribute(m_compiledProgram->texAttribLocation());
- unbindVertexAttribute(m_compiledProgram->internalTexCoordAttribLocation());
unbindVertexAttribute(m_compiledProgram->meshAttribLocation());
if (m_meshType == MeshTypeDetached)
unbindVertexAttribute(m_compiledProgram->triangleAttribLocation());
Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp (133240 => 133241)
--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp 2012-11-01 23:36:55 UTC (rev 133240)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp 2012-11-01 23:58:59 UTC (rev 133241)
@@ -39,6 +39,7 @@
#include "CustomFilterProgramInfo.h"
#include "NotImplemented.h"
#include <wtf/HashMap.h>
+#include <wtf/Vector.h>
#include <wtf/text/StringBuilder.h>
#include <wtf/text/StringHash.h>
@@ -192,7 +193,7 @@
// We need to add texture access, blending, and compositing code to shaders that are referenced from the CSS mix function.
if (blendsElementTexture) {
- rewriteMixVertexShader();
+ rewriteMixVertexShader(symbols);
rewriteMixFragmentShader();
}
@@ -216,21 +217,32 @@
&& m_programInfo.mixSettings().compositeOperator != CompositeCopy;
}
-void CustomFilterValidatedProgram::rewriteMixVertexShader()
+void CustomFilterValidatedProgram::rewriteMixVertexShader(const Vector<ANGLEShaderSymbol>& symbols)
{
ASSERT(m_programInfo.programType() == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE);
+ // If the author defined a_texCoord, we can use it to shuttle the texture coordinate to the fragment shader.
+ // Note that vertex attributes are read-only in GLSL, so the author could not have changed a_texCoord's value.
+ // Also, note that we would have already rejected the shader if the author defined a_texCoord with the wrong type.
+ bool texCoordAttributeDefined = false;
+ for (size_t i = 0; i < symbols.size(); ++i) {
+ if (symbols[i].name == "a_texCoord")
+ texCoordAttributeDefined = true;
+ }
+
+ if (!texCoordAttributeDefined)
+ m_validatedVertexShader.append("attribute mediump vec2 a_texCoord;");
+
// During validation, ANGLE renamed the author's "main" function to "css_main".
// We write our own "main" function and call "css_main" from it.
// This makes rewriting easy and ensures that our code runs after all author code.
m_validatedVertexShader.append(SHADER(
- attribute mediump vec2 css_a_texCoord;
varying mediump vec2 css_v_texCoord;
void main()
{
css_main();
- css_v_texCoord = css_a_texCoord;
+ css_v_texCoord = a_texCoord;
}
));
}
Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.h (133240 => 133241)
--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.h 2012-11-01 23:36:55 UTC (rev 133240)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.h 2012-11-01 23:58:59 UTC (rev 133241)
@@ -49,6 +49,7 @@
namespace WebCore {
+struct ANGLEShaderSymbol;
class CustomFilterCompiledProgram;
class CustomFilterGlobalContext;
@@ -99,7 +100,7 @@
static String blendFunctionString(BlendMode);
static String compositeFunctionString(CompositeOperator);
- void rewriteMixVertexShader();
+ void rewriteMixVertexShader(const Vector<ANGLEShaderSymbol>& symbols);
void rewriteMixFragmentShader();
bool needsInputTexture() const;