Introduce iced_sentinel and iced_debug crates

This commit is contained in:
Héctor Ramón Jiménez 2024-02-26 07:00:51 +01:00
parent 58a7007ac1
commit dd36893f7a
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
26 changed files with 543 additions and 567 deletions

View file

@ -12,7 +12,6 @@ keywords.workspace = true
[features]
default = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"]
debug = ["iced_runtime/debug"]
system = ["sysinfo"]
application = []
x11 = ["winit/x11"]

View file

@ -11,13 +11,14 @@ use crate::core::time::Instant;
use crate::core::widget::operation;
use crate::core::window;
use crate::core::{Event, Point, Size};
use crate::debug;
use crate::futures::futures;
use crate::futures::{Executor, Runtime, Subscription};
use crate::graphics::compositor::{self, Compositor};
use crate::runtime::clipboard;
use crate::runtime::program::Program;
use crate::runtime::user_interface::{self, UserInterface};
use crate::runtime::{Command, Debug};
use crate::runtime::Command;
use crate::style::application::{Appearance, StyleSheet};
use crate::{Clipboard, Error, Proxy, Settings};
@ -111,8 +112,7 @@ where
use futures::Future;
use winit::event_loop::EventLoopBuilder;
let mut debug = Debug::new();
debug.startup_started();
let boot_timer = debug::boot_time();
let event_loop = EventLoopBuilder::with_user_event()
.build()
@ -206,13 +206,13 @@ where
renderer,
runtime,
proxy,
debug,
event_receiver,
control_sender,
init_command,
window,
should_be_visible,
exit_on_close_request,
boot_timer,
));
let mut context = task::Context::from_waker(task::noop_waker_ref());
@ -276,7 +276,6 @@ async fn run_instance<A, E, C>(
mut renderer: A::Renderer,
mut runtime: Runtime<E, Proxy<A::Message>, A::Message>,
mut proxy: winit::event_loop::EventLoopProxy<A::Message>,
mut debug: Debug,
mut event_receiver: mpsc::UnboundedReceiver<
winit::event::Event<A::Message>,
>,
@ -285,6 +284,7 @@ async fn run_instance<A, E, C>(
window: Arc<winit::window::Window>,
should_be_visible: bool,
exit_on_close_request: bool,
boot_timer: debug::Timer,
) where
A: Application + 'static,
E: Executor + 'static,
@ -324,17 +324,16 @@ async fn run_instance<A, E, C>(
&mut clipboard,
&mut should_exit,
&mut proxy,
&mut debug,
&window,
);
runtime.track(application.subscription().into_recipes());
boot_timer.finish();
let mut user_interface = ManuallyDrop::new(build_user_interface(
&application,
cache,
&mut renderer,
state.logical_size(),
&mut debug,
));
let mut mouse_interaction = mouse::Interaction::default();
@ -342,8 +341,6 @@ async fn run_instance<A, E, C>(
let mut messages = Vec::new();
let mut redraw_pending = false;
debug.startup_finished();
while let Some(event) = event_receiver.next().await {
match event {
event::Event::NewEvents(
@ -382,12 +379,12 @@ async fn run_instance<A, E, C>(
if viewport_version != current_viewport_version {
let logical_size = state.logical_size();
debug.layout_started();
let layout_timer = debug::layout_time();
user_interface = ManuallyDrop::new(
ManuallyDrop::into_inner(user_interface)
.relayout(logical_size, &mut renderer),
);
debug.layout_finished();
layout_timer.finish();
compositor.configure_surface(
&mut surface,
@ -434,7 +431,7 @@ async fn run_instance<A, E, C>(
runtime.broadcast(redraw_event, core::event::Status::Ignored);
debug.draw_started();
let draw_timer = debug::draw_time();
let new_mouse_interaction = user_interface.draw(
&mut renderer,
state.theme(),
@ -444,7 +441,7 @@ async fn run_instance<A, E, C>(
state.cursor(),
);
redraw_pending = false;
debug.draw_finished();
draw_timer.finish();
if new_mouse_interaction != mouse_interaction {
window.set_cursor_icon(conversion::mouse_interaction(
@ -454,19 +451,15 @@ async fn run_instance<A, E, C>(
mouse_interaction = new_mouse_interaction;
}
debug.render_started();
let render_timer = debug::render_time();
match compositor.present(
&mut renderer,
&mut surface,
state.viewport(),
state.background_color(),
&debug.overlay(),
) {
Ok(()) => {
debug.render_finished();
// TODO: Handle animations!
// Maybe we can use `ControlFlow::WaitUntil` for this.
render_timer.finish();
}
Err(error) => match error {
// This is an unrecoverable error.
@ -474,8 +467,6 @@ async fn run_instance<A, E, C>(
panic!("{error:?}");
}
_ => {
debug.render_finished();
// Try rendering again next frame.
window.request_redraw();
}
@ -492,7 +483,7 @@ async fn run_instance<A, E, C>(
break;
}
state.update(&window, &window_event, &mut debug);
state.update(&window, &window_event);
if let Some(event) = conversion::window_event(
window::Id::MAIN,
@ -508,8 +499,7 @@ async fn run_instance<A, E, C>(
continue;
}
debug.event_processing_started();
let interact_timer = debug::interact_time();
let (interface_state, statuses) = user_interface.update(
&events,
state.cursor(),
@ -517,8 +507,7 @@ async fn run_instance<A, E, C>(
&mut clipboard,
&mut messages,
);
debug.event_processing_finished();
interact_timer.finish();
for (event, status) in
events.drain(..).zip(statuses.into_iter())
@ -547,7 +536,6 @@ async fn run_instance<A, E, C>(
&mut clipboard,
&mut should_exit,
&mut proxy,
&mut debug,
&mut messages,
&window,
);
@ -557,7 +545,6 @@ async fn run_instance<A, E, C>(
cache,
&mut renderer,
state.logical_size(),
&mut debug,
));
if should_exit {
@ -609,18 +596,17 @@ pub fn build_user_interface<'a, A: Application>(
cache: user_interface::Cache,
renderer: &mut A::Renderer,
size: Size,
debug: &mut Debug,
) -> UserInterface<'a, A::Message, A::Theme, A::Renderer>
where
A::Theme: StyleSheet,
{
debug.view_started();
let view_timer = debug::view_time();
let view = application.view();
debug.view_finished();
view_timer.finish();
debug.layout_started();
let layout_timer = debug::layout_time();
let user_interface = UserInterface::build(view, size, cache, renderer);
debug.layout_finished();
layout_timer.finish();
user_interface
}
@ -638,7 +624,6 @@ pub fn update<A: Application, C, E: Executor>(
clipboard: &mut Clipboard,
should_exit: &mut bool,
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
debug: &mut Debug,
messages: &mut Vec<A::Message>,
window: &winit::window::Window,
) where
@ -646,11 +631,11 @@ pub fn update<A: Application, C, E: Executor>(
A::Theme: StyleSheet,
{
for message in messages.drain(..) {
debug.log_message(&message);
debug::log_message(&message);
debug.update_started();
let update_timer = debug::update_time();
let command = runtime.enter(|| application.update(message));
debug.update_finished();
update_timer.finish();
run_command(
application,
@ -664,7 +649,6 @@ pub fn update<A: Application, C, E: Executor>(
clipboard,
should_exit,
proxy,
debug,
window,
);
}
@ -688,7 +672,6 @@ pub fn run_command<A, C, E>(
clipboard: &mut Clipboard,
should_exit: &mut bool,
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
debug: &mut Debug,
window: &winit::window::Window,
) where
A: Application,
@ -855,7 +838,6 @@ pub fn run_command<A, C, E>(
surface,
state.viewport(),
state.background_color(),
&debug.overlay(),
);
proxy
@ -895,7 +877,6 @@ pub fn run_command<A, C, E>(
current_cache,
renderer,
state.logical_size(),
debug,
);
while let Some(mut operation) = current_operation.take() {

View file

@ -3,7 +3,6 @@ use crate::conversion;
use crate::core::mouse;
use crate::core::{Color, Size};
use crate::graphics::Viewport;
use crate::runtime::Debug;
use crate::Application;
use std::marker::PhantomData;
@ -122,12 +121,7 @@ where
/// Processes the provided window event and updates the [`State`]
/// accordingly.
pub fn update(
&mut self,
window: &Window,
event: &WindowEvent,
_debug: &mut Debug,
) {
pub fn update(&mut self, window: &Window, event: &WindowEvent) {
match event {
WindowEvent::Resized(new_size) => {
let size = Size::new(new_size.width, new_size.height);
@ -176,7 +170,7 @@ where
..
},
..
} => _debug.toggle(),
} => crate::debug::open_axe(),
_ => {}
}
}

View file

@ -29,6 +29,7 @@
pub use iced_graphics as graphics;
pub use iced_runtime as runtime;
pub use iced_runtime::core;
pub use iced_runtime::debug;
pub use iced_runtime::futures;
pub use iced_style as style;
pub use winit;

View file

@ -11,6 +11,7 @@ use crate::core::renderer;
use crate::core::widget::operation;
use crate::core::window;
use crate::core::{Point, Size};
use crate::debug;
use crate::futures::futures::channel::mpsc;
use crate::futures::futures::{task, Future, StreamExt};
use crate::futures::{Executor, Runtime, Subscription};
@ -19,7 +20,6 @@ use crate::multi_window::window_manager::WindowManager;
use crate::runtime::command::{self, Command};
use crate::runtime::multi_window::Program;
use crate::runtime::user_interface::{self, UserInterface};
use crate::runtime::Debug;
use crate::style::application::StyleSheet;
use crate::{Clipboard, Error, Proxy, Settings};
@ -112,8 +112,7 @@ where
{
use winit::event_loop::EventLoopBuilder;
let mut debug = Debug::new();
debug.startup_started();
let boot_timer = debug::boot_time();
let event_loop = EventLoopBuilder::with_user_event()
.build()
@ -202,12 +201,12 @@ where
compositor,
runtime,
proxy,
debug,
event_receiver,
control_sender,
init_command,
window_manager,
should_main_be_visible,
boot_timer,
));
let mut context = task::Context::from_waker(task::noop_waker_ref());
@ -339,12 +338,12 @@ async fn run_instance<A, E, C>(
mut compositor: C,
mut runtime: Runtime<E, Proxy<A::Message>, A::Message>,
mut proxy: winit::event_loop::EventLoopProxy<A::Message>,
mut debug: Debug,
mut event_receiver: mpsc::UnboundedReceiver<Event<A::Message>>,
mut control_sender: mpsc::UnboundedSender<Control>,
init_command: Command<A::Message>,
mut window_manager: WindowManager<A, C>,
should_main_window_be_visible: bool,
boot_timer: debug::Timer,
) where
A: Application + 'static,
E: Executor + 'static,
@ -377,15 +376,6 @@ async fn run_instance<A, E, C>(
};
let mut ui_caches = HashMap::new();
let mut user_interfaces = ManuallyDrop::new(build_user_interfaces(
&application,
&mut debug,
&mut window_manager,
HashMap::from_iter([(
window::Id::MAIN,
user_interface::Cache::default(),
)]),
));
run_command(
&application,
@ -395,17 +385,24 @@ async fn run_instance<A, E, C>(
&mut clipboard,
&mut control_sender,
&mut proxy,
&mut debug,
&mut window_manager,
&mut ui_caches,
);
runtime.track(application.subscription().into_recipes());
boot_timer.finish();
let mut user_interfaces = ManuallyDrop::new(build_user_interfaces(
&application,
&mut window_manager,
HashMap::from_iter([(
window::Id::MAIN,
user_interface::Cache::default(),
)]),
));
let mut messages = Vec::new();
debug.startup_finished();
'main: while let Some(event) = event_receiver.next().await {
match event {
Event::WindowCreated {
@ -430,7 +427,6 @@ async fn run_instance<A, E, C>(
user_interface::Cache::default(),
&mut window.renderer,
logical_size,
&mut debug,
id,
),
);
@ -513,7 +509,7 @@ async fn run_instance<A, E, C>(
&mut messages,
);
debug.draw_started();
let draw_timer = debug::draw_time();
let new_mouse_interaction = ui.draw(
&mut window.renderer,
window.state.theme(),
@ -522,7 +518,7 @@ async fn run_instance<A, E, C>(
},
cursor,
);
debug.draw_finished();
draw_timer.finish();
if new_mouse_interaction != window.mouse_interaction {
window.raw.set_cursor_icon(
@ -569,7 +565,7 @@ async fn run_instance<A, E, C>(
{
let logical_size = window.state.logical_size();
debug.layout_started();
let layout_time = debug::layout_time();
let ui = user_interfaces
.remove(&id)
.expect("Remove user interface");
@ -578,9 +574,9 @@ async fn run_instance<A, E, C>(
id,
ui.relayout(logical_size, &mut window.renderer),
);
debug.layout_finished();
layout_time.finish();
debug.draw_started();
let draw_time = debug::draw_time();
let new_mouse_interaction = user_interfaces
.get_mut(&id)
.expect("Get user interface")
@ -592,7 +588,7 @@ async fn run_instance<A, E, C>(
},
window.state.cursor(),
);
debug.draw_finished();
draw_time.finish();
if new_mouse_interaction != window.mouse_interaction
{
@ -616,16 +612,15 @@ async fn run_instance<A, E, C>(
window.state.viewport_version();
}
debug.render_started();
let render_time = debug::render_time();
match compositor.present(
&mut window.renderer,
&mut window.surface,
window.state.viewport(),
window.state.background_color(),
&debug.overlay(),
) {
Ok(()) => {
debug.render_finished();
render_time.finish();
// TODO: Handle animations!
// Maybe we can use `ControlFlow::WaitUntil` for this.
@ -636,8 +631,6 @@ async fn run_instance<A, E, C>(
panic!("{:?}", error);
}
_ => {
debug.render_finished();
log::error!(
"Error {error:?} when \
presenting surface."
@ -681,11 +674,7 @@ async fn run_instance<A, E, C>(
break 'main;
}
} else {
window.state.update(
&window.raw,
&window_event,
&mut debug,
);
window.state.update(&window.raw, &window_event);
if let Some(event) = conversion::window_event(
id,
@ -702,7 +691,7 @@ async fn run_instance<A, E, C>(
continue;
}
debug.event_processing_started();
let interact_time = debug::interact_time();
let mut uis_stale = false;
for (id, window) in window_manager.iter_mut() {
@ -749,8 +738,7 @@ async fn run_instance<A, E, C>(
runtime.broadcast(event, status);
}
}
debug.event_processing_finished();
interact_time.finish();
// TODO mw application update returns which window IDs to update
if !messages.is_empty() || uis_stale {
@ -770,7 +758,6 @@ async fn run_instance<A, E, C>(
&mut clipboard,
&mut control_sender,
&mut proxy,
&mut debug,
&mut messages,
&mut window_manager,
&mut cached_interfaces,
@ -794,7 +781,6 @@ async fn run_instance<A, E, C>(
user_interfaces =
ManuallyDrop::new(build_user_interfaces(
&application,
&mut debug,
&mut window_manager,
cached_interfaces,
));
@ -815,19 +801,18 @@ fn build_user_interface<'a, A: Application>(
cache: user_interface::Cache,
renderer: &mut A::Renderer,
size: Size,
debug: &mut Debug,
id: window::Id,
) -> UserInterface<'a, A::Message, A::Theme, A::Renderer>
where
A::Theme: StyleSheet,
{
debug.view_started();
let view_timer = debug::view_time();
let view = application.view(id);
debug.view_finished();
view_timer.finish();
debug.layout_started();
let layout_timer = debug::layout_time();
let user_interface = UserInterface::build(view, size, cache, renderer);
debug.layout_finished();
layout_timer.finish();
user_interface
}
@ -841,7 +826,6 @@ fn update<A: Application, C, E: Executor>(
clipboard: &mut Clipboard,
control_sender: &mut mpsc::UnboundedSender<Control>,
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
debug: &mut Debug,
messages: &mut Vec<A::Message>,
window_manager: &mut WindowManager<A, C>,
ui_caches: &mut HashMap<window::Id, user_interface::Cache>,
@ -850,11 +834,11 @@ fn update<A: Application, C, E: Executor>(
A::Theme: StyleSheet,
{
for message in messages.drain(..) {
debug.log_message(&message);
debug.update_started();
debug::log_message(&message);
let update_timer = debug::update_time();
let command = runtime.enter(|| application.update(message));
debug.update_finished();
update_timer.finish();
run_command(
application,
@ -864,7 +848,6 @@ fn update<A: Application, C, E: Executor>(
clipboard,
control_sender,
proxy,
debug,
window_manager,
ui_caches,
);
@ -883,7 +866,6 @@ fn run_command<A, C, E>(
clipboard: &mut Clipboard,
control_sender: &mut mpsc::UnboundedSender<Control>,
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
debug: &mut Debug,
window_manager: &mut WindowManager<A, C>,
ui_caches: &mut HashMap<window::Id, user_interface::Cache>,
) where
@ -1118,7 +1100,6 @@ fn run_command<A, C, E>(
&mut window.surface,
window.state.viewport(),
window.state.background_color(),
&debug.overlay(),
);
proxy
@ -1155,7 +1136,6 @@ fn run_command<A, C, E>(
let mut uis = build_user_interfaces(
application,
debug,
window_manager,
std::mem::take(ui_caches),
);
@ -1211,7 +1191,6 @@ fn run_command<A, C, E>(
/// Build the user interface for every window.
pub fn build_user_interfaces<'a, A: Application, C: Compositor>(
application: &'a A,
debug: &mut Debug,
window_manager: &mut WindowManager<A, C>,
mut cached_user_interfaces: HashMap<window::Id, user_interface::Cache>,
) -> HashMap<window::Id, UserInterface<'a, A::Message, A::Theme, A::Renderer>>
@ -1231,7 +1210,6 @@ where
cache,
&mut window.renderer,
window.state.logical_size(),
debug,
id,
),
))

View file

@ -138,12 +138,7 @@ where
}
/// Processes the provided window event and updates the [`State`] accordingly.
pub fn update(
&mut self,
window: &Window,
event: &WindowEvent,
_debug: &mut crate::runtime::Debug,
) {
pub fn update(&mut self, window: &Window, event: &WindowEvent) {
match event {
WindowEvent::Resized(new_size) => {
let size = Size::new(new_size.width, new_size.height);