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 struct wl_registry *registry;
44 } VADisplayContextWaylandEMGD;
47 wl_emgd_destroy(struct wl_emgd *emgd)
49 wl_proxy_destroy((struct wl_proxy *)emgd);
53 va_DisplayContextGetDriverName(
54 VADisplayContextP pDisplayContext,
55 char **driver_name_ptr
58 *driver_name_ptr = strdup("emgd");
59 return VA_STATUS_SUCCESS;
63 va_wayland_emgd_destroy(VADisplayContextP pDisplayContext)
65 VADriverContextP const ctx = pDisplayContext->pDriverContext;
66 VADisplayContextWaylandEMGD * const wl_emgd_ctx = pDisplayContext->opaque;
67 struct drm_state * const drm_state = ctx->drm_state;
69 if (wl_emgd_ctx->emgd) {
70 wl_emgd_destroy(wl_emgd_ctx->emgd);
71 wl_emgd_ctx->emgd = NULL;
73 wl_emgd_ctx->is_created = 0;
75 if (wl_emgd_ctx->handle) {
76 dlclose(wl_emgd_ctx->handle);
77 wl_emgd_ctx->handle = NULL;
81 if (drm_state->fd >= 0) {
86 ctx->drm_state = NULL;
91 registry_handle_global(
93 struct wl_registry *registry,
95 const char *interface,
99 VADisplayContextWaylandEMGD *wl_emgd_ctx = data;
101 if (strcmp(interface, "wl_emgd") == 0) {
103 wl_registry_bind(registry, id, wl_emgd_ctx->emgd_interface, 1);
107 static const struct wl_registry_listener registry_listener = {
108 registry_handle_global,
113 va_wayland_emgd_create(VADisplayContextP pDisplayContext)
115 VADriverContextP const ctx = pDisplayContext->pDriverContext;
116 VADisplayContextWaylandEMGD *wl_emgd_ctx;
117 struct drm_state *drm_state;
120 wl_emgd_ctx = malloc(sizeof(*wl_emgd_ctx));
123 wl_emgd_ctx->base.destroy = va_wayland_emgd_destroy;
124 wl_emgd_ctx->handle = NULL;
125 wl_emgd_ctx->emgd = NULL;
126 wl_emgd_ctx->emgd_interface = NULL;
127 wl_emgd_ctx->is_created = 0;
128 pDisplayContext->opaque = wl_emgd_ctx;
129 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
131 drm_state = calloc(1, sizeof(struct drm_state));
135 drm_state->auth_type = 0;
136 ctx->drm_state = drm_state;
138 wl_emgd_ctx->handle = dlopen(LIBWAYLAND_EMGD_NAME, RTLD_LAZY|RTLD_LOCAL);
139 if (!wl_emgd_ctx->handle)
142 wl_emgd_ctx->emgd_interface =
143 dlsym(wl_emgd_ctx->handle, "wl_emgd_interface");
144 if (!wl_emgd_ctx->emgd_interface)
147 wl_emgd_ctx->registry = wl_display_get_registry(ctx->native_dpy);
148 wl_registry_add_listener(wl_emgd_ctx->registry, ®istry_listener, wl_emgd_ctx);
149 wl_display_roundtrip(ctx->native_dpy);
151 /* registry_handle_global should have been called by the
152 * wl_display_roundtrip above
154 if (!wl_emgd_ctx->emgd)