Skip to content

Commit f2e936c

Browse files
[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): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@203496 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent c317dec commit f2e936c

File tree

7 files changed

+85
-24
lines changed

7 files changed

+85
-24
lines changed

Source/WebKit2/ChangeLog

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
2016-07-21 Carlos Garcia Campos <[email protected]>
2+
3+
[GTK] Web view background colors don't work in accelerated compositing mode
4+
https://bugs.webkit.org/show_bug.cgi?id=159455
5+
6+
Reviewed by Michael Catanzaro.
7+
8+
In non AC mode it's the drawing area backing store the one drawing the background, and the web process just
9+
renders into a transparent bitmap. In AC mode we need to make the redirected window pixmap transparent for the
10+
web process to render there, and let the web view fill the background color before rendering the redirected
11+
window pixmap on top. To be able to make the redirected window surface transparent, we need to ensure the parent
12+
window has an RGBA visual, even when setting a fully opaque background, because we still need the web process
13+
to render on the transparent xwindow.
14+
15+
* UIProcess/API/gtk/WebKitWebView.cpp: Update documentation of webkit_web_view_set_background_color() since now
16+
it's required to set the RGBA visual even for opaque colors in case AC mode is enabled.
17+
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
18+
(webkitWebViewRenderAcceleratedCompositingResults): When a background color has been set, fill it before
19+
rendering the redirected window surface.
20+
* UIProcess/gtk/RedirectedXCompositeWindow.cpp:
21+
(WebKit::RedirectedXCompositeWindow::RedirectedXCompositeWindow): Mark the surface as dirty after every damage
22+
event, since the web process has modified it.
23+
(WebKit::RedirectedXCompositeWindow::surface): Initialize the surface after creating it, to avoid flickering and
24+
rendering artifacts when waiting for the first damage event from the web process.
25+
* WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
26+
(WebKit::LayerTreeHostGtk::compositeLayersToContext): Use a fully transparent color to clear the context when the page
27+
is resized or when a view background color has been set.
28+
129
2016-07-20 Carlos Garcia Campos <[email protected]>
230

331
[GTK] Avoid the redirected window resize when the view is realized in AC mode

Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -3515,25 +3515,22 @@ void webkitWebViewWebProcessCrashed(WebKitWebView* webView)
35153515
* the actual contents are rendered. Note that if the web page loaded in @web_view
35163516
* specifies a background color, it will take precedence over the @rgba color.
35173517
* By default the @web_view background color is opaque white.
3518-
* If the @rgba color is not fully opaque, the parent window must have a RGBA visual and
3519-
* #GtkWidget:app-paintable property set to %TRUE, for the transparencies to work.
3518+
* Note that the parent window must have a RGBA visual and
3519+
* #GtkWidget:app-paintable property set to %TRUE for backgrounds colors to work.
35203520
*
35213521
* <informalexample><programlisting>
35223522
* static void browser_window_set_background_color (BrowserWindow *window,
35233523
* const GdkRGBA *rgba)
35243524
* {
35253525
* WebKitWebView *web_view;
3526+
* GdkScreen *screen = gtk_window_get_screen (GTK_WINDOW (window));
3527+
* GdkVisual *rgba_visual = gdk_screen_get_rgba_visual (screen);
35263528
*
3527-
* if (rgba->alpha < 1) {
3528-
* GdkScreen *screen = gtk_window_get_screen (GTK_WINDOW (window));
3529-
* GdkVisual *rgba_visual = gdk_screen_get_rgba_visual (screen);
3529+
* if (!rgba_visual)
3530+
* return;
35303531
*
3531-
* if (!rgba_visual)
3532-
* return;
3533-
*
3534-
* gtk_widget_set_visual (GTK_WIDGET (window), rgba_visual);
3535-
* gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
3536-
* }
3532+
* gtk_widget_set_visual (GTK_WIDGET (window), rgba_visual);
3533+
* gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
35373534
*
35383535
* web_view = browser_window_get_web_view (window);
35393536
* webkit_web_view_set_background_color (web_view, rgba);

Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,28 @@ static bool webkitWebViewRenderAcceleratedCompositingResults(WebKitWebViewBase*
592592
webkitWebViewBaseResizeRedirectedWindow(webViewBase);
593593
if (cairo_surface_t* surface = priv->redirectedWindow->surface()) {
594594
cairo_save(cr);
595+
596+
if (!priv->pageProxy->drawsBackground()) {
597+
const WebCore::Color& color = priv->pageProxy->backgroundColor();
598+
if (color.hasAlpha()) {
599+
cairo_rectangle(cr, clipRect->x, clipRect->y, clipRect->width, clipRect->height);
600+
cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
601+
cairo_fill(cr);
602+
}
603+
604+
if (color.alpha() > 0) {
605+
setSourceRGBAFromColor(cr, color);
606+
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
607+
cairo_rectangle(cr, clipRect->x, clipRect->y, clipRect->width, clipRect->height);
608+
cairo_fill(cr);
609+
}
610+
}
611+
595612
cairo_rectangle(cr, clipRect->x, clipRect->y, clipRect->width, clipRect->height);
596613
cairo_set_source_surface(cr, surface, 0, 0);
597-
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
614+
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
598615
cairo_fill(cr);
616+
599617
cairo_restore(cr);
600618
}
601619

Source/WebKit2/UIProcess/gtk/RedirectedXCompositeWindow.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ RedirectedXCompositeWindow::RedirectedXCompositeWindow(WebPageProxy& webPage, co
189189
&windowAttributes);
190190
XMapWindow(m_display, m_window.get());
191191

192-
xDamageNotifier().add(m_window.get(), WTFMove(damageNotify));
192+
xDamageNotifier().add(m_window.get(), [this, damageNotify = WTFMove(damageNotify)] {
193+
// The surface has been modified by the web process, mark it as dirty.
194+
if (m_surface)
195+
cairo_surface_mark_dirty(m_surface.get());
196+
damageNotify();
197+
});
193198

194199
while (1) {
195200
XEvent event;
@@ -269,14 +274,18 @@ cairo_surface_t* RedirectedXCompositeWindow::surface()
269274
cairoSurfaceSetDeviceScale(newSurface.get(), m_webPage.deviceScaleFactor(), m_webPage.deviceScaleFactor());
270275

271276
RefPtr<cairo_t> cr = adoptRef(cairo_create(newSurface.get()));
272-
cairo_set_source_rgb(cr.get(), 1, 1, 1);
277+
if (!m_webPage.drawsBackground())
278+
cairo_set_operator(cr.get(), CAIRO_OPERATOR_CLEAR);
279+
else
280+
setSourceRGBAFromColor(cr.get(), m_webPage.backgroundColor());
273281
cairo_paint(cr.get());
274282

275283
// Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions
276284
// of a second after each resize, while doing continuous resizing (which constantly destroys and creates
277285
// pixmap window-backings), the pixmap memory is uninitialized. To work around this issue, paint the old
278286
// pixmap to the new one to properly initialize it.
279287
if (m_surface) {
288+
cairo_set_operator(cr.get(), CAIRO_OPERATOR_OVER);
280289
cairo_set_source_surface(cr.get(), m_surface.get(), 0, 0);
281290
cairo_paint(cr.get());
282291
}

Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ void LayerTreeHostGtk::compositeLayersToContext(CompositePurpose purpose)
313313
// we set the viewport parameters directly from the window size.
314314
IntSize contextSize = m_context->defaultFrameBufferSize();
315315
glViewport(0, 0, contextSize.width(), contextSize.height());
316-
317-
if (purpose == ForResize) {
318-
glClearColor(1, 1, 1, 0);
316+
if (purpose == ForResize || !m_webPage.drawsBackground()) {
317+
glClearColor(0, 0, 0, 0);
319318
glClear(GL_COLOR_BUFFER_BIT);
320319
}
321320

Tools/ChangeLog

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2016-07-21 Carlos Garcia Campos <[email protected]>
2+
3+
[GTK] Web view background colors don't work in accelerated compositing mode
4+
https://bugs.webkit.org/show_bug.cgi?id=159455
5+
6+
Reviewed by Michael Catanzaro.
7+
8+
Set always RGBA visual to the view widget when setting a background color.
9+
10+
* MiniBrowser/gtk/BrowserWindow.c:
11+
(browser_window_set_background_color):
12+
113
2016-07-20 Youenn Fablet <[email protected]>
214

315
Bots should run built-ins generator tests

Tools/MiniBrowser/gtk/BrowserWindow.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -1069,14 +1069,12 @@ void browser_window_set_background_color(BrowserWindow *window, GdkRGBA *rgba)
10691069
if (gdk_rgba_equal(rgba, &viewRGBA))
10701070
return;
10711071

1072-
if (rgba->alpha < 1) {
1073-
GdkVisual *rgbaVisual = gdk_screen_get_rgba_visual(gtk_window_get_screen(GTK_WINDOW(window)));
1074-
if (!rgbaVisual)
1075-
return;
1072+
GdkVisual *rgbaVisual = gdk_screen_get_rgba_visual(gtk_window_get_screen(GTK_WINDOW(window)));
1073+
if (!rgbaVisual)
1074+
return;
10761075

1077-
gtk_widget_set_visual(GTK_WIDGET(window), rgbaVisual);
1078-
gtk_widget_set_app_paintable(GTK_WIDGET(window), TRUE);
1079-
}
1076+
gtk_widget_set_visual(GTK_WIDGET(window), rgbaVisual);
1077+
gtk_widget_set_app_paintable(GTK_WIDGET(window), TRUE);
10801078

10811079
webkit_web_view_set_background_color(webView, rgba);
10821080
}

0 commit comments

Comments
 (0)