Draft multi-threaded image rendering in iced_wgpu

This commit is contained in:
Héctor Ramón Jiménez 2025-10-24 17:23:40 +02:00
parent 92888a3639
commit cb8d2710da
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
22 changed files with 886 additions and 305 deletions

View file

@ -49,7 +49,7 @@ use crate::futures::futures::task;
use crate::futures::futures::{Future, StreamExt};
use crate::futures::subscription;
use crate::futures::{Executor, Runtime};
use crate::graphics::{Compositor, compositor};
use crate::graphics::{Compositor, Shell, compositor};
use crate::runtime::system;
use crate::runtime::user_interface::{self, UserInterface};
use crate::runtime::{Action, Task};
@ -587,8 +587,10 @@ async fn run_instance<P>(
let default_fonts = default_fonts.clone();
async move {
let shell = Shell::new(proxy.clone());
let mut compositor =
<P::Renderer as compositor::Default>::Compositor::new(graphics_settings, window).await;
<P::Renderer as compositor::Default>::Compositor::new(graphics_settings, window, shell).await;
if let Ok(compositor) = &mut compositor {
for font in default_fonts {
@ -824,7 +826,7 @@ async fn run_instance<P>(
.get_mut(&id)
.expect("Get user interface");
let draw_span = debug::draw(id);
let interact_span = debug::interact(id);
let mut change_count = 0;
let state = loop {
@ -947,7 +949,9 @@ async fn run_instance<P>(
user_interfaces.get_mut(&id).unwrap();
}
};
interact_span.finish();
let draw_span = debug::draw(id);
interface.draw(
&mut window.renderer,
window.state.theme(),
@ -1646,6 +1650,26 @@ fn run_action<'a, P, C>(
let _ = window.raw.set_cursor_hittest(true);
}
}
window::Action::RedrawAll => {
for (_id, window) in window_manager.iter_mut() {
window.raw.request_redraw();
}
}
window::Action::RelayoutAll => {
for (id, window) in window_manager.iter_mut() {
if let Some(ui) = interfaces.remove(&id) {
let _ = interfaces.insert(
id,
ui.relayout(
window.state.logical_size(),
&mut window.renderer,
),
);
}
window.raw.request_redraw();
}
}
},
Action::System(action) => match action {
system::Action::GetInformation(_channel) => {

View file

@ -4,7 +4,9 @@ use crate::futures::futures::{
select,
task::{Context, Poll},
};
use crate::graphics::shell;
use crate::runtime::Action;
use crate::runtime::window;
use std::pin::Pin;
/// An event loop proxy with backpressure that implements `Sink`.
@ -134,3 +136,16 @@ impl<T: 'static> Sink<Action<T>> for Proxy<T> {
Poll::Ready(Ok(()))
}
}
impl<T> shell::Notifier for Proxy<T>
where
T: Send,
{
fn request_redraw(&self) {
self.send_action(Action::Window(window::Action::RedrawAll));
}
fn invalidate_layout(&self) {
self.send_action(Action::Window(window::Action::RelayoutAll));
}
}