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

Some performance improvements. #4054

Closed
wants to merge 7 commits into from
Closed
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
36 changes: 25 additions & 11 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn run_and_return(
viewport_id,
}) => {
let current_frame_nr = winit_app.frame_nr(*viewport_id);
if current_frame_nr == *frame_nr || current_frame_nr == *frame_nr + 1 {
if current_frame_nr >= *frame_nr {
log::trace!("UserEvent::RequestRepaint scheduling repaint at {when:?}");
if let Some(window_id) = winit_app.window_id_from_viewport_id(*viewport_id) {
EventResult::RepaintAt(window_id, *when)
Expand Down Expand Up @@ -181,33 +181,40 @@ fn run_and_return(
}

let mut next_repaint_time = windows_next_repaint_times.values().min().copied();
let now = Instant::now();

windows_next_repaint_times.retain(|window_id, repaint_time| {
if Instant::now() < *repaint_time {
if now < *repaint_time {
return true; // not yet ready
};

if next_repaint_time.is_none() {
return false;
}

next_repaint_time = None;
event_loop_window_target.set_control_flow(ControlFlow::Poll);

if let Some(window) = winit_app.window(*window_id) {
log::trace!("request_redraw for {window_id:?}");
let is_minimized = window.is_minimized().unwrap_or(false);
if is_minimized {
false
// Don't draw.
// See: https://github.com/rust-windowing/winit/issues/208
// See: https://github.com/emilk/egui/issues/3321
} else {
window.request_redraw();
true
}
return false;
} else {
log::trace!("No window found for {window_id:?}");
false
}
false
});

if let Some(next_repaint_time) = next_repaint_time {
event_loop_window_target.set_control_flow(ControlFlow::WaitUntil(next_repaint_time));
};
}
})?;

log::debug!("eframe window closed");
Expand Down Expand Up @@ -270,7 +277,7 @@ fn run_and_exit(
viewport_id,
}) => {
let current_frame_nr = winit_app.frame_nr(*viewport_id);
if current_frame_nr == *frame_nr || current_frame_nr == *frame_nr + 1 {
if current_frame_nr >= *frame_nr {
if let Some(window_id) = winit_app.window_id_from_viewport_id(*viewport_id) {
EventResult::RepaintAt(window_id, *when)
} else {
Expand Down Expand Up @@ -339,28 +346,35 @@ fn run_and_exit(
}

let mut next_repaint_time = windows_next_repaint_times.values().min().copied();
let now = Instant::now();

windows_next_repaint_times.retain(|window_id, repaint_time| {
if Instant::now() < *repaint_time {
if now < *repaint_time {
return true; // not yet ready
}

if next_repaint_time.is_none() {
return false;
}

next_repaint_time = None;
event_loop_window_target.set_control_flow(ControlFlow::Poll);

if let Some(window) = winit_app.window(*window_id) {
log::trace!("request_redraw for {window_id:?}");
let is_minimized = window.is_minimized().unwrap_or(false);
if is_minimized {
false
// Don't draw.
// See: https://github.com/rust-windowing/winit/issues/208
// See: https://github.com/emilk/egui/issues/3321
} else {
window.request_redraw();
true
}
return false;
} else {
log::trace!("No window found for {window_id:?}");
false
}
false
});

if let Some(next_repaint_time) = next_repaint_time {
Expand Down
Loading