【RFB】linux

如果应用程序需要知道Framebuffer设备的相关参数,必须通过ioctl()系统调用来完成。

在头文件<linux/fb.h>中定义了所有的ioctl命令字,不过,最常用的ioctl命令字是下面这两个:FBIOGET_FSCREENINFO和FBIOGET_VSCREENINFO。

前者返回与Framebuffer有关的固定的信息,比如图形硬件上实际的帧缓存空间的大小、能否硬件加速等信息。

而后者返回的是与Framebuffer有关的可变信息。

之所以可变,是因为对同样的图形硬件,可以工作在不同的模式下。

简单来讲,一个支持1024x768x24图形模式的硬件通常也能工作在800x600x16的图形模式下。

可变的信息就是指Framebuffer的长度、宽度以及颜色深度等信息。

这两个命令字相关的结构体有两个:struct fb_fix_screeninfo和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 */};

这两个结构体都比较大,前者用于保存Framebuffer设备的固定信息,后者用于保存Framebuffer设备的可变信息。

在调用ioctl()的时候,要用到这两个结构体。

应用程序中通常要用到struct fb_var_screeninfo的下面这几个字段:

xres、yres、bits_per_pixel,分别表示x轴的分辨率、y轴的分辨率以及每像素的颜色深度(颜色深度的单位为bit/pixel),其类型定义都是无符号32位整型数。

http://hi.baidu.com/atoe/blog/item/e8da6416912a8a4a20a4e94f.html

http://hi.baidu.com/excellentderek/blog/item/f387e64e24b713cdd0c86a59.html

图形系统开发基础(挺详细)

http://linux.chinaunix.net/bbs/thread-1063136-1-1.html

又一个framebuffer编程的例子。

————————————-#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的获取,是很核心的步骤,表示成功获得了framebuffer设备*/

picture=(char *)malloc(fb_var.yres*fb_fix.line_length);memset(picture,0xFF,fb_var.yres*fb_fix.line_length); /*注意,这里对颜色的赋值只是一次赋一半值,也就是一个字节,8bit*/ /*而事实上,一个像素的颜色值是16bit*/ /*0xFFFF就是白色*/ /*介绍一下16bit的颜色的类型,颜色是由RGB组成,如果是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; /*像素数乘以2即是字节数,因为颜色深度是2个字节(16bit)*/

while(–height>=0){ memcpy(t_fb_addr,t_data,bytew); /*一行的数据赋值*/ t_fb_addr += width; t_data += width;}}

分明是比谁记的都清楚,比谁都更加在意,

【RFB】linux

相关文章:

你感兴趣的文章:

标签云: