Skip to main content

euv_core/font/atlas/
struct.rs

1use super::*;
2
3/// Fast 128-entry ASCII glyph slot lookup table bound to one quantized style signature.
4#[derive(Clone, Debug)]
5pub(crate) struct AsciiGlyphStyleTable {
6    /// Packed `(size_tenths | bold<<16 | monospace<<17 | italic<<18)` style signature.
7    pub(crate) style_sig: u32,
8    /// Direct slot indices into `GlyphAtlas::entries` for ASCII codepoints `0..128` (`u32::MAX` when uncached).
9    pub(crate) slots: [u32; 128],
10}
11
12/// Memoized glyph rasterization cache shared across frames with O(1) slot indexing, ASCII direct tables, bounded LRU budget, and hit/miss telemetry.
13#[derive(Clone, Data, Debug, Default)]
14pub struct GlyphAtlas {
15    /// Open-addressed power-of-two lookup table packing `(slot << 40) | packed_key` (`u64::MAX` when empty).
16    #[get(pub(crate))]
17    #[get_mut(pub(crate))]
18    #[set(pub(crate))]
19    pub(crate) glyph_index: Vec<u64>,
20    /// Contiguous flat arena of `(GlyphKey, RasterizedGlyph)` pairs indexed directly by `u32` slot.
21    #[get(pub(crate))]
22    #[get_mut(pub(crate))]
23    #[set(pub(crate))]
24    pub(crate) entries: Vec<(GlyphKey, RasterizedGlyph)>,
25    /// Per-entry monotonic access ticks aligned 1:1 with `entries` for bounded LRU eviction.
26    #[get(skip)]
27    #[get_mut(skip)]
28    #[set(skip)]
29    pub(crate) entry_last_used: Vec<u64>,
30    /// Compact per-style `[u32; 128]` ASCII lookup tables eliminating hash probes on ASCII text runs.
31    #[get(pub(crate))]
32    #[get_mut(pub(crate))]
33    #[set(pub(crate))]
34    pub(crate) ascii_tables: Vec<AsciiGlyphStyleTable>,
35    /// Monotonic counter incremented when new glyphs are inserted or evicted for GPU texture sync.
36    #[get(type(copy))]
37    #[get_mut(pub(crate))]
38    #[set(pub(crate))]
39    pub(crate) revision: u64,
40    /// Configured resident memory budget in bytes (`0` selects `GLYPH_ATLAS_DEFAULT_BUDGET_BYTES`).
41    #[get(type(copy))]
42    #[get_mut(skip)]
43    #[set(pub(crate))]
44    pub(crate) budget_bytes: usize,
45    /// Current resident memory usage in bytes across all cached glyph bitmaps and metadata.
46    #[get(type(copy))]
47    #[get_mut(skip)]
48    #[set(skip)]
49    pub(crate) resident_bytes: usize,
50    /// Monotonic logical clock incremented on cache accesses for LRU ordering.
51    #[get(skip)]
52    #[get_mut(skip)]
53    #[set(skip)]
54    pub(crate) lru_clock: u64,
55    /// Cumulative number of cache hits served without rasterizing.
56    #[get(type(copy))]
57    #[get_mut(skip)]
58    #[set(skip)]
59    pub(crate) cache_hits: u64,
60    /// Cumulative number of cache misses requiring rasterization.
61    #[get(type(copy))]
62    #[get_mut(skip)]
63    #[set(skip)]
64    pub(crate) cache_misses: u64,
65    /// Cumulative number of cold glyphs evicted to stay within `budget_bytes`.
66    #[get(type(copy))]
67    #[get_mut(skip)]
68    #[set(skip)]
69    pub(crate) evictions: u64,
70    /// Guard pinning arena slot indices for the duration of a single frame's `prepare_frame_range`.
71    #[get(pub(crate), type(copy))]
72    #[get_mut(skip)]
73    #[set(pub(crate))]
74    pub(crate) slots_pinned: bool,
75    /// Active DPI scale IEEE-754 bits bound to currently rasterized atlas bitmaps (`0` before first bind).
76    #[get(type(copy))]
77    #[get_mut(skip)]
78    #[set(skip)]
79    pub(crate) active_dpi_scale_bits: u32,
80    /// Active anti-aliasing policy bound to currently rasterized atlas bitmaps.
81    #[get(type(copy))]
82    #[get_mut(skip)]
83    #[set(skip)]
84    pub(crate) active_aa_mode: AntialiasingMode,
85    /// Active font fallback chain revision bound to currently rasterized atlas bitmaps.
86    #[get(type(copy))]
87    #[get_mut(skip)]
88    #[set(skip)]
89    pub(crate) font_chain_revision: u64,
90    /// Current in-flight GPU submission fence tagged onto touched glyph entries.
91    #[get(type(copy))]
92    #[get_mut(skip)]
93    #[set(skip)]
94    pub(crate) active_fence_id: u64,
95    /// Highest GPU submission fence known to have completed on the device.
96    #[get(type(copy))]
97    #[get_mut(skip)]
98    #[set(skip)]
99    pub(crate) completed_fence_id: u64,
100    /// Per-entry last-referenced GPU fence identifier aligned 1:1 with `entries` for fence-deferred reclamation.
101    #[get(skip)]
102    #[get_mut(skip)]
103    #[set(skip)]
104    pub(crate) entry_fence_ids: Vec<u64>,
105    /// Evicted glyph bitmap allocations waiting for `(retire_fence_id, byte_size)` GPU fence completion.
106    #[get(skip)]
107    #[get_mut(skip)]
108    #[set(skip)]
109    pub(crate) pending_reclaim: Vec<(u64, usize)>,
110    /// Aggregate bytes currently awaiting GPU fence completion before final release.
111    #[get(type(copy))]
112    #[get_mut(skip)]
113    #[set(skip)]
114    pub(crate) pending_reclaim_bytes: usize,
115    /// Cumulative count of evicted glyph allocations reclaimed after GPU fence completion.
116    #[get(type(copy))]
117    #[get_mut(skip)]
118    #[set(skip)]
119    pub(crate) reclaimed_entries: u64,
120}