<!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>[199536] 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/199536">199536</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-04-14 04:09:37 -0700 (Thu, 14 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>WebGL based canvases composite incorrectly after changing size
https://bugs.webkit.org/show_bug.cgi?id=152556
&lt;rdar://problem/24012678&gt;

Patch by Antoine Quint &lt;graouts@apple.com&gt; on 2016-04-14
Reviewed by Dean Jackson.

Source/WebCore:

On iOS, we use the CAEAGLLayer's bounds to set the size of the backing store.
However, that layer's bounds is also used to size the layer during layout. If
the canvas backing store is resized after layout has been performed, the call
to setBounds loses the layout value and the &lt;canvas&gt; element is incorrectly
sized on screen.

To address this, when updating the backing store, we keep track of the previous
layer bounds so we can reset it after we sized the backing store.

Test: webgl/webgl-backing-store-size-update.html

* platform/graphics/GraphicsContext3D.h:
* platform/graphics/mac/GraphicsContext3DMac.mm:
(WebCore::GraphicsContext3D::setRenderbufferStorageFromDrawable):

LayoutTests:

Adding a new test that sets the size of the backing store to a different
size than the layout size after the layout size of the &lt;canvas&gt; element
has been applied to ensure that the implementation correctly retains the
layout size as the canvas backing store is resized.

* webgl/webgl-backing-store-size-update-expected.html: Added.
* webgl/webgl-backing-store-size-update.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</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="#trunkSourceWebCoreplatformgraphicsmacGraphicsContext3DMacmm">trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestswebglwebglbackingstoresizeupdateexpectedhtml">trunk/LayoutTests/webgl/webgl-backing-store-size-update-expected.html</a></li>
<li><a href="#trunkLayoutTestswebglwebglbackingstoresizeupdatehtml">trunk/LayoutTests/webgl/webgl-backing-store-size-update.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (199535 => 199536)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-04-14 10:12:12 UTC (rev 199535)
+++ trunk/LayoutTests/ChangeLog        2016-04-14 11:09:37 UTC (rev 199536)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2016-04-14  Antoine Quint  &lt;graouts@apple.com&gt;
+
+        WebGL based canvases composite incorrectly after changing size
+        https://bugs.webkit.org/show_bug.cgi?id=152556
+        &lt;rdar://problem/24012678&gt;
+
+        Reviewed by Dean Jackson.
+
+        Adding a new test that sets the size of the backing store to a different
+        size than the layout size after the layout size of the &lt;canvas&gt; element
+        has been applied to ensure that the implementation correctly retains the
+        layout size as the canvas backing store is resized.
+
+        * webgl/webgl-backing-store-size-update-expected.html: Added.
+        * webgl/webgl-backing-store-size-update.html: Added.
+
</ins><span class="cx"> 2016-04-13  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         JSContext Inspector: Improve Class instances and JSC API Exported Values view in Console / ObjectTree
</span></span></pre></div>
<a id="trunkLayoutTestswebglwebglbackingstoresizeupdateexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/webgl/webgl-backing-store-size-update-expected.html (0 => 199536)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webgl/webgl-backing-store-size-update-expected.html                                (rev 0)
+++ trunk/LayoutTests/webgl/webgl-backing-store-size-update-expected.html        2016-04-14 11:09:37 UTC (rev 199536)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+&lt;div style=&quot;width: 50px; height: 50px; background-color: black;&quot;&gt;&lt;/div&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestswebglwebglbackingstoresizeupdatehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/webgl/webgl-backing-store-size-update.html (0 => 199536)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/webgl/webgl-backing-store-size-update.html                                (rev 0)
+++ trunk/LayoutTests/webgl/webgl-backing-store-size-update.html        2016-04-14 11:09:37 UTC (rev 199536)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+&lt;canvas style=&quot;width:100px; height:100px;&quot;&gt;
+&lt;script type=&quot;text/javascript&quot;&gt;
+    if (window.testRunner)
+        testRunner.waitUntilDone();
+
+    var canvas = document.querySelector(&quot;canvas&quot;);
+
+    function draw() {
+        // For the purpose of this test, we want the backing store metrics to
+        // not match the layout metrics.
+        var scaleFactor = 2;
+        canvas.width = canvas.clientWidth * scaleFactor;
+        canvas.height = canvas.clientHeight * scaleFactor;
+
+        var gl = canvas.getContext(&quot;webgl&quot;);
+        gl.clearColor(0, 0, 0, 1);
+        gl.clear(gl.COLOR_BUFFER_BIT);
+    }
+
+    // Size the canvas once at the initial 100px by 100px size.
+    draw();
+
+    // Now change the layout size of the canvas and in the next animation
+    // frame, after we know the layout size has taken effect, change the
+    // size of the backing store.
+    canvas.style.width = &quot;50px&quot;;
+    canvas.style.height = &quot;50px&quot;;
+    window.requestAnimationFrame(function() {
+        draw();
+        if (window.testRunner)
+            testRunner.notifyDone();
+    });
+
+&lt;/script&gt;
+&lt;/canvas&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (199535 => 199536)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-04-14 10:12:12 UTC (rev 199535)
+++ trunk/Source/WebCore/ChangeLog        2016-04-14 11:09:37 UTC (rev 199536)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2016-04-14  Antoine Quint  &lt;graouts@apple.com&gt;
+
+        WebGL based canvases composite incorrectly after changing size
+        https://bugs.webkit.org/show_bug.cgi?id=152556
+        &lt;rdar://problem/24012678&gt;
+
+        Reviewed by Dean Jackson.
+
+        On iOS, we use the CAEAGLLayer's bounds to set the size of the backing store.
+        However, that layer's bounds is also used to size the layer during layout. If
+        the canvas backing store is resized after layout has been performed, the call
+        to setBounds loses the layout value and the &lt;canvas&gt; element is incorrectly
+        sized on screen.
+
+        To address this, when updating the backing store, we keep track of the previous
+        layer bounds so we can reset it after we sized the backing store.
+
+        Test: webgl/webgl-backing-store-size-update.html
+
+        * platform/graphics/GraphicsContext3D.h:
+        * platform/graphics/mac/GraphicsContext3DMac.mm:
+        (WebCore::GraphicsContext3D::setRenderbufferStorageFromDrawable):
+
</ins><span class="cx"> 2016-04-13  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Fix GObject DOM bindings API break after r199392.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContext3Dh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (199535 => 199536)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h        2016-04-14 10:12:12 UTC (rev 199535)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h        2016-04-14 11:09:37 UTC (rev 199536)
</span><span class="lines">@@ -1291,7 +1291,7 @@
</span><span class="cx">     void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels);
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-    bool setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height);
</del><ins>+    void setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     bool reshapeFBOs(const IntSize&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacGraphicsContext3DMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm (199535 => 199536)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm        2016-04-14 10:12:12 UTC (rev 199535)
+++ trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm        2016-04-14 11:09:37 UTC (rev 199536)
</span><span class="lines">@@ -340,12 +340,18 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-bool GraphicsContext3D::setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height)
</del><ins>+void GraphicsContext3D::setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height)
</ins><span class="cx"> {
</span><ins>+    // We need to make a call to setBounds below to update the backing store size but we also
+    // do not want to clobber the bounds set during layout.
+    CGRect previousBounds = [m_webGLLayer.get() bounds];
+
</ins><span class="cx">     [m_webGLLayer setBounds:CGRectMake(0, 0, width, height)];
</span><span class="cx">     [m_webGLLayer setOpaque:(m_internalColorFormat != GL_RGBA8)];
</span><span class="cx"> 
</span><del>-    return [m_contextObj renderbufferStorage:GL_RENDERBUFFER fromDrawable:static_cast&lt;id&lt;EAGLDrawable&gt;&gt;(m_webGLLayer.get())];
</del><ins>+    [m_contextObj renderbufferStorage:GL_RENDERBUFFER fromDrawable:static_cast&lt;id&lt;EAGLDrawable&gt;&gt;(m_webGLLayer.get())];
+
+    [m_webGLLayer setBounds:previousBounds];
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>