• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

hardware/intel/libva


Commit MetaInfo

修訂98ed754fa7ecf5848f9aeb56a6237ef415ff0a4d (tree)
時間2009-08-25 01:35:05
作者Austin Yuan <shengquan.yuan@inte...>
CommiterAustin Yuan

Log Message

Merge branch 'test'

Change Summary

差異

--- a/Makefile.am
+++ b/Makefile.am
@@ -21,9 +21,21 @@
2121 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
2323 AUTOMAKE_OPTIONS = foreign
24-SUBDIRS = src dummy_drv_video i965_drv_video test
24+
25+SUBDIRS = src test
26+if BUILD_DUMMY_DRIVER
27+SUBDIRS += dummy_drv_video
28+endif
29+if BUILD_I965_DRIVER
30+SUBDIRS += i965_drv_video
31+endif
32+
33+pcfiles = \
34+ libva.pc
2535
2636 pkgconfigdir = @pkgconfigdir@
27-pkgconfig_DATA = libva.pc
37+pkgconfig_DATA = $(pcfiles)
2838
2939 EXTRA_DIST = libva.pc.in
40+
41+CLEANFILES = $(pcfiles)
--- a/configure.ac
+++ b/configure.ac
@@ -20,13 +20,70 @@
2020 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2121 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
23+# libva package version number, (as distinct from shared library version)
24+m4_define([libva_major_version], [0])
25+m4_define([libva_minor_version], [30])
26+m4_define([libva_micro_version], [4])
27+
28+m4_define([libva_version],
29+ [libva_major_version.libva_minor_version.libva_micro_version])
30+
31+# increase this number for each API change
32+m4_define([libva_sds_version], [2])
33+
34+# if the library source code has changed, increment revision
35+m4_define([libva_lt_revision], [1])
36+# if any interface was added/removed/changed, then inc current, reset revision
37+m4_define([libva_lt_current], [0])
38+# if any interface was added since last public release, then increment age
39+# if any interface was removed since last public release, then set age to 0
40+m4_define([libva_lt_age], [0])
41+
2342 AC_PREREQ(2.57)
24-AC_INIT([libva], 0.30.4, [waldo.bastian@intel.com], libva)
43+AC_INIT([libva], [libva_version], [waldo.bastian@intel.com], libva)
2544 AC_CONFIG_SRCDIR([Makefile.am])
2645 AM_INIT_AUTOMAKE([dist-bzip2])
2746
2847 AM_CONFIG_HEADER([config.h])
2948
49+LIBVA_MAJOR_VERSION=libva_major_version
50+LIBVA_MINOR_VERSION=libva_minor_version
51+LIBVA_MICRO_VERSION=libva_micro_version
52+LIBVA_VERSION=libva_version
53+AC_SUBST(LIBVA_MAJOR_VERSION)
54+AC_SUBST(LIBVA_MINOR_VERSION)
55+AC_SUBST(LIBVA_MICRO_VERSION)
56+AC_SUBST(LIBVA_VERSION)
57+
58+LIBVA_SDS_VERSION=libva_sds_version
59+AC_SUBST(LIBVA_SDS_VERSION)
60+
61+LIBVA_LT_CURRENT=libva_lt_current
62+LIBVA_LT_REV=libva_lt_revision
63+LIBVA_LT_AGE=libva_lt_age
64+LIBVA_LT_VERSION="$LIBVA_LT_CURRENT:$LIBVA_LT_REV:$LIBVA_LT_AGE"
65+LIBVA_LT_LDFLAGS="-version-info $LIBVA_LT_VERSION"
66+AC_SUBST(LIBVA_LT_VERSION)
67+AC_SUBST(LIBVA_LT_LDFLAGS)
68+
69+AC_ARG_ENABLE(dummy-driver,
70+ [AC_HELP_STRING([--enable-dummy-driver],
71+ [build dummy video driver])],
72+ [], [enable_dummy_driver=yes])
73+AM_CONDITIONAL(BUILD_DUMMY_DRIVER, test x$enable_dummy_driver = xyes)
74+
75+AC_ARG_ENABLE(i965-driver,
76+ [AC_HELP_STRING([--enable-i965-driver],
77+ [build i965 video driver])],
78+ [], [enable_i965_driver=no])
79+
80+AC_ARG_WITH(drivers-path,
81+ [AC_HELP_STRING([--with-drivers-path=[[path]]], [drivers path])],,
82+ [with_drivers_path="$libdir/dri"])
83+
84+LIBVA_DRIVERS_PATH="$with_drivers_path"
85+AC_SUBST(LIBVA_DRIVERS_PATH)
86+
3087 AC_DISABLE_STATIC
3188 AC_PROG_LIBTOOL
3289 AC_PROG_CC
@@ -36,23 +93,34 @@ AC_SYS_LARGEFILE
3693
3794 PKG_CHECK_MODULES([X11], [x11])
3895 PKG_CHECK_MODULES([XEXT],[xext])
96+PKG_CHECK_MODULES([XFIXES], [xfixes])
3997 PKG_CHECK_MODULES([DRM], [libdrm])
40-PKG_CHECK_MODULES(LIBDRM_DEPS, [libdrm])
4198
4299 PKG_CHECK_MODULES(GEN4ASM, [intel-gen4asm >= 1.0], [gen4asm=yes], [gen4asm=no])
43100 AM_CONDITIONAL(HAVE_GEN4ASM, test x$gen4asm = xyes)
44101
102+# Check for libdrm >= 2.4 (needed for i965_drv_video.so)
103+if test x$enable_i965_driver = xyes && ! $PKG_CONFIG --atleast-version=2.4 libdrm; then
104+ AC_MSG_WARN([libdrm < 2.4 found, disabling build of i965 video driver])
105+ enable_i965_driver=no
106+fi
107+AM_CONDITIONAL(BUILD_I965_DRIVER, test x$enable_i965_driver = xyes)
108+
45109 # We only need the headers, we don't link against the DRM libraries
46-LIBVA_CFLAGS="$LIBDRM_DEPS_CFLAGS"
110+LIBVA_CFLAGS="$DRM_CFLAGS"
47111 AC_SUBST(LIBVA_CFLAGS)
48112 AC_SUBST(LIBVA_LIBS)
49113
50114 pkgconfigdir=${libdir}/pkgconfig
51115 AC_SUBST(pkgconfigdir)
52116
117+libvabackendlib=libva.la
118+AC_SUBST([libvabackendlib])
119+
53120 AC_OUTPUT([
54121 Makefile
55122 src/Makefile
123+ src/va_version.h
56124 src/x11/Makefile
57125 dummy_drv_video/Makefile
58126 i965_drv_video/Makefile
--- a/dummy_drv_video/Makefile.am
+++ b/dummy_drv_video/Makefile.am
@@ -21,9 +21,10 @@
2121 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
2323 dummy_drv_video_la_LTLIBRARIES = dummy_drv_video.la
24-dummy_drv_video_ladir = /usr/lib/dri
24+dummy_drv_video_ladir = @LIBVA_DRIVERS_PATH@
2525 dummy_drv_video_la_LDFLAGS = -module -avoid-version -no-undefined -Wl,--no-undefined
26-dummy_drv_video_la_LIBADD = ../src/libva.la
26+dummy_drv_video_la_LIBADD = $(top_srcdir)/src/$(libvabackendlib)
27+dummy_drv_video_la_DEPENDENCIES = $(top_srcdir)/src/$(libvabackendlib)
2728
2829 AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/../../include/external/ -I$(top_srcdir)/../../include/kmd -DIN_LIBVA
2930 dummy_drv_video_la_SOURCES = dummy_drv_video.c object_heap.c
--- a/dummy_drv_video/dummy_drv_video.c
+++ b/dummy_drv_video/dummy_drv_video.c
@@ -1211,15 +1211,15 @@ VAStatus dummy_Terminate( VADriverContextP ctx )
12111211 return VA_STATUS_SUCCESS;
12121212 }
12131213
1214-VAStatus __vaDriverInit_0_29( VADriverContextP ctx )
1214+VAStatus __vaDriverInit_0_30( VADriverContextP ctx )
12151215 {
12161216 object_base_p obj;
12171217 int result;
12181218 struct dummy_driver_data *driver_data;
12191219 int i;
12201220
1221- ctx->version_major = 0;
1222- ctx->version_minor = 29;
1221+ ctx->version_major = VA_MAJOR_VERSION;
1222+ ctx->version_minor = VA_MINOR_VERSION;
12231223 ctx->max_profiles = DUMMY_MAX_PROFILES;
12241224 ctx->max_entrypoints = DUMMY_MAX_ENTRYPOINTS;
12251225 ctx->max_attributes = DUMMY_MAX_CONFIG_ATTRIBUTES;
--- a/i965_drv_video/Makefile.am
+++ b/i965_drv_video/Makefile.am
@@ -25,7 +25,7 @@ SUBDIRS = shaders
2525 AM_CFLAGS = -Wall -I$(top_srcdir)/src -I$(top_srcdir)/src/x11 @DRM_CFLAGS@ -DIN_LIBVA
2626
2727 i965_drv_video_la_LTLIBRARIES = i965_drv_video.la
28-i965_drv_video_ladir = $(libdir)/dri
28+i965_drv_video_ladir = @LIBVA_DRIVERS_PATH@
2929 i965_drv_video_la_LDFLAGS = -module -avoid-version -no-undefined -Wl,--no-undefined @DRM_LIBS@ -ldrm_intel
3030 i965_drv_video_la_LIBADD = ../src/libva.la -lpthread
3131
--- a/libva.pc.in
+++ b/libva.pc.in
@@ -2,6 +2,7 @@ prefix=@prefix@
22 exec_prefix=@exec_prefix@
33 libdir=@libdir@
44 includedir=@includedir@
5+driverdir=@LIBVA_DRIVERS_PATH@
56
67 Name: libva
78 Description: Userspace Video Acceleration (VA) core interface
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -22,25 +22,26 @@
2222
2323 INCLUDES = \
2424 $(LIBVA_CFLAGS) -I$(top_srcdir)/src/x11 \
25- -DIN_LIBVA
25+ -DIN_LIBVA \
26+ -DVA_DRIVERS_PATH="\"$(LIBVA_DRIVERS_PATH)\""
27+
28+LDADD = \
29+ $(LIBVA_LT_LDFLAGS)
2630
2731 libva_la_LTLIBRARIES = libva.la
2832 libva_ladir = $(libdir)
29-libva_la_LDFLAGS = -version-number 0:30:4 -no-undefined
33+libva_la_LDFLAGS = $(LDADD) -no-undefined
3034 libva_la_LIBADD = $(LIBVA_LIBS) -ldl -lX11 -lXext x11/libva_x11.la -ldrm -lXfixes
3135
32-nodist_libva_la_SOURCES = va_version.h
33-BUILT_SOURCES = va_version.h
34-
35-CLEANFILES = va_version.h
36-
37-va_version.h: Makefile
38- echo "#define VA_BUILD_DATE \"$(shell date +'%Y%m%d') $(shell date +'1%H%M%S') \"" > va_version.h
39- echo "#define VA_BUILD_GIT \"($(shell git log | head -n1 | cut -f2 -d' ')) \" " >> va_version.h
40-
4136 SUBDIRS = x11
4237
4338 libva_la_SOURCES = va.c
4439
4540 libvaincludedir = ${includedir}/va
46-libvainclude_HEADERS = va.h va_backend.h
41+libvainclude_HEADERS = va.h va_backend.h va_version.h
42+
43+DISTCLEANFILES = \
44+ va_version.h
45+
46+EXTRA_DIST = \
47+ va_version.h.in
--- a/src/va.c
+++ b/src/va.c
@@ -22,11 +22,10 @@
2222 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2323 */
2424
25+#define _GNU_SOURCE 1
2526 #include "va.h"
2627 #include "va_backend.h"
2728
28-#include "va_version.h"
29-
3029 #include <assert.h>
3130 #include <stdarg.h>
3231 #include <stdio.h>
@@ -40,13 +39,9 @@
4039 #include "va_dricommon.h"
4140
4241
43-#define VA_STR_VERSION VA_BUILD_DATE VA_BUILD_GIT
44-
45-#define VA_MAJOR_VERSION 0
46-#define VA_MINOR_VERSION 30
4742 #define DRIVER_INIT_FUNC "__vaDriverInit_0_30"
43+#define DRIVER_INIT_FUNC_SDS "__vaDriverInit_0_30_sds"
4844
49-#define DEFAULT_DRIVER_DIR "/usr/lib/dri/"
5045 #define DRIVER_EXTENSION "_drv_video.so"
5146
5247 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
@@ -116,21 +111,8 @@ static Bool va_checkString(const char* value, char *variable)
116111 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
117112 {
118113 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
119- VADriverContextP ctx = CTX(dpy);
120114
121- VAStatus ret;
122- ret = pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
123- if (ret == VA_STATUS_SUCCESS)
124- {
125- if (isDRI2Connected(ctx, driver_name))
126- {
127- ret = VA_STATUS_SUCCESS;
128- } else if (isDRI1Connected(ctx, driver_name))
129- {
130- ret = VA_STATUS_SUCCESS;
131- }
132- }
133- return ret;
115+ return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
134116 }
135117
136118 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
@@ -152,7 +134,7 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
152134 }
153135 if (!search_path)
154136 {
155- search_path = DEFAULT_DRIVER_DIR;
137+ search_path = VA_DRIVERS_PATH;
156138 }
157139
158140 search_path = strdup((const char *)search_path);
@@ -185,6 +167,11 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
185167 init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC);
186168 if (!init_func)
187169 {
170+ /* Then try SDS extensions (VDPAU and XvBA backends) */
171+ init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC_SDS);
172+ }
173+ if (!init_func)
174+ {
188175 va_errorMessage("%s has no function %s\n", driver_path, DRIVER_INIT_FUNC);
189176 dlclose(handle);
190177 }
@@ -347,7 +334,7 @@ VAStatus vaInitialize (
347334
348335 va_debug_trace = (getenv("LIBVA_DEBUG_TRACE") != NULL);
349336
350- va_infoMessage("libva build on %s\n", VA_STR_VERSION);
337+ va_infoMessage("libva version %s\n", VA_VERSION_S);
351338
352339 vaStatus = va_getDriverName(dpy, &driver_name);
353340 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
--- a/src/va.h
+++ b/src/va.h
@@ -63,6 +63,12 @@
6363 #ifndef _VA_H_
6464 #define _VA_H_
6565
66+#ifdef IN_LIBVA
67+#include "va_version.h"
68+#else
69+#include <va/va_version.h>
70+#endif
71+
6672 #ifdef __cplusplus
6773 extern "C" {
6874 #endif
@@ -364,7 +370,8 @@ typedef VAGenericID VAContextID;
364370
365371 typedef VAGenericID VASurfaceID;
366372
367-#define VA_INVALID_SURFACE -1
373+#define VA_INVALID_ID 0xffffffff
374+#define VA_INVALID_SURFACE VA_INVALID_ID
368375
369376 /*
370377 * vaCreateSurfaces - Create an array of surfaces used for decode and display
@@ -465,6 +472,27 @@ typedef enum
465472 } VABufferType;
466473
467474
475+/*
476+ * There will be cases where the bitstream buffer will not have enough room to hold
477+ * the data for the entire slice, and the following flags will be used in the slice
478+ * parameter to signal to the server for the possible cases.
479+ * If a slice parameter buffer and slice data buffer pair is sent to the server with
480+ * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below),
481+ * then a slice parameter and data buffer needs to be sent again to complete this slice.
482+ */
483+#define VA_SLICE_DATA_FLAG_ALL 0x00 /* whole slice is in the buffer */
484+#define VA_SLICE_DATA_FLAG_BEGIN 0x01 /* The beginning of the slice is in the buffer but the end if not */
485+#define VA_SLICE_DATA_FLAG_MIDDLE 0x02 /* Neither beginning nor end of the slice is in the buffer */
486+#define VA_SLICE_DATA_FLAG_END 0x04 /* end of the slice is in the buffer */
487+
488+/* Codec-independent Slice Parameter Buffer base */
489+typedef struct _VASliceParameterBufferBase
490+{
491+ unsigned int slice_data_size; /* number of bytes in the slice data buffer for this slice */
492+ unsigned int slice_data_offset; /* the offset to the first byte of slice data */
493+ unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX definitions */
494+} VASliceParameterBufferBase;
495+
468496 /****************************
469497 * MPEG-2 data structures
470498 ****************************/
@@ -516,19 +544,6 @@ typedef struct _VAIQMatrixBufferMPEG2
516544 unsigned char chroma_non_intra_quantiser_matrix[64];
517545 } VAIQMatrixBufferMPEG2;
518546
519-/*
520- * There will be cases where the bitstream buffer will not have enough room to hold
521- * the data for the entire slice, and the following flags will be used in the slice
522- * parameter to signal to the server for the possible cases.
523- * If a slice parameter buffer and slice data buffer pair is sent to the server with
524- * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below),
525- * then a slice parameter and data buffer needs to be sent again to complete this slice.
526- */
527-#define VA_SLICE_DATA_FLAG_ALL 0x00 /* whole slice is in the buffer */
528-#define VA_SLICE_DATA_FLAG_BEGIN 0x01 /* The beginning of the slice is in the buffer but the end if not */
529-#define VA_SLICE_DATA_FLAG_MIDDLE 0x02 /* Neither beginning nor end of the slice is in the buffer */
530-#define VA_SLICE_DATA_FLAG_END 0x04 /* end of the slice is in the buffer */
531-
532547 /* MPEG-2 Slice Parameter Buffer */
533548 typedef struct _VASliceParameterBufferMPEG2
534549 {
--- a/src/va_backend.h
+++ b/src/va_backend.h
@@ -407,14 +407,11 @@ struct VADriverVTable
407407
408408 struct VADriverContext
409409 {
410- void *old_pNext; /* preserved for binary compatibility */
411-
412410 void *pDriverData;
413411 struct VADriverVTable vtable;
414412
415413 Display *x11_dpy;
416414 int x11_screen;
417- int dri2;
418415 int version_major;
419416 int version_minor;
420417 int max_profiles;
--- /dev/null
+++ b/src/va_version.h.in
@@ -0,0 +1,94 @@
1+/*
2+ * Copyright (C) 2009 Splitted-Desktop Systems. All Rights Reserved.
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a
5+ * copy of this software and associated documentation files (the
6+ * "Software"), to deal in the Software without restriction, including
7+ * without limitation the rights to use, copy, modify, merge, publish,
8+ * distribute, sub license, and/or sell copies of the Software, and to
9+ * permit persons to whom the Software is furnished to do so, subject to
10+ * the following conditions:
11+ *
12+ * The above copyright notice and this permission notice (including the
13+ * next paragraph) shall be included in all copies or substantial portions
14+ * of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+ */
24+
25+#ifndef VA_VERSION_H
26+#define VA_VERSION_H
27+
28+/**
29+ * VA_MAJOR_VERSION:
30+ *
31+ * The major version of the VA library (1, if %VA_VERSION is 1.2.3)
32+ */
33+#define VA_MAJOR_VERSION (@LIBVA_MAJOR_VERSION@)
34+
35+/**
36+ * VA_MINOR_VERSION:
37+ *
38+ * The minor version of the VA library (2, if %VA_VERSION is 1.2.3)
39+ */
40+#define VA_MINOR_VERSION (@LIBVA_MINOR_VERSION@)
41+
42+/**
43+ * VA_MICRO_VERSION:
44+ *
45+ * The micro version of the VA library (3, if %VA_VERSION is 1.2.3)
46+ */
47+#define VA_MICRO_VERSION (@LIBVA_MICRO_VERSION@)
48+
49+/**
50+ * VA_SDS_VERSION:
51+ *
52+ * The version of the SDS API extensions to the VA library
53+ */
54+#define VA_SDS_VERSION (@LIBVA_SDS_VERSION@)
55+
56+/**
57+ * VA_VERSION:
58+ *
59+ * The full version of the VA library, like 1.2.3
60+ */
61+#define VA_VERSION @LIBVA_VERSION@
62+
63+/**
64+ * VA_VERSION_S:
65+ *
66+ * The full version of the VA library, in string form (suited for
67+ * string concatenation)
68+ */
69+#define VA_VERSION_S "@LIBVA_VERSION@-sds@LIBVA_SDS_VERSION@"
70+
71+/**
72+ * VA_VERSION_HEX:
73+ *
74+ * Numerically encoded version of the VA library, like 0x010203
75+ */
76+#define VA_VERSION_HEX ((VA_MAJOR_VERSION << 24) | \
77+ (VA_MINOR_VERSION << 16) | \
78+ (VA_MICRO_VERSION << 8))
79+
80+/**
81+ * VA_CHECK_VERSION:
82+ * @major: major version, like 1 in 1.2.3
83+ * @minor: minor version, like 2 in 1.2.3
84+ * @micro: micro version, like 3 in 1.2.3
85+ *
86+ * Evaluates to %TRUE if the version of the VA library is greater
87+ * than @major, @minor and @micro
88+ */
89+#define VA_CHECK_VERSION(major,minor,micro) \
90+ (VA_MAJOR_VERSION > (major) || \
91+ (VA_MAJOR_VERSION == (major) && VA_MINOR_VERSION > (minor)) || \
92+ (VA_MAJOR_VERSION == (major) && VA_MINOR_VERSION == (minor) && VA_MICRO_VERSION >= (micro)))
93+
94+#endif /* VA_VERSION_H */
--- a/src/x11/Makefile.am
+++ b/src/x11/Makefile.am
@@ -22,9 +22,9 @@ AM_CFLAGS = -DLINUX -DIN_LIBVA -I$(top_srcdir)/src $(DRM_CFLAGS)
2222
2323 noinst_LTLIBRARIES = libva_x11.la
2424
25-libva_x11includedir = ${includedir}/va
25+libva_x11includedir = ${includedir}/va
2626 libva_x11include_HEADERS = va_x11.h va_dri.h va_dri2.h va_dricommon.h
2727
28-libva_x11_la_SOURCES = va_x11.c va_dri.c va_dri2.c va_dricommon.c dri2_util.c dri1_util.c
28+libva_x11_la_SOURCES = va_x11.c va_dri.c va_dri2.c va_dricommon.c dri2_util.c dri1_util.c va_nvctrl.c
2929
30-EXTRA_DIST = va_dristr.h va_dri2str.h va_dri2tokens.h
30+EXTRA_DIST = va_dristr.h va_dri2str.h va_dri2tokens.h va_nvctrl.h
--- a/src/x11/dri2_util.c
+++ b/src/x11/dri2_util.c
@@ -5,7 +5,8 @@
55
66 #include <xf86drm.h>
77
8-#include "X11/Xlib.h"
8+#include <X11/Xlibint.h>
9+#include <X11/Xlib.h>
910 #include "va.h"
1011 #include "va_backend.h"
1112
--- /dev/null
+++ b/src/x11/va_nvctrl.c
@@ -0,0 +1,392 @@
1+/*
2+ * Copyright (c) 2008 NVIDIA, Corporation
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice (including the next
12+ * paragraph) shall be included in all copies or substantial portions of the
13+ * Software.
14+ *
15+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+ * SOFTWARE.
22+ */
23+
24+#define _GNU_SOURCE 1
25+#include <string.h>
26+
27+#define NEED_REPLIES
28+#include <stdlib.h>
29+#include <X11/Xlibint.h>
30+#include <X11/Xutil.h>
31+#include <X11/extensions/Xext.h>
32+#include <X11/extensions/extutil.h>
33+#include "va_nvctrl.h"
34+
35+#define NV_CONTROL_ERRORS 0
36+#define NV_CONTROL_EVENTS 5
37+#define NV_CONTROL_NAME "NV-CONTROL"
38+
39+#define NV_CTRL_TARGET_TYPE_X_SCREEN 0
40+#define NV_CTRL_TARGET_TYPE_GPU 1
41+#define NV_CTRL_TARGET_TYPE_FRAMELOCK 2
42+#define NV_CTRL_TARGET_TYPE_VCSC 3 /* Visual Computing System */
43+
44+#define NV_CTRL_STRING_NVIDIA_DRIVER_VERSION 3 /* R--G */
45+
46+#define X_nvCtrlQueryExtension 0
47+#define X_nvCtrlIsNv 1
48+#define X_nvCtrlQueryStringAttribute 4
49+
50+typedef struct {
51+ CARD8 reqType;
52+ CARD8 nvReqType;
53+ CARD16 length B16;
54+} xnvCtrlQueryExtensionReq;
55+#define sz_xnvCtrlQueryExtensionReq 4
56+
57+typedef struct {
58+ BYTE type; /* X_Reply */
59+ CARD8 padb1;
60+ CARD16 sequenceNumber B16;
61+ CARD32 length B32;
62+ CARD16 major B16;
63+ CARD16 minor B16;
64+ CARD32 padl4 B32;
65+ CARD32 padl5 B32;
66+ CARD32 padl6 B32;
67+ CARD32 padl7 B32;
68+ CARD32 padl8 B32;
69+} xnvCtrlQueryExtensionReply;
70+#define sz_xnvCtrlQueryExtensionReply 32
71+
72+typedef struct {
73+ CARD8 reqType;
74+ CARD8 nvReqType;
75+ CARD16 length B16;
76+ CARD32 screen B32;
77+} xnvCtrlIsNvReq;
78+#define sz_xnvCtrlIsNvReq 8
79+
80+typedef struct {
81+ BYTE type; /* X_Reply */
82+ CARD8 padb1;
83+ CARD16 sequenceNumber B16;
84+ CARD32 length B32;
85+ CARD32 isnv B32;
86+ CARD32 padl4 B32;
87+ CARD32 padl5 B32;
88+ CARD32 padl6 B32;
89+ CARD32 padl7 B32;
90+ CARD32 padl8 B32;
91+} xnvCtrlIsNvReply;
92+#define sz_xnvCtrlIsNvReply 32
93+
94+typedef struct {
95+ CARD8 reqType;
96+ CARD8 nvReqType;
97+ CARD16 length B16;
98+ CARD16 target_id B16; /* X screen number or GPU number */
99+ CARD16 target_type B16; /* X screen or GPU */
100+ CARD32 display_mask B32;
101+ CARD32 attribute B32;
102+} xnvCtrlQueryStringAttributeReq;
103+#define sz_xnvCtrlQueryStringAttributeReq 16
104+
105+typedef struct {
106+ BYTE type;
107+ BYTE pad0;
108+ CARD16 sequenceNumber B16;
109+ CARD32 length B32;
110+ CARD32 flags B32;
111+ CARD32 n B32; /* Length of string */
112+ CARD32 pad4 B32;
113+ CARD32 pad5 B32;
114+ CARD32 pad6 B32;
115+ CARD32 pad7 B32;
116+} xnvCtrlQueryStringAttributeReply;
117+#define sz_xnvCtrlQueryStringAttributeReply 32
118+
119+#define NVCTRL_EXT_NEED_CHECK (XPointer)(~0)
120+#define NVCTRL_EXT_NEED_NOTHING (XPointer)(0)
121+#define NVCTRL_EXT_NEED_TARGET_SWAP (XPointer)(1)
122+
123+static XExtensionInfo _nvctrl_ext_info_data;
124+static XExtensionInfo *nvctrl_ext_info = &_nvctrl_ext_info_data;
125+static /* const */ char *nvctrl_extension_name = NV_CONTROL_NAME;
126+
127+#define XNVCTRLCheckExtension(dpy,i,val) \
128+ XextCheckExtension (dpy, i, nvctrl_extension_name, val)
129+#define XNVCTRLSimpleCheckExtension(dpy,i) \
130+ XextSimpleCheckExtension (dpy, i, nvctrl_extension_name)
131+
132+static int close_display();
133+static /* const */ XExtensionHooks nvctrl_extension_hooks = {
134+ NULL, /* create_gc */
135+ NULL, /* copy_gc */
136+ NULL, /* flush_gc */
137+ NULL, /* free_gc */
138+ NULL, /* create_font */
139+ NULL, /* free_font */
140+ close_display, /* close_display */
141+ NULL, /* wire_to_event */
142+ NULL, /* event_to_wire */
143+ NULL, /* error */
144+ NULL, /* error_string */
145+};
146+
147+static XEXT_GENERATE_FIND_DISPLAY (find_display, nvctrl_ext_info,
148+ nvctrl_extension_name,
149+ &nvctrl_extension_hooks,
150+ NV_CONTROL_EVENTS, NVCTRL_EXT_NEED_CHECK)
151+
152+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, nvctrl_ext_info)
153+
154+static Bool XNVCTRLQueryVersion (Display *dpy, int *major, int *minor);
155+
156+/*
157+ * NV-CONTROL versions 1.8 and 1.9 pack the target_type and target_id
158+ * fields in reversed order. In order to talk to one of these servers,
159+ * we need to swap these fields.
160+ */
161+static void XNVCTRLCheckTargetData(Display *dpy, XExtDisplayInfo *info,
162+ int *target_type, int *target_id)
163+{
164+ /* Find out what the server's NV-CONTROL version is and
165+ * setup for swapping if we need to.
166+ */
167+ if (info->data == NVCTRL_EXT_NEED_CHECK) {
168+ int major, minor;
169+
170+ if (XNVCTRLQueryVersion(dpy, &major, &minor)) {
171+ if (major == 1 &&
172+ (minor == 8 || minor == 9)) {
173+ info->data = NVCTRL_EXT_NEED_TARGET_SWAP;
174+ } else {
175+ info->data = NVCTRL_EXT_NEED_NOTHING;
176+ }
177+ } else {
178+ info->data = NVCTRL_EXT_NEED_NOTHING;
179+ }
180+ }
181+
182+ /* We need to swap the target_type and target_id */
183+ if (info->data == NVCTRL_EXT_NEED_TARGET_SWAP) {
184+ int tmp;
185+ tmp = *target_type;
186+ *target_type = *target_id;
187+ *target_id = tmp;
188+ }
189+}
190+
191+
192+static Bool XNVCTRLQueryExtension (
193+ Display *dpy,
194+ int *event_basep,
195+ int *error_basep
196+){
197+ XExtDisplayInfo *info = find_display (dpy);
198+
199+ if (XextHasExtension(info)) {
200+ if (event_basep) *event_basep = info->codes->first_event;
201+ if (error_basep) *error_basep = info->codes->first_error;
202+ return True;
203+ } else {
204+ return False;
205+ }
206+}
207+
208+
209+static Bool XNVCTRLQueryVersion (
210+ Display *dpy,
211+ int *major,
212+ int *minor
213+){
214+ XExtDisplayInfo *info = find_display (dpy);
215+ xnvCtrlQueryExtensionReply rep;
216+ xnvCtrlQueryExtensionReq *req;
217+
218+ if(!XextHasExtension(info))
219+ return False;
220+
221+ XNVCTRLCheckExtension (dpy, info, False);
222+
223+ LockDisplay (dpy);
224+ GetReq (nvCtrlQueryExtension, req);
225+ req->reqType = info->codes->major_opcode;
226+ req->nvReqType = X_nvCtrlQueryExtension;
227+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
228+ UnlockDisplay (dpy);
229+ SyncHandle ();
230+ return False;
231+ }
232+ if (major) *major = rep.major;
233+ if (minor) *minor = rep.minor;
234+ UnlockDisplay (dpy);
235+ SyncHandle ();
236+ return True;
237+}
238+
239+
240+static Bool XNVCTRLIsNvScreen (
241+ Display *dpy,
242+ int screen
243+){
244+ XExtDisplayInfo *info = find_display (dpy);
245+ xnvCtrlIsNvReply rep;
246+ xnvCtrlIsNvReq *req;
247+ Bool isnv;
248+
249+ if(!XextHasExtension(info))
250+ return False;
251+
252+ XNVCTRLCheckExtension (dpy, info, False);
253+
254+ LockDisplay (dpy);
255+ GetReq (nvCtrlIsNv, req);
256+ req->reqType = info->codes->major_opcode;
257+ req->nvReqType = X_nvCtrlIsNv;
258+ req->screen = screen;
259+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
260+ UnlockDisplay (dpy);
261+ SyncHandle ();
262+ return False;
263+ }
264+ isnv = rep.isnv;
265+ UnlockDisplay (dpy);
266+ SyncHandle ();
267+ return isnv;
268+}
269+
270+
271+static Bool XNVCTRLQueryTargetStringAttribute (
272+ Display *dpy,
273+ int target_type,
274+ int target_id,
275+ unsigned int display_mask,
276+ unsigned int attribute,
277+ char **ptr
278+){
279+ XExtDisplayInfo *info = find_display (dpy);
280+ xnvCtrlQueryStringAttributeReply rep;
281+ xnvCtrlQueryStringAttributeReq *req;
282+ Bool exists;
283+ int length, numbytes, slop;
284+
285+ if (!ptr) return False;
286+
287+ if(!XextHasExtension(info))
288+ return False;
289+
290+ XNVCTRLCheckExtension (dpy, info, False);
291+ XNVCTRLCheckTargetData(dpy, info, &target_type, &target_id);
292+
293+ LockDisplay (dpy);
294+ GetReq (nvCtrlQueryStringAttribute, req);
295+ req->reqType = info->codes->major_opcode;
296+ req->nvReqType = X_nvCtrlQueryStringAttribute;
297+ req->target_type = target_type;
298+ req->target_id = target_id;
299+ req->display_mask = display_mask;
300+ req->attribute = attribute;
301+ if (!_XReply (dpy, (xReply *) &rep, 0, False)) {
302+ UnlockDisplay (dpy);
303+ SyncHandle ();
304+ return False;
305+ }
306+ length = rep.length;
307+ numbytes = rep.n;
308+ slop = numbytes & 3;
309+ *ptr = (char *) Xmalloc(numbytes);
310+ if (! *ptr) {
311+ _XEatData(dpy, length);
312+ UnlockDisplay (dpy);
313+ SyncHandle ();
314+ return False;
315+ } else {
316+ _XRead(dpy, (char *) *ptr, numbytes);
317+ if (slop) _XEatData(dpy, 4-slop);
318+ }
319+ exists = rep.flags;
320+ UnlockDisplay (dpy);
321+ SyncHandle ();
322+ return exists;
323+}
324+
325+static Bool XNVCTRLQueryStringAttribute (
326+ Display *dpy,
327+ int screen,
328+ unsigned int display_mask,
329+ unsigned int attribute,
330+ char **ptr
331+){
332+ return XNVCTRLQueryTargetStringAttribute(dpy, NV_CTRL_TARGET_TYPE_X_SCREEN,
333+ screen, display_mask,
334+ attribute, ptr);
335+}
336+
337+
338+Bool VA_NVCTRLQueryDirectRenderingCapable( Display *dpy, int screen,
339+ Bool *isCapable )
340+{
341+ int event_base;
342+ int error_base;
343+
344+ if (isCapable)
345+ *isCapable = False;
346+
347+ if (!XNVCTRLQueryExtension(dpy, &event_base, &error_base))
348+ return False;
349+
350+ if (isCapable && XNVCTRLIsNvScreen(dpy, screen))
351+ *isCapable = True;
352+
353+ return True;
354+}
355+
356+Bool VA_NVCTRLGetClientDriverName( Display *dpy, int screen,
357+ int *ddxDriverMajorVersion, int *ddxDriverMinorVersion,
358+ int *ddxDriverPatchVersion, char **clientDriverName )
359+{
360+ if (ddxDriverMajorVersion)
361+ *ddxDriverMajorVersion = 0;
362+ if (ddxDriverMinorVersion)
363+ *ddxDriverMinorVersion = 0;
364+ if (ddxDriverPatchVersion)
365+ *ddxDriverPatchVersion = 0;
366+ if (clientDriverName)
367+ *clientDriverName = NULL;
368+
369+ char *nvidia_driver_version = NULL;
370+ if (!XNVCTRLQueryStringAttribute(dpy, screen, 0, NV_CTRL_STRING_NVIDIA_DRIVER_VERSION, &nvidia_driver_version))
371+ return False;
372+
373+ char *end, *str = nvidia_driver_version;
374+ unsigned long v = strtoul(str, &end, 10);
375+ if (end && end != str) {
376+ if (ddxDriverMajorVersion)
377+ *ddxDriverMajorVersion = v;
378+ if (*(str = end) == '.') {
379+ v = strtoul(str + 1, &end, 10);
380+ if (end && end != str && *end == '\0') {
381+ if (ddxDriverMinorVersion)
382+ *ddxDriverMinorVersion = v;
383+ }
384+ }
385+ }
386+ Xfree(nvidia_driver_version);
387+
388+ if (clientDriverName)
389+ *clientDriverName = strdup("nvidia");
390+
391+ return True;
392+}
--- /dev/null
+++ b/src/x11/va_nvctrl.h
@@ -0,0 +1,36 @@
1+/*
2+ * Copyright (c) 2008 NVIDIA, Corporation
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5+ * of this software and associated documentation files (the "Software"), to deal
6+ * in the Software without restriction, including without limitation the rights
7+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+ * copies of the Software, and to permit persons to whom the Software is
9+ * furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice (including the next
12+ * paragraph) shall be included in all copies or substantial portions of the
13+ * Software.
14+ *
15+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+ * SOFTWARE.
22+ */
23+
24+#ifndef VA_NVCTRLLIB_H
25+#define VA_NVCTRLLIB_H
26+
27+#include <X11/Xlib.h>
28+
29+Bool VA_NVCTRLQueryDirectRenderingCapable( Display *dpy, int screen,
30+ Bool *isCapable );
31+
32+Bool VA_NVCTRLGetClientDriverName( Display *dpy, int screen,
33+ int *ddxDriverMajorVersion, int *ddxDriverMinorVersion,
34+ int *ddxDriverPatchVersion, char **clientDriverName );
35+
36+#endif /* VA_NVCTRLLIB_H */
--- a/src/x11/va_x11.c
+++ b/src/x11/va_x11.c
@@ -22,6 +22,7 @@
2222 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2323 */
2424
25+#define _GNU_SOURCE 1
2526 #include "config.h"
2627 #include "va.h"
2728 #include "va_backend.h"
@@ -29,9 +30,11 @@
2930 #include "va_dri.h"
3031 #include "va_dri2.h"
3132 #include "va_dricommon.h"
33+#include "va_nvctrl.h"
3234 #include <stdio.h>
3335 #include <stdarg.h>
3436 #include <string.h>
37+#include <unistd.h>
3538 #include <sys/types.h>
3639 #include <sys/stat.h>
3740 #include <fcntl.h>
@@ -91,6 +94,7 @@ static void va_DisplayContextDestroy (
9194 }
9295 ctx = &((*ctx)->pNext);
9396 }
97+ free(pDisplayContext->pDriverContext->dri_state);
9498 free(pDisplayContext->pDriverContext);
9599 free(pDisplayContext);
96100 }
@@ -102,63 +106,46 @@ static VAStatus va_DRI2GetDriverName (
102106 )
103107 {
104108 VADriverContextP ctx = pDisplayContext->pDriverContext;
105- VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
106- int eventBase, errorBase;
107- char *device_name;
108- int driver_major;
109- int driver_minor;
110- int driver_patch;
111- Bool result = True;
112109
113- if (!VA_DRI2QueryExtension(ctx->x11_dpy, &eventBase, &errorBase)) {
114- va_infoMessage("DRI2 extension isn't present\n");
110+ if (!isDRI2Connected(ctx, driver_name))
115111 return VA_STATUS_ERROR_UNKNOWN;
116- }
117112
118- if (!VA_DRI2QueryVersion(ctx->x11_dpy, &driver_major, &driver_minor)) {
119- va_errorMessage("VA_DRI2QueryVersion failed\n");
120- return VA_STATUS_ERROR_UNKNOWN;
121- }
122-
123- if (!VA_DRI2Connect(ctx->x11_dpy, RootWindow(ctx->x11_dpy, ctx->x11_screen),
124- driver_name, &device_name)) {
125- va_infoMessage("DRI2 isn't enabled, fallback to DRI1\n");
113+ return VA_STATUS_SUCCESS;
114+}
115+
116+static VAStatus va_DRIGetDriverName (
117+ VADisplayContextP pDisplayContext,
118+ char **driver_name
119+)
120+{
121+ VADriverContextP ctx = pDisplayContext->pDriverContext;
122+
123+ if (!isDRI1Connected(ctx, driver_name))
126124 return VA_STATUS_ERROR_UNKNOWN;
127- }
128125
129- va_infoMessage("VA_DRI2Connect: %d.%d.%d %s (screen %d)\n",
130- driver_major, driver_minor, driver_patch, *driver_name, ctx->x11_screen);
131- ctx->dri2 = 1;
132-
133126 return VA_STATUS_SUCCESS;
134127 }
135128
136-static VAStatus va_DRIGetDriverName (
129+static VAStatus va_NVCTRL_GetDriverName (
137130 VADisplayContextP pDisplayContext,
138131 char **driver_name
139132 )
140133 {
141134 VADriverContextP ctx = pDisplayContext->pDriverContext;
142135 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
143- int eventBase, errorBase;
144136 int direct_capable;
145137 int driver_major;
146138 int driver_minor;
147139 int driver_patch;
148140 Bool result = True;
149- char *x_driver_name = NULL;
141+ char *nvidia_driver_name = NULL;
150142
151- if (!VA_DRIQueryExtension(ctx->x11_dpy, &eventBase, &errorBase)) {
152- va_errorMessage("VA_DRIQueryExtension failed\n");
153- return VA_STATUS_ERROR_UNKNOWN;
154- }
155-
156143 if (result)
157144 {
158- result = VA_DRIQueryDirectRenderingCapable(ctx->x11_dpy, ctx->x11_screen, &direct_capable);
145+ result = VA_NVCTRLQueryDirectRenderingCapable(ctx->x11_dpy, ctx->x11_screen, &direct_capable);
159146 if (!result)
160147 {
161- va_errorMessage("VA_DRIQueryDirectRenderingCapable failed\n");
148+ va_errorMessage("VA_NVCTRLQueryDirectRenderingCapable failed\n");
162149 }
163150 }
164151 if (result)
@@ -166,29 +153,27 @@ static VAStatus va_DRIGetDriverName (
166153 result = direct_capable;
167154 if (!result)
168155 {
169- va_errorMessage("VA_DRIQueryDirectRenderingCapable returned false\n");
156+ va_errorMessage("VA_NVCTRLQueryDirectRenderingCapable returned false\n");
170157 }
171158 }
172159 if (result)
173160 {
174- result = VA_DRIGetClientDriverName(ctx->x11_dpy, ctx->x11_screen, &driver_major, &driver_minor,
175- &driver_patch, &x_driver_name);
161+ result = VA_NVCTRLGetClientDriverName(ctx->x11_dpy, ctx->x11_screen, &driver_major, &driver_minor,
162+ &driver_patch, &nvidia_driver_name);
176163 if (!result)
177164 {
178- va_errorMessage("VA_DRIGetClientDriverName returned false\n");
165+ va_errorMessage("VA_NVCTRLGetClientDriverName returned false\n");
179166 }
180167 }
181168 if (result)
182169 {
183170 vaStatus = VA_STATUS_SUCCESS;
184- va_infoMessage("VA_DRIGetClientDriverName: %d.%d.%d %s (screen %d)\n",
185- driver_major, driver_minor, driver_patch, x_driver_name, ctx->x11_screen);
186- if (driver_name)
187- *driver_name = strdup(x_driver_name);
171+ va_infoMessage("va_NVCTRL_GetDriverName: %d.%d.%d %s (screen %d)\n",
172+ driver_major, driver_minor, driver_patch,
173+ nvidia_driver_name, ctx->x11_screen);
174+ if (driver_name)
175+ *driver_name = nvidia_driver_name;
188176 }
189- if (x_driver_name)
190- XFree(x_driver_name);
191-
192177 return vaStatus;
193178 }
194179
@@ -197,37 +182,26 @@ static VAStatus va_DisplayContextGetDriverName (
197182 char **driver_name
198183 )
199184 {
200- VADriverContextP ctx = pDisplayContext->pDriverContext;
201- VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
202- int direct_capable;
203- int driver_major;
204- int driver_minor;
205- int driver_patch;
206- Bool result = True;
207- char *x_driver_name = NULL;
185+ VAStatus vaStatus;
186+ char *driver_name_env;
208187
209188 if (driver_name)
210189 *driver_name = NULL;
211-
212- vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
213- if (vaStatus != VA_STATUS_SUCCESS)
214- vaStatus = va_DRIGetDriverName(pDisplayContext, driver_name);
215190
216- if ((vaStatus == VA_STATUS_SUCCESS)
191+ if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL
217192 && geteuid() == getuid())
218193 {
219194 /* don't allow setuid apps to use LIBVA_DRIVER_NAME */
220- if (getenv("LIBVA_DRIVER_NAME"))
221- {
222- /* For easier debugging */
223- if (*driver_name)
224- XFree(*driver_name);
225-
226- *driver_name = strdup(getenv("LIBVA_DRIVER_NAME"));
227- return VA_STATUS_SUCCESS;
228- }
195+ *driver_name = strdup(driver_name_env);
196+ return VA_STATUS_SUCCESS;
229197 }
230-
198+
199+ vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
200+ if (vaStatus != VA_STATUS_SUCCESS)
201+ vaStatus = va_DRIGetDriverName(pDisplayContext, driver_name);
202+ if (vaStatus != VA_STATUS_SUCCESS)
203+ vaStatus = va_NVCTRL_GetDriverName(pDisplayContext, driver_name);
204+
231205 return vaStatus;
232206 }
233207
@@ -278,11 +252,12 @@ VADisplay vaGetDisplay (
278252 {
279253 /* create new entry */
280254 VADriverContextP pDriverContext;
255+ struct dri_state *dri_state;
281256 pDisplayContext = calloc(1, sizeof(*pDisplayContext));
282257 pDriverContext = calloc(1, sizeof(*pDriverContext));
283- if (pDisplayContext && pDriverContext)
258+ dri_state = calloc(1, sizeof(*dri_state));
259+ if (pDisplayContext && pDriverContext && dri_state)
284260 {
285- pDriverContext->old_pNext = (void *)(unsigned long)0xdeadbeef;
286261 pDriverContext->x11_dpy = native_dpy;
287262 pDisplayContext->pNext = pDisplayContexts;
288263 pDisplayContext->pDriverContext = pDriverContext;
@@ -290,7 +265,7 @@ VADisplay vaGetDisplay (
290265 pDisplayContext->vaDestroy = va_DisplayContextDestroy;
291266 pDisplayContext->vaGetDriverName = va_DisplayContextGetDriverName;
292267 pDisplayContexts = pDisplayContext;
293- pDriverContext->dri_state = calloc(1, sizeof(struct dri_state));
268+ pDriverContext->dri_state = dri_state;
294269 dpy = (VADisplay)pDisplayContext;
295270 }
296271 else
@@ -299,6 +274,8 @@ VADisplay vaGetDisplay (
299274 free(pDisplayContext);
300275 if (pDriverContext)
301276 free(pDriverContext);
277+ if (dri_state)
278+ free(dri_state);
302279 }
303280 }
304281
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -31,9 +31,10 @@ AM_CFLAGS = -I$(top_srcdir)/../../include/external/ -I$(top_srcdir)/src -I$(top_
3131
3232 TESTS = $(check_PROGRAMS)
3333
34-TEST_LIBS = ../src/libva.la
34+TEST_LIBS = $(top_srcdir)/src/$(libvabackendlib)
3535
36-vainfo_LDADD = ../src/libva.la
36+vainfo_LDADD = $(top_srcdir)/src/$(libvabackendlib)
37+vainfo_DEPENDENCIES = $(top_srcdir)/src/$(libvabackendlib)
3738 vainfo_SOURCES = vainfo.c
3839
3940 test_01_LDADD = $(TEST_LIBS)
--- a/test/test_common.c
+++ b/test/test_common.c
@@ -63,7 +63,7 @@ void status(const char *msg, ...)
6363
6464 int main(int argc, const char* argv[])
6565 {
66- const char *name = rindex(argv[0], '/');
66+ const char *name = strrchr(argv[0], '/');
6767 if (name)
6868 name++;
6969 else