1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

perf(vg_lite): reduce matrix and radius calculations (#6800)

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
VIFEX 2024-09-10 09:21:39 +08:00 committed by GitHub
parent f7a4fc9147
commit 0c8e77265e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 24 additions and 61 deletions

View File

@ -107,7 +107,9 @@ static void draw_execute(lv_draw_vg_lite_unit_t * u)
lv_draw_buf_set_flag(layer->draw_buf, LV_IMAGE_FLAGS_PREMULTIPLIED);
vg_lite_identity(&u->global_matrix);
vg_lite_translate(-layer->buf_area.x1, -layer->buf_area.y1, &u->global_matrix);
if(layer->buf_area.x1 || layer->buf_area.y1) {
vg_lite_translate(-layer->buf_area.x1, -layer->buf_area.y1, &u->global_matrix);
}
#if LV_DRAW_TRANSFORM_USE_MATRIX
vg_lite_matrix_t layer_matrix;

View File

@ -149,9 +149,7 @@ void lv_draw_vg_lite_arc(lv_draw_unit_t * draw_unit, const lv_draw_arc_dsc_t * d
lv_vg_lite_path_end(path);
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
lv_vg_lite_matrix_multiply(&matrix, &u->global_matrix);
vg_lite_matrix_t matrix = u->global_matrix;
vg_lite_color_t color = lv_vg_lite_color(dsc->color, dsc->opa, true);
@ -175,9 +173,7 @@ void lv_draw_vg_lite_arc(lv_draw_unit_t * draw_unit, const lv_draw_arc_dsc_t * d
vg_lite_buffer_t src_buf;
lv_image_decoder_dsc_t decoder_dsc;
if(lv_vg_lite_buffer_open_image(&src_buf, &decoder_dsc, dsc->img_src, false, true)) {
vg_lite_matrix_t path_matrix;
vg_lite_identity(&path_matrix);
lv_vg_lite_matrix_multiply(&path_matrix, &u->global_matrix);
vg_lite_matrix_t path_matrix = u->global_matrix;
/* move image to center */
vg_lite_translate(cx - radius_out, cy - radius_out, &matrix);

View File

@ -85,9 +85,7 @@ void lv_draw_vg_lite_border(lv_draw_unit_t * draw_unit, const lv_draw_border_dsc
lv_vg_lite_path_end(path);
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
lv_vg_lite_matrix_multiply(&matrix, &u->global_matrix);
vg_lite_matrix_t matrix = u->global_matrix;
vg_lite_color_t color = lv_vg_lite_color(dsc->color, dsc->opa, true);

View File

@ -57,22 +57,15 @@ void lv_draw_vg_lite_fill(lv_draw_unit_t * draw_unit, const lv_draw_fill_dsc_t *
LV_PROFILER_BEGIN;
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
lv_vg_lite_matrix_multiply(&matrix, &u->global_matrix);
int32_t w = lv_area_get_width(coords);
int32_t h = lv_area_get_height(coords);
float r = dsc->radius;
if(dsc->radius) {
float r_short = LV_MIN(w, h) / 2.0f;
r = LV_MIN(r, r_short);
}
vg_lite_matrix_t matrix = u->global_matrix;
lv_vg_lite_path_t * path = lv_vg_lite_path_get(u, VG_LITE_FP32);
lv_vg_lite_path_set_quality(path, dsc->radius == 0 ? VG_LITE_LOW : VG_LITE_HIGH);
lv_vg_lite_path_set_bonding_box_area(path, &clip_area);
lv_vg_lite_path_append_rect(path, coords->x1, coords->y1, w, h, r);
lv_vg_lite_path_append_rect(path,
coords->x1, coords->y1,
lv_area_get_width(coords), lv_area_get_height(coords),
dsc->radius);
lv_vg_lite_path_end(path);
vg_lite_path_t * vg_lite_path = lv_vg_lite_path_get_path(path);

View File

@ -98,13 +98,12 @@ void lv_draw_vg_lite_img(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t *
bool has_pre_mul = lv_draw_buf_has_flag(decoder_dsc.decoded, LV_IMAGE_FLAGS_PREMULTIPLIED);
vg_lite_blend_t blend = lv_vg_lite_blend_mode(dsc->blend_mode, has_pre_mul);
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
lv_vg_lite_matrix_multiply(&matrix, &u->global_matrix);
vg_lite_matrix_t matrix = u->global_matrix;
lv_vg_lite_image_matrix(&matrix, coords->x1, coords->y1, dsc);
LV_VG_LITE_ASSERT_SRC_BUFFER(&src_buf);
LV_VG_LITE_ASSERT_DEST_BUFFER(&u->target_buffer);
LV_VG_LITE_ASSERT_MATRIX(&matrix);
bool no_transform = lv_matrix_is_identity_or_translation((const lv_matrix_t *)&matrix);
vg_lite_filter_t filter = no_transform ? VG_LITE_FILTER_POINT : VG_LITE_FILTER_BI_LINEAR;
@ -158,9 +157,8 @@ void lv_draw_vg_lite_img(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t *
vg_lite_path_t * vg_lite_path = lv_vg_lite_path_get_path(path);
LV_VG_LITE_ASSERT_PATH(vg_lite_path);
vg_lite_matrix_t path_matrix;
vg_lite_identity(&path_matrix);
lv_vg_lite_matrix_multiply(&path_matrix, &u->global_matrix);
vg_lite_matrix_t path_matrix = u->global_matrix;
LV_VG_LITE_ASSERT_MATRIX(&path_matrix);
LV_PROFILER_BEGIN_TAG("vg_lite_draw_pattern");
LV_VG_LITE_CHECK_ERROR(vg_lite_draw_pattern(

View File

@ -150,9 +150,7 @@ static void draw_letter_bitmap(lv_draw_vg_lite_unit_t * u, const lv_draw_glyph_d
lv_area_t image_area = *dsc->letter_coords;
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
lv_vg_lite_matrix_multiply(&matrix, &u->global_matrix);
vg_lite_matrix_t matrix = u->global_matrix;
vg_lite_translate(image_area.x1, image_area.y1, &matrix);
vg_lite_buffer_t src_buf;
@ -198,9 +196,7 @@ static void draw_letter_bitmap(lv_draw_vg_lite_unit_t * u, const lv_draw_glyph_d
vg_lite_path_t * vg_lite_path = lv_vg_lite_path_get_path(path);
LV_VG_LITE_ASSERT_PATH(vg_lite_path);
vg_lite_matrix_t path_matrix;
vg_lite_identity(&path_matrix);
lv_vg_lite_matrix_multiply(&path_matrix, &u->global_matrix);
vg_lite_matrix_t path_matrix = u->global_matrix;
LV_VG_LITE_ASSERT_MATRIX(&path_matrix);
LV_PROFILER_BEGIN_TAG("vg_lite_draw_pattern");
@ -255,10 +251,7 @@ static void draw_letter_outline(lv_draw_vg_lite_unit_t * u, const lv_draw_glyph_
vg_lite_identity(&matrix);
/* matrix for drawing, different from matrix for calculating the bonding box */
vg_lite_matrix_t draw_matrix;
vg_lite_identity(&draw_matrix);
lv_vg_lite_matrix_multiply(&draw_matrix, &u->global_matrix);
vg_lite_matrix_t draw_matrix = u->global_matrix;
/* convert to vg-lite coordinate */
vg_lite_translate(pos.x - dsc->g->ofs_x, pos.y + dsc->g->box_h + dsc->g->ofs_y, &draw_matrix);

View File

@ -180,9 +180,7 @@ void lv_draw_vg_lite_line(lv_draw_unit_t * draw_unit, const lv_draw_line_dsc_t *
lv_vg_lite_path_end(path);
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
lv_vg_lite_matrix_multiply(&matrix, &u->global_matrix);
vg_lite_matrix_t matrix = u->global_matrix;
vg_lite_color_t color = lv_vg_lite_color(dsc->color, dsc->opa, true);

View File

@ -102,28 +102,23 @@ void lv_draw_vg_lite_mask_rect(lv_draw_unit_t * draw_unit, const lv_draw_mask_re
int32_t w = lv_area_get_width(&dsc->area);
int32_t h = lv_area_get_height(&dsc->area);
float r = dsc->radius;
if(dsc->radius) {
float r_short = LV_MIN(w, h) / 2.0f;
r = LV_MIN(r, r_short);
}
lv_vg_lite_path_t * path = lv_vg_lite_path_get(u, VG_LITE_FP32);
lv_vg_lite_path_set_quality(path, VG_LITE_HIGH);
lv_vg_lite_path_set_bonding_box_area(path, &draw_area);
/* Use rounded rectangles and normal rectangles of the same size to nest the cropped area */
lv_vg_lite_path_append_rect(path, dsc->area.x1, dsc->area.y1, w, h, r);
lv_vg_lite_path_append_rect(path, dsc->area.x1, dsc->area.y1, w, h, dsc->radius);
lv_vg_lite_path_append_rect(path, dsc->area.x1, dsc->area.y1, w, h, 0);
lv_vg_lite_path_end(path);
vg_lite_path_t * vg_lite_path = lv_vg_lite_path_get_path(path);
vg_lite_matrix_t * matrix = &u->global_matrix;
vg_lite_matrix_t matrix = u->global_matrix;
LV_VG_LITE_ASSERT_DEST_BUFFER(&u->target_buffer);
LV_VG_LITE_ASSERT_PATH(vg_lite_path);
LV_VG_LITE_ASSERT_MATRIX(matrix);
LV_VG_LITE_ASSERT_MATRIX(&matrix);
/* Use VG_LITE_BLEND_DST_IN (Sa * D) blending mode to make the corners transparent */
LV_PROFILER_BEGIN_TAG("vg_lite_draw");
@ -131,7 +126,7 @@ void lv_draw_vg_lite_mask_rect(lv_draw_unit_t * draw_unit, const lv_draw_mask_re
&u->target_buffer,
vg_lite_path,
VG_LITE_FILL_EVEN_ODD,
matrix,
&matrix,
VG_LITE_BLEND_DST_IN,
0));
LV_PROFILER_END_TAG("vg_lite_draw");

View File

@ -71,9 +71,7 @@ void lv_draw_vg_lite_triangle(lv_draw_unit_t * draw_unit, const lv_draw_triangle
LV_VG_LITE_ASSERT_DEST_BUFFER(&u->target_buffer);
LV_VG_LITE_ASSERT_PATH(vg_lite_path);
vg_lite_matrix_t matrix;
vg_lite_identity(&matrix);
lv_vg_lite_matrix_multiply(&matrix, &u->global_matrix);
vg_lite_matrix_t matrix = u->global_matrix;
LV_VG_LITE_ASSERT_MATRIX(&matrix);
if(dsc->bg_grad.dir != LV_GRAD_DIR_NONE) {

View File

@ -778,15 +778,11 @@ void lv_vg_lite_rect(vg_lite_rectangle_t * rect, const lv_area_t * area)
rect->height = lv_area_get_height(area);
}
#if LV_USE_MATRIX
void lv_vg_lite_matrix(vg_lite_matrix_t * dest, const lv_matrix_t * src)
{
lv_memcpy(dest, src, sizeof(lv_matrix_t));
}
#endif
uint32_t lv_vg_lite_get_palette_size(vg_lite_buffer_format_t format)
{
uint32_t size = 0;

View File

@ -145,12 +145,8 @@ vg_lite_color_t lv_vg_lite_color(lv_color_t color, lv_opa_t opa, bool pre_mul);
void lv_vg_lite_rect(vg_lite_rectangle_t * rect, const lv_area_t * area);
#if LV_USE_MATRIX
void lv_vg_lite_matrix(vg_lite_matrix_t * dest, const lv_matrix_t * src);
#endif
/* Param checker */
bool lv_vg_lite_buffer_check(const vg_lite_buffer_t * buffer, bool is_src);