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

Update to winit 0.29 #3606

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
679 changes: 522 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ image = { version = "0.24", default-features = false, features = [
"png",
] } # Needed for app icon
raw-window-handle.workspace = true
winit = { version = "0.28.1", default-features = false }
winit = { version = "0.29", default-features = false, features = ["rwh_05"] }

# optional native:
directories-next = { version = "2", optional = true }
Expand All @@ -138,8 +138,8 @@ pollster = { version = "0.3", optional = true } # needed for wgpu

# we can expose these to user so that they can select which backends they want to enable to avoid compiling useless deps.
# this can be done at the same time we expose x11/wayland features of winit crate.
glutin = { version = "0.30", optional = true }
glutin-winit = { version = "0.3.0", optional = true }
glutin = { version = "0.31", optional = true }
glutin-winit = { version = "0.4", optional = true }
puffin = { workspace = true, optional = true }
wgpu = { workspace = true, optional = true }

Expand Down
5 changes: 5 additions & 0 deletions crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ pub enum Error {
#[error("winit error: {0}")]
Winit(#[from] winit::error::OsError),

/// An error from [`winit::EventLoop`].
#[cfg(not(target_arch = "wasm32"))]
#[error("winit EventLoopError: {0}")]
WinitEventLoop(#[from] winit::error::EventLoopError),

/// An error from [`glutin`] when using [`glow`].
#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
#[error("glutin error: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl EpiIntegration {

pub fn on_window_event(
&mut self,
event: &winit::event::WindowEvent<'_>,
event: &winit::event::WindowEvent,
egui_winit: &mut egui_winit::State,
) -> EventResponse {
crate::profile_function!(egui_winit::short_window_event_description(event));
Expand Down
23 changes: 7 additions & 16 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{cell::RefCell, rc::Rc, sync::Arc, time::Instant};

use glutin::{
context::NotCurrentGlContext,
display::GetGlDisplay,
prelude::{GlDisplay, NotCurrentGlContextSurfaceAccessor, PossiblyCurrentGlContext},
prelude::{GlDisplay, PossiblyCurrentGlContext},
surface::GlSurface,
};
use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _};
Expand Down Expand Up @@ -402,7 +403,7 @@ impl WinitApp for GlowWinitApp {
fn on_event(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
event: &winit::event::Event<'_, UserEvent>,
event: &winit::event::Event<UserEvent>,
) -> Result<EventResult> {
crate::profile_function!(winit_integration::short_event_description(event));

Expand Down Expand Up @@ -434,15 +435,6 @@ impl WinitApp for GlowWinitApp {
EventResult::Wait
}

winit::event::Event::MainEventsCleared => {
if let Some(running) = &self.running {
if let Err(err) = running.glutin.borrow_mut().on_resume(event_loop) {
log::warn!("on_resume failed {err}");
}
}
EventResult::Wait
}

Copy link
Contributor Author

@fornwall fornwall Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to remove this, as winit::event::Event::Resumed is handled above.

Let's make sure to test on Android - there is a eframe using example in android-activity.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're working on glow_integration, it's probably wise to remove this stale comment entirely:

// Note: that the current Glutin API design tightly couples the GL context with
// the Window which means it's not practically possible to just destroy the
// window and re-create a new window while continuing to use the same GL context.
//
// For now this means it's not possible to support Android as well as we can with
// wgpu because we're basically forced to destroy and recreate _everything_ when
// the application suspends and resumes.
//
// There is work in progress to improve the Glutin API so it has a separate Surface
// API that would allow us to just destroy a Window/Surface when suspending, see:
// https://github.com/rust-windowing/glutin/pull/1435

The issue linked there has long been closed and fixed. Windows/Surfaces are only associated with context when/while it's made current, and it looks like eframe supports Android now with a proper Resumed/Suspended cycle?

winit::event::Event::WindowEvent { event, window_id } => {
if let Some(running) = &mut self.running {
running.on_window_event(*window_id, event)
Expand Down Expand Up @@ -664,7 +656,7 @@ impl GlowWinitRunning {
fn on_window_event(
&mut self,
window_id: WindowId,
event: &winit::event::WindowEvent<'_>,
event: &winit::event::WindowEvent,
) -> EventResult {
crate::profile_function!(egui_winit::short_window_event_description(event));

Expand Down Expand Up @@ -703,10 +695,9 @@ impl GlowWinitRunning {
}
}

winit::event::WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
if let Some(viewport_id) = viewport_id {
winit::event::WindowEvent::ScaleFactorChanged { .. } => {
if viewport_id.is_some() {
repaint_asap = true;
glutin.resize(viewport_id, **new_inner_size);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In winit 0.29 ScaleFactorChanged does not expose the new OS suggested window size. But, a Resized event will come (recently fixed on macOS - rust-windowing/winit#3214).

}
}

Expand Down Expand Up @@ -821,7 +812,7 @@ impl GlutinWindowContext {
// Create GL display. This may probably create a window too on most platforms. Definitely on `MS windows`. Never on Android.
let display_builder = glutin_winit::DisplayBuilder::new()
// we might want to expose this option to users in the future. maybe using an env var or using native_options.
.with_preference(glutin_winit::ApiPrefence::FallbackEgl) // https://github.com/emilk/egui/issues/2520#issuecomment-1367841150
.with_preference(glutin_winit::ApiPreference::FallbackEgl) // https://github.com/emilk/egui/issues/2520#issuecomment-1367841150
.with_window_builder(Some(create_winit_window_builder(
egui_ctx,
event_loop,
Expand Down
Loading