fbdev version works with truetype
[winnie] / src / fbdev / gfx.cc
index c207b0c..742b6c6 100644 (file)
@@ -7,6 +7,7 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+#include <sys/time.h>
 #include <unistd.h>
 
 #include <linux/fb.h>
@@ -21,6 +22,8 @@ static int dev_fd = -1;
 static Rect screen_rect;
 static int color_depth; // bits per pixel
 
+static Pixmap *pixmap;
+
 bool init_gfx()
 {
        if((dev_fd = open("/dev/fb0", O_RDWR)) == -1) {
@@ -54,6 +57,24 @@ bool init_gfx()
                return false;
        }
 
+// TODO: uncomment when I find how to use intelfb instead of i915 GRRRR.-      
+       fb_vblank vblank;
+       if(ioctl(dev_fd, FBIOGET_VBLANK, &vblank) == -1) {
+//             fprintf(stderr, "FBIOGET_VBLANK error: %s\n", strerror(errno));
+       }
+/*     
+       else {
+               printf("flags: %x\n", vblank.flags);
+               printf("count: %d\n", vblank.count);
+               printf("beam position: %d, %d\n", vblank.hcount, vblank.vcount);
+       }
+*/
+
+       pixmap = new Pixmap;
+       pixmap->width = screen_rect.width;
+       pixmap->height = screen_rect.height;
+       pixmap->pixels = framebuffer;
+
        return true;
 }
 
@@ -69,6 +90,8 @@ void destroy_gfx()
 
        munmap(framebuffer, FRAMEBUFFER_SIZE(screen_rect.width, screen_rect.height, color_depth));
        framebuffer = 0;
+
+       pixmap->pixels = 0;
 }
 
 unsigned char *get_framebuffer()
@@ -76,6 +99,11 @@ unsigned char *get_framebuffer()
        return framebuffer;
 }
 
+Pixmap *get_framebuffer_pixmap()
+{
+       return pixmap;
+}
+
 Rect get_screen_size()
 {
        return screen_rect;
@@ -96,18 +124,20 @@ void fill_rect(const Rect &rect, int r, int g, int b)
        Rect drect = rect;
 
        if(drect.x < screen_rect.x) {
+               drect.width -= screen_rect.x - drect.x;
                drect.x = screen_rect.x;
        }
 
        if(drect.y < screen_rect.y) {
+               drect.height -= screen_rect.y - drect.y;
                drect.y = screen_rect.y;
        }
 
-       if(drect.x + drect.width > screen_rect.width) {
+       if(drect.x + drect.width >= screen_rect.x + screen_rect.width) {
                drect.width = screen_rect.width - drect.x;
        }
 
-       if(drect.y + drect.height > screen_rect.height) {
+       if(drect.y + drect.height >= screen_rect.y + screen_rect.height) {
                drect.height = screen_rect.height - drect.y;
        }
 
@@ -231,4 +261,12 @@ void gfx_update()
 {
 }
 
+void wait_vsync()
+{
+       unsigned long arg = 0;
+       if(ioctl(dev_fd, FBIO_WAITFORVSYNC, &arg) == -1) {
+//             printf("ioctl error %s\n", strerror(errno));
+       }
+}
+
 #endif // WINNIE_FBDEV