]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - utils/fbtestpat.cpp
Support RGB888
[android/external-libkmsxx.git] / utils / fbtestpat.cpp
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <unistd.h>
8 #include <sys/ioctl.h>
9 #include <sys/stat.h>
10 #include <sys/mman.h>
12 #include <linux/fb.h>
14 #include <kms++util/kms++util.h>
16 using namespace kms;
18 int main(int argc, char** argv)
19 {
20         const char* fbdev = "/dev/fb0";
21         int r;
23         int fd = open(fbdev, O_RDWR);
24         FAIL_IF(fd < 0, "open %s failed\n", fbdev);
26         struct fb_var_screeninfo var;
28         r = ioctl(fd, FBIOGET_VSCREENINFO, &var);
29         FAIL_IF(r, "FBIOGET_VSCREENINFO failed");
31         struct fb_fix_screeninfo fix;
33         r = ioctl(fd, FBIOGET_FSCREENINFO, &fix);
34         FAIL_IF(r, "FBIOGET_FSCREENINFO failed");
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);
41         FAIL_IF(ptr == MAP_FAILED, "mmap failed");
43         ExtCPUFramebuffer buf(var.xres, var.yres_virtual, PixelFormat::XRGB8888, ptr, fix.line_length);
45         printf("%s: res %dx%d, virtual %dx%d, line_len %d\n",
46                fbdev,
47                var.xres, var.yres,
48                var.xres_virtual, var.yres_virtual,
49                fix.line_length);
51         draw_test_pattern(buf);
53         for (unsigned y = 0; y < var.yres_virtual; ++y)
54                 memcpy(ptr + fix.line_length * y, buf.map(0) + buf.stride(0) * y, buf.stride(0));
56         close(fd);
58         return 0;
59 }