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