mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Merge branch 'master' of https://github.com/littlevgl/lvgl
This commit is contained in:
commit
af98c9a9c0
@ -33,6 +33,10 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
#if LV_IMG_CACHE_DEF_SIZE
|
||||
static bool lv_img_cache_match(const void * src1, const void * src2);
|
||||
#endif
|
||||
|
||||
#if LV_IMG_CACHE_DEF_SIZE == 0
|
||||
static lv_img_cache_entry_t cache_temp;
|
||||
#endif
|
||||
@ -82,16 +86,8 @@ lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color)
|
||||
}
|
||||
|
||||
for(i = 0; i < entry_cnt; i++) {
|
||||
bool match = false;
|
||||
lv_img_src_t src_type = lv_img_src_get_type(cache[i].dec_dsc.src);
|
||||
if(src_type == LV_IMG_SRC_VARIABLE) {
|
||||
if(cache[i].dec_dsc.src == src && cache[i].dec_dsc.color.full == color.full) match = true;
|
||||
}
|
||||
else if(src_type == LV_IMG_SRC_FILE) {
|
||||
if(strcmp(cache[i].dec_dsc.src, src) == 0) match = true;
|
||||
}
|
||||
|
||||
if(match) {
|
||||
if(color.full == cache[i].dec_dsc.color.full &&
|
||||
lv_img_cache_match(src, cache[i].dec_dsc.src)) {
|
||||
/* If opened increment its life.
|
||||
* Image difficult to open should live longer to keep avoid frequent their recaching.
|
||||
* Therefore increase `life` with `time_to_open`*/
|
||||
@ -122,7 +118,6 @@ lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color)
|
||||
else {
|
||||
LV_LOG_INFO("image draw: cache miss, cached to an empty entry");
|
||||
}
|
||||
|
||||
#else
|
||||
cached_src = &cache_temp;
|
||||
#endif
|
||||
@ -131,8 +126,6 @@ lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color)
|
||||
lv_res_t open_res = lv_img_decoder_open(&cached_src->dec_dsc, src, color);
|
||||
if(open_res == LV_RES_INV) {
|
||||
LV_LOG_WARN("Image draw cannot open the image resource");
|
||||
lv_img_decoder_close(&cached_src->dec_dsc);
|
||||
_lv_memset_00(&cached_src->dec_dsc, sizeof(lv_img_decoder_dsc_t));
|
||||
_lv_memset_00(cached_src, sizeof(lv_img_cache_entry_t));
|
||||
cached_src->life = INT32_MIN; /*Make the empty entry very "weak" to force its use */
|
||||
return NULL;
|
||||
@ -178,11 +171,7 @@ void lv_img_cache_set_size(uint16_t new_entry_cnt)
|
||||
entry_cnt = new_entry_cnt;
|
||||
|
||||
/*Clean the cache*/
|
||||
uint16_t i;
|
||||
for(i = 0; i < entry_cnt; i++) {
|
||||
_lv_memset_00(&LV_GC_ROOT(_lv_img_cache_array)[i].dec_dsc, sizeof(lv_img_decoder_dsc_t));
|
||||
_lv_memset_00(&LV_GC_ROOT(_lv_img_cache_array)[i], sizeof(lv_img_cache_entry_t));
|
||||
}
|
||||
_lv_memset_00(LV_GC_ROOT(_lv_img_cache_array), entry_cnt * sizeof(lv_img_cache_entry_t));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -198,12 +187,11 @@ void lv_img_cache_invalidate_src(const void * src)
|
||||
|
||||
uint16_t i;
|
||||
for(i = 0; i < entry_cnt; i++) {
|
||||
if(cache[i].dec_dsc.src == src || src == NULL) {
|
||||
if(src == NULL || lv_img_cache_match(src, cache[i].dec_dsc.src)) {
|
||||
if(cache[i].dec_dsc.src != NULL) {
|
||||
lv_img_decoder_close(&cache[i].dec_dsc);
|
||||
}
|
||||
|
||||
_lv_memset_00(&cache[i].dec_dsc, sizeof(lv_img_decoder_dsc_t));
|
||||
_lv_memset_00(&cache[i], sizeof(lv_img_cache_entry_t));
|
||||
}
|
||||
}
|
||||
@ -213,3 +201,17 @@ void lv_img_cache_invalidate_src(const void * src)
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#if LV_IMG_CACHE_DEF_SIZE
|
||||
static bool lv_img_cache_match(const void * src1, const void * src2)
|
||||
{
|
||||
lv_img_src_t src_type = lv_img_src_get_type(src1);
|
||||
if(src_type == LV_IMG_SRC_VARIABLE)
|
||||
return src1 == src2;
|
||||
if(src_type != LV_IMG_SRC_FILE)
|
||||
return false;
|
||||
if(lv_img_src_get_type(src2) != LV_IMG_SRC_FILE)
|
||||
return false;
|
||||
return strcmp(src1, src2) == 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -31,7 +31,7 @@ extern "C" {
|
||||
typedef struct {
|
||||
lv_img_decoder_dsc_t dec_dsc; /**< Image information */
|
||||
|
||||
/** Count the cache entries's life. Add `time_tio_open` to `life` when the entry is used.
|
||||
/** Count the cache entries's life. Add `time_to_open` to `life` when the entry is used.
|
||||
* Decrement all lifes by one every in every ::lv_img_cache_open.
|
||||
* If life == 0 the entry can be reused */
|
||||
int32_t life;
|
||||
|
Loading…
x
Reference in New Issue
Block a user