From 2b7a8a4ef38096dd24f05b845295cfa846852d1c Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Fri, 13 Jul 2012 07:27:11 +0200 Subject: [PATCH] wayland: add initial support for EMGD driver. --- va/wayland/Makefile.am | 2 + va/wayland/va_wayland.c | 2 + va/wayland/va_wayland_emgd.c | 154 ++++++++++++++++++++++++++++++++++++++++ va/wayland/va_wayland_emgd.h | 47 ++++++++++++ va/wayland/va_wayland_private.h | 10 +++ 5 files changed, 215 insertions(+) create mode 100644 va/wayland/va_wayland_emgd.c create mode 100644 va/wayland/va_wayland_emgd.h diff --git a/va/wayland/Makefile.am b/va/wayland/Makefile.am index 9e97e2a..0ea22a9 100644 --- a/va/wayland/Makefile.am +++ b/va/wayland/Makefile.am @@ -33,6 +33,7 @@ INCLUDES = \ source_c = \ va_wayland.c \ va_wayland_drm.c \ + va_wayland_emgd.c \ $(top_srcdir)/va/drm/va_drm_utils.c \ $(NULL) @@ -43,6 +44,7 @@ source_h = \ source_h_priv = \ va_wayland_drm.h \ + va_wayland_emgd.h \ va_wayland_private.h \ $(NULL) diff --git a/va/wayland/va_wayland.c b/va/wayland/va_wayland.c index af509bb..b8688e2 100644 --- a/va/wayland/va_wayland.c +++ b/va/wayland/va_wayland.c @@ -28,6 +28,7 @@ #include #include "va_wayland.h" #include "va_wayland_drm.h" +#include "va_wayland_emgd.h" #include "va_wayland_private.h" #include "va_backend.h" #include "va_backend_wayland.h" @@ -98,6 +99,7 @@ va_DisplayContextGetDriverName(VADisplayContextP pDisplayContext, char **name) static const VADisplayContextInitFunc g_display_context_init_funcs[] = { va_wayland_drm_init, + va_wayland_emgd_init, NULL }; diff --git a/va/wayland/va_wayland_emgd.c b/va/wayland/va_wayland_emgd.c new file mode 100644 index 0000000..d79f755 --- /dev/null +++ b/va/wayland/va_wayland_emgd.c @@ -0,0 +1,154 @@ +/* + * va_wayland_emgd.c - Wayland/EMGD helpers + * + * Copyright (c) 2012 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include "va_drmcommon.h" +#include "va_wayland_emgd.h" +#include "va_wayland_private.h" + +/* XXX: wayland-emgd currently lives in libEMGD.so.* library */ +#define LIBEGL_NAME "libwayland-emgd.so.1" + +/* XXX: not implemented */ +#define BIND_EMGD_INTERFACE 0 + +#if BIND_EMGD_INTERFACE +static void +emgd_handle_created(void *data, struct wl_emgd *emgd, const char *device) +{ + VADisplayContextP const pDisplayContext = data; + VADisplayContextWaylandP const wl_ctx = pDisplayContext->opaque; + VADisplayContextWaylandEMGD * const wl_emgd_ctx = &wl_ctx->backend.emgd; + + wl_emgd_ctx->is_created = 1; +} + +static void +emgd_handle_format(void *data, struct wl_emgd *emgd, uint32_t format) +{ +} + +static const struct wl_emgd_listener emgd_listener = { + emgd_handle_device, + emgd_handle_format, + emgd_handle_authenticated +}; +#endif + +static VAStatus +va_DisplayContextGetDriverName( + VADisplayContextP pDisplayContext, + char **driver_name_ptr +) +{ + *driver_name_ptr = strdup("emgd"); + return VA_STATUS_SUCCESS; +} + +static void +va_wayland_emgd_finalize(VADisplayContextP pDisplayContext) +{ + VADriverContextP const ctx = pDisplayContext->pDriverContext; + VADisplayContextWaylandP const wl_ctx = pDisplayContext->opaque; + VADisplayContextWaylandEMGD * const wl_emgd_ctx = &wl_ctx->backend.emgd; + struct drm_state * const drm_state = ctx->drm_state; + + if (wl_emgd_ctx->emgd) { + //wl_emgd_destroy(wl_emgd_ctx->emgd); + wl_emgd_ctx->emgd = NULL; + } + wl_emgd_ctx->is_created = 0; + + if (wl_emgd_ctx->libEGL_handle) { + dlclose(wl_emgd_ctx->libEGL_handle); + wl_emgd_ctx->libEGL_handle = NULL; + } + + if (drm_state) { + if (drm_state->fd >= 0) { + close(drm_state->fd); + drm_state->fd = -1; + } + free(ctx->drm_state); + ctx->drm_state = NULL; + } +} + +bool +va_wayland_emgd_init(VADisplayContextP pDisplayContext) +{ + VADriverContextP const ctx = pDisplayContext->pDriverContext; + VADisplayContextWaylandP const wl_ctx = pDisplayContext->opaque; + VADisplayContextWaylandEMGD * const wl_emgd_ctx = &wl_ctx->backend.emgd; + struct drm_state *drm_state; + uint32_t id; + + wl_emgd_ctx->libEGL_handle = NULL; + wl_emgd_ctx->emgd = NULL; + wl_emgd_ctx->is_created = 0; + wl_ctx->finalize = va_wayland_emgd_finalize; + pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName; + + drm_state = calloc(1, sizeof(struct drm_state)); + if (!drm_state) + return false; + drm_state->fd = -1; + drm_state->auth_type = 0; + ctx->drm_state = drm_state; + + id = wl_display_get_global(ctx->native_dpy, "wl_emgd", 1); + if (!id) { + wl_display_roundtrip(ctx->native_dpy); + id = wl_display_get_global(ctx->native_dpy, "wl_emgd", 1); + if (!id) + return false; + } + + wl_emgd_ctx->libEGL_handle = dlopen(LIBEGL_NAME, RTLD_LAZY|RTLD_LOCAL); + if (!wl_emgd_ctx->libEGL_handle) + return false; + + wl_emgd_ctx->emgd_interface = + dlsym(wl_emgd_ctx->libEGL_handle, "wl_emgd_interface"); + if (!wl_emgd_ctx->emgd_interface) + return false; + + wl_emgd_ctx->emgd = + wl_display_bind(ctx->native_dpy, id, wl_emgd_ctx->emgd_interface); + if (!wl_emgd_ctx->emgd) + return false; + +#if BIND_EMGD_INTERFACE + wl_emgd_add_listener(wl_emgd_ctx->emgd, &emgd_listener, pDisplayContext); + wl_display_roundtrip(ctx->native_dpy); + if (!wl_emgd_ctx->is_created) + return false; +#endif + return true; +} diff --git a/va/wayland/va_wayland_emgd.h b/va/wayland/va_wayland_emgd.h new file mode 100644 index 0000000..b39c105 --- /dev/null +++ b/va/wayland/va_wayland_emgd.h @@ -0,0 +1,47 @@ +/* + * va_wayland_emgd.h - Wayland/EMGD helpers + * + * Copyright (c) 2012 Intel Corporation. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef VA_WAYLAND_EMGD_H +#define VA_WAYLAND_EMGD_H + +#include +#include "va_wayland.h" +#include "va_backend.h" +#include "va_backend_wayland.h" + +/** + * \brief Initializes Wayland/EMGD layer. + * + * This is an internal function used to initialize the VA/EMGD subsystem + * if the application is running on an EMGD-based server. + * + * @param[in] pDisplayContext the VA display context + * @return true if successful + */ +bool +va_wayland_emgd_init(VADisplayContextP pDisplayContext); + +#endif /* VA_WAYLAND_EMGD_H */ diff --git a/va/wayland/va_wayland_private.h b/va/wayland/va_wayland_private.h index c55a7b4..06ef95c 100644 --- a/va/wayland/va_wayland_private.h +++ b/va/wayland/va_wayland_private.h @@ -26,6 +26,7 @@ #ifndef VA_WAYLAND_PRIVATE_H #define VA_WAYLAND_PRIVATE_H +#include "sysdeps.h" typedef bool (*VADisplayContextInitFunc)(VADisplayContextP pDisplayContext); typedef void (*VADisplayContextFinalizeFunc)(VADisplayContextP pDisplayContext); @@ -38,9 +39,18 @@ typedef struct _VADisplayContextWaylandDRM { unsigned int is_authenticated : 1; } VADisplayContextWaylandDRM; +typedef struct _VADisplayContextWaylandEMGD { + /* XXX: wayland-emgd lives in libEMGDegl.so.* for now */ + void *libEGL_handle; + struct wl_emgd *emgd; + void *emgd_interface; + unsigned int is_created : 1; +} VADisplayContextWaylandEMGD; + typedef struct _VADisplayContextWayland { union { VADisplayContextWaylandDRM drm; + VADisplayContextWaylandEMGD emgd; } backend; VADisplayContextFinalizeFunc finalize; } VADisplayContextWayland, *VADisplayContextWaylandP; -- 2.7.4