mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-21 06:53:01 +08:00
implement caching on style lists
This commit is contained in:
parent
c173f28a3f
commit
41fd83e1d3
@ -1300,6 +1300,8 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_property_t prop)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
|
||||
|
||||
_lv_obj_invalidate_style_cache(obj);
|
||||
|
||||
/*If a real style refresh is required*/
|
||||
bool real_refr = false;
|
||||
switch(prop) {
|
||||
@ -1387,6 +1389,64 @@ void lv_obj_report_style_mod(lv_style_t * style)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the cache of style list
|
||||
* @param obj pointer to an obejct
|
||||
* @param part the part of the object
|
||||
*/
|
||||
void _lv_obj_update_style_cache(lv_obj_t * obj, uint8_t part)
|
||||
{
|
||||
lv_style_list_t * list = lv_obj_get_style_list(obj, part);
|
||||
if(list->valid_cache) return;
|
||||
|
||||
bool ignore_cache_ori = list->ignore_cache;
|
||||
list->ignore_cache = 1;
|
||||
list->bg_grad_dir_none = lv_obj_get_style_bg_grad_dir(obj, part) == LV_GRAD_DIR_NONE ? 1 : 0;
|
||||
list->bg_opa_transp = lv_obj_get_style_bg_opa(obj, part) == LV_OPA_TRANSP ? 1 : 0;
|
||||
list->border_width_zero = lv_obj_get_style_border_width(obj, part) == LV_OPA_TRANSP ? 1 : 0;
|
||||
list->clip_corner_off = lv_obj_get_style_clip_corner(obj, part) == false ? 1 : 0;
|
||||
list->img_recolor_opa_transp = lv_obj_get_style_image_recolor_opa(obj, part) == LV_OPA_TRANSP ? 1 : 0;
|
||||
list->line_width_zerop = lv_obj_get_style_line_width(obj, part) == 0 ? 1 : 0;
|
||||
list->opa_scale_transp = lv_obj_get_style_opa_scale(obj, part) == LV_OPA_TRANSP ? 1 : 0;
|
||||
list->outline_width_zero = lv_obj_get_style_outline_width(obj, part) == 0 ? 1 : 0;
|
||||
list->pattern_img_null = lv_obj_get_style_pattern_image(obj, part) == NULL ? 1 : 0;
|
||||
list->shadow_width_zero = lv_obj_get_style_shadow_width(obj, part) == 0 ? 1 : 0;
|
||||
list->text_decor_none = lv_obj_get_style_text_decor(obj, part) == LV_TEXT_DECOR_NONE ? 1 : 0;
|
||||
list->text_letter_space_zero = lv_obj_get_style_text_letter_space(obj, part) == 0 ? 1 : 0;
|
||||
list->text_line_space_zero = lv_obj_get_style_text_line_space(obj, part) == 0 ? 1 : 0;
|
||||
list->transform_angle_zero = lv_obj_get_style_transform_angle(obj, part) == 0 ? 1 : 0;
|
||||
list->transform_height_zero = lv_obj_get_style_transform_width(obj, part) == 0 ? 1 : 0;
|
||||
list->transform_width_zero = lv_obj_get_style_transform_height(obj, part) == 0 ? 1 : 0;
|
||||
list->transform_zoom_zero = lv_obj_get_style_transform_zoom(obj, part) == LV_IMG_ZOOM_NONE ? 1 : 0;
|
||||
list->value_txt_str = lv_obj_get_style_value_str(obj, part) == NULL ? 1 : 0;
|
||||
|
||||
list->ignore_cache = ignore_cache_ori;
|
||||
list->valid_cache = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the object and all of it's children's style lists as invalid.
|
||||
* The cache will be updated when a cached property asked nest time
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void _lv_obj_invalidate_style_cache(lv_obj_t * obj)
|
||||
{
|
||||
uint8_t part;
|
||||
for(part = 0; part != _LV_OBJ_PART_REAL_LAST; part++) {
|
||||
lv_style_list_t * list = lv_obj_get_style_list(obj, part);
|
||||
if(list == NULL) break;
|
||||
list->valid_cache = 0;
|
||||
|
||||
}
|
||||
|
||||
lv_obj_t * child = lv_obj_get_child(obj, NULL);
|
||||
while(child) {
|
||||
_lv_obj_invalidate_style_cache(child);
|
||||
child = lv_obj_get_child(obj, child);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------
|
||||
* Attribute set
|
||||
*----------------*/
|
||||
@ -2448,12 +2508,58 @@ lv_style_int_t _lv_obj_get_style_int(const lv_obj_t * obj, uint8_t part, lv_styl
|
||||
lv_res_t res = LV_RES_INV;
|
||||
const lv_obj_t * parent = obj;
|
||||
while(parent) {
|
||||
lv_style_list_t * dsc = lv_obj_get_style_list(parent, part);
|
||||
lv_style_list_t * list = lv_obj_get_style_list(parent, part);
|
||||
|
||||
if(!list->ignore_cache) {
|
||||
_lv_obj_update_style_cache((lv_obj_t*)parent, part);
|
||||
bool def = false;
|
||||
switch(prop & (~LV_STYLE_STATE_MASK)) {
|
||||
case LV_STYLE_BG_GRAD_DIR:
|
||||
if(list->bg_grad_dir_none) def = true;
|
||||
break;
|
||||
case LV_STYLE_CLIP_CORNER:
|
||||
if(list->clip_corner_off) def = true;
|
||||
break;
|
||||
case LV_STYLE_TEXT_LETTER_SPACE:
|
||||
if(list->text_letter_space_zero) def = true;
|
||||
break;
|
||||
case LV_STYLE_TEXT_LINE_SPACE:
|
||||
if(list->text_line_space_zero) def = true;
|
||||
break;
|
||||
case LV_STYLE_TRANSFORM_ANGLE:
|
||||
if(list->transform_angle_zero) def = true;
|
||||
break;
|
||||
case LV_STYLE_TRANSFORM_WIDTH:
|
||||
if(list->transform_width_zero) def = true;
|
||||
break;
|
||||
case LV_STYLE_TRANSFORM_HEIGHT:
|
||||
if(list->transform_height_zero) def = true;
|
||||
break;
|
||||
case LV_STYLE_TRANSFORM_ZOOM:
|
||||
if(list->transform_zoom_zero) def = true;
|
||||
break;
|
||||
case LV_STYLE_BORDER_WIDTH:
|
||||
if(list->border_width_zero) def = true;
|
||||
break;
|
||||
case LV_STYLE_LINE_WIDTH:
|
||||
if(list->line_width_zerop) def = true;
|
||||
break;
|
||||
case LV_STYLE_OUTLINE_WIDTH:
|
||||
if(list->outline_width_zero) def = true;
|
||||
break;
|
||||
case LV_STYLE_SHADOW_WIDTH:
|
||||
if(list->shadow_width_zero) def = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(def) break;
|
||||
}
|
||||
|
||||
|
||||
lv_state_t state = lv_obj_get_state(parent, part);
|
||||
prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS);
|
||||
|
||||
res = _lv_style_list_get_int(dsc, prop, &value_act);
|
||||
res = _lv_style_list_get_int(list, prop, &value_act);
|
||||
if(res == LV_RES_OK) return value_act;
|
||||
|
||||
if(LV_STYLE_ATTR_GET_INHERIT(attr) == 0) break;
|
||||
@ -2511,12 +2617,12 @@ lv_color_t _lv_obj_get_style_color(const lv_obj_t * obj, uint8_t part, lv_style_
|
||||
lv_res_t res = LV_RES_INV;
|
||||
const lv_obj_t * parent = obj;
|
||||
while(parent) {
|
||||
lv_style_list_t * dsc = lv_obj_get_style_list(parent, part);
|
||||
lv_style_list_t * list = lv_obj_get_style_list(parent, part);
|
||||
|
||||
lv_state_t state = lv_obj_get_state(parent, part);
|
||||
prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS);
|
||||
|
||||
res = _lv_style_list_get_color(dsc, prop, &value_act);
|
||||
res = _lv_style_list_get_color(list, prop, &value_act);
|
||||
if(res == LV_RES_OK) return value_act;
|
||||
|
||||
if(LV_STYLE_ATTR_GET_INHERIT(attr) == 0) break;
|
||||
@ -2567,12 +2673,31 @@ lv_opa_t _lv_obj_get_style_opa(const lv_obj_t * obj, uint8_t part, lv_style_prop
|
||||
lv_res_t res = LV_RES_INV;
|
||||
const lv_obj_t * parent = obj;
|
||||
while(parent) {
|
||||
lv_style_list_t * dsc = lv_obj_get_style_list(parent, part);
|
||||
lv_style_list_t * list = lv_obj_get_style_list(parent, part);
|
||||
|
||||
|
||||
if(!list->ignore_cache) {
|
||||
_lv_obj_update_style_cache((lv_obj_t*)parent, part);
|
||||
bool def = false;
|
||||
switch(prop & (~LV_STYLE_STATE_MASK)) {
|
||||
case LV_STYLE_OPA_SCALE:
|
||||
if(list->opa_scale_transp) def = true;
|
||||
break;
|
||||
case LV_STYLE_BG_OPA:
|
||||
if(list->bg_opa_transp) def = true;
|
||||
break;
|
||||
case LV_STYLE_IMAGE_RECOLOR_OPA:
|
||||
if(list->img_recolor_opa_transp) def = true;
|
||||
break;
|
||||
}
|
||||
if(def) break;
|
||||
}
|
||||
|
||||
|
||||
lv_state_t state = lv_obj_get_state(parent, part);
|
||||
prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS);
|
||||
|
||||
res = _lv_style_list_get_opa(dsc, prop, &value_act);
|
||||
res = _lv_style_list_get_opa(list, prop, &value_act);
|
||||
if(res == LV_RES_OK) return value_act;
|
||||
|
||||
if(LV_STYLE_ATTR_GET_INHERIT(attr) == 0) break;
|
||||
@ -2624,12 +2749,27 @@ const void * _lv_obj_get_style_ptr(const lv_obj_t * obj, uint8_t part, lv_style_
|
||||
lv_res_t res = LV_RES_INV;
|
||||
const lv_obj_t * parent = obj;
|
||||
while(parent) {
|
||||
lv_style_list_t * dsc = lv_obj_get_style_list(parent, part);
|
||||
lv_style_list_t * list = lv_obj_get_style_list(parent, part);
|
||||
|
||||
if(!list->ignore_cache) {
|
||||
bool def = false;
|
||||
_lv_obj_update_style_cache((lv_obj_t*)parent, part);
|
||||
switch(prop & (~LV_STYLE_STATE_MASK)) {
|
||||
case LV_STYLE_VALUE_STR:
|
||||
if(list->opa_scale_transp) def = true;
|
||||
break;
|
||||
case LV_STYLE_PATTERN_IMAGE:
|
||||
if(list->pattern_img_null) def = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(def) break;
|
||||
}
|
||||
|
||||
lv_state_t state = lv_obj_get_state(parent, part);
|
||||
prop = (uint16_t)prop_ori + ((uint16_t)state << LV_STYLE_STATE_POS);
|
||||
|
||||
res = _lv_style_list_get_ptr(dsc, prop, &value_act);
|
||||
res = _lv_style_list_get_ptr(list, prop, &value_act);
|
||||
if(res == LV_RES_OK) return value_act;
|
||||
|
||||
if(LV_STYLE_ATTR_GET_INHERIT(attr) == 0) break;
|
||||
@ -3809,14 +3949,14 @@ static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coor
|
||||
*/
|
||||
static void report_style_mod_core(void * style, lv_obj_t * obj)
|
||||
{
|
||||
uint8_t part_sub;
|
||||
for(part_sub = 0; part_sub != _LV_OBJ_PART_REAL_LAST; part_sub++) {
|
||||
lv_style_list_t * dsc = lv_obj_get_style_list(obj, part_sub);
|
||||
if(dsc == NULL) break;
|
||||
uint8_t part;
|
||||
for(part = 0; part != _LV_OBJ_PART_REAL_LAST; part++) {
|
||||
lv_style_list_t * list = lv_obj_get_style_list(obj, part);
|
||||
if(list == NULL) break;
|
||||
|
||||
uint8_t ci;
|
||||
for(ci = 0; ci < dsc->style_cnt; ci++) {
|
||||
lv_style_t * class = lv_style_list_get_style(dsc, ci);
|
||||
for(ci = 0; ci < list->style_cnt; ci++) {
|
||||
lv_style_t * class = lv_style_list_get_style(list, ci);
|
||||
if(class == style || style == NULL) {
|
||||
lv_obj_refresh_style(obj, LV_STYLE_PROP_ALL);
|
||||
break;
|
||||
|
@ -595,6 +595,20 @@ void lv_obj_refresh_style(lv_obj_t * obj, lv_style_property_t prop);
|
||||
*/
|
||||
void lv_obj_report_style_mod(lv_style_t * style);
|
||||
|
||||
/**
|
||||
* Update the cache of style list
|
||||
* @param obj pointer to an obejct
|
||||
* @param part the part of the object
|
||||
*/
|
||||
void _lv_obj_update_style_cache(lv_obj_t * obj, uint8_t part);
|
||||
|
||||
/**
|
||||
* Mark the object and all of it's children's style lists as invalid.
|
||||
* The cache will be updated when a cached property asked nest time
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void _lv_obj_invalidate_style_cache(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Set a local style property of a part of an object in a given state.
|
||||
* @param obj pointer to an object
|
||||
|
@ -1052,6 +1052,9 @@ bool lv_debug_check_style_list(const lv_style_list_t * list)
|
||||
*/
|
||||
LV_ATTRIBUTE_FAST_MEM static inline int32_t get_property_index(const lv_style_t * style, lv_style_property_t prop)
|
||||
{
|
||||
static uint32_t c = 0;
|
||||
c++;
|
||||
if(c % 100 == 0) printf("%d\n", c);
|
||||
LV_ASSERT_STYLE(style);
|
||||
|
||||
if(style->map == NULL) return -1;
|
||||
|
@ -221,11 +221,32 @@ typedef struct {
|
||||
#if LV_USE_ASSERT_STYLE
|
||||
uint32_t sentinel;
|
||||
#endif
|
||||
uint8_t style_cnt;
|
||||
uint8_t has_local : 1;
|
||||
uint8_t has_trans : 1;
|
||||
uint8_t skip_trans : 1; /*1: Temporally skip the transition style if any*/
|
||||
uint8_t ignore_trans : 1; /*1: Mark that this style list shouldn't receive transitions at all*/
|
||||
uint32_t style_cnt :7;
|
||||
uint32_t has_local :1;
|
||||
uint32_t has_trans :1;
|
||||
uint32_t skip_trans :1; /*1: Temporally skip the transition style if any*/
|
||||
uint32_t ignore_trans :1; /*1: Mark that this style list shouldn't receive transitions at all*/
|
||||
uint32_t ignore_cache :1; /*1: Ignore cache while getting value of properties*/
|
||||
uint32_t valid_cache :1; /*1: The cache is invalid and needs to be updated*/
|
||||
|
||||
uint32_t opa_scale_transp :1;
|
||||
uint32_t clip_corner_off :1;
|
||||
uint32_t transform_width_zero :1;
|
||||
uint32_t transform_height_zero :1;
|
||||
uint32_t transform_angle_zero :1;
|
||||
uint32_t transform_zoom_zero :1;
|
||||
uint32_t bg_opa_transp :1;
|
||||
uint32_t bg_grad_dir_none :1;
|
||||
uint32_t border_width_zero :1;
|
||||
uint32_t outline_width_zero :1;
|
||||
uint32_t pattern_img_null :1;
|
||||
uint32_t shadow_width_zero :1;
|
||||
uint32_t value_txt_str :1;
|
||||
uint32_t line_width_zerop :1;
|
||||
uint32_t img_recolor_opa_transp :1;
|
||||
uint32_t text_letter_space_zero :1;
|
||||
uint32_t text_line_space_zero :1;
|
||||
uint32_t text_decor_none :1;
|
||||
} lv_style_list_t;
|
||||
|
||||
/**********************
|
||||
|
Loading…
x
Reference in New Issue
Block a user