Everywhere: Give stbtt its own 32MB static memory pool

At boot time, we preallocate 32MB of RAM to reuse for all malloc()
requests by stbtt_RenderText(), which should be more than enough for the
primary use case (browsing web pages).
This commit is contained in:
Alec Murphy 2025-04-19 21:01:14 -04:00
parent b40820272f
commit a322c06850
8 changed files with 49 additions and 8 deletions

31
System/FFI/TrueType.HC Normal file
View file

@ -0,0 +1,31 @@
U64 stbtt_heap = MAlloc(1048576 * 32);
U64 stbtt_pos = 0;
U64 @stbtt_malloc(I64 size)
{
//"stbtt_malloc(%d)\n", size;
U64 ptr = stbtt_heap + stbtt_pos;
stbtt_pos += size;
return ptr;
}
U0 @stbtt_free(U8* ptr)
{
//"stbtt_free(0x%08x)\n", ptr;
}
U0 _Z15truetype_malloci()
{
PUSH_SYSV_REGS
GET_SYSV_ARGS
@stbtt_malloc(p0);
POP_SYSV_REGS
}
U0 _Z13truetype_freePv()
{
PUSH_SYSV_REGS
GET_SYSV_ARGS
@stbtt_free(p0);
POP_SYSV_REGS
}

View file

@ -1206,7 +1206,7 @@ I64 @get_truetype_baseline(U8* font_name, I64 size)
dc->width -= 16;
dc->height -= size / 4;
res = Y2Pos(dc);
DCDel(dc);
Free(dc);
return res;
}
@ -1232,7 +1232,7 @@ U0 Text2D(Context2D* ctx, U8* font_name, I64 x, I64 y, I64 size, U32 color, U8*
}
BlendRect2D(text_ctx, ctx);
DelContext2D(text_ctx);
DCDel(dc);
Free(dc);
}
Context2D* FastBoxBlur2D(Context2D* img, I64 radius)

View file

@ -23,6 +23,7 @@ WinToTop(adam_task);
#include "FFI/LibC";
#include "FFI/New";
#include "FFI/ELF64";
#include "FFI/TrueType";
// stb_image library
#include "Utilities/Image";

View file

@ -44,6 +44,7 @@ U8* @stbtt_RenderText(stbtt_fontinfo* info, I32 b_w, I32 b_h, I32 l_h, I32* word
U64 reg R8 r8 = word;
U64 reg R9 r9 = advance;
no_warn rdi, rsi, rdx, rcx, r8, r9;
stbtt_pos = 0;
asm {
MOV RAX, STBTT_RENDERTEXT
CALL RAX