if the application needs to know the relevant parameters of the framebuffer device, it must be done through the IOCTL () system call.
all the IOCTL command words are defined in header file <linux/fb.h>, but the most commonly used IOCTL command word is the following two: Fbioget_fscreeninfo and Fbioget_vscreeninfo.
The former returns fixed information related to framebuffer, such as the actual frame cache space on the graphics hardware, the ability to accelerate hardware, and so on.
The latter returns variable information related to Framebuffer.
The reason for the variability is that the same graphics hardware can work in different modes.
in simple terms, a hardware that supports 1024x768x24 graphics mode can often work in 800x600x16 graphics mode.
variable information refers to the length, width, and color depth of the framebuffer.
The two command words are related to two structural bodies: struct fb_fix_screeninfo and struct fb_var_screeninfo.
Both structures are relatively large, which is used to hold the fixed information of the framebuffer device, which is used to hold the variable information of the framebuffer device.
These two structures are used when calling IOCTL ().
The following fields of struct fb_var_screeninfo are commonly used in applications:
xres, Yres, Bits_per_pixel, respectively, represent the resolution of the x-axis, the resolution of the y-axis, and the color depth per pixel (the unit of color depth is bit/pixel), and its type definition is unsigned 32-bit integer numbers.
http://hi.baidu.com/atoe/blog/item/e8da6416912a8a4a20a4e94f.html
Http://hi.baidu.com/excellentderek/blog/item/f387e64e24b713cdd0c86a59.html
Graphic System Development Foundation (very detailed)
http://linux.chinaunix.net/bbs/thread-1063136-1-1.html
Another example of framebuffer programming.
-------------------------------------
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
Char *fb_addr;
unsigned fb_size;
int Print_screen (char *buf,int width,int height);
int main (int argc,char *argv[])
{
int screen_fbd=0;
struct Fb_fix_screeninfo fb_fix;
struct Fb_var_screeninfo Fb_var;
Char *env=null;
Short *picture;
env= "/dev/fb0";
Screen_fbd=open (ENV,O_RDWR);
printf ("Success Opening framebuffer device%s/n", env);
IOCTL (screen_fbd,fbioget_fscreeninfo,&fb_fix);
printf ("fb_fix.line_length=%d/n", fb_fix.line_length);
printf ("fb_fix.accel=%d/n", fb_fix.accel);
IOCTL (Screen_fbd,fbioget_vscreeninfo,&fb_var);
printf ("fb_var.xres=%d/n", fb_var.xres);
printf ("fb_var.yres=%d/n", fb_var.yres);
fb_size=fb_var.yres*fb_fix.line_length;
Fb_addr= (char *) mmap (null,fb_size,prot_read| prot_write,map_shared,screen_fbd,0);
The acquisition of/*FB_ADDR is a very core step, indicating the successful acquisition of framebuffer equipment * *
Picture= (char *) malloc (fb_var.yres*fb_fix.line_length);
memset (picture,0xff,fb_var.yres*fb_fix.line_length);
/* Note that the assignment of the color here is only one half of the value, that is, a byte, 8bit*/
/* And in fact, the color value of a pixel is 16bit*/
/*0XFFFF is white * *
/* Introduce the color of the 16bit type, color is composed of RGB, if it is 565 permutations,
Red Green Blue in turn
11111 111111 11111
*/
Print_screen (picture,fb_var.xres,fb_var.yres);
return 0;
}
int Print_screen (char *buf,int width,int height)
{
Short *t_data= (short *) buf;
Short *t_fb_addr= (short *) fb_addr;
int bytew=width<<1;/* pixels multiplied by 2 is the number of bytes because the color depth is 2 bytes (16bit) */
while (--height>=0)
{
memcpy (T_FB_ADDR,T_DATA,BYTEW); /* A row of data assignment * *
T_fb_addr + = width;
T_data + = width;
}
}