2 * va_wayland_emgd.c - Wayland/EMGD helpers
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.
30 #include "va_drmcommon.h"
31 #include "va_wayland_emgd.h"
32 #include "va_wayland_private.h"
34 /* XXX: Wayland/EMGD support currently lives in libwayland-emgd.so.* library */
35 #define LIBWAYLAND_EMGD_NAME "libwayland-emgd.so.1"
37 typedef struct va_wayland_emgd_context {
38 struct va_wayland_context base;
42 unsigned int is_created : 1;
43 } VADisplayContextWaylandEMGD;
46 wl_emgd_destroy(struct wl_emgd *emgd)
48 wl_proxy_destroy((struct wl_proxy *)emgd);
52 va_DisplayContextGetDriverName(
53 VADisplayContextP pDisplayContext,
54 char **driver_name_ptr
57 *driver_name_ptr = strdup("emgd");
58 return VA_STATUS_SUCCESS;
62 va_wayland_emgd_destroy(VADisplayContextP pDisplayContext)
64 VADriverContextP const ctx = pDisplayContext->pDriverContext;
65 VADisplayContextWaylandEMGD * const wl_emgd_ctx = pDisplayContext->opaque;
66 struct drm_state * const drm_state = ctx->drm_state;
68 if (wl_emgd_ctx->emgd) {
69 wl_emgd_destroy(wl_emgd_ctx->emgd);
70 wl_emgd_ctx->emgd = NULL;
72 wl_emgd_ctx->is_created = 0;
74 if (wl_emgd_ctx->handle) {
75 dlclose(wl_emgd_ctx->handle);
76 wl_emgd_ctx->handle = NULL;
80 if (drm_state->fd >= 0) {
85 ctx->drm_state = NULL;
90 va_wayland_emgd_create(VADisplayContextP pDisplayContext)
92 VADriverContextP const ctx = pDisplayContext->pDriverContext;
93 VADisplayContextWaylandEMGD *wl_emgd_ctx;
94 struct drm_state *drm_state;
97 wl_emgd_ctx = malloc(sizeof(*wl_emgd_ctx));
100 wl_emgd_ctx->base.destroy = va_wayland_emgd_destroy;
101 wl_emgd_ctx->handle = NULL;
102 wl_emgd_ctx->emgd = NULL;
103 wl_emgd_ctx->emgd_interface = NULL;
104 wl_emgd_ctx->is_created = 0;
105 pDisplayContext->opaque = wl_emgd_ctx;
106 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
108 drm_state = calloc(1, sizeof(struct drm_state));
112 drm_state->auth_type = 0;
113 ctx->drm_state = drm_state;
115 id = wl_display_get_global(ctx->native_dpy, "wl_emgd", 1);
117 wl_display_roundtrip(ctx->native_dpy);
118 id = wl_display_get_global(ctx->native_dpy, "wl_emgd", 1);
123 wl_emgd_ctx->handle = dlopen(LIBWAYLAND_EMGD_NAME, RTLD_LAZY|RTLD_LOCAL);
124 if (!wl_emgd_ctx->handle)
127 wl_emgd_ctx->emgd_interface =
128 dlsym(wl_emgd_ctx->handle, "wl_emgd_interface");
129 if (!wl_emgd_ctx->emgd_interface)
133 wl_display_bind(ctx->native_dpy, id, wl_emgd_ctx->emgd_interface);
134 if (!wl_emgd_ctx->emgd)