From 031784e274b0a65dc67004e503b89d29fe0e36ea Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Dec 2023 10:00:27 +0100 Subject: Batch events for processing in `iced_winit` event loop --- winit/src/application.rs | 123 ++++++++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 59 deletions(-) (limited to 'winit/src') diff --git a/winit/src/application.rs b/winit/src/application.rs index 5ff76060..7f5a3620 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -469,71 +469,74 @@ async fn run_instance( events.push(event); } } - _ => {} - } + event::Event::AboutToWait => { + if events.is_empty() && messages.is_empty() { + continue; + } - if events.is_empty() && messages.is_empty() { - continue; - } + debug.event_processing_started(); - debug.event_processing_started(); + let (interface_state, statuses) = user_interface.update( + &events, + state.cursor(), + &mut renderer, + &mut clipboard, + &mut messages, + ); - let (interface_state, statuses) = user_interface.update( - &events, - state.cursor(), - &mut renderer, - &mut clipboard, - &mut messages, - ); + debug.event_processing_finished(); - debug.event_processing_finished(); + for (event, status) in + events.drain(..).zip(statuses.into_iter()) + { + runtime.broadcast(event, status); + } - for (event, status) in events.drain(..).zip(statuses.into_iter()) { - runtime.broadcast(event, status); - } + if !messages.is_empty() + || matches!( + interface_state, + user_interface::State::Outdated + ) + { + let mut cache = + ManuallyDrop::into_inner(user_interface).into_cache(); - if !messages.is_empty() - || matches!(interface_state, user_interface::State::Outdated) - { - let mut cache = - ManuallyDrop::into_inner(user_interface).into_cache(); - - // Update application - update( - &mut application, - &mut compositor, - &mut surface, - &mut cache, - &state, - &mut renderer, - &mut runtime, - &mut clipboard, - &mut should_exit, - &mut proxy, - &mut debug, - &mut messages, - &window, - ); - - // Update window - state.synchronize(&application, &window); - - user_interface = ManuallyDrop::new(build_user_interface( - &application, - cache, - &mut renderer, - state.logical_size(), - &mut debug, - )); - - if should_exit { - break; - } - } + // Update application + update( + &mut application, + &mut compositor, + &mut surface, + &mut cache, + &mut state, + &mut renderer, + &mut runtime, + &mut clipboard, + &mut should_exit, + &mut proxy, + &mut debug, + &mut messages, + &window, + ); + + user_interface = ManuallyDrop::new(build_user_interface( + &application, + cache, + &mut renderer, + state.logical_size(), + &mut debug, + )); + + if should_exit { + break; + } + } - if !redraw_pending { - window.request_redraw(); - redraw_pending = true; + if !redraw_pending { + window.request_redraw(); + redraw_pending = true; + } + } + _ => {} } } @@ -595,7 +598,7 @@ pub fn update( compositor: &mut C, surface: &mut C::Surface, cache: &mut user_interface::Cache, - state: &State, + state: &mut State, renderer: &mut A::Renderer, runtime: &mut Runtime, A::Message>, clipboard: &mut Clipboard, @@ -632,6 +635,8 @@ pub fn update( ); } + state.synchronize(application, window); + let subscription = application.subscription(); runtime.track(subscription.into_recipes()); } -- cgit