Rev 5362 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5362 | serge | 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: |
||
5366 | serge | 11 | * |
5362 | serge | 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. |
||
5366 | serge | 15 | * |
5362 | serge | 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 | #include "sysdeps.h" |
||
26 | #include |
||
27 | #include |
||
28 | #include |
||
29 | #include |
||
30 | #include |
||
31 | #include "va_display.h" |
||
32 | |||
33 | extern const VADisplayHooks va_display_hooks_drm; |
||
34 | |||
35 | static const VADisplayHooks *g_display_hooks; |
||
36 | static const VADisplayHooks *g_display_hooks_available[] = { |
||
37 | &va_display_hooks_drm, |
||
38 | NULL |
||
39 | }; |
||
40 | |||
41 | static const char *g_display_name; |
||
42 | |||
43 | static const char * |
||
44 | get_display_name(int argc, char *argv[]) |
||
45 | { |
||
46 | const char *display_name = NULL; |
||
47 | int i; |
||
48 | |||
49 | for (i = 1; i < argc; i++) { |
||
50 | if (strcmp(argv[i], "--display") != 0) |
||
51 | continue; |
||
52 | argv[i] = NULL; |
||
53 | |||
54 | if (++i < argc) { |
||
55 | display_name = argv[i]; |
||
56 | argv[i] = NULL; |
||
57 | } |
||
58 | } |
||
59 | return display_name; |
||
60 | } |
||
61 | |||
62 | static void |
||
63 | print_display_names(void) |
||
64 | { |
||
65 | const VADisplayHooks **h; |
||
66 | |||
67 | printf("Available displays:\n"); |
||
68 | for (h = g_display_hooks_available; *h != NULL; h++) |
||
69 | printf(" %s\n", (*h)->name); |
||
70 | } |
||
71 | |||
72 | static void |
||
73 | sanitize_args(int *argc, char *argv[]) |
||
74 | { |
||
75 | char **out_args = argv; |
||
76 | int i, n = *argc; |
||
77 | |||
78 | for (i = 0; i < n; i++) { |
||
79 | if (argv[i]) |
||
80 | *out_args++ = argv[i]; |
||
81 | } |
||
82 | *out_args = NULL; |
||
83 | *argc = out_args - argv; |
||
84 | } |
||
85 | |||
86 | void |
||
87 | va_init_display_args(int *argc, char *argv[]) |
||
88 | { |
||
89 | const char *display_name; |
||
90 | |||
91 | display_name = get_display_name(*argc, argv); |
||
92 | if (display_name && strcmp(display_name, "help") == 0) { |
||
93 | print_display_names(); |
||
94 | exit(0); |
||
95 | } |
||
96 | g_display_name = display_name; |
||
97 | |||
98 | sanitize_args(argc, argv); |
||
99 | } |
||
100 | |||
101 | VADisplay |
||
102 | va_open_display(void) |
||
103 | { |
||
104 | VADisplay va_dpy = NULL; |
||
105 | unsigned int i; |
||
106 | |||
107 | for (i = 0; !va_dpy && g_display_hooks_available[i]; i++) { |
||
108 | g_display_hooks = g_display_hooks_available[i]; |
||
109 | if (g_display_name && |
||
110 | strcmp(g_display_name, g_display_hooks->name) != 0) |
||
111 | continue; |
||
112 | if (!g_display_hooks->open_display) |
||
113 | continue; |
||
114 | va_dpy = g_display_hooks->open_display(); |
||
115 | } |
||
116 | |||
117 | if (!va_dpy) { |
||
118 | fprintf(stderr, "error: failed to initialize display"); |
||
119 | if (g_display_name) |
||
120 | fprintf(stderr, " '%s'", g_display_name); |
||
121 | fprintf(stderr, "\n"); |
||
122 | abort(); |
||
123 | } |
||
124 | return va_dpy; |
||
125 | } |
||
126 | |||
127 | void |
||
128 | va_close_display(VADisplay va_dpy) |
||
129 | { |
||
130 | if (!va_dpy) |
||
131 | return; |
||
132 | |||
133 | if (g_display_hooks && g_display_hooks->close_display) |
||
134 | g_display_hooks->close_display(va_dpy); |
||
135 | } |
||
136 | |||
137 | VAStatus |
||
138 | va_put_surface( |
||
139 | VADisplay va_dpy, |
||
140 | VASurfaceID surface, |
||
141 | const VARectangle *src_rect, |
||
142 | const VARectangle *dst_rect |
||
143 | ) |
||
144 | { |
||
145 | if (!va_dpy) |
||
146 | return VA_STATUS_ERROR_INVALID_DISPLAY; |
||
147 | |||
148 | if (g_display_hooks && g_display_hooks->put_surface) |
||
149 | return g_display_hooks->put_surface(va_dpy, surface, src_rect, dst_rect); |
||
150 | return VA_STATUS_ERROR_UNIMPLEMENTED; |
||
151 | }>>> |