X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;ds=sidebyside;f=src%2Fgfx.cc;h=1da29539767792a7823f303ad0bc70abed2473a9;hb=ed66dbc4e6c017dad675a83dbcd7619b1b5d1e7d;hp=54ed7f96a757d847ba852e93871e4dd02563b851;hpb=0860ce537422597075fbc63ddcc9a73303362a93;p=winnie diff --git a/src/gfx.cc b/src/gfx.cc index 54ed7f9..1da2953 100644 --- a/src/gfx.cc +++ b/src/gfx.cc @@ -1,102 +1,155 @@ -#include -#include -#include #include -#include -#include -#include -#include - -#include - +#include "geom.h" #include "gfx.h" -#define FRAMEBUFFER_SIZE(xsz, ysz, bpp) ((xsz) * (ysz) * (bpp) / CHAR_BIT) +static Rect clipping_rect; + +void set_clipping_rect(const Rect &rect) +{ + clipping_rect = rect_intersection(rect, get_screen_size()); +} -static unsigned char* framebuffer; -static int dev_fd = -1; +const Rect &get_clipping_rect() +{ + return clipping_rect; +} -static Rect screen_rect; -static int color_depth; //bits per pixel +void clear_screen(int r, int g, int b) +{ + Rect screen_rect = get_screen_size(); + fill_rect(screen_rect, r, g, b); +} -bool init_gfx() +void fill_rect(const Rect &rect, int r, int g, int b) { - if((dev_fd = open("/dev/fb0", O_RDWR)) == -1) { - fprintf(stderr, "Cannot open /dev/fb0 : %s\n", strerror(errno)); - return false; - } + Rect drect = rect; + Rect screen_rect = get_screen_size(); - fb_var_screeninfo sinfo; - if(ioctl(dev_fd, FBIOGET_VSCREENINFO, &sinfo) == -1) { - close(dev_fd); - dev_fd = -1; - fprintf(stderr, "Unable to get screen info : %s\n", strerror(errno)); - return false; + if(drect.x < clipping_rect.x) { + drect.width -= clipping_rect.x - drect.x; + drect.x = clipping_rect.x; } - printf("width : %d height : %d\n : bpp : %d\n", sinfo.xres, sinfo.yres, sinfo.bits_per_pixel); - printf("virtual w: %d virtual h: %d\n", sinfo.xres_virtual, sinfo.yres_virtual); - - screen_rect.x = screen_rect.y = 0; - screen_rect.width = sinfo.xres_virtual; - screen_rect.height = sinfo.yres_virtual; - color_depth = sinfo.bits_per_pixel; + if(drect.y < clipping_rect.y) { + drect.height -= clipping_rect.y - drect.y; + drect.y = clipping_rect.y; + } - int sz = FRAMEBUFFER_SIZE(screen_rect.width, screen_rect.height, color_depth); - framebuffer = (unsigned char*)mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0); + if(drect.x + drect.width >= clipping_rect.x + clipping_rect.width) { + drect.width = clipping_rect.width + clipping_rect.x - drect.x; + } - if(framebuffer == (void*)-1) { - close(dev_fd); - dev_fd = -1; - fprintf(stderr, "Cannot map the framebuffer to memory : %s\n", strerror(errno)); - return false; + if(drect.y + drect.height >= clipping_rect.y + clipping_rect.height) { + drect.height = clipping_rect.height + clipping_rect.y - drect.y; } - return true; + unsigned char *fb = get_framebuffer() + (drect.x + screen_rect.width * drect.y) * 4; + for(int i=0; i= irect.width) { + width -= xend - irect.width; + } -void clear_screen(int r, int g, int b) -{ - unsigned char* fb = framebuffer; - for(int i=0; i= irect.height) { + height -= yend - irect.height; + } + + if(width <= 0 || height <= 0) { + return; + } + + unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4; + unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4; + + for(int i=0; i= irect.width) { + width -= xend - irect.width; + } + + int yend = dest_y + height; + if(yend >= irect.height) { + height -= yend - irect.height; + } + + if(width <= 0 || height <= 0) { + return; + } + + unsigned char *sptr = src_img + (src_rect.y * src_rect.width + src_rect.x) * 4; + unsigned char *dptr = dest_img + (dest_y * dest_rect.width + dest_x) * 4; + + for(int i=0; i