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