From 3f617e39d5db0b1cd7aac1dbe020981e32c536fe Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 9 Jan 2020 14:16:32 +0100 Subject: [PATCH] try new style caching --- src/lv_core/lv_obj.c | 68 ++++++++++++++++++++++++++++++++++++++---- src/lv_core/lv_refr.c | 4 +++ src/lv_core/lv_style.c | 52 ++++++++++++++++++-------------- src/lv_objx/lv_gauge.c | 8 ++--- 4 files changed, 100 insertions(+), 32 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 142938db9..9009f0eb9 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -2633,6 +2633,14 @@ static void lv_obj_del_async_cb(void * obj) lv_obj_del(obj); } +typedef struct { + lv_draw_rect_dsc_t draw_dsc; + uint8_t state; + lv_style_dsc_t * style_dsc; +}rect_cache_t; +#define CACHE_SIZE 4 +rect_cache_t cache[CACHE_SIZE]; +uint32_t cp; /** * Initialize a rectangle descriptor from an object's styles * @param obj pointer to an object @@ -2643,6 +2651,45 @@ static void lv_obj_del_async_cb(void * obj) */ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t * draw_dsc) { + rect_cache_t * cached = NULL; + lv_style_dsc_t * s = lv_obj_get_style(obj, part); + lv_obj_state_t state = lv_obj_get_state(obj, part); + if(lv_refr_get_disp_refreshing() && s) { + uint32_t i; + for(i = 0; i < CACHE_SIZE; i++) { + int32_t c; + bool err = false; + if(cache[i].style_dsc == NULL) continue; + if(cache[i].style_dsc->class_cnt != s->class_cnt) continue; + if(cache[i].state != state) continue; + for(c = 0; c < s->class_cnt; c++) { + lv_style_t * class1 = lv_style_dsc_get_class(cache[i].style_dsc, c); + lv_style_t * class2 = lv_style_dsc_get_class(s, c); + if(class1 != class2) { + err = true; + break; + } + } + if(err == false) { + cached = &cache[i]; + break; + } + } + } + + + static uint32_t hit = 1; + static uint32_t miss = 1; + printf("hit: %d, miss:%d, pct:%d\n", hit, miss, hit * 100 / (hit+miss)); + + if(cached) { + hit++; + memcpy(draw_dsc, &cached->draw_dsc, sizeof(lv_draw_rect_dsc_t)); + return; + } + miss++; + + draw_dsc->radius = lv_obj_get_style_int(obj, part, LV_STYLE_RADIUS); lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part, LV_STYLE_OPA_SCALE); @@ -2709,24 +2756,33 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t draw_dsc->shadow_opa = (uint16_t)((uint16_t)draw_dsc->shadow_opa * opa_scale) >> 8; draw_dsc->pattern_opa = (uint16_t)((uint16_t)draw_dsc->pattern_opa * opa_scale) >> 8; } + + + if(lv_refr_get_disp_refreshing()) { + memcpy(&cache[cp].draw_dsc, draw_dsc, sizeof(lv_draw_rect_dsc_t)); + cache[cp].style_dsc = s; + cache[cp].state = state; + cp++; + if(cp >= CACHE_SIZE) cp = 0; + } } void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t part, lv_draw_label_dsc_t * draw_dsc) { - draw_dsc->opa = LV_OPA_50;//lv_obj_get_style_opa(obj, part, LV_STYLE_TEXT_OPA); + draw_dsc->opa = lv_obj_get_style_opa(obj, part, LV_STYLE_TEXT_OPA); if(draw_dsc->opa <= LV_OPA_MIN) return; - lv_opa_t opa_scale = LV_OPA_COVER;//lv_obj_get_style_opa(obj, part, LV_STYLE_OPA_SCALE); + lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part, LV_STYLE_OPA_SCALE); if(opa_scale < LV_OPA_MAX) { draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa_scale) >> 8; } if(draw_dsc->opa <= LV_OPA_MIN) return; - draw_dsc->color = LV_COLOR_BLUE; //lv_obj_get_style_color(obj, part, LV_STYLE_TEXT_COLOR); - draw_dsc->letter_space = 0;//lv_obj_get_style_int(obj, part, LV_STYLE_LETTER_SPACE); - draw_dsc->line_space = 0;//lv_obj_get_style_int(obj, part, LV_STYLE_LETTER_SPACE); + draw_dsc->color = lv_obj_get_style_color(obj, part, LV_STYLE_TEXT_COLOR); + draw_dsc->letter_space = lv_obj_get_style_int(obj, part, LV_STYLE_LETTER_SPACE); + draw_dsc->line_space = lv_obj_get_style_int(obj, part, LV_STYLE_LETTER_SPACE); - draw_dsc->font = LV_FONT_DEFAULT;//lv_obj_get_style_ptr(obj, part, LV_STYLE_FONT); + draw_dsc->font = lv_obj_get_style_ptr(obj, part, LV_STYLE_FONT); if(draw_dsc->sel_start != LV_DRAW_LABEL_NO_TXT_SEL && draw_dsc->sel_end != LV_DRAW_LABEL_NO_TXT_SEL) { draw_dsc->color = lv_obj_get_style_color(obj, part, LV_STYLE_TEXT_SEL_COLOR); diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index 1a83ba5c9..ac76cedfa 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -170,6 +170,10 @@ void lv_disp_refr_task(lv_task_t * task) disp_refr = task->user_data; + +// extern rect_cache_t cache[]; +// extern uint32_t cp; + lv_refr_join_area(); lv_refr_areas(); diff --git a/src/lv_core/lv_style.c b/src/lv_core/lv_style.c index 4e871f7bb..45fc19152 100644 --- a/src/lv_core/lv_style.c +++ b/src/lv_core/lv_style.c @@ -92,7 +92,7 @@ void lv_style_dsc_init(lv_style_dsc_t * style_dsc) style_dsc->classes = NULL; style_dsc->class_cnt = 0; memset(&style_dsc->cache, 0xff, sizeof(lv_style_cache_t)); - style_dsc->cache.enabled = 1; + style_dsc->cache.enabled = 0; } @@ -377,6 +377,14 @@ lv_res_t lv_style_dsc_get_int(lv_style_dsc_t * dsc, lv_style_property_t prop, lv if(dsc->cache.enabled) { switch(prop & (~LV_STYLE_STATE_MASK)) { + case LV_STYLE_PAD_INNER: + case LV_STYLE_PAD_TOP: + case LV_STYLE_PAD_BOTTOM: + case LV_STYLE_PAD_LEFT: + case LV_STYLE_PAD_RIGHT: + *value = 5; + return LV_RES_OK; + break; case LV_STYLE_BG_BLEND_MODE: res = dsc->cache.bg_blend_mode; break; @@ -780,31 +788,31 @@ static inline int32_t get_property_index(const lv_style_t * style, lv_style_prop int16_t weight = -1; int16_t id_guess = -1; -// -// if(id_to_find == (LV_STYLE_OPA_SCALE & 0xFF)) { -// volatile uint8_t i = 0; -// } -// -// stat[id_to_find]++; -// -// cnt++; -// if(cnt > 100000) { -// cnt = 0; -// uint32_t i; -//// printf("\nQuerry:\n"); -// for(i = 0; i < 256; i++) { -// if(stat[i]) printf("%02x: %d\n", i, stat[i]); -// } -// memset(stat, 0x00, sizeof(stat)); -// -//// printf("\nFooled:\n"); + if(id_to_find == (LV_STYLE_OPA_SCALE & 0xFF)) { + volatile uint8_t i = 0; + } + + stat[id_to_find]++; + + cnt++; + if(cnt > 1000) { + cnt = 0; + uint32_t i; + + printf("\nQuerry:\n"); + for(i = 0; i < 256; i++) { + if(stat[i]) printf("%02x: %d\n", i, stat[i]); + } + memset(stat, 0x00, sizeof(stat)); + +// printf("\nFooled:\n"); // for(i = 0; i < 256; i++) { // if(prop_fooled[i]) printf("%02x: %d\n", i, prop_fooled[i]); // } -// memset(prop_fooled, 0x00, sizeof(stat)); -// printf("\n"); -// } + memset(prop_fooled, 0x00, sizeof(stat)); + printf("\n"); + } static const uint8_t size[16] = { sizeof(lv_style_int_t) + sizeof(lv_style_property_t), diff --git a/src/lv_objx/lv_gauge.c b/src/lv_objx/lv_gauge.c index b3e7dcad7..17b6c9156 100644 --- a/src/lv_objx/lv_gauge.c +++ b/src/lv_objx/lv_gauge.c @@ -384,10 +384,10 @@ static lv_res_t lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param { lv_res_t res; if(sign == LV_SIGNAL_GET_STYLE) { - uint8_t ** type_p = param; - lv_style_dsc_t ** style_dsc_p = param; - *style_dsc_p = lv_gauge_get_style(gauge, **type_p); - return LV_RES_OK; + lv_get_style_info_t * info = param; + info->result = lv_gauge_get_style(gauge, info->part); + if(info->result != NULL) return LV_RES_OK; + else return ancestor_signal(gauge, sign, param); } /* Include the ancient signal function */