euv_core/font/shaping/struct.rs
1use super::*;
2
3/// DPI- and wrap-width-independent lookup key identifying shaped glyph advances for a text run.
4#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
5pub struct TextShapingKey {
6 /// Primary 64-bit hash of the source UTF-8 text bytes.
7 #[get(type(copy))]
8 pub(crate) text_hash_a: u64,
9 /// Secondary 64-bit hash of the source UTF-8 text bytes.
10 #[get(type(copy))]
11 pub(crate) text_hash_b: u64,
12 /// Byte length of the source text string.
13 #[get(type(copy))]
14 pub(crate) text_len: u32,
15 /// IEEE-754 bits of the logical font size.
16 #[get(type(copy))]
17 pub(crate) font_size_bits: u32,
18 /// Logical font family classification.
19 #[get(type(copy))]
20 pub(crate) family: FontFamily,
21 /// Logical font weight classification.
22 #[get(type(copy))]
23 pub(crate) weight: FontWeight,
24 /// Whether italic styling is enabled.
25 #[get(type(copy))]
26 pub(crate) italic: bool,
27 /// IEEE-754 bits of additional logical letter spacing.
28 #[get(type(copy))]
29 pub(crate) letter_spacing_bits: u32,
30 /// Hash of the active BCP-47 locale string.
31 #[get(type(copy))]
32 pub(crate) locale_hash: u64,
33 /// Whether right-to-left base direction is active.
34 #[get(type(copy))]
35 pub(crate) rtl: bool,
36 /// Active font fallback chain revision invalidating shaping when system fonts change.
37 #[get(type(copy))]
38 pub(crate) font_chain_revision: u64,
39}
40
41/// DPI- and color-independent lookup key identifying wrapped lines derived from a shaped run.
42#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
43pub struct LineBreakKey {
44 /// Primary 64-bit shaping key hash.
45 #[get(type(copy))]
46 pub(crate) shaping_hash_a: u64,
47 /// Secondary 64-bit shaping key hash.
48 #[get(type(copy))]
49 pub(crate) shaping_hash_b: u64,
50 /// IEEE-754 bits of optional wrap width (`u32::MAX` when unbounded).
51 #[get(type(copy))]
52 pub(crate) max_width_bits: u32,
53 /// IEEE-754 bits of line-height multiplier.
54 #[get(type(copy))]
55 pub(crate) line_height_bits: u32,
56 /// Overflow policy (`Wrap`, `Ellipsis`, `Clip`).
57 #[get(type(copy))]
58 pub(crate) overflow: TextOverflow,
59 /// Active font fallback chain revision matching the underlying shaped run.
60 #[get(type(copy))]
61 pub(crate) font_chain_revision: u64,
62}
63
64/// Cached logical glyph-advance shaping result independent of DPI scale and raster bitmap atlas.
65#[derive(Clone, Data, Debug, Default, PartialEq)]
66pub struct ShapedGlyphRun {
67 /// Logical advance width for each shaped character cluster.
68 pub(crate) cluster_advances: Vec<f32>,
69 /// Total unwrapped logical advance width of the run.
70 #[get(type(copy))]
71 pub(crate) total_width: f32,
72 /// Number of shaped character clusters.
73 #[get(type(copy))]
74 pub(crate) cluster_count: usize,
75 /// Tracked resident byte footprint of this entry.
76 #[get(type(copy))]
77 pub(crate) byte_size: usize,
78 /// Monotonic LRU access tick.
79 #[get(type(copy))]
80 pub(crate) last_used_tick: u64,
81}
82
83/// Cached wrapped line-break entry stored independently of GPU/CPU glyph bitmap atlas residency.
84#[derive(Clone, Data, Debug, Default, PartialEq)]
85pub(crate) struct CachedLineBreakEntry {
86 /// Wrapped line metrics and sliced line strings.
87 pub(crate) layout: TextLayoutResult,
88 /// Tracked resident byte footprint of this entry.
89 #[get(type(copy))]
90 pub(crate) byte_size: usize,
91 /// Monotonic LRU access tick.
92 #[get(type(copy))]
93 pub(crate) last_used_tick: u64,
94}
95
96/// Candidate eviction descriptor pairing LRU tick, table tag, and key for `TextShapingCache`.
97#[derive(Clone, Copy, Debug)]
98pub(crate) struct ShapingEvictVictim {
99 /// Monotonic last-used tick governing LRU eviction order.
100 pub(crate) last_used_tick: u64,
101 /// True when this candidate belongs to `shaped_runs`, false for `line_breaks`.
102 pub(crate) is_shape: bool,
103 /// Shaping table key when `is_shape` is `true`.
104 pub(crate) shape_key: TextShapingKey,
105 /// Line-break table key when `is_shape` is `false`.
106 pub(crate) line_break_key: LineBreakKey,
107 /// Tracked resident byte footprint of this candidate.
108 pub(crate) byte_size: usize,
109}
110
111/// Bounded DPI-independent text shaping and line-break cache split cleanly from the bitmap `GlyphAtlas`.
112#[derive(Clone, Data, Debug)]
113pub struct TextShapingCache {
114 /// Configured aggregate memory budget in bytes across shaping runs and wrapped line layouts.
115 #[get(type(copy))]
116 pub(crate) budget_bytes: usize,
117 /// Current resident bytes tracked across shaping runs and wrapped line layouts.
118 #[get(type(copy))]
119 #[get_mut(skip)]
120 #[set(skip)]
121 pub(crate) resident_bytes: usize,
122 /// Active font fallback chain revision; bumping it invalidates shaping without touching unrelated caches.
123 #[get(type(copy))]
124 #[get_mut(skip)]
125 #[set(skip)]
126 pub(crate) font_chain_revision: u64,
127 /// Monotonic logical LRU access clock.
128 #[get(skip)]
129 #[get_mut(skip)]
130 #[set(skip)]
131 pub(crate) lru_clock: u64,
132 /// Cached shaping runs keyed by `TextShapingKey`.
133 #[get(pub(crate))]
134 #[get_mut(pub(crate))]
135 #[set(skip)]
136 pub(crate) shaped_runs: HashMap<TextShapingKey, ShapedGlyphRun>,
137 /// Cached wrapped line-break results keyed by `LineBreakKey`.
138 #[get(pub(crate))]
139 #[get_mut(pub(crate))]
140 #[set(skip)]
141 pub(crate) line_breaks: HashMap<LineBreakKey, CachedLineBreakEntry>,
142 /// Cumulative shaping cache hits.
143 #[get(type(copy))]
144 #[get_mut(skip)]
145 #[set(skip)]
146 pub(crate) shaping_hits: u64,
147 /// Cumulative shaping cache misses.
148 #[get(type(copy))]
149 #[get_mut(skip)]
150 #[set(skip)]
151 pub(crate) shaping_misses: u64,
152 /// Cumulative line-break cache hits.
153 #[get(type(copy))]
154 #[get_mut(skip)]
155 #[set(skip)]
156 pub(crate) line_break_hits: u64,
157 /// Cumulative line-break cache misses.
158 #[get(type(copy))]
159 #[get_mut(skip)]
160 #[set(skip)]
161 pub(crate) line_break_misses: u64,
162 /// Cumulative cold entries evicted to stay within `budget_bytes`.
163 #[get(type(copy))]
164 #[get_mut(skip)]
165 #[set(skip)]
166 pub(crate) evictions: u64,
167}