[Libva] [PATCH] fix build issue when there is wayland platform support only

Zhao Halley halley.zhao at intel.com
Sat Apr 27 00:18:12 PDT 2013


---
 test/Makefile.am                         |    3 +
 test/putsurface/Makefile.am              |    5 +-
 va/wayland/va_wayland_pvr.c              |  202 ++++++++++++++++++++++++++++++
 va/wayland/va_wayland_pvr.h              |   52 ++++++++
 va/wayland/wayland-pvr-client-protocol.h |   68 ++++++++++
 5 files changed, 329 insertions(+), 1 deletion(-)
 create mode 100755 va/wayland/va_wayland_pvr.c
 create mode 100755 va/wayland/va_wayland_pvr.h
 create mode 100755 va/wayland/wayland-pvr-client-protocol.h

diff --git a/test/Makefile.am b/test/Makefile.am
index 451b90f..c75e006 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -25,5 +25,8 @@ SUBDIRS = common decode encode vainfo
 if USE_X11
 SUBDIRS += basic putsurface v4l_h264
 endif
+if USE_WAYLAND
+SUBDIRS += putsurface
+endif
 
 EXTRA_DIST = loadsurface.h loadsurface_yuv.h
diff --git a/test/putsurface/Makefile.am b/test/putsurface/Makefile.am
index 8ffe255..e6dbe57 100644
--- a/test/putsurface/Makefile.am
+++ b/test/putsurface/Makefile.am
@@ -20,7 +20,6 @@
 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-bin_PROGRAMS = putsurface
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)		\
@@ -36,11 +35,15 @@ TEST_LIBS = \
 	-lpthread		\
 	$(NULL)
 
+bin_PROGRAMS =
+if USE_X11
+bin_PROGRAMS += putsurface
 putsurface_SOURCES		= putsurface_x11.c
 putsurface_CFLAGS		= $(X11_CFLAGS) $(TEST_CFLAGS)
 putsurface_LDADD		= $(X11_LIBS) $(TEST_LIBS)	\
 	$(top_builddir)/va/libva-x11.la			\
 	$(NULL)
+endif
 
 if USE_WAYLAND
 bin_PROGRAMS			+= putsurface_wayland
diff --git a/va/wayland/va_wayland_pvr.c b/va/wayland/va_wayland_pvr.c
new file mode 100755
index 0000000..8f9b8fd
--- /dev/null
+++ b/va/wayland/va_wayland_pvr.c
@@ -0,0 +1,202 @@
+/*
+ * va_wayland_pvr.c - Wayland/PVR 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 "sysdeps.h"
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <dlfcn.h>
+#include <sys/stat.h>
+#include <xf86drm.h>
+#include "va_drmcommon.h"
+#include "drm/va_drm_utils.h"
+#include "va_wayland_pvr.h"
+#include "va_wayland_private.h"
+#include "wayland-pvr-client-protocol.h"
+
+/* XXX: Wayland/PVR support currently lives in libEGL.so.* library */
+#define LIBWAYLAND_PVR_NAME "libEGL.so.1"
+
+typedef struct va_wayland_pvr_context {
+    struct va_wayland_context   base;
+    void                       *handle;
+    struct wl_pvr              *pvr;
+    struct wl_registry         *registry;
+    void                       *pvr_interface;
+    unsigned int                is_authenticated        : 1;
+} VADisplayContextWaylandPVR;
+
+static int open_device (char *dev_name)
+{
+    struct stat st;
+    int fd;
+
+    if (-1 == stat (dev_name, &st))
+    {
+        printf ("Cannot identify '%s': %d, %s\n",
+                dev_name, errno, strerror (errno));
+        return -1;
+    }
+
+    if (!S_ISCHR (st.st_mode))
+    {
+        printf ("%s is no device\n", dev_name);
+        return -1;
+    }
+
+    fd = open (dev_name, O_RDWR);
+
+    if (-1 == fd)
+    {
+        fprintf (stderr, "Cannot open '%s': %d, %s\n",
+                 dev_name, errno, strerror (errno));
+        return -1;
+    }
+
+    return fd;
+}
+
+
+#define DEVICE_NAME "/dev/dri/card0"
+
+static VAStatus
+va_DisplayContextGetDriverName(
+    VADisplayContextP pDisplayContext,
+    char            **driver_name_ptr
+)
+{
+    VADriverContextP const ctx = pDisplayContext->pDriverContext;
+    struct drm_state * drm_state = (struct drm_state *)ctx->drm_state;
+
+    memset(drm_state, 0, sizeof(*drm_state));
+    drm_state->fd = open_device((char *)DEVICE_NAME);
+
+    if (drm_state->fd < 0) {
+        fprintf(stderr,"can't open DRM devices\n");
+        return VA_STATUS_ERROR_UNKNOWN;
+    }
+    drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
+
+    return VA_DRM_GetDriverName(ctx, driver_name_ptr);
+}
+
+void
+va_wayland_pvr_destroy(VADisplayContextP pDisplayContext)
+{
+    VADriverContextP const ctx = pDisplayContext->pDriverContext;
+    struct va_wayland_pvr_context * const wl_pvr_ctx = pDisplayContext->opaque;
+    struct drm_state * const drm_state = ctx->drm_state;
+
+    if (wl_pvr_ctx->pvr) {
+        wl_pvr_destroy(wl_pvr_ctx->pvr);
+        wl_pvr_ctx->pvr = NULL;
+    }
+    wl_pvr_ctx->is_authenticated = 0;
+
+    if (wl_pvr_ctx->handle) {
+        dlclose(wl_pvr_ctx->handle);
+        wl_pvr_ctx->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;
+    }
+}
+
+static void
+registry_handle_global(
+    void               *data,
+    struct wl_registry *registry,
+    uint32_t            id,
+    const char         *interface,
+    uint32_t            version
+)
+{
+    struct va_wayland_pvr_context *wl_pvr_ctx = data;
+
+    if (strcmp(interface, "wl_pvr") == 0) {
+        wl_pvr_ctx->pvr =
+            wl_registry_bind(wl_pvr_ctx->registry, id, wl_pvr_ctx->pvr_interface, 1);
+    }
+}
+
+static const struct wl_registry_listener registry_listener = {
+    registry_handle_global,
+    NULL,
+};
+
+bool
+va_wayland_pvr_create(VADisplayContextP pDisplayContext)
+{
+    VADriverContextP const ctx = pDisplayContext->pDriverContext;
+    struct va_wayland_pvr_context *wl_pvr_ctx;
+    struct drm_state *drm_state;
+    uint32_t id;
+
+    wl_pvr_ctx = malloc(sizeof(*wl_pvr_ctx));
+    if (!wl_pvr_ctx)
+        return false;
+    wl_pvr_ctx->base.destroy            = va_wayland_pvr_destroy;
+    wl_pvr_ctx->handle                  = NULL;
+    wl_pvr_ctx->pvr                     = NULL;
+    wl_pvr_ctx->pvr_interface           = NULL;
+    wl_pvr_ctx->is_authenticated        = 0;
+    pDisplayContext->opaque             = wl_pvr_ctx;
+    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;
+
+    wl_pvr_ctx->handle = dlopen(LIBWAYLAND_PVR_NAME, RTLD_LAZY|RTLD_LOCAL);
+    if (!wl_pvr_ctx->handle)
+        return false;
+
+    wl_pvr_ctx->pvr_interface =
+        dlsym(wl_pvr_ctx->handle, "wl_pvr_interface");
+    if (!wl_pvr_ctx->pvr_interface)
+        return false;
+
+    wl_pvr_ctx->registry = wl_display_get_registry(ctx->native_dpy);
+    wl_registry_add_listener(wl_pvr_ctx->registry, &registry_listener, wl_pvr_ctx);
+    wl_display_roundtrip(ctx->native_dpy);
+
+    /* registry_handle_global should have been called by the
+     * wl_display_roundtrip above
+     */
+    if (!wl_pvr_ctx->pvr)
+        return false;
+
+    return true;
+}
diff --git a/va/wayland/va_wayland_pvr.h b/va/wayland/va_wayland_pvr.h
new file mode 100755
index 0000000..e970368
--- /dev/null
+++ b/va/wayland/va_wayland_pvr.h
@@ -0,0 +1,52 @@
+/*
+ * 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_PVR_H
+#define VA_WAYLAND_PVR_H
+
+#include <stdbool.h>
+#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
+ */
+DLL_HIDDEN
+bool
+va_wayland_pvr_create(VADisplayContextP pDisplayContext);
+
+DLL_HIDDEN
+void
+va_wayland_pvr_destroy(VADisplayContextP pDisplayContext);
+
+#endif /* VA_WAYLAND_PVR_H */
diff --git a/va/wayland/wayland-pvr-client-protocol.h b/va/wayland/wayland-pvr-client-protocol.h
new file mode 100755
index 0000000..0331e71
--- /dev/null
+++ b/va/wayland/wayland-pvr-client-protocol.h
@@ -0,0 +1,68 @@
+#ifndef PVR_CLIENT_PROTOCOL_H
+#define PVR_CLIENT_PROTOCOL_H
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stddef.h>
+#include "wayland-client.h"
+
+struct wl_client;
+struct wl_resource;
+
+struct wl_pvr;
+
+extern const struct wl_interface wl_pvr_interface;
+
+#ifndef WL_PVR_FORMAT_ENUM
+#define WL_PVR_FORMAT_ENUM
+enum wl_pvr_format {
+	WL_PVR_FORMAT_ARGB32 = 0,
+	WL_PVR_FORMAT_PREMULTIPLIED_ARGB32 = 1,
+	WL_PVR_FORMAT_XRGB32 = 2,
+};
+#endif /* WL_PVR_FORMAT_ENUM */
+
+#define WL_PVR_CREATE_BUFFER	0
+
+static inline void
+wl_pvr_set_user_data(struct wl_pvr *wl_pvr, void *user_data)
+{
+	wl_proxy_set_user_data((struct wl_proxy *) wl_pvr, user_data);
+}
+
+static inline void *
+wl_pvr_get_user_data(struct wl_pvr *wl_pvr)
+{
+	return wl_proxy_get_user_data((struct wl_proxy *) wl_pvr);
+}
+
+static inline void
+wl_pvr_destroy(struct wl_pvr *wl_pvr)
+{
+	wl_proxy_destroy((struct wl_proxy *) wl_pvr);
+}
+
+static inline struct wl_buffer *
+wl_pvr_create_buffer(struct wl_pvr *wl_pvr, uint32_t handle, int32_t width, int32_t height, uint32_t stride, uint32_t format)
+{
+	struct wl_proxy *id;
+
+	id = wl_proxy_create((struct wl_proxy *) wl_pvr,
+			     &wl_buffer_interface);
+	if (!id)
+		return NULL;
+
+	wl_proxy_marshal((struct wl_proxy *) wl_pvr,
+			 WL_PVR_CREATE_BUFFER, id, handle, width, height, stride, format);
+
+	return (struct wl_buffer *) id;
+}
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif
-- 
1.7.9.5



More information about the Libva mailing list