From c0a875faffce8e5966028cb50532cf25a9a842bc Mon Sep 17 00:00:00 2001 From: Conn O'Griofa Date: Mon, 13 Apr 2020 14:48:38 -0400 Subject: [PATCH] SDL_EGL_ChooseConfig: don't fall through if no matching format exists On Raspberry Pi 3 via the VC4 driver in firmware KMS mode, none of the found configs match the desired format, causing the function to fall through without any config being selected. Fix by first iterating over the found configs, and if no match exists, don't exclude the non-matching configs. This should fix RPI3 and possibly other targets without breaking targets that have a matching native format (such as RPI4). --- src/video/SDL_egl.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index 1561bc9ca..cb19a287d 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -683,6 +683,7 @@ SDL_EGL_ChooseConfig(_THIS) EGLint found_configs = 0, value; /* 128 seems even nicer here */ EGLConfig configs[128]; + SDL_bool has_matching_format = SDL_FALSE; int i, j, best_bitdiff = -1, bitdiff; if (!_this->egl_data) { @@ -766,11 +767,24 @@ SDL_EGL_ChooseConfig(_THIS) return SDL_EGL_SetError("Couldn't find matching EGL config", "eglChooseConfig"); } + /* first ensure that a found config has a matching format, or the function will fall through. */ + for (i = 0; i < found_configs; i++ ) { + if (_this->egl_data->egl_required_visual_id) + { + EGLint format; + _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, + configs[i], + EGL_NATIVE_VISUAL_ID, &format); + if (_this->egl_data->egl_required_visual_id == format) + has_matching_format = SDL_TRUE; + } + } + /* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */ /* From those, we select the one that matches our requirements more closely via a makeshift algorithm */ for (i = 0; i < found_configs; i++ ) { - if (_this->egl_data->egl_required_visual_id) + if (has_matching_format && _this->egl_data->egl_required_visual_id) { EGLint format; _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,