]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - utils/fbtestpat.cpp
d82f3e4210646e1824b3822c6b01f8323c0657f6
[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 "test.h"
15 #include "extcpuframebuffer.h"
17 using namespace kms;
19 int main(int argc, char** argv)
20 {
21         const char* fbdev = "/dev/fb0";
22         int r;
24         int fd = open(fbdev, O_RDWR);
25         FAIL_IF(fd < 0, "open %s failed\n", fbdev);
27         struct fb_var_screeninfo var;
29         r = ioctl(fd, FBIOGET_VSCREENINFO, &var);
30         FAIL_IF(r, "FBIOGET_VSCREENINFO failed");
32         struct fb_fix_screeninfo fix;
34         r = ioctl(fd, FBIOGET_FSCREENINFO, &fix);
35         FAIL_IF(r, "FBIOGET_FSCREENINFO failed");
37         uint8_t* ptr = (uint8_t*)mmap(NULL,
38                          var.yres_virtual * fix.line_length,
39                          PROT_WRITE | PROT_READ,
40                          MAP_SHARED, fd, 0);
42         FAIL_IF(ptr == MAP_FAILED, "mmap failed");
44         ExtCPUFramebuffer buf(var.xres, var.yres_virtual, PixelFormat::XRGB8888, ptr, fix.line_length);
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);
52         draw_test_pattern(buf);
54         for (unsigned y = 0; y < var.yres_virtual; ++y)
55                 memcpy(ptr + fix.line_length * y, buf.map(0) + buf.stride(0) * y, buf.stride(0));
57         close(fd);
59         return 0;
60 }