LayoutTests/ChangeLog

 12012-10-30 Max Vujovic <mvujovic@adobe.com>
 2
 3 [CSS Shaders] Get rid of internal tex coord attribute
 4 https://bugs.webkit.org/show_bug.cgi?id=94358
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Add a test which verifies that a custom filter executes regardless of whether the author
 9 defines a_texCoord in the vertex shader. We check this because the implementation uses
 10 the author's a_texCoord definition if it exists. If it doesn't exist, the implementation
 11 adds its own a_texCoord definition to the author's shader.
 12
 13 * css3/filters/custom/custom-filter-a-tex-coord-optional-expected.html: Added.
 14 * css3/filters/custom/custom-filter-a-tex-coord-optional.html: Added.
 15 * css3/filters/resources/a-tex-coord-defined.vs: Added.
 16 * css3/filters/resources/a-tex-coord-undefined.vs: Added.
 17
1182012-10-30 Robert Hogan <robert@webkit.org>
219
320 white-space: nowrap inline element beside a floated element wraps incorrectly without trailing textnode/newline

LayoutTests/css3/filters/custom/custom-filter-a-tex-coord-optional-expected.html

 1<!doctype html>
 2<html>
 3<head>
 4 <title>Tests that custom filters with blending and compositing execute whether or not the author defines a_texCoord.</title>
 5 <!-- If the test passes, you should see 2 vertically-stacked green boxes. -->
 6 <style>
 7 div {
 8 background-color: rgb(0, 255, 0);
 9 width: 50px;
 10 height: 50px;
 11 margin: 10px;
 12 }
 13 </style>
 14</head>
 15<body>
 16 <div></div>
 17 <div></div>
 18</body>
 19</html>

LayoutTests/css3/filters/custom/custom-filter-a-tex-coord-optional.html

 1<!doctype html>
 2<html>
 3<head>
 4 <title>Tests that custom filters with blending and compositing execute whether or not the author defines a_texCoord.</title>
 5 <!-- If the test passes, you should see 2 vertically-stacked green boxes. -->
 6 <script>
 7 if (window.testRunner) {
 8 window.testRunner.overridePreference("WebKitCSSCustomFilterEnabled", "1");
 9 window.testRunner.overridePreference("WebKitWebGLEnabled", "1");
 10 window.testRunner.waitUntilDone();
 11 }
 12
 13 function runTest()
 14 {
 15 // We need to run the tests after the shaders download.
 16 if (window.testRunner)
 17 window.testRunner.notifyDone();
 18 }
 19 </script>
 20 <style>
 21 div {
 22 /* If the shaders execute, they will turn the element's color from red to green. */
 23 background-color: rgb(255, 0, 0);
 24 width: 50px;
 25 height: 50px;
 26 margin: 10px;
 27 }
 28 .a-tex-coord-defined {
 29 -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);
 30 }
 31 .a-tex-coord-undefined {
 32 -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);
 33 }
 34 </style>
 35</head>
 36<body onload="runTest()">
 37 <div class="a-tex-coord-defined"></div>
 38 <div class="a-tex-coord-undefined"></div>
 39</body>
 40</html>

LayoutTests/css3/filters/resources/a-tex-coord-defined.vs

 1// This shader defines a_texCoord. It's associated custom filter should execute properly.
 2
 3precision mediump float;
 4
 5attribute vec2 a_texCoord;
 6attribute vec4 a_position;
 7uniform mat4 u_projectionMatrix;
 8
 9void main()
 10{
 11 gl_Position = u_projectionMatrix * a_position;
 12}

LayoutTests/css3/filters/resources/a-tex-coord-undefined.vs

 1// This shader does not define a_texCoord. It's associated custom filter should execute properly.
 2
 3precision mediump float;
 4
 5attribute vec4 a_position;
 6uniform mat4 u_projectionMatrix;
 7
 8void main()
 9{
 10 gl_Position = u_projectionMatrix * a_position;
 11}

Source/WebCore/ChangeLog

 12012-10-30 Max Vujovic <mvujovic@adobe.com>
 2
 3 [CSS Shaders] Get rid of internal tex coord attribute
 4 https://bugs.webkit.org/show_bug.cgi?id=94358
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Remove the internal css_a_texCoord attribute that WebKit added to shaders in order to
 9 sample the element texture by texture coordinate.
 10
 11 Now, the WebKit-added sampling code can leverage a_texCoord if the author defined it, or
 12 WebKit can add its own a_texCoord definition to the author's shader.
 13
 14 Note that vertex attributes are read-only in GLSL. Also, note that we already reject the
 15 shader if the author did not define a_texCoord with the correct type. Essentially, if
 16 a_texCoord exists in the author's validated shader, we are guaranteed that it's the correct
 17 type and that its value is unmodified.
 18
 19 Test: css3/filters/custom/custom-filter-a-tex-coord-optional.html
 20
 21 * platform/graphics/filters/CustomFilterCompiledProgram.cpp:
 22 (WebCore::CustomFilterCompiledProgram::CustomFilterCompiledProgram):
 23 Remove the references to m_internalTexCoordAttribLocation.
 24 (WebCore::CustomFilterCompiledProgram::initializeParameterLocations): Ditto.
 25 * platform/graphics/filters/CustomFilterCompiledProgram.h: Ditto.
 26 * platform/graphics/filters/CustomFilterRenderer.cpp:
 27 (WebCore::CustomFilterRenderer::bindProgramAndBuffers): Ditto.
 28 (WebCore::CustomFilterRenderer::unbindVertexAttributes): Ditto.
 29 * platform/graphics/filters/CustomFilterValidatedProgram.cpp:
 30 (WebCore::CustomFilterValidatedProgram::CustomFilterValidatedProgram):
 31 Pass the set of symbols found in the author's shaders to the rewriteMixVertexShader
 32 method.
 33 (WebCore::CustomFilterValidatedProgram::rewriteMixVertexShader):
 34 If the author didn't define a_texCoord, add it to the end of the author's vertex
 35 shader, but before the shader's new main function. As before, the new main function
 36 will pass the texture coordinate to the fragment shader via the css_v_texCoord varying.
 37 * platform/graphics/filters/CustomFilterValidatedProgram.h:
 38 (WebCore):
 39 Add a forward declaration for ANGLEShaderSymbol.
 40 (CustomFilterValidatedProgram):
 41 Update the method prototype for rewriteMixVertexShader.
 42
1432012-10-30 Antti Koivisto <antti@apple.com>
244
345 Avoid unnecessary style recalcs on class attribute mutation

Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.cpp

@@CustomFilterCompiledProgram::CustomFilterCompiledProgram(PassRefPtr<GraphicsCont
5050 , m_samplerLocation(-1)
5151 , m_samplerSizeLocation(-1)
5252 , m_contentSamplerLocation(-1)
53  , m_internalTexCoordAttribLocation(-1)
5453 , m_isInitialized(false)
5554{
5655 m_context->makeContextCurrent();

@@void CustomFilterCompiledProgram::initializeParameterLocations(CustomFilterProgr
130129 m_samplerSizeLocation = m_context->getUniformLocation(m_program, "u_textureSize");
131130 m_contentSamplerLocation = m_context->getUniformLocation(m_program, "u_contentTexture");
132131 if (programType == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE) {
133  // When the author uses the CSS mix function in a custom filter, we add internal symbols to the shader code.
134  // One of them, css_u_texture, references the texture of the element.
 132 // When the author uses the CSS mix function in a custom filter, WebKit adds the internal
 133 // symbol css_u_texture to the shader code, which references the texture of the element.
135134 m_samplerLocation = m_context->getUniformLocation(m_program, "css_u_texture");
136  m_internalTexCoordAttribLocation = m_context->getAttribLocation(m_program, "css_a_texCoord");
137135 }
138136}
139137

Source/WebCore/platform/graphics/filters/CustomFilterCompiledProgram.h

@@public:
6161 int samplerLocation() const { return m_samplerLocation; }
6262 int contentSamplerLocation() const { return m_contentSamplerLocation; }
6363 int samplerSizeLocation() const { return m_samplerSizeLocation; }
64  // FIXME: Get rid of the internal tex coord attribute "css_a_texCoord".
65  // If the author defined "a_texCoord", we should leverage that.
66  // If not, we should write "a_texCoord" in the shader.
67  // This requires us to first get the list of attributes from the vertex shader using ANGLE.
68  // https://bugs.webkit.org/show_bug.cgi?id=94358
69  int internalTexCoordAttribLocation() const { return m_internalTexCoordAttribLocation; }
7064
7165 int uniformLocationByName(const String&);
7266

@@private:
9488 int m_samplerLocation;
9589 int m_samplerSizeLocation;
9690 int m_contentSamplerLocation;
97  // FIXME: Get rid of the internal tex coord attribute "css_a_texCoord".
98  // https://bugs.webkit.org/show_bug.cgi?id=94358
99  int m_internalTexCoordAttribLocation;
10091
10192 bool m_isInitialized;
10293};

Source/WebCore/platform/graphics/filters/CustomFilterRenderer.cpp

@@void CustomFilterRenderer::bindProgramAndBuffers(Platform3DObject inputTexture)
284284
285285 bindVertexAttribute(m_compiledProgram->positionAttribLocation(), PositionAttribSize, PositionAttribOffset);
286286 bindVertexAttribute(m_compiledProgram->texAttribLocation(), TexAttribSize, TexAttribOffset);
287  // FIXME: Get rid of the internal tex coord attribute "css_a_texCoord".
288  // https://bugs.webkit.org/show_bug.cgi?id=94358
289  bindVertexAttribute(m_compiledProgram->internalTexCoordAttribLocation(), TexAttribSize, TexAttribOffset);
290287 bindVertexAttribute(m_compiledProgram->meshAttribLocation(), MeshAttribSize, MeshAttribOffset);
291288 if (m_meshType == MeshTypeDetached)
292289 bindVertexAttribute(m_compiledProgram->triangleAttribLocation(), TriangleAttribSize, TriangleAttribOffset);

@@void CustomFilterRenderer::unbindVertexAttributes()
298295{
299296 unbindVertexAttribute(m_compiledProgram->positionAttribLocation());
300297 unbindVertexAttribute(m_compiledProgram->texAttribLocation());
301  unbindVertexAttribute(m_compiledProgram->internalTexCoordAttribLocation());
302298 unbindVertexAttribute(m_compiledProgram->meshAttribLocation());
303299 if (m_meshType == MeshTypeDetached)
304300 unbindVertexAttribute(m_compiledProgram->triangleAttribLocation());

Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.cpp

3939#include "CustomFilterProgramInfo.h"
4040#include "NotImplemented.h"
4141#include <wtf/HashMap.h>
 42#include <wtf/Vector.h>
4243#include <wtf/text/StringBuilder.h>
4344#include <wtf/text/StringHash.h>
4445

@@CustomFilterValidatedProgram::CustomFilterValidatedProgram(CustomFilterGlobalCon
173174
174175 // We need to add texture access, blending, and compositing code to shaders that are referenced from the CSS mix function.
175176 if (blendsElementTexture) {
176  rewriteMixVertexShader();
 177 rewriteMixVertexShader(symbols);
177178 rewriteMixFragmentShader();
178179 }
179180

@@bool CustomFilterValidatedProgram::needsInputTexture() const
197198 && m_programInfo.mixSettings().compositeOperator != CompositeCopy;
198199}
199200
200 void CustomFilterValidatedProgram::rewriteMixVertexShader()
 201void CustomFilterValidatedProgram::rewriteMixVertexShader(const Vector<ANGLEShaderSymbol>& symbols)
201202{
202203 ASSERT(m_programInfo.programType() == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE);
203204
 205 bool texCoordAttributeDefined = false;
 206 for (size_t i = 0; i < symbols.size(); ++i) {
 207 if (symbols[i].name == "a_texCoord")
 208 texCoordAttributeDefined = true;
 209 }
 210
 211 if (!texCoordAttributeDefined)
 212 m_validatedVertexShader.append("attribute mediump vec2 a_texCoord;");
 213
204214 // During validation, ANGLE renamed the author's "main" function to "css_main".
205215 // We write our own "main" function and call "css_main" from it.
206216 // This makes rewriting easy and ensures that our code runs after all author code.
207217 m_validatedVertexShader.append(SHADER(
208  attribute mediump vec2 css_a_texCoord;
209218 varying mediump vec2 css_v_texCoord;
210219
211220 void main()
212221 {
213222 css_main();
214  css_v_texCoord = css_a_texCoord;
 223 css_v_texCoord = a_texCoord;
215224 }
216225 ));
217226}

Source/WebCore/platform/graphics/filters/CustomFilterValidatedProgram.h

@@typedef WebCore::LayerCompiledProgram PlatformCompiledProgram;
4949
5050namespace WebCore {
5151
 52struct ANGLEShaderSymbol;
5253class CustomFilterCompiledProgram;
5354class CustomFilterGlobalContext;
5455

@@private:
99100 static String blendFunctionString(BlendMode);
100101 static String compositeFunctionString(CompositeOperator);
101102
102  void rewriteMixVertexShader();
 103 void rewriteMixVertexShader(const Vector<ANGLEShaderSymbol>& symbols);
103104 void rewriteMixFragmentShader();
104105
105106 bool needsInputTexture() const;