ui/sdl2: Explicitly specify EGL platform
Mesa's eglGetDisplay() chooses the native EGL platform from EGL_PLATFORM, limited autodetection, or the build-time default. If that selects Wayland while SDL is using the X11 video backend, Mesa can treat the X11 Display pointer as a wl_display and crash during eglInitialize(). Probe EGL with the X11 platform explicitly before enabling SDL_HINT_VIDEO_X11_FORCE_EGL. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3540 Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260611-sdl-v1-1-93d4a51684bb@rsg.ci.i.u-tokyo.ac.jp>
Akihiko Odaki committed
Jun 11, 2026 at 20:58 UTC
6157908503f9a5a14d17a8ecf8cc3308107e1458
3 files changed
+9
-3
include/ui/egl-helpers.h
+5
@@ -61,6 +61,11 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf);
61
62
EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win);
63
64
+#if defined(CONFIG_X11) || defined(CONFIG_GBM) || defined(WIN32)
65
+EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
66
+ EGLenum platform);
67
+#endif
68
+
69
#if defined(CONFIG_X11) || defined(CONFIG_GBM)
70
71
int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode);
ui/egl-helpers.c
+2
-2
@@ -520,8 +520,8 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win)
520
* platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem
521
* like mesa will be able to advertise these (even though it can do EGL 1.5).
522
*/
523
-static EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
524
- EGLenum platform)
523
+EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native,
524
+ EGLenum platform)
525
{
526
EGLDisplay dpy = EGL_NO_DISPLAY;
527
ui/sdl2.c
+2
-1
@@ -862,7 +862,8 @@ static void sdl2_set_hint_x11_force_egl(void)
862
}
863
864
/* Prefer EGL over GLX to get dma-buf support. */
865
- egl_display = eglGetDisplay((EGLNativeDisplayType)x_disp);
865
+ egl_display = qemu_egl_get_display((EGLNativeDisplayType)x_disp,
866
+ EGL_PLATFORM_X11_KHR);
867
868
if (egl_display != EGL_NO_DISPLAY) {
869
/*