Skip to content

Commit

Permalink
Update raw-window-handle to v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
declantsien committed Mar 19, 2024
1 parent e1bf1e2 commit 0fefa0b
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 99 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Unreleased
- **Breaking:** updated `raw-window-handle` dependency to `0.6`.

# Version 0.31.3

Expand Down
4 changes: 2 additions & 2 deletions glutin-winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ wayland = ["glutin/wayland", "winit/wayland"]

[dependencies]
glutin = { version = "0.31.0", path = "../glutin", default-features = false }
raw-window-handle = "0.5.2"
winit = { version = "0.29.2", default-features = false, features = ["rwh_05"] }
raw-window-handle = "0.6"
winit = { version = "0.29.2", default-features = false, features = ["rwh_06"] }

[build-dependencies]
cfg_aliases = "0.1.1"
12 changes: 8 additions & 4 deletions glutin-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use glutin::platform::x11::X11GlConfigExt;
use glutin::prelude::*;

#[cfg(wgl_backend)]
use raw_window_handle::HasRawWindowHandle;
use raw_window_handle::HasWindowHandle;

use raw_window_handle::{HasRawDisplayHandle, RawWindowHandle};
use raw_window_handle::{HasDisplayHandle, RawWindowHandle};
use winit::error::OsError;
use winit::event_loop::EventLoopWindowTarget;
use winit::window::{Window, WindowBuilder};
Expand Down Expand Up @@ -104,7 +104,10 @@ impl DisplayBuilder {
};

#[cfg(wgl_backend)]
let raw_window_handle = window.as_ref().map(|window| window.raw_window_handle());
let raw_window_handle = window
.as_ref()
.and_then(|window| window.window_handle().ok())
.map(|handle| handle.as_raw());
#[cfg(not(wgl_backend))]
let raw_window_handle = None;

Expand Down Expand Up @@ -170,7 +173,8 @@ fn create_display<T>(
ApiPreference::FallbackEgl => DisplayApiPreference::WglThenEgl(_raw_window_handle),
};

unsafe { Ok(Display::new(window_target.raw_display_handle(), _preference)?) }
let handle = window_target.display_handle()?;
unsafe { Ok(Display::new(handle.as_raw(), _preference)?) }
}

/// Finalize [`Window`] creation by applying the options from the [`Config`], be
Expand Down
9 changes: 5 additions & 4 deletions glutin-winit/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use glutin::surface::{
GlSurface, ResizeableSurface, Surface, SurfaceAttributes, SurfaceAttributesBuilder,
SurfaceTypeTrait, WindowSurface,
};
use raw_window_handle::HasRawWindowHandle;
use raw_window_handle::{HandleError, HasWindowHandle};
use winit::window::Window;

/// [`Window`] extensions for working with [`glutin`] surfaces.
Expand All @@ -25,7 +25,7 @@ pub trait GlWindow {
fn build_surface_attributes(
&self,
builder: SurfaceAttributesBuilder<WindowSurface>,
) -> SurfaceAttributes<WindowSurface>;
) -> Result<SurfaceAttributes<WindowSurface>, HandleError>;

/// Resize the surface to the window inner size.
///
Expand All @@ -51,9 +51,10 @@ impl GlWindow for Window {
fn build_surface_attributes(
&self,
builder: SurfaceAttributesBuilder<WindowSurface>,
) -> SurfaceAttributes<WindowSurface> {
) -> Result<SurfaceAttributes<WindowSurface>, HandleError> {
let (w, h) = self.inner_size().non_zero().expect("invalid zero inner size");
builder.build(self.raw_window_handle(), w, h)
let handle = self.window_handle()?.as_raw();
Ok(builder.build(handle, w, h))
}

fn resize_surface(
Expand Down
2 changes: 1 addition & 1 deletion glutin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ wayland = ["wayland-sys", "egl"]
bitflags = "2.2.1"
libloading = { version = "0.8.0", optional = true }
once_cell = "1.13"
raw-window-handle = "0.5.2"
raw-window-handle = "0.6"

[target.'cfg(windows)'.dependencies]
glutin_egl_sys = { version = "0.6.0", path = "../glutin_egl_sys", optional = true }
Expand Down
36 changes: 16 additions & 20 deletions glutin/src/api/cgl/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt;
use std::marker::PhantomData;
use std::num::NonZeroU32;

use icrate::AppKit::{NSView, NSWindow};
use icrate::AppKit::NSView;
use icrate::Foundation::{MainThreadBound, MainThreadMarker};
use objc2::rc::Id;
use raw_window_handle::RawWindowHandle;
Expand Down Expand Up @@ -59,28 +59,19 @@ impl Display {

// SAFETY: Validity of the view and window is ensured by caller
// This function makes sure the window is non null.
let ns_view = if let Some(ns_view) = unsafe { Id::retain(native_window.ns_view.cast()) } {
let ns_view = if let Some(ns_view) =
unsafe { Id::retain(native_window.ns_view.as_ptr().cast()) }
{
ns_view
} else {
return Err(ErrorKind::NotSupported("ns_view of provided native window is nil").into());
};
let ns_view = MainThreadBound::new(ns_view, mtm);

let ns_window =
if let Some(ns_window) = unsafe { Id::retain(native_window.ns_window.cast()) } {
ns_window
} else {
return Err(
ErrorKind::NotSupported("ns_window of provided native window is nil").into()
);
};
let ns_window = MainThreadBound::new(ns_window, mtm);

let surface = Surface {
display: self.clone(),
config: config.clone(),
ns_view,
ns_window,
_nosync: PhantomData,
_ty: PhantomData,
};
Expand All @@ -93,7 +84,6 @@ pub struct Surface<T: SurfaceTypeTrait> {
display: Display,
config: Config,
pub(crate) ns_view: MainThreadBound<Id<NSView>>,
ns_window: MainThreadBound<Id<NSWindow>>,
_nosync: PhantomData<*const std::ffi::c_void>,
_ty: PhantomData<T>,
}
Expand All @@ -110,21 +100,27 @@ impl<T: SurfaceTypeTrait> GlSurface<T> for Surface<T> {
}

fn width(&self) -> Option<u32> {
let window = &self.ns_window;
let view = &self.ns_view;
MainThreadMarker::run_on_main(|mtm| unsafe {
let scale_factor = window.get(mtm).backingScaleFactor();
let frame = view.get(mtm).frame();
let view = view.get(mtm);
let scale_factor = match view.window() {
Some(window) => window.backingScaleFactor(),
None => 1.0,
};
let frame = view.frame();
Some((frame.size.width * scale_factor) as u32)
})
}

fn height(&self) -> Option<u32> {
let window = &self.ns_window;
let view = &self.ns_view;
MainThreadMarker::run_on_main(|mtm| unsafe {
let scale_factor = window.get(mtm).backingScaleFactor();
let frame = view.get(mtm).frame();
let view = view.get(mtm);
let scale_factor = match view.window() {
Some(window) => window.backingScaleFactor(),
None => 1.0,
};
let frame = view.frame();
Some((frame.size.height * scale_factor) as u32)
})
}
Expand Down
6 changes: 3 additions & 3 deletions glutin/src/api/egl/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ impl Display {
// XXX This can't be done by passing visual in the EGL attributes
// when calling `eglChooseConfig` since the visual is ignored.
match template.native_window {
Some(RawWindowHandle::Xcb(xcb)) if xcb.visual_id > 0 => {
xcb.visual_id as u32 == config.native_visual()
Some(RawWindowHandle::Xcb(xcb)) => {
xcb.visual_id.map_or(false, |id| id.get() == config.native_visual())
},
Some(RawWindowHandle::Xlib(xlib)) if xlib.visual_id > 0 => {
xlib.visual_id as u32 == config.native_visual()
Expand Down Expand Up @@ -386,7 +386,7 @@ impl X11GlConfigExt for Config {
match *self.inner.display.inner._native_display? {
raw_window_handle::RawDisplayHandle::Xlib(display_handle) => unsafe {
let xid = self.native_visual();
X11VisualInfo::from_xid(display_handle.display as *mut _, xid as _)
X11VisualInfo::from_xid(display_handle.display?.as_ptr() as *mut _, xid as _)
},
_ => None,
}
Expand Down
20 changes: 10 additions & 10 deletions glutin/src/api/egl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use glutin_egl_sys::egl::types::{EGLAttrib, EGLDisplay, EGLint};

use once_cell::sync::OnceCell;

use raw_window_handle::RawDisplayHandle;
use raw_window_handle::{RawDisplayHandle, XlibDisplayHandle};

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, aarch64-linux-android, ubuntu-latest, apk --)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, i686-pc-windows-msvc, windows-latest, --no-default-features, egl)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, i686-pc-windows-msvc, windows-latest, --no-default-features, egl)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, i686-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.69.0, aarch64-linux-android, ubuntu-latest, apk --)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, i686-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-unknown-linux-gnu, ubuntu-latest, --no-default-features, egl,wayland)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-unknown-linux-gnu, ubuntu-latest, --no-default-features, egl,wayland)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check failure on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-msvc, windows-latest, --no-default-features, egl)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-msvc, windows-latest, --no-default-features, egl)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check failure on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, x86_64-unknown-linux-gnu, ubuntu-latest, --no-default-features, egl,wayland)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, x86_64-unknown-linux-gnu, ubuntu-latest, --no-default-features, egl,wayland)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check failure on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, x86_64-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, x86_64-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, aarch64-linux-android, ubuntu-latest, apk --)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (nightly, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check failure on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (1.65.0, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, i686-pc-windows-msvc, windows-latest, --no-default-features, egl)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, i686-pc-windows-msvc, windows-latest, --no-default-features, egl)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, x86_64-unknown-linux-gnu, ubuntu-latest, --no-default-features, egl,wayland)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, x86_64-unknown-linux-gnu, ubuntu-latest, --no-default-features, egl,wayland)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, i686-pc-windows-gnu, windows-latest, -i686-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, i686-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, i686-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, x86_64-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, x86_64-pc-windows-msvc, windows-latest)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `XlibDisplayHandle`

Check warning on line 16 in glutin/src/api/egl/display.rs

View workflow job for this annotation

GitHub Actions / Tests (stable, x86_64-pc-windows-gnu, windows-latest, -x86_64-pc-windows-gnu)

unused import: `XlibDisplayHandle`

use crate::config::ConfigTemplate;
use crate::context::Version;
Expand Down Expand Up @@ -244,16 +244,16 @@ impl Display {
RawDisplayHandle::Wayland(handle)
if extensions.contains("EGL_KHR_platform_wayland") =>
{
(egl::PLATFORM_WAYLAND_KHR, handle.display)
(egl::PLATFORM_WAYLAND_KHR, handle.display.as_ptr())
},
#[cfg(x11_platform)]
RawDisplayHandle::Xlib(handle) if extensions.contains("EGL_KHR_platform_x11") => {
attrs.push(egl::PLATFORM_X11_SCREEN_KHR as EGLAttrib);
attrs.push(handle.screen as EGLAttrib);
(egl::PLATFORM_X11_KHR, handle.display)
(egl::PLATFORM_X11_KHR, handle.display.map_or(ptr::null_mut(), |d| d.as_ptr()))
},
RawDisplayHandle::Gbm(handle) if extensions.contains("EGL_KHR_platform_gbm") => {
(egl::PLATFORM_GBM_KHR, handle.gbm_device)
(egl::PLATFORM_GBM_KHR, handle.gbm_device.as_ptr())
},
RawDisplayHandle::Android(_) if extensions.contains("EGL_KHR_platform_android") => {
(egl::PLATFORM_ANDROID_KHR, egl::DEFAULT_DISPLAY as *mut _)
Expand Down Expand Up @@ -320,13 +320,13 @@ impl Display {
RawDisplayHandle::Wayland(handle)
if extensions.contains("EGL_EXT_platform_wayland") =>
{
(egl::PLATFORM_WAYLAND_EXT, handle.display)
(egl::PLATFORM_WAYLAND_EXT, handle.display.as_ptr())
},
#[cfg(x11_platform)]
RawDisplayHandle::Xlib(handle) if extensions.contains("EGL_EXT_platform_x11") => {
attrs.push(egl::PLATFORM_X11_SCREEN_EXT as EGLint);
attrs.push(handle.screen as EGLint);
(egl::PLATFORM_X11_EXT, handle.display)
(egl::PLATFORM_X11_EXT, handle.display.map_or(ptr::null_mut(), |d| d.as_ptr()))
},
#[cfg(x11_platform)]
RawDisplayHandle::Xcb(handle)
Expand All @@ -335,10 +335,10 @@ impl Display {
{
attrs.push(egl::PLATFORM_XCB_SCREEN_EXT as EGLint);
attrs.push(handle.screen as EGLint);
(egl::PLATFORM_XCB_EXT, handle.connection)
(egl::PLATFORM_XCB_EXT, handle.connection.map_or(ptr::null_mut(), |c| c.as_ptr()))
},
RawDisplayHandle::Gbm(handle) if extensions.contains("EGL_MESA_platform_gbm") => {
(egl::PLATFORM_GBM_MESA, handle.gbm_device)
(egl::PLATFORM_GBM_MESA, handle.gbm_device.as_ptr())
},
RawDisplayHandle::Windows(..) if extensions.contains("EGL_ANGLE_platform_angle") => {
// Only CreateWindowSurface appears to work with Angle.
Expand Down Expand Up @@ -405,9 +405,9 @@ impl Display {

fn get_display(egl: &Egl, display: RawDisplayHandle) -> Result<EglDisplay> {
let mut display = match display {
RawDisplayHandle::Gbm(handle) => handle.gbm_device,
RawDisplayHandle::Gbm(handle) => handle.gbm_device.as_ptr(),
#[cfg(x11_platform)]
RawDisplayHandle::Xlib(handle) => handle.display,
RawDisplayHandle::Xlib(XlibDisplayHandle { display: Some(d), .. }) => d.as_ptr(),
RawDisplayHandle::Android(_) => egl::DEFAULT_DISPLAY as *mut _,
_ => {
return Err(
Expand Down
36 changes: 5 additions & 31 deletions glutin/src/api/egl/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,10 @@ impl NativeWindow {
let native_window = match raw_window_handle {
#[cfg(wayland_platform)]
RawWindowHandle::Wayland(window_handle) => unsafe {
if window_handle.surface.is_null() {
return Err(ErrorKind::BadNativeWindow.into());
}

let ptr = ffi_dispatch!(
wayland_egl_handle(),
wl_egl_window_create,
window_handle.surface.cast(),
window_handle.surface.as_ptr().cast(),
_width.get() as _,
_height.get() as _
);
Expand All @@ -497,37 +493,15 @@ impl NativeWindow {
Self::Xlib(window_handle.window as _)
},
#[cfg(x11_platform)]
RawWindowHandle::Xcb(window_handle) => {
if window_handle.window == 0 {
return Err(ErrorKind::BadNativeWindow.into());
}

Self::Xcb(window_handle.window as _)
},
RawWindowHandle::Xcb(window_handle) => Self::Xcb(window_handle.window.get() as _),
#[cfg(android_platform)]
RawWindowHandle::AndroidNdk(window_handle) => {
if window_handle.a_native_window.is_null() {
return Err(ErrorKind::BadNativeWindow.into());
}

Self::Android(window_handle.a_native_window)
Self::Android(window_handle.a_native_window.as_ptr())
},
#[cfg(windows)]
RawWindowHandle::Win32(window_handle) => {
if window_handle.hwnd.is_null() {
return Err(ErrorKind::BadNativeWindow.into());
}

Self::Win32(window_handle.hwnd as _)
},
RawWindowHandle::Win32(window_handle) => Self::Win32(window_handle.hwnd.get() as _),
#[cfg(free_unix)]
RawWindowHandle::Gbm(window_handle) => {
if window_handle.gbm_surface.is_null() {
return Err(ErrorKind::BadNativeWindow.into());
}

Self::Gbm(window_handle.gbm_surface)
},
RawWindowHandle::Gbm(window_handle) => Self::Gbm(window_handle.gbm_surface.as_ptr()),
_ => {
return Err(
ErrorKind::NotSupported("provided native window is not supported").into()
Expand Down
9 changes: 3 additions & 6 deletions glutin/src/api/glx/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ impl Display {
) -> Result<Self> {
// Don't load GLX when unsupported platform was requested.
let (display, screen) = match display {
RawDisplayHandle::Xlib(handle) => {
if handle.display.is_null() {
return Err(ErrorKind::BadDisplay.into());
}

(GlxDisplay(handle.display as *mut _), handle.screen as i32)
RawDisplayHandle::Xlib(handle) => match handle.display {
Some(display) => (GlxDisplay(display.as_ptr() as *mut _), handle.screen as i32),
None => return Err(ErrorKind::BadDisplay.into()),
},
_ => {
return Err(
Expand Down
4 changes: 2 additions & 2 deletions glutin/src/api/wgl/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Display {
template: ConfigTemplate,
) -> Result<Box<dyn Iterator<Item = Config> + '_>> {
let hwnd = match template.native_window {
Some(RawWindowHandle::Win32(window_handle)) => window_handle.hwnd as _,
Some(RawWindowHandle::Win32(window_handle)) => window_handle.hwnd.get() as _,
_ => 0,
};
let hdc = unsafe { gdi::GetDC(hwnd) };
Expand Down Expand Up @@ -289,7 +289,7 @@ impl Config {
/// The `raw_window_handle` should point to a valid value.
pub unsafe fn apply_on_native_window(&self, raw_window_handle: &RawWindowHandle) -> Result<()> {
let hdc = match raw_window_handle {
RawWindowHandle::Win32(window) => unsafe { gdi::GetDC(window.hwnd as _) },
RawWindowHandle::Win32(window) => unsafe { gdi::GetDC(window.hwnd.get() as _) },
_ => return Err(ErrorKind::BadNativeWindow.into()),
};

Expand Down
2 changes: 1 addition & 1 deletion glutin/src/api/wgl/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Display {
let hdc = match context_attributes.raw_window_handle.as_ref() {
handle @ Some(RawWindowHandle::Win32(window)) => unsafe {
let _ = config.apply_on_native_window(handle.unwrap());
gdi::GetDC(window.hwnd as _)
gdi::GetDC(window.hwnd.get() as _)
},
_ => config.inner.hdc,
};
Expand Down
6 changes: 4 additions & 2 deletions glutin/src/api/wgl/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ impl Display {
let (wgl_extra, client_extensions) =
if let Some(RawWindowHandle::Win32(window)) = native_window {
unsafe {
let (wgl_extra, client_extensions) =
super::load_extra_functions(window.hinstance as _, window.hwnd as _)?;
let (wgl_extra, client_extensions) = super::load_extra_functions(
window.hinstance.map(|i| i.get()).unwrap_or(0) as _,
window.hwnd.get() as _,
)?;
(Some(wgl_extra), client_extensions)
}
} else {
Expand Down
6 changes: 1 addition & 5 deletions glutin/src/api/wgl/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ impl Display {
) -> Result<Surface<WindowSurface>> {
let hwnd = match surface_attributes.raw_window_handle.as_ref().unwrap() {
handle @ RawWindowHandle::Win32(window_handle) => {
if window_handle.hwnd.is_null() {
return Err(ErrorKind::BadNativeWindow.into());
}

let _ = unsafe { config.apply_on_native_window(handle) };
window_handle.hwnd as HWND
window_handle.hwnd.get() as HWND
},
_ => {
return Err(
Expand Down
Loading

0 comments on commit 0fefa0b

Please sign in to comment.