We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5451

Summary: Cant create EGLSurface in Wayland from SDLWindow (no EGLNativeWindow pointer)
Product: SDL Reporter: sashikknox <sashikknox>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: enhancement    
Priority: P2 CC: sashikknox
Version: 2.0.12   
Hardware: All   
OS: Linux   
Attachments: egl wayland
patch

Description sashikknox 2021-01-08 15:28:48 UTC
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
Comment 1 Sam Lantinga 2021-01-08 18:12:57 UTC
Yes, this sounds fine.

Can you attach a tested patch that implements this, relative to the latest SDL code?

Thanks!
Comment 2 sashikknox 2021-01-08 18:51:12 UTC
Ok, i'll try do it as fast as i can )
Comment 3 sashikknox 2021-01-08 22:51:21 UTC
Created attachment 4644 [details]
egl wayland

patch for Wayland backend of SDL2
Comment 4 sashikknox 2021-01-08 22:53:21 UTC
Created attachment 4645 [details]
patch
Comment 5 sashikknox 2021-01-13 10:37:28 UTC
(In reply to Sam Lantinga from comment #1)
> Yes, this sounds fine.
> 
> Can you attach a tested patch that implements this, relative to the latest
> SDL code?
> 
> Thanks!

is my patch enough?
Comment 6 Sam Lantinga 2021-01-14 22:43:41 UTC
Pretty close. I added a version check and pushed it:
https://hg.libsdl.org/SDL/rev/72d90e6fd083

Thanks!