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();
51 #include "uterm_video.h"
52 #include "test_include.h"
55 static struct ev_eloop *eloop;
63 static int blit_outputs(struct uterm_video *video)
65 struct uterm_display *iter;
67 struct uterm_mode *mode;
70 iter = uterm_video_get_displays(video);
71 for ( ; iter; iter = uterm_display_next(iter)) {
72 log_notice("Activating display %d %p...", j, iter);
73 ret = uterm_display_activate(iter, NULL);
75 log_err("Cannot activate display %d: %d", j, ret);
77 log_notice("Successfully activated display %d", j);
79 ret = uterm_display_set_dpms(iter, UTERM_DPMS_ON);
81 log_err("Cannot set DPMS to ON: %d", ret);
86 iter = uterm_video_get_displays(video);
87 for ( ; iter; iter = uterm_display_next(iter)) {
88 if (uterm_display_get_state(iter) != UTERM_DISPLAY_ACTIVE)
91 mode = uterm_display_get_current(iter);
92 ret = uterm_display_fill(iter, 0xff, 0xff, 0xff, 0, 0,
93 uterm_mode_get_width(mode),
94 uterm_mode_get_height(mode));
96 log_err("cannot fill framebuffer");
100 ret = uterm_display_swap(iter, true);
102 log_err("Cannot swap screen: %d", ret);
106 log_notice("Successfully set screen on display %p", iter);
109 log_notice("Waiting 5 seconds...");
110 ev_eloop_run(eloop, 5000);
111 log_notice("Exiting...");
116 static int list_outputs(struct uterm_video *video)
118 struct uterm_display *iter;
119 struct uterm_mode *cur, *mode;
122 log_notice("List of Outputs:");
125 iter = uterm_video_get_displays(video);
126 for ( ; iter; iter = uterm_display_next(iter)) {
127 cur = uterm_display_get_current(iter);
129 log_notice("Output %d:", i++);
130 log_notice(" active: %d", uterm_display_get_state(iter));
131 log_notice(" has current: %s", cur ? "yes" : "no");
133 mode = uterm_display_get_modes(iter);
134 for ( ; mode; mode = uterm_mode_next(mode)) {
135 log_notice(" Mode '%s':", uterm_mode_get_name(mode));
136 log_notice(" x: %u", uterm_mode_get_width(mode));
137 log_notice(" y: %u", uterm_mode_get_height(mode));
141 log_notice("End of Output list");
146 static void print_help()
149 * Usage/Help information
150 * This should be scaled to a maximum of 80 characters per line:
153 * | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 |
154 * "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
155 * 80 char line starting with tab:
156 * |10| 20 | 30 | 40 | 50 | 60 | 70 | 80 |
157 * "\t901234567890123456789012345678901234567890123456789012345678901234567890\n"
162 "\t%1$s -h [options]\n"
164 "You can prefix boolean options with \"no-\" to negate it. If an argument is\n"
165 "given multiple times, only the last argument matters if not otherwise stated.\n"
171 "\t --fbdev [off] Use fbdev instead of DRM\n"
172 "\t --test [off] Try displaying content instead of listing devices\n"
173 "\t --dev [/dev/dri/card0 | /dev/fb0] Use the given device\n",
177 * | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 |
178 * "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
179 * 80 char line starting with tab:
180 * |10| 20 | 30 | 40 | 50 | 60 | 70 | 80 |
181 * "\t901234567890123456789012345678901234567890123456789012345678901234567890\n"
185 struct conf_option options[] = {
187 CONF_OPTION_BOOL(0, "fbdev", &output_conf.fbdev, false),
188 CONF_OPTION_BOOL(0, "test", &output_conf.test, false),
189 CONF_OPTION_STRING(0, "dev", &output_conf.dev, NULL),
192 int main(int argc, char **argv)
194 struct uterm_video *video;
197 const struct uterm_video_module *mode;
200 onum = sizeof(options) / sizeof(*options);
201 ret = test_prepare(options, onum, argc, argv, &eloop);
205 if (output_conf.fbdev) {
206 mode = UTERM_VIDEO_FBDEV;
209 mode = UTERM_VIDEO_DRM3D;
210 node = "/dev/dri/card0";
214 node = output_conf.dev;
216 log_notice("Creating video object using %s...", node);
218 ret = uterm_video_new(&video, eloop, node, mode);
220 if (mode == UTERM_VIDEO_DRM3D) {
221 log_notice("cannot create drm device; trying drm2d mode");
222 ret = uterm_video_new(&video, eloop, node,
231 log_notice("Wakeing up video object...");
232 ret = uterm_video_wake_up(video);
236 if (!output_conf.test) {
237 ret = list_outputs(video);
239 log_err("Cannot list outputs: %d", ret);
243 ret = blit_outputs(video);
245 log_err("Cannot set outputs: %d", ret);
251 uterm_video_unref(video);
253 test_exit(options, onum, eloop);
255 if (ret != -ECANCELED)