SDL: Add SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY

From 524964f9668b5a0edd484258f4831ff9e577e06e Mon Sep 17 00:00:00 2001
From: Ethan Lee <[EMAIL REDACTED]>
Date: Sat, 14 Aug 2021 12:09:13 -0400
Subject: [PATCH] Add SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY

---
 include/SDL_hints.h | 11 +++++++++++
 src/video/SDL_egl.c |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index c3ae80dbbe..c18c14f8db 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -1218,6 +1218,17 @@ extern "C" {
  */
 #define SDL_HINT_VIDEO_DOUBLE_BUFFER      "SDL_VIDEO_DOUBLE_BUFFER"
 
+/**
+ * \brief A variable controlling whether the EGL window is allowed to be
+ * composited as transparent, rather than opaque.
+ *
+ * Most window systems will always render windows opaque, even if the surface
+ * format has an alpha channel. This is not always true, however, so by default
+ * SDL will try to enforce opaque composition. To override this behavior, you
+ * can set this hint to "1".
+ */
+#define SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY "SDL_VIDEO_EGL_ALLOW_TRANSPARENCY"
+
 /**
  * \brief A variable controlling whether the graphics context is externally managed.
  *
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 41966db457..de7999cf63 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -1223,8 +1223,9 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
 
 #ifdef EGL_EXT_present_opaque
     if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_EXT_present_opaque")) {
+        const SDL_bool allow_transparent = SDL_GetHintBoolean(SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY, SDL_FALSE);
         attribs[attr++] = EGL_PRESENT_OPAQUE_EXT;
-        attribs[attr++] = EGL_TRUE;
+        attribs[attr++] = allow_transparent ? EGL_FALSE : EGL_TRUE;
     }
 #endif