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

/// 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,
}

/// Cached wrapped line-break entry stored independently of GPU/CPU glyph bitmap atlas residency.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub(crate) struct CachedLineBreakEntry {
    /// Wrapped line metrics and sliced line strings.
    pub(crate) layout: TextLayoutResult,
    /// 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,
}

/// Candidate eviction descriptor pairing LRU tick, table tag, and key for `TextShapingCache`.
#[derive(Clone, Copy, Debug)]
pub(crate) struct ShapingEvictVictim {
    /// Monotonic last-used tick governing LRU eviction order.
    pub(crate) last_used_tick: u64,
    /// True when this candidate belongs to `shaped_runs`, false for `line_breaks`.
    pub(crate) is_shape: bool,
    /// Shaping table key when `is_shape` is `true`.
    pub(crate) shape_key: TextShapingKey,
    /// Line-break table key when `is_shape` is `false`.
    pub(crate) line_break_key: LineBreakKey,
    /// Tracked resident byte footprint of this candidate.
    pub(crate) byte_size: usize,
}

/// Bounded DPI-independent text shaping and line-break cache split cleanly from the bitmap `GlyphAtlas`.
#[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,
    /// Cached shaping runs keyed by `TextShapingKey`.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) shaped_runs: HashMap<TextShapingKey, ShapedGlyphRun>,
    /// Cached wrapped line-break results keyed by `LineBreakKey`.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) line_breaks: HashMap<LineBreakKey, CachedLineBreakEntry>,
    /// 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,
}