本文主要是介绍FrameBuffer相关,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
FrameBuffer 之 fb_fix_screeninfo , fb_var_screeninfo
fb_fix_screeninfo 和 fb_var_screeninfo 都和 frame buffer 有关,详细的数据结构含义可以参考 kernel 头文件,这里只列出几个重要成员的含义。
fb_fix_screeninfo 的 line_length 成员,含义是一行的 size,以字节数表示,就是屏幕的宽度。
结构fb_var_screeninfo定义了视频硬件一些可变的特性。这些特性在程序运行期间可以由应用程序动态改变。
由于篇幅有限在此只对这个结构体中主要的成员作出解释,详细解释请参见fb.h。成员变量xres 和 yres定义在显示屏上真实显示的分辨率。而xres_virtual和yres_virtual是虚拟分辨率,它们定义的是显存分辨率。比如显示屏垂直分辨率是400,而虚拟分辨率是800。这就意味着在显存中存储着800行显示行,但是每次只能显示400行。但是显示哪400行呢?这就需要另外一个成员变量yoffset,当yoffset=0时,从显存0行开始显示400行,如果yoffset=30,就从显存31行开始显示400行。
C程序实现在LCD上全屏写蓝色及获取fb信息源码
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <stdlib.h>
int hello_main(int argc, char *argv[])
{
int fbfd = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
long int screensize = 0;
char *fbp = 0;
int x = 0, y = 0;
long int location = 0;
int sav=0;
/* open device*/
fbfd = open("/dev/graphics/fb0", O_RDWR);
if (!fbfd)
{
printf("Error: cannot open framebuffer device.\n");
exit(1);
}
printf("The framebuffer device was opened successfully.\n");
/* Get fixed screen information */
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo))
{
printf("Error reading fixed information.\n");
exit(2);
}
/* Get variable screen information */
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo))
{
printf("Error reading variable information.\n");
exit(3);
}
/* show these information*/
printf("vinfo.xres=%d\n",vinfo.xres);
printf("vinfo.yres=%d\n",vinfo.yres);
printf("vinfo.bits_per_pixel=%d\n",vinfo.bits_per_pixel);
printf("vinfo.xoffset=%d\n",vinfo.xoffset);
printf("vinfo.yoffset=%d\n",vinfo.yoffset);
printf("finfo.line_length=%d\n",finfo.line_length);
/* Figure out the size of the screen in bytes */
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
/* Map the device to memory */
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
if ((int)fbp == -1)
{
printf("Error: failed to map framebuffer device to memory.\n");
exit(4);
}
printf("The framebuffer device was mapped to memory successfully.\n");
memset(fbp, 0, screensize);
/* Where we are going to put the pixel */
for(x = 0; x < vinfo.xres; x++)
{
for(y = 0; y < vinfo.yres; y++)
{
location = (x + vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y + vinfo.yoffset) * finfo.line_length;
*(fbp + location) = 0xff; /* blue */
*(fbp + location + 1) = 0x00;
}
}
munmap(fbp, screensize);
/* release the memory */
close(fbfd);
return 0;
}
这篇关于FrameBuffer相关的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!