Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[GTK] Rendering artifacts when resizing the window in X11 with AC mod…
…e enabled

https://bugs.webkit.org/show_bug.cgi?id=168728

Reviewed by Žan Doberšek.

This happens because the pixmap we create from the redirected window is uninitialized until the threaded
compositor renders into it. We should always initialize the pixmap right after it's created.

* WebProcess/WebPage/gtk/AcceleratedSurfaceX11.cpp:
(WebKit::defaultVisual): Helper static method to get the default GdkVisual.
(WebKit::AcceleratedSurfaceX11::AcceleratedSurfaceX11): Use createPixmap().
(WebKit::AcceleratedSurfaceX11::createPixmap): Create and initialize the pixmap.
(WebKit::AcceleratedSurfaceX11::resize): Use createPixmap().
* WebProcess/WebPage/gtk/AcceleratedSurfaceX11.h:

Canonical link: https://commits.webkit.org/185899@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213061 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos committed Feb 27, 2017
1 parent 1dba9cb commit 1d031fd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
17 changes: 17 additions & 0 deletions Source/WebKit2/ChangeLog
@@ -1,3 +1,20 @@
2017-02-27 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] Rendering artifacts when resizing the window in X11 with AC mode enabled
https://bugs.webkit.org/show_bug.cgi?id=168728

Reviewed by Žan Doberšek.

This happens because the pixmap we create from the redirected window is uninitialized until the threaded
compositor renders into it. We should always initialize the pixmap right after it's created.

* WebProcess/WebPage/gtk/AcceleratedSurfaceX11.cpp:
(WebKit::defaultVisual): Helper static method to get the default GdkVisual.
(WebKit::AcceleratedSurfaceX11::AcceleratedSurfaceX11): Use createPixmap().
(WebKit::AcceleratedSurfaceX11::createPixmap): Create and initialize the pixmap.
(WebKit::AcceleratedSurfaceX11::resize): Use createPixmap().
* WebProcess/WebPage/gtk/AcceleratedSurfaceX11.h:

2017-02-27 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] Flickering when leaving accelerated compositing mode
Expand Down
29 changes: 22 additions & 7 deletions Source/WebKit2/WebProcess/WebPage/gtk/AcceleratedSurfaceX11.cpp
Expand Up @@ -30,8 +30,10 @@

#include "WebPage.h"
#include <WebCore/PlatformDisplayX11.h>
#include <WebCore/RefPtrCairo.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xcomposite.h>
#include <cairo-xlib.h>
#include <gdk/gdkx.h>
#include <wtf/RunLoop.h>

Expand All @@ -46,17 +48,22 @@ std::unique_ptr<AcceleratedSurfaceX11> AcceleratedSurfaceX11::create(WebPage& we
return std::unique_ptr<AcceleratedSurfaceX11>(new AcceleratedSurfaceX11(webPage));
}

static GdkVisual* defaultVisual()
{
if (GdkVisual* visual = gdk_screen_get_rgba_visual(gdk_screen_get_default()))
return visual;
return gdk_screen_get_system_visual(gdk_screen_get_default());
}

AcceleratedSurfaceX11::AcceleratedSurfaceX11(WebPage& webPage)
: AcceleratedSurface(webPage)
, m_display(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native())
{
Screen* screen = DefaultScreenOfDisplay(m_display);

ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display);
GdkVisual* visual = gdk_screen_get_rgba_visual(gdk_screen_get_default());
if (!visual)
visual = gdk_screen_get_system_visual(gdk_screen_get_default());

GdkVisual* visual = defaultVisual();
XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone));

XSetWindowAttributes windowAttributes;
Expand Down Expand Up @@ -103,8 +110,7 @@ AcceleratedSurfaceX11::AcceleratedSurfaceX11(WebPage& webPage)
}
XSelectInput(m_display, m_window.get(), NoEventMask);
XCompositeRedirectWindow(m_display, m_window.get(), CompositeRedirectManual);
m_pixmap = XCompositeNameWindowPixmap(m_display, m_window.get());
XSync(m_display, False);
createPixmap();
}

AcceleratedSurfaceX11::~AcceleratedSurfaceX11()
Expand All @@ -118,6 +124,16 @@ AcceleratedSurfaceX11::~AcceleratedSurfaceX11()
m_parentWindow.reset();
}

void AcceleratedSurfaceX11::createPixmap()
{
m_pixmap = XCompositeNameWindowPixmap(m_display, m_window.get());
RefPtr<cairo_surface_t> surface = adoptRef(cairo_xlib_surface_create(m_display, m_pixmap.get(), GDK_VISUAL_XVISUAL(defaultVisual()), m_size.width(), m_size.height()));
RefPtr<cairo_t> cr = adoptRef(cairo_create(surface.get()));
cairo_set_operator(cr.get(), CAIRO_OPERATOR_CLEAR);
cairo_paint(cr.get());
XSync(m_display, False);
}

bool AcceleratedSurfaceX11::resize(const IntSize& size)
{
if (!AcceleratedSurface::resize(size))
Expand All @@ -129,8 +145,7 @@ bool AcceleratedSurfaceX11::resize(const IntSize& size)

// Release the previous pixmap later to give some time to the UI process to update.
RunLoop::main().dispatchAfter(std::chrono::seconds(5), [pixmap = WTFMove(m_pixmap)] { });
m_pixmap = XCompositeNameWindowPixmap(m_display, m_window.get());
XSync(m_display, False);
createPixmap();
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit2/WebProcess/WebPage/gtk/AcceleratedSurfaceX11.h
Expand Up @@ -52,6 +52,8 @@ class AcceleratedSurfaceX11 final : public AcceleratedSurface {
private:
AcceleratedSurfaceX11(WebPage&);

void createPixmap();

Display* m_display { nullptr };
WebCore::XUniqueWindow m_window;
WebCore::XUniqueWindow m_parentWindow;
Expand Down

0 comments on commit 1d031fd

Please sign in to comment.