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:
parent
b40820272f
commit
a322c06850
8 changed files with 49 additions and 8 deletions
|
@ -74,4 +74,8 @@ long time_jiffies() { return 0; }
|
|||
|
||||
long time_now() { return 0; }
|
||||
|
||||
void time_sleep(long duration) { }
|
||||
void time_sleep(long duration) { }
|
||||
|
||||
void* truetype_malloc(int size) { return 0; }
|
||||
|
||||
void truetype_free(void* ptr) { }
|
4
src/truetype/stb_truetype.h
vendored
4
src/truetype/stb_truetype.h
vendored
|
@ -468,8 +468,8 @@ int main(int arg, char **argv)
|
|||
// #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h
|
||||
#ifndef STBTT_malloc
|
||||
#include <stdlib.h>
|
||||
#define STBTT_malloc(x,u) ((void)(u),malloc(x))
|
||||
#define STBTT_free(x,u) ((void)(u),free(x))
|
||||
#define STBTT_malloc(x,u) ((void)(u),_Z15truetype_malloci(x))
|
||||
#define STBTT_free(x,u) ((void)(u),_Z13truetype_freePv(x))
|
||||
#endif
|
||||
|
||||
#ifndef STBTT_assert
|
||||
|
|
6
src/truetype/truetype.c
vendored
6
src/truetype/truetype.c
vendored
|
@ -1,3 +1,6 @@
|
|||
void* _Z15truetype_malloci(int size);
|
||||
void _Z13truetype_freePv(void* ptr);
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include "stb_truetype.h"
|
||||
|
||||
|
@ -5,7 +8,8 @@ unsigned char* stbtt_RenderText(stbtt_fontinfo* info, int b_w, int b_h, int l_h,
|
|||
{
|
||||
// https://github.com/justinmeiners/stb-truetype-example
|
||||
/* create a bitmap for the phrase */
|
||||
unsigned char* bitmap = calloc(b_w * b_h, sizeof(unsigned char));
|
||||
unsigned char* bitmap = STBTT_malloc(b_w * b_h, sizeof(unsigned char));
|
||||
memset(bitmap, 0, b_w * b_h);
|
||||
|
||||
/* calculate font scaling */
|
||||
float scale = stbtt_ScaleForPixelHeight(info, l_h);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue