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.
33 * The application terminates automatically after 5 seconds, however, you need
34 * to switch VT to re-enable output on your screen. This application does not
35 * reset the screen automatically, yet.
37 * This lists all outputs:
40 * This would show a test screen on output 0 and 4:
42 * The test screen is a white background with two gray triangles in the top-left
43 * and lower-right corner.
46 #define GL_GLEXT_PROTOTYPES
60 static void sig_term(int sig)
64 static int set_outputs(struct kmscon_compositor *comp, int num, char **list)
66 struct kmscon_output *iter;
70 iter = kmscon_compositor_get_outputs(comp);
71 for ( ; iter; iter = kmscon_output_next(iter)) {
72 for (i = 0; i < num; ++i) {
79 log_info("Ignoring output %d\n", j);
81 log_info("Activating output %d %p...\n", j, iter);
82 ret = kmscon_output_activate(iter, NULL);
84 log_err("Cannot activate output %d: %d\n", j,
87 log_info("Successfully activated output %d\n",
94 iter = kmscon_compositor_get_outputs(comp);
95 for ( ; iter; iter = kmscon_output_next(iter)) {
96 if (!kmscon_output_is_active(iter))
99 ret = kmscon_output_use(iter);
101 log_err("Cannot use output %p: %d\n", iter, ret);
105 glClearColor(1.0, 1.0, 1.0, 1.0);
106 glClear(GL_COLOR_BUFFER_BIT);
108 glBegin(GL_TRIANGLES);
109 glColor4f(0.5, 0.5, 0.5, 1.0);
110 glVertex3f(1.0, 1.0, 0.0f);
111 glVertex3f(0, 0, 0.0f);
112 glVertex3f(1.0, 0, 0.0f);
113 glVertex3f(-1.0, -1.0, 0.0f);
114 glVertex3f(0, 0, 0.0f);
115 glVertex3f(-1.0, 0, 0.0f);
118 ret = kmscon_output_swap(iter);
120 log_err("Cannot swap buffers of output %p: %d\n",
125 log_info("Successfully set screen on output %p\n", iter);
128 log_info("Waiting 5 seconds...\n");
130 log_info("Exiting...\n");
135 static int list_outputs(struct kmscon_compositor *comp)
137 struct kmscon_output *iter;
138 struct kmscon_mode *cur, *mode;
141 log_info("List of Outputs:\n");
144 iter = kmscon_compositor_get_outputs(comp);
145 for ( ; iter; iter = kmscon_output_next(iter)) {
146 cur = kmscon_output_get_current(iter);
148 log_info("Output %d:\n", i++);
149 log_info(" active: %d\n", kmscon_output_is_active(iter));
150 log_info(" has current: %s\n", cur ? "yes" : "no");
152 mode = kmscon_output_get_modes(iter);
153 for ( ; mode; mode = kmscon_mode_next(mode)) {
154 log_info(" Mode '%s':\n", kmscon_mode_get_name(mode));
155 log_info(" x: %u\n", kmscon_mode_get_width(mode));
156 log_info(" y: %u\n", kmscon_mode_get_height(mode));
160 log_info("End of Output list\n");
165 int main(int argc, char **argv)
167 struct kmscon_compositor *comp;
169 struct sigaction sig;
171 memset(&sig, 0, sizeof(sig));
172 sig.sa_handler = sig_term;
173 sigaction(SIGTERM, &sig, NULL);
174 sigaction(SIGINT, &sig, NULL);
176 log_info("Creating compositor...\n");
177 ret = kmscon_compositor_new(&comp);
179 log_err("Cannot create compositor: %d\n", ret);
183 log_info("Wakeing up compositor...\n");
184 ret = kmscon_compositor_wake_up(comp);
186 log_err("Cannot wakeup compositor: %d\n", ret);
190 kmscon_compositor_use(comp);
193 ret = list_outputs(comp);
195 log_err("Cannot list outputs: %d\n", ret);
199 ret = set_outputs(comp, argc - 1, &argv[1]);
201 log_err("Cannot set outputs: %d\n", ret);
207 kmscon_compositor_unref(comp);