diff --git a/demos/lv_demos.c b/demos/lv_demos.c index 3decc20be..56af19994 100644 --- a/demos/lv_demos.c +++ b/demos/lv_demos.c @@ -64,7 +64,11 @@ static const demo_entry_info_t demos_entry_info[] = { #endif #if LV_USE_DEMO_VECTOR_GRAPHIC && LV_USE_VECTOR_GRAPHIC - { "vector_graphic", .entry_cb = lv_demo_vector_graphic }, + { "vector_graphic_buffered", .entry_cb = lv_demo_vector_graphic_buffered }, +#endif + +#if LV_USE_DEMO_VECTOR_GRAPHIC && LV_USE_VECTOR_GRAPHIC + { "vector_graphic_not_buffered", .entry_cb = lv_demo_vector_graphic_not_buffered }, #endif #if LV_USE_DEMO_BENCHMARK diff --git a/demos/vector_graphic/lv_demo_vector_graphic.c b/demos/vector_graphic/lv_demo_vector_graphic.c index be5ae5728..38729da05 100644 --- a/demos/vector_graphic/lv_demo_vector_graphic.c +++ b/demos/vector_graphic/lv_demo_vector_graphic.c @@ -245,6 +245,13 @@ static void delete_event_cb(lv_event_t * e) lv_draw_buf_destroy(draw_buf); } +static void event_cb(lv_event_t * e) +{ + lv_layer_t * layer = lv_event_get_layer(e); + + draw_vector(layer); +} + /********************** * STATIC VARIABLES **********************/ @@ -257,7 +264,12 @@ static void delete_event_cb(lv_event_t * e) * GLOBAL FUNCTIONS **********************/ -void lv_demo_vector_graphic(void) +void lv_demo_vector_graphic_not_buffered(void) +{ + lv_obj_add_event_cb(lv_screen_active(), event_cb, LV_EVENT_DRAW_MAIN, NULL); +} + +void lv_demo_vector_graphic_buffered(void) { lv_draw_buf_t * draw_buf = lv_draw_buf_create(WIDTH, HEIGHT, LV_COLOR_FORMAT_ARGB8888, LV_STRIDE_AUTO); lv_draw_buf_clear(draw_buf, NULL); @@ -278,7 +290,15 @@ void lv_demo_vector_graphic(void) **********************/ #else -void lv_demo_vector_graphic(void) +void lv_demo_vector_graphic_not_buffered(void) +{ + /*fallback for online examples*/ + lv_obj_t * label = lv_label_create(lv_screen_active()); + lv_label_set_text(label, "Vector graphics is not enabled"); + lv_obj_center(label); +} + +void lv_demo_vector_graphic_buffered(void) { /*fallback for online examples*/ lv_obj_t * label = lv_label_create(lv_screen_active()); diff --git a/demos/vector_graphic/lv_demo_vector_graphic.h b/demos/vector_graphic/lv_demo_vector_graphic.h index caf2acc4c..853e91799 100644 --- a/demos/vector_graphic/lv_demo_vector_graphic.h +++ b/demos/vector_graphic/lv_demo_vector_graphic.h @@ -27,7 +27,18 @@ extern "C" { /********************** * GLOBAL PROTOTYPES **********************/ -void lv_demo_vector_graphic(void); + +/** + * Draw many vector based shapes and paths to canvas. + * It requires a large amount of RAM for the buffer of the canvas + */ +void lv_demo_vector_graphic_buffered(void); + +/** + * Draw many vector based shapes and paths to canvas directly to the screen. + * It's slower as the graphics needs to rendered on each rendering cycle. + */ +void lv_demo_vector_graphic_not_buffered(void); /********************** * MACROS diff --git a/src/libs/thorvg/tvgSwRenderer.cpp b/src/libs/thorvg/tvgSwRenderer.cpp index 70234a952..9a0965424 100644 --- a/src/libs/thorvg/tvgSwRenderer.cpp +++ b/src/libs/thorvg/tvgSwRenderer.cpp @@ -443,11 +443,7 @@ bool SwRenderer::target(pixel_t* data, uint32_t stride, uint32_t w, uint32_t h, bool SwRenderer::preRender() { -#if LV_USE_DRAW_VG_LITE && LV_USE_VG_LITE_THORVG - return true; -#else - return rasterClear(surface, 0, 0, surface->w, surface->h); -#endif + return true; } diff --git a/src/widgets/lottie/lv_lottie.c b/src/widgets/lottie/lv_lottie.c index e30c7fe37..ea803d48d 100644 --- a/src/widgets/lottie/lv_lottie.c +++ b/src/widgets/lottie/lv_lottie.c @@ -219,14 +219,8 @@ static void lottie_update(lv_lottie_t * lottie, int32_t v) lv_draw_buf_t * draw_buf = lv_canvas_get_draw_buf(obj); if(draw_buf) { -#if LV_USE_DRAW_VG_LITE && LV_USE_VG_LITE_THORVG - /** - * Since the buffer clearing operation in the SwRenderer::preRender - * function is removed when the VG-Lite simulator is enabled, the canvas - * buffer must be manually cleared here. - */ lv_draw_buf_clear(draw_buf, NULL); -#endif + /*Drop old cached image*/ lv_image_cache_drop(lv_image_get_src(obj)); } diff --git a/tests/ref_imgs/draw/vector_draw_during_rendering.png b/tests/ref_imgs/draw/vector_draw_during_rendering.png new file mode 100644 index 000000000..1ef7ba54d Binary files /dev/null and b/tests/ref_imgs/draw/vector_draw_during_rendering.png differ diff --git a/tests/ref_imgs_vg_lite/draw/vector_draw_during_rendering.png b/tests/ref_imgs_vg_lite/draw/vector_draw_during_rendering.png new file mode 100644 index 000000000..65d5ee56b Binary files /dev/null and b/tests/ref_imgs_vg_lite/draw/vector_draw_during_rendering.png differ diff --git a/tests/src/test_cases/draw/test_draw_vector.c b/tests/src/test_cases/draw/test_draw_vector.c index cb729cd33..71ece5e6b 100644 --- a/tests/src/test_cases/draw/test_draw_vector.c +++ b/tests/src/test_cases/draw/test_draw_vector.c @@ -240,6 +240,8 @@ static void canvas_draw(const char * name, void (*draw_cb)(lv_layer_t *)) lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); lv_draw_buf_t * draw_buf = lv_draw_buf_create(640, 480, LV_COLOR_FORMAT_ARGB8888, LV_STRIDE_AUTO); TEST_ASSERT_NOT_NULL(draw_buf); + + lv_draw_buf_clear(draw_buf, NULL); lv_canvas_set_draw_buf(canvas, draw_buf); lv_layer_t layer; @@ -297,4 +299,38 @@ void test_draw_shapes(void) { canvas_draw("draw_shapes", draw_shapes); } + + +static void event_cb(lv_event_t * e) +{ + lv_layer_t * layer = lv_event_get_layer(e); + lv_obj_t * obj = lv_event_get_current_target_obj(e); + + lv_vector_dsc_t * dsc = lv_vector_dsc_create(layer); + lv_vector_path_t * path = lv_vector_path_create(LV_VECTOR_PATH_QUALITY_MEDIUM); + + lv_fpoint_t pts[] = {{10, 10}, {130, 130}, {10, 130}}; + lv_vector_path_move_to(path, &pts[0]); + lv_vector_path_line_to(path, &pts[1]); + lv_vector_path_line_to(path, &pts[2]); + lv_vector_path_close(path); + + lv_vector_dsc_translate(dsc, obj->coords.x1, obj->coords.y1); + lv_vector_dsc_set_fill_color(dsc, lv_color_make(0x00, 0x80, 0xff)); + lv_vector_dsc_add_path(dsc, path); + + lv_draw_vector(dsc); + lv_vector_path_delete(path); + lv_vector_dsc_delete(dsc); +} + +void test_draw_during_rendering(void) +{ + lv_obj_t * obj = lv_obj_create(lv_screen_active()); + lv_obj_center(obj); + lv_obj_add_event_cb(obj, event_cb, LV_EVENT_DRAW_MAIN, NULL); + + TEST_ASSERT_EQUAL_SCREENSHOT("draw/vector_draw_during_rendering.png"); +} + #endif