From ec3956318355b964f47370ac57046275bef24ea0 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 1 Nov 2023 18:43:13 +0100 Subject: [PATCH] Use less RwLocks and Arcs in public interfaces --- crates/eframe/src/native/run.rs | 50 +++++++++++++++++++-------------- crates/egui-winit/src/lib.rs | 14 +-------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 3ab6dc9c9ca..eee62641dd6 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -1583,17 +1583,21 @@ mod glow_integration { Self::process_viewport_builders(&glutin, viewports); - egui_winit::process_viewports_commands( - viewport_commands, - *self.is_focused.read(), - |viewport_id| { - glutin - .read() - .viewports - .get(&viewport_id) - .and_then(|w| w.read().window.clone()) - }, - ); + for (viewport_id, command) in viewport_commands { + if let Some(window) = glutin + .read() + .viewports + .get(&viewport_id) + .and_then(|w| w.read().window.clone()) + { + egui_winit::process_viewport_commands( + vec![command], + viewport_id, + *self.is_focused.read(), + &window.read(), + ); + } + } control_flow } else { @@ -2431,16 +2435,20 @@ mod wgpu_integration { active_viewports_ids.push(id); } - egui_winit::process_viewports_commands( - viewport_commands, - *self.is_focused.read(), - |viewport_id| { - windows - .read() - .get(&viewport_id) - .and_then(|w| w.window.clone()) - }, - ); + for (viewport_id, command) in viewport_commands { + if let Some(window) = windows + .read() + .get(&viewport_id) + .and_then(|w| w.window.clone()) + { + egui_winit::process_viewport_commands( + vec![command], + viewport_id, + *self.is_focused.read(), + &window.read(), + ); + } + } windows .write() diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 7d120a004a5..9ea9a3961e2 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -16,7 +16,7 @@ pub use accesskit_winit; pub use egui; #[cfg(feature = "accesskit")] use egui::accesskit; -use egui::{mutex::RwLock, Pos2, Rect, Vec2, ViewportBuilder, ViewportCommand, ViewportId}; +use egui::{Pos2, Rect, Vec2, ViewportBuilder, ViewportCommand, ViewportId}; pub use winit; pub mod clipboard; @@ -1113,18 +1113,6 @@ pub fn process_viewport_commands( } } -pub fn process_viewports_commands( - commands: Vec<(ViewportId, ViewportCommand)>, - focused: Option, - get_window: impl Fn(ViewportId) -> Option>>, -) { - for (viewport_id, command) in commands { - if let Some(window) = get_window(viewport_id) { - process_viewport_commands(vec![command], viewport_id, focused, &window.read()); - } - } -} - pub fn create_winit_window_builder(builder: &ViewportBuilder) -> winit::window::WindowBuilder { let mut window_builder = winit::window::WindowBuilder::new() .with_title(builder.title.clone())