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 any argument it will enable all outputs for 5seconds.
33 * This lists all outputs:
36 * This would show a test screen:
37 * $ ./test_output something
38 * The test screen is a colored quad with 4 different colors in each corner.
53 #include "test_include.h"
56 static struct ev_eloop *eloop;
59 float d_vert[] = { -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1 };
60 float d_col[] = { 1, 1, 0, 1,
67 static int set_outputs(struct uterm_video *video)
69 struct uterm_display *iter;
71 struct gl_shader *shader;
72 struct uterm_screen *screen;
74 ret = gl_shader_new(&shader);
76 log_err("Cannot create shader: %d", ret);
81 iter = uterm_video_get_displays(video);
82 for ( ; iter; iter = uterm_display_next(iter)) {
83 log_notice("Activating display %d %p...", j, iter);
84 ret = uterm_display_activate(iter, NULL);
86 log_err("Cannot activate display %d: %d", j, ret);
88 log_notice("Successfully activated display %d", j);
90 ret = uterm_display_set_dpms(iter, UTERM_DPMS_ON);
92 log_err("Cannot set DPMS to ON: %d", ret);
97 iter = uterm_video_get_displays(video);
98 for ( ; iter; iter = uterm_display_next(iter)) {
99 if (uterm_display_get_state(iter) != UTERM_DISPLAY_ACTIVE)
102 ret = uterm_screen_new_single(&screen, iter);
104 log_err("Cannot create temp-screen object: %d", ret);
108 ret = uterm_screen_use(screen);
110 log_err("Cannot use screen: %d", ret);
111 uterm_screen_unref(screen);
115 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
116 glClear(GL_COLOR_BUFFER_BIT);
118 uterm_screen_width(screen),
119 uterm_screen_height(screen));
121 gl_shader_draw_def(shader, d_vert, d_col, 6);
123 log_err("GL error occurred");
125 ret = uterm_screen_swap(screen);
127 log_err("Cannot swap screen: %d", ret);
128 uterm_screen_unref(screen);
132 log_notice("Successfully set screen on display %p", iter);
133 uterm_screen_unref(screen);
136 log_notice("Waiting 5 seconds...");
137 ev_eloop_run(eloop, 5000);
138 log_notice("Exiting...");
140 gl_shader_unref(shader);
145 static int list_outputs(struct uterm_video *video)
147 struct uterm_display *iter;
148 struct uterm_mode *cur, *mode;
151 log_notice("List of Outputs:");
154 iter = uterm_video_get_displays(video);
155 for ( ; iter; iter = uterm_display_next(iter)) {
156 cur = uterm_display_get_current(iter);
158 log_notice("Output %d:", i++);
159 log_notice(" active: %d", uterm_display_get_state(iter));
160 log_notice(" has current: %s", cur ? "yes" : "no");
162 mode = uterm_display_get_modes(iter);
163 for ( ; mode; mode = uterm_mode_next(mode)) {
164 log_notice(" Mode '%s':", uterm_mode_get_name(mode));
165 log_notice(" x: %u", uterm_mode_get_width(mode));
166 log_notice(" y: %u", uterm_mode_get_height(mode));
170 log_notice("End of Output list");
175 int main(int argc, char **argv)
177 struct uterm_video *video;
180 ret = test_prepare(argc, argv, &eloop);
184 log_notice("Creating video object...");
185 ret = uterm_video_new(&video, eloop, UTERM_VIDEO_DRM, "/dev/dri/card0");
189 ret = uterm_video_use(video);
193 log_notice("Wakeing up video object...");
194 ret = uterm_video_wake_up(video);
199 ret = list_outputs(video);
201 log_err("Cannot list outputs: %d", ret);
205 ret = set_outputs(video);
207 log_err("Cannot set outputs: %d", ret);
213 uterm_video_unref(video);