euv_core/layout/engine/struct.rs
1use super::*;
2
3/// Deterministic cross-platform Flexbox, Grid, Block, and Positioned layout engine.
4#[derive(Clone, Data, Debug, Default)]
5pub struct LayoutEngine {
6 /// Deterministic text measurer shared with the rendering pass.
7 #[get(type(copy))]
8 pub(crate) measurer: DeterministicTextMeasurer,
9 /// Statistics captured from the most recent layout pass.
10 #[get(type(copy))]
11 pub(crate) last_stats: LayoutStats,
12 /// Cumulative layout invalidation, pass, and changed-node telemetry counters.
13 #[get(type(copy))]
14 pub(crate) telemetry: LayoutTelemetry,
15 /// Reusable flat stack storing copied child handles across recursive `layout_node` frames.
16 #[get(pub(crate))]
17 #[get_mut(pub(crate))]
18 #[set(skip)]
19 pub(crate) children_scratch: Vec<NodeId>,
20 /// Reusable flat stack storing normal-flow child handles across recursive `layout_children` frames.
21 #[get(pub(crate))]
22 #[get_mut(pub(crate))]
23 #[set(skip)]
24 pub(crate) flow_scratch: Vec<NodeId>,
25 /// Reusable flat stack storing absolute/fixed overlay child handles across recursive `layout_children` frames.
26 #[get(pub(crate))]
27 #[get_mut(pub(crate))]
28 #[set(skip)]
29 pub(crate) abs_scratch: Vec<NodeId>,
30 /// Reusable flat stack storing measured flex child records across recursive `layout_flex` frames.
31 #[get(pub(crate))]
32 #[get_mut(pub(crate))]
33 #[set(skip)]
34 pub(crate) flex_items_scratch: Vec<FlexItemRecord>,
35 /// Reusable flat stack storing contiguous `(start, end)` line slices into `flex_items_scratch`.
36 #[get(pub(crate))]
37 #[get_mut(pub(crate))]
38 #[set(skip)]
39 pub(crate) flex_lines_scratch: Vec<(usize, usize)>,
40 /// Reusable stack buffer for iterative zero-allocation subtree translations.
41 #[get(skip)]
42 #[get_mut(pub(crate))]
43 #[set(skip)]
44 pub(crate) translate_scratch: Vec<NodeId>,
45 /// Bounded 2-way set-associative interval-aware cache of measured text sizes for layout passes.
46 #[get(skip)]
47 #[get_mut(pub(crate))]
48 #[set(skip)]
49 pub(crate) text_size_cache: TextSizeCache,
50 /// Whether the active layout pass is recording pre-layout geometry snapshots for partial damage diffing.
51 #[get(skip)]
52 #[get_mut(skip)]
53 #[set(skip)]
54 pub(crate) track_damage: bool,
55 /// Active fallback trigger recorded during a tracked layout pass (`LAYOUT_FALLBACK_*`).
56 #[get(skip)]
57 #[get_mut(skip)]
58 #[set(skip)]
59 pub(crate) damage_fallback: u8,
60 /// Bounded pre-layout geometry snapshots collected during surgical partial-layout damage diffing.
61 #[get(skip)]
62 #[get_mut(skip)]
63 #[set(skip)]
64 pub(crate) layout_snapshots: Vec<LayoutNodeSnapshot>,
65 /// Flat SoA split measure/final layout cache, spatial subtree bounds, and generation-stamped dedup state.
66 #[get(skip)]
67 #[get_mut(skip)]
68 #[set(skip)]
69 pub(crate) split_cache: SplitLayoutCache,
70 /// Split cache and interval text cache diagnostics from the most recent layout pass.
71 #[get(skip)]
72 #[get_mut(skip)]
73 #[set(skip)]
74 pub(crate) last_split_stats: SplitCacheStats,
75 /// Boxed dense `Send + Sync` layout SoA mirror and level-contiguous BFS topology shared by CPU parallel and GPU compute solvers.
76 #[get(skip)]
77 #[get_mut(skip)]
78 #[set(skip)]
79 pub(crate) layout_soa: Box<SceneLayoutSoa>,
80 /// Lazily boxed lock-free parallel CPU dirty-subtree layout solver backed by `EngineWorkerPool` and SIMD micro-kernels.
81 #[get(skip)]
82 #[get_mut(skip)]
83 #[set(skip)]
84 pub(crate) parallel_solver: Option<Box<ParallelLayoutSolver>>,
85 /// Disables automatic parallel dispatch inside `compute` when `true` (default `false` enables parallel dispatch above thresholds).
86 #[get(skip)]
87 #[get_mut(skip)]
88 #[set(skip)]
89 pub(crate) parallel_disabled: bool,
90 /// `SceneTree::topology_revision` observed during the previous layout pass.
91 #[get(skip)]
92 #[get_mut(skip)]
93 #[set(skip)]
94 pub(crate) last_topology_revision: u64,
95 /// Live reachable node count observed during the previous layout pass.
96 #[get(skip)]
97 #[get_mut(skip)]
98 #[set(skip)]
99 pub(crate) last_live_node_count: usize,
100}
101
102/// Pre-layout geometry snapshot used for surgical partial-layout damage diffing.
103#[derive(Clone, Copy, Debug, Default, PartialEq)]
104pub(crate) struct LayoutNodeSnapshot {
105 /// Target scene node handle.
106 pub(crate) id: NodeId,
107 /// Pre-layout border-box rectangle in layout coordinates.
108 pub(crate) old_bounds: Rect,
109 /// Pre-layout content-box rectangle in layout coordinates.
110 pub(crate) old_content_bounds: Rect,
111 /// Pre-layout intrinsic content dimensions.
112 pub(crate) old_content_size: Size,
113 /// Whether `old_screen` holds a valid pre-layout conservative logical screen rectangle.
114 pub(crate) has_old_screen: bool,
115 /// Pre-layout conservative logical screen bounds (including shadow, border, scroll, and transform).
116 pub(crate) old_screen: Rect,
117}
118
119/// Outcome of surgical pre/post-layout conservative bounds diffing.
120#[derive(Clone, Copy, Debug, Default, PartialEq)]
121pub(crate) struct LayoutDamageReport {
122 /// Tight physical damage rectangles unioning old and new bounds of geometry-changed nodes.
123 pub(crate) damage: DamageRegion,
124 /// Fallback trigger (`LAYOUT_FALLBACK_*`) requesting full-viewport damage when non-zero.
125 pub(crate) fallback_kind: u8,
126}
127
128/// Immutable hit-test query context passed across recursive spatial traversal frames.
129#[derive(Clone, Copy)]
130pub(crate) struct HitTestQuery<'a> {
131 /// Retained scene tree being hit-tested.
132 pub(crate) tree: &'a SceneTree,
133 /// Target logical pointer coordinates in root space.
134 pub(crate) point: Point,
135 /// Whether traversal is already inside the top-layer portal pass.
136 pub(crate) in_portal_pass: bool,
137 /// Optional synced spatial layout cache providing `subtree_bounds` and `has_nonzero_z_child`.
138 pub(crate) active_cache: Option<&'a SplitLayoutCache>,
139}
140
141/// Compact z-order sort record for zero-allocation multi-child hit testing.
142#[derive(Clone, Copy, Debug, Default)]
143pub(crate) struct ZItem {
144 /// Child `LayoutStyle::z_index`.
145 pub(crate) z_index: i32,
146 /// Original child paint order index breaking z-index ties deterministically.
147 pub(crate) order: usize,
148 /// Child scene node handle.
149 pub(crate) node_id: NodeId,
150}
151
152/// Compact sort record for zero-allocation top-layer portal hit testing.
153#[derive(Clone, Copy, Debug, Default)]
154pub(crate) struct PortalZItem {
155 /// Portal `LayoutStyle::z_index`.
156 pub(crate) z_index: i32,
157 /// Top-layer portal or `Position::Fixed` node handle.
158 pub(crate) node_id: NodeId,
159}
160
161/// Thread-local reusable overflow scratch buffers used by `hit_test` only above stack thresholds.
162#[derive(Debug, Default)]
163pub(crate) struct HitTestScratch {
164 /// Flat stack of z-sorted child records when a container exceeds `HIT_TEST_STACK_Z_CAP`.
165 pub(crate) z_items: Vec<ZItem>,
166 /// Reusable buffer of active top-layer portals when exceeding `HIT_TEST_STACK_PORTAL_CAP`.
167 pub(crate) portals: Vec<PortalZItem>,
168 /// Reusable ancestor path buffer A for `tree_order_pair` when depth exceeds `HIT_TEST_STACK_PATH_CAP`.
169 pub(crate) path_a: Vec<NodeId>,
170 /// Reusable ancestor path buffer B for `tree_order_pair` when depth exceeds `HIT_TEST_STACK_PATH_CAP`.
171 pub(crate) path_b: Vec<NodeId>,
172}