euv-core 0.47.1

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Compiled WebGL2 fullscreen blit pipeline handles returned by `web_init_gl2_blit_pipeline`.
pub(crate) struct WebGl2BlitPipeline {
    /// Compiled fullscreen blit `WebGlProgram`.
    pub(crate) program: WebGlProgram,
    /// Resident WebGL2 texture object.
    pub(crate) texture: Option<JsValue>,
    /// Optional `u_view` drawing-buffer size uniform location.
    pub(crate) view_loc: Option<WebGlUniformLocation>,
}

/// Initialized DOM canvas surface bundle returned by `web_create_canvas`.
pub(crate) struct WebCanvasSurface {
    /// Mounted `<canvas>` element.
    pub(crate) canvas: HtmlCanvasElement,
    /// Selected graphics context tier (`WebGpu`, `WebGl2`, or fallback `Canvas2d`).
    pub(crate) context_kind: WebCanvasContextKind,
    /// Optional WebGPU `GPUCanvasContext`.
    pub(crate) webgpu_ctx: Option<Object>,
    /// Optional hardware-composited `WebGl2RenderingContext`.
    pub(crate) gl2: Option<WebGl2RenderingContext>,
    /// Optional compiled WebGL2 fullscreen blit program.
    pub(crate) gl2_program: Option<WebGlProgram>,
    /// Optional resident WebGL2 texture object.
    pub(crate) gl2_texture: Option<JsValue>,
    /// Optional `u_view` drawing-buffer size uniform location of the blit program.
    pub(crate) gl2_view_loc: Option<WebGlUniformLocation>,
    /// Optional last-resort `CanvasRenderingContext2d`.
    pub(crate) ctx2d: Option<CanvasRenderingContext2d>,
}

/// Browser canvas window record storing live DOM `HtmlCanvasElement`, GPU/WebGL2/2D context, and `ResizeObserver`.
#[derive(Clone, CustomDebug, Data)]
pub struct WebWindowRecord {
    /// Declarative window configuration.
    pub(crate) config: WindowConfig,
    /// Live window state and DPR metrics.
    #[get(type(copy))]
    pub(crate) state: WindowState,
    /// Assigned canvas registration identifier.
    #[get(type(copy))]
    pub(crate) canvas_id: u32,
    /// Active graphics context tier (`WebGpu`, `WebGl2`, or last-resort `Canvas2d`).
    #[get(type(copy))]
    pub(crate) context_kind: WebCanvasContextKind,
    /// Backing DOM canvas element.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) canvas: Option<HtmlCanvasElement>,
    /// Active WebGPU `GPUCanvasContext` when WebGPU is primary.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) webgpu_ctx: Option<Object>,
    /// Active hardware-composited `WebGl2RenderingContext` when WebGL2 is bound.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2: Option<WebGl2RenderingContext>,
    /// Compiled fullscreen blit `WebGlProgram` for WebGL2 dirty-rect texture presentation.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_program: Option<WebGlProgram>,
    /// Resident WebGL2 texture object backing dirty-rect `texSubImage2D` uploads.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_texture: Option<JsValue>,
    /// `u_view` drawing-buffer size uniform location enabling 1:1 `texelFetch` presentation.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) gl2_view_loc: Option<WebGlUniformLocation>,
    /// Allocated WebGL2 texture width in pixels.
    #[get(type(copy))]
    pub(crate) gl2_tex_width: u32,
    /// Allocated WebGL2 texture height in pixels.
    #[get(type(copy))]
    pub(crate) gl2_tex_height: u32,
    /// Last-resort 2D software blit context (only acquired when WebGPU & WebGL2 are unavailable).
    #[debug(skip)]
    #[get(skip)]
    pub(crate) ctx2d: Option<CanvasRenderingContext2d>,
    /// Attached browser `ResizeObserver` watching canvas layout changes without polling reflows.
    #[debug(skip)]
    #[get(skip)]
    pub(crate) resize_observer: Option<Object>,
}

/// Direct Browser WebAssembly (`web-sys` WebGPU / WebGL2 / Canvas2D / DOM Events) platform backend.
#[derive(Clone, Data, Debug)]
pub struct WebPlatform {
    /// Monotonic window handle allocator.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) next_id: u64,
    /// Active web canvas windows.
    pub(crate) windows: HashMap<WindowId, WebWindowRecord>,
    /// Queued browser pointer, keyboard, wheel, and resize events.
    pub(crate) pending_events: Vec<WindowEvent>,
    /// Clipboard cache.
    #[get(skip)]
    pub(crate) clipboard_cache: Option<String>,
    /// Last observed `document.hidden` visibility state.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) last_hidden: bool,
    /// Last observed `navigator.onLine` connectivity state.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) last_online: bool,
    /// Last observed browser dark/light appearance mode.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) last_theme: ThemeMode,
    /// Last observed browser BCP-47 locale tag.
    #[get(pub(crate))]
    #[set(pub(crate))]
    pub(crate) last_locale: String,
    /// Last measured CSS `env(safe-area-inset-*)` insets in logical CSS pixels.
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) last_safe_area: SafeAreaInsets,
    /// Measured browser display refresh rate in Hertz (`60.0` default, updated from `requestAnimationFrame` cadence).
    #[get(pub(crate), type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) refresh_rate_hz: f32,
    /// Whether the browser `requestAnimationFrame` loop is paused while hidden/backgrounded.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) pump_paused: bool,
    /// Demand-driven `rAF` dirty flag (`true` when input, signal, or animation requires a frame; `false` sleeps at 0 Hz).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) needs_frame: bool,
    /// Whether a browser `requestAnimationFrame` callback is currently scheduled.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) raf_scheduled: bool,
    /// Active `requestAnimationFrame` handle (`0` when no frame callback is armed).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) raf_handle: i32,
}

/// Thread-local sensor fusion state bridging browser `devicemotion` and `deviceorientation` events into `DeviceMotionSample`.
#[derive(Clone, Copy, Debug)]
pub(crate) struct WebDeviceMotionState {
    /// Whether `devicemotion` and `deviceorientation` DOM listeners have already been attached.
    pub(crate) listeners_attached: bool,
    /// Whether at least one `devicemotion` callback has delivered live inertial readings.
    pub(crate) has_motion_event: bool,
    /// Latest device-frame gravity vector derived from `deviceorientation` (`+X_right, +Y_up, +Z_out`, `m/s²`).
    pub(crate) orient_gravity_dev: Option<[f32; 3]>,
    /// Latest azimuth/yaw angle in radians from `deviceorientation.alpha`.
    pub(crate) last_yaw_rad: f32,
    /// Low-pass filtered device-frame gravity fallback used when `event.acceleration` is null.
    pub(crate) filtered_gravity_dev: Option<[f32; 3]>,
    /// Auto-detected sign multiplier converting raw `accelerationIncludingGravity` to downward gravity (`-1.0` W3C / `+1.0` Safari).
    pub(crate) gravity_sign: f32,
    /// Whether `pending_sample` holds an unread sensor update for `WebPlatform::poll_events`.
    pub(crate) has_pending_sample: bool,
    /// Most recently fused screen-aligned `DeviceMotionSample` pending delivery into `WebPlatform::poll_events`.
    pub(crate) pending_sample: DeviceMotionSample,
}