mirror of
https://github.com/lvgl/lvgl.git
synced 2024-11-23 09:43:41 +08:00
fix(thorvg): support rendering in draw events (#6406)
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
parent
aa3320db53
commit
e3f8d167cd
@ -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
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
BIN
tests/ref_imgs/draw/vector_draw_during_rendering.png
Normal file
BIN
tests/ref_imgs/draw/vector_draw_during_rendering.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
BIN
tests/ref_imgs_vg_lite/draw/vector_draw_during_rendering.png
Normal file
BIN
tests/ref_imgs_vg_lite/draw/vector_draw_during_rendering.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user