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.
54 #include "test_include.h"
57 static struct ev_eloop *eloop;
60 float d_vert[] = { -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1 };
61 float d_col[] = { 1, 1, 0, 1,
68 static int set_outputs(struct uterm_video *video, int num, char **list)
70 struct uterm_display *iter;
72 struct gl_shader *shader;
73 struct uterm_screen *screen;
75 ret = gl_shader_new(&shader);
77 log_err("Cannot create shader: %d", ret);
82 iter = uterm_video_get_displays(video);
83 for ( ; iter; iter = uterm_display_next(iter)) {
84 for (i = 0; i < num; ++i) {
91 log_notice("Ignoring display %d", j);
93 log_notice("Activating display %d %p...", j, iter);
94 ret = uterm_display_activate(iter, NULL);
96 log_err("Cannot activate display %d: %d", j,
99 log_notice("Successfully activated display %d",
102 ret = uterm_display_set_dpms(iter, UTERM_DPMS_ON);
104 log_err("Cannot set DPMS to ON: %d", ret);
110 iter = uterm_video_get_displays(video);
111 for ( ; iter; iter = uterm_display_next(iter)) {
112 if (uterm_display_get_state(iter) != UTERM_DISPLAY_ACTIVE)
115 ret = uterm_screen_new_single(&screen, iter);
117 log_err("Cannot create temp-screen object: %d", ret);
121 ret = uterm_screen_use(screen);
123 log_err("Cannot use screen: %d", ret);
124 uterm_screen_unref(screen);
128 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
129 glClear(GL_COLOR_BUFFER_BIT);
131 uterm_screen_width(screen),
132 uterm_screen_height(screen));
134 gl_shader_draw_def(shader, d_vert, d_col, 6);
136 log_err("GL error occurred");
138 ret = uterm_screen_swap(screen);
140 log_err("Cannot swap screen: %d", ret);
141 uterm_screen_unref(screen);
145 log_notice("Successfully set screen on display %p", iter);
146 uterm_screen_unref(screen);
149 log_notice("Waiting 5 seconds...");
150 ev_eloop_run(eloop, 5000);
151 log_notice("Exiting...");
153 gl_shader_unref(shader);
158 static int list_outputs(struct uterm_video *video)
160 struct uterm_display *iter;
161 struct uterm_mode *cur, *mode;
164 log_notice("List of Outputs:");
167 iter = uterm_video_get_displays(video);
168 for ( ; iter; iter = uterm_display_next(iter)) {
169 cur = uterm_display_get_current(iter);
171 log_notice("Output %d:", i++);
172 log_notice(" active: %d", uterm_display_get_state(iter));
173 log_notice(" has current: %s", cur ? "yes" : "no");
175 mode = uterm_display_get_modes(iter);
176 for ( ; mode; mode = uterm_mode_next(mode)) {
177 log_notice(" Mode '%s':", uterm_mode_get_name(mode));
178 log_notice(" x: %u", uterm_mode_get_width(mode));
179 log_notice(" y: %u", uterm_mode_get_height(mode));
183 log_notice("End of Output list");
188 int main(int argc, char **argv)
190 struct uterm_video *video;
193 ret = test_prepare(argc, argv, &eloop);
197 log_notice("Creating video object...");
198 ret = uterm_video_new(&video, UTERM_VIDEO_DRM, eloop);
202 log_notice("Wakeing up video object...");
203 ret = uterm_video_wake_up(video);
208 ret = list_outputs(video);
210 log_err("Cannot list outputs: %d", ret);
214 ret = set_outputs(video, argc - 1, &argv[1]);
216 log_err("Cannot set outputs: %d", ret);
222 uterm_video_unref(video);