Skip to content

Commit

Permalink
chore: Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed May 25, 2024
2 parents 0ddee11 + c68d98f commit 006464e
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 168 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- **Breaking:** updated `raw-window-handle` dependency to `0.6`.
- Bump MSRV from `1.65` to `1.70`.

# Version 0.31.3
Expand Down
6 changes: 3 additions & 3 deletions glutin-winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,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.30.0", default-features = false, features = ["rwh_05"] }
raw-window-handle = "0.6"
winit = { version = "0.30.0", default-features = false, features = ["rwh_06"] }

[build-dependencies]
cfg_aliases = "0.1.1"
cfg_aliases = "0.2.1"
15 changes: 0 additions & 15 deletions glutin-winit/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,4 @@ fn main() {
wgl_backend: { all(feature = "wgl", windows, not(wasm_platform)) },
cgl_backend: { all(macos_platform, not(wasm_platform)) },
}

println!("cargo:rustc-check-cfg=cfg(android_platform)");
println!("cargo:rustc-check-cfg=cfg(wasm_platform)");
println!("cargo:rustc-check-cfg=cfg(macos_platform)");
println!("cargo:rustc-check-cfg=cfg(ios_platform)");
println!("cargo:rustc-check-cfg=cfg(apple)");
println!("cargo:rustc-check-cfg=cfg(free_unix)");

println!("cargo:rustc-check-cfg=cfg(x11_platform)");
println!("cargo:rustc-check-cfg=cfg(wayland_platform)");

println!("cargo:rustc-check-cfg=cfg(egl_backend)");
println!("cargo:rustc-check-cfg=cfg(glx_backend)");
println!("cargo:rustc-check-cfg=cfg(wgl_backend)");
println!("cargo:rustc-check-cfg=cfg(cgl_backend)");
}
12 changes: 6 additions & 6 deletions glutin-winit/src/event_loop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle};
use raw_window_handle::{DisplayHandle, HandleError, HasDisplayHandle};
use winit::error::OsError;
use winit::event_loop::{ActiveEventLoop, EventLoop};
use winit::window::{Window, WindowAttributes};
Expand All @@ -10,7 +10,7 @@ use crate::private::Sealed;
pub trait GlutinEventLoop: Sealed {
fn create_window(&self, window_attributes: WindowAttributes) -> Result<Window, OsError>;

fn display_handle(&self) -> RawDisplayHandle;
fn glutin_display_handle(&self) -> Result<DisplayHandle<'_>, HandleError>;
}

impl Sealed for ActiveEventLoop {}
Expand All @@ -20,8 +20,8 @@ impl GlutinEventLoop for ActiveEventLoop {
self.create_window(window_attributes)
}

fn display_handle(&self) -> RawDisplayHandle {
self.raw_display_handle()
fn glutin_display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
self.display_handle()
}
}

Expand All @@ -33,7 +33,7 @@ impl<T> GlutinEventLoop for EventLoop<T> {
self.create_window(window_attributes)
}

fn display_handle(&self) -> RawDisplayHandle {
self.raw_display_handle()
fn glutin_display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
self.display_handle()
}
}
10 changes: 7 additions & 3 deletions glutin-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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::RawWindowHandle;
use winit::error::OsError;
Expand Down Expand Up @@ -112,7 +112,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 @@ -178,7 +181,8 @@ fn create_display(
ApiPreference::FallbackEgl => DisplayApiPreference::WglThenEgl(_raw_window_handle),
};

unsafe { Ok(Display::new(event_loop.display_handle(), _preference)?) }
let handle = event_loop.glutin_display_handle()?.as_raw();
unsafe { Ok(Display::new(handle, _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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -73,7 +73,7 @@ features = [
]

[build-dependencies]
cfg_aliases = "0.1.1"
cfg_aliases = "0.2.1"

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
Expand Down
15 changes: 0 additions & 15 deletions glutin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,4 @@ fn main() {
wgl_backend: { all(feature = "wgl", windows, not(wasm_platform)) },
cgl_backend: { all(macos_platform, not(wasm_platform)) },
}

println!("cargo:rustc-check-cfg=cfg(android_platform)");
println!("cargo:rustc-check-cfg=cfg(wasm_platform)");
println!("cargo:rustc-check-cfg=cfg(macos_platform)");
println!("cargo:rustc-check-cfg=cfg(ios_platform)");
println!("cargo:rustc-check-cfg=cfg(apple)");
println!("cargo:rustc-check-cfg=cfg(free_unix)");

println!("cargo:rustc-check-cfg=cfg(x11_platform)");
println!("cargo:rustc-check-cfg=cfg(wayland_platform)");

println!("cargo:rustc-check-cfg=cfg(egl_backend)");
println!("cargo:rustc-check-cfg=cfg(glx_backend)");
println!("cargo:rustc-check-cfg=cfg(wgl_backend)");
println!("cargo:rustc-check-cfg=cfg(cgl_backend)");
}
36 changes: 16 additions & 20 deletions glutin/src/api/cgl/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::marker::PhantomData;
use std::num::NonZeroU32;

use objc2::rc::Id;
use objc2_app_kit::{NSView, NSWindow};
use objc2_app_kit::NSView;
use objc2_foundation::{run_on_main, MainThreadBound, MainThreadMarker};
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;
run_on_main(|mtm| {
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;
run_on_main(|mtm| {
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
Loading

0 comments on commit 006464e

Please sign in to comment.