Skip to content

Commit

Permalink
Use less RwLocks and Arcs in public interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 1, 2023
1 parent 521678b commit ec39563
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
50 changes: 29 additions & 21 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 1 addition & 13 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1113,18 +1113,6 @@ pub fn process_viewport_commands(
}
}

pub fn process_viewports_commands(
commands: Vec<(ViewportId, ViewportCommand)>,
focused: Option<ViewportId>,
get_window: impl Fn(ViewportId) -> Option<Arc<RwLock<winit::window::Window>>>,
) {
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())
Expand Down

0 comments on commit ec39563

Please sign in to comment.