Skip to content

Commit

Permalink
fix(vg_lite): fix rounded rectangle path error
Browse files Browse the repository at this point in the history
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
  • Loading branch information
pengyiqiang committed Aug 23, 2024
1 parent a7853fb commit 4511c17
Show file tree
Hide file tree
Showing 228 changed files with 50 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/draw/vg_lite/lv_draw_vg_lite_border.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ void lv_draw_vg_lite_border(lv_draw_unit_t * draw_unit, const lv_draw_border_dsc
lv_vg_lite_path_append_rect(path,
coords->x1, coords->y1,
w, h,
r_out, r_out);
r_out);

/* inner rect */
lv_vg_lite_path_append_rect(path,
coords->x1 + border_w, coords->y1 + border_w,
w - border_w * 2, h - border_w * 2,
r_in, r_in);
r_in);

lv_vg_lite_path_end(path);

Expand Down
2 changes: 1 addition & 1 deletion src/draw/vg_lite/lv_draw_vg_lite_fill.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void lv_draw_vg_lite_fill(lv_draw_unit_t * draw_unit, const lv_draw_fill_dsc_t *
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, r);
lv_vg_lite_path_append_rect(path, coords->x1, coords->y1, w, h, r);
lv_vg_lite_path_end(path);

vg_lite_path_t * vg_lite_path = lv_vg_lite_path_get_path(path);
Expand Down
4 changes: 2 additions & 2 deletions src/draw/vg_lite/lv_draw_vg_lite_img.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ void lv_draw_vg_lite_img(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t *
path,
coords->x1, coords->y1,
width, height,
radius, radius);
radius);
}
else {
lv_vg_lite_path_append_rect(
path,
clip_area.x1, clip_area.y1,
lv_area_get_width(&clip_area), lv_area_get_height(&clip_area),
0, 0);
0);
}

lv_vg_lite_path_set_bonding_box_area(path, &clip_area);
Expand Down
2 changes: 1 addition & 1 deletion src/draw/vg_lite/lv_draw_vg_lite_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static void draw_letter_bitmap(lv_draw_vg_lite_unit_t * u, const lv_draw_glyph_d
path,
clip_area.x1, clip_area.y1,
lv_area_get_width(&clip_area), lv_area_get_height(&clip_area),
0, 0);
0);
lv_vg_lite_path_set_bonding_box_area(path, &clip_area);
lv_vg_lite_path_end(path);

Expand Down
4 changes: 2 additions & 2 deletions src/draw/vg_lite/lv_draw_vg_lite_mask_rect.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ void lv_draw_vg_lite_mask_rect(lv_draw_unit_t * draw_unit, const lv_draw_mask_re
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, r);
lv_vg_lite_path_append_rect(path, dsc->area.x1, dsc->area.y1, w, h, 0, 0);
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, 0);
lv_vg_lite_path_end(path);

vg_lite_path_t * vg_lite_path = lv_vg_lite_path_get_path(path);
Expand Down
63 changes: 41 additions & 22 deletions src/draw/vg_lite/lv_vg_lite_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,19 @@ void lv_vg_lite_path_append_rect(
lv_vg_lite_path_t * path,
float x, float y,
float w, float h,
float rx, float ry)
float r)
{
LV_PROFILER_BEGIN;
const float half_w = w * 0.5f;
const float half_h = h * 0.5f;
const float half_w = w / 2.0f;
const float half_h = h / 2.0f;

/*clamping cornerRadius by minimum size*/
if(rx > half_w)
rx = half_w;
if(ry > half_h)
ry = half_h;
const float r_max = LV_MIN(half_w, half_h);
if(r > r_max)
r = r_max;

/*rectangle*/
if(rx == 0 && ry == 0) {
if(r <= 0) {
lv_vg_lite_path_move_to(path, x, y);
lv_vg_lite_path_line_to(path, x + w, y);
lv_vg_lite_path_line_to(path, x + w, y + h);
Expand All @@ -358,24 +357,44 @@ void lv_vg_lite_path_append_rect(
}

/*circle*/
if(math_equal(rx, half_w) && math_equal(ry, half_h)) {
lv_vg_lite_path_append_circle(path, x + (w * 0.5f), y + (h * 0.5f), rx, ry);
if(math_equal(r, half_w) && math_equal(r, half_h)) {
lv_vg_lite_path_append_circle(path, x + half_w, y + half_h, r, r);
LV_PROFILER_END;
return;
}

/*rounded rectangle*/
float hrx = rx * 0.5f;
float hry = ry * 0.5f;
lv_vg_lite_path_move_to(path, x + rx, y);
lv_vg_lite_path_line_to(path, x + w - rx, y);
lv_vg_lite_path_cubic_to(path, x + w - rx + hrx, y, x + w, y + ry - hry, x + w, y + ry);
lv_vg_lite_path_line_to(path, x + w, y + h - ry);
lv_vg_lite_path_cubic_to(path, x + w, y + h - ry + hry, x + w - rx + hrx, y + h, x + w - rx, y + h);
lv_vg_lite_path_line_to(path, x + rx, y + h);
lv_vg_lite_path_cubic_to(path, x + rx - hrx, y + h, x, y + h - ry + hry, x, y + h - ry);
lv_vg_lite_path_line_to(path, x, y + ry);
lv_vg_lite_path_cubic_to(path, x, y + ry - hry, x + rx - hrx, y, x + rx, y);
/* Get the control point offset for rounded cases */
const float offset = r * PATH_ARC_MAGIC;

/* Rounded rectangle case */
/* Starting point */
lv_vg_lite_path_move_to(path, x + r, y);

/* Top side */
lv_vg_lite_path_line_to(path, x + w - r, y);

/* Top-right corner */
lv_vg_lite_path_cubic_to(path, x + w - r + offset, y, x + w, y + r - offset, x + w, y + r);

/* Right side */
lv_vg_lite_path_line_to(path, x + w, y + h - r);

/* Bottom-right corner*/
lv_vg_lite_path_cubic_to(path, x + w, y + h - r + offset, x + w - r + offset, y + h, x + w - r, y + h);

/* Bottom side */
lv_vg_lite_path_line_to(path, x + r, y + h);

/* Bottom-left corner */
lv_vg_lite_path_cubic_to(path, x + r - offset, y + h, x, y + h - r + offset, x, y + h - r);

/* Left side*/
lv_vg_lite_path_line_to(path, x, y + r);

/* Top-left corner */
lv_vg_lite_path_cubic_to(path, x, y + r - offset, x + r - offset, y, x + r, y);

/* Ending point */
lv_vg_lite_path_close(path);
LV_PROFILER_END;
}
Expand Down
2 changes: 1 addition & 1 deletion src/draw/vg_lite/lv_vg_lite_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void lv_vg_lite_path_end(lv_vg_lite_path_t * path);
void lv_vg_lite_path_append_rect(lv_vg_lite_path_t * path,
float x, float y,
float w, float h,
float rx, float ry);
float r);

void lv_vg_lite_path_append_circle(lv_vg_lite_path_t * path,
float cx, float cy,
Expand Down
Binary file modified tests/ref_imgs_vg_lite/binding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride1_LZ4_recolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride1_LZ4_rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride1_LZ4_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride1_RLE_recolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride1_RLE_rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride1_RLE_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride64_LZ4_recolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride64_LZ4_rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride64_LZ4_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride64_RLE_recolor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride64_RLE_rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/bin_image_stride64_RLE_simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/ref_imgs_vg_lite/draw/blend_to_argb8888.png
Binary file modified tests/ref_imgs_vg_lite/draw/blend_to_rgb565.png
Binary file modified tests/ref_imgs_vg_lite/draw/blend_to_rgb888.png
Binary file modified tests/ref_imgs_vg_lite/draw/blend_to_xrgb8888.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride1_LZ4_recolor.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride1_LZ4_rotate.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride1_LZ4_simple.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride1_RLE_recolor.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride1_RLE_rotate.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride1_RLE_simple.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride64_LZ4_recolor.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride64_LZ4_rotate.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride64_LZ4_simple.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride64_RLE_recolor.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride64_RLE_rotate.png
Binary file modified tests/ref_imgs_vg_lite/draw/c_array_image_stride64_RLE_simple.png
Binary file modified tests/ref_imgs_vg_lite/draw/clip_corner_1.png
Binary file modified tests/ref_imgs_vg_lite/draw/draw_layer_bitmap_mask.png
Binary file modified tests/ref_imgs_vg_lite/draw/draw_layer_bitmap_mask_not_masked.png
Binary file modified tests/ref_imgs_vg_lite/draw/layer_transform_1.png
Binary file modified tests/ref_imgs_vg_lite/draw/layer_transform_2.png
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Binary file modified tests/ref_imgs_vg_lite/draw/vector_draw_during_rendering.png
Diff not rendered.
Diff not rendered.
Binary file modified tests/ref_imgs_vg_lite/grid_fr.png
Binary file modified tests/ref_imgs_vg_lite/libs/tiny_ttf_2.png
Binary file modified tests/ref_imgs_vg_lite/margin_align_0.png
Binary file modified tests/ref_imgs_vg_lite/margin_align_1.png
Binary file modified tests/ref_imgs_vg_lite/margin_flex_0.png
Binary file modified tests/ref_imgs_vg_lite/margin_flex_1.png
Binary file modified tests/ref_imgs_vg_lite/margin_flex_2.png
Binary file modified tests/ref_imgs_vg_lite/margin_flex_3.png
Binary file modified tests/ref_imgs_vg_lite/margin_flex_4.png
Binary file modified tests/ref_imgs_vg_lite/margin_flex_5.png
Binary file modified tests/ref_imgs_vg_lite/scale_2.png
Binary file modified tests/ref_imgs_vg_lite/subgrid_col.png
Binary file modified tests/ref_imgs_vg_lite/subgrid_row.png
Binary file modified tests/ref_imgs_vg_lite/widgets/bar_1.png
Binary file modified tests/ref_imgs_vg_lite/widgets/bar_2.png
Binary file modified tests/ref_imgs_vg_lite/widgets/bar_corner_1.png
Binary file modified tests/ref_imgs_vg_lite/widgets/bar_corner_2.png
Binary file modified tests/ref_imgs_vg_lite/widgets/bar_corner_3.png
Binary file modified tests/ref_imgs_vg_lite/widgets/bar_corner_4.png
Binary file modified tests/ref_imgs_vg_lite/widgets/bar_corner_5.png
Binary file modified tests/ref_imgs_vg_lite/widgets/bar_corner_6.png
Binary file modified tests/ref_imgs_vg_lite/widgets/btnm_1.png
Binary file modified tests/ref_imgs_vg_lite/widgets/btnm_2.png
Binary file modified tests/ref_imgs_vg_lite/widgets/calendar_01.png
Binary file modified tests/ref_imgs_vg_lite/widgets/calendar_02.png
Binary file modified tests/ref_imgs_vg_lite/widgets/calendar_03.png
Binary file modified tests/ref_imgs_vg_lite/widgets/calendar_04.png
Binary file modified tests/ref_imgs_vg_lite/widgets/calendar_05.png
Binary file modified tests/ref_imgs_vg_lite/widgets/calendar_06.png
Binary file modified tests/ref_imgs_vg_lite/widgets/calendar_07.png
Binary file modified tests/ref_imgs_vg_lite/widgets/calendar_08.png
Binary file modified tests/ref_imgs_vg_lite/widgets/calendar_09.png
Binary file modified tests/ref_imgs_vg_lite/widgets/chart_bar_draw_hook.png
Binary file modified tests/ref_imgs_vg_lite/widgets/chart_line_draw_hook.png
Binary file modified tests/ref_imgs_vg_lite/widgets/checkbox_rtl_1.png
Binary file modified tests/ref_imgs_vg_lite/widgets/dropdown_1.png
Binary file modified tests/ref_imgs_vg_lite/widgets/dropdown_2.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_clip_radius_10.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_normal_align.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_normal_align_offset.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_rotate_pivot_center.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_rotate_pivot_top_left.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_scale_pivot_center.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_scale_pivot_top_left.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_scale_x_pivot_center.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_scale_x_pivot_top_left.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_scale_y_pivot_center.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_scale_y_pivot_top_left.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_stretch.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_tile.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_transform_align.png
Binary file modified tests/ref_imgs_vg_lite/widgets/image_transform_align_offset.png
Binary file modified tests/ref_imgs_vg_lite/widgets/keyboard_1.png
Binary file modified tests/ref_imgs_vg_lite/widgets/keyboard_2.png
Binary file modified tests/ref_imgs_vg_lite/widgets/keyboard_3.png
Binary file modified tests/ref_imgs_vg_lite/widgets/keyboard_4.png
Binary file modified tests/ref_imgs_vg_lite/widgets/list_1.png
Binary file modified tests/ref_imgs_vg_lite/widgets/msgbox_ok_no_close_btn.png
Binary file modified tests/ref_imgs_vg_lite/widgets/msgbox_ok_with_close_btn.png
Binary file modified tests/ref_imgs_vg_lite/widgets/obj_flag_overflow_visible_1_1.png
Binary file modified tests/ref_imgs_vg_lite/widgets/obj_flag_overflow_visible_1_2.png
Binary file modified tests/ref_imgs_vg_lite/widgets/obj_flag_overflow_visible_1_3.png
Binary file modified tests/ref_imgs_vg_lite/widgets/obj_flag_overflow_visible_1_4.png
Binary file modified tests/ref_imgs_vg_lite/widgets/roller_2.png
Binary file modified tests/ref_imgs_vg_lite/widgets/roller_3.png
Binary file modified tests/ref_imgs_vg_lite/widgets/span_08.png
Binary file modified tests/ref_imgs_vg_lite/widgets/win_01.png
Binary file modified tests/ref_imgs_vg_lite/widgets/win_02.png

0 comments on commit 4511c17

Please sign in to comment.