<!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>[203496] 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/203496">203496</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2016-07-21 00:18:03 -0700 (Thu, 21 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Web view background colors don't work in accelerated compositing mode
https://bugs.webkit.org/show_bug.cgi?id=159455

Reviewed by Michael Catanzaro.

Source/WebKit2:

In non AC mode it's the drawing area backing store the one drawing the background, and the web process just
renders into a transparent bitmap. In AC mode we need to make the redirected window pixmap transparent for the
web process to render there, and let the web view fill the background color before rendering the redirected
window pixmap on top. To be able to make the redirected window surface transparent, we need to ensure the parent
window has an RGBA visual, even when setting a fully opaque background, because we still need the web process
to render on the transparent xwindow.

* UIProcess/API/gtk/WebKitWebView.cpp: Update documentation of webkit_web_view_set_background_color() since now
it's required to set the RGBA visual even for opaque colors in case AC mode is enabled.
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewRenderAcceleratedCompositingResults): When a background color has been set, fill it before
rendering the redirected window surface.
* UIProcess/gtk/RedirectedXCompositeWindow.cpp:
(WebKit::RedirectedXCompositeWindow::RedirectedXCompositeWindow): Mark the surface as dirty after every damage
event, since the web process has modified it.
(WebKit::RedirectedXCompositeWindow::surface): Initialize the surface after creating it, to avoid flickering and
rendering artifacts when waiting for the first damage event from the web process.
* WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
(WebKit::LayerTreeHostGtk::compositeLayersToContext): Use a fully transparent color to clear the context when the page
is resized or when a view background color has been set.

Tools:

Set always RGBA visual to the view widget when setting a background color.

* MiniBrowser/gtk/BrowserWindow.c:
(browser_window_set_background_color):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewBasecpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkRedirectedXCompositeWindowcpp">trunk/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPagegtkLayerTreeHostGtkcpp">trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsMiniBrowsergtkBrowserWindowc">trunk/Tools/MiniBrowser/gtk/BrowserWindow.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (203495 => 203496)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-07-21 07:04:59 UTC (rev 203495)
+++ trunk/Source/WebKit2/ChangeLog        2016-07-21 07:18:03 UTC (rev 203496)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2016-07-21  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK] Web view background colors don't work in accelerated compositing mode
+        https://bugs.webkit.org/show_bug.cgi?id=159455
+
+        Reviewed by Michael Catanzaro.
+
+        In non AC mode it's the drawing area backing store the one drawing the background, and the web process just
+        renders into a transparent bitmap. In AC mode we need to make the redirected window pixmap transparent for the
+        web process to render there, and let the web view fill the background color before rendering the redirected
+        window pixmap on top. To be able to make the redirected window surface transparent, we need to ensure the parent
+        window has an RGBA visual, even when setting a fully opaque background, because we still need the web process
+        to render on the transparent xwindow.
+
+        * UIProcess/API/gtk/WebKitWebView.cpp: Update documentation of webkit_web_view_set_background_color() since now
+        it's required to set the RGBA visual even for opaque colors in case AC mode is enabled.
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewRenderAcceleratedCompositingResults): When a background color has been set, fill it before
+        rendering the redirected window surface.
+        * UIProcess/gtk/RedirectedXCompositeWindow.cpp:
+        (WebKit::RedirectedXCompositeWindow::RedirectedXCompositeWindow): Mark the surface as dirty after every damage
+        event, since the web process has modified it.
+        (WebKit::RedirectedXCompositeWindow::surface): Initialize the surface after creating it, to avoid flickering and
+        rendering artifacts when waiting for the first damage event from the web process.
+        * WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
+        (WebKit::LayerTreeHostGtk::compositeLayersToContext): Use a fully transparent color to clear the context when the page
+        is resized or when a view background color has been set.
+
</ins><span class="cx"> 2016-07-20  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] Avoid the redirected window resize when the view is realized in AC mode
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (203495 => 203496)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2016-07-21 07:04:59 UTC (rev 203495)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2016-07-21 07:18:03 UTC (rev 203496)
</span><span class="lines">@@ -3515,8 +3515,8 @@
</span><span class="cx">  * the actual contents are rendered. Note that if the web page loaded in @web_view
</span><span class="cx">  * specifies a background color, it will take precedence over the @rgba color.
</span><span class="cx">  * By default the @web_view background color is opaque white.
</span><del>- * If the @rgba color is not fully opaque, the parent window must have a RGBA visual and
- * #GtkWidget:app-paintable property set to %TRUE, for the transparencies to work.
</del><ins>+ * Note that the parent window must have a RGBA visual and
+ * #GtkWidget:app-paintable property set to %TRUE for backgrounds colors to work.
</ins><span class="cx">  *
</span><span class="cx">  * &lt;informalexample&gt;&lt;programlisting&gt;
</span><span class="cx">  * static void browser_window_set_background_color (BrowserWindow *window,
</span><span class="lines">@@ -3523,18 +3523,15 @@
</span><span class="cx">  *                                                  const GdkRGBA *rgba)
</span><span class="cx">  * {
</span><span class="cx">  *     WebKitWebView *web_view;
</span><ins>+ *     GdkScreen *screen = gtk_window_get_screen (GTK_WINDOW (window));
+ *     GdkVisual *rgba_visual = gdk_screen_get_rgba_visual (screen);
</ins><span class="cx">  *
</span><del>- *     if (rgba-&gt;alpha &lt; 1) {
- *         GdkScreen *screen = gtk_window_get_screen (GTK_WINDOW (window));
- *         GdkVisual *rgba_visual = gdk_screen_get_rgba_visual (screen);
</del><ins>+ *     if (!rgba_visual)
+ *          return;
</ins><span class="cx">  *
</span><del>- *         if (!rgba_visual)
- *              return;
</del><ins>+ *     gtk_widget_set_visual (GTK_WIDGET (window), rgba_visual);
+ *     gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
</ins><span class="cx">  *
</span><del>- *         gtk_widget_set_visual (GTK_WIDGET (window), rgba_visual);
- *         gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
- *     }
- *
</del><span class="cx">  *     web_view = browser_window_get_web_view (window);
</span><span class="cx">  *     webkit_web_view_set_background_color (web_view, rgba);
</span><span class="cx">  * }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp (203495 => 203496)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp        2016-07-21 07:04:59 UTC (rev 203495)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp        2016-07-21 07:18:03 UTC (rev 203496)
</span><span class="lines">@@ -592,10 +592,28 @@
</span><span class="cx">     webkitWebViewBaseResizeRedirectedWindow(webViewBase);
</span><span class="cx">     if (cairo_surface_t* surface = priv-&gt;redirectedWindow-&gt;surface()) {
</span><span class="cx">         cairo_save(cr);
</span><ins>+
+        if (!priv-&gt;pageProxy-&gt;drawsBackground()) {
+            const WebCore::Color&amp; color = priv-&gt;pageProxy-&gt;backgroundColor();
+            if (color.hasAlpha()) {
+                cairo_rectangle(cr, clipRect-&gt;x, clipRect-&gt;y, clipRect-&gt;width, clipRect-&gt;height);
+                cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
+                cairo_fill(cr);
+            }
+
+            if (color.alpha() &gt; 0) {
+                setSourceRGBAFromColor(cr, color);
+                cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+                cairo_rectangle(cr, clipRect-&gt;x, clipRect-&gt;y, clipRect-&gt;width, clipRect-&gt;height);
+                cairo_fill(cr);
+            }
+        }
+
</ins><span class="cx">         cairo_rectangle(cr, clipRect-&gt;x, clipRect-&gt;y, clipRect-&gt;width, clipRect-&gt;height);
</span><span class="cx">         cairo_set_source_surface(cr, surface, 0, 0);
</span><del>-        cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
</del><ins>+        cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
</ins><span class="cx">         cairo_fill(cr);
</span><ins>+
</ins><span class="cx">         cairo_restore(cr);
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkRedirectedXCompositeWindowcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp (203495 => 203496)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp        2016-07-21 07:04:59 UTC (rev 203495)
+++ trunk/Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp        2016-07-21 07:18:03 UTC (rev 203496)
</span><span class="lines">@@ -189,7 +189,12 @@
</span><span class="cx">         &amp;windowAttributes);
</span><span class="cx">     XMapWindow(m_display, m_window.get());
</span><span class="cx"> 
</span><del>-    xDamageNotifier().add(m_window.get(), WTFMove(damageNotify));
</del><ins>+    xDamageNotifier().add(m_window.get(), [this, damageNotify = WTFMove(damageNotify)] {
+        // The surface has been modified by the web process, mark it as dirty.
+        if (m_surface)
+            cairo_surface_mark_dirty(m_surface.get());
+        damageNotify();
+    });
</ins><span class="cx"> 
</span><span class="cx">     while (1) {
</span><span class="cx">         XEvent event;
</span><span class="lines">@@ -269,7 +274,10 @@
</span><span class="cx">     cairoSurfaceSetDeviceScale(newSurface.get(), m_webPage.deviceScaleFactor(), m_webPage.deviceScaleFactor());
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;cairo_t&gt; cr = adoptRef(cairo_create(newSurface.get()));
</span><del>-    cairo_set_source_rgb(cr.get(), 1, 1, 1);
</del><ins>+    if (!m_webPage.drawsBackground())
+        cairo_set_operator(cr.get(), CAIRO_OPERATOR_CLEAR);
+    else
+        setSourceRGBAFromColor(cr.get(), m_webPage.backgroundColor());
</ins><span class="cx">     cairo_paint(cr.get());
</span><span class="cx"> 
</span><span class="cx">     // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions
</span><span class="lines">@@ -277,6 +285,7 @@
</span><span class="cx">     // pixmap window-backings), the pixmap memory is uninitialized. To work around this issue, paint the old
</span><span class="cx">     // pixmap to the new one to properly initialize it.
</span><span class="cx">     if (m_surface) {
</span><ins>+        cairo_set_operator(cr.get(), CAIRO_OPERATOR_OVER);
</ins><span class="cx">         cairo_set_source_surface(cr.get(), m_surface.get(), 0, 0);
</span><span class="cx">         cairo_paint(cr.get());
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPagegtkLayerTreeHostGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp (203495 => 203496)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp        2016-07-21 07:04:59 UTC (rev 203495)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp        2016-07-21 07:18:03 UTC (rev 203496)
</span><span class="lines">@@ -313,9 +313,8 @@
</span><span class="cx">     // we set the viewport parameters directly from the window size.
</span><span class="cx">     IntSize contextSize = m_context-&gt;defaultFrameBufferSize();
</span><span class="cx">     glViewport(0, 0, contextSize.width(), contextSize.height());
</span><del>-
-    if (purpose == ForResize) {
-        glClearColor(1, 1, 1, 0);
</del><ins>+    if (purpose == ForResize || !m_webPage.drawsBackground()) {
+        glClearColor(0, 0, 0, 0);
</ins><span class="cx">         glClear(GL_COLOR_BUFFER_BIT);
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (203495 => 203496)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-07-21 07:04:59 UTC (rev 203495)
+++ trunk/Tools/ChangeLog        2016-07-21 07:18:03 UTC (rev 203496)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-07-21  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [GTK] Web view background colors don't work in accelerated compositing mode
+        https://bugs.webkit.org/show_bug.cgi?id=159455
+
+        Reviewed by Michael Catanzaro.
+
+        Set always RGBA visual to the view widget when setting a background color.
+
+        * MiniBrowser/gtk/BrowserWindow.c:
+        (browser_window_set_background_color):
+
</ins><span class="cx"> 2016-07-20  Youenn Fablet  &lt;youenn@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Bots should run built-ins generator tests
</span></span></pre></div>
<a id="trunkToolsMiniBrowsergtkBrowserWindowc"></a>
<div class="modfile"><h4>Modified: trunk/Tools/MiniBrowser/gtk/BrowserWindow.c (203495 => 203496)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/MiniBrowser/gtk/BrowserWindow.c        2016-07-21 07:04:59 UTC (rev 203495)
+++ trunk/Tools/MiniBrowser/gtk/BrowserWindow.c        2016-07-21 07:18:03 UTC (rev 203496)
</span><span class="lines">@@ -1069,14 +1069,12 @@
</span><span class="cx">     if (gdk_rgba_equal(rgba, &amp;viewRGBA))
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (rgba-&gt;alpha &lt; 1) {
-        GdkVisual *rgbaVisual = gdk_screen_get_rgba_visual(gtk_window_get_screen(GTK_WINDOW(window)));
-        if (!rgbaVisual)
-            return;
</del><ins>+    GdkVisual *rgbaVisual = gdk_screen_get_rgba_visual(gtk_window_get_screen(GTK_WINDOW(window)));
+    if (!rgbaVisual)
+        return;
</ins><span class="cx"> 
</span><del>-        gtk_widget_set_visual(GTK_WIDGET(window), rgbaVisual);
-        gtk_widget_set_app_paintable(GTK_WIDGET(window), TRUE);
-    }
</del><ins>+    gtk_widget_set_visual(GTK_WIDGET(window), rgbaVisual);
+    gtk_widget_set_app_paintable(GTK_WIDGET(window), TRUE);
</ins><span class="cx"> 
</span><span class="cx">     webkit_web_view_set_background_color(webView, rgba);
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>