feat(image_cache): add resize function to image cache (#5829)
This commit is contained in:
1
src/misc/cache/lv_cache.c
vendored
1
src/misc/cache/lv_cache.c
vendored
@@ -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);
|
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) {
|
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);
|
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;
|
for(; reserve_cond_res == LV_CACHE_RESERVE_COND_NEED_VICTIM;
|
||||||
|
|||||||
26
src/misc/cache/lv_image_cache.c
vendored
26
src/misc/cache/lv_image_cache.c
vendored
@@ -59,6 +59,19 @@ void lv_image_cache_drop(const void * src)
|
|||||||
#endif
|
#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)
|
void lv_image_header_cache_drop(const void * src)
|
||||||
{
|
{
|
||||||
#if LV_IMAGE_HEADER_CACHE_DEF_CNT > 0
|
#if LV_IMAGE_HEADER_CACHE_DEF_CNT > 0
|
||||||
@@ -78,6 +91,19 @@ void lv_image_header_cache_drop(const void * src)
|
|||||||
#endif
|
#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
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|||||||
14
src/misc/cache/lv_image_cache.h
vendored
14
src/misc/cache/lv_image_cache.h
vendored
@@ -33,6 +33,13 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
void lv_image_cache_drop(const void * src);
|
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.
|
* Invalidate image header cache. Use NULL to invalidate all image headers.
|
||||||
* It's also automatically called when an image is invalidated.
|
* 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);
|
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
|
* GLOBAL VARIABLES
|
||||||
*************************/
|
*************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user