- memcpy(framebuffer, gfx->pixmap->pixels, gfx->pixmap->width * gfx->pixmap->height * (gfx->color_depth / 8));
+ Rect rect = rect_intersection(upd_rect, gfx->screen_rect);
+ unsigned char *sptr = gfx->pixmap->pixels + (rect.y * gfx->screen_rect.width + rect.x) * 4;
+ unsigned char *dptr = framebuffer + (rect.y * gfx->screen_rect.width + rect.x) * 4;
+
+ for(int i=0; i<rect.height; i++) {
+ memcpy(dptr, sptr, rect.width * 4);
+ sptr += gfx->screen_rect.width * 4;
+ dptr += gfx->screen_rect.width * 4;
+ }