Skip to content

Commit e8f72ea

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 e8f72ea

File tree

16 files changed

+169
-123
lines changed

16 files changed

+169
-123
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ 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"
54-
naga = { version = "0.9.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] }
54+
naga = { version = "0.10.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] }
5555
serde = { version = "1", features = ["derive"] }
5656
bitflags = "1.2.1"
5757
smallvec = { version = "1.6", features = ["union", "const_generics"] }

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ 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"
2525

2626
# other
2727
serde = { version = "1.0", features = ["derive"], optional = true }

crates/bevy_window/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#[warn(missing_docs)]
22
mod cursor;
33
mod event;
4-
mod raw_window_handle;
4+
mod raw_handle;
55
mod system;
66
mod window;
77
mod windows;
88

9-
pub use crate::raw_window_handle::*;
9+
pub use crate::raw_handle::*;
1010
pub use cursor::*;
1111
pub use event::*;
1212
pub use system::*;

crates/bevy_window/src/raw_handle.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use raw_window_handle::{
2+
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
3+
};
4+
5+
/// A wrapper over [`RawWindowHandle`] and [`RawDisplayHandle`] that allows us to safely pass it across threads.
6+
///
7+
/// Depending on the platform, the underlying pointer-containing handle cannot be used on all threads,
8+
/// and so we cannot simply make it (or any type that has a safe operation to get a [`RawWindowHandle`] or [`RawDisplayHandle`])
9+
/// thread-safe.
10+
#[derive(Debug, Clone)]
11+
pub struct RawHandleWrapper {
12+
pub window_handle: RawWindowHandle,
13+
pub display_handle: RawDisplayHandle,
14+
}
15+
16+
impl RawHandleWrapper {
17+
/// Returns a [`HasRawWindowHandle`] + [`HasRawDisplayHandle`] impl, which exposes [`RawWindowHandle`] and [`RawDisplayHandle`].
18+
///
19+
/// # Safety
20+
///
21+
/// Some platforms have constraints on where/how this handle can be used. For example, some platforms don't support doing window
22+
/// operations off of the main thread. The caller must ensure the [`RawHandleWrapper`] is only used in valid contexts.
23+
pub unsafe fn get_handle(&self) -> ThreadLockedRawWindowHandleWrapper {
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
33+
}
34+
}
35+
36+
// SAFETY: [`RawHandleWrapper`] is just a normal "raw pointer", which doesn't impl Send/Sync. However the pointer is only
37+
// exposed via an unsafe method that forces the user to make a call for a given platform. (ex: some platforms don't
38+
// support doing window operations off of the main thread).
39+
// A recommendation for this pattern (and more context) is available here:
40+
// https://github.com/rust-windowing/raw-window-handle/issues/59
41+
unsafe impl Send for RawHandleWrapper {}
42+
unsafe impl Sync for RawHandleWrapper {}
43+
44+
/// A [`RawHandleWrapper`] that cannot be sent across threads.
45+
///
46+
/// This safely exposes [`RawWindowHandle`] and [`RawDisplayHandle`], but care must be taken to ensure that the construction itself is correct.
47+
///
48+
/// This can only be constructed via the [`RawHandleWrapper::get_handle()`] method;
49+
/// be sure to read the safety docs there about platform-specific limitations.
50+
/// In many cases, this should only be constructed on the main thread.
51+
pub struct ThreadLockedRawWindowHandleWrapper(RawHandleWrapper);
52+
53+
// SAFETY: the caller has validated that this is a valid context to get [`RawHandleWrapper`]
54+
// as otherwise an instance of this type could not have been constructed
55+
// NOTE: we cannot simply impl HasRawWindowHandle for RawHandleWrapper,
56+
// as the `raw_window_handle` method is safe. We cannot guarantee that all calls
57+
// of this method are correct (as it may be off the main thread on an incompatible platform),
58+
// and so exposing a safe method to get a [`RawWindowHandle`] directly would be UB.
59+
unsafe impl HasRawWindowHandle for ThreadLockedRawWindowHandleWrapper {
60+
fn raw_window_handle(&self) -> RawWindowHandle {
61+
self.0.get_window_handle()
62+
}
63+
}
64+
65+
// SAFETY: the caller has validated that this is a valid context to get [`RawDisplayHandle`]
66+
// as otherwise an instance of this type could not have been constructed
67+
// NOTE: we cannot simply impl HasRawDisplayHandle for RawHandleWrapper,
68+
// as the `raw_display_handle` method is safe. We cannot guarantee that all calls
69+
// of this method are correct (as it may be off the main thread on an incompatible platform),
70+
// and so exposing a safe method to get a [`RawDisplayHandle`] directly would be UB.
71+
unsafe impl HasRawDisplayHandle for ThreadLockedRawWindowHandleWrapper {
72+
fn raw_display_handle(&self) -> RawDisplayHandle {
73+
self.0.get_display_handle()
74+
}
75+
}

crates/bevy_window/src/raw_window_handle.rs

Lines changed: 0 additions & 54 deletions
This file was deleted.

crates/bevy_window/src/window.rs

Lines changed: 37 additions & 26 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_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,34 +603,34 @@ 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 grab, 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 grab, 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
///
620631
/// ## Platform-specific
621632
///
622-
/// - **`Windows`**, **`X11`**, and **`Wayland`**: The cursor is hidden only when inside the window. To stop the cursor from leaving the window, use [`set_cursor_lock_mode`](Window::set_cursor_lock_mode).
633+
/// - **`Windows`**, **`X11`**, and **`Wayland`**: The cursor is hidden only when inside the window. To stop the cursor from leaving the window, use [`set_cursor_grab_mode`](Window::set_cursor_grab_mode).
623634
/// - **`macOS`**: The cursor is hidden only when the window is focused.
624635
/// - **`iOS`** and **`Android`** do not have cursors
625636
#[inline]
@@ -630,7 +641,7 @@ impl Window {
630641
///
631642
/// ## Platform-specific
632643
///
633-
/// - **`Windows`**, **`X11`**, and **`Wayland`**: The cursor is hidden only when inside the window. To stop the cursor from leaving the window, use [`set_cursor_lock_mode`](Window::set_cursor_lock_mode).
644+
/// - **`Windows`**, **`X11`**, and **`Wayland`**: The cursor is hidden only when inside the window. To stop the cursor from leaving the window, use [`set_cursor_grab_mode`](Window::set_cursor_grab_mode).
634645
/// - **`macOS`**: The cursor is hidden only when the window is focused.
635646
/// - **`iOS`** and **`Android`** do not have cursors
636647
pub fn set_cursor_visibility(&mut self, visible_mode: bool) {
@@ -719,9 +730,9 @@ impl Window {
719730
pub fn is_focused(&self) -> bool {
720731
self.focused
721732
}
722-
/// Get the [`RawWindowHandleWrapper`] corresponding to this window
723-
pub fn raw_window_handle(&self) -> RawWindowHandleWrapper {
724-
self.raw_window_handle.clone()
733+
/// Get the [`RawHandleWrapper`] corresponding to this window
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,

0 commit comments

Comments
 (0)