[Libva] [PATCH 3/3] tests: allow selection of display.

Gwenole Beauchesne gb.devel at gmail.com
Tue Jul 10 09:16:05 PDT 2012


Make it possible to select display for test applications that need
to render the decoded surfaces. Usage: --display <name> args.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 test/common/va_display.c           |   56 ++++++++++++++++++++++++++++++++++++
 test/common/va_display.h           |    4 +++
 test/common/va_display_android.cpp |    1 +
 test/common/va_display_x11.c       |    1 +
 test/decode/loadjpeg.c             |    3 ++
 test/decode/mpeg2vldemo.cpp        |    2 ++
 6 files changed, 67 insertions(+)

diff --git a/test/common/va_display.c b/test/common/va_display.c
index 9b20591..47928fb 100644
--- a/test/common/va_display.c
+++ b/test/common/va_display.c
@@ -23,7 +23,10 @@
  */
 
 #include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
 #include <stddef.h>
+#include <string.h>
 #include <va/va.h>
 #include "va_display.h"
 
@@ -40,6 +43,48 @@ static const VADisplayHooks *g_display_hooks_available[] = {
     NULL
 };
 
+static const char *g_display_name;
+
+static const char *
+get_display_name(int argc, char *argv[])
+{
+    const char *display_name = NULL;
+    int i;
+
+    for (i = 1; i < argc; i++) {
+        if (strcmp(argv[i], "--display") != 0)
+            continue;
+        argv[i] = NULL;
+
+        if (++i < argc) {
+            display_name = argv[i];
+            argv[i] = NULL;
+        }
+    }
+    return display_name;
+}
+
+static void
+sanitize_args(int *argc, char *argv[])
+{
+    char **out_args = argv;
+    int i, n = *argc;
+
+    for (i = 0; i < n; i++) {
+        if (argv[i])
+            *out_args++ = argv[i];
+    }
+    *out_args = NULL;
+    *argc = out_args - argv;
+}
+
+void
+va_init_display_args(int *argc, char *argv[])
+{
+    g_display_name = get_display_name(*argc, argv);
+    sanitize_args(argc, argv);
+}
+
 VADisplay
 va_open_display(void)
 {
@@ -48,10 +93,21 @@ va_open_display(void)
 
     for (i = 0; !va_dpy && g_display_hooks_available[i]; i++) {
         g_display_hooks = g_display_hooks_available[i];
+        if (g_display_name &&
+            strcmp(g_display_name, g_display_hooks->name) != 0)
+            continue;
         if (!g_display_hooks->open_display)
             continue;
         va_dpy = g_display_hooks->open_display();
     }
+
+    if (!va_dpy)  {
+        fprintf(stderr, "error: failed to initialize display");
+        if (g_display_name)
+            fprintf(stderr, " '%s'", g_display_name);
+        fprintf(stderr, "\n");
+        abort();
+    }
     return va_dpy;
 }
 
diff --git a/test/common/va_display.h b/test/common/va_display.h
index 12992f5..4ed33e0 100644
--- a/test/common/va_display.h
+++ b/test/common/va_display.h
@@ -32,6 +32,7 @@ extern "C" {
 #endif
 
 typedef struct {
+    const char *name;
     VADisplay (*open_display)   (void);
     void      (*close_display)  (VADisplay va_dpy);
     VAStatus  (*put_surface)    (VADisplay va_dpy, VASurfaceID surface,
@@ -39,6 +40,9 @@ typedef struct {
                                  const VARectangle *dst_rect);
 } VADisplayHooks;
 
+void
+va_init_display_args(int *argc, char *argv[]);
+
 VADisplay
 va_open_display(void);
 
diff --git a/test/common/va_display_android.cpp b/test/common/va_display_android.cpp
index 33b510d..23630d7 100644
--- a/test/common/va_display_android.cpp
+++ b/test/common/va_display_android.cpp
@@ -84,6 +84,7 @@ va_put_surface_android(
 }
 
 const VADisplayHooks va_display_hooks_android = {
+    "android",
     va_open_display_android,
     va_close_display_android,
     va_put_surface_android
diff --git a/test/common/va_display_x11.c b/test/common/va_display_x11.c
index 6f22821..65ea60e 100644
--- a/test/common/va_display_x11.c
+++ b/test/common/va_display_x11.c
@@ -110,6 +110,7 @@ va_put_surface_x11(
 }
 
 const VADisplayHooks va_display_hooks_x11 = {
+    "x11",
     va_open_display_x11,
     va_close_display_x11,
     va_put_surface_x11,
diff --git a/test/decode/loadjpeg.c b/test/decode/loadjpeg.c
index 6258e28..7a9a235 100644
--- a/test/decode/loadjpeg.c
+++ b/test/decode/loadjpeg.c
@@ -37,6 +37,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
+#include "va_display.h"
 
 static void exitmessage(const char *message) __attribute__((noreturn));
 static void exitmessage(const char *message)
@@ -114,6 +115,8 @@ int main(int argc, char *argv[])
   unsigned int duration;
   int current_argument;
 
+  va_init_display_args(&argc, argv);
+
   if (argc < 2)
     usage();
 
diff --git a/test/decode/mpeg2vldemo.cpp b/test/decode/mpeg2vldemo.cpp
index fa7928d..715ea49 100644
--- a/test/decode/mpeg2vldemo.cpp
+++ b/test/decode/mpeg2vldemo.cpp
@@ -150,6 +150,8 @@ int main(int argc,char **argv)
     VAStatus va_status;
     int putsurface=0;
 
+    va_init_display_args(&argc, argv);
+
     if (argc > 1)
         putsurface=1;
     
-- 
1.7.9.5



More information about the Libva mailing list