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) {
80 wl_registry_bind (registry, name, &wl_shell_interface, 1);
84 static const struct wl_registry_listener registry_listener = {
85 registry_handle_global
89 _connect_listeners (GstGLDisplayWayland * display)
91 display->registry = wl_display_get_registry (display->display);
92 wl_registry_add_listener (display->registry, ®istry_listener, display);
94 wl_display_roundtrip (display->display);
98 gst_gl_display_wayland_class_init (GstGLDisplayWaylandClass * klass)
100 GST_GL_DISPLAY_CLASS (klass)->get_handle =
101 GST_DEBUG_FUNCPTR (gst_gl_display_wayland_get_handle);
103 G_OBJECT_CLASS (klass)->finalize = gst_gl_display_wayland_finalize;
107 gst_gl_display_wayland_init (GstGLDisplayWayland * display_wayland)
109 GstGLDisplay *display = (GstGLDisplay *) display_wayland;
111 display->type = GST_GL_DISPLAY_TYPE_WAYLAND;
112 display_wayland->foreign_display = FALSE;
116 gst_gl_display_wayland_finalize (GObject * object)
118 GstGLDisplayWayland *display_wayland = GST_GL_DISPLAY_WAYLAND (object);
119 GstGLDisplayWaylandPrivate *priv =
120 gst_gl_display_wayland_get_instance_private (display_wayland);
122 g_clear_pointer (&display_wayland->wl_shell, wl_shell_destroy);
123 g_clear_pointer (&priv->xdg_wm_base, xdg_wm_base_destroy);
125 /* Cause eglTerminate() to occur before wl_display_disconnect()
126 * https://bugzilla.gnome.org/show_bug.cgi?id=787293 */
127 g_object_set_data (object, "gst.gl.display.egl", NULL);
129 if (!display_wayland->foreign_display && display_wayland->display) {
130 wl_display_flush (display_wayland->display);
131 wl_display_disconnect (display_wayland->display);
134 G_OBJECT_CLASS (gst_gl_display_wayland_parent_class)->finalize (object);
138 * gst_gl_display_wayland_new:
139 * @name: (allow-none): a display name
141 * Create a new #GstGLDisplayWayland from the wayland display name. See wl_display_connect()
142 * for details on what is a valid name.
144 * Returns: (transfer full): a new #GstGLDisplayWayland or %NULL
146 GstGLDisplayWayland *
147 gst_gl_display_wayland_new (const gchar * name)
149 GstGLDisplayWayland *ret;
151 GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
153 ret = g_object_new (GST_TYPE_GL_DISPLAY_WAYLAND, NULL);
154 gst_object_ref_sink (ret);
155 ret->display = wl_display_connect (name);
159 GST_ERROR ("Failed to open Wayland display connection with name \'%s\'",
162 GST_INFO ("Failed to open Wayland display connection.");
164 gst_object_unref (ret);
168 _connect_listeners (ret);
174 * gst_gl_display_wayland_new_with_display:
175 * @display: an existing, wayland display
177 * Creates a new display connection from a wl_display Display.
179 * Returns: (transfer full): a new #GstGLDisplayWayland
181 GstGLDisplayWayland *
182 gst_gl_display_wayland_new_with_display (struct wl_display * display)
184 GstGLDisplayWayland *ret;
186 g_return_val_if_fail (display != NULL, NULL);
188 GST_DEBUG_CATEGORY_GET (gst_gl_display_debug, "gldisplay");
190 ret = g_object_new (GST_TYPE_GL_DISPLAY_WAYLAND, NULL);
191 gst_object_ref_sink (ret);
193 ret->display = display;
194 ret->foreign_display = TRUE;
196 _connect_listeners (ret);
202 gst_gl_display_wayland_get_handle (GstGLDisplay * display)
204 return (guintptr) GST_GL_DISPLAY_WAYLAND (display)->display;
208 gst_gl_display_wayland_get_xdg_wm_base (GstGLDisplayWayland * display)
210 GstGLDisplayWaylandPrivate *priv =
211 gst_gl_display_wayland_get_instance_private (display);
213 return priv->xdg_wm_base;