diff --git a/src/misc/cache/lv_cache.c b/src/misc/cache/lv_cache.c index 27b52b14f..e22cd9e42 100644 --- a/src/misc/cache/lv_cache.c +++ b/src/misc/cache/lv_cache.c @@ -261,6 +261,7 @@ static lv_cache_entry_t * cache_add_internal_no_lock(lv_cache_t * cache, const v lv_cache_reserve_cond_res_t reserve_cond_res = cache->clz->reserve_cond_cb(cache, key, 0, user_data); if(reserve_cond_res == LV_CACHE_RESERVE_COND_TOO_LARGE) { LV_LOG_ERROR("data %p is too large that exceeds max size (%" LV_PRIu32 ")", key, cache->max_size); + return NULL; } for(; reserve_cond_res == LV_CACHE_RESERVE_COND_NEED_VICTIM; diff --git a/src/misc/cache/lv_image_cache.c b/src/misc/cache/lv_image_cache.c index 61969e0f7..28f0aec75 100644 --- a/src/misc/cache/lv_image_cache.c +++ b/src/misc/cache/lv_image_cache.c @@ -59,6 +59,19 @@ void lv_image_cache_drop(const void * src) #endif } +void lv_image_cache_resize(uint32_t new_size, bool evict_now) +{ +#if LV_CACHE_DEF_SIZE > 0 + lv_cache_set_max_size(img_cache_p, new_size, NULL); + if(evict_now) { + lv_cache_reserve(img_cache_p, new_size, NULL); + } +#else + LV_UNUSED(new_size); + LV_UNUSED(evict_now); +#endif +} + void lv_image_header_cache_drop(const void * src) { #if LV_IMAGE_HEADER_CACHE_DEF_CNT > 0 @@ -78,6 +91,19 @@ void lv_image_header_cache_drop(const void * src) #endif } +void lv_image_header_cache_resize(uint32_t new_size, bool evict_now) +{ +#if LV_IMAGE_HEADER_CACHE_DEF_CNT > 0 + lv_cache_set_max_size(img_header_cache_p, new_size, NULL); + if(evict_now) { + lv_cache_reserve(img_header_cache_p, new_size, NULL); + } +#else + LV_UNUSED(new_size); + LV_UNUSED(evict_now); +#endif +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/misc/cache/lv_image_cache.h b/src/misc/cache/lv_image_cache.h index 4c4f4eb0f..f8a590349 100644 --- a/src/misc/cache/lv_image_cache.h +++ b/src/misc/cache/lv_image_cache.h @@ -33,6 +33,13 @@ extern "C" { */ void lv_image_cache_drop(const void * src); +/** + * Resize image cache. + * @param new_size new size of the cache in bytes. + * @param evict_now true: evict the images should be removed by the eviction policy, false: wait for the next cache cleanup. + */ +void lv_image_cache_resize(uint32_t new_size, bool evict_now); + /** * Invalidate image header cache. Use NULL to invalidate all image headers. * It's also automatically called when an image is invalidated. @@ -40,6 +47,13 @@ void lv_image_cache_drop(const void * src); */ void lv_image_header_cache_drop(const void * src); +/** + * Resize image header cache. + * @param new_size new size of the cache in count of image headers. + * @param evict_now true: evict the image headers should be removed by the eviction policy, false: wait for the next cache cleanup. + */ +void lv_image_header_cache_resize(uint32_t new_size, bool evict_now); + /************************* * GLOBAL VARIABLES *************************/