SDL: SDL3: opengles2 render not support window with transparent flag on Linux/X11 (#11167)

From 22566506d0679af649df01133af1b690458eb39d Mon Sep 17 00:00:00 2001
From: rhett-lee <[EMAIL REDACTED]>
Date: Sat, 12 Oct 2024 11:30:52 +0800
Subject: [PATCH] SDL3: opengles2 render not support window with transparent
 flag on Linux/X11 (#11167)

---
 src/video/x11/SDL_x11opengles.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c
index ebb455c37295e..caa2d0c4e4659 100644
--- a/src/video/x11/SDL_x11opengles.c
+++ b/src/video/x11/SDL_x11opengles.c
@@ -59,9 +59,9 @@ XVisualInfo *X11_GLES_GetVisual(SDL_VideoDevice *_this, Display *display, int sc
 {
 
     XVisualInfo *egl_visualinfo = NULL;
-    EGLint visual_id;
+    EGLint visual_id = 0;
     XVisualInfo vi_in;
-    int out_count;
+    int out_count = 0;
 
     if (!_this->egl_data) {
         // The EGL library wasn't loaded, SDL_GetError() should have info
@@ -71,8 +71,24 @@ XVisualInfo *X11_GLES_GetVisual(SDL_VideoDevice *_this, Display *display, int sc
     if (_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
                                             _this->egl_data->egl_config,
                                             EGL_NATIVE_VISUAL_ID,
-                                            &visual_id) == EGL_FALSE ||
-        !visual_id) {
+                                            &visual_id) == EGL_FALSE) {
+        visual_id = 0;
+    }
+    if (visual_id != 0) {
+        vi_in.screen = screen;
+        vi_in.visualid = visual_id;
+        egl_visualinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &vi_in, &out_count);
+        if (transparent && egl_visualinfo) {
+            Uint32 format = X11_GetPixelFormatFromVisualInfo(display, egl_visualinfo);
+            if (!SDL_ISPIXELFORMAT_ALPHA(format)) {
+                // not transparent!
+                X11_XFree(egl_visualinfo);
+                egl_visualinfo = NULL;
+            }
+        }
+    }
+    
+    if(!egl_visualinfo) {
         // Use the default visual when all else fails
         vi_in.screen = screen;
         egl_visualinfo = X11_XGetVisualInfo(display,
@@ -95,12 +111,7 @@ XVisualInfo *X11_GLES_GetVisual(SDL_VideoDevice *_this, Display *display, int sc
                 }
             }
         }
-    } else {
-        vi_in.screen = screen;
-        vi_in.visualid = visual_id;
-        egl_visualinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &vi_in, &out_count);
     }
-
     return egl_visualinfo;
 }