2 * Copyright © 2014 NVIDIA Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 #ifdef HAVE_SYS_SELECT_H
32 #include <sys/select.h>
35 #include <drm_fourcc.h>
37 #include "util/pattern.h"
38 #include "libkms-test.h"
40 static void signal_handler(int signum)
44 int main(int argc, char *argv[])
46 struct kms_framebuffer *fb;
47 struct kms_screen *screen;
48 struct kms_device *device;
49 unsigned int index = 0;
55 fprintf(stderr, "usage: %s DEVICE\n", argv[0]);
59 memset(&sa, 0, sizeof(sa));
60 sa.sa_handler = signal_handler;
62 err = sigaction(SIGINT, &sa, NULL);
64 fprintf(stderr, "sigaction() failed: %m\n");
68 fd = open(argv[1], O_RDWR);
70 fprintf(stderr, "open() failed: %m\n");
74 device = kms_device_open(fd);
76 fprintf(stderr, "kms_device_open() failed: %m\n");
80 if (device->num_screens < 1) {
81 fprintf(stderr, "no screens found\n");
82 kms_device_close(device);
87 /* TODO: allow command-line to override */
88 screen = device->screens[0];
90 printf("Using screen %s, resolution %ux%u\n", screen->name,
91 screen->width, screen->height);
93 fb = kms_framebuffer_create(device, screen->width, screen->height,
96 fprintf(stderr, "kms_framebuffer_create() failed\n");
100 err = kms_framebuffer_map(fb, &ptr);
102 fprintf(stderr, "kms_framebuffer_map() failed: %d\n", err);
106 util_fill_pattern(fb->format, UTIL_PATTERN_SMPTE, &ptr, fb->width,
107 fb->height, fb->pitch);
109 kms_framebuffer_unmap(fb);
111 err = kms_screen_set(screen, device->crtcs[index++], fb);
113 fprintf(stderr, "kms_screen_set() failed: %d\n", err);
118 int nfds = STDIN_FILENO + 1;
119 struct timeval timeout;
122 memset(&timeout, 0, sizeof(timeout));
127 FD_SET(STDIN_FILENO, &fds);
129 err = select(nfds, &fds, NULL, NULL, &timeout);
134 fprintf(stderr, "select() failed: %d\n", errno);
139 if (FD_ISSET(STDIN_FILENO, &fds))
144 if (index >= device->num_crtcs)
147 err = kms_screen_set(screen, device->crtcs[index], fb);
149 fprintf(stderr, "kms_screen_set() failed: %d\n", err);
156 kms_framebuffer_free(fb);
157 kms_device_close(device);