]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - tests/fbtestpat.cpp
96077578b8486114f2995dd602cf0ce7f52a5c50
[android/external-libkmsxx.git] / tests / 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 "mappedbuffer.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         void* ptr = 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         MappedCPUBuffer buf(var.xres_virtual, var.yres_virtual, PixelFormat::XRGB8888);
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         memcpy(ptr, buf.map(0), buf.size(0));
56         close(fd);
58         return 0;
59 }