Hardware Framebuffer
From OpenTom
(Redirected from Framebuffer)
[edit]
General
- Information can be gathered from the Hello world example
- Framebuffer is now working with linux 2.6
- Screen size and colour depth (bits per pixel) can be aquired using IOCTL calls
[edit]
Open Framebuffer
The framebuffer is opened and mapped to memory. A second screen buffer is also allocated.
int fbfd = open(FB_DEVICE_NAME, O_RDWR);
if (!fbfd) {
printf("Could not open framebuffer.\n");
return -1;
}
// Get fixed screen information
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
printf("Could not read fixed screen info.\n");
return -2;
}
// Get variable screen information
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
printf("Could not read variable screen info.\n");
return -3;
}
printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );
// Figure out the size of the screen in bytes
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
// Map the device to memory
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
if ((int)fbp == -1) {
printf("Fout: gefaald bij het mappen van de framebuffer device in het geheugen.\n");
return -4;
}
fbbackp = (char*)malloc(screensize);
printf("framebuffer ready.\n");
[edit]
Use the Framebuffer
Manipulate the second buffer *fbbackp, then copy all the data to the first one.
// set pixel x,y to color unsigned short *ptr = (unsigned short*)(fbbackp+y*((vinfo.xres*vinfo.bits_per_pixel)/8)); ptr+=x; *ptr = color;
Flush the changes to the real buffer
memcpy(fbp,fbbackp,screensize);
Or display the second buffer (faster) :
struct fb_var_screeninfo fb_var; ioctl(fb,FBIOGET_VSCREENINFO,&fb_var)) fb_var.yoffset=fb_var.yres; ioctl(fb,FBIOPAN_DISPLAY,&fb_var))
(That's how TT does it.)
To switch back to the first buffer :
fb_var.yoffset=0; ioctl(fb,FBIOPAN_DISPLAY,&fb_var))
Read more about programming in LibSDL.

