blob: e3e8b77d8f60b3ede3e140794fbdcf3999b82fae (
plain)
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
|
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<stdbool.h>
#include<fcntl.h>
#include<linux/fb.h>
#include<sys/ioctl.h>
#include<sys/mman.h>
int
main(void) {
// Open frambuffer and get the size.
int fb = open("/dev/fb0", O_RDWR);
if (fb <= 0) {
fprintf(stderr, "couldn't open the framebuffer\n");
exit(EXIT_FAILURE);
}
struct fb_var_screeninfo info;
if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) {
fprintf(stderr, "couldn't get the framebuffer size\n");
exit(EXIT_FAILURE);
}
// Mmap the framebuffer to a buffer object.
size_t width = info.xres;
size_t height = info.yres;
size_t len = 4 * width * height;
uint32_t *buf = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
if (buf == MAP_FAILED) {
fprintf(stderr, "couldn't mmap the framebuffer\n");
exit(EXIT_FAILURE);
}
uint8_t shade = 0;
while (true) {
for (size_t j = 0; j < height; j++) {
for (size_t i = 0; i < width; i++) {
buf[j * width + i] = shade;
}
}
shade++;
}
return 0;
}
|