Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdl_render): support all draw task types #6437

Merged
merged 16 commits into from
Aug 26, 2024

Conversation

kisvegabor
Copy link
Member

@kisvegabor kisvegabor commented Jun 27, 2024

Fixes #6410,

Description of the feature or fix

I'm working on adding support to all draw task types, but I'm facing a cache related issue. The current code crashes in lv_example_buttonmatrix_1() if this line is enabled:

==34516==ERROR: AddressSanitizer: heap-use-after-free on address 0x60600001e100 at pc 0x559d6a5c9864 bp 0x7ffeda3e96c0 sp 0x7ffeda3e96b0
READ of size 4 at 0x60600001e100 thread T0
    #0 0x559d6a5c9863 in lv_cache_entry_get_ref ../lvgl/src/misc/cache/lv_cache_entry.c:71
    #1 0x559d6a5c79f8 in get_victim_cb ../lvgl/src/misc/cache/_lv_cache_lru_rb.c:420
    #2 0x559d6a5c91df in cache_evict_one_internal_no_lock ../lvgl/src/misc/cache/lv_cache.c:319
    #3 0x559d6a5c9414 in cache_add_internal_no_lock ../lvgl/src/misc/cache/lv_cache.c:342
    #4 0x559d6a5c86ea in lv_cache_acquire_or_create ../lvgl/src/misc/cache/lv_cache.c:173
    #5 0x559d6a7dd55f in draw_from_cached_texture ../lvgl/src/draw/sdl/lv_draw_sdl.c:406
    #6 0x559d6a7de33e in execute_drawing ../lvgl/src/draw/sdl/lv_draw_sdl.c:479

I'd like to immediately drop the cache in some case. In this case with text_local = 1 the label_draw_dsc->text will be freed later, so we cannot keep a reference to it in the draw_dsc saved in the cache..

Other thing: In sdl_texture_cache_compare_cb I'd like to compare text of the label draw dsc-s with strcmp and not by pointer value. Can I simply return return strcmp_res > 0 ? 1 : -1;?

cc @W-Mai

Notes

@kisvegabor
Copy link
Member Author

@W-Mai will you have time to take a look at it in the near future?

@lhdjply
Copy link
Contributor

lhdjply commented Jul 15, 2024

After testing, it was found that the system freezes and images do not rotate. I have attempted to fix these two issues, please test again

From 876d0c6397e80ad1c3c38af33e9bc1db770ca91a Mon Sep 17 00:00:00 2001
From: lhdjply <lhdjply@126.com>
Date: Mon, 15 Jul 2024 16:24:08 +0800
Subject: [PATCH] fix freezing issues and add image rotation functionality.

Signed-off-by: lhdjply <lhdjply@126.com>
---
 demos/widgets/lv_demo_widgets.c |  4 ++--
 src/draw/sdl/lv_draw_sdl.c      | 10 ++++------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/demos/widgets/lv_demo_widgets.c b/demos/widgets/lv_demo_widgets.c
index eb0e880d6..be4ebf75f 100644
--- a/demos/widgets/lv_demo_widgets.c
+++ b/demos/widgets/lv_demo_widgets.c
@@ -252,8 +252,8 @@ static void profile_create(lv_obj_t * parent)
 
     LV_IMAGE_DECLARE(img_demo_widgets_avatar);
     lv_obj_t * avatar = lv_image_create(panel1);
-    //    lv_image_set_src(avatar, &img_demo_widgets_avatar);
-    lv_image_set_src(avatar, "A:lvgl/demos/widgets/assets/avatar.png");
+    lv_image_set_src(avatar, &img_demo_widgets_avatar);
+    //    lv_image_set_src(avatar, "A:lvgl/demos/widgets/assets/avatar.png")
 
     lv_obj_t * name = lv_label_create(panel1);
     lv_label_set_text(name, "Elena Smith");
diff --git a/src/draw/sdl/lv_draw_sdl.c b/src/draw/sdl/lv_draw_sdl.c
index 511dd064c..d685ff31f 100644
--- a/src/draw/sdl/lv_draw_sdl.c
+++ b/src/draw/sdl/lv_draw_sdl.c
@@ -345,8 +345,8 @@ static bool draw_to_texture(lv_draw_sdl_unit_t * u, cache_data_t * cache_data)
 
     cache_data->draw_dsc = lv_malloc(base_dsc->dsc_size);
     lv_memcpy((void *)cache_data->draw_dsc, base_dsc, base_dsc->dsc_size);
-    cache_data->w = texture_w;
-    cache_data->h = texture_h;
+    cache_data->w = lv_area_get_width(&task->area);
+    cache_data->h = lv_area_get_height(&task->area);
     cache_data->texture = texture;
 
     if(obj) {
@@ -441,7 +441,8 @@ static void draw_from_cached_texture(lv_draw_sdl_unit_t * u)
         rect.h = lv_area_get_height(&image_area);
 
         SDL_RenderSetClipRect(renderer, &clip_rect);
-        SDL_RenderCopy(renderer, texture, NULL, &rect);
+        SDL_Point center = {draw_dsc->pivot.x, draw_dsc->pivot.y};
+        SDL_RenderCopyEx(renderer, texture, NULL, &rect, draw_dsc->rotation / 10, &center, SDL_FLIP_NONE);
     }
     else {
         rect.x = t->_real_area.x1 - dest_layer->buf_area.x1;
@@ -460,12 +461,9 @@ static void draw_from_cached_texture(lv_draw_sdl_unit_t * u)
         lv_draw_label_dsc_t * label_dsc = t->draw_dsc;
         if(label_dsc->text_local) {
             //          lv_cache_entry_set_invalid(entry_cached, true);
-            printf("a\n");
         }
     }
-    printf("b\n");
     lv_cache_release(u->texture_cache, entry_cached, u);
-    printf("c\n");
 }
 
 static void execute_drawing(lv_draw_sdl_unit_t * u)
-- 
2.43.0

if(t->type == LV_DRAW_TASK_TYPE_LABEL) {
lv_draw_label_dsc_t * label_dsc = t->draw_dsc;
if(label_dsc->text_local) {
// lv_cache_entry_set_invalid(entry_cached, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this API is private, don't use

@kisvegabor
Copy link
Member Author

I resolved the caching issue by using lv_cache_drop.

I've also added support for image rotation. It's done by LVGL not SDL to make sure that all SW render features are supported.

@lhdjply
Copy link
Contributor

lhdjply commented Jul 18, 2024

I resolved the caching issue by using lv_cache_drop.

I've also added support for image rotation. It's done by LVGL not SDL to make sure that all SW render features are supported.

Nice!

Currently, two issues have been identified:

  • The application also crashes when the window is resized or when the maximize button is clicked.

  • The lv_demo_transform example does not allow for scaling.

@kisvegabor
Copy link
Member Author

Thanks, I've fixed both.

@lhdjply
Copy link
Contributor

lhdjply commented Jul 30, 2024

Test passed. Please rebase onto the master branch to resolve conflicts.

@sliang951753
Copy link

hello,
I have two questions regarding the SDL support for LVGL.

  1. I 'm wondering why using SDL_RENDERER_SOFTWARE flag in SDL_CreateRenderer() function ? As my test, I found when changing it to SDL_RENDERER_ACCELERATED, the FPS will be more stable than using SDL_RENDERER_SOFTWARE (Not enable SDL DRAW ).
  2. After trying to use the latest fix feat(sdl_render): support all draw task types #6437, I found the performance was worse than software rendering. Especially the score of "Container with opa_layer" was super low. It looks the drawing operation spent more time than using pure software rendering and the flush operation is very fast with SDL draw.
    image

@kisvegabor
Copy link
Member Author

I'll test the performance issue tomorrow.

@kisvegabor kisvegabor force-pushed the feat/sdl-draw-complete branch from 25811db to f16fa63 Compare August 14, 2024 14:00
@kisvegabor
Copy link
Member Author

I've significantly improved the perfornace. opa_layered still could be faster, but I think it's okay for the first round.

@@ -9,13 +9,13 @@
#include "../lv_draw_private.h"
#if LV_USE_DRAW_SDL
#include LV_SDL_INCLUDE_PATH
#include <SDL2/SDL_image.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm it's remove as intended.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. It was one of the goals to get rid of SDL_image.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. It was one of the goals to get rid of SDL_image.

Can it be removed from lv_dsl_window.c, tests/CMakeLists.txt, and scripts/install-prerequisites.sh too?

@@ -998,11 +997,11 @@ void shop_create(lv_obj_t * parent)
lv_obj_add_style(title, &style_title, 0);

LV_IMAGE_DECLARE(img_clothes);
create_shop_item(list, &img_clothes, "Blue jeans", "Clothes", "$722");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert unnecessary changes.


// lv_obj_t * img2 = lv_image_create(lv_screen_active());
// lv_image_set_src(img2, LV_SYMBOL_OK "Accept");
// lv_obj_align_to(img2, img1, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's cleanup a bit.

{
static int32_t x = 0;
printf("%d\n", x++);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

break;
}
default:
return false;
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

@kisvegabor
Copy link
Member Author

Updated, please review again.

Copy link
Collaborator

@liamHowatt liamHowatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the Kconfig.

@@ -9,13 +9,13 @@
#include "../lv_draw_private.h"
#if LV_USE_DRAW_SDL
#include LV_SDL_INCLUDE_PATH
#include <SDL2/SDL_image.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. It was one of the goals to get rid of SDL_image.

Can it be removed from lv_dsl_window.c, tests/CMakeLists.txt, and scripts/install-prerequisites.sh too?

src/draw/sdl/lv_draw_sdl.c Show resolved Hide resolved
src/draw/sdl/lv_draw_sdl.c Outdated Show resolved Hide resolved
src/draw/sdl/lv_draw_sdl.c Outdated Show resolved Hide resolved
src/draw/sdl/lv_draw_sdl.c Show resolved Hide resolved
@kisvegabor
Copy link
Member Author

Thank you Liam, all fixed.

Copy link
Collaborator

@liamHowatt liamHowatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kisvegabor
Copy link
Member Author

Fixed

@kisvegabor kisvegabor requested a review from XuNeo August 23, 2024 22:34
@kisvegabor
Copy link
Member Author

Force merging now for v9.2. There shouldn't be major issues.

@kisvegabor kisvegabor merged commit 51f06c0 into lvgl:master Aug 26, 2024
20 checks passed
@kisvegabor kisvegabor deleted the feat/sdl-draw-complete branch August 26, 2024 08:46
@Kirbyrawr
Copy link

I noticed heavy performance degradation in basic screens from 9.1 to 9.2.
In 9.1 i was getting 30 fps using SDL in Windows and Linux.
In 9.2 i'm getting 6 fps without changing any part of the code.

Let me know if you need more details but i wanted to put it here just in case is related.

@kisvegabor
Copy link
Member Author

Wow, that's not ideal for sure. Can you run perf on Linux to see what takes so long?

Could you try LV_SDL_ACCELERATED 0 or 1 and make sure that LV_COLOR_DEPTH is 32.

rodb70 pushed a commit to rodb70/lvgl that referenced this pull request Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Draw arc not working if LV_DRAW_SDL is enabled.
7 participants