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 Issues : Unexpected Monitor Behavior When Resizing with wgpu on Windows. #5213

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 12 additions & 7 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,16 @@ impl<'app> GlowWinitRunning<'app> {
};

viewport.info.events.clear(); // they should have been processed
let window = viewport.window.clone().unwrap();
let gl_surface = viewport.gl_surface.as_ref().unwrap();
let egui_winit = viewport.egui_winit.as_mut().unwrap();

egui_winit.handle_platform_output(&window, platform_output);
let (Some(egui_winit), Some(window), Some(gl_surface)) = (
viewport.egui_winit.as_mut(),
&viewport.window.clone(),
&viewport.gl_surface,
) else {
return Ok(EventResult::Wait);
};

egui_winit.handle_platform_output(window, platform_output);

let clipped_primitives = integration.egui_ctx.tessellate(shapes, pixels_per_point);

Expand Down Expand Up @@ -691,7 +696,7 @@ impl<'app> GlowWinitRunning<'app> {
}
}

integration.post_rendering(&window);
integration.post_rendering(window);
}

{
Expand Down Expand Up @@ -720,7 +725,7 @@ impl<'app> GlowWinitRunning<'app> {

integration.report_frame_time(frame_timer.total_time_sec()); // don't count auto-save time as part of regular frame time

integration.maybe_autosave(app.as_mut(), Some(&window));
integration.maybe_autosave(app.as_mut(), Some(window));

if window.is_minimized() == Some(true) {
// On Mac, a minimized Window uses up all CPU:
Expand Down Expand Up @@ -1478,7 +1483,7 @@ fn render_immediate_viewport(
viewport.info.events.clear(); // they should have been processed

let (Some(egui_winit), Some(window), Some(gl_surface)) = (
&mut viewport.egui_winit,
viewport.egui_winit.as_mut(),
&viewport.window,
&viewport.gl_surface,
) else {
Expand Down
73 changes: 36 additions & 37 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,48 +77,47 @@ impl<T: WinitApp> WinitAppWrapper<T> {
event_loop: &ActiveEventLoop,
event_result: Result<EventResult>,
) {
let mut now = Instant::now();
let mut exit = false;

log::trace!("event_result: {event_result:?}");

let combined_result = event_result.and_then(|event_result| {
match event_result {
EventResult::Wait => {
event_loop.set_control_flow(ControlFlow::Wait);
Ok(event_result)
}
EventResult::RepaintNow(window_id) => {
log::trace!("RepaintNow of {window_id:?}",);
let mut event_result = event_result;

if cfg!(target_os = "windows") {
// Fix flickering on Windows, see https://github.com/emilk/egui/pull/2280
self.winit_app.run_ui_and_paint(event_loop, window_id)
} else {
// Fix for https://github.com/emilk/egui/issues/2425
self.windows_next_repaint_times
.insert(window_id, Instant::now());
Ok(event_result)
}
}
EventResult::RepaintNext(window_id) => {
log::trace!("RepaintNext of {window_id:?}",);
self.windows_next_repaint_times
.insert(window_id, Instant::now());
Ok(event_result)
}
EventResult::RepaintAt(window_id, repaint_time) => {
self.windows_next_repaint_times.insert(
window_id,
self.windows_next_repaint_times
.get(&window_id)
.map_or(repaint_time, |last| (*last).min(repaint_time)),
);
Ok(event_result)
}
EventResult::Exit => {
exit = true;
Ok(event_result)
}
if cfg!(target_os = "windows") {
if let Ok(EventResult::RepaintNow(window_id)) = event_result {
log::trace!("RepaintNow of {window_id:?}");
self.windows_next_repaint_times.insert(window_id, now);

// Fix flickering on Windows, see https://github.com/emilk/egui/pull/2280
event_result = self.winit_app.run_ui_and_paint(event_loop, window_id);

now = Instant::now();
}
}

let combined_result = event_result.map(|event_result| match event_result {
EventResult::Wait => {
event_loop.set_control_flow(ControlFlow::Wait);
event_result
}
EventResult::RepaintNow(window_id) => {
log::trace!("RepaintNow of {window_id:?}");
self.windows_next_repaint_times.insert(window_id, now);
event_result
}
EventResult::RepaintNext(window_id) => {
log::trace!("RepaintNext of {window_id:?}");
self.windows_next_repaint_times.insert(window_id, now);
event_result
}
EventResult::RepaintAt(window_id, when) => {
self.windows_next_repaint_times.insert(window_id, when);
event_result
}
EventResult::Exit => {
exit = true;
event_result
}
});

Expand Down
7 changes: 0 additions & 7 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,6 @@ impl<'app> WgpuWinitRunning<'app> {

integration.post_rendering(window);

let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect();

handle_viewport_output(
&integration.egui_ctx,
&viewport_output,
Expand All @@ -702,11 +700,6 @@ impl<'app> WgpuWinitRunning<'app> {
viewport_from_window,
);

// Prune dead viewports:
viewports.retain(|id, _| active_viewports_ids.contains(id));
viewport_from_window.retain(|_, id| active_viewports_ids.contains(id));
painter.gc_viewports(&active_viewports_ids);

let window = viewport_from_window
.get(&window_id)
.and_then(|id| viewports.get(id))
Expand Down
Loading