Skip to content

Commit 716b294

Browse files
committed
Update wgpu to 0.14.0, winit to 0.27.4, raw-window-handle to 0.5.0
1 parent 1738527 commit 716b294

File tree

12 files changed

+115
-67
lines changed

12 files changed

+115
-67
lines changed

crates/bevy_asset/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ wasm-bindgen-futures = "0.4"
4040
js-sys = "0.3"
4141

4242
[target.'cfg(target_os = "android")'.dependencies]
43-
ndk-glue = { version = "0.5" }
43+
ndk-glue = { version = "0.7" }
4444

4545
[dev-dependencies]
4646
futures-lite = "1.4.0"

crates/bevy_internal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.9.0-dev" }
100100
[target.'cfg(target_os = "android")'.dependencies]
101101
# This version *must* be the same as the version used by winit,
102102
# or Android will break: https://github.com/rust-windowing/winit#android
103-
ndk-glue = {version = "0.5", features = ["logger"]}
103+
ndk-glue = {version = "0.7", features = ["logger"]}

crates/bevy_render/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bevy_utils = { path = "../bevy_utils", version = "0.9.0-dev" }
4949
image = { version = "0.24", default-features = false }
5050

5151
# misc
52-
wgpu = { version = "0.13.1", features = ["spirv"] }
52+
wgpu = { version = "0.14.0", features = ["spirv"] }
5353
codespan-reporting = "0.11.0"
5454
naga = { version = "0.9.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] }
5555
serde = { version = "1", features = ["derive"] }

crates/bevy_render/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl Plugin for RenderPlugin {
147147
let surface = {
148148
let windows = app.world.resource_mut::<bevy_window::Windows>();
149149
let raw_handle = windows.get_primary().map(|window| unsafe {
150-
let handle = window.raw_window_handle().get_handle();
150+
let handle = window.raw_handle().get_handle();
151151
instance.create_surface(&handle)
152152
});
153153
raw_handle

crates/bevy_render/src/view/window.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
use bevy_app::{App, Plugin};
88
use bevy_ecs::prelude::*;
99
use bevy_utils::{tracing::debug, HashMap, HashSet};
10-
use bevy_window::{PresentMode, RawWindowHandleWrapper, WindowClosed, WindowId, Windows};
10+
use bevy_window::{PresentMode, RawHandleWrapper, WindowClosed, WindowId, Windows};
1111
use std::ops::{Deref, DerefMut};
1212
use wgpu::TextureFormat;
1313

@@ -40,7 +40,7 @@ impl Plugin for WindowRenderPlugin {
4040

4141
pub struct ExtractedWindow {
4242
pub id: WindowId,
43-
pub handle: RawWindowHandleWrapper,
43+
pub handle: RawHandleWrapper,
4444
pub physical_width: u32,
4545
pub physical_height: u32,
4646
pub present_mode: PresentMode,
@@ -85,7 +85,7 @@ fn extract_windows(
8585
.entry(window.id())
8686
.or_insert(ExtractedWindow {
8787
id: window.id(),
88-
handle: window.raw_window_handle(),
88+
handle: window.raw_handle(),
8989
physical_width: new_width,
9090
physical_height: new_height,
9191
present_mode: window.present_mode(),
@@ -184,6 +184,7 @@ pub fn prepare_windows(
184184
PresentMode::AutoVsync => wgpu::PresentMode::AutoVsync,
185185
PresentMode::AutoNoVsync => wgpu::PresentMode::AutoNoVsync,
186186
},
187+
alpha_mode: wgpu::CompositeAlphaMode::Auto,
187188
};
188189

189190
// Do the initial surface configuration if it hasn't been configured yet. Or if size or

crates/bevy_window/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.9.0-dev" }
2121
bevy_utils = { path = "../bevy_utils", version = "0.9.0-dev" }
2222
# Used for close_on_esc
2323
bevy_input = { path = "../bevy_input", version = "0.9.0-dev" }
24-
raw-window-handle = "0.4.2"
24+
raw-window-handle = "0.5.0"
25+
winit = { git = "https://github.com/rust-windowing/winit", default-features = false }
2526

2627
# other
2728
serde = { version = "1.0", features = ["derive"], optional = true }
Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1-
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
1+
use raw_window_handle::{
2+
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
3+
};
24

35
/// A wrapper over [`RawWindowHandle`] that allows us to safely pass it across threads.
46
///
57
/// Depending on the platform, the underlying pointer-containing handle cannot be used on all threads,
68
/// and so we cannot simply make it (or any type that has a safe operation to get a [`RawWindowHandle`])
79
/// thread-safe.
810
#[derive(Debug, Clone)]
9-
pub struct RawWindowHandleWrapper(RawWindowHandle);
10-
11-
impl RawWindowHandleWrapper {
12-
pub(crate) fn new(handle: RawWindowHandle) -> Self {
13-
Self(handle)
14-
}
11+
pub struct RawHandleWrapper {
12+
pub window_handle: RawWindowHandle,
13+
pub display_handle: RawDisplayHandle,
14+
}
1515

16+
impl RawHandleWrapper {
1617
/// Returns a [`HasRawWindowHandle`] impl, which exposes [`RawWindowHandle`].
1718
///
1819
/// # Safety
1920
///
2021
/// Some platforms have constraints on where/how this handle can be used. For example, some platforms don't support doing window
2122
/// operations off of the main thread. The caller must ensure the [`RawWindowHandle`] is only used in valid contexts.
2223
pub unsafe fn get_handle(&self) -> ThreadLockedRawWindowHandleWrapper {
23-
ThreadLockedRawWindowHandleWrapper(self.0)
24+
ThreadLockedRawWindowHandleWrapper(self.clone())
25+
}
26+
27+
pub fn get_display_handle(&self) -> RawDisplayHandle {
28+
self.display_handle
29+
}
30+
31+
pub fn get_window_handle(&self) -> RawWindowHandle {
32+
self.window_handle
2433
}
2534
}
2635

@@ -29,17 +38,17 @@ impl RawWindowHandleWrapper {
2938
// support doing window operations off of the main thread).
3039
// A recommendation for this pattern (and more context) is available here:
3140
// https://github.com/rust-windowing/raw-window-handle/issues/59
32-
unsafe impl Send for RawWindowHandleWrapper {}
33-
unsafe impl Sync for RawWindowHandleWrapper {}
41+
unsafe impl Send for RawHandleWrapper {}
42+
unsafe impl Sync for RawHandleWrapper {}
3443

35-
/// A [`RawWindowHandleWrapper`] that cannot be sent across threads.
44+
/// A [`RawHandleWrapper`] that cannot be sent across threads.
3645
///
37-
/// This safely exposes a [`RawWindowHandle`], but care must be taken to ensure that the construction itself is correct.
46+
/// This safely exposes a [`RawHandle`], but care must be taken to ensure that the construction itself is correct.
3847
///
39-
/// This can only be constructed via the [`RawWindowHandleWrapper::get_handle()`] method;
48+
/// This can only be constructed via the [`RawHandleWrapper::get_handle()`] method;
4049
/// be sure to read the safety docs there about platform-specific limitations.
4150
/// In many cases, this should only be constructed on the main thread.
42-
pub struct ThreadLockedRawWindowHandleWrapper(RawWindowHandle);
51+
pub struct ThreadLockedRawWindowHandleWrapper(RawHandleWrapper);
4352

4453
// SAFETY: the caller has validated that this is a valid context to get RawWindowHandle
4554
// as otherwise an instance of this type could not have been constructed
@@ -49,6 +58,17 @@ pub struct ThreadLockedRawWindowHandleWrapper(RawWindowHandle);
4958
// and so exposing a safe method to get a `RawWindowHandle` directly would be UB.
5059
unsafe impl HasRawWindowHandle for ThreadLockedRawWindowHandleWrapper {
5160
fn raw_window_handle(&self) -> RawWindowHandle {
52-
self.0
61+
self.0.get_window_handle()
62+
}
63+
}
64+
// SAFETY: the caller has validated that this is a valid context to get RawDisplayHandle
65+
// as otherwise an instance of this type could not have been constructed
66+
// NOTE: we cannot simply impl HasRawDisplayHandle for RawWindowHandleWrapper,
67+
// as the `raw_display_handle` method is safe. We cannot guarantee that all calls
68+
// of this method are correct (as it may be off the main thread on an incompatible platform),
69+
// and so exposing a safe method to get a `RawDisplayHandle` directly would be UB.
70+
unsafe impl HasRawDisplayHandle for ThreadLockedRawWindowHandleWrapper {
71+
fn raw_display_handle(&self) -> RawDisplayHandle {
72+
self.0.get_display_handle()
5373
}
5474
}

crates/bevy_window/src/window.rs

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use bevy_ecs::system::Resource;
22
use bevy_math::{DVec2, IVec2, UVec2, Vec2};
33
use bevy_reflect::{FromReflect, Reflect};
44
use bevy_utils::{tracing::warn, Uuid};
5-
use raw_window_handle::RawWindowHandle;
65

76
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Reflect, FromReflect)]
87
#[reflect_value(PartialEq, Hash)]
@@ -76,7 +75,7 @@ impl WindowId {
7675
use crate::CursorIcon;
7776
use std::fmt;
7877

79-
use crate::raw_window_handle::RawWindowHandleWrapper;
78+
use crate::raw_window_handle::RawHandleWrapper;
8079

8180
impl fmt::Display for WindowId {
8281
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -204,9 +203,9 @@ pub struct Window {
204203
decorations: bool,
205204
cursor_icon: CursorIcon,
206205
cursor_visible: bool,
207-
cursor_locked: bool,
206+
cursor_grab_mode: CursorGrabMode,
208207
physical_cursor_position: Option<DVec2>,
209-
raw_window_handle: RawWindowHandleWrapper,
208+
raw_handle: RawHandleWrapper,
210209
focused: bool,
211210
mode: WindowMode,
212211
canvas: Option<String>,
@@ -253,8 +252,8 @@ pub enum WindowCommand {
253252
decorations: bool,
254253
},
255254
/// Set whether or not the cursor's position is locked.
256-
SetCursorLockMode {
257-
locked: bool,
255+
SetCursorGrabMode {
256+
grab_mode: CursorGrabMode,
258257
},
259258
/// Set the cursor's [`CursorIcon`].
260259
SetCursorIcon {
@@ -290,6 +289,18 @@ pub enum WindowCommand {
290289
Close,
291290
}
292291

292+
/// Defines if and how the cursor is grabbed.
293+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
294+
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
295+
pub enum CursorGrabMode {
296+
/// The cursor can freely leave the window
297+
None,
298+
/// The cursor is confined to the window area.
299+
Confined,
300+
/// The cursor is locked inside the window area to a certain position.
301+
Locked,
302+
}
303+
293304
/// Defines the way a window is displayed.
294305
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
295306
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
@@ -315,7 +326,7 @@ impl Window {
315326
physical_height: u32,
316327
scale_factor: f64,
317328
position: Option<IVec2>,
318-
raw_window_handle: RawWindowHandle,
329+
raw_handle: RawHandleWrapper,
319330
) -> Self {
320331
Window {
321332
id,
@@ -332,10 +343,10 @@ impl Window {
332343
resizable: window_descriptor.resizable,
333344
decorations: window_descriptor.decorations,
334345
cursor_visible: window_descriptor.cursor_visible,
335-
cursor_locked: window_descriptor.cursor_locked,
346+
cursor_grab_mode: window_descriptor.cursor_grab_mode,
336347
cursor_icon: CursorIcon::Default,
337348
physical_cursor_position: None,
338-
raw_window_handle: RawWindowHandleWrapper::new(raw_window_handle),
349+
raw_handle,
339350
focused: true,
340351
mode: window_descriptor.mode,
341352
canvas: window_descriptor.canvas.clone(),
@@ -592,28 +603,28 @@ impl Window {
592603
self.command_queue
593604
.push(WindowCommand::SetDecorations { decorations });
594605
}
595-
/// Get whether or not the cursor is locked.
606+
/// Get whether or how the cursor is grabed.
596607
///
597608
/// ## Platform-specific
598609
///
599-
/// - **`macOS`** doesn't support cursor lock, but most windowing plugins can emulate it. See [issue #4875](https://github.com/bevyengine/bevy/issues/4875#issuecomment-1153977546) for more information.
610+
/// - **`macOS`** doesn't support cursor grabed, but most windowing plugins can emulate it. See [issue #4875](https://github.com/bevyengine/bevy/issues/4875#issuecomment-1153977546) for more information.
600611
/// - **`iOS/Android`** don't have cursors.
601612
#[inline]
602-
pub fn cursor_locked(&self) -> bool {
603-
self.cursor_locked
613+
pub fn cursor_grab_mode(&self) -> CursorGrabMode {
614+
self.cursor_grab_mode
604615
}
605-
/// Set whether or not the cursor is locked.
616+
/// Set whether and how the cursor is grabed.
606617
///
607618
/// This doesn't hide the cursor. For that, use [`set_cursor_visibility`](Window::set_cursor_visibility)
608619
///
609620
/// ## Platform-specific
610621
///
611-
/// - **`macOS`** doesn't support cursor lock, but most windowing plugins can emulate it. See [issue #4875](https://github.com/bevyengine/bevy/issues/4875#issuecomment-1153977546) for more information.
622+
/// - **`macOS`** doesn't support cursor grabed, but most windowing plugins can emulate it. See [issue #4875](https://github.com/bevyengine/bevy/issues/4875#issuecomment-1153977546) for more information.
612623
/// - **`iOS/Android`** don't have cursors.
613-
pub fn set_cursor_lock_mode(&mut self, lock_mode: bool) {
614-
self.cursor_locked = lock_mode;
624+
pub fn set_cursor_grab_mode(&mut self, grab_mode: CursorGrabMode) {
625+
self.cursor_grab_mode = grab_mode;
615626
self.command_queue
616-
.push(WindowCommand::SetCursorLockMode { locked: lock_mode });
627+
.push(WindowCommand::SetCursorGrabMode { grab_mode });
617628
}
618629
/// Get whether or not the cursor is visible.
619630
///
@@ -720,8 +731,8 @@ impl Window {
720731
self.focused
721732
}
722733
/// Get the [`RawWindowHandleWrapper`] corresponding to this window
723-
pub fn raw_window_handle(&self) -> RawWindowHandleWrapper {
724-
self.raw_window_handle.clone()
734+
pub fn raw_handle(&self) -> RawHandleWrapper {
735+
self.raw_handle.clone()
725736
}
726737

727738
/// The "html canvas" element selector.
@@ -836,8 +847,8 @@ pub struct WindowDescriptor {
836847
pub decorations: bool,
837848
/// Sets whether the cursor is visible when the window has focus.
838849
pub cursor_visible: bool,
839-
/// Sets whether the window locks the cursor inside its borders when the window has focus.
840-
pub cursor_locked: bool,
850+
/// Sets whether and how the window grabs the cursor.
851+
pub cursor_grab_mode: CursorGrabMode,
841852
/// Sets the [`WindowMode`](crate::WindowMode).
842853
///
843854
/// The monitor to go fullscreen on can be selected with the `monitor` field.
@@ -882,7 +893,7 @@ impl Default for WindowDescriptor {
882893
present_mode: PresentMode::Fifo,
883894
resizable: true,
884895
decorations: true,
885-
cursor_locked: false,
896+
cursor_grab_mode: CursorGrabMode::None,
886897
cursor_visible: true,
887898
mode: WindowMode::Windowed,
888899
transparent: false,

crates/bevy_winit/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ bevy_window = { path = "../bevy_window", version = "0.9.0-dev" }
2222
bevy_utils = { path = "../bevy_utils", version = "0.9.0-dev" }
2323

2424
# other
25-
winit = { version = "0.26.0", default-features = false }
26-
approx = { version = "0.5.0", default-features = false }
27-
raw-window-handle = "0.4.2"
25+
winit = { version = "0.27.4", default-features = false }
26+
approx = { version = "0.5", default-features = false }
27+
raw-window-handle = "0.5"
2828

2929
[target.'cfg(target_arch = "wasm32")'.dependencies]
30-
winit = { version = "0.26.0", default-features = false }
3130
wasm-bindgen = { version = "0.2" }
3231
web-sys = "0.3"
3332
crossbeam-channel = "0.5"

crates/bevy_winit/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ fn change_window(
137137
let window = winit_windows.get_window(id).unwrap();
138138
window.set_cursor_icon(converters::convert_cursor_icon(icon));
139139
}
140-
bevy_window::WindowCommand::SetCursorLockMode { locked } => {
140+
bevy_window::WindowCommand::SetCursorGrabMode { grab_mode } => {
141141
let window = winit_windows.get_window(id).unwrap();
142142
window
143-
.set_cursor_grab(locked)
143+
.set_cursor_grab(winit_grab_mode(grab_mode))
144144
.unwrap_or_else(|e| error!("Unable to un/grab cursor: {}", e));
145145
}
146146
bevy_window::WindowCommand::SetCursorVisibility { visible } => {
@@ -727,3 +727,12 @@ fn handle_create_window_events(
727727
}
728728
}
729729
}
730+
731+
/// Map `bevy_window::CursorGrabMode` to `winit::window::CursorGrabMode`.
732+
fn winit_grab_mode(mode: bevy_window::CursorGrabMode) -> winit::window::CursorGrabMode {
733+
match mode {
734+
bevy_window::CursorGrabMode::None => winit::window::CursorGrabMode::None,
735+
bevy_window::CursorGrabMode::Confined => winit::window::CursorGrabMode::Confined,
736+
bevy_window::CursorGrabMode::Locked => winit::window::CursorGrabMode::Locked,
737+
}
738+
}

0 commit comments

Comments
 (0)