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 embed;
16#[cfg(not(target_arch = "wasm32"))]
17mod harness;
18#[cfg(not(target_arch = "wasm32"))]
19mod headless;
20#[cfg(not(target_arch = "wasm32"))]
21mod os_clipboard;
22#[cfg(not(target_arch = "wasm32"))]
23mod scenario;
24#[cfg(not(target_arch = "wasm32"))]
25mod synthetic;
26#[cfg(not(target_arch = "wasm32"))]
27pub mod testing;
28mod window;
29
30#[cfg(not(target_arch = "wasm32"))]
31pub use element_render::{
32    render_element, render_element_with, render_element_with_state, with_fonts, with_headless,
33};
34#[cfg(not(target_arch = "wasm32"))]
35pub use embed::{Embedded, EventResponse};
36#[cfg(not(target_arch = "wasm32"))]
37pub use harness::Harness;
38#[cfg(not(target_arch = "wasm32"))]
39pub use headless::Headless;
40#[cfg(not(target_arch = "wasm32"))]
41pub use os_clipboard::OsClipboard;
42#[cfg(not(target_arch = "wasm32"))]
43pub use scenario::{ScenarioError, ScenarioReport, run_scenario};
44#[cfg(not(target_arch = "wasm32"))]
45pub use synthetic::{SyntheticEvent, render_app};
46pub use window::{WindowOptions, run_app};
47
48// Re-exports for embedders: integration code must use the same wgpu and
49// winit versions fenestra was built with (the egui-wgpu convention).
50pub use vello;
51pub use vello::wgpu;
52#[cfg(not(target_arch = "wasm32"))]
53pub use window::{run_scene, run_static};
54pub use winit;
55
56/// Errors from the windowed or headless runners.
57#[derive(Debug)]
58pub enum ShellError {
59    /// No compute-capable wgpu adapter was found.
60    NoDevice,
61    /// The vello renderer failed to build or render.
62    Vello(vello::Error),
63    /// The winit event loop failed.
64    EventLoop(winit::error::EventLoopError),
65    /// GPU readback of the rendered image failed.
66    Readback,
67}
68
69impl fmt::Display for ShellError {
70    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71        match self {
72            Self::NoDevice => write!(f, "no compute-capable wgpu adapter found"),
73            Self::Vello(e) => write!(f, "vello renderer error: {e}"),
74            Self::EventLoop(e) => write!(f, "winit event loop error: {e}"),
75            Self::Readback => write!(f, "GPU readback failed"),
76        }
77    }
78}
79
80impl std::error::Error for ShellError {}