From 2693d0e46cf55c613e560d2eed8a2f762fe76bb5 Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 6 Jul 2024 18:40:57 +1000 Subject: Allocate a max viewport so that re-creating images isn't needed. --- plat.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'plat.c') diff --git a/plat.c b/plat.c index e0d72be..f0d60ba 100644 --- a/plat.c +++ b/plat.c @@ -1,5 +1,6 @@ #include "config.h" #include "error.h" +#include "maths.h" #include "memory.h" #include "plat.h" @@ -184,16 +185,10 @@ void init_rendering( XWindowAttributes* wa ) { Colour* p, * fb; - int w = i->w = wa->width; - int h = i->h = wa->height; - int tw = (w + a->s) / a->s; - int th = (h + a->s) / a->s; - a->w = tw; - a->h = th; - if (i->bb) { - heap_free(a->heap, a->fb); - XDestroyImage(i->bb); - } + int w = max_pc_window_w; + int h = max_pc_window_h; + int tw = max_vp_w; + int th = max_vp_h; p = malloc(sizeof *p * w * h); fb = heap_alloc(a->heap, sizeof *p * tw * th); if (!p || !fb) { @@ -275,6 +270,10 @@ void init_window(App* a, App_Internal* i, const char* n) { print_war("Detected BGR. Colours will look fucked.\n"); } init_rendering(a, i, &wa); + a->w = (wa.width + a->s) / a->s; + a->h = (wa.height + a->s) / a->s; + i->w = wa.width; + i->h = wa.height; } App* new_app(Heap* mem, int w, int h, const char* n) { @@ -315,7 +314,6 @@ void app_begin(App* a) { while (XPending(d)) { XEvent e; XWindowAttributes wa; - int nw, nh; XNextEvent(d, &e); switch (e.type) { case ClientMessage: @@ -328,15 +326,12 @@ void app_begin(App* a) { break; case Expose: XGetWindowAttributes(d, w, &wa); - nw = wa.width; - nh = wa.height; - if ( - !i->bb || - nw != i->w || - nh != i->h - ) { - init_rendering(a, i, &wa); - } + a->w = (wa.width + a->s) / a->s; + a->h = (wa.height + a->s) / a->s; + a->w = mini(a->w, max_vp_w); + a->h = mini(a->h, max_vp_w); + i->w = mini(wa.width, max_pc_window_w); + i->h = mini(wa.height, max_pc_window_h); break; case MotionNotify: a->mx = e.xmotion.x / a->s; @@ -362,7 +357,7 @@ void app_rencpy( int ix, iy, sw, sh, dw, dh; int dsx, dsy; int dex, dey; - int pidx, fbits = 9; + int pidx; Colour* dst; const Colour* src; unsigned char t; @@ -385,7 +380,7 @@ void app_rencpy( for (ix = dsx; ix < dex; ix++) { sx = (rat_x * (ix << fbits)) >> (fbits * 2); pidx = sx + sy * sw; - dst = &i->bbp[ix + iy * dw]; + dst = &i->bbp[ix + iy * max_pc_window_w]; *dst = src[pidx]; t = dst->r; dst->r = dst->b; -- cgit v1.2.3-54-g00ecf