Commit 6a342954e8d00d461e55607a3d196e7d6f334298

Sam Lantinga 2021-01-14T14:42:53

Fixed bug 5451 - Can't create EGLSurface in Wayland from SDLWindow (no EGLNativeWindow pointer) sashikknox In some cases, need create EGLWindow with SDLWindow. In X11 i can get pointer to NativeWindow from **struct SDL_SysWMinfo wmInfo** ```C++ struct SDL_SysWMinfo wmInfo; SDL_GetWindowWMInfo(ptSDLWindow, &wmInfo) #if defined(__unix__) && defined(SDL_VIDEO_DRIVER_X11) nativeWindow=(EGLNativeWindowType)wmInfo.info.x11.window; nativeDisplay=(EGLNativeDisplayType)wmInfo.info.x11.display; #endif ``` than i can create EGLSurface ``` eglCreateWindowSurface(nativeDisplay, EGL_CONFIG, nativeWindow, SURFACE_ATTRIBUTES); ``` in Wayland i can do it with same way, just need pointer to **EGLWindow**, we already have pointer to **wl_display** from **SDL_sysWMInfo**, need add to **wl** struct in SDL_SysWMInfo another pointer to **struct wl_egl_window *egl_window;**. And in wayland backend, in function **Wayland_GetWindowWMInfo** return pointer to **egl_window** from **SDL_WindowData** Now i use patched statically built SDL2 in port of Quake 2 GLES2 for SailfishOS (it use QtWayland): link to SDL2 commit and changed string for patch: - https://github.com/savegame/lp-public/commit/6858a618cd179b766fe3cab36055f07cb03ad0ea - https://github.com/savegame/lp-public/blob/b1e29e87b9d15780e47f04918b329ac15554fc69/SDL2/src/video/wayland/SDL_waylandwindow.c#L463 link to use in Quake2 port: 1. here i get pointer to EGLNativeWindowType: https://github.com/savegame/lp-public/blob/6d94fedb1b720da24999ae6286a1809cd3d55ff5/Engine/Sources/Compatibility/OpenGLES/EGLWrapper.c#L319 2. then use it for create EGLSurface: https://github.com/savegame/lp-public/blob/6d94fedb1b720da24999ae6286a1809cd3d55ff5/Engine/Sources/Compatibility/OpenGLES/EGLWrapper.c#L391

diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h
index 6dae377..ee3705d 100644
--- a/include/SDL_syswm.h
+++ b/include/SDL_syswm.h
@@ -274,9 +274,10 @@ struct SDL_SysWMinfo
 #if defined(SDL_VIDEO_DRIVER_WAYLAND)
         struct
         {
-            struct wl_display *display;            /**< Wayland display */
-            struct wl_surface *surface;            /**< Wayland surface */
+            struct wl_display *display;             /**< Wayland display */
+            struct wl_surface *surface;             /**< Wayland surface */
             struct wl_shell_surface *shell_surface; /**< Wayland shell_surface (window manager handle) */
+            struct wl_egl_window *egl_window;       /**< Wayland EGL window (native window) */
         } wl;
 #endif
 #if defined(SDL_VIDEO_DRIVER_MIR)  /* no longer available, left for API/ABI compatibility. Remove in 2.1! */
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index 0478958..f776f26 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -437,9 +437,9 @@ SDL_bool
 Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
-    const Uint32 version = ((((Uint32) info->version.major) * 1000000) +
-                            (((Uint32) info->version.minor) * 10000) +
-                            (((Uint32) info->version.patch)));
+    const Uint32 version = SDL_VERSIONNUM((Uint32)info->version.major,
+                                          (Uint32)info->version.minor,
+                                          (Uint32)info->version.patch);
 
     /* Before 2.0.6, it was possible to build an SDL with Wayland support
        (SDL_SysWMinfo will be large enough to hold Wayland info), but build
@@ -451,7 +451,7 @@ Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
        just return an error for older apps using this function. Those apps
        will need to be recompiled against newer headers or not use Wayland,
        maybe by forcing SDL_VIDEODRIVER=x11. */
-    if (version < 2000006) {
+    if (version < SDL_VERSIONNUM(2, 0, 6)) {
         info->subsystem = SDL_SYSWM_UNKNOWN;
         SDL_SetError("Version must be 2.0.6 or newer");
         return SDL_FALSE;
@@ -460,6 +460,9 @@ Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
     info->info.wl.display = data->waylandData->display;
     info->info.wl.surface = data->surface;
     info->info.wl.shell_surface = data->shell_surface.wl;
+    if (version >= SDL_VERSIONNUM(2, 0, 15)) {
+        info->info.wl.egl_window = data->egl_window;
+    }
     info->subsystem = SDL_SYSWM_WAYLAND;
 
     return SDL_TRUE;