From d6e7187d01647b167ca3ceed85bdd4354c98399b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 16 Jun 2020 12:47:09 +0200 Subject: [PATCH] fix crash when drawing gradient to the same color --- CHANGELOG.md | 3 ++- src/lv_draw/lv_draw_rect.c | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fef6a9eb1..e42521c2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,8 @@ - `lv_btnm` fix sending events for hidden buttons - `lv_gaguge` make `lv_gauge_set_angle_offset` offset the labels and needles too - Fix typo in the API `scrllable` -> `scrollable` -- `tabview`: by default allow auto expanding the page only to right and bottom (#1573) +- `tabview` by default allow auto expanding the page only to right and bottom (#1573) +- fix crash when drawing gradient to the same color ## v7.0.1 (01.06.2020) diff --git a/src/lv_draw/lv_draw_rect.c b/src/lv_draw/lv_draw_rect.c index c0ac87a88..466dce2c7 100644 --- a/src/lv_draw/lv_draw_rect.c +++ b/src/lv_draw/lv_draw_rect.c @@ -185,10 +185,13 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are /*Create a mask if there is a radius*/ lv_opa_t * mask_buf = _lv_mem_buf_get(draw_area_w); + lv_grad_dir_t grad_dir = dsc->bg_grad_dir; + if(dsc->bg_color.full == dsc->bg_grad_color.full) grad_dir = LV_GRAD_DIR_NONE; + uint16_t other_mask_cnt = lv_draw_mask_get_cnt(); bool simple_mode = true; if(other_mask_cnt) simple_mode = false; - else if(dsc->bg_grad_dir == LV_GRAD_DIR_HOR) simple_mode = false; + else if(grad_dir == LV_GRAD_DIR_HOR) simple_mode = false; int16_t mask_rout_id = LV_MASK_ID_INV; @@ -201,7 +204,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are if(rout > short_side >> 1) rout = short_side >> 1; /*Most simple case: just a plain rectangle*/ - if(simple_mode && rout == 0 && (dsc->bg_grad_dir == LV_GRAD_DIR_NONE)) { + if(simple_mode && rout == 0 && (grad_dir == LV_GRAD_DIR_NONE)) { _lv_blend_fill(clip, &coords_bg, dsc->bg_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, dsc->bg_blend_mode); @@ -222,7 +225,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are lv_color_t * grad_map = NULL; /*In case of horizontal gradient pre-compute a line with a gradient*/ - if(dsc->bg_grad_dir == LV_GRAD_DIR_HOR && dsc->bg_color.full != dsc->bg_grad_color.full) { + if(grad_dir == LV_GRAD_DIR_HOR) { grad_map = _lv_mem_buf_get(coords_w * sizeof(lv_color_t)); int32_t i; @@ -267,7 +270,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are } /*Get the current line color*/ - if(dsc->bg_grad_dir == LV_GRAD_DIR_VER && dsc->bg_color.full != dsc->bg_grad_color.full) { + if(grad_dir == LV_GRAD_DIR_VER) { grad_color = grad_get(dsc, lv_area_get_height(&coords_bg), y - coords_bg.y1); } @@ -288,7 +291,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are grad_color, mask_buf, mask_res, opa2, dsc->bg_blend_mode); /*Center part*/ - if(dsc->bg_grad_dir == LV_GRAD_DIR_VER) { + if(grad_dir == LV_GRAD_DIR_VER) { fill_area2.x1 = coords_bg.x1 + rout; fill_area2.x2 = coords_bg.x2 - rout; _lv_blend_fill(clip, &fill_area2, @@ -307,10 +310,10 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are } else { - if(dsc->bg_grad_dir == LV_GRAD_DIR_HOR) { + if(grad_dir == LV_GRAD_DIR_HOR) { _lv_blend_map(clip, &fill_area, grad_map, mask_buf, mask_res, opa2, dsc->bg_blend_mode); } - else if(dsc->bg_grad_dir == LV_GRAD_DIR_VER) { + else if(grad_dir == LV_GRAD_DIR_VER) { _lv_blend_fill(clip, &fill_area, grad_color, mask_buf, mask_res, opa2, dsc->bg_blend_mode); } @@ -323,7 +326,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_bg(const lv_area_t * coords, const lv_are fill_area.y2++; } - if(dsc->bg_grad_dir == LV_GRAD_DIR_NONE && other_mask_cnt == 0 && split) { + if(grad_dir == LV_GRAD_DIR_NONE && other_mask_cnt == 0 && split) { /*Central part*/ fill_area.x1 = coords_bg.x1 + rout; fill_area.x2 = coords_bg.x2 - rout;