17 #define FRAMEBUFFER_SIZE(xsz, ysz, bpp) ((xsz) * (ysz) * (bpp) / CHAR_BIT)
19 static unsigned char *framebuffer;
20 static int dev_fd = -1;
22 static Rect screen_rect;
24 static int color_depth; // bits per pixel
26 static Pixmap *pixmap;
30 if((dev_fd = open("/dev/fb0", O_RDWR)) == -1) {
31 fprintf(stderr, "Cannot open /dev/fb0 : %s\n", strerror(errno));
35 fb_var_screeninfo sinfo;
36 if(ioctl(dev_fd, FBIOGET_VSCREENINFO, &sinfo) == -1) {
39 fprintf(stderr, "Unable to get screen info : %s\n", strerror(errno));
43 printf("width : %d height : %d\n : bpp : %d\n", sinfo.xres, sinfo.yres, sinfo.bits_per_pixel);
44 printf("virtual w: %d virtual h: %d\n", sinfo.xres_virtual, sinfo.yres_virtual);
46 screen_rect.x = screen_rect.y = 0;
47 screen_rect.width = sinfo.xres_virtual;
48 screen_rect.height = sinfo.yres_virtual;
49 color_depth = sinfo.bits_per_pixel;
51 set_clipping_rect(screen_rect);
53 int sz = FRAMEBUFFER_SIZE(screen_rect.width, screen_rect.height, color_depth);
54 framebuffer = (unsigned char*)mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0);
56 if(framebuffer == (void*)-1) {
59 fprintf(stderr, "Cannot map the framebuffer to memory : %s\n", strerror(errno));
63 // TODO: uncomment when I find how to use intelfb instead of i915 GRRRR.-
65 if(ioctl(dev_fd, FBIOGET_VBLANK, &vblank) == -1) {
66 // fprintf(stderr, "FBIOGET_VBLANK error: %s\n", strerror(errno));
70 printf("flags: %x\n", vblank.flags);
71 printf("count: %d\n", vblank.count);
72 printf("beam position: %d, %d\n", vblank.hcount, vblank.vcount);
77 pixmap->width = screen_rect.width;
78 pixmap->height = screen_rect.height;
79 pixmap->pixels = framebuffer;
86 clear_screen(0, 0, 0);
94 munmap(framebuffer, FRAMEBUFFER_SIZE(screen_rect.width, screen_rect.height, color_depth));
100 unsigned char *get_framebuffer()
105 Pixmap *get_framebuffer_pixmap()
110 Rect get_screen_size()
115 int get_color_depth()
121 void set_cursor_visibility(bool visible)
124 curs.enable = visible ? 1 : 0;
126 if(ioctl(dev_fd, FBIO_CURSOR, &curs) == -1) {
127 fprintf(stderr, "Cannot toggle cursor visibility : %s\n", strerror(errno));
137 unsigned long arg = 0;
138 if(ioctl(dev_fd, FBIO_WAITFORVSYNC, &arg) == -1) {
139 // printf("ioctl error %s\n", strerror(errno));
143 #endif // WINNIE_FBDEV