Commit 524ce7f8 authored by Rob Bradford's avatar Rob Bradford

wayland: Cache the discovery connection and reuse if possible

This will prevent us opening, closing and reopening the same display
connection in the majority of cases.

https://bugzilla.gnome.org/show_bug.cgi?id=694465
parent 3df715a5
......@@ -214,18 +214,13 @@ log_handler(const char *format, va_list args)
}
GdkDisplay *
_gdk_wayland_display_open (const gchar *display_name)
_gdk_wayland_display_open (struct wl_display *wl_display)
{
struct wl_display *wl_display;
GdkDisplay *display;
GdkWaylandDisplay *display_wayland;
wl_log_set_handler_client(log_handler);
wl_display = wl_display_connect(display_name);
if (!wl_display)
return NULL;
display = g_object_new (GDK_TYPE_WAYLAND_DISPLAY, NULL);
display_wayland = GDK_WAYLAND_DISPLAY (display);
......
......@@ -34,6 +34,10 @@ struct _GdkWaylandDisplayManager
GSList *displays;
gboolean init_failed;
struct {
struct wl_display *wl_display;
gchar *name;
} cached_display;
};
struct _GdkWaylandDisplayManagerClass
......@@ -51,6 +55,7 @@ gdk_wayland_display_manager_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
GdkWaylandDisplayManager *manager = GDK_WAYLAND_DISPLAY_MANAGER (initable);
struct wl_display *wl_display;
/* Set by the compositor when launching a special client - and it gets reset
......@@ -64,12 +69,12 @@ gdk_wayland_display_manager_initable_init (GInitable *initable,
if (!wl_display)
{
GDK_WAYLAND_DISPLAY_MANAGER (initable)->init_failed = TRUE;
manager->init_failed = TRUE;
return FALSE;
}
wl_display_disconnect (wl_display);
manager->cached_display.name = g_strdup (gdk_get_display_arg_name ());
manager->cached_display.wl_display = wl_display;
return TRUE;
}
......@@ -89,10 +94,35 @@ gdk_wayland_display_manager_finalize (GObject *object)
}
static GdkDisplay *
gdk_wayland_display_manager_open_display (GdkDisplayManager *manager,
gdk_wayland_display_manager_open_display (GdkDisplayManager *display_manager,
const gchar *name)
{
return _gdk_wayland_display_open (name);
GdkWaylandDisplayManager *manager = GDK_WAYLAND_DISPLAY_MANAGER (display_manager);
struct wl_display *wl_display;
if (name == manager->cached_display.name ||
g_strcmp0 (name, manager->cached_display.name))
{
/* Cache hit */
wl_display = manager->cached_display.wl_display;
}
if (!wl_display)
{
/* Cache miss */
if (manager->cached_display.wl_display)
wl_display_disconnect (manager->cached_display.wl_display);
wl_display = wl_display_connect (name);
}
/* Use the cache at most once */
g_free (manager->cached_display.name);
manager->cached_display.wl_display = NULL;
if (!wl_display)
return NULL;
return _gdk_wayland_display_open (wl_display);
}
static void
......
......@@ -155,7 +155,7 @@ void _gdk_wayland_display_queue_events (GdkDisplay *display);
GdkAppLaunchContext *_gdk_wayland_display_get_app_launch_context (GdkDisplay *display);
GdkDisplay *_gdk_wayland_display_open (const gchar *display_name);
GdkDisplay *_gdk_wayland_display_open (struct wl_display *display);
GdkWindow *_gdk_wayland_screen_create_root_window (GdkScreen *screen,
int width,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment