[Libva] [PATCH v2 1/7] API: add support for raw DRM.

Gwenole Beauchesne gb.devel at gmail.com
Mon Jul 16 02:04:23 PDT 2012


From: Dmitry Ermilov <dmitry.ermilov at intel.com>

This API makes it possible to use DRM-based VA drivers without an X server.
Since this is a renderless API, vaPutSurface() is not available.

Signed-off-by: Dmitry Ermilov <dmitry.ermilov at intel.com>
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 configure.ac              |   17 +++++-
 pkgconfig/Makefile.am     |    4 ++
 pkgconfig/libva-drm.pc.in |   12 ++++
 va/Makefile.am            |   12 +++-
 va/drm/Makefile.am        |   48 +++++++++++++++
 va/drm/va_drm.c           |  148 +++++++++++++++++++++++++++++++++++++++++++++
 va/drm/va_drm.h           |   61 +++++++++++++++++++
 va/va_backend.h           |    2 +
 8 files changed, 302 insertions(+), 2 deletions(-)
 create mode 100644 pkgconfig/libva-drm.pc.in
 create mode 100644 va/drm/Makefile.am
 create mode 100644 va/drm/va_drm.c
 create mode 100644 va/drm/va_drm.h

diff --git a/configure.ac b/configure.ac
index a706c35..efacc2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,11 @@ AC_ARG_ENABLE(docs,
                     [build Doxygen documentation @<:@default=no@:>@])],
     [], [enable_docs="no"])
 
+AC_ARG_ENABLE(drm,
+    [AC_HELP_STRING([--enable-drm],
+                    [build with VA/DRM API support @<:@default=yes@:>@])],
+    [], [enable_drm="yes"])
+
 AC_ARG_ENABLE(glx,
     [AC_HELP_STRING([--enable-glx],
                     [build with GLX support @<:@default=yes@:>@])],
@@ -164,7 +169,7 @@ if test "$enable_docs" = "yes"; then
 fi
 AM_CONDITIONAL(ENABLE_DOCS, test "$enable_docs" = "yes")
 
-# Check for recent enough DRM
+# Check for DRM
 LIBDRM_VERSION=libdrm_version
 PKG_CHECK_MODULES([DRM], [libdrm >= $LIBDRM_VERSION])
 AC_SUBST(LIBDRM_VERSION)
@@ -177,6 +182,13 @@ if test x$libudev = xno; then
 fi
 AM_CONDITIONAL(BUILD_DUMMY_BACKEND, test x$enable_dummy_backend = xyes)
 
+USE_DRM="no"
+if test "$enable_drm" = "yes"; then
+    USE_DRM="yes"
+    AC_DEFINE([HAVE_VA_DRM], [1], [Defined to 1 if VA/DRM API is built])
+fi
+AM_CONDITIONAL(USE_DRM, test "$USE_DRM" = "yes")
+
 # Check for GLX
 USE_GLX="no"
 GL_DEPS_CFLAGS=""
@@ -240,6 +252,7 @@ AC_OUTPUT([
     doc/Makefile
     dummy_drv_video/Makefile
     pkgconfig/Makefile
+    pkgconfig/libva-drm.pc
     pkgconfig/libva-egl.pc
     pkgconfig/libva-glx.pc
     pkgconfig/libva-tpi.pc
@@ -254,6 +267,7 @@ AC_OUTPUT([
     test/transcode/Makefile
     test/vainfo/Makefile
     va/Makefile
+    va/drm/Makefile
     va/dummy/Makefile
     va/egl/Makefile
     va/glx/Makefile
@@ -262,6 +276,7 @@ AC_OUTPUT([
 ])
 
 # Print a small summary
+AS_IF([test x$USE_DRM = xyes], [BACKENDS="drm $BACKENDS"])
 AS_IF([test x$USE_GLX = xyes], [BACKENDS="glx $BACKENDS"])
 AS_IF([test x$USE_EGL = xyes], [BACKENDS="egl $BACKENDS"])
 
diff --git a/pkgconfig/Makefile.am b/pkgconfig/Makefile.am
index f595413..2298c84 100644
--- a/pkgconfig/Makefile.am
+++ b/pkgconfig/Makefile.am
@@ -22,6 +22,9 @@
 
 pcfiles		 = libva.pc
 pcfiles		+= libva-tpi.pc
+if USE_DRM
+pcfiles		+= libva-drm.pc
+endif
 pcfiles		+= libva-x11.pc
 if USE_GLX
 pcfiles		+= libva-glx.pc
@@ -32,6 +35,7 @@ endif
 
 all_pcfiles_in	 = libva.pc.in
 all_pcfiles_in	+= libva-tpi.pc.in
+all_pcfiles_in	+= libva-drm.pc.in
 all_pcfiles_in	+= libva-x11.pc.in
 all_pcfiles_in	+= libva-glx.pc.in
 all_pcfiles_in	+= libva-egl.pc.in
diff --git a/pkgconfig/libva-drm.pc.in b/pkgconfig/libva-drm.pc.in
new file mode 100644
index 0000000..b3fb471
--- /dev/null
+++ b/pkgconfig/libva-drm.pc.in
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+display=drm
+
+Name: libva-${display}
+Description: Userspace Video Acceleration (VA) ${display} interface
+Requires: libva
+Version: @VA_API_VERSION@
+Libs: -L${libdir} -lva-${display}
+Cflags: -I${includedir}
diff --git a/va/Makefile.am b/va/Makefile.am
index 47b7ba6..295d0ad 100644
--- a/va/Makefile.am
+++ b/va/Makefile.am
@@ -91,6 +91,16 @@ libva_x11_la_DEPENDENCIES	= $(libvacorelib) x11/libva_x11.la
 libva_x11_la_LIBADD		= $(libvacorelib) x11/libva_x11.la \
 	$(LIBVA_LIBS) $(X11_LIBS) $(XEXT_LIBS) $(DRM_LIBS) $(XFIXES_LIBS) -ldl
 
+if USE_DRM
+SUBDIRS				+= drm
+lib_LTLIBRARIES			+= libva-drm.la
+libva_drm_la_SOURCES		=
+libva_drm_la_LDFLAGS		= $(LDADD)
+libva_drm_la_DEPENDENCIES	= $(libvacorelib) drm/libva_drm.la
+libva_drm_la_LIBADD		= $(libvacorelib) drm/libva_drm.la \
+	$(LIBVA_LIBS) $(DRM_LIBS)  -ldl
+endif
+
 if USE_GLX
 SUBDIRS				+= glx
 lib_LTLIBRARIES			+= libva-glx.la
@@ -121,7 +131,7 @@ libva_dummy_la_LIBADD		= $(libvacorelib) dummy/libva_dummy.la \
 	$(LIBVA_LIBS) $(DRM_LIBS)
 endif
 
-DIST_SUBDIRS = x11 glx egl dummy
+DIST_SUBDIRS = x11 glx egl dummy drm
 
 DISTCLEANFILES = \
 	va_version.h		\
diff --git a/va/drm/Makefile.am b/va/drm/Makefile.am
new file mode 100644
index 0000000..a2770f2
--- /dev/null
+++ b/va/drm/Makefile.am
@@ -0,0 +1,48 @@
+# 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 PRECISION INSIGHT 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.
+
+INCLUDES = \
+	-DLINUX			\
+	-I$(top_srcdir)		\
+	-I$(top_srcdir)/va	\
+	$(DRM_CFLAGS)		\
+	$(NULL)
+
+source_c = \
+	va_drm.c		\
+	$(NULL)
+
+source_h = \
+	va_drm.h		\
+	$(NULL)
+
+source_h_priv = \
+	$(NULL)
+
+noinst_LTLIBRARIES		= libva_drm.la
+libva_drmincludedir		= ${includedir}/va
+libva_drminclude_HEADERS	= $(source_h)
+libva_drm_la_SOURCES		= $(source_c)
+noinst_HEADERS			= $(source_h_priv)
+
+# Extra clean files so that maintainer-clean removes *everything*
+MAINTAINERCLEANFILES = Makefile.in
diff --git a/va/drm/va_drm.c b/va/drm/va_drm.c
new file mode 100644
index 0000000..c45565f
--- /dev/null
+++ b/va/drm/va_drm.c
@@ -0,0 +1,148 @@
+/*
+ * 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 PRECISION INSIGHT 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 <xf86drm.h>
+#include "va_drm.h"
+#include "va_backend.h"
+#include "va_drmcommon.h"
+
+static int
+va_DisplayContextIsValid(VADisplayContextP pDisplayContext)
+{
+    VADriverContextP const pDriverContext = pDisplayContext->pDriverContext;
+
+    return (pDriverContext &&
+            pDriverContext->display_type == VA_DISPLAY_DRM);
+}
+
+static void
+va_DisplayContextDestroy(VADisplayContextP pDisplayContext)
+{
+    if (!pDisplayContext)
+        return;
+
+    free(pDisplayContext->pDriverContext->drm_state);
+    free(pDisplayContext->pDriverContext);
+    free(pDisplayContext);
+}
+
+struct driver_name_map {
+    const char *key;
+    int         key_len;
+    const char *name;
+};
+
+static const struct driver_name_map g_driver_name_map[] = {
+    { "i915",       4, "i965"   }, // Intel OTC GenX driver
+    { "pvrsrvkm",   8, "pvr"    }, // Intel UMG PVR driver
+    { "emgd",       4, "emgd"   }, // Intel ECG PVR driver
+    { NULL, }
+};
+
+static VAStatus
+va_DisplayContextGetDriverName(
+    VADisplayContextP pDisplayContext,
+    char            **driver_name_ptr
+)
+{
+
+    VADriverContextP const ctx = pDisplayContext->pDriverContext;
+    struct drm_state * const drm_state = ctx->drm_state;
+    drmVersionPtr drm_version;
+    char *driver_name = NULL;
+    const struct driver_name_map *m;
+    drm_magic_t magic;
+
+    *driver_name_ptr = NULL;
+
+    drm_version = drmGetVersion(drm_state->fd);
+    if (!drm_version)
+        return VA_STATUS_ERROR_UNKNOWN;
+
+    for (m = g_driver_name_map; m->key != NULL; m++) {
+        if (drm_version->name_len >= m->key_len &&
+            strncmp(drm_version->name, m->key, m->key_len) == 0)
+            break;
+    }
+    drmFreeVersion(drm_version);
+
+    if (!m->name)
+        return VA_STATUS_ERROR_UNKNOWN;
+
+    driver_name = strdup(m->name);
+    if (!driver_name)
+        return VA_STATUS_ERROR_ALLOCATION_FAILED;
+
+    *driver_name_ptr = driver_name;
+
+    drmGetMagic(drm_state->fd, &magic);
+    drmAuthMagic(drm_state->fd, magic);
+
+    drm_state->auth_type = VA_DRM_AUTH_CUSTOM;
+
+    return VA_STATUS_SUCCESS;
+}
+
+VADisplay
+vaGetDisplayDRM(int fd)
+{
+    VADisplayContextP pDisplayContext = NULL;
+    VADriverContextP  pDriverContext  = NULL;
+    struct drm_state *drm_state       = NULL;
+
+    if (fd < 0)
+        return NULL;
+
+    /* Create new entry */
+    /* XXX: handle cache? */
+    drm_state = calloc(1, sizeof(*drm_state));
+    if (!drm_state)
+        goto error;
+    drm_state->fd = fd;
+
+    pDriverContext = calloc(1, sizeof(*pDriverContext));
+    if (!pDriverContext)
+        goto error;
+    pDriverContext->native_dpy   = NULL;
+    pDriverContext->display_type = VA_DISPLAY_DRM;
+    pDriverContext->drm_state    = drm_state;
+
+    pDisplayContext = calloc(1, sizeof(*pDisplayContext));
+    if (!pDisplayContext)
+        goto error;
+
+    pDisplayContext->vadpy_magic     = VA_DISPLAY_MAGIC;
+    pDisplayContext->pDriverContext  = pDriverContext;
+    pDisplayContext->vaIsValid       = va_DisplayContextIsValid;
+    pDisplayContext->vaDestroy       = va_DisplayContextDestroy;
+    pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
+    return pDisplayContext;
+
+error:
+    free(pDisplayContext);
+    free(pDriverContext);
+    free(drm_state);
+    return NULL;
+}
diff --git a/va/drm/va_drm.h b/va/drm/va_drm.h
new file mode 100644
index 0000000..9af3cc8
--- /dev/null
+++ b/va/drm/va_drm.h
@@ -0,0 +1,61 @@
+/*
+ * va_drm.h - Raw DRM API
+ *
+ * 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_DRM_H
+#define VA_DRM_H
+
+#include <va/va.h>
+
+/**
+ * \file va_drm.h
+ * \brief The raw DRM API
+ *
+ * This file contains the \ref api_drm "Raw DRM API".
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Returns a VA display derived from the specified DRM connection.
+ *
+ * This function returns a (possibly cached) VA display from the
+ * specified DRM connection @fd.
+ *
+ * @param[in]   fd      the DRM connection descriptor
+ * @return the VA display
+ */
+VADisplay
+vaGetDisplayDRM(int fd);
+
+/**@}*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* VA_DRM_H */
diff --git a/va/va_backend.h b/va/va_backend.h
index 72e8d7d..6c7177e 100644
--- a/va/va_backend.h
+++ b/va/va_backend.h
@@ -49,6 +49,8 @@ enum {
     VA_DISPLAY_GLX      = (VA_DISPLAY_X11 | (1 << 0)),
     /** \brief VA/Android API is used, through vaGetDisplay() entry-point. */
     VA_DISPLAY_ANDROID  = 0x20,
+    /** \brief VA/DRM API is used, through vaGetDisplayDRM() entry-point. */
+    VA_DISPLAY_DRM      = 0x30,
 };
 
 struct VADriverVTable
-- 
1.7.9.5



More information about the Libva mailing list