X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fgfx.cc;h=b72e43bcf1fa67788a349c72366e73a6379aacde;hb=e2626c41c841dbbfb64ddf6341b4e23089036299;hp=226d26954369b37c945bfe69dd6494bcb0b4a1d2;hpb=094e53b80e5576db6c86bb7dc6141b0cff7fa665;p=winnie diff --git a/src/gfx.cc b/src/gfx.cc index 226d269..b72e43b 100644 --- a/src/gfx.cc +++ b/src/gfx.cc @@ -1,129 +1,175 @@ -#include -#include -#include -#include +/* +winnie - an experimental window system -#include -#include -#include -#include +Copyright (C) 2013 Eleni Maria Stea -#include +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. -#include "gfx.h" +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. -#define FRAMEBUFFER_SIZE(xsz, ysz, bpp) ((xsz) * (ysz) * (bpp) / CHAR_BIT) +You should have received a copy of the GNU General Public License +along with this program. If not, see . -static unsigned char *framebuffer; -static int dev_fd = -1; +Author: Eleni Maria Stea +*/ + +#include -static Rect screen_rect; -static int color_depth; //bits per pixel +#include "geom.h" +#include "gfx.h" -bool init_gfx() +void clear_screen(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 screen_rect = get_screen_size(); + fill_rect(screen_rect, r, g, b); +} - 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; - } +void fill_rect(const Rect &rect, int r, int g, int b) +{ + Rect drect = rect; + Rect screen_rect = get_screen_size(); + Rect clipping_rect = get_clipping_rect(); - 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); + if(drect.x < clipping_rect.x) { + drect.width -= clipping_rect.x - drect.x; + drect.x = clipping_rect.x; + } - 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; + } -int get_color_depth() -{ - return color_depth; -} + int yend = dest_y + height; + if(yend >= irect.height) { + height -= yend - irect.height; + } -void clear_screen(int r, int g, int b) -{ - fill_rect(screen_rect, r, g, b); -} + if(width <= 0 || height <= 0) { + return; + } -void fill_rect(const Rect &rect, int r, int g, int b) -{ - unsigned char *fb = framebuffer + (rect.x + screen_rect.width * rect.y) * 4; - for(int i=0; i= irect.width) { + width -= xend - irect.width; } - if(dest_y < screen_rect.y) { - dest_rect.y = screen_rect.y; + int yend = dest_y + height; + if(yend >= irect.height) { + height -= yend - irect.height; } - //TODO :p zzz + 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