2 * test_output - Test KMS/DRI output
4 * Copyright (c) 2011 David Herrmann <dh.herrmann@googlemail.com>
5 * Copyright (c) 2011 University of Tuebingen
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Test KMS/DRI output subsystem
29 * This is an example how to use the output subsystem. Invoked without
30 * arguments it prints a list of all connected outputs and their modes.
31 * If you pass numbers as arguments, it will enable these outputs and show an
32 * image on the given monitors for 5 seconds.
34 * This lists all outputs:
37 * This would show a test screen on output 0 and 4:
39 * The test screen is a colored quad with 4 different colors in each corner.
57 float d_vert[] = { -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1 };
58 float d_col[] = { 1, 1, 0, 1,
65 static void sig_term(int signum)
69 static int set_outputs(struct uterm_video *video, int num, char **list)
71 struct uterm_display *iter;
73 struct gl_shader *shader;
74 struct uterm_screen *screen;
76 ret = gl_shader_new(&shader);
78 log_err("Cannot create shader: %d", ret);
83 iter = uterm_video_get_displays(video);
84 for ( ; iter; iter = uterm_display_next(iter)) {
85 for (i = 0; i < num; ++i) {
92 log_notice("Ignoring display %d", j);
94 log_notice("Activating display %d %p...", j, iter);
95 ret = uterm_display_activate(iter, NULL);
97 log_err("Cannot activate display %d: %d", j,
100 log_notice("Successfully activated display %d",
103 ret = uterm_display_set_dpms(iter, UTERM_DPMS_ON);
105 log_err("Cannot set DPMS to ON: %d", ret);
111 iter = uterm_video_get_displays(video);
112 for ( ; iter; iter = uterm_display_next(iter)) {
113 if (uterm_display_get_state(iter) != UTERM_DISPLAY_ACTIVE)
116 ret = uterm_screen_new_single(&screen, iter);
118 log_err("Cannot create temp-screen object: %d", ret);
122 ret = uterm_screen_use(screen);
124 log_err("Cannot use screen: %d", ret);
125 uterm_screen_unref(screen);
129 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
130 glClear(GL_COLOR_BUFFER_BIT);
132 uterm_screen_width(screen),
133 uterm_screen_height(screen));
135 gl_shader_draw_def(shader, d_vert, d_col, 6);
137 log_err("GL error occurred");
139 ret = uterm_screen_swap(screen);
141 log_err("Cannot swap screen: %d", ret);
142 uterm_screen_unref(screen);
146 log_notice("Successfully set screen on display %p", iter);
147 uterm_screen_unref(screen);
150 log_notice("Waiting 5 seconds...");
152 log_notice("Exiting...");
154 gl_shader_unref(shader);
159 static int list_outputs(struct uterm_video *video)
161 struct uterm_display *iter;
162 struct uterm_mode *cur, *mode;
165 log_notice("List of Outputs:");
168 iter = uterm_video_get_displays(video);
169 for ( ; iter; iter = uterm_display_next(iter)) {
170 cur = uterm_display_get_current(iter);
172 log_notice("Output %d:", i++);
173 log_notice(" active: %d", uterm_display_get_state(iter));
174 log_notice(" has current: %s", cur ? "yes" : "no");
176 mode = uterm_display_get_modes(iter);
177 for ( ; mode; mode = uterm_mode_next(mode)) {
178 log_notice(" Mode '%s':", uterm_mode_get_name(mode));
179 log_notice(" x: %u", uterm_mode_get_width(mode));
180 log_notice(" y: %u", uterm_mode_get_height(mode));
184 log_notice("End of Output list");
189 int main(int argc, char **argv)
191 struct uterm_video *video;
193 struct ev_eloop *eloop;
194 struct sigaction sig;
196 log_print_init("test_output");
197 log_set_config(&LOG_CONFIG_INFO(1, 1));
199 ret = ev_eloop_new(&eloop);
203 memset(&sig, 0, sizeof(sig));
204 sig.sa_handler = sig_term;
205 sigaction(SIGTERM, &sig, NULL);
206 sigaction(SIGINT, &sig, NULL);
208 log_notice("Creating video object...");
209 ret = uterm_video_new(&video, UTERM_VIDEO_DRM, eloop);
211 log_err("Cannot create video object: %d", ret);
215 log_notice("Wakeing up video object...");
216 ret = uterm_video_wake_up(video);
218 log_err("Cannot wakeup video object: %d", ret);
223 ret = list_outputs(video);
225 log_err("Cannot list outputs: %d", ret);
229 ret = set_outputs(video, argc - 1, &argv[1]);
231 log_err("Cannot set outputs: %d", ret);
237 uterm_video_unref(video);