feat(nuttx): add defer feature for nuttx image cache (#5967)

This commit is contained in:
Benign X
2024-03-27 14:36:29 +08:00
committed by GitHub
parent 03b5f583bc
commit 000699827f

View File

@@ -34,6 +34,8 @@ typedef struct {
struct mm_heap_s * heap;
uint32_t heap_size;
bool initialized;
} lv_nuttx_ctx_image_cache_t;
/**********************
* STATIC PROTOTYPES
@@ -63,10 +65,29 @@ void lv_nuttx_image_cache_init(void)
ctx = lv_malloc_zeroed(sizeof(lv_nuttx_ctx_image_cache_t));
LV_ASSERT_MALLOC(ctx);
ctx->mem_size = LV_CACHE_DEF_SIZE;
ctx->initialized = false;
}
/**********************
* STATIC FUNCTIONS
**********************/
static bool defer_init(void)
{
if(ctx->mem != NULL && ctx->heap != NULL) {
return true;
}
ctx->mem_size = img_cache_p->max_size;
ctx->mem = malloc(ctx->mem_size);
LV_ASSERT_MALLOC(ctx->mem);
if(ctx->mem == NULL) {
LV_LOG_ERROR("Failed to allocate memory for image cache");
ctx->initialized = false;
return false;
}
ctx->heap = mm_initialize(
HEAP_NAME,
ctx->mem,
@@ -86,16 +107,19 @@ void lv_nuttx_image_cache_init(void)
LV_LOG_USER(" mxordblk: %d", info.mxordblk);
LV_LOG_USER(" uordblks: %d", info.uordblks);
LV_LOG_USER(" fordblks: %d", info.fordblks);
}
/**********************
* STATIC FUNCTIONS
**********************/
ctx->initialized = true;
return true;
}
static void * malloc_cb(size_t size_bytes, lv_color_format_t color_format)
{
LV_UNUSED(color_format);
if(ctx->initialized == false) {
if(defer_init() == false) return NULL;
}
/*Allocate larger memory to be sure it can be aligned as needed*/
size_bytes += LV_DRAW_BUF_ALIGN - 1;
uint32_t cache_max_size = lv_cache_get_max_size(img_cache_p, NULL);