From 1d6e5855e2fbc75cda078878341184f29a831fd6 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Fri, 5 Apr 2024 18:18:47 +0200 Subject: [PATCH] Massively reduce the default size of bump alloc pool Also limit the resolution of the terminal if necessary and force no-canvas mode if using bump allocator --- backends/fb.c | 16 +++++++++++++++- backends/fb.h | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/backends/fb.c b/backends/fb.c index b501400..6717a43 100644 --- a/backends/fb.c +++ b/backends/fb.c @@ -35,7 +35,10 @@ void *memcpy(void *, const void *, size_t); #ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC #ifndef FLANTERM_FB_BUMP_ALLOC_POOL_SIZE -#define FLANTERM_FB_BUMP_ALLOC_POOL_SIZE (64*1024*1024) +#define FLANTERM_FB_BUMP_ALLOC_POOL_SIZE 873000 + +#define FLANTERM_FB_WIDTH_LIMIT 1920 +#define FLANTERM_FB_HEIGHT_LIMIT 1200 #endif static uint8_t bump_alloc_pool[FLANTERM_FB_BUMP_ALLOC_POOL_SIZE]; @@ -884,6 +887,17 @@ struct flanterm_context *flanterm_fb_init( ) { #ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC size_t orig_bump_alloc_ptr = bump_alloc_ptr; + + // Limit terminal size if needed + if (width > FLANTERM_FB_WIDTH_LIMIT || height > FLANTERM_FB_HEIGHT_LIMIT) { + size_t width_limit = width > FLANTERM_FB_WIDTH_LIMIT ? FLANTERM_FB_WIDTH_LIMIT : width; + size_t height_limit = height > FLANTERM_FB_HEIGHT_LIMIT ? FLANTERM_FB_HEIGHT_LIMIT : height; + + framebuffer = (uint32_t *)((uintptr_t)framebuffer + ((((height / 2) - (height_limit / 2)) * pitch) + (((width / 2) - (width_limit / 2)) * 4))); + + width = width_limit; + height = height_limit; + } #endif #ifdef FLANTERM_FB_SUPPORT_BPP diff --git a/backends/fb.h b/backends/fb.h index 34f11e8..ae4d4f9 100644 --- a/backends/fb.h +++ b/backends/fb.h @@ -36,6 +36,10 @@ extern "C" { #include "../flanterm.h" +#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC +# define FLANTERM_FB_DISABLE_CANVAS 1 +#endif + #define FLANTERM_FB_FONT_GLYPHS 256 struct flanterm_fb_char {