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
This commit is contained in:
mintsuki 2024-04-05 18:18:47 +02:00
parent 9b51770c7a
commit 1d6e5855e2
2 changed files with 19 additions and 1 deletions

View File

@ -35,7 +35,10 @@ void *memcpy(void *, const void *, size_t);
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC #ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
#ifndef FLANTERM_FB_BUMP_ALLOC_POOL_SIZE #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 #endif
static uint8_t bump_alloc_pool[FLANTERM_FB_BUMP_ALLOC_POOL_SIZE]; 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 #ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
size_t orig_bump_alloc_ptr = bump_alloc_ptr; 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 #endif
#ifdef FLANTERM_FB_SUPPORT_BPP #ifdef FLANTERM_FB_SUPPORT_BPP

View File

@ -36,6 +36,10 @@ extern "C" {
#include "../flanterm.h" #include "../flanterm.h"
#ifndef FLANTERM_FB_DISABLE_BUMP_ALLOC
# define FLANTERM_FB_DISABLE_CANVAS 1
#endif
#define FLANTERM_FB_FONT_GLYPHS 256 #define FLANTERM_FB_FONT_GLYPHS 256
struct flanterm_fb_char { struct flanterm_fb_char {