feat(image_cache): add resize function to image cache (#5829)

This commit is contained in:
Benign X
2024-03-12 15:39:35 +08:00
committed by GitHub
parent 0a9d86dd7b
commit 09985a8e80
3 changed files with 41 additions and 0 deletions

View File

@@ -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;

View File

@@ -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
**********************/

View File

@@ -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
*************************/