euv-core 0.48.0

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::*;

/// Unified cross-platform rendering path candidate evaluated by `AdaptiveRenderRouter`.
#[derive(
    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[serde(rename_all = "snake_case")]
pub enum RenderBackendCandidate {
    /// Direct GPU primitive rendering with zero steady-state CPU RGBA framebuffer mirroring.
    GpuDirect,
    /// GPU texture upload path presenting CPU-rasterized dirty rectangles or framebuffers.
    GpuUpload,
    /// Sparse CPU-local effect tiles composited alongside GPU-native primitives.
    Hybrid,
    /// Pure CPU analytical-SDF software rasterizer and surface blit.
    #[default]
    Software,
    /// Terminal character-cell incremental diff / CLI batched pipe output (never GPU-routed).
    Terminal,
}

/// Rollout policy governing whether adaptive routing only records shadow recommendations or performs live frame-boundary switches.
#[derive(
    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[serde(rename_all = "snake_case")]
pub enum AdaptiveSwitchMode {
    /// Shadow mode (default): evaluates candidates and records recommendations + evidence without switching live.
    #[default]
    RecommendOnly,
    /// Live mode: triggers seamless frame-boundary handoff once all quality, gain, dwell, and cooldown gates pass.
    AutoSwitch,
}

/// Workload scene profile ensuring candidate comparisons always occur under matching rendering characteristics.
#[derive(
    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[serde(rename_all = "snake_case")]
pub enum SceneProfile {
    /// Static or lightly updated UI surfaces.
    #[default]
    StaticUi,
    /// High-refresh scrolling or retained layer translation.
    SmoothScroll,
    /// Complex page/route transition with warmups and portal overlays.
    RouteTransition,
    /// Rich media playback, vector charts, or markdown/code canvases.
    RichMedia,
    /// Interactive 2D game scene with HUD overlay.
    Game2d,
    /// Interactive 3D game scene with HUD overlay.
    Game3d,
    /// Scene containing sparse CPU-local effects (e.g., isolated backdrop blur) over GPU primitives.
    SparseCpuEffect,
    /// Terminal PTY cell grid or CLI pipe workload.
    TerminalTui,
}

/// Explicit hardware, surface, driver, or thermal fault classification excluded from seamless-handoff success counts.
#[derive(
    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[serde(rename_all = "snake_case")]
pub enum FaultEventKind {
    /// Active GPU device or graphics context was lost; triggers immediate failover skipping perf comparison.
    #[default]
    DeviceLost,
    /// OS destroyed or invalidated the presentation surface.
    SurfaceDestroyed,
    /// Graphics driver was suspended or reset by the OS.
    DriverSuspended,
    /// OS or hardware thermal throttling reduced sustained clock/refresh headroom.
    ThermalThrottled,
}

/// Specific invariant violated when a candidate fails the visual-equivalence or capability gate.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum VisualEquivalenceFailure {
    /// Candidate is not supported on the host platform.
    BackendUnsupported,
    /// Candidate is a simulated profile lacking on-device GPU direct-present verification.
    UnverifiedSimulatedGpu,
    /// Font rasterization or shaping metrics are not equivalent.
    FontMismatch,
    /// Layout geometry or subpixel alignment is not equivalent.
    LayoutMismatch,
    /// Output color space or gamma blending is not equivalent.
    ColorSpaceMismatch,
    /// Anti-aliasing coverage quality is not equivalent.
    AntialiasingMismatch,
    /// Drop-shadow rendering is not equivalent.
    ShadowMismatch,
    /// Backdrop-blur quality or coverage is not equivalent.
    BackdropBlurMismatch,
    /// Visible tile coverage or clipping is not equivalent.
    VisibleTileMismatch,
    /// Media/image decoding or sampling quality is not equivalent.
    MediaQualityMismatch,
}

/// Lifecycle stage of a frame-boundary backend handoff managed by `HandoffCoordinator`.
#[derive(
    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[serde(rename_all = "snake_case")]
pub enum HandoffStage {
    /// No handoff in progress.
    #[default]
    Idle,
    /// Candidate backend is warming up on the exact `scene_version` using per-frame budget slices while old backend presents.
    WarmingUp,
    /// Candidate warmup completed and awaits frame-boundary first-frame verification.
    ReadyForBoundary,
    /// Frame-boundary takeover occurred; old resources remain alive pending post-handoff present confirmation and sync fence.
    AwaitingPresentConfirmation,
    /// Post-handoff present confirmed and sync fence completed; old resources released cleanly.
    Committed,
    /// Handoff aborted cleanly due to failure, mismatch, staleness, deadline miss, timeout, or fault.
    Aborted,
}

/// Explicit diagnostic reason why a frame-boundary handoff aborted and remained on the old backend.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum HandoffAbortReason {
    /// Candidate backend failed initialization.
    InitFailed,
    /// Candidate failed to produce its first frame.
    FirstFrameFailed,
    /// Candidate first-frame dimensions diverged from current viewport dimensions.
    DimensionMismatch,
    /// Candidate first-frame DPI scale factor diverged from current scale factor.
    ScaleFactorMismatch,
    /// Candidate first-frame `scene_version` became stale before boundary commit.
    StaleSceneVersion,
    /// Candidate first frame exceeded the active frame deadline.
    MissedDeadline,
    /// Candidate warmup exceeded `max_warmup_timeout_ms`.
    TimedOut,
    /// Candidate failed the visual-equivalence gate before commit.
    VisualEquivalenceFailed,
    /// An external hardware, surface, driver, or thermal fault interrupted the handoff.
    FaultInterrupted,
}

/// Runtime degradation trigger permitting a headroom-gated short candidate probe.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum ProbeTriggerReason {
    /// Sustained consecutive frame deadline misses observed.
    SustainedDeadlineMiss,
    /// Observed input-to-present latency degraded beyond the configured ratio.
    InputLatencyDegraded,
}

/// Outcome classification produced by each stage of `AdaptiveRenderRouter`.
#[derive(
    Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
)]
#[serde(rename_all = "snake_case")]
pub enum AdaptiveDecisionKind {
    /// Retain the currently active backend without changes.
    #[default]
    KeepCurrent,
    /// Startup selected a previously verified winner from `WinnerCache`.
    UseCachedWinner,
    /// Startup selected visually-equivalent `GpuDirect` as its first trial candidate.
    StartupGpuDirect,
    /// Startup candidate failed initialization or first frame; failed over immediately.
    StartupFailover,
    /// Shadow mode (`RecommendOnly`) logged a verified recommendation without live switching.
    RecommendSwitch,
    /// Live mode (`AutoSwitch`) authorized starting a seamless frame-boundary handoff.
    BeginHandoff,
    /// Seamless frame-boundary handoff committed cleanly on matching geometry and scene version.
    CommitHandoff,
    /// Handoff aborted cleanly; old backend continues presenting without interruption.
    AbortHandoff,
    /// Immediate fault failover (e.g., `DeviceLost`) retaining last valid frame when window valid.
    FaultFailover,
    /// Single-channel host locked permanently to its sole channel with probing disabled.
    LockedSingleChannel,
    /// Probe suppressed because system lacked idle time or explicit frame headroom.
    ProbeSkippedNoHeadroom,
    /// Short candidate probe authorized during idle or explicit frame headroom.
    ProbeStarted,
}