Framebuffer from user space
You usually access framebuffer memory by means of the mmap()
command in order to map the framebuffer memory to the part of the system RAM, so that drawing pixels on the screen becomes a simple matter of affecting memory value. Screen parameters (variable and fixed) are extracted by means of ioctl
commands, especially FBIOGET_VSCREENINFO
and FBIOGET_FSCREENINFO
. The complete list is available at include/uapi/linux/fb.h
in the kernel source.
The following is a sample code to draw a 300*300 square on the framebuffer:
#include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <linux/fb.h> #include <sys/mman.h> #include <sys/ioctl.h> #define FBCTL(_fd, _cmd, _arg) \ if(ioctl(_fd, _cmd, _arg) == -1) { \ ERROR("ioctl failed"); \ exit(1); } int main() { int fd; int x, y, pos; int r, g, b; unsigned short color; void *fbmem; ...