From: Akihiko Odaki <[email protected]> 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 <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> Message-ID: <[email protected]> (cherry picked from commit 6157908503f9a5a14d17a8ecf8cc3308107e1458) Signed-off-by: Michael Tokarev <[email protected]> diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h index acf993fcf5..c97a0d5c24 100644 --- a/include/ui/egl-helpers.h +++ b/include/ui/egl-helpers.h @@ -61,6 +61,11 @@ void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf); EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win); +#if defined(CONFIG_X11) || defined(CONFIG_GBM) || defined(WIN32) +EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native, + EGLenum platform); +#endif + #if defined(CONFIG_X11) || defined(CONFIG_GBM) int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode); diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index e3f2872cc1..069a524955 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -520,8 +520,8 @@ EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, EGLNativeWindowType win) * platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem * like mesa will be able to advertise these (even though it can do EGL 1.5). */ -static EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native, - EGLenum platform) +EGLDisplay qemu_egl_get_display(EGLNativeDisplayType native, + EGLenum platform) { EGLDisplay dpy = EGL_NO_DISPLAY; diff --git a/ui/sdl2.c b/ui/sdl2.c index 987ad334bb..9dd5e305e1 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -862,7 +862,8 @@ static void sdl2_set_hint_x11_force_egl(void) } /* Prefer EGL over GLX to get dma-buf support. */ - egl_display = eglGetDisplay((EGLNativeDisplayType)x_disp); + egl_display = qemu_egl_get_display((EGLNativeDisplayType)x_disp, + EGL_PLATFORM_X11_KHR); if (egl_display != EGL_NO_DISPLAY) { /* -- 2.47.3
