···
void *memset(void *, int, size_t);
void *memcpy(void *, const void *, size_t);
35
+
#ifdef FLANTERM_FB_ENABLE_BUMP_ALLOC
37
+
#ifndef FLANTERM_FB_BUMP_ALLOC_POOL_SIZE
38
+
#define FLANTERM_FB_BUMP_ALLOC_POOL_SIZE (64*1024*1024)
41
+
static uint8_t bump_alloc_pool[FLANTERM_FB_BUMP_ALLOC_POOL_SIZE];
42
+
static size_t bump_alloc_ptr = 0;
44
+
static void *bump_alloc(size_t s) {
45
+
size_t next_ptr = bump_alloc_ptr + s;
46
+
if (next_ptr > FLANTERM_FB_BUMP_ALLOC_POOL_SIZE) {
49
+
void *ret = &bump_alloc_pool[bump_alloc_ptr];
50
+
bump_alloc_ptr = next_ptr;
// Builtin font originally taken from:
// https://github.com/viler-int10h/vga-text-mode-fonts/raw/master/FONTS/PC-OTHER/TOSH-SAT.F16
static const uint8_t builtin_font[] = {
···
static void flanterm_fb_deinit(struct flanterm_context *_ctx, void (*_free)(void *, size_t)) {
struct flanterm_fb_context *ctx = (void *)_ctx;
831
+
if (_free == NULL) {
_free(ctx->font_bits, ctx->font_bits_size);
_free(ctx->font_bool, ctx->font_bool_size);
_free(ctx->grid, ctx->grid_size);
···
struct flanterm_context *flanterm_fb_init(
void *(*_malloc)(size_t),
850
+
void (*_free)(void *, size_t),
uint32_t *framebuffer, size_t width, size_t height, size_t pitch,
#ifndef FLANTERM_FB_DISABLE_CANVAS
···
size_t font_scale_x, size_t font_scale_y,
836
-
struct flanterm_fb_context *ctx = _malloc(sizeof(struct flanterm_fb_context));
862
+
#ifdef FLANTERM_FB_ENABLE_BUMP_ALLOC
863
+
size_t orig_bump_alloc_ptr = bump_alloc_ptr;
866
+
if (_malloc == NULL) {
867
+
#ifdef FLANTERM_FB_ENABLE_BUMP_ALLOC
868
+
_malloc = bump_alloc;
874
+
struct flanterm_fb_context *ctx = NULL;
875
+
ctx = _malloc(sizeof(struct flanterm_fb_context));
struct flanterm_context *_ctx = (void *)ctx;
···
ctx->font_width = font_width;
ctx->font_height = font_height;
905
-
ctx->font_bits = _malloc(FONT_BYTES);
906
-
memcpy(ctx->font_bits, font, FONT_BYTES);
947
+
ctx->font_bits_size = FONT_BYTES;
948
+
ctx->font_bits = _malloc(ctx->font_bits_size);
949
+
if (ctx->font_bits == NULL) {
952
+
memcpy(ctx->font_bits, font, ctx->font_bits_size);
ctx->font_width = font_width = 8;
ctx->font_height = font_height = 16;
956
+
ctx->font_bits_size = FONT_BYTES;
911
-
ctx->font_bits = _malloc(FONT_BYTES);
912
-
memcpy(ctx->font_bits, builtin_font, FONT_BYTES);
958
+
ctx->font_bits = _malloc(ctx->font_bits_size);
959
+
if (ctx->font_bits == NULL) {
962
+
memcpy(ctx->font_bits, builtin_font, ctx->font_bits_size);
915
-
ctx->font_bits_size = FONT_BYTES;
ctx->font_width += font_spacing;
ctx->font_bool_size = FLANTERM_FB_FONT_GLYPHS * font_height * ctx->font_width * sizeof(bool);
ctx->font_bool = _malloc(ctx->font_bool_size);
971
+
if (ctx->font_bool == NULL) {
for (size_t i = 0; i < FLANTERM_FB_FONT_GLYPHS; i++) {
uint8_t *glyph = &ctx->font_bits[i * font_height];
···
ctx->grid_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_char);
ctx->grid = _malloc(ctx->grid_size);
1018
+
if (ctx->grid == NULL) {
for (size_t i = 0; i < _ctx->rows * _ctx->cols; i++) {
ctx->grid[i].fg = ctx->text_fg;
···
ctx->queue_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item);
ctx->queue = _malloc(ctx->queue_size);
1029
+
if (ctx->queue == NULL) {
memset(ctx->queue, 0, ctx->queue_size);
ctx->map_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item *);
ctx->map = _malloc(ctx->map_size);
1037
+
if (ctx->map == NULL) {
memset(ctx->map, 0, ctx->map_size);
#ifndef FLANTERM_FB_DISABLE_CANVAS
ctx->canvas_size = ctx->width * ctx->height * sizeof(uint32_t);
ctx->canvas = _malloc(ctx->canvas_size);
1045
+
if (ctx->canvas == NULL) {
memcpy(ctx->canvas, canvas, ctx->canvas_size);
···
flanterm_fb_full_refresh(_ctx);
1087
+
#ifdef FLANTERM_FB_ENABLE_BUMP_ALLOC
1088
+
if (_malloc == bump_alloc) {
1089
+
bump_alloc_ptr = orig_bump_alloc_ptr;
1094
+
if (_free == NULL) {
1098
+
#ifndef FLANTERM_FB_DISABLE_CANVAS
1099
+
if (ctx->canvas != NULL) {
1100
+
_free(ctx->canvas, ctx->canvas_size);
1103
+
if (ctx->map != NULL) {
1104
+
_free(ctx->map, ctx->map_size);
1106
+
if (ctx->queue != NULL) {
1107
+
_free(ctx->queue, ctx->queue_size);
1109
+
if (ctx->grid != NULL) {
1110
+
_free(ctx->grid, ctx->grid_size);
1112
+
if (ctx->font_bool != NULL) {
1113
+
_free(ctx->font_bool, ctx->font_bool_size);
1115
+
if (ctx->font_bits != NULL) {
1116
+
_free(ctx->font_bits, ctx->font_bits_size);
1118
+
if (ctx != NULL) {
1119
+
_free(ctx, sizeof(struct flanterm_fb_context));