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"
35 #include "va_internal.h"
37 static inline VADriverContextP
38 get_driver_context(VADisplay dpy)
40 if (!vaDisplayIsValid(dpy))
42 return ((VADisplayContextP)dpy)->pDriverContext;
46 va_wayland_error(const char *format, ...)
50 va_start(args, format);
51 fprintf(stderr, "VA error: wayland: ");
52 vfprintf(stderr, format, args);
53 fprintf(stderr, "\n");
58 va_DisplayContextIsValid(VADisplayContextP pDisplayContext)
60 VADriverContextP const pDriverContext = pDisplayContext->pDriverContext;
62 return (pDriverContext &&
63 pDriverContext->display_type == VA_DISPLAY_WAYLAND);
67 va_DisplayContextDestroy(VADisplayContextP pDisplayContext)
69 VADriverContextP pDriverContext;
70 VADisplayContextWaylandP pDisplayContextWl;
75 pDisplayContextWl = pDisplayContext->opaque;
76 if (pDisplayContextWl && pDisplayContextWl->destroy)
77 pDisplayContextWl->destroy(pDisplayContext);
79 pDriverContext = pDisplayContext->pDriverContext;
81 free(pDriverContext->vtable_wayland);
82 pDriverContext->vtable_wayland = NULL;
84 pDisplayContext->pDriverContext = NULL;
87 free(pDisplayContext->opaque);
88 pDisplayContext->opaque = NULL;
89 free(pDisplayContext);
93 va_DisplayContextGetDriverName(VADisplayContextP pDisplayContext, char **name)
96 return VA_STATUS_ERROR_UNKNOWN;
99 /* -------------------------------------------------------------------------- */
100 /* --- Public interface --- */
101 /* -------------------------------------------------------------------------- */
103 struct va_wayland_backend {
104 VADisplayContextCreateFunc create;
105 VADisplayContextDestroyFunc destroy;
108 static const struct va_wayland_backend g_backends[] = {
109 { va_wayland_drm_create,
110 va_wayland_drm_destroy },
111 { va_wayland_emgd_create,
112 va_wayland_emgd_destroy },
117 vaGetDisplayWl(struct wl_display *display)
119 VADisplayContextP pDisplayContext = NULL;
120 VADriverContextP pDriverContext;
121 struct VADriverVTableWayland *vtable;
124 pDisplayContext = va_newDisplayContext();
125 if (!pDisplayContext)
128 pDisplayContext->vaIsValid = va_DisplayContextIsValid;
129 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
130 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
132 pDriverContext = va_newDriverContext(pDisplayContext);
136 pDriverContext->native_dpy = display;
137 pDriverContext->display_type = VA_DISPLAY_WAYLAND;
139 vtable = calloc(1, sizeof(*vtable));
142 pDriverContext->vtable_wayland = vtable;
144 vtable->version = VA_WAYLAND_API_VERSION;
146 for (i = 0; g_backends[i].create != NULL; i++) {
147 if (g_backends[i].create(pDisplayContext))
149 g_backends[i].destroy(pDisplayContext);
152 return (VADisplay)pDisplayContext;
155 va_DisplayContextDestroy(pDisplayContext);
160 vaGetSurfaceBufferWl(
164 struct wl_buffer **out_buffer
167 VADriverContextP const ctx = get_driver_context(dpy);
170 return VA_STATUS_ERROR_INVALID_DISPLAY;
171 if (!ctx->vtable_wayland || !ctx->vtable_wayland->vaGetSurfaceBufferWl)
172 return VA_STATUS_ERROR_UNIMPLEMENTED;
173 return ctx->vtable_wayland->vaGetSurfaceBufferWl(ctx, surface, flags,
182 struct wl_buffer **out_buffer
185 VADriverContextP const ctx = get_driver_context(dpy);
188 return VA_STATUS_ERROR_INVALID_DISPLAY;
189 if (!ctx->vtable_wayland || !ctx->vtable_wayland->vaGetImageBufferWl)
190 return VA_STATUS_ERROR_UNIMPLEMENTED;
191 return ctx->vtable_wayland->vaGetImageBufferWl(ctx, image, flags,