2 * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 # include "va/wayland/va_wayland.h"
30 # include <va/va_wayland.h>
32 #include "va_display.h"
35 struct wl_display *display;
36 struct wl_registry *registry;
37 struct wl_compositor *compositor;
38 struct wl_shell *shell;
39 struct wl_shell_surface *shell_surface;
40 struct wl_surface *surface;
41 unsigned int ref_count;
45 static struct display *g_display;
48 registry_handle_global(
50 struct wl_registry *registry,
52 const char *interface,
56 struct display * const d = data;
58 if (strcmp(interface, "wl_compositor") == 0)
60 wl_registry_bind(registry, id, &wl_compositor_interface, 1);
61 else if (strcmp(interface, "wl_shell") == 0)
62 d->shell = wl_registry_bind(registry, id, &wl_shell_interface, 1);
65 static const struct wl_registry_listener registry_listener = {
66 registry_handle_global,
71 va_open_display_wayland(void)
80 d = calloc(1, sizeof(*d));
85 d->display = wl_display_connect(NULL);
90 wl_display_set_user_data(d->display, d);
91 d->registry = wl_display_get_registry(d->display);
92 wl_registry_add_listener(d->registry, ®istry_listener, d);
93 d->event_fd = wl_display_get_fd(d->display);
94 wl_display_dispatch(d->display);
99 return vaGetDisplayWl(d->display);
103 va_close_display_wayland(VADisplay va_dpy)
105 struct display * const d = g_display;
107 if (!d || --d->ref_count > 0)
111 wl_surface_destroy(d->surface);
115 if (d->shell_surface) {
116 wl_shell_surface_destroy(d->shell_surface);
117 d->shell_surface = NULL;
121 wl_shell_destroy(d->shell);
126 wl_compositor_destroy(d->compositor);
127 d->compositor = NULL;
131 wl_display_disconnect(d->display);
139 ensure_window(VADisplay va_dpy, unsigned int width, unsigned int height)
141 struct display * const d = g_display;
144 d->surface = wl_compositor_create_surface(d->compositor);
149 if (!d->shell_surface) {
150 d->shell_surface = wl_shell_get_shell_surface(d->shell, d->surface);
151 if (!d->shell_surface)
153 wl_shell_surface_set_toplevel(d->shell_surface);
159 va_put_surface_wayland(
162 const VARectangle *src_rect,
163 const VARectangle *dst_rect
166 struct display * const d = g_display;
168 struct wl_buffer *buffer;
170 if (!ensure_window(va_dpy, dst_rect->width, dst_rect->height))
171 return VA_STATUS_ERROR_ALLOCATION_FAILED;
173 va_status = vaGetSurfaceBufferWl(va_dpy, surface, VA_FRAME_PICTURE, &buffer);
174 if (va_status != VA_STATUS_SUCCESS)
177 wl_surface_attach(d->surface, buffer, 0, 0);
180 dst_rect->x, dst_rect->y, dst_rect->width, dst_rect->height
183 wl_surface_commit(d->surface);
184 wl_display_flush(d->display);
185 return VA_STATUS_SUCCESS;
188 const VADisplayHooks va_display_hooks_wayland = {
190 va_open_display_wayland,
191 va_close_display_wayland,
192 va_put_surface_wayland,