S3C6410 FrameBuffer编程(一) ---- 获取屏幕属性

来源:互联网 发布:混合高斯模型的em算法 编辑:程序博客网 时间:2024/06/06 01:04

#include <unistd.h> 
#include <stdio.h> 
#include <fcntl.h> 
#include <linux/fb.h> 
#include <sys/mman.h> 
int main ()  
{  
    int fp=0;  
    struct fb_var_screeninfo vinfo;  
    struct fb_fix_screeninfo finfo;  
     
    fp = open ("/dev/fb0",O_RDWR);  
    if (fp < 0
    {   
        printf("Error : Can not open framebuffer device\n");   
        exit(1);  
    }  
    if (ioctl(fp,FBIOGET_FSCREENINFO,&finfo)) 
    {   
        printf("Error reading fixed information\n");   
        exit(2);  
    }   
    if (ioctl(fp,FBIOGET_VSCREENINFO,&vinfo)) 
    {   
        printf("Error reading variable information\n");   
        exit(3);  
    }  
    printf("The mem is :%d\n",finfo.smem_len);  
    printf("The line_length is :%d\n",finfo.line_length);  
    printf("The xres is :%d\n",vinfo.xres);  
    printf("The yres is :%d\n",vinfo.yres);  
    printf("bits_per_pixel is :%d\n",vinfo.bits_per_pixel);  
    close (fp); 


struct fb_var_screeninfo 和 struct fb_fix_screeninfo 两个数据结构是在/usr/include/linux/fb.h中定义的,里面有些有趣的值:(都是 无符号32位的整数) 
在fb_fix_screeninfo中有 
    __u32 smem_len 是这个/dev/fb0的大小,也就是内存大小。 
    __u32 line_length 是屏幕上一行的点在内存中占有的空间,不是一行上的点数。 
在fb_var_screeninfo 中有 
    __u32 xres ,__u32 yres 是x和y方向的分辨率,就是两个方向上的点数。 
    __u32 bits_per_pixel 是每一点占有的内存空间。 

把上面的程序编译以后运行,在我的机器上的结果如下: 

命令: 
The mem is :522240
The line_length is :960 
The xres is :480 
The yres is :272

bits_per_pixel is :16 

内存长度恰好是510K字节,每行占有960字节的空间,分辨率是480x272,色彩深度是16位。屏幕实际占用的内存只有255K字节,缓存要占255K字节。这是因为在现代的图形系统中大多有缓冲技术,显存中存有两页屏幕数据,这是方便快速的改变屏幕内容实现动画之类比较高的要求。关 于这种缓冲技术有点复杂,我们目前先不讨论。对于我们来说只有255K字节的内存来存放这一个屏幕的颜色数据。

原创粉丝点击