Skip to main content

fenestra_shell/
lib.rs

1//! OS glue for fenestra: the winit + wgpu windowed runner and the headless
2//! renderer. Everything that touches a display server lives here;
3//! `fenestra-core` and `fenestra-kit` stay windowless.
4
5use std::fmt;
6
7// Headless rendering, GPU readback, the OS clipboard, and the AccessKit
8// adapter are native-only; on the web only the windowed (canvas) runner
9// exists. `fenestra-core` and `fenestra-kit` compile everywhere.
10#[cfg(not(target_arch = "wasm32"))]
11mod access;
12#[cfg(not(target_arch = "wasm32"))]
13mod element_render;
14#[cfg(not(target_arch = "wasm32"))]
15mod harness;
16#[cfg(not(target_arch = "wasm32"))]
17mod headless;
18#[cfg(not(target_arch = "wasm32"))]
19mod os_clipboard;
20#[cfg(not(target_arch = "wasm32"))]
21mod scenario;
22#[cfg(not(target_arch = "wasm32"))]
23mod synthetic;
24#[cfg(not(target_arch = "wasm32"))]
25pub mod testing;
26mod window;
27
28#[cfg(not(target_arch = "wasm32"))]
29pub use element_render::{
30    render_element, render_element_with, render_element_with_state, with_fonts, with_headless,
31};
32#[cfg(not(target_arch = "wasm32"))]
33pub use harness::Harness;
34#[cfg(not(target_arch = "wasm32"))]
35pub use headless::Headless;
36#[cfg(not(target_arch = "wasm32"))]
37pub use os_clipboard::OsClipboard;
38#[cfg(not(target_arch = "wasm32"))]
39pub use scenario::{ScenarioError, ScenarioReport, run_scenario};
40#[cfg(not(target_arch = "wasm32"))]
41pub use synthetic::{SyntheticEvent, render_app};
42pub use window::{WindowOptions, run_app};
43#[cfg(not(target_arch = "wasm32"))]
44pub use window::{run_scene, run_static};
45
46/// Errors from the windowed or headless runners.
47#[derive(Debug)]
48pub enum ShellError {
49    /// No compute-capable wgpu adapter was found.
50    NoDevice,
51    /// The vello renderer failed to build or render.
52    Vello(vello::Error),
53    /// The winit event loop failed.
54    EventLoop(winit::error::EventLoopError),
55    /// GPU readback of the rendered image failed.
56    Readback,
57}
58
59impl fmt::Display for ShellError {
60    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
61        match self {
62            Self::NoDevice => write!(f, "no compute-capable wgpu adapter found"),
63            Self::Vello(e) => write!(f, "vello renderer error: {e}"),
64            Self::EventLoop(e) => write!(f, "winit event loop error: {e}"),
65            Self::Readback => write!(f, "GPU readback failed"),
66        }
67    }
68}
69
70impl std::error::Error for ShellError {}