feat(sdl/egl): detect driver at runtime and explain x11 limitation (#9972)

This commit is contained in:
André Costa
2026-04-24 12:07:03 +02:00
committed by GitHub
parent 95a4dea683
commit fc1136e8d9
3 changed files with 31 additions and 10 deletions
+11
View File
@@ -126,6 +126,17 @@ The SDL driver can leverage OpenGL for hardware-accelerated rendering. LVGL prov
See the [Complete OpenGL overview](/integration/embedded_linux/opengl) for more information.
<Callout type="info" title="Driver Support">
OpenGL-based rendering is only supported on Linux when using `x11` as the SDL video driver.
When the EGL/OpenGL path is enabled, LVGL currently forces SDL to use the `x11`
video driver, overriding `SDL_VIDEODRIVER`. As a result, selecting drivers such as
`wayland` or `kmsdrm` via `SDL_VIDEODRIVER` will not take effect in this mode.
To use those SDL backends, do not enable the OpenGL/EGL rendering path; use the
regular SDL renderer instead.
</Callout>
## See Also
- [SDL Draw Unit](/integration/embedded_linux/draw_sdl) - SDL texture-based rendering
+19 -10
View File
@@ -79,7 +79,9 @@ static lv_result_t init_display(lv_display_t * display)
}
ddata->egl_ctx = lv_opengles_egl_context_create(&ifc);
if(!ddata->egl_ctx) {
LV_LOG_ERROR("Failed to initialize EGL context");
LV_LOG_ERROR("Failed to initialize EGL context.");
LV_LOG_ERROR("This probably means you're trying to use an unsupported SDL_VIDEO_DRIVER.");
LV_LOG_ERROR("Try setting SDL_VIDEODRIVER=x11 via an environment variable");
lv_free(ddata);
return LV_RESULT_INVALID;
}
@@ -161,19 +163,26 @@ static void * create_window_cb(void * driver_data, const lv_egl_native_window_pr
lv_display_t * display = (lv_display_t *)driver_data;
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
SDL_GetWindowWMInfo(lv_sdl_window_get_window(display), &wmInfo);
if(SDL_GetWindowWMInfo(lv_sdl_window_get_window(display), &wmInfo) != SDL_TRUE) {
LV_LOG_ERROR("SDL_GetWindowWMInfo failed: %s", SDL_GetError());
return NULL;
}
EGLNativeWindowType native_window;
#if defined(SDL_VIDEO_DRIVER_WINDOWS)
native_window = wmInfo.info.win.window;
#elif defined(SDL_VIDEO_DRIVER_X11)
native_window = wmInfo.info.x11.window;
#elif defined(SDL_VIDEO_DRIVER_WAYLAND)
native_window = wmInfo.info.wl.surface;
const char * driver = SDL_GetCurrentVideoDriver();
if(driver && strcmp(driver, "x11") == 0) {
#if defined(SDL_VIDEO_DRIVER_X11)
native_window = (EGLNativeWindowType)wmInfo.info.x11.window;
#else
LV_LOG_ERROR("Unsupported platform for EGL");
return NULL;
LV_LOG_ERROR("SDL built without X11 support");
return NULL;
#endif
}
else {
LV_LOG_ERROR("Unsupported SDL video driver: (%s)", driver ? driver : "(null)");
return NULL;
}
return (void *)native_window;
}
+1
View File
@@ -61,6 +61,7 @@ lv_display_t * lv_sdl_window_create(int32_t hor_res, int32_t ver_res)
{
if(!inited) {
#if LV_SDL_USE_EGL && defined(SDL_VIDEO_DRIVER_X11)
/* We only support x11 with EGL for now*/
SDL_SetHintWithPriority("SDL_VIDEODRIVER", "x11", SDL_HINT_OVERRIDE);
SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1");
#endif