From dae89a5a9145853220385e0d5036319689afa13c Mon Sep 17 00:00:00 2001 From: jan Kilika <137905832+janKilika@users.noreply.github.com> Date: Tue, 10 Sep 2024 17:51:21 +0300 Subject: [PATCH] egl/display: ensure provider after version check EGL doesn't differentiate between objects created by different extensions, and the display version check could be done, after we've created it, so ensure what display we actually created and use its functions. --- CHANGELOG.md | 1 + glutin/src/api/egl/display.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b6fde86b8..fda224e295 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Fixed EGL's `Device::query_devices()` being too strict about required extensions - Fixed crash in `EglGetProcAddress` on Win32-x86 platform due to wrong calling convention - Fixed EGL's `Display::device()` always returning an error due to invalid pointer-argument passing inside +- Fixed EGL's `Display::new()` making an `EGLDisplay::Khr` when the EGL version for the display is 1.4 or lower. # Version 0.32.0 diff --git a/glutin/src/api/egl/display.rs b/glutin/src/api/egl/display.rs index 0e2ee62e38..e2295ac54b 100644 --- a/glutin/src/api/egl/display.rs +++ b/glutin/src/api/egl/display.rs @@ -492,6 +492,26 @@ impl Display { Version::new(major as u8, minor as u8) }; + let display = match display { + // `eglGetPlatformDisplay` and `GetPlatformDisplayEXT` aren't really differentiated, + // we must check if the version of the initialized display is not sensible for the + // EglDisplay type and downgrade it if so. + EglDisplay::Khr(display) if version <= Version { major: 1, minor: 4 } => { + let client_extensions = CLIENT_EXTENSIONS.get().unwrap(); + if client_extensions.contains("EGL_EXT_platform_base") + && (version == Version { major: 1, minor: 4 }) + { + // `EGL_EXT_platform_base` requires EGL 1.4 per specification; we cannot safely + // presume that an `Ext` display would be valid for older versions. + EglDisplay::Ext(display) + } else { + EglDisplay::Legacy(display) + } + }, + // We do not do anything otherwise. + display => display, + }; + // Load extensions. let display_extensions = get_extensions(egl, *display); let features = Self::extract_display_features(&display_extensions, version);