-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplay_fbdev.cpp
64 lines (49 loc) · 1.2 KB
/
display_fbdev.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "display_fbdev.hpp"
#define FB_NAME "/dev/fb0"
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
#include <stdexcept>
#include <sys/signal.h>
static volatile bool running = true;
Display::Display(int width, int height, bool fullscreen)
{
fbfd = open(FB_NAME, O_RDWR);
signal(SIGINT, [] (int) { running = false; });
if (fbfd < 0) {
throw std::runtime_error("Unable to open " FB_NAME);
}
struct fb_fix_screeninfo fixinfo;
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &fixinfo) < 0) {
close(fbfd);
throw std::runtime_error("get fixed screen info failed");
}
struct fb_var_screeninfo varinfo;
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &varinfo) < 0) {
close(fbfd);
throw std::runtime_error("get variable screen info failed");
}
void* fb = mmap(NULL, fixinfo.line_length * varinfo.yres, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
if (!fb) {
printf("mmap failed:\n");
close(fbfd);
abort();
}
canvas.width = fixinfo.line_length / 4;
canvas.height = varinfo.yres;
canvas.data = (uint32_t*)fb;
}
Display::~Display()
{
close(fbfd);
}
void Display::operator()()
{
bindCanvas();
while (running) {
pause();
}
releaseCanvas();
}