From 133aee3fca2f00cf5439117dcdfb2814c5eac586 Mon Sep 17 00:00:00 2001 From: _VIFEXTech Date: Mon, 4 Mar 2024 10:17:04 +0800 Subject: [PATCH] feat(vg_lite): add grad cache size config and auto release cache (#5731) Signed-off-by: pengyiqiang Co-authored-by: pengyiqiang --- Kconfig | 7 +++++++ lv_conf_template.h | 5 +++++ src/draw/vg_lite/lv_vg_lite_grad.c | 9 +++++++-- src/lv_conf_internal.h | 11 +++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Kconfig b/Kconfig index b3a577c7d2..e34b3aa3a9 100644 --- a/Kconfig +++ b/Kconfig @@ -389,6 +389,13 @@ menu "LVGL configuration" which usually improves performance, but does not guarantee the same rendering quality as the software. + config LV_VG_LITE_GRAD_CACHE_SIZE + int "VG-Lite gradient image maximum cache number." + default 32 + depends on LV_USE_DRAW_VG_LITE + help + The memory usage of a single gradient image is 4K bytes. + config LV_USE_GPU_SDL bool "Use SDL renderer API" default n diff --git a/lv_conf_template.h b/lv_conf_template.h index 988897c0e5..f77a949600 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -187,6 +187,11 @@ * but does not guarantee the same rendering quality as the software. */ #define LV_VG_LITE_USE_BOX_SHADOW 0 +/* VG-Lite gradient image maximum cache number. + * NOTE: The memory usage of a single gradient image is 4K bytes. + */ +#define LV_VG_LITE_GRAD_CACHE_SIZE 32 + #endif /*======================= diff --git a/src/draw/vg_lite/lv_vg_lite_grad.c b/src/draw/vg_lite/lv_vg_lite_grad.c index 34d1ce511d..60c0025637 100644 --- a/src/draw/vg_lite/lv_vg_lite_grad.c +++ b/src/draw/vg_lite/lv_vg_lite_grad.c @@ -17,8 +17,6 @@ * DEFINES *********************/ -#define LV_VG_LITE_GRAD_CACHE_SIZE 16 - /********************** * TYPEDEFS **********************/ @@ -180,6 +178,13 @@ static vg_lite_linear_gradient_t * lv_vg_lite_linear_grad_get(struct _lv_draw_vg lv_cache_entry_t * cache_node_entry = lv_cache_acquire(u->grad_cache, &search_key, NULL); if(cache_node_entry == NULL) { + /* check if the cache is full */ + size_t free_size = lv_cache_get_free_size(u->grad_cache, NULL); + if(free_size == 0) { + LV_LOG_INFO("grad cache is full, release all pending cache entries"); + lv_vg_lite_finish(u); + } + cache_node_entry = lv_cache_acquire_or_create(u->grad_cache, &search_key, NULL); if(cache_node_entry == NULL) { LV_LOG_ERROR("grad cache creating failed"); diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index c6e3eb8e8b..4eecd47469 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -495,6 +495,17 @@ #endif #endif +/* VG-Lite gradient image maximum cache number. + * NOTE: The memory usage of a single gradient image is 4K bytes. + */ +#ifndef LV_VG_LITE_GRAD_CACHE_SIZE + #ifdef CONFIG_LV_VG_LITE_GRAD_CACHE_SIZE + #define LV_VG_LITE_GRAD_CACHE_SIZE CONFIG_LV_VG_LITE_GRAD_CACHE_SIZE + #else + #define LV_VG_LITE_GRAD_CACHE_SIZE 32 + #endif +#endif + #endif /*=======================