commit 38fdffc0a6d22adb6c3d5dd456f28459ed2e9132
Author: Gwenole Beauchesne <gbeauchesne@splitted-desktop.com>
Date:   Wed Jun 24 11:40:56 2009 +0000

    Add compatibility layer with original VA-API 0.29 to 0.31.

diff --git a/va/Makefile.am b/va/Makefile.am
index 3ec4d82..d590966 100644
--- a/va/Makefile.am
+++ b/va/Makefile.am
@@ -27,7 +27,7 @@ INCLUDES = \
 LDADD = \
 	$(LIBVA_LT_LDFLAGS)
 
-libva_la_SOURCES = va.c va_trace.c va_crystalhd.c
+libva_la_SOURCES = va.c va_trace.c va_crystalhd.c va_compat.c
 libva_ladir = $(libdir)
 libva_la_LDFLAGS = $(LDADD) -no-undefined
 libva_la_LIBADD = $(LIBVA_LIBS) -ldl
@@ -88,4 +88,8 @@ DISTCLEANFILES = \
 
 EXTRA_DIST = \
 	va_version.h.in \
-	va_crystalhd.h
+	va_crystalhd.h \
+	va_compat.h \
+	va_compat_template.h
+
+va_compat.c: va_compat_template.h
diff --git a/va/va.c b/va/va.c
index 410abaf..9b68500 100644
--- a/va/va.c
+++ b/va/va.c
@@ -28,6 +28,7 @@
 #include "va.h"
 #include "va_backend.h"
 #include "va_crystalhd.h"
+#include "va_compat.h"
 
 #include <assert.h>
 #include <stdarg.h>
@@ -44,6 +45,8 @@
 #endif
 
 #define DRIVER_INIT_FUNC	"__vaDriverInit_0_31"
+#define DRIVER_INIT_FUNC_0_29	"__vaDriverInit_0_29"
+#define DRIVER_INIT_FUNC_0_30	"__vaDriverInit_0_30"
 
 #define DRIVER_EXTENSION	"_drv_video.so"
 
@@ -174,13 +177,24 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
         {
             VADriverInit init_func;
             char driver_init_func_sds[32];
+            int compat_version = 0;
             /* First, try SDS extensions (VDPAU and XvBA backends) */
             sprintf(driver_init_func_sds, "%s_%d_sds%d",
                     DRIVER_INIT_FUNC, VA_MICRO_VERSION, VA_SDS_VERSION);
             init_func = (VADriverInit) dlsym(handle, driver_init_func_sds);
             if (!init_func)
             {
+                /* Otherwise, we need the compatibility layer for some buffers */
                 init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC);
+                compat_version = VA_MINOR_VERSION;
+                if (!init_func) {
+                    init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC_0_29);
+                    compat_version = 29;
+                }
+                if (!init_func) {
+                    init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC_0_30);
+                    compat_version = 30;
+                }
             }
             if (!init_func)
             {
@@ -189,7 +203,36 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
             }
             else
             {
-                vaStatus = (*init_func)(ctx);
+                struct VADriverContext_0_29 ctx_0_29;
+                struct VADriverContext_0_30 ctx_0_30;
+                void *compat_ctx = NULL;
+
+                switch (compat_version) {
+                case 29:
+                    compat_ctx           = &ctx_0_29;
+                    ctx_0_29.pDriverData = NULL;
+                    ctx_0_29.x11_dpy     = ctx->native_dpy;
+                    ctx_0_29.x11_screen  = ctx->x11_screen;
+                    break;
+                case 30:
+                    compat_ctx           = &ctx_0_30;
+                    ctx_0_30.pDriverData = NULL;
+                    ctx_0_30.x11_dpy     = ctx->native_dpy;
+                    ctx_0_30.x11_screen  = ctx->x11_screen;
+                    break;
+                case VA_MINOR_VERSION:
+                    compat_ctx           = ctx;
+                    break;
+                default:
+                    ASSERT(compat_version == 0);
+                    vaStatus = VA_STATUS_ERROR_UNKNOWN;
+                    break;
+                }
+
+                vaStatus = (*init_func)(compat_ctx ? compat_ctx : ctx);
+
+                if (VA_STATUS_SUCCESS == vaStatus)
+                    vaStatus = va_compat_init(dpy, compat_version, compat_ctx);
 
                 if (VA_STATUS_SUCCESS == vaStatus)
                 {
@@ -410,6 +453,8 @@ VAStatus vaTerminate (
       old_ctx->handle = NULL;
   }
 
+  va_compat_fini(dpy);
+
   if (VA_STATUS_SUCCESS == vaStatus)
       pDisplayContext->vaDestroy(pDisplayContext);
 
diff --git a/va/va_backend.h b/va/va_backend.h
index 62ac970..dc06873 100644
--- a/va/va_backend.h
+++ b/va/va_backend.h
@@ -398,6 +398,7 @@ struct VADriverContext
     
     void *dri_state;
     void *glx;				/* opaque for GLX code */
+    void *compat;			/* opaque for compat code */
 };
 
 #define VA_DISPLAY_MAGIC 0x56414430 /* VAD0 */
diff --git a/va/va_compat.c b/va/va_compat.c
new file mode 100644
index 0000000..6895cf2
diff --git a/va/va_compat.h b/va/va_compat.h
new file mode 100644
index 0000000..2c9d801
diff --git a/va/va_compat_template.h b/va/va_compat_template.h
new file mode 100644
index 0000000..ee41aee
