Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upgrade to winit v0.30 #13366

Merged
merged 63 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
23793e4
fix: migrating to winit 0.30
pietrosophya May 14, 2024
fac832b
chore: removing deprecations
pietrosophya May 14, 2024
146a117
chore: split content in files
pietrosophya May 14, 2024
1dcf701
fix: app is running again
pietrosophya May 14, 2024
c2b1f68
chore: renamed file
pietrosophya May 14, 2024
bdbf9f8
fix: restored exit events
pietrosophya May 15, 2024
5249c30
fix: restored accessibility (to be tested)
pietrosophya May 15, 2024
1533a7a
chore: fixed fmt
pietrosophya May 15, 2024
f7d21ea
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 15, 2024
ce6e392
fix: revisited AppLifecycle events
pietrosophya May 15, 2024
7e7ac67
chore: refactored AppLifecycle
pietrosophya May 15, 2024
7303fde
fix: fixing android compilation
pietrosophya May 15, 2024
577bce6
fix: fixing android compilation
pietrosophya May 15, 2024
6575d0f
fix: cleaning up code
pietrosophya May 15, 2024
cd040ce
chore: fixed fmt
pietrosophya May 15, 2024
5e5f218
fix: fixed wasm compilation
pietrosophya May 15, 2024
ffd88cc
fix: fixed AppLifecycle states
pietrosophya May 15, 2024
299cad7
fix: refactored UpdateMode
pietrosophya May 15, 2024
c871130
fix: extended WinitPlugin and loop to handle custom events
pietrosophya May 15, 2024
ffe6f03
fix: fixing Windows and Linux compilation
pietrosophya May 15, 2024
f7b285a
chore: fixed fmt
pietrosophya May 15, 2024
5011160
chore: fixed clippy
pietrosophya May 15, 2024
cba01a2
fix: added WinitPlugin name and fixed UpdateMode::reactive_low_power
pietrosophya May 15, 2024
80900cc
fix: restored reactive_low_power in WinitSettings::game
pietrosophya May 15, 2024
8bddb18
fix: cached event_writer_system_state
pietrosophya May 15, 2024
b63a7ad
fix: fixed low_power example
pietrosophya May 15, 2024
6f09a13
fix: fixed mobile example on iOS
pietrosophya May 15, 2024
87fd862
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 15, 2024
e10e69c
fix: fixed without winit example
pietrosophya May 15, 2024
beca3ab
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 15, 2024
a9a46ed
fix: fixed cleaning up windows when exiting
pietrosophya May 15, 2024
62c6733
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 16, 2024
9051b31
support webgl2
mockersf May 18, 2024
00fa59b
fix patches
mockersf May 19, 2024
f2f3d93
Merge pull request #5 from mockersf/winit-0.30-with-webgl2
pietrosophya May 19, 2024
1115013
Merge pull request #6 from mockersf/winit-0.30-fix-patches
pietrosophya May 19, 2024
fceb774
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 19, 2024
02d3259
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 22, 2024
c1e2f49
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 22, 2024
e5eff40
chore: simplified import
pietrosophya May 16, 2024
2016d83
fix: fixed comments
pietrosophya May 22, 2024
67b9b4e
chore: fmt ❤️
pietrosophya May 22, 2024
04a0d8c
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 23, 2024
032d459
fix: fixed comments
pietrosophya May 23, 2024
7afbc6f
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 23, 2024
4a2729c
fix: fix CI
pietrosophya May 23, 2024
8f20b76
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 24, 2024
b5f98e5
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 26, 2024
3cc1bee
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 27, 2024
b72b917
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 27, 2024
0dc017e
fix: fixed scale factor override
pietrosophya May 28, 2024
fe29a6c
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 28, 2024
d85ed05
fix: fixed CI
pietrosophya May 28, 2024
1307fca
chore: removed logs
pietrosophya May 28, 2024
33cb44f
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 28, 2024
c0d747c
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 28, 2024
069c0da
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 29, 2024
40b74ec
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 30, 2024
bf5d291
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya May 31, 2024
08b68f7
update patch
mockersf Jun 1, 2024
0a8e99f
Update examples/mobile/Makefile
pietrosophya Jun 3, 2024
e4b499d
Merge branch 'main' into fix/upgrade-winit-0.30
pietrosophya Jun 3, 2024
d31ce1b
Merge pull request #7 from mockersf/update-patch-winit-0.30
pietrosophya Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ argh = "0.1.12"
thiserror = "1.0"
event-listener = "5.3.0"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen = { version = "0.2" }
web-sys = { version = "0.3", features = ["Window"] }

[[example]]
name = "hello_world"
path = "examples/hello_world.rs"
Expand Down Expand Up @@ -2836,6 +2840,17 @@ description = "Creates a solid color window"
category = "Window"
wasm = true

[[example]]
name = "custom_user_event"
path = "examples/window/custom_user_event.rs"
doc-scrape-examples = true

[package.metadata.example.custom_user_event]
name = "Custom User Event"
description = "Handles custom user events within the event loop"
category = "Window"
wasm = true

[[example]]
name = "low_power"
path = "examples/window/low_power.rs"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_a11y/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
bevy_derive = { path = "../bevy_derive", version = "0.14.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" }

accesskit = "0.12"
accesskit = "0.14"

[lints]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_internal/src/default_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl PluginGroup for DefaultPlugins {

#[cfg(feature = "bevy_winit")]
{
group = group.add(bevy_winit::WinitPlugin::default());
group = group.add::<bevy_winit::WinitPlugin>(bevy_winit::WinitPlugin::default());
}

#[cfg(feature = "bevy_render")]
Expand Down
24 changes: 16 additions & 8 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use bevy_utils::prelude::default;
pub use extract_param::Extract;

use bevy_hierarchy::ValidParentCheckPlugin;
use bevy_window::{PrimaryWindow, RawHandleWrapper};
use bevy_window::{PrimaryWindow, RawHandleWrapperHolder};
use extract_resource::ExtractResourcePlugin;
use globals::GlobalsPlugin;
use render_asset::RenderAssetBytesPerFrame;
Expand Down Expand Up @@ -268,10 +268,9 @@ impl Plugin for RenderPlugin {
));

let mut system_state: SystemState<
Query<&RawHandleWrapper, With<PrimaryWindow>>,
Query<&RawHandleWrapperHolder, With<PrimaryWindow>>,
> = SystemState::new(app.world_mut());
let primary_window = system_state.get(app.world()).get_single().ok().cloned();

let settings = render_creation.clone();
let async_renderer = async move {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
Expand All @@ -282,11 +281,20 @@ impl Plugin for RenderPlugin {
});

// SAFETY: Plugins should be set up on the main thread.
let surface = primary_window.map(|wrapper| unsafe {
let handle = wrapper.get_handle();
instance
.create_surface(handle)
.expect("Failed to create wgpu surface")
let surface = primary_window.and_then(|wrapper| unsafe {
let maybe_handle = wrapper.0.lock().expect(
"Couldn't get the window handle in time for renderer initialization",
);
if let Some(wrapper) = maybe_handle.as_ref() {
let handle = wrapper.get_handle();
Some(
instance
.create_surface(handle)
.expect("Failed to create wgpu surface"),
)
} else {
None
}
});

let request_adapter_options = wgpu::RequestAdapterOptions {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_tasks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ concurrent-queue = { version = "2.0.0", optional = true }
wasm-bindgen-futures = "0.4"

[dev-dependencies]
web-time = { version = "0.2" }
web-time = { version = "1.1" }

[lints]
workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ detailed_trace = []
[dependencies]
ahash = "0.8.7"
tracing = { version = "0.1", default-features = false, features = ["std"] }
web-time = { version = "0.2" }
web-time = { version = "1.1" }
hashbrown = { version = "0.14", features = ["serde"] }
bevy_utils_proc_macros = { version = "0.14.0-dev", path = "macros" }
thread_local = "1.0"
Expand Down
29 changes: 22 additions & 7 deletions crates/bevy_window/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,28 @@ pub struct WindowThemeChanged {
derive(serde::Serialize, serde::Deserialize),
reflect(Serialize, Deserialize)
)]
pub enum ApplicationLifetime {
pietrosophya marked this conversation as resolved.
Show resolved Hide resolved
/// The application just started.
Started,
pub enum AppLifecycle {
/// The application is not started yet.
Idle,
/// The application is running.
Running,
/// The application is going to be suspended.
/// Applications have one frame to react to this event before being paused in the background.
WillSuspend,
/// The application was suspended.
///
/// On Android, applications have one frame to react to this event before being paused in the background.
Suspended,
/// The application was resumed.
Resumed,
/// The application is going to be resumed.
/// Applications have one extra frame to react to this event before being fully resumed.
WillResume,
}

impl AppLifecycle {
/// Return `true` if the app can be updated.
#[inline]
pub fn is_active(&self) -> bool {
match self {
Self::Idle | Self::Suspended => false,
Self::Running | Self::WillSuspend | Self::WillResume => true,
}
}
}
11 changes: 8 additions & 3 deletions crates/bevy_window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//! The [`WindowPlugin`] sets up some global window-related parameters and
//! is part of the [`DefaultPlugins`](https://docs.rs/bevy/latest/bevy/struct.DefaultPlugins.html).

use std::sync::{Arc, Mutex};

use bevy_a11y::Focus;

mod cursor;
Expand Down Expand Up @@ -106,13 +108,16 @@ impl Plugin for WindowPlugin {
.add_event::<FileDragAndDrop>()
.add_event::<WindowMoved>()
.add_event::<WindowThemeChanged>()
.add_event::<ApplicationLifetime>();
.add_event::<AppLifecycle>();

if let Some(primary_window) = &self.primary_window {
let initial_focus = app
.world_mut()
.spawn(primary_window.clone())
.insert(PrimaryWindow)
.insert((
PrimaryWindow,
RawHandleWrapperHolder(Arc::new(Mutex::new(None))),
))
.id();
if let Some(mut focus) = app.world_mut().get_resource_mut::<Focus>() {
**focus = Some(initial_focus);
Expand Down Expand Up @@ -153,7 +158,7 @@ impl Plugin for WindowPlugin {
.register_type::<FileDragAndDrop>()
.register_type::<WindowMoved>()
.register_type::<WindowThemeChanged>()
.register_type::<ApplicationLifetime>();
.register_type::<AppLifecycle>();

// Register window descriptor and related types
app.register_type::<Window>()
Expand Down
11 changes: 10 additions & 1 deletion crates/bevy_window/src/raw_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use raw_window_handle::{
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
RawWindowHandle, WindowHandle,
};
use std::{any::Any, marker::PhantomData, ops::Deref, sync::Arc};
use std::{
any::Any,
marker::PhantomData,
ops::Deref,
sync::{Arc, Mutex},
};

/// A wrapper over a window.
///
Expand Down Expand Up @@ -116,3 +121,7 @@ impl HasDisplayHandle for ThreadLockedRawWindowHandleWrapper {
Ok(unsafe { DisplayHandle::borrow_raw(self.0.display_handle) })
}
}

/// Holder of the [`RawHandleWrapper`] with wrappers, to allow use in asynchronous context
#[derive(Debug, Clone, Component)]
pub struct RawHandleWrapperHolder(pub Arc<Mutex<Option<RawHandleWrapper>>>);
6 changes: 3 additions & 3 deletions crates/bevy_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" }

# other
# feature rwh_06 refers to window_raw_handle@v0.6
winit = { version = "0.29", default-features = false, features = ["rwh_06"] }
accesskit_winit = { version = "0.17", default-features = false, features = [
winit = { version = "0.30", default-features = false, features = ["rwh_06"] }
accesskit_winit = { version = "0.20", default-features = false, features = [
"rwh_06",
] }
approx = { version = "0.5", default-features = false }
Expand All @@ -42,7 +42,7 @@ raw-window-handle = "0.6"
serde = { version = "1.0", features = ["derive"], optional = true }

[target.'cfg(target_os = "android")'.dependencies]
winit = { version = "0.29", default-features = false, features = [
winit = { version = "0.30", default-features = false, features = [
"android-native-activity",
"rwh_06",
] }
Expand Down
Loading