2 * va_wayland.c - Wayland API
4 * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include "va_wayland.h"
30 #include "va_wayland_drm.h"
31 #include "va_wayland_emgd.h"
32 #include "va_wayland_private.h"
33 #include "va_backend.h"
34 #include "va_backend_wayland.h"
36 static inline VADriverContextP
37 get_driver_context(VADisplay dpy)
39 if (!vaDisplayIsValid(dpy))
41 return ((VADisplayContextP)dpy)->pDriverContext;
45 va_wayland_error(const char *format, ...)
49 va_start(args, format);
50 fprintf(stderr, "VA error: wayland: ");
51 vfprintf(stderr, format, args);
52 fprintf(stderr, "\n");
57 va_DisplayContextIsValid(VADisplayContextP pDisplayContext)
59 VADriverContextP const pDriverContext = pDisplayContext->pDriverContext;
61 return (pDriverContext &&
62 pDriverContext->display_type == VA_DISPLAY_WAYLAND);
66 va_DisplayContextDestroy(VADisplayContextP pDisplayContext)
68 VADriverContextP pDriverContext;
69 VADisplayContextWaylandP pDisplayContextWl;
74 pDisplayContextWl = pDisplayContext->opaque;
75 if (pDisplayContextWl && pDisplayContextWl->destroy)
76 pDisplayContextWl->destroy(pDisplayContext);
78 pDriverContext = pDisplayContext->pDriverContext;
80 free(pDriverContext->vtable_wayland);
81 pDriverContext->vtable_wayland = NULL;
83 pDisplayContext->pDriverContext = NULL;
86 free(pDisplayContext->opaque);
87 pDisplayContext->opaque = NULL;
88 free(pDisplayContext);
92 va_DisplayContextGetDriverName(VADisplayContextP pDisplayContext, char **name)
95 return VA_STATUS_ERROR_UNKNOWN;
98 /* -------------------------------------------------------------------------- */
99 /* --- Public interface --- */
100 /* -------------------------------------------------------------------------- */
102 struct va_wayland_backend {
103 VADisplayContextCreateFunc create;
104 VADisplayContextDestroyFunc destroy;
107 static const struct va_wayland_backend g_backends[] = {
108 { va_wayland_drm_create,
109 va_wayland_drm_destroy },
110 { va_wayland_emgd_create,
111 va_wayland_emgd_destroy },
116 vaGetDisplayWl(struct wl_display *display)
118 VADisplayContextP pDisplayContext = NULL;
119 VADriverContextP pDriverContext;
120 struct VADriverVTableWayland *vtable;
123 pDisplayContext = calloc(1, sizeof(*pDisplayContext));
124 if (!pDisplayContext)
127 pDisplayContext->vadpy_magic = VA_DISPLAY_MAGIC;
128 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
129 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
130 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
132 pDriverContext = calloc(1, sizeof(*pDriverContext));
135 pDisplayContext->pDriverContext = pDriverContext;
137 pDriverContext->native_dpy = display;
138 pDriverContext->display_type = VA_DISPLAY_WAYLAND;
140 vtable = calloc(1, sizeof(*vtable));
143 pDriverContext->vtable_wayland = vtable;
145 vtable->version = VA_WAYLAND_API_VERSION;
147 for (i = 0; g_backends[i].create != NULL; i++) {
148 if (g_backends[i].create(pDisplayContext))
150 g_backends[i].destroy(pDisplayContext);
153 return (VADisplay)pDisplayContext;
156 va_DisplayContextDestroy(pDisplayContext);
161 vaGetSurfaceBufferWl(
165 struct wl_buffer **out_buffer
168 VADriverContextP const ctx = get_driver_context(dpy);
171 return VA_STATUS_ERROR_INVALID_DISPLAY;
172 if (!ctx->vtable_wayland || !ctx->vtable_wayland->vaGetSurfaceBufferWl)
173 return VA_STATUS_ERROR_UNIMPLEMENTED;
174 return ctx->vtable_wayland->vaGetSurfaceBufferWl(ctx, surface, flags,
183 struct wl_buffer **out_buffer
186 VADriverContextP const ctx = get_driver_context(dpy);
189 return VA_STATUS_ERROR_INVALID_DISPLAY;
190 if (!ctx->vtable_wayland || !ctx->vtable_wayland->vaGetImageBufferWl)
191 return VA_STATUS_ERROR_UNIMPLEMENTED;
192 return ctx->vtable_wayland->vaGetImageBufferWl(ctx, image, flags,