3 * Copyright (C) 2013 Matthew Waters <ystreet00@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
25 #include "gstgldisplay_wayland.h"
26 #include "gstgldisplay_wayland_private.h"
28 GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
29 #define GST_CAT_DEFAULT gst_gl_display_debug
31 /* We can't define these in the public struct, or we'd break ABI */
32 typedef struct _GstGLDisplayWaylandPrivate
34 struct xdg_wm_base *xdg_wm_base;
35 } GstGLDisplayWaylandPrivate;
37 G_DEFINE_TYPE_WITH_PRIVATE (GstGLDisplayWayland, gst_gl_display_wayland,
40 static void gst_gl_display_wayland_finalize (GObject * object);
41 static guintptr gst_gl_display_wayland_get_handle (GstGLDisplay * display);
44 handle_xdg_wm_base_ping (void *user_data, struct xdg_wm_base *xdg_wm_base,
47 xdg_wm_base_pong (xdg_wm_base, serial);
50 static const struct xdg_wm_base_listener xdg_wm_base_listener = {
51 handle_xdg_wm_base_ping
55 registry_handle_global (void *data, struct wl_registry *registry,
56 uint32_t name, const char *interface, uint32_t version)
58 GstGLDisplayWayland *display = data;
59 GstGLDisplayWaylandPrivate *priv =
60 gst_gl_display_wayland_get_instance_private (display);
62 GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
64 GST_TRACE_OBJECT (display, "registry_handle_global with registry %p, "
65 "interface %s, version %u", registry, interface, version);
67 if (g_strcmp0 (interface, "wl_compositor") == 0) {
69 wl_registry_bind (registry, name, &wl_compositor_interface, 1);
70 } else if (g_strcmp0 (interface, "wl_subcompositor") == 0) {
71 display->subcompositor =
72 wl_registry_bind (registry, name, &wl_subcompositor_interface, 1);
73 } else if (g_strcmp0 (interface, "xdg_wm_base") == 0) {
75 wl_registry_bind (registry, name, &xdg_wm_base_interface, 1);
76 xdg_wm_base_add_listener (priv->xdg_wm_base, &xdg_wm_base_listener,
78 } else if (g_strcmp0 (interface, "wl_shell") == 0) {
79 display->shell = wl_registry_bind (registry, name, &wl_shell_interface, 1);
83 static const struct wl_registry_listener registry_listener = {
84 registry_handle_global
88 _connect_listeners (GstGLDisplayWayland * display)
90 display->registry = wl_display_get_registry (display->display);
91 wl_registry_add_listener (display->registry, ®istry_listener, display);
93 wl_display_roundtrip (display->display);
97 gst_gl_display_wayland_class_init (GstGLDisplayWaylandClass * klass)
99 GST_GL_DISPLAY_CLASS (klass)->get_handle =
100 GST_DEBUG_FUNCPTR (gst_gl_display_wayland_get_handle);
102 G_OBJECT_CLASS (klass)->finalize = gst_gl_display_wayland_finalize;
106 gst_gl_display_wayland_init (GstGLDisplayWayland * display_wayland)
108 GstGLDisplay *display = (GstGLDisplay *) display_wayland;
110 display->type = GST_GL_DISPLAY_TYPE_WAYLAND;
111 display_wayland->foreign_display = FALSE;
115 gst_gl_display_wayland_finalize (GObject * object)
117 GstGLDisplayWayland *display_wayland = GST_GL_DISPLAY_WAYLAND (object);
118 GstGLDisplayWaylandPrivate *priv =
119 gst_gl_display_wayland_get_instance_private (display_wayland);
121 g_clear_pointer (&display_wayland->shell, wl_shell_destroy);
122 g_clear_pointer (&priv->xdg_wm_base, xdg_wm_base_destroy);
124 /* Cause eglTerminate() to occur before wl_display_disconnect()
125 * https://bugzilla.gnome.org/show_bug.cgi?id=787293 */
126 g_object_set_data (object, "gst.gl.display.egl", NULL);
128 if (!display_wayland->foreign_display && display_wayland->display) {
129 wl_display_flush (display_wayland->display);
130 wl_display_disconnect (display_wayland->display);
133 G_OBJECT_CLASS (gst_gl_display_wayland_parent_class)->finalize (object);
137 * gst_gl_display_wayland_new:
138 * @name: (allow-none): a display name
140 * Create a new #GstGLDisplayWayland from the wayland display name. See wl_display_connect()
141 * for details on what is a valid name.
143 * Returns: (transfer full): a new #GstGLDisplayWayland or %NULL
145 GstGLDisplayWayland *
146 gst_gl_display_wayland_new (const gchar * name)
148 GstGLDisplayWayland *ret;
150 GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
152 ret = g_object_new (GST_TYPE_GL_DISPLAY_WAYLAND, NULL);
153 gst_object_ref_sink (ret);
154 ret->display = wl_display_connect (name);
158 GST_ERROR ("Failed to open Wayland display connection with name \'%s\'",
161 GST_INFO ("Failed to open Wayland display connection.");
163 gst_object_unref (ret);
167 _connect_listeners (ret);
173 * gst_gl_display_wayland_new_with_display:
174 * @display: an existing, wayland display
176 * Creates a new display connection from a wl_display Display.
178 * Returns: (transfer full): a new #GstGLDisplayWayland
180 GstGLDisplayWayland *
181 gst_gl_display_wayland_new_with_display (struct wl_display * display)
183 GstGLDisplayWayland *ret;
185 g_return_val_if_fail (display != NULL, NULL);
187 GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
189 ret = g_object_new (GST_TYPE_GL_DISPLAY_WAYLAND, NULL);
190 gst_object_ref_sink (ret);
192 ret->display = display;
193 ret->foreign_display = TRUE;
195 _connect_listeners (ret);
201 gst_gl_display_wayland_get_handle (GstGLDisplay * display)
203 return (guintptr) GST_GL_DISPLAY_WAYLAND (display)->display;
207 gst_gl_display_wayland_get_xdg_wm_base (GstGLDisplayWayland * display)
209 GstGLDisplayWaylandPrivate *priv =
210 gst_gl_display_wayland_get_instance_private (display);
212 return priv->xdg_wm_base;