wayland: Implement an EGL equivalent to VkCompositeAlphaFlagBitsKHR
Background: I've been working on Wayland support for SDL this year...
https://github.com/libsdl-org/SDL/tree/main/src/video/wayland
... and the results as of writing have been great! Most games work really well with today's drivers and desktop environments; I've been posting test cases here:
- https://twitter.com/flibitijibibo/status/1403895424872759296
- https://twitter.com/flibitijibibo/status/1404550971422908420
There are two issues we've run into with the existing catalog of games, however, and both seem to be rooted in EGL. This is issue 2 (see #4932 for issue 1):
As it turns out, most engines I've been testing with set ALPHA_SIZE
to 8, which has been fine up until now. I figured most games would clear to something opaque anyway, but it turns out a shocking percentage of games have transparency all over the place! Portal 2 in the first link above shows it really well. In hindsight we probably should have expected that a transparent backbuffer might actually be transparent some day, but as of today we've got a whole lot of games that are unintentionally translucent in Wayland.
However, Vulkan has VkCompositeAlphaFlagBitsKHR which is a wonderful fix for this problem - it lets games have an alpha channel in the backbuffer while ensuring the window is always opaque. As far as I can tell, EGL does not have such a feature - I tried goofing around with EGL_ALPHA_SIZE and EGL_BUFFER_SIZE to try and make an XRGB8888 surface, but didn't have any luck. Then I looked in the source for Vulkan WSI and EGL and found these bits:
- https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/vulkan/wsi/wsi_common_wayland.c#L223
- https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/egl/drivers/dri2/platform_wayland.c#L118-130
I could be completely misreading this but it seems like EGL Wayland already supports XRGB8888, but clients aren't able to request this format explicitly. With that in mind, I was thinking of adding a new attribute called EGL_COMPOSITE_ALPHA_WL
, where clients can choose to be either opaque or premultiplied and allow for easy access to XRGB8888 like we have with Vulkan. In SDL we would probably default to opaque for compatibility but add a hint called SDL_VIDEO_WAYLAND_COMPOSITE_ALPHA_TRANSPARENT
that allows for transparent windows with OpenGL.
This touches a lot of projects at once and proposes a whole new EGL extension, so I wanted to throw this out there to see if I'm on the right track before trying to draft anything serious. I feel like this should be possible already and that I'm just missing something obvious.