From 12919453d35bb3a8ef3b0e430c8cbc96558c881c Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 6 May 2020 09:27:28 +0200 Subject: [PATCH] free the buffer of font decompression --- src/lv_core/lv_refr.c | 2 ++ src/lv_font/lv_font_fmt_txt.c | 26 ++++++++++++++++++-------- src/lv_font/lv_font_fmt_txt.h | 5 +++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index 3c6d18904..2992525f8 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -16,6 +16,7 @@ #include "../lv_misc/lv_math.h" #include "../lv_misc/lv_gc.h" #include "../lv_draw/lv_draw.h" +#include "../lv_font/lv_font_fmt_txt.h" #if LV_USE_PERF_MONITOR #include "../lv_widgets/lv_label.h" @@ -245,6 +246,7 @@ void lv_disp_refr_task(lv_task_t * task) } lv_mem_buf_free_all(); + lv_font_clean_up_fmt_txt(); #if LV_USE_PERF_MONITOR && LV_USE_LABEL static lv_obj_t * perf_label = NULL; diff --git a/src/lv_font/lv_font_fmt_txt.c b/src/lv_font/lv_font_fmt_txt.c index c5c47dc75..800b2ca92 100644 --- a/src/lv_font/lv_font_fmt_txt.c +++ b/src/lv_font/lv_font_fmt_txt.c @@ -47,7 +47,7 @@ static inline uint8_t rle_next(void); /********************** * STATIC VARIABLES **********************/ - +static uint8_t * decompr_buf; static uint32_t rle_rdp; static const uint8_t * rle_in; static uint8_t rle_bpp; @@ -88,19 +88,18 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic } /*Handle compressed bitmap*/ else { - static uint8_t * buf = NULL; uint32_t gsize = gdsc->box_w * gdsc->box_h; if(gsize == 0) return NULL; - if(lv_mem_get_size(buf) < gsize) { - buf = lv_mem_realloc(buf, gsize); - LV_ASSERT_MEM(buf); - if(buf == NULL) return NULL; + if(lv_mem_get_size(decompr_buf) < gsize) { + decompr_buf = lv_mem_realloc(decompr_buf, gsize); + LV_ASSERT_MEM(decompr_buf); + if(decompr_buf == NULL) return NULL; } - decompress(&fdsc->glyph_bitmap[gdsc->bitmap_index], buf, gdsc->box_w, gdsc->box_h, (uint8_t)fdsc->bpp); - return buf; + decompress(&fdsc->glyph_bitmap[gdsc->bitmap_index], decompr_buf, gdsc->box_w, gdsc->box_h, (uint8_t)fdsc->bpp); + return decompr_buf; } /*If not returned earlier then the letter is not found in this font*/ @@ -158,6 +157,17 @@ bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * return true; } +/** + * Free the allocated memories. + */ +void lv_font_clean_up_fmt_txt(void) +{ + if(decompr_buf) { + lv_mem_free(decompr_buf); + decompr_buf = NULL; + } +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/lv_font/lv_font_fmt_txt.h b/src/lv_font/lv_font_fmt_txt.h index ca16d533a..edd69626a 100644 --- a/src/lv_font/lv_font_fmt_txt.h +++ b/src/lv_font/lv_font_fmt_txt.h @@ -218,6 +218,11 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t lett bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next); +/** + * Free the allocated memories. + */ +void lv_font_clean_up_fmt_txt(void); + /********************** * MACROS **********************/