1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <unistd.h>
7
8 #include <sys/ioctl.h>
9 #include <sys/stat.h>
10 #include <sys/mman.h>
11
12 #include <linux/fb.h>
13
14 #include <kms++util/kms++util.h>
15
16 using namespace kms;
17
main(int argc,char ** argv)18 int main(int argc, char** argv)
19 {
20 const char* fbdev = "/dev/fb0";
21 int r;
22
23 int fd = open(fbdev, O_RDWR);
24 FAIL_IF(fd < 0, "open %s failed\n", fbdev);
25
26 struct fb_var_screeninfo var;
27
28 r = ioctl(fd, FBIOGET_VSCREENINFO, &var);
29 FAIL_IF(r, "FBIOGET_VSCREENINFO failed");
30
31 struct fb_fix_screeninfo fix;
32
33 r = ioctl(fd, FBIOGET_FSCREENINFO, &fix);
34 FAIL_IF(r, "FBIOGET_FSCREENINFO failed");
35
36 uint8_t* ptr = (uint8_t*)mmap(NULL,
37 var.yres_virtual * fix.line_length,
38 PROT_WRITE | PROT_READ,
39 MAP_SHARED, fd, 0);
40
41 FAIL_IF(ptr == MAP_FAILED, "mmap failed");
42
43 ExtCPUFramebuffer buf(var.xres, var.yres, PixelFormat::XRGB8888,
44 ptr, var.yres_virtual * fix.line_length, fix.line_length, 0);
45
46 printf("%s: res %dx%d, virtual %dx%d, line_len %d\n",
47 fbdev,
48 var.xres, var.yres,
49 var.xres_virtual, var.yres_virtual,
50 fix.line_length);
51
52 draw_test_pattern(buf);
53 draw_text(buf, buf.width() / 2, 0, fbdev, RGB(255, 255, 255));
54
55 close(fd);
56
57 return 0;
58 }
59