Draft multi-threaded image rendering in iced_wgpu
This commit is contained in:
parent
92888a3639
commit
cb8d2710da
22 changed files with 886 additions and 305 deletions
|
|
@ -2,7 +2,7 @@
|
|||
//! surfaces.
|
||||
use crate::core::Color;
|
||||
use crate::futures::{MaybeSend, MaybeSync};
|
||||
use crate::{Error, Settings, Viewport};
|
||||
use crate::{Error, Settings, Shell, Viewport};
|
||||
|
||||
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
|
||||
use thiserror::Error;
|
||||
|
|
@ -21,8 +21,9 @@ pub trait Compositor: Sized {
|
|||
fn new<W: Window + Clone>(
|
||||
settings: Settings,
|
||||
compatible_window: W,
|
||||
shell: Shell,
|
||||
) -> impl Future<Output = Result<Self, Error>> {
|
||||
Self::with_backend(settings, compatible_window, None)
|
||||
Self::with_backend(settings, compatible_window, shell, None)
|
||||
}
|
||||
|
||||
/// Creates a new [`Compositor`] with a backend preference.
|
||||
|
|
@ -32,6 +33,7 @@ pub trait Compositor: Sized {
|
|||
fn with_backend<W: Window + Clone>(
|
||||
_settings: Settings,
|
||||
_compatible_window: W,
|
||||
_shell: Shell,
|
||||
_backend: Option<&str>,
|
||||
) -> impl Future<Output = Result<Self, Error>>;
|
||||
|
||||
|
|
@ -153,6 +155,7 @@ impl Compositor for () {
|
|||
async fn with_backend<W: Window + Clone>(
|
||||
_settings: Settings,
|
||||
_compatible_window: W,
|
||||
_shell: Shell,
|
||||
_preferred_backend: Option<&str>,
|
||||
) -> Result<Self, Error> {
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ pub mod gradient;
|
|||
pub mod image;
|
||||
pub mod layer;
|
||||
pub mod mesh;
|
||||
pub mod shell;
|
||||
pub mod text;
|
||||
|
||||
#[cfg(feature = "geometry")]
|
||||
|
|
@ -35,6 +36,7 @@ pub use image::Image;
|
|||
pub use layer::Layer;
|
||||
pub use mesh::Mesh;
|
||||
pub use settings::Settings;
|
||||
pub use shell::Shell;
|
||||
pub use text::Text;
|
||||
pub use viewport::Viewport;
|
||||
|
||||
|
|
|
|||
45
graphics/src/shell.rs
Normal file
45
graphics/src/shell.rs
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue