Skip to content

Commit

Permalink
Lock once up-front
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 13, 2023
1 parent 0cd6204 commit 4ba27bd
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,14 @@ mod wgpu_integration {
event: &winit::event::WindowEvent<'_>,
focused_viewport: &mut Option<ViewportId>,
) -> EventResult {
let viewport_id = self.shared.borrow().viewport_maps.get(&window_id).copied();
let Self {
integration,
app,
shared,
} = self;
let mut shared = shared.borrow_mut();

let viewport_id = shared.viewport_maps.get(&window_id).copied();

// On Windows, if a window is resized by the user, it should repaint synchronously, inside the
// event handler.
Expand Down Expand Up @@ -1911,11 +1918,7 @@ mod wgpu_integration {
NonZeroU32::new(physical_size.width),
NonZeroU32::new(physical_size.height),
) {
self.shared.borrow_mut().painter.on_window_resized(
viewport_id,
width,
height,
);
shared.painter.on_window_resized(viewport_id, width, height);
}
}
}
Expand All @@ -1924,41 +1927,28 @@ mod wgpu_integration {
if let (Some(width), Some(height), Some(viewport_id)) = (
NonZeroU32::new(new_inner_size.width),
NonZeroU32::new(new_inner_size.height),
self.shared.borrow().viewport_maps.get(&window_id).copied(),
shared.viewport_maps.get(&window_id).copied(),
) {
repaint_asap = true;
self.shared.borrow_mut().painter.on_window_resized(
viewport_id,
width,
height,
);
shared.painter.on_window_resized(viewport_id, width, height);
}
}
winit::event::WindowEvent::CloseRequested if self.integration.should_close() => {
winit::event::WindowEvent::CloseRequested if integration.should_close() => {
log::debug!("Received WindowEvent::CloseRequested");
return EventResult::Exit;
}
_ => {}
};

let mut shared = self.shared.borrow_mut();

let event_response = if let Some((id, viewport)) = viewport_id
.and_then(|id| shared.viewports.get_mut(&id).map(|viewport| (id, viewport)))
{
if let Some(egui_winit) = &mut viewport.egui_winit {
Some(
self.integration
.on_event(self.app.as_mut(), event, egui_winit, id),
)
} else {
None
}
} else {
None
};
let event_response = viewport_id.and_then(|viewport_id| {
shared.viewports.get_mut(&viewport_id).and_then(|viewport| {
viewport.egui_winit.as_mut().map(|egui_winit| {
integration.on_event(app.as_mut(), event, egui_winit, viewport_id)
})
})
});

if self.integration.should_close() {
if integration.should_close() {
EventResult::Exit
} else if let Some(event_response) = event_response {
if event_response.repaint {
Expand Down

0 comments on commit 4ba27bd

Please sign in to comment.