perf(vg_lite): simplify the global path acquisition method (#5325)

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
_VIFEXTech
2024-01-15 19:38:06 +08:00
committed by GitHub
parent e0be0c9253
commit d619d6b7f5
2 changed files with 15 additions and 50 deletions

View File

@@ -39,8 +39,8 @@ struct _lv_draw_vg_lite_unit_t {
lv_draw_task_t * task_act;
vg_lite_buffer_t target_buffer;
vg_lite_matrix_t global_matrix;
lv_ll_t path_free_ll;
int path_max_cnt;
struct _lv_vg_lite_path_t * global_path;
bool path_in_use;
};
/**********************

View File

@@ -20,7 +20,6 @@
*********************/
#define PATH_KAPPA 0.552284f
#define PATH_MAX_CNT 32
/* Magic number from https://spencermortensen.com/articles/bezier-circle/ */
#define PATH_ARC_MAGIC 0.55191502449351f
@@ -41,8 +40,6 @@ struct _lv_vg_lite_path_t {
uint8_t format_len;
};
typedef struct _lv_vg_lite_path_t * lv_vg_lite_path_ref_t;
typedef struct {
float min_x;
float min_y;
@@ -69,21 +66,16 @@ typedef struct {
void lv_vg_lite_path_init(struct _lv_draw_vg_lite_unit_t * unit)
{
LV_ASSERT_NULL(unit);
_lv_ll_init(&unit->path_free_ll, sizeof(lv_vg_lite_path_ref_t));
unit->global_path = lv_vg_lite_path_create(VG_LITE_FP32);
unit->path_in_use = false;
}
void lv_vg_lite_path_deinit(struct _lv_draw_vg_lite_unit_t * unit)
{
LV_ASSERT_NULL(unit);
lv_ll_t * ll_p = &unit->path_free_ll;
lv_vg_lite_path_ref_t * path_ref;
_LV_LL_READ(ll_p, path_ref) {
lv_vg_lite_path_destroy(*path_ref);
}
_lv_ll_clear(ll_p);
LV_ASSERT(!unit->path_in_use);
lv_vg_lite_path_destroy(unit->global_path);
unit->global_path = NULL;
}
lv_vg_lite_path_t * lv_vg_lite_path_create(vg_lite_format_t data_format)
@@ -115,52 +107,25 @@ void lv_vg_lite_path_destroy(lv_vg_lite_path_t * path)
lv_vg_lite_path_t * lv_vg_lite_path_get(struct _lv_draw_vg_lite_unit_t * unit, vg_lite_format_t data_format)
{
LV_ASSERT_NULL(unit);
unit->path_max_cnt++;
LV_ASSERT(unit->path_max_cnt < PATH_MAX_CNT);
lv_ll_t * ll_p = &unit->path_free_ll;
lv_vg_lite_path_ref_t * path_ref = _lv_ll_get_head(ll_p);
if(path_ref) {
lv_vg_lite_path_t * path = *path_ref;
lv_vg_lite_path_reset(path, data_format);
_lv_ll_remove(ll_p, path_ref);
lv_free(path_ref);
return path;
}
return lv_vg_lite_path_create(data_format);
LV_ASSERT_NULL(unit->global_path);
LV_ASSERT(!unit->path_in_use);
lv_vg_lite_path_reset(unit->global_path, data_format);
unit->path_in_use = true;
return unit->global_path;
}
void lv_vg_lite_path_drop(struct _lv_draw_vg_lite_unit_t * unit, lv_vg_lite_path_t * path)
{
LV_ASSERT_NULL(unit);
LV_ASSERT_NULL(path);
unit->path_max_cnt--;
LV_ASSERT(unit->path_max_cnt >= 0);
lv_ll_t * ll_p = &unit->path_free_ll;
uint32_t len = _lv_ll_get_len(ll_p);
if(len >= PATH_MAX_CNT) {
lv_vg_lite_path_ref_t * tail = _lv_ll_get_tail(ll_p);
lv_vg_lite_path_destroy(*tail);
_lv_ll_remove(ll_p, tail);
lv_free(tail);
}
lv_vg_lite_path_ref_t * head = _lv_ll_ins_head(ll_p);
LV_ASSERT_MALLOC(head);
*head = path;
LV_ASSERT(unit->global_path == path);
LV_ASSERT(unit->path_in_use);
unit->path_in_use = false;
}
void lv_vg_lite_path_reset(lv_vg_lite_path_t * path, vg_lite_format_t data_format)
{
LV_ASSERT_NULL(path);
lv_memzero(path->base.path, path->mem_size);
path->base.path_length = 0;
path->base.format = data_format;
path->base.quality = VG_LITE_MEDIUM;