If the application needs to know the relevant parameters of the framebuffer device, it must be called by the ioctl () system.
All IOCTL command words are defined in the header file <Linux/FB. h>. However, the most common IOCTL command words are fbioget_fscreeninfo and fbioget_vscreeninfo.
The former returns fixed information related to framebuffer, such as the actual size of the frame cache space on the hardware, and whether hardware acceleration is possible.
The latter returns variable information related to framebuffer.
The reason for the change is that the same graphic hardware can work in different modes.
Simply put, a hardware supporting the 1024x768x24 graphics mode usually works in the 800x600x16 graphics mode.
Variable information refers to the length, width, color depth, and other information of framebuffer.
There are two structures related to these two command words: struct fb_fix_screeninfo and struct fb_var_screeninfo.
struct fb_fix_screeninfo {char id[16];/* identification string eg "TT Builtin" */unsigned long smem_start;/* Start of frame buffer mem *//* (physical address) */__u32 smem_len;/* Length of frame buffer mem */__u32 type;/* see FB_TYPE_**/__u32 type_aux;/* Interleave for interleaved Planes */__u32 visual;/* see FB_VISUAL_**/ __u16 xpanstep;/* zero if no hardware panning */__u16 ypanstep;/* zero if no hardware panning */__u16 ywrapstep;/* zero if no hardware ywrap */__u32 line_length;/* length of a line in bytes */unsigned long mmio_start;/* Start of Memory Mapped I/O *//* (physical address) */__u32 mmio_len;/* Length of Memory Mapped I/O */__u32 accel;/* Indicate to driver which*//* specific chip/card we have*/__u16 reserved[3];/* Reserved for future compatibility */};
struct fb_var_screeninfo {__u32 xres;/* visible resolution*/__u32 yres;__u32 xres_virtual;/* virtual resolution*/__u32 yres_virtual;__u32 xoffset;/* offset from virtual to visible */__u32 yoffset;/* resolution*/__u32 bits_per_pixel;/* guess what*/__u32 grayscale;/* != 0 Graylevels instead of colors */struct fb_bitfield red;/* bitfield in fb mem if true color, */struct fb_bitfield green;/* else only length is significant */struct fb_bitfield blue;struct fb_bitfield transp;/* transparency*/__u32 nonstd;/* != 0 Non standard pixel format */__u32 activate;/* see FB_ACTIVATE_**/__u32 height;/* height of picture in mm */__u32 width;/* width of picture in mm */__u32 accel_flags;/* (OBSOLETE) see fb_info.flags *//* Timing: All values in pixclocks, except pixclock (of course) */__u32 pixclock;/* pixel clock in ps (pico seconds) */__u32 left_margin;/* time from sync to picture*/__u32 right_margin;/* time from picture to sync*/__u32 upper_margin;/* time from sync to picture*/__u32 lower_margin;__u32 hsync_len;/* length of horizontal sync*/__u32 vsync_len;/* length of vertical sync*/__u32 sync;/* see FB_SYNC_**/__u32 vmode;/* see FB_VMODE_**/__u32 rotate;/* angle we rotate counter clockwise */__u32 reserved[5];/* Reserved for future compatibility */};
Both structures are large. The former is used to save the fixed information of the framebuffer device, and the latter is used to save variable information of the framebuffer device.
When calling IOCTL (), you need to use these two struct.
The following fields of struct fb_var_screeninfo are usually used in applications:
Xres, yres, and bits_per_pixel indicate the resolution of the X axis, the Y axis, and the color depth of each pixel (unit: bit/pixel), respectively ), its Type Definitions are all unsigned 32-bit integer numbers.
Http://hi.baidu.com/atoe/blog/item/e8da6416912a8a4a20a4e94f.html
Http://hi.baidu.com/excellentderek/blog/item/f387e64e24b713cdd0c86a59.html
Graph System Development BASICS (quite 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 );
/* Fb_addr acquisition is a core step, indicating that the framebuffer device is successfully obtained */
Picture = (char *) malloc (fb_var.yres * fb_fix.line_length );
Memset (picture, 0xff, fb_var.yres * fb_fix.line_length );
/* Note that the color assignment is only a half value, that is, a byte, 8 bit */
/* In fact, the color value of a pixel is 16 bit */
/* 0xffff is white */
/* Describes the 16-bit color type. The color is composed of RGB. If the color is 565,
Red green blue
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;/* The number of bytes multiplied by 2 is the number of bytes, because the color depth is 2 bytes (16 bit )*/
While (-- height> = 0)
{
Memcpy (t_fb_addr, t_data, bytew);/* assign values to data in a row */
T_fb_addr + = width;
T_data + = width;
}
}