waylandsink: drop width/height arguments from gst_wl_window_new_from_surface()
[platform/upstream/gstreamer.git] / ext / wayland / wlwindow.c
1 /* GStreamer Wayland video sink
2  *
3  * Copyright (C) 2011 Intel Corporation
4  * Copyright (C) 2011 Sreerenj Balachandran <sreerenj.balachandran@intel.com>
5  * Copyright (C) 2014 Collabora Ltd.
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include "wlwindow.h"
28
29 GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
30 #define GST_CAT_DEFAULT gstwayland_debug
31
32 G_DEFINE_TYPE (GstWlWindow, gst_wl_window, G_TYPE_OBJECT);
33
34 static void gst_wl_window_finalize (GObject * gobject);
35
36 static void
37 handle_ping (void *data, struct wl_shell_surface *shell_surface,
38     uint32_t serial)
39 {
40   wl_shell_surface_pong (shell_surface, serial);
41 }
42
43 static void
44 handle_configure (void *data, struct wl_shell_surface *shell_surface,
45     uint32_t edges, int32_t width, int32_t height)
46 {
47 }
48
49 static void
50 handle_popup_done (void *data, struct wl_shell_surface *shell_surface)
51 {
52 }
53
54 static const struct wl_shell_surface_listener shell_surface_listener = {
55   handle_ping,
56   handle_configure,
57   handle_popup_done
58 };
59
60 static void
61 gst_wl_window_class_init (GstWlWindowClass * klass)
62 {
63   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
64   gobject_class->finalize = gst_wl_window_finalize;
65 }
66
67 static void
68 gst_wl_window_init (GstWlWindow * self)
69 {
70 }
71
72 static void
73 gst_wl_window_finalize (GObject * gobject)
74 {
75   GstWlWindow *self = GST_WL_WINDOW (gobject);
76
77   wl_viewport_destroy (self->viewport);
78
79   if (self->shell_surface) {
80     wl_shell_surface_destroy (self->shell_surface);
81   }
82
83   if (self->own_surface) {
84     wl_surface_destroy (self->surface);
85   }
86
87   g_clear_object (&self->display);
88
89   G_OBJECT_CLASS (gst_wl_window_parent_class)->finalize (gobject);
90 }
91
92 GstWlWindow *
93 gst_wl_window_new_toplevel (GstWlDisplay * display, gint width, gint height)
94 {
95   GstWlWindow *window;
96
97   window = gst_wl_window_new_from_surface (display,
98       wl_compositor_create_surface (display->compositor));
99   window->own_surface = TRUE;
100
101   gst_wl_window_set_size (window, width, height);
102
103   window->shell_surface = wl_shell_get_shell_surface (display->shell,
104       window->surface);
105
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);
110   } else {
111     GST_ERROR ("Unable to get wl_shell_surface");
112
113     g_object_unref (window);
114     return NULL;
115   }
116
117   return window;
118 }
119
120 GstWlWindow *
121 gst_wl_window_new_from_surface (GstWlDisplay * display,
122     struct wl_surface * surface)
123 {
124   GstWlWindow *window;
125   struct wl_region *region;
126
127   g_return_val_if_fail (surface != NULL, NULL);
128
129   window = g_object_new (GST_TYPE_WL_WINDOW, NULL);
130   window->display = g_object_ref (display);
131   window->width = 0;
132   window->height = 0;
133
134   window->surface = surface;
135   window->own_surface = FALSE;
136
137   window->viewport = wl_scaler_get_viewport (display->scaler, window->surface);
138
139   /* do not accept input */
140   region = wl_compositor_create_region (display->compositor);
141   wl_surface_set_input_region (surface, region);
142   wl_region_destroy (region);
143
144   return window;
145 }
146
147 GstWlDisplay *
148 gst_wl_window_get_display (GstWlWindow * window)
149 {
150   g_return_val_if_fail (window != NULL, NULL);
151
152   return g_object_ref (window->display);
153 }
154
155 struct wl_surface *
156 gst_wl_window_get_wl_surface (GstWlWindow * window)
157 {
158   g_return_val_if_fail (window != NULL, NULL);
159
160   return window->surface;
161 }
162
163 gboolean
164 gst_wl_window_is_toplevel (GstWlWindow * window)
165 {
166   g_return_val_if_fail (window != NULL, FALSE);
167
168   return (window->shell_surface != NULL);
169 }
170
171 void
172 gst_wl_window_set_size (GstWlWindow * window, gint w, gint h)
173 {
174   g_return_if_fail (window != NULL);
175
176   window->width = w;
177   window->height = h;
178 }