<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[168112] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/168112">168112</a></dd>
<dt>Author</dt> <dd>bfulgham@apple.com</dd>
<dt>Date</dt> <dd>2014-05-01 12:02:49 -0700 (Thu, 01 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix handling of attributes prior to compiling shader
https://bugs.webkit.org/show_bug.cgi?id=132430

Reviewed by Dean Jackson.


Source/WebCore: 
WebGL programs that called bindAttribLocations prior to compiling shader sources
would perform the bind using the non-hashed symbol name, but would later create
the attributes as hashed names. Consequently, the program would refer to
attributes that were never actually part of any shader, resulting in some amazing
display artifacts.

This patch adds a dictionary of hashed symbol names so that we can tell the WebGL
program the proper name that will be used when the shader is eventually compiled,
allowing the WebGL program to link against the proper symbol after compiling and
linking completes.

* platform/graphics/GraphicsContext3D.h:
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::generateHashedName): Function uses the ANGLE hashing
function to generate correct symbol.
(WebCore::GraphicsContext3D::mappedSymbolName): If we haven't compiled shaders yet, look
in our set of potentially unused attributes.
(WebCore::GraphicsContext3D::originalSymbolName): Ditto, for reverse lookup.

Source/WTF: 
WebGL programs that called bindAttribLocations prior to compiling shader sources
would perform the bind using the non-hashed symbol name, but would later create
the attributes as hashed names. Consequently, the program would refer to
attributes that were never actually part of any shader, resulting in some amazing
display artifacts.

This patch adds a dictionary of hashed symbol names so that we can tell the WebGL
program the proper name that will be used when the shader is eventually compiled,
allowing the WebGL program to link against the proper symbol after compiling and
linking completes.

* wtf/HexNumber.h:
(WTF::appendUnsigned64AsHex): Add uint64_t-compatible hex-&gt;string converter.

LayoutTests: 
* fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt: Added.
* fast/canvas/webgl/gl-bind-attrib-location-before-compile-test.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfHexNumberh">trunk/Source/WTF/wtf/HexNumber.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContext3Dh">trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsopenglGraphicsContext3DOpenGLCommoncpp">trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastcanvaswebglglbindattriblocationbeforecompiletestexpectedtxt">trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastcanvaswebglglbindattriblocationbeforecompiletesthtml">trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (168111 => 168112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-05-01 18:49:37 UTC (rev 168111)
+++ trunk/LayoutTests/ChangeLog        2014-05-01 19:02:49 UTC (rev 168112)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2014-05-01  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        Fix handling of attributes prior to compiling shader
+        https://bugs.webkit.org/show_bug.cgi?id=132430
+
+        Reviewed by Dean Jackson.
+
+        * fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt: Added.
+        * fast/canvas/webgl/gl-bind-attrib-location-before-compile-test.html: Added.
+
</ins><span class="cx"> 2014-05-01  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Subpixel rendering: Make selection gaps painting subpixel aware.
</span></span></pre></div>
<a id="trunkLayoutTestsfastcanvaswebglglbindattriblocationbeforecompiletestexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt (0 => 168112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test-expected.txt        2014-05-01 19:02:49 UTC (rev 168112)
</span><span class="lines">@@ -0,0 +1,28 @@
</span><ins>+This test ensures WebGL implementations properly handle bindAttribLocation before compiling shaders.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Canvas.getContext
+PASS [object WebGLRenderingContext] is non-null.
+
+Checking gl.bindAttribLocation.
+PASS getError was expected value: NO_ERROR : bindAttribLocation should return NO_ERROR when called before compiling shader.
+PASS program linked successfully
+_glesVertex:5
+vColor   :2
+PASS location of _glesVertex should be 5
+PASS location of vColor should be 2
+PASS drawing is correct
+PASS program linked successfully
+_glesVertex:5
+vColor   :1
+PASS location of _glesVertex should be 5
+PASS location of vColor should be 1
+FAIL pixel at (20,15) is (0,255,0,255), should be (255,0,0,255)
+PASS getError was expected value: NO_ERROR : 
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastcanvaswebglglbindattriblocationbeforecompiletesthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test.html (0 => 168112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test.html                                (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/gl-bind-attrib-location-before-compile-test.html        2014-05-01 19:02:49 UTC (rev 168112)
</span><span class="lines">@@ -0,0 +1,197 @@
</span><ins>+&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
+  &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
+&lt;title&gt;WebGL BindAttribLocation (Before Compile) Conformance Tests&lt;/title&gt;
+&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;resources/webgl-test.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div id=&quot;description&quot;&gt;&lt;/div&gt;
+&lt;div id=&quot;console&quot;&gt;&lt;/div&gt;
+&lt;canvas style=&quot;border: 1px solid black;&quot; id=&quot;canvas&quot; width=&quot;50&quot; height=&quot;50&quot;&gt;&lt;/canvas&gt;
+&lt;script id=&quot;vshader&quot; type=&quot;text/something-not-javascript&quot;&gt;
+attribute vec4 _glesVertex;
+attribute vec4 vColor;
+varying vec4 color;
+void main()
+{
+  gl_Position = _glesVertex;
+  color = vColor;
+}
+&lt;/script&gt;
+&lt;script id=&quot;fshader&quot; type=&quot;text/something-not-javascript&quot;&gt;
+#ifdef GL_ES
+precision highp float;
+#endif
+varying vec4 color;
+void main()
+{
+  gl_FragColor = color;
+}
+&lt;/script&gt;
+&lt;script&gt;
+description(&quot;This test ensures WebGL implementations properly handle bindAttribLocation before compiling shaders.&quot;);
+
+if (window.internals)
+    window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
+
+debug(&quot;&quot;);
+debug(&quot;Canvas.getContext&quot;);
+
+var gl = create3DContext(document.getElementById(&quot;canvas&quot;));
+shouldBeNonNull(gl);
+
+function fail(x,y, buf, shouldBe)
+{
+  var i = (y*50+x) * 4;
+  var reason = &quot;pixel at (&quot;+x+&quot;,&quot;+y+&quot;) is (&quot;+buf[i]+&quot;,&quot;+buf[i+1]+&quot;,&quot;+buf[i+2]+&quot;,&quot;+buf[i+3]+&quot;), should be &quot;+shouldBe;
+  testFailed(reason);
+}
+
+function pass()
+{
+  testPassed(&quot;drawing is correct&quot;);
+}
+
+function loadShader(shaderType, shaderId) {
+  // Get the shader source.
+  var shaderSource = document.getElementById(shaderId).text;
+
+  // Create the shader object
+  var shader = gl.createShader(shaderType);
+  if (shader == null) {
+    debug(&quot;*** Error: unable to create shader '&quot;+shaderId+&quot;'&quot;);
+    return null;
+  }
+
+  // Load the shader source
+  gl.shaderSource(shader, shaderSource);
+
+  // Compile the shader
+  gl.compileShader(shader);
+
+  // Check the compile status
+  var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
+  if (!compiled) {
+    // Something went wrong during compilation; get the error
+    var error = gl.getShaderInfoLog(shader);
+    debug(&quot;*** Error compiling shader '&quot;+shader+&quot;':&quot;+error);
+    gl.deleteShader(shader);
+    return null;
+  }
+  return shader;
+}
+
+debug(&quot;&quot;);
+debug(&quot;Checking gl.bindAttribLocation.&quot;);
+
+var program = gl.createProgram();
+
+// Bind _glesVertex BEFORE we comile the program.
+gl.bindAttribLocation(program, 5, &quot;_glesVertex&quot;);
+glErrorShouldBe(gl, gl.NO_ERROR,
+    &quot;bindAttribLocation should return NO_ERROR when called before compiling shader.&quot;);
+
+var vs = loadShader(gl.VERTEX_SHADER, &quot;vshader&quot;);
+var fs = loadShader(gl.FRAGMENT_SHADER, &quot;fshader&quot;);
+gl.attachShader(program, vs);
+gl.attachShader(program, fs);
+
+var positions = gl.createBuffer();
+gl.bindBuffer(gl.ARRAY_BUFFER, positions);
+gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW);
+
+var colors = gl.createBuffer();
+gl.bindBuffer(gl.ARRAY_BUFFER, colors);
+gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
+    0,1,0,1,
+    0,1,0,1,
+    0,1,0,1]), gl.STATIC_DRAW);
+
+function setBindLocations(colorLocation, positionLocation) {
+  gl.bindAttribLocation(program, colorLocation, &quot;vColor&quot;);
+  gl.linkProgram(program);
+  gl.useProgram(program);
+  var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
+  assertMsg(linked, &quot;program linked successfully&quot;);
+
+  debug(&quot;_glesVertex:&quot; + gl.getAttribLocation(program, &quot;_glesVertex&quot;))
+  debug(&quot;vColor   :&quot; + gl.getAttribLocation(program, &quot;vColor&quot;))
+  assertMsg(gl.getAttribLocation(program, &quot;_glesVertex&quot;) == positionLocation,
+            &quot;location of _glesVertex should be &quot; + positionLocation);
+  assertMsg(gl.getAttribLocation(program, &quot;vColor&quot;) == colorLocation,
+            &quot;location of vColor should be &quot; + colorLocation);
+
+  var ploc = gl.getAttribLocation(program, &quot;_glesVertex&quot;);
+  var cloc = gl.getAttribLocation(program, &quot;vColor&quot;);
+  gl.bindBuffer(gl.ARRAY_BUFFER, positions);
+  gl.enableVertexAttribArray(positionLocation);
+  gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
+  gl.bindBuffer(gl.ARRAY_BUFFER, colors);
+  gl.enableVertexAttribArray(colorLocation);
+  gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
+}
+
+function checkDraw(colorLocation, positionLocation, r, g, b, a) {
+  gl.clearColor(0, 0, 0, 1);
+  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+  gl.drawArrays(gl.TRIANGLES, 0, 3);
+
+  var width = 50;
+  var height = 50;
+  var buf = new Uint8Array(width * height * 4);
+  gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
+
+  function checkPixel(x, y, r, g, b, a) {
+    var offset = (y * width + x) * 4;
+    if (buf[offset + 0] != r ||
+        buf[offset + 1] != g ||
+        buf[offset + 2] != b ||
+        buf[offset + 3] != a) {
+        fail(x, y, buf, &quot;(&quot; + r + &quot;,&quot; + g + &quot;,&quot; + b + &quot;,&quot; + a + &quot;)&quot;);
+        return false;
+    }
+    return true;
+  }
+
+  // Test several locations
+  // First line should be all black
+  var success = true;
+  for (var i = 0; i &lt; 50; ++i)
+    success = success &amp;&amp; checkPixel(i, 0, 0, 0, 0, 255);
+
+  // Line 15 should be red for at least 10 rgba pixels starting 20 pixels in
+  var offset = (15 * 50 + 20) * 4;
+  for (var i = 0; i &lt; 10; ++i)
+    success = success &amp;&amp; checkPixel(20 + i, 15, r, g, b, a);
+
+  // Last line should be all black
+  for (var i = 0; i &lt; 50; ++i)
+    success = success &amp;&amp; checkPixel(i, 49, 0, 0, 0, 255);
+
+  if (success)
+    pass();
+
+  gl.disableVertexAttribArray(positionLocation);
+  gl.disableVertexAttribArray(colorLocation);
+}
+
+setBindLocations(2, 5);
+checkDraw(2, 5, 0, 255, 0, 255);
+
+setBindLocations(1, 5);
+gl.disableVertexAttribArray(0);
+gl.vertexAttrib4f(0, 1, 0, 0, 1);
+checkDraw(1, 5, 255, 0, 0, 255);
+
+glErrorShouldBe(gl, gl.NO_ERROR);
+
+debug(&quot;&quot;);
+
+&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (168111 => 168112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-05-01 18:49:37 UTC (rev 168111)
+++ trunk/Source/WTF/ChangeLog        2014-05-01 19:02:49 UTC (rev 168112)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2014-05-01  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        Fix handling of attributes prior to compiling shader
+        https://bugs.webkit.org/show_bug.cgi?id=132430
+
+        Reviewed by Dean Jackson.
+
+        WebGL programs that called bindAttribLocations prior to compiling shader sources
+        would perform the bind using the non-hashed symbol name, but would later create
+        the attributes as hashed names. Consequently, the program would refer to
+        attributes that were never actually part of any shader, resulting in some amazing
+        display artifacts.
+
+        This patch adds a dictionary of hashed symbol names so that we can tell the WebGL
+        program the proper name that will be used when the shader is eventually compiled,
+        allowing the WebGL program to link against the proper symbol after compiling and
+        linking completes.
+
+        * wtf/HexNumber.h:
+        (WTF::appendUnsigned64AsHex): Add uint64_t-compatible hex-&gt;string converter.
+
</ins><span class="cx"> 2014-04-30  Geoffrey Garen  &lt;ggaren@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Link against bmalloc in production builds
</span></span></pre></div>
<a id="trunkSourceWTFwtfHexNumberh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/HexNumber.h (168111 => 168112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/HexNumber.h        2014-05-01 18:49:37 UTC (rev 168111)
+++ trunk/Source/WTF/wtf/HexNumber.h        2014-05-01 19:02:49 UTC (rev 168112)
</span><span class="lines">@@ -78,6 +78,20 @@
</span><span class="cx">     result.reverse();
</span><span class="cx">     destination.append(result.data(), result.size());
</span><span class="cx"> }
</span><ins>+    
+template&lt;typename T&gt;
+inline void appendUnsigned64AsHex(uint64_t number, T&amp; destination, HexConversionMode mode = Uppercase)
+{
+    const LChar* hexDigits = Internal::hexDigitsForMode(mode);
+    Vector&lt;LChar, 8&gt; result;
+    do {
+        result.append(hexDigits[number % 16]);
+        number &gt;&gt;= 4;
+    } while (number &gt; 0);
+    
+    result.reverse();
+    destination.append(result.data(), result.size());
+}
</ins><span class="cx"> 
</span><span class="cx"> // Same as appendUnsignedAsHex, but using exactly 'desiredDigits' for the conversion.
</span><span class="cx"> template&lt;typename T&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (168111 => 168112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-05-01 18:49:37 UTC (rev 168111)
+++ trunk/Source/WebCore/ChangeLog        2014-05-01 19:02:49 UTC (rev 168112)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2014-05-01  Brent Fulgham  &lt;bfulgham@apple.com&gt;
+
+        Fix handling of attributes prior to compiling shader
+        https://bugs.webkit.org/show_bug.cgi?id=132430
+
+        Reviewed by Dean Jackson.
+
+        WebGL programs that called bindAttribLocations prior to compiling shader sources
+        would perform the bind using the non-hashed symbol name, but would later create
+        the attributes as hashed names. Consequently, the program would refer to
+        attributes that were never actually part of any shader, resulting in some amazing
+        display artifacts.
+
+        This patch adds a dictionary of hashed symbol names so that we can tell the WebGL
+        program the proper name that will be used when the shader is eventually compiled,
+        allowing the WebGL program to link against the proper symbol after compiling and
+        linking completes.
+
+        * platform/graphics/GraphicsContext3D.h:
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+        (WebCore::generateHashedName): Function uses the ANGLE hashing
+        function to generate correct symbol.
+        (WebCore::GraphicsContext3D::mappedSymbolName): If we haven't compiled shaders yet, look
+        in our set of potentially unused attributes.
+        (WebCore::GraphicsContext3D::originalSymbolName): Ditto, for reverse lookup.
+
</ins><span class="cx"> 2014-05-01  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Subpixel rendering: Make selection gaps painting subpixel aware.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContext3Dh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (168111 => 168112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h        2014-05-01 18:49:37 UTC (rev 168111)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h        2014-05-01 19:02:49 UTC (rev 168112)
</span><span class="lines">@@ -1091,7 +1091,10 @@
</span><span class="cx">     };
</span><span class="cx">     typedef HashMap&lt;Platform3DObject, ActiveShaderSymbolCounts&gt; ShaderProgramSymbolCountMap;
</span><span class="cx">     ShaderProgramSymbolCountMap m_shaderProgramSymbolCountMap;
</span><del>-    
</del><ins>+
+    typedef HashMap&lt;String, String&gt; HashedSymbolMap;
+    HashedSymbolMap m_possiblyUnusedAttributeMap;
+
</ins><span class="cx">     String mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String&amp; name);
</span><span class="cx">     String mappedSymbolName(Platform3DObject shaders[2], size_t count, const String&amp; name);
</span><span class="cx">     String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String&amp; name);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsopenglGraphicsContext3DOpenGLCommoncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (168111 => 168112)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp        2014-05-01 18:49:37 UTC (rev 168111)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp        2014-05-01 19:02:49 UTC (rev 168112)
</span><span class="lines">@@ -54,6 +54,7 @@
</span><span class="cx"> #include &lt;runtime/Float32Array.h&gt;
</span><span class="cx"> #include &lt;runtime/Int32Array.h&gt;
</span><span class="cx"> #include &lt;runtime/Uint8Array.h&gt;
</span><ins>+#include &lt;wtf/HexNumber.h&gt;
</ins><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><span class="cx"> #include &lt;wtf/text/StringBuilder.h&gt;
</span><span class="lines">@@ -76,7 +77,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-static ShaderNameHash* currentNameHashMapForShader;
</del><ins>+static ShaderNameHash* currentNameHashMapForShader = nullptr;
</ins><span class="cx"> 
</span><span class="cx"> // Hash function used by the ANGLE translator/compiler to do
</span><span class="cx"> // symbol name mangling. Since this is a static method, before
</span><span class="lines">@@ -789,10 +790,21 @@
</span><span class="cx">     ::glGetAttachedShaders(program, maxCount, count, shaders);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static String generateHashedName(const String&amp; name)
+{
+    if (name.isEmpty())
+        return name;
+    uint64_t number = nameHashForShader(name.utf8().data(), name.length());
+    StringBuilder builder;
+    builder.append(&quot;webgl_&quot;);
+    appendUnsigned64AsHex(number, builder, Lowercase);
+    return builder.toString();
+}
+
</ins><span class="cx"> String GraphicsContext3D::mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType symbolType, const String&amp; name)
</span><span class="cx"> {
</span><span class="cx">     GC3Dsizei count;
</span><del>-    Platform3DObject shaders[2];
</del><ins>+    Platform3DObject shaders[2] = { };
</ins><span class="cx">     getAttachedShaders(program, 2, &amp;count, shaders);
</span><span class="cx"> 
</span><span class="cx">     for (GC3Dsizei i = 0; i &lt; count; ++i) {
</span><span class="lines">@@ -805,6 +817,23 @@
</span><span class="cx">         if (symbolEntry != symbolMap.end())
</span><span class="cx">             return symbolEntry-&gt;value.mappedName;
</span><span class="cx">     }
</span><ins>+
+    if (symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE &amp;&amp; !name.isEmpty()) {
+        // Attributes are a special case: they may be requested before any shaders have been compiled,
+        // and aren't even required to be used in any shader program.
+        if (!nameHashMapForShaders)
+            nameHashMapForShaders = adoptPtr(new ShaderNameHash);
+        currentNameHashMapForShader = nameHashMapForShaders.get();
+
+        String generatedName = generateHashedName(name);
+
+        currentNameHashMapForShader = nullptr;
+
+        m_possiblyUnusedAttributeMap.set(generatedName, name);
+
+        return generatedName;
+    }
+
</ins><span class="cx">     return name;
</span><span class="cx"> }
</span><span class="cx">     
</span><span class="lines">@@ -825,6 +854,16 @@
</span><span class="cx">                 return symbolEntry.key;
</span><span class="cx">         }
</span><span class="cx">     }
</span><ins>+
+    if (symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE &amp;&amp; !name.isEmpty()) {
+        // Attributes are a special case: they may be requested before any shaders have been compiled,
+        // and aren't even required to be used in any shader program.
+
+        const auto&amp; cached = m_possiblyUnusedAttributeMap.find(name);
+        if (cached != m_possiblyUnusedAttributeMap.end())
+            return cached-&gt;value;
+    }
+
</ins><span class="cx">     return name;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>