Skip to content

Commit

Permalink
egl: remove cfg from code not needing them
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov committed Oct 3, 2024
1 parent 5a7783c commit aa2a4a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 47 deletions.
12 changes: 3 additions & 9 deletions glutin/src/api/egl/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,21 +327,15 @@ impl GlConfig for Config {
unsafe { self.raw_attribute(egl::CONFIG_CAVEAT as EGLint) != egl::SLOW_CONFIG as EGLint }
}

#[cfg(not(any(wayland_platform, x11_platform)))]
fn supports_transparency(&self) -> Option<bool> {
None
}

#[cfg(any(wayland_platform, x11_platform))]
fn supports_transparency(&self) -> Option<bool> {
use raw_window_handle::RawDisplayHandle;
match *self.inner.display.inner._native_display? {
#[cfg(x11_platform)]
RawDisplayHandle::Xlib(_) | RawDisplayHandle::Xcb(_) => {
raw_window_handle::RawDisplayHandle::Xlib(_)
| raw_window_handle::RawDisplayHandle::Xcb(_) => {
self.x11_visual().map(|visual| visual.supports_transparency())
},
#[cfg(wayland_platform)]
RawDisplayHandle::Wayland(_) => Some(self.alpha_size() != 0),
raw_window_handle::RawDisplayHandle::Wayland(_) => Some(self.alpha_size() != 0),
_ => None,
}
}
Expand Down
44 changes: 6 additions & 38 deletions glutin/src/api/egl/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,25 +444,13 @@ impl<T: SurfaceTypeTrait> Sealed for Surface<T> {}

#[derive(Debug)]
enum NativeWindow {
#[cfg(wayland_platform)]
#[allow(dead_code)]
Wayland(*mut ffi::c_void),

#[cfg(x11_platform)]
Xlib(std::os::raw::c_ulong),

#[cfg(x11_platform)]
Xcb(u32),

#[cfg(android_platform)]
Android(*mut ffi::c_void),

#[cfg(ohos_platform)]
Ohos(*mut ffi::c_void),

#[cfg(windows)]
Win32(isize),

#[cfg(free_unix)]
Gbm(*mut ffi::c_void),
}

Expand All @@ -487,27 +475,21 @@ impl NativeWindow {
}
Self::Wayland(ptr.cast())
},
#[cfg(x11_platform)]
RawWindowHandle::Xlib(window_handle) => {
if window_handle.window == 0 {
return Err(ErrorKind::BadNativeWindow.into());
}

Self::Xlib(window_handle.window as _)
},
#[cfg(x11_platform)]
RawWindowHandle::Xcb(window_handle) => Self::Xcb(window_handle.window.get() as _),
#[cfg(android_platform)]
RawWindowHandle::AndroidNdk(window_handle) => {
Self::Android(window_handle.a_native_window.as_ptr())
},
#[cfg(ohos_platform)]
RawWindowHandle::OhosNdk(window_handle) => {
Self::Ohos(window_handle.native_window.as_ptr())
},
#[cfg(windows)]
RawWindowHandle::Win32(window_handle) => Self::Win32(window_handle.hwnd.get() as _),
#[cfg(free_unix)]
RawWindowHandle::Gbm(window_handle) => Self::Gbm(window_handle.gbm_surface.as_ptr()),
_ => {
return Err(
Expand Down Expand Up @@ -539,20 +521,13 @@ impl NativeWindow {
/// Returns the underlying handle value.
fn as_native_window(&self) -> egl::NativeWindowType {
match *self {
#[cfg(wayland_platform)]
Self::Wayland(wl_egl_surface) => wl_egl_surface,
#[cfg(x11_platform)]
Self::Wayland(wl_egl_surface) => wl_egl_surface as egl::NativeWindowType,
Self::Xlib(window_id) => window_id as egl::NativeWindowType,
#[cfg(x11_platform)]
Self::Xcb(window_id) => window_id as egl::NativeWindowType,
#[cfg(windows)]
Self::Win32(hwnd) => hwnd,
#[cfg(android_platform)]
Self::Android(a_native_window) => a_native_window,
#[cfg(ohos_platform)]
Self::Ohos(native_window) => native_window,
#[cfg(free_unix)]
Self::Gbm(gbm_surface) => gbm_surface,
Self::Win32(hwnd) => hwnd as egl::NativeWindowType,
Self::Android(a_native_window) => a_native_window as egl::NativeWindowType,
Self::Ohos(native_window) => native_window as egl::NativeWindowType,
Self::Gbm(gbm_surface) => gbm_surface as egl::NativeWindowType,
}
}

Expand All @@ -572,19 +547,12 @@ impl NativeWindow {
/// On X11 the returned pointer is a cast of the `&self` borrow.
fn as_platform_window(&self) -> *mut ffi::c_void {
match self {
#[cfg(wayland_platform)]
Self::Wayland(wl_egl_surface) => *wl_egl_surface,
#[cfg(x11_platform)]
Self::Xlib(window_id) => window_id as *const _ as *mut ffi::c_void,
#[cfg(x11_platform)]
Self::Xcb(window_id) => window_id as *const _ as *mut ffi::c_void,
#[cfg(windows)]
Self::Win32(hwnd) => *hwnd as *const ffi::c_void as *mut _,
#[cfg(android_platform)]
Self::Android(a_native_window) => *a_native_window,
#[cfg(ohos_platform)]
Self::Ohos(native_window) => *native_window,
#[cfg(free_unix)]
Self::Gbm(gbm_surface) => *gbm_surface,
}
}
Expand Down

0 comments on commit aa2a4a5

Please sign in to comment.