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

45
graphics/src/shell.rs Normal file
View file

@ -0,0 +1,45 @@
//! Control the windowing runtime from a renderer.
use std::sync::Arc;
/// A windowing shell.
#[derive(Clone)]
pub struct Shell(Arc<dyn Notifier>);
impl Shell {
/// Creates a new [`Shell`].
pub fn new(notifier: impl Notifier) -> Self {
Self(Arc::new(notifier))
}
/// Creates a headless [`Shell`].
pub fn headless() -> Self {
struct Headless;
impl Notifier for Headless {
fn request_redraw(&self) {}
fn invalidate_layout(&self) {}
}
Self::new(Headless)
}
/// Requests for all windows of the [`Shell`] to be redrawn.
pub fn request_redraw(&self) {
self.0.request_redraw();
}
/// Requests for all layouts of the [`Shell`] to be recomputed.
pub fn invalidate_layout(&self) {
self.0.invalidate_layout();
}
}
/// A type that can notify a shell of certain events.
pub trait Notifier: Send + Sync + 'static {
/// Requests for all windows of the [`Shell`] to be redrawn.
fn request_redraw(&self);
/// Requests for all layouts of the [`Shell`] to be recomputed.
fn invalidate_layout(&self);
}