mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-26 11:07:34 +08:00
fix(draw_vector): draw vector not calc draw_buf offset (#8262)
Signed-off-by: yushuailong1 <yushuailong1@xiaomi.com>
This commit is contained in:
@@ -46,6 +46,8 @@ typedef struct {
|
||||
typedef struct {
|
||||
Tvg_Canvas * canvas;
|
||||
int32_t partial_y_offset;
|
||||
int32_t translate_x;
|
||||
int32_t translate_y;
|
||||
} _tvg_draw_state;
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
@@ -436,20 +438,25 @@ static void _task_draw_cb(void * ctx, const lv_vector_path_t * path, const lv_ve
|
||||
};
|
||||
_set_paint_matrix(obj, &mtx);
|
||||
mtx.e23 -= (float)(y_offset);
|
||||
tvg_shape_append_rect(obj, rc.x, rc.y, rc.w, rc.h, 0, 0);
|
||||
tvg_shape_append_rect(obj, rc.x + state->translate_x, rc.y + state->translate_y, rc.w, rc.h, 0, 0);
|
||||
tvg_shape_set_fill_color(obj, c.r, c.g, c.b, c.a);
|
||||
}
|
||||
else {
|
||||
tvg_canvas_set_viewport(canvas, (int32_t)rc.x, (int32_t)(rc.y - y_offset), (int32_t)rc.w, (int32_t)rc.h);
|
||||
tvg_canvas_set_viewport(canvas, (int32_t)rc.x + state->translate_x, (int32_t)(rc.y - y_offset) + state->translate_y,
|
||||
(int32_t)rc.w, (int32_t)rc.h);
|
||||
|
||||
lv_matrix_t matrix;
|
||||
lv_matrix_identity(&matrix);
|
||||
lv_matrix_translate(&matrix, state->translate_x, state->translate_y);
|
||||
lv_matrix_multiply(&matrix, &dsc->matrix);
|
||||
Tvg_Matrix mtx;
|
||||
lv_matrix_to_tvg(&mtx, &dsc->matrix);
|
||||
lv_matrix_to_tvg(&mtx, &matrix);
|
||||
mtx.e23 -= (float)(y_offset);
|
||||
_set_paint_matrix(obj, &mtx);
|
||||
|
||||
_set_paint_shape(obj, path);
|
||||
|
||||
_set_paint_fill(obj, canvas, &dsc->fill_dsc, &dsc->matrix);
|
||||
_set_paint_fill(obj, canvas, &dsc->fill_dsc, &matrix);
|
||||
_set_paint_stroke(obj, &dsc->stroke_dsc);
|
||||
_set_paint_blend_mode(obj, dsc->blend_mode);
|
||||
}
|
||||
@@ -495,7 +502,7 @@ void lv_draw_sw_vector(lv_draw_task_t * t, lv_draw_vector_task_dsc_t * dsc)
|
||||
lv_area_to_tvg(&rc, &t->clip_area);
|
||||
tvg_canvas_set_viewport(canvas, (int32_t)rc.x, (int32_t)(rc.y - layer->partial_y_offset), (int32_t)rc.w, (int32_t)rc.h);
|
||||
|
||||
_tvg_draw_state state = {canvas, layer->partial_y_offset};
|
||||
_tvg_draw_state state = {canvas, layer->partial_y_offset, -layer->buf_area.x1, -layer->buf_area.y1};
|
||||
|
||||
lv_ll_t * task_list = dsc->task_list;
|
||||
lv_vector_for_each_destroy_tasks(task_list, _task_draw_cb, &state);
|
||||
|
||||
@@ -136,11 +136,10 @@ static void draw_execute(lv_draw_vg_lite_unit_t * u)
|
||||
|
||||
/* Crop out extra pixels drawn due to scaling accuracy issues */
|
||||
lv_area_t scissor_area = layer->phy_clip_area;
|
||||
lv_area_move(&scissor_area, -layer->buf_area.x1, -layer->buf_area.y1);
|
||||
#else
|
||||
lv_area_t scissor_area = layer->_clip_area;
|
||||
#endif
|
||||
|
||||
lv_area_move(&scissor_area, -layer->buf_area.x1, -layer->buf_area.y1);
|
||||
if(vg_lite_query_feature(gcFEATURE_BIT_VG_SCISSOR)) {
|
||||
lv_vg_lite_set_scissor_area(&scissor_area);
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ static void task_draw_cb(void * ctx, const lv_vector_path_t * path, const lv_vec
|
||||
|
||||
vg_lite_matrix_t matrix = u->global_matrix;
|
||||
|
||||
const lv_area_t scissor_area = lv_matrix_is_identity_or_translation((lv_matrix_t *)&matrix)
|
||||
const lv_area_t scissor_area = lv_matrix_is_identity((lv_matrix_t *)&matrix)
|
||||
? dsc->scissor_area
|
||||
: lv_matrix_transform_area((lv_matrix_t *)&matrix, &dsc->scissor_area);
|
||||
|
||||
|
||||
@@ -218,6 +218,11 @@ lv_area_t lv_matrix_transform_area(const lv_matrix_t * matrix, const lv_area_t *
|
||||
return res;
|
||||
}
|
||||
|
||||
bool lv_matrix_is_identity(const lv_matrix_t * matrix)
|
||||
{
|
||||
return (matrix->m[0][2] == 0.0f && matrix->m[1][2] == 0.0f && lv_matrix_is_identity_or_translation(matrix));
|
||||
}
|
||||
|
||||
bool lv_matrix_is_identity_or_translation(const lv_matrix_t * matrix)
|
||||
{
|
||||
return (matrix->m[0][0] == 1.0f &&
|
||||
|
||||
@@ -109,6 +109,13 @@ lv_point_precise_t lv_matrix_transform_precise_point(const lv_matrix_t * matrix,
|
||||
*/
|
||||
lv_area_t lv_matrix_transform_area(const lv_matrix_t * matrix, const lv_area_t * area);
|
||||
|
||||
/**
|
||||
* Check if the matrix is identity
|
||||
* @param matrix pointer to a matrix
|
||||
* @return true: the matrix is identity , false: the matrix is not identity
|
||||
*/
|
||||
bool lv_matrix_is_identity(const lv_matrix_t * matrix);
|
||||
|
||||
/**
|
||||
* Check if the matrix is identity or translation matrix
|
||||
* @param matrix pointer to a matrix
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
@@ -48,4 +48,23 @@ void test_svg_decoder_file(void)
|
||||
lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
|
||||
assert_screenshot("svg_decoder_2");
|
||||
}
|
||||
|
||||
void test_svg_snapshot(void)
|
||||
{
|
||||
LV_IMAGE_DECLARE(test_image_svg);
|
||||
lv_obj_t * img = lv_image_create(lv_screen_active());
|
||||
lv_image_set_src(img, &test_image_svg);
|
||||
lv_obj_center(img);
|
||||
|
||||
lv_draw_buf_t * draw_buf = lv_snapshot_take(img, LV_COLOR_FORMAT_ARGB8888);
|
||||
lv_obj_add_flag(img, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_t * img2 = lv_image_create(lv_screen_active());
|
||||
lv_image_set_src(img2, draw_buf);
|
||||
lv_obj_set_style_outline_width(img2, 2, 0);
|
||||
lv_obj_set_style_outline_color(img2, lv_color_hex3(0xf00), 0);
|
||||
lv_obj_center(img2);
|
||||
assert_screenshot("svg_decoder_3");
|
||||
lv_draw_buf_destroy(draw_buf);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user