zephyr: SDL display driver doesn't support API calls from a thread other than main
Describe the bug
Trying to call display functions (ex display_write) from a thread other than main does not seem to work.
To Reproduce Steps to reproduce the behavior:
- change
samples/drivers/display/src/main.cso that the contents of main() is effectively executed in a different thread - build and run on native_sim --> screen is black
Expected behavior
SDL driver should work in a multithreaded environment, just like other display drivers.
Impact
can’t run custom GUI code that requires a dedicated thread using native sim
Environment (please complete the following information):
Linux x86_64, 3.6.99 f419ea7990998ee13476d5c206a6bdb83a4a0567
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 22 (18 by maintainers)
Commits related to this issue
- Workaround for Linux build getting black screen on some computers. See issue for more details https://github.com/zephyrproject-rtos/zephyr/issues/71410 Workaround is to run lv_task_handler from main ... — committed to ZSWatch/ZSWatch by jakkra 2 years ago
- Workaround for Linux build getting black screen on some computers. See issue for more details https://github.com/zephyrproject-rtos/zephyr/issues/71410 Workaround is to run lv_task_handler from main ... — committed to ZSWatch/ZSWatch by jakkra 2 years ago
- Workaround for Linux build getting black screen on some computers. See issue for more details https://github.com/zephyrproject-rtos/zephyr/issues/71410 Workaround is to run lv_task_handler from main ... — committed to ZSWatch/ZSWatch by jakkra 2 years ago
- Workaround for Linux build getting black screen on some computers. See issue for more details https://github.com/zephyrproject-rtos/zephyr/issues/71410 Workaround is to run lv_task_handler from main ... — committed to ldab/ZSWatch by jakkra 2 years ago
- Workaround for Linux build getting black screen on some computers. See issue for more details https://github.com/zephyrproject-rtos/zephyr/issues/71410 Workaround is to run lv_task_handler from main ... — committed to ldab/ZSWatch by jakkra 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to faxe1008/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to flextrack/zephyr by faxe1008 2 years ago
- drivers: display: sdl: Ensure draw is performed from init thread Add a thread to the SDL display driver to ensure that init and renderer calls are performed from the same thread. Fixes #71410. Sign... — committed to abrarnasirjaffari/zephyr by faxe1008 2 years ago
@aescolar Tweaking the display driver sample like the below is the minimal repro. After applying the change, sample still works fine on e.g. M5Stack Core 2 (ILI9342C display controller), but SDL/native_sim_64 gives a black screen.
SDL documentation is pretty clear on the fact that e.g.
SDL_RenderPresent()orSDL_PollEvent()should only be called from the thread that initialized the video system.I took some time yesterday and did some testing. An easy way to break rendering is to have an additional flush thread:
What I found is that rendering breaks the second writes are done from a different thread:
What I find strange is that currently even without the
-DCONFIG_LV_Z_FLUSH_THREADhandling of input events also happens from another thread https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/native/common/sdl/sdl_events.c#L13 But this seems to work?Anyways I feel like all operations need to be happening in one thread:
The input_sdl_touch binding should be ok since it only adds a callback within the
initeverything else pretty much happens when the callback is triggered.Don’t know what is the best solution for this - let the display driver have an own thread where
inithappens and a message queue for pending writes? Any ideas @Finomnis @aescolar@Finomnis just in case you feel like spending more time on the SDL driver 😃
@KimBP just to be clear: That (https://github.com/zephyrproject-rtos/zephyr/issues/71410#issuecomment-2051649697) was not a workaround, and I would very much discourage anybody from doing that. That comment was only meant to provide information about the possible cause of the issue.