euv-core 0.52.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::*;

/// Fast 128-entry ASCII glyph slot lookup table bound to one quantized style signature.
#[derive(Clone, Debug)]
pub(crate) struct AsciiGlyphStyleTable {
    /// Packed `(size_tenths | bold<<16 | monospace<<17 | italic<<18)` style signature.
    pub(crate) style_sig: u32,
    /// Direct slot indices into `GlyphAtlas::entries` for ASCII codepoints `0..128` (`u32::MAX` when uncached).
    pub(crate) slots: [u32; 128],
}

/// Intermediate shelf placement record for one glyph prior to multi-page RGBA8 raster blitting.
pub(crate) struct RawGlyphPageItem {
    /// Index into `GlyphAtlas::entries`.
    pub(crate) entry_idx: usize,
    /// Horizontal pixel offset inside the target page.
    pub(crate) x: u32,
    /// Vertical pixel offset inside the target page.
    pub(crate) y: u32,
    /// Clamped glyph width in pixels.
    pub(crate) width: u32,
    /// Clamped glyph height in pixels.
    pub(crate) height: u32,
}

/// Intermediate shelf-packed page bucket collected prior to LRU eviction and RGBA8 allocation.
pub(crate) struct RawGlyphPageBucket {
    /// Packed page width in pixels.
    pub(crate) width: u32,
    /// Packed page height in pixels.
    pub(crate) height: u32,
    /// Highest LRU access tick among glyphs assigned to this page.
    pub(crate) last_used_tick: u64,
    /// Glyph placements belonging to this page.
    pub(crate) items: Vec<RawGlyphPageItem>,
}

/// Retained CPU glyph bitmap snapshot for one recent DPI scale enabling zero-thrash hysteresis across multi-monitor drags.
#[derive(Clone, Debug)]
pub(crate) struct DpiAtlasSnapshot {
    /// IEEE-754 bits of the DPI scale factor bound to these rasterized bitmaps.
    pub(crate) dpi_scale_bits: u32,
    /// Anti-aliasing policy bound to these rasterized bitmaps.
    pub(crate) aa_mode: AntialiasingMode,
    /// Font fallback chain revision bound to these rasterized bitmaps.
    pub(crate) font_chain_revision: u64,
    /// Saved `(GlyphKey, RasterizedGlyph)` entries for exact-DPI instant restore.
    pub(crate) entries: Vec<(GlyphKey, RasterizedGlyph)>,
    /// Saved per-entry LRU timestamps aligned 1:1 with `entries`.
    pub(crate) entry_last_used: Vec<u64>,
    /// Total resident byte footprint of `entries`.
    pub(crate) resident_bytes: usize,
    /// Monotonic LRU clock value when this DPI snapshot was stashed.
    pub(crate) stashed_tick: u64,
}

/// Multi-page atlas UV placement assigning a cached `GlyphKey` to one bounded texture page and pixel rectangle.
#[derive(Clone, Copy, Debug, Default, Eq, Getter, New, PartialEq)]
pub struct GlyphPagePlacement {
    /// Zero-based index of the owning `GlyphAtlasPage`.
    #[get(type(copy))]
    pub(crate) page_index: u32,
    /// Horizontal pixel offset inside the owning page texture.
    #[get(type(copy))]
    pub(crate) x: u32,
    /// Vertical pixel offset inside the owning page texture.
    #[get(type(copy))]
    pub(crate) y: u32,
    /// Packed glyph width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Packed glyph height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
}

/// Single shelf-packed RGBA8 glyph texture page strictly bounded by `<= min(max_texture_dim, 2048)` per axis.
#[derive(Clone, Debug, Default, Getter, New)]
pub struct GlyphAtlasPage {
    /// Zero-based sequential page identifier inside `PackedMultiPageGlyphAtlas`.
    #[get(type(copy))]
    pub(crate) page_index: u32,
    /// Page texture width in physical pixels (`<= page_dim_limit`).
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Page texture height in physical pixels (`<= page_dim_limit`).
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Packed RGBA8 pixel data (white RGB with glyph alpha coverage).
    pub(crate) pixels: Vec<u8>,
    /// Number of glyph bitmaps packed onto this page.
    #[get(type(copy))]
    pub(crate) glyph_count: usize,
    /// Highest LRU access tick among glyphs resident on this page for LRU page eviction.
    #[get(type(copy))]
    pub(crate) last_used_tick: u64,
}

/// Multi-page shelf-packed RGBA8 glyph texture atlas enforcing per-page GPU texture bounds and LRU page eviction.
#[derive(Clone, Debug, Default, Getter, New)]
pub struct PackedMultiPageGlyphAtlas {
    /// Effective maximum per-page width and height in pixels enforced across all pages.
    #[get(type(copy))]
    pub(crate) page_dim_limit: u32,
    /// Resident shelf-packed RGBA8 texture pages strictly within `page_dim_limit x page_dim_limit`.
    pub(crate) pages: Vec<GlyphAtlasPage>,
    /// Per-glyph page index and pixel UV rectangles for every retained glyph.
    pub(crate) placements: HashMap<GlyphKey, GlyphPagePlacement>,
    /// Source `GlyphAtlas` revision number captured at pack time.
    #[get(type(copy))]
    pub(crate) revision: u64,
    /// Number of coldest pages evicted during packing to stay within the configured page cap.
    #[get(type(copy))]
    pub(crate) evicted_pages: u64,
}

/// Memoized glyph rasterization cache shared across frames with O(1) slot indexing, ASCII direct tables, bounded LRU budget, and hit/miss telemetry.
#[derive(Clone, Data, Debug, Default)]
pub struct GlyphAtlas {
    /// Open-addressed power-of-two lookup table packing `(slot << 40) | packed_key` (`u64::MAX` when empty).
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) glyph_index: Vec<u64>,
    /// Contiguous flat arena of `(GlyphKey, RasterizedGlyph)` pairs indexed directly by `u32` slot.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) entries: Vec<(GlyphKey, RasterizedGlyph)>,
    /// Per-entry monotonic access ticks aligned 1:1 with `entries` for bounded LRU eviction.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) entry_last_used: Vec<u64>,
    /// Compact per-style `[u32; 128]` ASCII lookup tables eliminating hash probes on ASCII text runs.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) ascii_tables: Vec<AsciiGlyphStyleTable>,
    /// Most recently matched ASCII style signature for 1-branch hot-run table lookup.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) last_ascii_style_sig: u32,
    /// Table index inside `ascii_tables` corresponding to `last_ascii_style_sig`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) last_ascii_table_idx: usize,
    /// Monotonic counter incremented when new glyphs are inserted or evicted for GPU texture sync.
    #[get(type(copy))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) revision: u64,
    /// Configured resident memory budget in bytes (`0` selects `GLYPH_ATLAS_DEFAULT_BUDGET_BYTES`).
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(pub(crate))]
    pub(crate) budget_bytes: usize,
    /// Current resident memory usage in bytes across all cached glyph bitmaps and metadata.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) resident_bytes: usize,
    /// Monotonic logical clock incremented on cache accesses for LRU ordering.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) lru_clock: u64,
    /// Cumulative number of cache hits served without rasterizing.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) cache_hits: u64,
    /// Cumulative number of cache misses requiring rasterization.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) cache_misses: u64,
    /// Cumulative number of cold glyphs evicted to stay within `budget_bytes`.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) evictions: u64,
    /// Guard pinning arena slot indices for the duration of a single frame's `prepare_frame_range`.
    #[get(pub(crate), type(copy))]
    #[get_mut(skip)]
    #[set(pub(crate))]
    pub(crate) slots_pinned: bool,
    /// Active DPI scale IEEE-754 bits bound to currently rasterized atlas bitmaps (`0` before first bind).
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) active_dpi_scale_bits: u32,
    /// Active anti-aliasing policy bound to currently rasterized atlas bitmaps.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) active_aa_mode: AntialiasingMode,
    /// Active font fallback chain revision bound to currently rasterized atlas bitmaps.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) font_chain_revision: u64,
    /// Current in-flight GPU submission fence tagged onto touched glyph entries.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) active_fence_id: u64,
    /// Highest GPU submission fence known to have completed on the device.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) completed_fence_id: u64,
    /// Per-entry last-referenced GPU fence identifier aligned 1:1 with `entries` for fence-deferred reclamation.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) entry_fence_ids: Vec<u64>,
    /// Evicted glyph bitmap allocations waiting for `(retire_fence_id, byte_size)` GPU fence completion.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) pending_reclaim: Vec<(u64, usize)>,
    /// Aggregate bytes currently awaiting GPU fence completion before final release.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) pending_reclaim_bytes: usize,
    /// Cumulative count of evicted glyph allocations reclaimed after GPU fence completion.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) reclaimed_entries: u64,
    /// Bounded 2-slot recent-DPI hysteresis snapshots preventing rasterization thrash across multi-DPI monitors.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) recent_dpi_slots: Vec<DpiAtlasSnapshot>,
    /// Cumulative number of exact-DPI restores served from `recent_dpi_slots` without OS re-rasterization.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) dpi_hysteresis_restores: u64,
}