feat(nuttx): add defer feature for nuttx image cache (#5967)
This commit is contained in:
@@ -34,6 +34,8 @@ typedef struct {
|
|||||||
|
|
||||||
struct mm_heap_s * heap;
|
struct mm_heap_s * heap;
|
||||||
uint32_t heap_size;
|
uint32_t heap_size;
|
||||||
|
|
||||||
|
bool initialized;
|
||||||
} lv_nuttx_ctx_image_cache_t;
|
} lv_nuttx_ctx_image_cache_t;
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
@@ -63,10 +65,29 @@ void lv_nuttx_image_cache_init(void)
|
|||||||
ctx = lv_malloc_zeroed(sizeof(lv_nuttx_ctx_image_cache_t));
|
ctx = lv_malloc_zeroed(sizeof(lv_nuttx_ctx_image_cache_t));
|
||||||
LV_ASSERT_MALLOC(ctx);
|
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);
|
ctx->mem = malloc(ctx->mem_size);
|
||||||
LV_ASSERT_MALLOC(ctx->mem);
|
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(
|
ctx->heap = mm_initialize(
|
||||||
HEAP_NAME,
|
HEAP_NAME,
|
||||||
ctx->mem,
|
ctx->mem,
|
||||||
@@ -86,16 +107,19 @@ void lv_nuttx_image_cache_init(void)
|
|||||||
LV_LOG_USER(" mxordblk: %d", info.mxordblk);
|
LV_LOG_USER(" mxordblk: %d", info.mxordblk);
|
||||||
LV_LOG_USER(" uordblks: %d", info.uordblks);
|
LV_LOG_USER(" uordblks: %d", info.uordblks);
|
||||||
LV_LOG_USER(" fordblks: %d", info.fordblks);
|
LV_LOG_USER(" fordblks: %d", info.fordblks);
|
||||||
}
|
|
||||||
|
|
||||||
/**********************
|
ctx->initialized = true;
|
||||||
* STATIC FUNCTIONS
|
return true;
|
||||||
**********************/
|
}
|
||||||
|
|
||||||
static void * malloc_cb(size_t size_bytes, lv_color_format_t color_format)
|
static void * malloc_cb(size_t size_bytes, lv_color_format_t color_format)
|
||||||
{
|
{
|
||||||
LV_UNUSED(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*/
|
/*Allocate larger memory to be sure it can be aligned as needed*/
|
||||||
size_bytes += LV_DRAW_BUF_ALIGN - 1;
|
size_bytes += LV_DRAW_BUF_ALIGN - 1;
|
||||||
uint32_t cache_max_size = lv_cache_get_max_size(img_cache_p, NULL);
|
uint32_t cache_max_size = lv_cache_get_max_size(img_cache_p, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user