chore: code and configs cleanups; add builtin cache tracing (#4593)

This commit is contained in:
PGNetHun
2023-09-25 17:16:22 +02:00
committed by GitHub
parent 064a844d74
commit 453235c245
10 changed files with 86 additions and 75 deletions

View File

@@ -253,7 +253,8 @@
#define LV_LOG_TRACE_OBJ_CREATE 1
#define LV_LOG_TRACE_LAYOUT 1
#define LV_LOG_TRACE_ANIM 1
#define LV_LOG_TRACE_MSG 1
#define LV_LOG_TRACE_MSG 1
#define LV_LOG_TRACE_CACHE 1
#endif /*LV_USE_LOG*/
@@ -499,8 +500,6 @@
#define LV_USE_CHECKBOX 1
#define LV_USE_COLORWHEEL 1
#define LV_USE_DROPDOWN 1 /*Requires: lv_label*/
#define LV_USE_IMG 1 /*Requires: lv_label*/

View File

@@ -230,7 +230,8 @@
#define LV_LOG_TRACE_OBJ_CREATE 1
#define LV_LOG_TRACE_LAYOUT 1
#define LV_LOG_TRACE_ANIM 1
#define LV_LOG_TRACE_MSG 1
#define LV_LOG_TRACE_MSG 1
#define LV_LOG_TRACE_CACHE 1
#endif /*LV_USE_LOG*/
@@ -481,8 +482,6 @@
#define LV_USE_CHECKBOX 1
#define LV_USE_COLORWHEEL 1
#define LV_USE_DROPDOWN 1 /*Requires: lv_label*/
#define LV_USE_IMG 1 /*Requires: lv_label*/

View File

@@ -177,7 +177,8 @@
#define LV_LOG_TRACE_OBJ_CREATE 1
#define LV_LOG_TRACE_LAYOUT 1
#define LV_LOG_TRACE_ANIM 1
#define LV_LOG_TRACE_MSG 1
#define LV_LOG_TRACE_MSG 1
#define LV_LOG_TRACE_CACHE 1
#endif /*LV_USE_LOG*/
@@ -738,7 +739,7 @@
#define LV_SDL_RENDER_MODE LV_DISPLAY_RENDER_MODE_DIRECT /*LV_DISPLAY_RENDER_MODE_DIRECT is recommended for best performance*/
#define LV_SDL_BUF_COUNT 1 /*1 or 2*/
#define LV_SDL_FULLSCREEN 0 /*1: Make the window full screen by default*/
#define LV_SDL_DIRECT_EXIT 1 /*1: Exit the application when all SDL widows are closed*/
#define LV_SDL_DIRECT_EXIT 1 /*1: Exit the application when all SDL windows are closed*/
#endif
/*Driver for /dev/fb*/

View File

@@ -94,10 +94,10 @@ lv_result_t lv_image_decoder_get_info(const void * src, lv_image_header_t * head
}
lv_result_t res = LV_RESULT_INVALID;
lv_image_decoder_t * d;
_LV_LL_READ(img_decoder_ll_p, d) {
if(d->info_cb) {
res = d->info_cb(d, src, header);
lv_image_decoder_t * decoder;
_LV_LL_READ(img_decoder_ll_p, decoder) {
if(decoder->info_cb) {
res = decoder->info_cb(decoder, src, header);
if(res == LV_RESULT_OK) {
if(header->stride == 0) header->stride = img_width_to_stride(header);
break;

View File

@@ -489,17 +489,28 @@
#define LV_LOG_TRACE_ANIM 1
#endif
#endif
#ifndef LV_LOG_TRACE_MSG
#ifdef _LV_KCONFIG_PRESENT
#ifdef CONFIG_LV_LOG_TRACE_MSG
#define LV_LOG_TRACE_MSG CONFIG_LV_LOG_TRACE_MSG
#else
#define LV_LOG_TRACE_MSG 0
#endif
#else
#define LV_LOG_TRACE_MSG 1
#endif
#endif
#ifndef LV_LOG_TRACE_MSG
#ifdef _LV_KCONFIG_PRESENT
#ifdef CONFIG_LV_LOG_TRACE_MSG
#define LV_LOG_TRACE_MSG CONFIG_LV_LOG_TRACE_MSG
#else
#define LV_LOG_TRACE_MSG 0
#endif
#else
#define LV_LOG_TRACE_MSG 1
#endif
#endif
#ifndef LV_LOG_TRACE_CACHE
#ifdef _LV_KCONFIG_PRESENT
#ifdef CONFIG_LV_LOG_TRACE_CACHE
#define LV_LOG_TRACE_CACHE CONFIG_LV_LOG_TRACE_CACHE
#else
#define LV_LOG_TRACE_CACHE 0
#endif
#else
#define LV_LOG_TRACE_CACHE 1
#endif
#endif
#endif /*LV_USE_LOG*/
@@ -2414,7 +2425,7 @@
#define LV_SDL_DIRECT_EXIT 0
#endif
#else
#define LV_SDL_DIRECT_EXIT 1 /*1: Exit the application when all SDL widows are closed*/
#define LV_SDL_DIRECT_EXIT 1 /*1: Exit the application when all SDL windows are closed*/
#endif
#endif
#endif

View File

@@ -45,9 +45,9 @@ static int32_t lv_anim_path_cubic_bezier(const lv_anim_t * a, int32_t x1,
* MACROS
**********************/
#if LV_LOG_TRACE_ANIM
#define TRACE_ANIM(...) LV_LOG_TRACE(__VA_ARGS__)
#define LV_TRACE_ANIM(...) LV_LOG_TRACE(__VA_ARGS__)
#else
#define TRACE_ANIM(...)
#define LV_TRACE_ANIM(...)
#endif
@@ -77,7 +77,7 @@ void lv_anim_init(lv_anim_t * a)
lv_anim_t * lv_anim_start(const lv_anim_t * a)
{
TRACE_ANIM("begin");
LV_TRACE_ANIM("begin");
/*Do not let two animations for the same 'var' with the same 'exec_cb'*/
if(a->exec_cb != NULL) lv_anim_del(a->var, a->exec_cb); /*exec_cb == NULL would delete all animations of var*/
@@ -108,7 +108,7 @@ lv_anim_t * lv_anim_start(const lv_anim_t * a)
*It's important if it happens in a ready callback. (see `anim_timer`)*/
anim_mark_list_change();
TRACE_ANIM("finished");
LV_TRACE_ANIM("finished");
return new_anim;
}

View File

@@ -25,14 +25,13 @@
/**********************
* STATIC PROTOTYPES
**********************/
static lv_cache_entry_t * add_cb(size_t size);
static lv_cache_entry_t * find_cb(const void * src, lv_cache_src_type_t src_type, uint32_t param1, uint32_t param2);
static void invalidate_cb(lv_cache_entry_t * entry);
static const void * get_data_cb(lv_cache_entry_t * entry);
static void release_cb(lv_cache_entry_t * entry);
static void set_max_size_cb(size_t new_size);
static bool drop_yougest(void);
static bool drop_youngest(void);
/**********************
* STATIC VARIABLES
@@ -41,6 +40,11 @@ static bool drop_yougest(void);
/**********************
* MACROS
**********************/
#if LV_LOG_TRACE_CACHE
#define LV_TRACE_CACHE(...) LV_LOG_TRACE(__VA_ARGS__)
#else
#define LV_TRACE_CACHE(...)
#endif
/**********************
* GLOBAL FUNCTIONS
@@ -59,7 +63,6 @@ void _lv_cache_builtin_init(void)
_lv_ll_init(&dsc.entry_ll, sizeof(lv_cache_entry_t));
}
/**********************
* STATIC FUNCTIONS
**********************/
@@ -73,7 +76,7 @@ static lv_cache_entry_t * add_cb(size_t size)
if(!temporary) {
/*Keep dropping items until there is enough space*/
while(dsc.cur_size + size > _cache_manager.max_size) {
bool ret = drop_yougest();
bool ret = drop_youngest();
/*No item could be dropped.
*It can happen because the usage_count of the remaining items are not zero.*/
@@ -82,37 +85,36 @@ static lv_cache_entry_t * add_cb(size_t size)
break;
}
}
}
lv_cache_entry_t * e = _lv_ll_ins_head(&dsc.entry_ll);
lv_memzero(e, sizeof(lv_cache_entry_t));
e->data_size = size;
e->weight = 1;
e->temporary = temporary;
lv_cache_entry_t * entry = _lv_ll_ins_head(&dsc.entry_ll);
lv_memzero(entry, sizeof(lv_cache_entry_t));
entry->data_size = size;
entry->weight = 1;
entry->temporary = temporary;
if(temporary) {
LV_LOG_USER("cache add temporary: %"LV_PRIu32, (uint32_t)size);
LV_TRACE_CACHE("Add temporary cache: %lu bytes", (unsigned long)size);
}
else {
LV_LOG_USER("cache add: %"LV_PRIu32, (uint32_t)size);
LV_TRACE_CACHE("Add cache: %lu bytes", (unsigned long)size);
dsc.cur_size += size;
}
return e;
return entry;
}
static lv_cache_entry_t * find_cb(const void * src, lv_cache_src_type_t src_type, uint32_t param1, uint32_t param2)
{
lv_cache_entry_t * e = _lv_ll_get_head(&dsc.entry_ll);
while(e) {
if(param1 == e->param1 && param2 == e->param2 && src_type == e->src_type &&
((src_type == LV_CACHE_SRC_TYPE_PTR && src == e->src) ||
(src_type == LV_CACHE_SRC_TYPE_STR && strcmp(src, e->src) == 0))) {
return e;
lv_cache_entry_t * entry = _lv_ll_get_head(&dsc.entry_ll);
while(entry) {
if(param1 == entry->param1 && param2 == entry->param2 && src_type == entry->src_type &&
((src_type == LV_CACHE_SRC_TYPE_PTR && src == entry->src) ||
(src_type == LV_CACHE_SRC_TYPE_STR && strcmp(src, entry->src) == 0))) {
return entry;
}
e = _lv_ll_get_next(&dsc.entry_ll, e);
entry = _lv_ll_get_next(&dsc.entry_ll, entry);
}
return NULL;
@@ -123,7 +125,7 @@ static void invalidate_cb(lv_cache_entry_t * entry)
if(entry == NULL) return;
dsc.cur_size -= entry->data_size;
LV_LOG_USER("cache drop %"LV_PRIu32, (uint32_t)entry->data_size);
LV_TRACE_CACHE("Drop cache: %lu bytes", (unsigned long)entry->data_size);
if(entry->free_src) lv_free((void *)entry->src);
if(entry->free_data) lv_draw_buf_free((void *)entry->data);
@@ -164,7 +166,7 @@ static void release_cb(lv_cache_entry_t * entry)
static void set_max_size_cb(size_t new_size)
{
while(dsc.cur_size > new_size) {
bool ret = drop_yougest();
bool ret = drop_youngest();
/*No item could be dropped.
*It can happen because the usage_count of the remaining items are not zero.*/
@@ -172,23 +174,21 @@ static void set_max_size_cb(size_t new_size)
}
}
static bool drop_yougest(void)
static bool drop_youngest(void)
{
int32_t life_min = INT32_MAX;
lv_cache_entry_t * e_min = NULL;
lv_cache_entry_t * entry_to_drop = NULL;
lv_cache_entry_t * e = _lv_ll_get_head(&dsc.entry_ll);
while(e) {
if(e->life < life_min && e->usage_count == 0) e_min = e;
e = _lv_ll_get_next(&dsc.entry_ll, e);
lv_cache_entry_t * entry = _lv_ll_get_head(&dsc.entry_ll);
while(entry) {
if(entry->life < life_min && entry->usage_count == 0) entry_to_drop = entry;
entry = _lv_ll_get_next(&dsc.entry_ll, entry);
}
if(e_min == NULL) {
if(entry_to_drop == NULL) {
return false;
}
invalidate_cb(e_min);
invalidate_cb(entry_to_drop);
return true;
}

View File

@@ -53,9 +53,9 @@ static void obj_delete_event_cb(lv_event_t * e);
* MACROS
**********************/
#if LV_LOG_TRACE_MSG
#define MSG_TRACE(...) LV_LOG_TRACE(__VA_ARGS__)
#define LV_TRACE_MSG(...) LV_LOG_TRACE(__VA_ARGS__)
#else
#define MSG_TRACE(...)
#define LV_TRACE_MSG(...)
#endif
/**********************
@@ -194,7 +194,7 @@ static void notify(lv_msg_t * m)
/*restart or load next*/
if(restart_notify) {
MSG_TRACE("Start from the first sub_dsc_t again because _subs_ll may have changed");
LV_TRACE_MSG("Start from the first sub_dsc_t again because _subs_ll may have changed");
break;
}
s = next;

View File

@@ -29,6 +29,7 @@
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/

View File

@@ -212,7 +212,7 @@ void lv_buttonmatrix_set_button_ctrl(lv_obj_t * obj, uint32_t btn_id, lv_buttonm
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
if(btn_id >= btnm->btn_cnt) return;
@@ -232,7 +232,7 @@ void lv_buttonmatrix_clear_button_ctrl(lv_obj_t * obj, uint32_t btn_id, lv_butto
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
if(btn_id >= btnm->btn_cnt) return;
@@ -248,7 +248,7 @@ void lv_buttonmatrix_set_button_ctrl_all(lv_obj_t * obj, lv_buttonmatrix_ctrl_t
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
uint32_t i;
for(i = 0; i < btnm->btn_cnt; i++) {
lv_buttonmatrix_set_button_ctrl(obj, i, ctrl);
@@ -259,7 +259,7 @@ void lv_buttonmatrix_clear_button_ctrl_all(lv_obj_t * obj, lv_buttonmatrix_ctrl_
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
uint32_t i;
for(i = 0; i < btnm->btn_cnt; i++) {
lv_buttonmatrix_clear_button_ctrl(obj, i, ctrl);
@@ -270,7 +270,7 @@ void lv_buttonmatrix_set_button_width(lv_obj_t * obj, uint32_t btn_id, uint32_t
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
if(btn_id >= btnm->btn_cnt) return;
btnm->ctrl_bits[btn_id] &= (~LV_BUTTONMATRIX_WIDTH_MASK);
btnm->ctrl_bits[btn_id] |= (LV_BUTTONMATRIX_WIDTH_MASK & width);
@@ -282,7 +282,7 @@ void lv_buttonmatrix_set_one_checked(lv_obj_t * obj, bool en)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
btnm->one_check = en;
/*If more than one button is toggled only the first one should be*/
@@ -297,7 +297,7 @@ const char ** lv_buttonmatrix_get_map(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
return btnm->map_p;
}
@@ -305,7 +305,7 @@ uint32_t lv_buttonmatrix_get_selected_button(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
return btnm->btn_id_sel;
}
@@ -338,7 +338,7 @@ bool lv_buttonmatrix_has_button_ctrl(lv_obj_t * obj, uint32_t btn_id, lv_buttonm
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
if(btn_id >= btnm->btn_cnt) return false;
return (btnm->ctrl_bits[btn_id] & ctrl) == ctrl;
@@ -348,7 +348,7 @@ bool lv_buttonmatrix_get_one_checked(const lv_obj_t * obj)
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
return btnm->one_check;
}
@@ -921,7 +921,7 @@ static uint32_t get_button_from_point(lv_obj_t * obj, lv_point_t * p)
{
lv_area_t obj_cords;
lv_area_t btn_area;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
uint32_t i;
lv_obj_get_coords(obj, &obj_cords);
@@ -977,7 +977,7 @@ static void invalidate_button_area(const lv_obj_t * obj, uint32_t btn_idx)
lv_area_t btn_area;
lv_area_t obj_area;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;;
lv_buttonmatrix_t * btnm = (lv_buttonmatrix_t *)obj;
if(btn_idx >= btnm->btn_cnt) return;
lv_area_copy(&btn_area, &btnm->button_areas[btn_idx]);