【RFB】linux-framebuffer裝置相關參數

來源:互聯網
上載者:User

如果應用程式需要知道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;
}
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.