Skip to content

Commit

Permalink
Inlined the sanitization in the initialize_display function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilika authored and Kilika committed Sep 5, 2024
1 parent 85b8cfa commit 21d0172
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions glutin/src/api/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,29 +485,10 @@ impl Display {
Version::new(major as u8, minor as u8)
};

// Sanitize for libglvnd's aliasing.
// Sanitize the display provider, as the received EGL 1.4 display could have
// been marked incorrectly as `EglDisplay::Khr`.
#[cfg(free_unix)]
let display = Self::sanitize_egl_display_provider(display, version);

// Load extensions.
let display_extensions = get_extensions(egl, *display);
let features = Self::extract_display_features(&display_extensions, version);

let inner = Arc::new(DisplayInner {
egl,
raw: display,
_native_display: raw_display_handle.map(NativeDisplay),
version,
display_extensions,
features,
});
Ok(Self { inner })
}

#[cfg(free_unix)]
fn sanitize_egl_display_provider(display: EglDisplay, version: Version) -> EglDisplay {
let client_extensions = CLIENT_EXTENSIONS.get().unwrap();
match display {
let display = match display {
// Since according to libglvnd, `eglGetPlatformDisplay` and `GetPlatformDisplayEXT`
// aren't really differentiated under the hood, we must check if the version of the
// initialized display is not sensible for the EglDisplay type and downgrade it if so
Expand All @@ -516,6 +497,7 @@ impl Display {
// https://gitlab.freedesktop.org/glvnd/libglvnd/-/blob/606f6627cf481ee6dcb32387edc010c502cdf38b/include/glvnd/libeglabi.h#L231-232
// https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/251
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") {
EglDisplay::Ext(display)
} else {
Expand All @@ -524,7 +506,21 @@ impl 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);

let inner = Arc::new(DisplayInner {
egl,
raw: display,
_native_display: raw_display_handle.map(NativeDisplay),
version,
display_extensions,
features,
});
Ok(Self { inner })
}
}

Expand Down

0 comments on commit 21d0172

Please sign in to comment.