1 /* GStreamer Wayland video sink
3 * Copyright (C) 2011 Intel Corporation
4 * Copyright (C) 2011 Sreerenj Balachandran <sreerenj.balachandran@intel.com>
5 * Copyright (C) 2014 Collabora Ltd.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA.
29 GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
30 #define GST_CAT_DEFAULT gstwayland_debug
32 G_DEFINE_TYPE (GstWlWindow, gst_wl_window, G_TYPE_OBJECT);
34 static void gst_wl_window_finalize (GObject * gobject);
37 handle_ping (void *data, struct wl_shell_surface *shell_surface,
40 wl_shell_surface_pong (shell_surface, serial);
44 handle_configure (void *data, struct wl_shell_surface *shell_surface,
45 uint32_t edges, int32_t width, int32_t height)
50 handle_popup_done (void *data, struct wl_shell_surface *shell_surface)
54 static const struct wl_shell_surface_listener shell_surface_listener = {
61 gst_wl_window_class_init (GstWlWindowClass * klass)
63 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
64 gobject_class->finalize = gst_wl_window_finalize;
68 gst_wl_window_init (GstWlWindow * self)
73 gst_wl_window_finalize (GObject * gobject)
75 GstWlWindow *self = GST_WL_WINDOW (gobject);
77 wl_viewport_destroy (self->viewport);
79 if (self->shell_surface) {
80 wl_shell_surface_destroy (self->shell_surface);
83 if (self->own_surface) {
84 wl_surface_destroy (self->surface);
87 g_clear_object (&self->display);
89 G_OBJECT_CLASS (gst_wl_window_parent_class)->finalize (gobject);
93 gst_wl_window_new_toplevel (GstWlDisplay * display, gint width, gint height)
97 window = gst_wl_window_new_from_surface (display,
98 wl_compositor_create_surface (display->compositor));
99 window->own_surface = TRUE;
101 gst_wl_window_set_size (window, width, height);
103 window->shell_surface = wl_shell_get_shell_surface (display->shell,
106 if (window->shell_surface) {
107 wl_shell_surface_add_listener (window->shell_surface,
108 &shell_surface_listener, window);
109 wl_shell_surface_set_toplevel (window->shell_surface);
111 GST_ERROR ("Unable to get wl_shell_surface");
113 g_object_unref (window);
121 gst_wl_window_new_from_surface (GstWlDisplay * display,
122 struct wl_surface * surface)
125 struct wl_region *region;
127 g_return_val_if_fail (surface != NULL, NULL);
129 window = g_object_new (GST_TYPE_WL_WINDOW, NULL);
130 window->display = g_object_ref (display);
134 window->surface = surface;
135 window->own_surface = FALSE;
137 /* make sure the surface runs on our local queue */
138 wl_proxy_set_queue ((struct wl_proxy *) surface, display->queue);
140 window->viewport = wl_scaler_get_viewport (display->scaler, window->surface);
142 /* do not accept input */
143 region = wl_compositor_create_region (display->compositor);
144 wl_surface_set_input_region (surface, region);
145 wl_region_destroy (region);
151 gst_wl_window_get_display (GstWlWindow * window)
153 g_return_val_if_fail (window != NULL, NULL);
155 return g_object_ref (window->display);
159 gst_wl_window_get_wl_surface (GstWlWindow * window)
161 g_return_val_if_fail (window != NULL, NULL);
163 return window->surface;
167 gst_wl_window_is_toplevel (GstWlWindow * window)
169 g_return_val_if_fail (window != NULL, FALSE);
171 return (window->shell_surface != NULL);
175 gst_wl_window_set_size (GstWlWindow * window, gint w, gint h)
177 g_return_if_fail (window != NULL);