euv-core 0.48.3

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

/// Context signature binding pre-warmed route artifacts to resource version, theme, display DPR, and locale.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
pub struct PrewarmContextKey {
    /// Active application/bundle resource version.
    #[get(type(copy))]
    pub(crate) resource_version: u64,
    /// Active light or dark theme mode.
    #[get(type(copy))]
    pub(crate) theme_mode: ThemeMode,
    /// IEEE-754 bits of the active display scale factor.
    #[get(type(copy))]
    pub(crate) dpr_bits: u32,
    /// Deterministic 64-bit hash of the active BCP-47 locale (`0` when locale-agnostic).
    #[get(type(copy))]
    pub(crate) locale_hash: u64,
}

/// Bounded speculative task queued to pre-warm a target route without competing with foreground frames.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct RoutePrewarmTask {
    /// Target route identifier (e.g. `"/details/42"`).
    pub(crate) route_key: String,
    /// Pre-warm phase kind (`TextShaping`, `GlyphRaster`, `ImageDecode`, `PipelineWarmup`).
    #[get(type(copy))]
    pub(crate) kind: PrewarmWorkKind,
    /// Context key `(version, theme, DPR, locale)` this task was scheduled against.
    #[get(type(copy))]
    pub(crate) context: PrewarmContextKey,
    /// Estimated memory/upload footprint in bytes.
    #[get(type(copy))]
    pub(crate) estimated_bytes: usize,
    /// Estimated execution duration in microseconds for budgeted frame slicing.
    #[get(type(copy))]
    pub(crate) estimated_us: u64,
    /// Lower values execute earlier (`0` = highest pre-warm priority).
    #[get(type(copy))]
    pub(crate) priority: u8,
    /// Optional representative label text warmed into the font shaping cache during idle pre-warm slices.
    pub(crate) sample_text: String,
}

/// Completed route pre-warm artifact retained under bounded memory until consumed or invalidated.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct PrewarmedRouteArtifact {
    /// Target route identifier.
    pub(crate) route_key: String,
    /// Exact `(version, theme, DPR)` context key matching this artifact.
    #[get(type(copy))]
    pub(crate) context: PrewarmContextKey,
    /// Bitmask of completed `PrewarmWorkKind` phases (`1 << (kind as u8)`).
    #[get(type(copy))]
    pub(crate) completed_work_mask: u8,
    /// Aggregate tracked bytes held by this artifact.
    #[get(type(copy))]
    pub(crate) resident_bytes: usize,
    /// Number of completed pre-warm tasks folded into this artifact.
    #[get(type(copy))]
    pub(crate) prepared_items: usize,
}

/// Bounded, cancellable, context-validated route pre-warming pipeline.
#[derive(Clone, Data, Debug)]
pub struct RoutePrewarmer {
    /// Maximum pending tasks allowed in the bounded queue.
    #[get(type(copy))]
    pub(crate) max_pending_tasks: usize,
    /// Maximum aggregate resident bytes held across all ready artifacts.
    #[get(type(copy))]
    pub(crate) max_memory_bytes: usize,
    /// Maximum bytes processed/uploaded per budgeted frame slice.
    #[get(type(copy))]
    pub(crate) max_upload_bytes_per_frame: usize,
    /// Default time slice budget in microseconds per frame.
    #[get(type(copy))]
    pub(crate) default_step_budget_us: u64,
    /// Active context `(version, theme, DPR)` governing queue validity.
    #[get(type(copy))]
    pub(crate) active_context: PrewarmContextKey,
    /// Whether speculative pre-warming is enabled (paused automatically under memory pressure).
    #[get(type(copy))]
    pub(crate) enabled: bool,
    /// Bounded queue of pending pre-warm tasks ordered by priority.
    pub(crate) pending: Vec<RoutePrewarmTask>,
    /// Ready pre-warmed route artifacts awaiting consumption on navigation.
    pub(crate) ready: Vec<PrewarmedRouteArtifact>,
    /// Current aggregate resident bytes across `ready`.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) resident_bytes: usize,
    /// Cumulative accepted pre-warm tasks.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) enqueued_count: u64,
    /// Cumulative pre-warm tasks completed inside frame budgets.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) executed_tasks: u64,
    /// Cumulative pre-warm tasks cancelled via route cancellation, context drift, or memory pressure.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) cancelled_tasks: u64,
    /// Cumulative ready artifacts discarded due to version/theme/DPR invalidation or budget eviction.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) invalidated_artifacts: u64,
    /// Cumulative tasks deferred because the per-frame time or upload budget was reached.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) budget_deferrals: u64,
    /// True when recent user input or navigation preempted speculative pre-warming until the next quiet frame.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) preempted_until_idle: bool,
    /// Cumulative post-Frame-1 idle pre-warm slices executed without competing against foreground work.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) idle_slices_executed: u64,
}

/// Non-blocking cross-platform background worker handle committing computed payloads onto the UI thread without stalling frames.
#[derive(CustomDebug)]
pub struct BackgroundTask<T> {
    /// Lock-free readiness flag flipped to `true` once the background worker stores its payload.
    pub(crate) ready: Arc<AtomicBool>,
    /// Shared payload slot populated by the background worker (or synchronously on `wasm32`).
    #[debug(skip)]
    pub(crate) slot: Arc<Mutex<Option<T>>>,
}