summaryrefslogtreecommitdiff
path: root/plat.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-07-06 18:40:57 +1000
committerquou <quou@disroot.org>2024-07-06 18:40:57 +1000
commit2693d0e46cf55c613e560d2eed8a2f762fe76bb5 (patch)
treeeda3c4571c16e24602e5adc3d59b2b99aef3e3cf /plat.c
parente6f8a3356a91e0304e9965c7b8bfc2f06a2b79cc (diff)
Allocate a max viewport so that re-creating images isn't needed.
Diffstat (limited to 'plat.c')
-rw-r--r--plat.c39
1 files changed, 17 insertions, 22 deletions
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;