framebuffer 测试程序 arm linux 6410 2440 2416

#include <stdio.h>
#include <stdlib.h>

#include <fcntl.h>

#include <linux/fb.h>

#include <sys/mman.h>


void setpixel(void *fb,struct fb_var_screeninfo *pVarInfo, int x, int y, char r, char g, char b)

{
if(pVarInfo->bits_per_pixel==16)  *((unsigned short *)((char *)fb  + (y + x)*2))=(unsigned short )(r<<11|g<<5|b);
else if(pVarInfo->bits_per_pixel==24 || pVarInfo->bits_per_pixel== 32)  *((unsigned  long *)fb  + y + x)=(unsigned long )(r<<16|g<<8|b);
else  fprintf(stderr, " error bits_per_pixel is not surport !\n");

}



void DrawScreen(void *fb, struct fb_var_screeninfo *pVarInfo, int h)

{

    int x, y, ytimesw;



    for(y = 0; y < pVarInfo->yres; y++ )

    {

        ytimesw = y*pVarInfo->xres;

        for( x = 0; x < pVarInfo->xres; x++ )

        {

            setpixel(fb,pVarInfo,x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h);

        }

    }



}


int main() {
int i =0;
struct fb_fix_screeninfo fixInfo;

struct fb_var_screeninfo varInfo;

int fbfd = -1;

void *buffer = (void *) -1;

    /* open the buffer device */

    fbfd = open("/dev/fb0", O_RDWR);

    if (fbfd < 0) {

        fprintf(stderr, "Error opening /dev/fb0\n");

        exit(1);

    }

    /* Get the fixed screen info */

    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &fixInfo)) {

        fprintf(stderr, "error: ioctl(FBIOGET_FSCREENINFO) failed\n");

        exit(1);

    }

    /* get the variable screen info */

    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &varInfo)) {

        fprintf(stderr, "error: ioctl(FBIOGET_VSCREENINFO) failed\n");

        exit(1);

    }

     
	printf("xres=%d ; yres=%d ; bits_per_pixel=%d\n",varInfo.xres,varInfo.yres,varInfo.bits_per_pixel );


    if (fixInfo.visual != FB_VISUAL_TRUECOLOR && fixInfo.visual != FB_VISUAL_DIRECTCOLOR) {

        fprintf(stderr, "non-TRUE/DIRECT-COLOR visuals (0x%x) not supported by this demo.\n", fixInfo.visual);

        exit(1);

    }

    /*

     * fbdev says the frame buffer is at offset zero, and the mmio region

     * is immediately after.

     */

    /* mmap the buffer into our address space */

    buffer = (void *) mmap(0, /* start */

        fixInfo.smem_len, /* bytes */

        PROT_READ | PROT_WRITE, /* prot */

        MAP_SHARED, /* flags */

        fbfd, /* fd */

        0 /* offset */);

    if (buffer == (void *) - 1) {

        fprintf(stderr, "error: unable to mmap buffer\n");

        exit(1);

    }

    fprintf(stderr, "open finish\n");
   while (1) DrawScreen(buffer,&varInfo,i++);

    munmap(buffer, fixInfo.smem_len);

    close(fbfd);

    fprintf(stderr, "close finish\n");

    return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值