Browse Source

EGL: Always pass the platform type when available

Always pass the EGL platform type for Wayland and X11, or the driver could potentially select the wrong backend if certain envvars are misconfigured.

(cherry picked from commit 34af24276f0c5777aa253fa5a73e6e3636922496)
Frank Praznik 3 days ago
parent
commit
b7b1f7843d

+ 3 - 3
src/video/kmsdrm/SDL_kmsdrmopengles.c

@@ -30,8 +30,8 @@
 
 #define VOID2U64(x) ((uint64_t)(size_t)(x))
 
-#ifndef EGL_PLATFORM_GBM_MESA
-#define EGL_PLATFORM_GBM_MESA 0x31D7
+#ifndef EGL_PLATFORM_GBM_KHR
+#define EGL_PLATFORM_GBM_KHR 0x31D7
 #endif
 
 #ifndef EGL_SYNC_NATIVE_FENCE_ANDROID
@@ -70,7 +70,7 @@ bool KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
        call order in SDL_CreateWindow(). */
 #if 0
     NativeDisplayType display = (NativeDisplayType)_this->internal->gbm_dev;
-    return SDL_EGL_LoadLibrary(_this, path, display, EGL_PLATFORM_GBM_MESA);
+    return SDL_EGL_LoadLibrary(_this, path, display, EGL_PLATFORM_GBM_KHR);
 #endif
     return true;
 }

+ 4 - 4
src/video/kmsdrm/SDL_kmsdrmvideo.c

@@ -74,8 +74,8 @@ static char kmsdrm_dri_cardpath[32];
 #define DRM_FORMAT_MOD_LINEAR fourcc_mod_code(NONE, 0)
 #endif
 
-#ifndef EGL_PLATFORM_GBM_MESA
-#define EGL_PLATFORM_GBM_MESA 0x31D7
+#ifndef EGL_PLATFORM_GBM_KHR
+#define EGL_PLATFORM_GBM_KHR 0x31D7
 #endif
 
 static int get_driindex(void)
@@ -2135,12 +2135,12 @@ bool KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert
            before we call KMSDRM_GBMInit(), causing all GLES programs to fail. */
         if (!_this->egl_data) {
             egl_display = (NativeDisplayType)_this->internal->gbm_dev;
-            if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA)) {
+            if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_KHR)) {
                 // Try again with OpenGL ES 2.0
                 _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
                 _this->gl_config.major_version = 2;
                 _this->gl_config.minor_version = 0;
-                if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA)) {
+                if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_KHR)) {
                     return SDL_SetError("Can't load EGL/GL library on window creation.");
                 }
             }

+ 7 - 0
src/video/wayland/SDL_waylandopengles.c

@@ -32,6 +32,10 @@
 
 #include "xdg-shell-client-protocol.h"
 
+#ifndef EGL_PLATFORM_WAYLAND_KHR
+#define EGL_PLATFORM_WAYLAND_KHR 0x31D8
+#endif
+
 // EGL implementation of SDL OpenGL ES support
 
 bool Wayland_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
@@ -39,6 +43,9 @@ bool Wayland_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
     bool result;
     SDL_VideoData *data = _this->internal;
 
+    if (!_this->gl_config.egl_platform) {
+        _this->gl_config.egl_platform = EGL_PLATFORM_WAYLAND_KHR;
+    }
     result = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)data->display, _this->gl_config.egl_platform);
 
     Wayland_PumpEvents(_this);

+ 7 - 0
src/video/x11/SDL_x11opengles.c

@@ -27,6 +27,10 @@
 #include "SDL_x11opengl.h"
 #include "SDL_x11xsync.h"
 
+#ifndef EGL_PLATFORM_X11_KHR
+#define EGL_PLATFORM_X11_KHR 0x31D5
+#endif
+
 // EGL implementation of SDL OpenGL support
 
 bool X11_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
@@ -53,6 +57,9 @@ bool X11_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
 #endif
     }
 
+    if (!_this->gl_config.egl_platform) {
+        _this->gl_config.egl_platform = EGL_PLATFORM_X11_KHR;
+    }
     return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)data->display, _this->gl_config.egl_platform);
 }