hardware/intel/libva
Revision | 7e31f1283285258198bd1b276b6195badc3c7e4e (tree) |
---|---|
Zeit | 2012-09-26 18:40:50 |
Autor | Gwenole Beauchesne <gwenole.beauchesne@inte...> |
Commiter | Gwenole Beauchesne |
tests: allow selection of display.
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@intel.com>
@@ -25,7 +25,10 @@ | ||
25 | 25 | #ifdef HAVE_CONFIG_H |
26 | 26 | # include "config.h" |
27 | 27 | #endif |
28 | +#include <stdio.h> | |
29 | +#include <stdlib.h> | |
28 | 30 | #include <stddef.h> |
31 | +#include <string.h> | |
29 | 32 | #include <va/va.h> |
30 | 33 | #include "va_display.h" |
31 | 34 |
@@ -42,6 +45,66 @@ static const VADisplayHooks *g_display_hooks_available[] = { | ||
42 | 45 | NULL |
43 | 46 | }; |
44 | 47 | |
48 | +static const char *g_display_name; | |
49 | + | |
50 | +static const char * | |
51 | +get_display_name(int argc, char *argv[]) | |
52 | +{ | |
53 | + const char *display_name = NULL; | |
54 | + int i; | |
55 | + | |
56 | + for (i = 1; i < argc; i++) { | |
57 | + if (strcmp(argv[i], "--display") != 0) | |
58 | + continue; | |
59 | + argv[i] = NULL; | |
60 | + | |
61 | + if (++i < argc) { | |
62 | + display_name = argv[i]; | |
63 | + argv[i] = NULL; | |
64 | + } | |
65 | + } | |
66 | + return display_name; | |
67 | +} | |
68 | + | |
69 | +static void | |
70 | +print_display_names(void) | |
71 | +{ | |
72 | + const VADisplayHooks **h; | |
73 | + | |
74 | + printf("Available displays:\n"); | |
75 | + for (h = g_display_hooks_available; *h != NULL; h++) | |
76 | + printf(" %s\n", (*h)->name); | |
77 | +} | |
78 | + | |
79 | +static void | |
80 | +sanitize_args(int *argc, char *argv[]) | |
81 | +{ | |
82 | + char **out_args = argv; | |
83 | + int i, n = *argc; | |
84 | + | |
85 | + for (i = 0; i < n; i++) { | |
86 | + if (argv[i]) | |
87 | + *out_args++ = argv[i]; | |
88 | + } | |
89 | + *out_args = NULL; | |
90 | + *argc = out_args - argv; | |
91 | +} | |
92 | + | |
93 | +void | |
94 | +va_init_display_args(int *argc, char *argv[]) | |
95 | +{ | |
96 | + const char *display_name; | |
97 | + | |
98 | + display_name = get_display_name(*argc, argv); | |
99 | + if (display_name && strcmp(display_name, "help") == 0) { | |
100 | + print_display_names(); | |
101 | + exit(0); | |
102 | + } | |
103 | + g_display_name = display_name; | |
104 | + | |
105 | + sanitize_args(argc, argv); | |
106 | +} | |
107 | + | |
45 | 108 | VADisplay |
46 | 109 | va_open_display(void) |
47 | 110 | { |
@@ -50,10 +113,21 @@ va_open_display(void) | ||
50 | 113 | |
51 | 114 | for (i = 0; !va_dpy && g_display_hooks_available[i]; i++) { |
52 | 115 | g_display_hooks = g_display_hooks_available[i]; |
116 | + if (g_display_name && | |
117 | + strcmp(g_display_name, g_display_hooks->name) != 0) | |
118 | + continue; | |
53 | 119 | if (!g_display_hooks->open_display) |
54 | 120 | continue; |
55 | 121 | va_dpy = g_display_hooks->open_display(); |
56 | 122 | } |
123 | + | |
124 | + if (!va_dpy) { | |
125 | + fprintf(stderr, "error: failed to initialize display"); | |
126 | + if (g_display_name) | |
127 | + fprintf(stderr, " '%s'", g_display_name); | |
128 | + fprintf(stderr, "\n"); | |
129 | + abort(); | |
130 | + } | |
57 | 131 | return va_dpy; |
58 | 132 | } |
59 | 133 |
@@ -32,6 +32,7 @@ extern "C" { | ||
32 | 32 | #endif |
33 | 33 | |
34 | 34 | typedef struct { |
35 | + const char *name; | |
35 | 36 | VADisplay (*open_display) (void); |
36 | 37 | void (*close_display) (VADisplay va_dpy); |
37 | 38 | VAStatus (*put_surface) (VADisplay va_dpy, VASurfaceID surface, |
@@ -39,6 +40,9 @@ typedef struct { | ||
39 | 40 | const VARectangle *dst_rect); |
40 | 41 | } VADisplayHooks; |
41 | 42 | |
43 | +void | |
44 | +va_init_display_args(int *argc, char *argv[]); | |
45 | + | |
42 | 46 | VADisplay |
43 | 47 | va_open_display(void); |
44 | 48 |
@@ -85,6 +85,7 @@ va_put_surface_android( | ||
85 | 85 | |
86 | 86 | extern "C" |
87 | 87 | const VADisplayHooks va_display_hooks_android = { |
88 | + "android", | |
88 | 89 | va_open_display_android, |
89 | 90 | va_close_display_android, |
90 | 91 | va_put_surface_android |
@@ -132,6 +132,7 @@ va_put_surface_x11( | ||
132 | 132 | } |
133 | 133 | |
134 | 134 | const VADisplayHooks va_display_hooks_x11 = { |
135 | + "x11", | |
135 | 136 | va_open_display_x11, |
136 | 137 | va_close_display_x11, |
137 | 138 | va_put_surface_x11, |
@@ -37,6 +37,7 @@ | ||
37 | 37 | #include <stdlib.h> |
38 | 38 | #include <string.h> |
39 | 39 | #include <time.h> |
40 | +#include "va_display.h" | |
40 | 41 | |
41 | 42 | static void exitmessage(const char *message) __attribute__((noreturn)); |
42 | 43 | static void exitmessage(const char *message) |
@@ -114,6 +115,8 @@ int main(int argc, char *argv[]) | ||
114 | 115 | unsigned int duration; |
115 | 116 | int current_argument; |
116 | 117 | |
118 | + va_init_display_args(&argc, argv); | |
119 | + | |
117 | 120 | if (argc < 2) |
118 | 121 | usage(); |
119 | 122 |
@@ -150,6 +150,8 @@ int main(int argc,char **argv) | ||
150 | 150 | VAStatus va_status; |
151 | 151 | int putsurface=0; |
152 | 152 | |
153 | + va_init_display_args(&argc, argv); | |
154 | + | |
153 | 155 | if (argc > 1) |
154 | 156 | putsurface=1; |
155 | 157 |