Android: prevent error EGL_BAD_DISPLAY while getting egl version without display

There is an error "E libEGL  : validate_display:91 error 3008 (EGL_BAD_DISPLAY)"
that occurs when calling "eglQueryString(display, EGL_VERSION)", with EGL_NO_DISPLAY.

Khronos says "EGL_BAD_DISPLAY is generated if display is not an EGL display connection, unless display is EGL_NO_DISPLAY and name is EGL_EXTENSIONS."
but this was added in SDL with "EGL 1.5 allows querying for client version"
( 56363ebf61 )

In fact:
- it actually doesn't work on Android that has 1.5 egl client
- it works on desktop X11 (using SDL_VIDEO_X11_FORCE_EGL=1)

The commit moves the version call where it's used, eg inside the "if (platform) {"
and checks that "eglGetPlatformDisplay" has been correctly loaded.
This commit is contained in:
Sylvain 2021-04-20 13:46:25 +02:00
parent 03503423e9
commit 6be9c00970
No known key found for this signature in database
GPG Key ID: 5F87E02E5BC0939E
1 changed files with 15 additions and 13 deletions

View File

@ -484,26 +484,28 @@ SDL_EGL_GetVersion(_THIS) {
int
SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
{
int egl_version_major, egl_version_minor;
int library_load_retcode = SDL_EGL_LoadLibraryOnly(_this, egl_path);
if (library_load_retcode != 0) {
return library_load_retcode;
}
/* EGL 1.5 allows querying for client version with EGL_NO_DISPLAY */
SDL_EGL_GetVersion(_this);
egl_version_major = _this->egl_data->egl_version_major;
egl_version_minor = _this->egl_data->egl_version_minor;
if (egl_version_major == 1 && egl_version_minor == 5) {
LOAD_FUNC(eglGetPlatformDisplay);
}
_this->egl_data->egl_display = EGL_NO_DISPLAY;
#if !defined(__WINRT__)
if (platform) {
if (egl_version_major == 1 && egl_version_minor == 5) {
/* EGL 1.5 allows querying for client version with EGL_NO_DISPLAY
* --
* Khronos doc: "EGL_BAD_DISPLAY is generated if display is not an EGL display connection, unless display is EGL_NO_DISPLAY and name is EGL_EXTENSIONS."
* Therefore SDL_EGL_GetVersion() shouldn't work with uninitialized display.
* - it actually doesn't work on Android that has 1.5 egl client
* - it works on desktop X11 (using SDL_VIDEO_X11_FORCE_EGL=1) */
SDL_EGL_GetVersion(_this);
if (_this->egl_data->egl_version_major == 1 && _this->egl_data->egl_version_minor == 5) {
LOAD_FUNC(eglGetPlatformDisplay);
}
if (_this->egl_data->eglGetPlatformDisplay) {
_this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplay(platform, (void *)(size_t)native_display, NULL);
} else {
if (SDL_EGL_HasExtension(_this, SDL_EGL_CLIENT_EXTENSION, "EGL_EXT_platform_base")) {
@ -523,7 +525,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
*_this->gl_config.driver_path = '\0';
return SDL_SetError("Could not get EGL display");
}
if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
_this->gl_config.driver_loaded = 0;
*_this->gl_config.driver_path = '\0';