mirror of
https://github.com/lvgl/lvgl.git
synced 2025-02-04 07:13:00 +08:00
try new style caching
This commit is contained in:
parent
621ff4e0f7
commit
3f617e39d5
@ -2633,6 +2633,14 @@ static void lv_obj_del_async_cb(void * obj)
|
|||||||
lv_obj_del(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
|
* Initialize a rectangle descriptor from an object's styles
|
||||||
* @param obj pointer to an object
|
* @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)
|
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);
|
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);
|
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->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;
|
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)
|
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;
|
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) {
|
if(opa_scale < LV_OPA_MAX) {
|
||||||
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa_scale) >> 8;
|
draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa_scale) >> 8;
|
||||||
}
|
}
|
||||||
if(draw_dsc->opa <= LV_OPA_MIN) return;
|
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->color = 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->letter_space = 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->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) {
|
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);
|
draw_dsc->color = lv_obj_get_style_color(obj, part, LV_STYLE_TEXT_SEL_COLOR);
|
||||||
|
@ -170,6 +170,10 @@ void lv_disp_refr_task(lv_task_t * task)
|
|||||||
|
|
||||||
disp_refr = task->user_data;
|
disp_refr = task->user_data;
|
||||||
|
|
||||||
|
|
||||||
|
// extern rect_cache_t cache[];
|
||||||
|
// extern uint32_t cp;
|
||||||
|
|
||||||
lv_refr_join_area();
|
lv_refr_join_area();
|
||||||
|
|
||||||
lv_refr_areas();
|
lv_refr_areas();
|
||||||
|
@ -92,7 +92,7 @@ void lv_style_dsc_init(lv_style_dsc_t * style_dsc)
|
|||||||
style_dsc->classes = NULL;
|
style_dsc->classes = NULL;
|
||||||
style_dsc->class_cnt = 0;
|
style_dsc->class_cnt = 0;
|
||||||
memset(&style_dsc->cache, 0xff, sizeof(lv_style_cache_t));
|
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) {
|
if(dsc->cache.enabled) {
|
||||||
switch(prop & (~LV_STYLE_STATE_MASK)) {
|
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:
|
case LV_STYLE_BG_BLEND_MODE:
|
||||||
res = dsc->cache.bg_blend_mode;
|
res = dsc->cache.bg_blend_mode;
|
||||||
break;
|
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 weight = -1;
|
||||||
int16_t id_guess = -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");
|
if(id_to_find == (LV_STYLE_OPA_SCALE & 0xFF)) {
|
||||||
// for(i = 0; i < 256; i++) {
|
volatile uint8_t i = 0;
|
||||||
// if(stat[i]) printf("%02x: %d\n", i, stat[i]);
|
}
|
||||||
// }
|
|
||||||
// memset(stat, 0x00, sizeof(stat));
|
stat[id_to_find]++;
|
||||||
//
|
|
||||||
//// printf("\nFooled:\n");
|
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++) {
|
// for(i = 0; i < 256; i++) {
|
||||||
// if(prop_fooled[i]) printf("%02x: %d\n", i, prop_fooled[i]);
|
// if(prop_fooled[i]) printf("%02x: %d\n", i, prop_fooled[i]);
|
||||||
// }
|
// }
|
||||||
// memset(prop_fooled, 0x00, sizeof(stat));
|
memset(prop_fooled, 0x00, sizeof(stat));
|
||||||
// printf("\n");
|
printf("\n");
|
||||||
// }
|
}
|
||||||
|
|
||||||
static const uint8_t size[16] = {
|
static const uint8_t size[16] = {
|
||||||
sizeof(lv_style_int_t) + sizeof(lv_style_property_t),
|
sizeof(lv_style_int_t) + sizeof(lv_style_property_t),
|
||||||
|
@ -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;
|
lv_res_t res;
|
||||||
if(sign == LV_SIGNAL_GET_STYLE) {
|
if(sign == LV_SIGNAL_GET_STYLE) {
|
||||||
uint8_t ** type_p = param;
|
lv_get_style_info_t * info = param;
|
||||||
lv_style_dsc_t ** style_dsc_p = param;
|
info->result = lv_gauge_get_style(gauge, info->part);
|
||||||
*style_dsc_p = lv_gauge_get_style(gauge, **type_p);
|
if(info->result != NULL) return LV_RES_OK;
|
||||||
return LV_RES_OK;
|
else return ancestor_signal(gauge, sign, param);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Include the ancient signal function */
|
/* Include the ancient signal function */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user