From e3f8d167cdebe2d4351ce2c6d72ed121059c7507 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 19 Jul 2024 12:04:32 +0200 Subject: [PATCH] fix(thorvg): support rendering in draw events (#6406) Co-authored-by: pengyiqiang --- demos/lv_demos.c | 6 ++- demos/vector_graphic/lv_demo_vector_graphic.c | 24 +++++++++++- demos/vector_graphic/lv_demo_vector_graphic.h | 13 ++++++- src/libs/thorvg/tvgSwRenderer.cpp | 6 +-- src/widgets/lottie/lv_lottie.c | 8 +--- .../draw/vector_draw_during_rendering.png | Bin 0 -> 3227 bytes .../draw/vector_draw_during_rendering.png | Bin 0 -> 3336 bytes tests/src/test_cases/draw/test_draw_vector.c | 36 ++++++++++++++++++ 8 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 tests/ref_imgs/draw/vector_draw_during_rendering.png create mode 100644 tests/ref_imgs_vg_lite/draw/vector_draw_during_rendering.png 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 0000000000000000000000000000000000000000..1ef7ba54df918ff2280810cc772fd8efba3c7173 GIT binary patch literal 3227 zcmeH~`BPI@6vyv-tf^Z%cGse=Mb72;qC4gC_UZV-jca{3zqicxX$C) zyYnLX3|nW5`Fp$-un8qkB>_4qq+bP_n5! zIbhpILt^okrK6NAx1ix>al64_fzbZ4FjIsqXUhp>Hcy4nFDxDs6*4$tn^OpF$GOPH zSB#{wcR?OI_=V+e+YIgP`2ov{*6W2~53uKUDy41DP+k6&t&1$OJX%Ae)f9Q+?#_|F zUzi*>qx`da<7LiPW%{3F!H)IUuNV83r{COO-x1$H?8;zLL#zZF=k%57uDnvqeAq+A z{EmIWJ_C_uepWeuNjWs1O;+3*xD?#ktjmC$0n5j0#aLX^2B`Igs zD1yc7|4KpR+N$W7T_nwx6Nj?2xYR{X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elu-7VD|>U{IL?4OfWO}y#uchCSI zK5UD{vd3@U)@pjm^Mj+J0GDTTZV1{e{(M0}K|)t{XhzO%t9+F1zSYhn_)aWp;Jw#9 zN)qlE3}rQ`IWboGFdf@pUR70U7GUvkLQTVCW8Ti^V638|sjb@4ynbqWx<2*Nx~&JN z&E}R?hhZp~`^kmJ?{eKBqJ;r7wJwf%V=&*vU?H$OsU8}w@5rM!He zS82kg;vc8(>cX}pX&xM!uT5FD9@$<#!s(Lno>-GJFZ({(ACde*!M8@E@t;8#1-0hU zwl{e^57k=*->OZ?_oXuZ;;d|W%3D5PR#jQ#a;Y)%X~$Ccq%QBe^;wE6f31Jt&DPfR z96Nn#Y=2Tx(ocsQp-3a8&+}|Qba>0<-|XLGyKm41Qv(sg9c@~j?nvX$gM))TJt~(^ zYRXd7J-RcIl*PpMXpQ-|}mDkhC19IgJ{a3#cOWy4N)!U6+ T-*^N5a8UFvL8Nx4@bv!yM#?Kg literal 0 HcmV?d00001 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