• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2012 Intel Corporation. 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 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stddef.h>
31 #include <string.h>
32 #include <va/va.h>
33 #include "va_display.h"
34 
35 extern const VADisplayHooks va_display_hooks_android;
36 extern const VADisplayHooks va_display_hooks_wayland;
37 extern const VADisplayHooks va_display_hooks_x11;
38 extern const VADisplayHooks va_display_hooks_drm;
39 extern const VADisplayHooks va_display_hooks_win32;
40 
41 static const VADisplayHooks *g_display_hooks;
42 static const VADisplayHooks *g_display_hooks_available[] = {
43 #ifdef HAVE_VA_WIN32
44     &va_display_hooks_win32,
45 #endif
46 #ifdef HAVE_VA_WAYLAND
47     &va_display_hooks_wayland,
48 #endif
49 #ifdef HAVE_VA_X11
50     &va_display_hooks_x11,
51 #endif
52 #ifdef HAVE_VA_DRM
53     &va_display_hooks_drm,
54 #endif
55     NULL};
56 
57 static const char *g_display_name;
58 const char *g_device_name;
59 
60 static const char *
get_display_name(int argc,char * argv[])61 get_display_name(int argc, char *argv[])
62 {
63     const char *display_name = NULL;
64     int i;
65 
66     for (i = 1; i < argc; i++) {
67         if (strcmp(argv[i], "--display") != 0)
68             continue;
69         argv[i] = NULL;
70 
71         if (++i < argc) {
72             display_name = argv[i];
73             argv[i] = NULL;
74         }
75     }
76     return display_name;
77 }
78 
79 static const char *
get_device_name(int argc,char * argv[])80 get_device_name(int argc, char *argv[])
81 {
82     const char *device_name = NULL;
83     int i;
84 
85     for (i = 1; i < argc; i++) {
86         if (argv[i] && (strcmp(argv[i], "--device") != 0))
87             continue;
88         argv[i] = NULL;
89 
90         if (++i < argc) {
91             device_name = argv[i];
92             argv[i] = NULL;
93         }
94     }
95     return device_name;
96 }
97 
98 static void
print_display_names(void)99 print_display_names(void)
100 {
101     const VADisplayHooks **h;
102 
103     printf("Available displays:\n");
104     for (h = g_display_hooks_available; *h != NULL; h++)
105         printf("  %s\n", (*h)->name);
106 }
107 
108 static void
sanitize_args(int * argc,char * argv[])109 sanitize_args(int *argc, char *argv[])
110 {
111     char **out_args = argv;
112     int i, n = *argc;
113 
114     for (i = 0; i < n; i++) {
115         if (argv[i])
116             *out_args++ = argv[i];
117     }
118     *out_args = NULL;
119     *argc = out_args - argv;
120 }
121 
122 void
va_init_display_args(int * argc,char * argv[])123 va_init_display_args(int *argc, char *argv[])
124 {
125     const char *display_name;
126 
127     display_name = get_display_name(*argc, argv);
128     if (display_name && strcmp(display_name, "help") == 0) {
129         print_display_names();
130         exit(0);
131     }
132     g_display_name = display_name;
133 
134     if (g_display_name &&
135         ((strcmp(g_display_name, "drm") == 0)
136         || (strcmp(g_display_name, "win32") == 0)))
137         g_device_name = get_device_name(*argc, argv);
138 
139     sanitize_args(argc, argv);
140 }
141 
142 VADisplay
va_open_display(void)143 va_open_display(void)
144 {
145     VADisplay va_dpy = NULL;
146     unsigned int i;
147 
148     for (i = 0; !va_dpy && g_display_hooks_available[i]; i++) {
149         g_display_hooks = g_display_hooks_available[i];
150         if (g_display_name &&
151             strcmp(g_display_name, g_display_hooks->name) != 0)
152             continue;
153         if (!g_display_hooks->open_display)
154             continue;
155         printf("Trying display: %s\n", g_display_hooks->name);
156         va_dpy = g_display_hooks->open_display();
157     }
158 
159     if (!va_dpy)  {
160         fprintf(stderr, "error: failed to initialize display");
161         if (g_display_name)
162             fprintf(stderr, " '%s'", g_display_name);
163         fprintf(stderr, "\n");
164         exit(1);
165     }
166     return va_dpy;
167 }
168 
169 void
va_close_display(VADisplay va_dpy)170 va_close_display(VADisplay va_dpy)
171 {
172     if (!va_dpy)
173         return;
174 
175     if (g_display_hooks && g_display_hooks->close_display)
176         g_display_hooks->close_display(va_dpy);
177 }
178 
179 VAStatus
va_put_surface(VADisplay va_dpy,VASurfaceID surface,const VARectangle * src_rect,const VARectangle * dst_rect)180 va_put_surface(
181     VADisplay          va_dpy,
182     VASurfaceID        surface,
183     const VARectangle *src_rect,
184     const VARectangle *dst_rect
185 )
186 {
187     if (!va_dpy)
188         return VA_STATUS_ERROR_INVALID_DISPLAY;
189 
190     if (g_display_hooks && g_display_hooks->put_surface)
191         return g_display_hooks->put_surface(va_dpy, surface, src_rect, dst_rect);
192     return VA_STATUS_ERROR_UNIMPLEMENTED;
193 }
194 
195 void
va_print_display_options(FILE * stream)196 va_print_display_options(FILE *stream)
197 {
198     fprintf(stream, "Display options:\n");
199     fprintf(stream, "\t--display display | help         Show information for the specified display, or the available display list \n");
200     fprintf(stream, "\t--device device                  Set device name, only available under drm and win32 displays\n");
201 }
202