SDL: video/wayland: use EGL_EXT_present_opaque when available

From 5113fedfa0e8592048a66cf8f852a59441e8bc9c Mon Sep 17 00:00:00 2001
From: Eric Engestrom <[EMAIL REDACTED]>
Date: Mon, 2 Aug 2021 23:01:12 +0100
Subject: [PATCH] video/wayland: use EGL_EXT_present_opaque when available

---
 src/video/SDL_egl.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 87d693e8d8..41966db457 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -43,6 +43,11 @@
 #endif
 #endif /* EGL_KHR_create_context */
 
+#ifndef EGL_EXT_present_opaque
+#define EGL_EXT_present_opaque 1
+#define EGL_PRESENT_OPAQUE_EXT            0x31DF
+#endif /* EGL_EXT_present_opaque */
+
 #if SDL_VIDEO_DRIVER_RPI
 /* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
 #define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "libbrcmEGL.so" )
@@ -1182,8 +1187,8 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
     EGLint format_wanted;
     EGLint format_got;
 #endif
-    /* max 2 values plus terminator. */
-    EGLint attribs[3];
+    /* max 2 key+value pairs, plus terminator. */
+    EGLint attribs[5];
     int attr = 0;
 
     EGLSurface * surface;
@@ -1216,6 +1221,13 @@ SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
         }
     }
 
+#ifdef EGL_EXT_present_opaque
+    if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_EXT_present_opaque")) {
+        attribs[attr++] = EGL_PRESENT_OPAQUE_EXT;
+        attribs[attr++] = EGL_TRUE;
+    }
+#endif
+
     attribs[attr++] = EGL_NONE;
     
     surface = _this->egl_data->eglCreateWindowSurface(