2 * gstvaapiwindow_wayland.c - VA/Wayland window abstraction
4 * Copyright (C) 2012 Intel Corporation
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
23 * SECTION:gstvaapiwindow_wayland
24 * @short_description: VA/Wayland window abstraction
29 #include "gstvaapicompat.h"
30 #include "gstvaapiwindow_wayland.h"
31 #include "gstvaapidisplay_wayland.h"
32 #include "gstvaapidisplay_wayland_priv.h"
33 #include "gstvaapiutils.h"
34 #include "gstvaapi_priv.h"
37 #include "gstvaapidebug.h"
39 G_DEFINE_TYPE(GstVaapiWindowWayland,
40 gst_vaapi_window_wayland,
41 GST_VAAPI_TYPE_WINDOW);
43 #define GST_VAAPI_WINDOW_WAYLAND_GET_PRIVATE(obj) \
44 (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
45 GST_VAAPI_TYPE_WINDOW_WAYLAND, \
46 GstVaapiWindowWaylandPrivate))
48 struct _GstVaapiWindowWaylandPrivate {
49 struct wl_shell_surface *shell_surface;
50 struct wl_surface *surface;
51 struct wl_buffer *buffer;
52 guint redraw_pending : 1;
56 gst_vaapi_window_wayland_show(GstVaapiWindow *window)
58 GST_WARNING("unimplemented GstVaapiWindowWayland::show()");
64 gst_vaapi_window_wayland_hide(GstVaapiWindow *window)
66 GST_WARNING("unimplemented GstVaapiWindowWayland::hide()");
72 handle_ping(void *data, struct wl_shell_surface *shell_surface,
75 wl_shell_surface_pong(shell_surface, serial);
79 handle_configure(void *data, struct wl_shell_surface *shell_surface,
80 uint32_t edges, int32_t width, int32_t height)
85 handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
89 static const struct wl_shell_surface_listener shell_surface_listener = {
96 gst_vaapi_window_wayland_create(
97 GstVaapiWindow *window,
102 GstVaapiWindowWaylandPrivate * const priv =
103 GST_VAAPI_WINDOW_WAYLAND(window)->priv;
104 GstVaapiDisplayWaylandPrivate * const priv_display =
105 GST_VAAPI_OBJECT_DISPLAY_WAYLAND(window)->priv;
107 GST_DEBUG("create window, size %ux%u", *width, *height);
109 g_return_val_if_fail(priv_display->compositor != NULL, FALSE);
110 g_return_val_if_fail(priv_display->shell != NULL, FALSE);
112 priv->surface = wl_compositor_create_surface(priv_display->compositor);
116 priv->shell_surface =
117 wl_shell_get_shell_surface(priv_display->shell, priv->surface);
118 if (!priv->shell_surface)
121 wl_shell_surface_add_listener(priv->shell_surface,
122 &shell_surface_listener, priv);
123 wl_shell_surface_set_toplevel(priv->shell_surface);
124 wl_shell_surface_set_fullscreen(
126 WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE,
131 priv->redraw_pending = FALSE;
136 gst_vaapi_window_wayland_destroy(GstVaapiWindow * window)
138 GstVaapiWindowWaylandPrivate * const priv =
139 GST_VAAPI_WINDOW_WAYLAND(window)->priv;
141 if (priv->shell_surface) {
142 wl_shell_surface_destroy(priv->shell_surface);
143 priv->shell_surface = NULL;
147 wl_surface_destroy(priv->surface);
148 priv->surface = NULL;
152 wl_buffer_destroy(priv->buffer);
158 gst_vaapi_window_wayland_resize(
159 GstVaapiWindow * window,
164 GST_DEBUG("resize window, new size %ux%u", width, height);
169 frame_redraw_callback(void *data, struct wl_callback *callback, uint32_t time)
171 GstVaapiWindowWaylandPrivate * const priv = data;
173 priv->redraw_pending = FALSE;
174 wl_buffer_destroy(priv->buffer);
176 wl_callback_destroy(callback);
179 static const struct wl_callback_listener frame_callback_listener = {
180 frame_redraw_callback
184 gst_vaapi_window_wayland_render(
185 GstVaapiWindow *window,
186 GstVaapiSurface *surface,
187 const GstVaapiRectangle *src_rect,
188 const GstVaapiRectangle *dst_rect,
192 GstVaapiWindowWaylandPrivate * const priv =
193 GST_VAAPI_WINDOW_WAYLAND(window)->priv;
194 GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(window);
195 struct wl_display * const wl_display = GST_VAAPI_OBJECT_WL_DISPLAY(window);
196 struct wl_buffer *buffer;
197 struct wl_callback *callback;
198 guint width, height, va_flags;
199 VASurfaceID surface_id;
202 /* XXX: use VPP to support unusual source and destination rectangles */
203 gst_vaapi_surface_get_size(surface, &width, &height);
204 if (src_rect->x != 0 ||
206 src_rect->width != width ||
207 src_rect->height != height) {
208 GST_ERROR("unsupported source rectangle for rendering");
212 if (0 && (dst_rect->width != width || dst_rect->height != height)) {
213 GST_ERROR("unsupported target rectangle for rendering");
217 surface_id = GST_VAAPI_OBJECT_ID(surface);
218 if (surface_id == VA_INVALID_ID)
221 GST_VAAPI_OBJECT_LOCK_DISPLAY(window);
223 /* Wait for the previous frame to complete redraw */
224 if (priv->redraw_pending)
225 wl_display_iterate(wl_display, WL_DISPLAY_READABLE);
227 /* XXX: use VA/VPP for other filters */
228 va_flags = from_GstVaapiSurfaceRenderFlags(flags);
229 status = vaGetSurfaceBufferWl(
230 GST_VAAPI_DISPLAY_VADISPLAY(display),
232 va_flags & (VA_TOP_FIELD|VA_BOTTOM_FIELD),
235 if (status == VA_STATUS_ERROR_FLAG_NOT_SUPPORTED) {
236 /* XXX: de-interlacing flags not supported, try with VPP? */
237 status = vaGetSurfaceBufferWl(
238 GST_VAAPI_DISPLAY_VADISPLAY(display),
244 if (!vaapi_check_status(status, "vaGetSurfaceBufferWl()"))
247 /* XXX: attach to the specified target rectangle */
248 wl_surface_attach(priv->surface, buffer, 0, 0);
249 wl_surface_damage(priv->surface, 0, 0, width, height);
251 wl_display_iterate(wl_display, WL_DISPLAY_WRITABLE);
252 priv->redraw_pending = TRUE;
253 priv->buffer = buffer;
255 callback = wl_surface_frame(priv->surface);
256 wl_callback_add_listener(callback, &frame_callback_listener, priv);
257 GST_VAAPI_OBJECT_UNLOCK_DISPLAY(window);
262 gst_vaapi_window_wayland_finalize(GObject *object)
264 G_OBJECT_CLASS(gst_vaapi_window_wayland_parent_class)->finalize(object);
268 gst_vaapi_window_wayland_constructed(GObject *object)
270 GObjectClass *parent_class;
272 parent_class = G_OBJECT_CLASS(gst_vaapi_window_wayland_parent_class);
273 if (parent_class->constructed)
274 parent_class->constructed(object);
278 gst_vaapi_window_wayland_class_init(GstVaapiWindowWaylandClass * klass)
280 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
281 GstVaapiWindowClass * const window_class = GST_VAAPI_WINDOW_CLASS(klass);
283 g_type_class_add_private(klass, sizeof(GstVaapiWindowWaylandPrivate));
285 object_class->finalize = gst_vaapi_window_wayland_finalize;
286 object_class->constructed = gst_vaapi_window_wayland_constructed;
288 window_class->create = gst_vaapi_window_wayland_create;
289 window_class->destroy = gst_vaapi_window_wayland_destroy;
290 window_class->show = gst_vaapi_window_wayland_show;
291 window_class->hide = gst_vaapi_window_wayland_hide;
292 window_class->render = gst_vaapi_window_wayland_render;
293 window_class->resize = gst_vaapi_window_wayland_resize;
297 gst_vaapi_window_wayland_init(GstVaapiWindowWayland * window)
299 GstVaapiWindowWaylandPrivate *priv =
300 GST_VAAPI_WINDOW_WAYLAND_GET_PRIVATE(window);
303 priv->shell_surface = NULL;
304 priv->surface = NULL;
306 priv->redraw_pending = FALSE;
310 * gst_vaapi_window_wayland_new:
311 * @display: a #GstVaapiDisplay
312 * @width: the requested window width, in pixels
313 * @height: the requested windo height, in pixels
315 * Creates a window with the specified @width and @height. The window
316 * will be attached to the @display and remains invisible to the user
317 * until gst_vaapi_window_show() is called.
319 * Return value: the newly allocated #GstVaapiWindow object
322 gst_vaapi_window_wayland_new(
323 GstVaapiDisplay *display,
328 GST_DEBUG("new window, size %ux%u", width, height);
330 g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
331 g_return_val_if_fail(width > 0, NULL);
332 g_return_val_if_fail(height > 0, NULL);
334 return g_object_new(GST_VAAPI_TYPE_WINDOW_WAYLAND,
336 "id", GST_VAAPI_ID(0),