*work in progress*
authorEleni Maria Stea <elene.mst@gmail.com>
Sat, 16 Feb 2013 12:26:42 +0000 (14:26 +0200)
committerEleni Maria Stea <elene.mst@gmail.com>
Sat, 16 Feb 2013 12:26:42 +0000 (14:26 +0200)
dirty rectangles, psaux device

src/geom.h
src/gfx.cc
src/gfx.h
src/mouse.cc
src/wm.cc
src/wm.h

index c294b54..9c00b41 100644 (file)
@@ -6,10 +6,7 @@ struct Rect {
        int width, height;
 };
 
-// TODO probably need to implement something like this:
-/*
 Rect rect_union(const Rect &a, const Rect &b);
 Rect rect_intersection(const Rect &a, const Rect &b);
-*/
 
 #endif // GEOM_H_
index 54ed7f9..0afa479 100644 (file)
@@ -14,7 +14,7 @@
 
 #define FRAMEBUFFER_SIZE(xsz, ysz, bpp) ((xsz) * (ysz) * (bpp) / CHAR_BIT)
 
-static unsigned char* framebuffer;
+static unsigned char *framebuffer;
 static int dev_fd = -1;
 
 static Rect screen_rect;
@@ -65,7 +65,7 @@ void destroy_gfx()
        framebuffer = 0;
 }
 
-unsigned char* get_framebuffer()
+unsigned char *get_framebuffer()
 {
        return framebuffer;
 }
@@ -82,12 +82,19 @@ int get_color_depth()
 
 void clear_screen(int r, int g, int b)
 {
-       unsigned char* fb = framebuffer;
-       for(int i=0; i<screen_rect.width * screen_rect.height; i++) {
-               *fb++ = r;
-               *fb++ = g;
-               *fb++ = b;
-               fb++;
+       fill_rect(screen_rect, r, g, b);
+}
+
+void fill_rect(const Rect &rect, int r, int g, int b)
+{
+       unsigned char *fb = framebuffer + rect.x + screen_rect.width * rect.y; 
+       for(int i=0; i<rect.height; i++) {
+               for(int j=0; j<rect.width; j++) {
+                       fb[j * 4] = r;
+                       fb[j * 4 + 1] = g;
+                       fb[j * 4 + 2] = b;
+               }
+               fb += screen_rect.width * 4;
        }
 }
 
index 8734e2d..ec31bc8 100644 (file)
--- a/src/gfx.h
+++ b/src/gfx.h
@@ -6,11 +6,12 @@
 bool init_gfx();
 void destroy_gfx();
 
-unsigned char* get_framebuffer();
+unsigned char *get_framebuffer();
 Rect get_screen_size();
 int get_color_depth();
 
 void clear_screen(int r, int g, int b);
+void fill_rect(const Rect &rect, int r, int g, int b);
 
 void set_cursor_visibility(bool visible);
 
index c461810..c83377c 100644 (file)
@@ -1,3 +1,13 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <unistd.h>
+
 #include "mouse.h"
 #include "geom.h"
 
@@ -7,13 +17,17 @@ static int pointer_x, pointer_y;
 
 bool init_mouse()
 {
-       // TODO open /dev/psaux (see O_NONBLOCK comment below)
+       if((dev_fd = open("/dev/psaux", O_NONBLOCK)) == -1) {
+               fprintf(stderr, "Cannot open /dev/psaux : %s\n", strerror(errno));
+               return false;
+       }
+
        return true;
 }
 
 void destroy_mouse()
 {
-       // TODO close /dev/psaux
+       close(dev_fd);
 }
 
 void set_mouse_bounds(const Rect &rect)
index 0428a7c..16b5a2a 100644 (file)
--- a/src/wm.cc
+++ b/src/wm.cc
@@ -1,8 +1,8 @@
 #include <stdexcept>
+#include "gfx.h"
 #include "wm.h"
 #include "window.h"
 
-
 WindowManager *wm;
 static WindowManager wminst;
 
@@ -13,6 +13,10 @@ WindowManager::WindowManager()
        } else {
                throw std::runtime_error("Trying to create a second instance of WindowManager!\n");
        }
+
+       bg_color[0] = 210;
+       bg_color[1] = 106;
+       bg_color[2] = 106;
 }
 
 void WindowManager::invalidate_region(const Rect &rect)
@@ -22,15 +26,23 @@ void WindowManager::invalidate_region(const Rect &rect)
 
 void WindowManager::process_windows()
 {
-       //TODO:
-       //sta dirty rectangles na brw to union
-       //na eleg3w poia einai sto dirty area k na ta kanw dirty
-       //na ka8arizw ta dirty areas
-       //prwta render to bg
-       //meta ola ta dirty:
+       if(dirty_rects.empty()) {
+               return;
+       }
+
+       std::list<Rect>::iterator drit = dirty_rects.begin();
+       Rect uni = *drit++;
+       while(drit != dirty_rects.end()) {
+               uni = rect_union(uni, *drit++);
+       }
+       dirty_rects.clear();
+
+       fill_rect(uni, bg_color[0], bg_color[1], bg_color[2]);
+       
        std::list<Window*>::iterator it = windows.begin();
        while(it != windows.end()) {
-               if((*it)->dirty) {
+               Rect intersect = rect_intersection((*it)->rect, uni); 
+               if(intersect.width && intersect.height) {
                        (*it)->draw();
                }
        }
index 27ae316..a754186 100644 (file)
--- a/src/wm.h
+++ b/src/wm.h
@@ -11,6 +11,8 @@ private:
        std::list<Window*> windows;
        std::list<Rect> dirty_rects;
 
+       int bg_color[3];
+
 public:
        WindowManager();