summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Ermilov <dmitry.ermilov@intel.com>2012-06-07 19:29:14 +0400
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-09-26 11:47:56 +0200
commitbcc85ca5200ae83cbbf895dde46bfa2767495f7f (patch)
treef6bf21d0f59aee73f630430537809cec4d0dbd9d
parent901bbe13c187bfcc138f5a9def3d3625a6395657 (diff)
downloadlibva-bcc85ca5200ae83cbbf895dde46bfa2767495f7f.tar.gz
API: add support for raw DRM.
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@intel.com> Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
-rw-r--r--configure.ac17
-rw-r--r--pkgconfig/Makefile.am4
-rw-r--r--pkgconfig/libva-drm.pc.in12
-rw-r--r--va/Makefile.am12
-rw-r--r--va/drm/Makefile.am48
-rw-r--r--va/drm/va_drm.c148
-rw-r--r--va/drm/va_drm.h61
-rw-r--r--va/va_backend.h2
8 files changed, 302 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 9e7437f..5ca44fe 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=""
@@ -244,6 +256,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
@@ -260,6 +273,7 @@ AC_OUTPUT([
test/v4l_h264/encode/Makefile
test/v4l_h264/decode/Makefile
va/Makefile
+ va/drm/Makefile
va/dummy/Makefile
va/egl/Makefile
va/glx/Makefile
@@ -268,6 +282,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 3fcf697..d681cbd 100644
--- a/va/Makefile.am
+++ b/va/Makefile.am
@@ -77,6 +77,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
@@ -107,7 +117,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 a6f4047..b6b651c 100644
--- a/va/va_backend.h
+++ b/va/va_backend.h
@@ -46,6 +46,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