18 #define FRAMEBUFFER_SIZE(xsz, ysz, bpp) ((xsz) * (ysz) * (bpp) / CHAR_BIT)
21 unsigned char *framebuffer;
33 if(!(gfx = (Graphics*)malloc(sizeof *gfx))) {
39 if((gfx->dev_fd = open("/dev/fb0", O_RDWR)) == -1) {
40 fprintf(stderr, "Cannot open /dev/fb0 : %s\n", strerror(errno));
44 fb_var_screeninfo sinfo;
45 if(ioctl(gfx->dev_fd, FBIOGET_VSCREENINFO, &sinfo) == -1) {
48 fprintf(stderr, "Unable to get screen info : %s\n", strerror(errno));
52 printf("width : %d height : %d\n : bpp : %d\n", sinfo.xres, sinfo.yres, sinfo.bits_per_pixel);
53 printf("virtual w: %d virtual h: %d\n", sinfo.xres_virtual, sinfo.yres_virtual);
55 gfx->screen_rect.x = gfx->screen_rect.y = 0;
56 gfx->screen_rect.width = sinfo.xres_virtual;
57 gfx->screen_rect.height = sinfo.yres_virtual;
58 gfx->color_depth = sinfo.bits_per_pixel;
60 set_clipping_rect(gfx->screen_rect);
62 int sz = FRAMEBUFFER_SIZE(gfx->screen_rect.width, gfx->screen_rect.height, gfx->color_depth);
63 gfx->framebuffer = (unsigned char*)mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, gfx->dev_fd, 0);
65 if(gfx->framebuffer == (void*)-1) {
68 fprintf(stderr, "Cannot map the framebuffer to memory : %s\n", strerror(errno));
72 // TODO: uncomment when I find how to use intelfb instead of i915 GRRRR.-
74 if(ioctl(gfx->dev_fd, FBIOGET_VBLANK, &vblank) == -1) {
75 // fprintf(stderr, "FBIOGET_VBLANK error: %s\n", strerror(errno));
79 printf("flags: %x\n", vblank.flags);
80 printf("count: %d\n", vblank.count);
81 printf("beam position: %d, %d\n", vblank.hcount, vblank.vcount);
85 gfx->pixmap = new Pixmap;
86 gfx->pixmap->width = gfx->screen_rect.width;
87 gfx->pixmap->height = gfx->screen_rect.height;
88 gfx->pixmap->pixels = gfx->framebuffer;
95 clear_screen(0, 0, 0);
97 if(gfx->dev_fd != -1) {
103 munmap(gfx->framebuffer, FRAMEBUFFER_SIZE(gfx->screen_rect.width, gfx->screen_rect.height, gfx->color_depth));
104 gfx->framebuffer = 0;
106 gfx->pixmap->pixels = 0;
111 unsigned char *get_framebuffer()
113 return gfx->framebuffer;
116 Pixmap *get_framebuffer_pixmap()
121 Rect get_screen_size()
123 return gfx->screen_rect;
126 int get_color_depth()
128 return gfx->color_depth;
131 void set_clipping_rect(const Rect &rect)
133 gfx->clipping_rect = rect_intersection(rect, get_screen_size());
136 const Rect &get_clipping_rect()
138 return gfx->clipping_rect;
141 void set_cursor_visibility(bool visible)
144 curs.enable = visible ? 1 : 0;
146 if(ioctl(gfx->dev_fd, FBIO_CURSOR, &curs) == -1) {
147 fprintf(stderr, "Cannot toggle cursor visibility : %s\n", strerror(errno));
157 unsigned long arg = 0;
158 if(ioctl(gfx->dev_fd, FBIO_WAITFORVSYNC, &arg) == -1) {
159 // printf("ioctl error %s\n", strerror(errno));
163 #endif // WINNIE_FBDEV