| 1 |
/* |
| 2 |
* va_wayland.c - Wayland API |
| 3 |
* |
| 4 |
* Copyright (c) 2012 Intel Corporation. All Rights Reserved. |
| 5 |
* |
| 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: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice (including the |
| 15 |
* next paragraph) shall be included in all copies or substantial portions |
| 16 |
* of the Software. |
| 17 |
* |
| 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. |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "sysdeps.h" |
| 28 |
#include <stdarg.h> |
| 29 |
#include "va_wayland.h" |
| 30 |
#include "va_wayland_linux_dmabuf.h" |
| 31 |
#include "va_wayland_drm.h" |
| 32 |
#include "va_wayland_emgd.h" |
| 33 |
#include "va_wayland_private.h" |
| 34 |
#include "va_backend.h" |
| 35 |
#include "va_backend_wayland.h" |
| 36 |
#include "va_internal.h" |
| 37 |
|
| 38 |
static inline VADriverContextP |
| 39 |
get_driver_context(VADisplay dpy) |
| 40 |
{ |
| 41 |
if (!vaDisplayIsValid(dpy)) |
| 42 |
return NULL; |
| 43 |
return ((VADisplayContextP)dpy)->pDriverContext; |
| 44 |
} |
| 45 |
|
| 46 |
void |
| 47 |
va_wayland_error(const char *format, ...) |
| 48 |
{ |
| 49 |
va_list args; |
| 50 |
|
| 51 |
va_start(args, format); |
| 52 |
fprintf(stderr, "VA error: wayland: "); |
| 53 |
vfprintf(stderr, format, args); |
| 54 |
fprintf(stderr, "\n"); |
| 55 |
va_end(args); |
| 56 |
} |
| 57 |
|
| 58 |
static void |
| 59 |
va_DisplayContextDestroy(VADisplayContextP pDisplayContext) |
| 60 |
{ |
| 61 |
VADriverContextP pDriverContext; |
| 62 |
VADisplayContextWaylandP pDisplayContextWl; |
| 63 |
|
| 64 |
if (!pDisplayContext) |
| 65 |
return; |
| 66 |
|
| 67 |
pDisplayContextWl = pDisplayContext->opaque; |
| 68 |
if (pDisplayContextWl && pDisplayContextWl->destroy) |
| 69 |
pDisplayContextWl->destroy(pDisplayContext); |
| 70 |
|
| 71 |
pDriverContext = pDisplayContext->pDriverContext; |
| 72 |
if (pDriverContext) { |
| 73 |
free(pDriverContext->vtable_wayland); |
| 74 |
pDriverContext->vtable_wayland = NULL; |
| 75 |
free(pDriverContext); |
| 76 |
pDisplayContext->pDriverContext = NULL; |
| 77 |
} |
| 78 |
|
| 79 |
free(pDisplayContext->opaque); |
| 80 |
pDisplayContext->opaque = NULL; |
| 81 |
free(pDisplayContext); |
| 82 |
} |
| 83 |
|
| 84 |
/* -------------------------------------------------------------------------- */ |
| 85 |
/* --- Public interface --- */ |
| 86 |
/* -------------------------------------------------------------------------- */ |
| 87 |
|
| 88 |
struct va_wayland_backend { |
| 89 |
VADisplayContextCreateFunc create; |
| 90 |
VADisplayContextDestroyFunc destroy; |
| 91 |
}; |
| 92 |
|
| 93 |
static const struct va_wayland_backend g_backends[] = { |
| 94 |
{ |
| 95 |
va_wayland_linux_dmabuf_create, |
| 96 |
va_wayland_linux_dmabuf_destroy |
| 97 |
}, |
| 98 |
{ |
| 99 |
va_wayland_drm_create, |
| 100 |
va_wayland_drm_destroy |
| 101 |
}, |
| 102 |
#ifdef HAVE_EMGD |
| 103 |
{ |
| 104 |
va_wayland_emgd_create, |
| 105 |
va_wayland_emgd_destroy |
| 106 |
}, |
| 107 |
#endif |
| 108 |
{ NULL, } |
| 109 |
}; |
| 110 |
|
| 111 |
VADisplay |
| 112 |
vaGetDisplayWl(struct wl_display *display) |
| 113 |
{ |
| 114 |
VADisplayContextP pDisplayContext = NULL; |
| 115 |
VADriverContextP pDriverContext; |
| 116 |
struct VADriverVTableWayland *vtable; |
| 117 |
unsigned int i; |
| 118 |
|
| 119 |
pDisplayContext = va_newDisplayContext(); |
| 120 |
if (!pDisplayContext) |
| 121 |
return NULL; |
| 122 |
|
| 123 |
pDisplayContext->vaDestroy = va_DisplayContextDestroy; |
| 124 |
|
| 125 |
pDriverContext = va_newDriverContext(pDisplayContext); |
| 126 |
if (!pDriverContext) |
| 127 |
goto error; |
| 128 |
|
| 129 |
pDriverContext->native_dpy = display; |
| 130 |
pDriverContext->display_type = VA_DISPLAY_WAYLAND; |
| 131 |
|
| 132 |
vtable = calloc(1, sizeof(*vtable)); |
| 133 |
if (!vtable) |
| 134 |
goto error; |
| 135 |
pDriverContext->vtable_wayland = vtable; |
| 136 |
|
| 137 |
vtable->version = VA_WAYLAND_API_VERSION; |
| 138 |
|
| 139 |
for (i = 0; g_backends[i].create != NULL; i++) { |
| 140 |
if (g_backends[i].create(pDisplayContext)) |
| 141 |
return (VADisplay)pDisplayContext; |
| 142 |
g_backends[i].destroy(pDisplayContext); |
| 143 |
} |
| 144 |
|
| 145 |
error: |
| 146 |
va_DisplayContextDestroy(pDisplayContext); |
| 147 |
return NULL; |
| 148 |
} |
| 149 |
|
| 150 |
VAStatus |
| 151 |
vaGetSurfaceBufferWl( |
| 152 |
VADisplay dpy, |
| 153 |
VASurfaceID surface, |
| 154 |
unsigned int flags, |
| 155 |
struct wl_buffer **out_buffer |
| 156 |
) |
| 157 |
{ |
| 158 |
VADriverContextP const ctx = get_driver_context(dpy); |
| 159 |
|
| 160 |
if (!ctx) |
| 161 |
return VA_STATUS_ERROR_INVALID_DISPLAY; |
| 162 |
if (!ctx->vtable_wayland || !ctx->vtable_wayland->vaGetSurfaceBufferWl) |
| 163 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 164 |
return ctx->vtable_wayland->vaGetSurfaceBufferWl(ctx, surface, flags, |
| 165 |
out_buffer); |
| 166 |
} |
| 167 |
|
| 168 |
VAStatus |
| 169 |
vaGetImageBufferWl( |
| 170 |
VADisplay dpy, |
| 171 |
VAImageID image, |
| 172 |
unsigned int flags, |
| 173 |
struct wl_buffer **out_buffer |
| 174 |
) |
| 175 |
{ |
| 176 |
VADriverContextP const ctx = get_driver_context(dpy); |
| 177 |
|
| 178 |
if (!ctx) |
| 179 |
return VA_STATUS_ERROR_INVALID_DISPLAY; |
| 180 |
if (!ctx->vtable_wayland || !ctx->vtable_wayland->vaGetImageBufferWl) |
| 181 |
return VA_STATUS_ERROR_UNIMPLEMENTED; |
| 182 |
return ctx->vtable_wayland->vaGetImageBufferWl(ctx, image, flags, |
| 183 |
out_buffer); |
| 184 |
} |