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

/// DPI- and wrap-width-independent lookup key identifying shaped glyph advances for a text run.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
pub struct TextShapingKey {
    /// Primary 64-bit hash of the source UTF-8 text bytes.
    #[get(type(copy))]
    pub(crate) text_hash_a: u64,
    /// Secondary 64-bit hash of the source UTF-8 text bytes.
    #[get(type(copy))]
    pub(crate) text_hash_b: u64,
    /// Byte length of the source text string.
    #[get(type(copy))]
    pub(crate) text_len: u32,
    /// IEEE-754 bits of the logical font size.
    #[get(type(copy))]
    pub(crate) font_size_bits: u32,
    /// Logical font family classification.
    #[get(type(copy))]
    pub(crate) family: FontFamily,
    /// Logical font weight classification.
    #[get(type(copy))]
    pub(crate) weight: FontWeight,
    /// Whether italic styling is enabled.
    #[get(type(copy))]
    pub(crate) italic: bool,
    /// IEEE-754 bits of additional logical letter spacing.
    #[get(type(copy))]
    pub(crate) letter_spacing_bits: u32,
    /// Hash of the active BCP-47 locale string.
    #[get(type(copy))]
    pub(crate) locale_hash: u64,
    /// Whether right-to-left base direction is active.
    #[get(type(copy))]
    pub(crate) rtl: bool,
    /// Active font fallback chain revision invalidating shaping when system fonts change.
    #[get(type(copy))]
    pub(crate) font_chain_revision: u64,
}

/// DPI- and color-independent lookup key identifying wrapped lines derived from a shaped run.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
pub struct LineBreakKey {
    /// Primary 64-bit shaping key hash.
    #[get(type(copy))]
    pub(crate) shaping_hash_a: u64,
    /// Secondary 64-bit shaping key hash.
    #[get(type(copy))]
    pub(crate) shaping_hash_b: u64,
    /// IEEE-754 bits of optional wrap width (`u32::MAX` when unbounded).
    #[get(type(copy))]
    pub(crate) max_width_bits: u32,
    /// IEEE-754 bits of line-height multiplier.
    #[get(type(copy))]
    pub(crate) line_height_bits: u32,
    /// Overflow policy (`Wrap`, `Ellipsis`, `Clip`).
    #[get(type(copy))]
    pub(crate) overflow: TextOverflow,
    /// Active font fallback chain revision matching the underlying shaped run.
    #[get(type(copy))]
    pub(crate) font_chain_revision: u64,
}

/// Cached logical glyph-advance shaping result independent of DPI scale and raster bitmap atlas.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct ShapedGlyphRun {
    /// Logical advance width for each shaped character cluster.
    pub(crate) cluster_advances: Vec<f32>,
    /// Total unwrapped logical advance width of the run.
    #[get(type(copy))]
    pub(crate) total_width: f32,
    /// Number of shaped character clusters.
    #[get(type(copy))]
    pub(crate) cluster_count: usize,
    /// Tracked resident byte footprint of this entry.
    #[get(type(copy))]
    pub(crate) byte_size: usize,
    /// Monotonic LRU access tick.
    #[get(type(copy))]
    pub(crate) last_used_tick: u64,
}

/// Typed intrusive LRU slot storing a cached `ShapedGlyphRun` and its exact key.
#[derive(Clone, Debug, Default, PartialEq)]
pub(crate) struct ShapingRunSlot {
    /// Whether this slot currently holds a live entry (`false` when on `shape_free_slots`).
    pub(crate) occupied: bool,
    /// Precomputed 64-bit FxHash of `key` for O(1) eviction and rehash.
    pub(crate) hash: u64,
    /// Exact shaping lookup key verified after 31-bit tag match.
    pub(crate) key: TextShapingKey,
    /// Cached shaped glyph run payload.
    pub(crate) run: ShapedGlyphRun,
    /// Tagged handle of the more-recently-used neighbor (`SHAPING_NODE_NONE` at head).
    pub(crate) prev: u32,
    /// Tagged handle of the less-recently-used neighbor (`SHAPING_NODE_NONE` at tail).
    pub(crate) next: u32,
}

/// Typed intrusive LRU slot storing a cached wrapped `TextLayoutResult` and its exact key.
#[derive(Clone, Debug, Default, PartialEq)]
pub(crate) struct LineBreakSlot {
    /// Whether this slot currently holds a live entry (`false` when on `line_break_free_slots`).
    pub(crate) occupied: bool,
    /// Precomputed 64-bit FxHash of `key` for O(1) eviction and rehash.
    pub(crate) hash: u64,
    /// Tracked resident byte footprint of this wrapped layout entry.
    pub(crate) byte_size: usize,
    /// Exact line-break lookup key verified after 31-bit tag match.
    pub(crate) key: LineBreakKey,
    /// Cached wrapped text layout result.
    pub(crate) layout: TextLayoutResult,
    /// Tagged handle of the more-recently-used neighbor (`SHAPING_NODE_NONE` at head).
    pub(crate) prev: u32,
    /// Tagged handle of the less-recently-used neighbor (`SHAPING_NODE_NONE` at tail).
    pub(crate) next: u32,
}

/// Bounded DPI-independent single-probe FxHash text shaping and line-break cache with O(1) intrusive LRU eviction.
#[derive(Clone, Data, Debug)]
pub struct TextShapingCache {
    /// Configured aggregate memory budget in bytes across shaping runs and wrapped line layouts.
    #[get(type(copy))]
    pub(crate) budget_bytes: usize,
    /// Current resident bytes tracked across shaping runs and wrapped line layouts.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) resident_bytes: usize,
    /// Active font fallback chain revision; bumping it invalidates shaping without touching unrelated caches.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) font_chain_revision: u64,
    /// Monotonic logical LRU access clock.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) lru_clock: u64,
    /// Open-addressed power-of-two shaping lookup table packing `(hash_tag_31 << 32) | slot_idx`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) shape_index: Vec<u64>,
    /// Open-addressed power-of-two line-break lookup table packing `(hash_tag_31 << 32) | slot_idx`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) line_break_index: Vec<u64>,
    /// Contiguous flat arena of shaped glyph run slots.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) shape_slots: Vec<ShapingRunSlot>,
    /// Contiguous flat arena of wrapped line-break slots.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) line_break_slots: Vec<LineBreakSlot>,
    /// Recycled shaping slot indices for zero-allocation O(1) reuse.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) shape_free_slots: Vec<u32>,
    /// Recycled line-break slot indices for zero-allocation O(1) reuse.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) line_break_free_slots: Vec<u32>,
    /// Tagged handle of the most-recently-used entry (`SHAPING_NODE_NONE` when empty).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) lru_head: u32,
    /// Tagged handle of the least-recently-used eviction victim (`SHAPING_NODE_NONE` when empty).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) lru_tail: u32,
    /// Active live entry count in `shape_slots`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) shape_count: usize,
    /// Active live entry count in `line_break_slots`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) line_break_count: usize,
    /// Live plus tombstone slot count in `shape_index` governing load-factor rehash triggers.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) shape_occupied: usize,
    /// Live plus tombstone slot count in `line_break_index` governing load-factor rehash triggers.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) line_break_occupied: usize,
    /// Cumulative shaping cache hits.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) shaping_hits: u64,
    /// Cumulative shaping cache misses.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) shaping_misses: u64,
    /// Cumulative line-break cache hits.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) line_break_hits: u64,
    /// Cumulative line-break cache misses.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) line_break_misses: u64,
    /// Cumulative cold entries evicted to stay within `budget_bytes`.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) evictions: u64,
}