2 * test_output - Test KMS/DRI output
4 * Copyright (c) 2011-2012 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
40 static void print_help();
52 #include "test_include.h"
55 static struct ev_eloop *eloop;
62 static int blit_outputs(struct uterm_video *video)
64 struct uterm_display *iter;
66 struct uterm_screen *screen;
69 iter = uterm_video_get_displays(video);
70 for ( ; iter; iter = uterm_display_next(iter)) {
71 log_notice("Activating display %d %p...", j, iter);
72 ret = uterm_display_activate(iter, NULL);
74 log_err("Cannot activate display %d: %d", j, ret);
76 log_notice("Successfully activated display %d", j);
78 ret = uterm_display_set_dpms(iter, UTERM_DPMS_ON);
80 log_err("Cannot set DPMS to ON: %d", ret);
85 iter = uterm_video_get_displays(video);
86 for ( ; iter; iter = uterm_display_next(iter)) {
87 if (uterm_display_get_state(iter) != UTERM_DISPLAY_ACTIVE)
90 ret = uterm_screen_new_single(&screen, iter);
92 log_err("Cannot create temp-screen object: %d", ret);
96 ret = uterm_screen_fill(screen, 0xff, 0xff, 0xff, 0, 0,
97 uterm_screen_width(screen),
98 uterm_screen_height(screen));
100 log_err("cannot fill framebuffer");
101 uterm_screen_unref(screen);
105 ret = uterm_screen_swap(screen);
107 log_err("Cannot swap screen: %d", ret);
108 uterm_screen_unref(screen);
112 log_notice("Successfully set screen on display %p", iter);
113 uterm_screen_unref(screen);
116 log_notice("Waiting 5 seconds...");
117 ev_eloop_run(eloop, 5000);
118 log_notice("Exiting...");
123 static int list_outputs(struct uterm_video *video)
125 struct uterm_display *iter;
126 struct uterm_mode *cur, *mode;
129 log_notice("List of Outputs:");
132 iter = uterm_video_get_displays(video);
133 for ( ; iter; iter = uterm_display_next(iter)) {
134 cur = uterm_display_get_current(iter);
136 log_notice("Output %d:", i++);
137 log_notice(" active: %d", uterm_display_get_state(iter));
138 log_notice(" has current: %s", cur ? "yes" : "no");
140 mode = uterm_display_get_modes(iter);
141 for ( ; mode; mode = uterm_mode_next(mode)) {
142 log_notice(" Mode '%s':", uterm_mode_get_name(mode));
143 log_notice(" x: %u", uterm_mode_get_width(mode));
144 log_notice(" y: %u", uterm_mode_get_height(mode));
148 log_notice("End of Output list");
153 static void print_help()
156 * Usage/Help information
157 * This should be scaled to a maximum of 80 characters per line:
160 * | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 |
161 * "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
162 * 80 char line starting with tab:
163 * |10| 20 | 30 | 40 | 50 | 60 | 70 | 80 |
164 * "\t901234567890123456789012345678901234567890123456789012345678901234567890\n"
169 "\t%1$s -h [options]\n"
171 "You can prefix boolean options with \"no-\" to negate it. If an argument is\n"
172 "given multiple times, only the last argument matters if not otherwise stated.\n"
178 "\t --fbdev [off] Use fbdev instead of DRM\n"
179 "\t --test [off] Try displaying content instead of listing devices\n",
183 * | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 |
184 * "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
185 * 80 char line starting with tab:
186 * |10| 20 | 30 | 40 | 50 | 60 | 70 | 80 |
187 * "\t901234567890123456789012345678901234567890123456789012345678901234567890\n"
191 struct conf_option options[] = {
193 CONF_OPTION_BOOL(0, "fbdev", NULL, &output_conf.fbdev, false),
194 CONF_OPTION_BOOL(0, "test", NULL, &output_conf.test, false),
197 int main(int argc, char **argv)
199 struct uterm_video *video;
205 onum = sizeof(options) / sizeof(*options);
206 ret = test_prepare(options, onum, argc, argv, &eloop);
210 if (output_conf.fbdev) {
211 mode = UTERM_VIDEO_FBDEV;
214 mode = UTERM_VIDEO_DRM;
215 node = "/dev/dri/card0";
218 log_notice("Creating video object using %s...", node);
220 ret = uterm_video_new(&video, eloop, mode, node);
222 if (mode == UTERM_VIDEO_DRM) {
223 log_notice("cannot create drm device; trying dumb drm mode");
224 ret = uterm_video_new(&video, eloop,
225 UTERM_VIDEO_DUMB, node);
233 log_notice("Wakeing up video object...");
234 ret = uterm_video_wake_up(video);
238 if (!output_conf.test) {
239 ret = list_outputs(video);
241 log_err("Cannot list outputs: %d", ret);
245 ret = blit_outputs(video);
247 log_err("Cannot set outputs: %d", ret);
253 uterm_video_unref(video);
255 test_exit(options, onum, eloop);
257 if (ret != -ECANCELED)