commit 1f9ee94ab4ac60459048bef5a2aa348cdf88c390
Author: Gwenole Beauchesne <gbeauchesne@splitted-desktop.com>
Date:   Tue Feb 23 09:11:22 2010 +0000

    Move LIBVA_DRIVER_NAME check in vaInitialize().

diff --git a/va/va.c b/va/va.c
index ada70ce..b5940e5 100644
--- a/va/va.c
+++ b/va/va.c
@@ -320,30 +320,42 @@ VAStatus vaInitialize (
     int *minor_version 	 /* out */
 )
 {
-  char *driver_name = NULL;
-  VAStatus vaStatus;
-  
-  CHECK_DISPLAY(dpy);
+    const char *driver_name_env = NULL;
+    char *driver_name = NULL;
+    VAStatus vaStatus;
 
-  va_debug_trace = (getenv("LIBVA_DEBUG_TRACE") != NULL);
+    CHECK_DISPLAY(dpy);
 
-  va_infoMessage("libva version %s\n", VA_VERSION_S);
+    va_debug_trace = (getenv("LIBVA_DEBUG_TRACE") != NULL);
 
-  vaStatus = va_getDriverName(dpy, &driver_name);
-  va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
-  
-  if (VA_STATUS_SUCCESS == vaStatus)
-  {
-      vaStatus = va_openDriver(dpy, driver_name);
-      va_infoMessage("va_openDriver() returns %d\n", vaStatus);
-      
-      *major_version = VA_MAJOR_VERSION;
-      *minor_version = VA_MINOR_VERSION;
-  }
+    va_infoMessage("libva version %s\n", VA_VERSION_S);
 
-  if (driver_name)
-      free(driver_name);
-  return vaStatus;
+    driver_name_env = getenv("LIBVA_DRIVER_NAME");
+    if (driver_name_env && geteuid() == getuid())
+    {
+        /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
+        driver_name = strdup(driver_name_env);
+        vaStatus = VA_STATUS_SUCCESS;
+        va_infoMessage("User requested driver '%s'\n", driver_name);
+    }
+    else
+    {
+        vaStatus = va_getDriverName(dpy, &driver_name);
+        va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
+    }
+
+    if (VA_STATUS_SUCCESS == vaStatus)
+    {
+        vaStatus = va_openDriver(dpy, driver_name);
+        va_infoMessage("va_openDriver() returns %d\n", vaStatus);
+
+        *major_version = VA_MAJOR_VERSION;
+        *minor_version = VA_MINOR_VERSION;
+    }
+
+    if (driver_name)
+        free(driver_name);
+    return vaStatus;
 }
 
 
diff --git a/va/x11/va_x11.c b/va/x11/va_x11.c
index 29e81c8..78e38de 100644
--- a/va/x11/va_x11.c
+++ b/va/x11/va_x11.c
@@ -136,19 +136,10 @@ static VAStatus va_DisplayContextGetDriverName (
 )
 {
     VAStatus vaStatus;
-    char *driver_name_env;
 
     if (driver_name)
 	*driver_name = NULL;
 
-    if ((driver_name_env = getenv("LIBVA_DRIVER_NAME")) != NULL
-        && geteuid() == getuid())
-    {
-        /* don't allow setuid apps to use LIBVA_DRIVER_NAME */
-        *driver_name = strdup(driver_name_env);
-        return VA_STATUS_SUCCESS;
-    }
-
     vaStatus = va_DRI2GetDriverName(pDisplayContext, driver_name);
     if (vaStatus != VA_STATUS_SUCCESS)
         vaStatus = va_DRIGetDriverName(pDisplayContext, driver_name);
