?? fb3e.c
字號:
#include <stdio.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <sys/ioctl.h>#include <sys/mman.h>#include <linux/fb.h>#include <linux/types.h>#define D 5int Bpp;int xlen;void* fb_mm;int scr_len;struct fb_fix_screeninfo fix;struct fb_var_screeninfo var;int nXL;int nYL; typedef struct _point { int x, y;}point;void draw_rect(point *pt, int w, int h){ char *p; int i; p = fb_mm + (var.xres * pt->y + pt->x) * Bpp; for (i = 0; i < h; i++) { memset(p, 0x99, w * Bpp); p += xlen; }}void* flying(void *pstart){ int dy = -D; int dx = -D; point *pt; char *p; int i; pt = (point *)pstart; while(1) { if (pt->x + nXL > var.xres) { pt->x = var.xres - nXL; dx = -D; } else if (pt->x < 0) { pt->x = 0; dx = D; } if (pt->y + nYL > var.yres) { pt->y = var.yres - nYL; dy = -D; } else if (pt->y < 0) { pt->y = 0; dy = D; } memset(fb_mm, 0, scr_len); draw_rect(pt, nXL, nYL); usleep(20); pt->x += dx; pt->y += dy; } return NULL;}int main(){ int fd; pthread_t tid0, tid1; point pt = {0, 0}; fd = open("/dev/fb0", O_RDWR); if(fd < 0) { fprintf(stderr, "fail to open fb!\n"); return 0; } ioctl(fd, FBIOGET_VSCREENINFO, &var); Bpp = var.bits_per_pixel / 8; xlen = var.xres * Bpp; scr_len = var.yres * xlen; nXL = var.xres / 16; nYL = nXL; ioctl(fd, FBIOGET_FSCREENINFO, &fix); fb_mm = mmap(NULL, fix.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); if (MAP_FAILED == fb_mm) { fprintf(stderr, "fail to mmap\n"); close(fd); return -ENOMEM; } pthread_create(&tid0, NULL, flying, &pt); pthread_join(tid0, NULL); munmap(fb_mm, fix.smem_len); close(fd); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -