Skip to main content

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}
76
77/// Pre-layout geometry snapshot used for surgical partial-layout damage diffing.
78#[derive(Clone, Copy, Debug, Default, PartialEq)]
79pub(crate) struct LayoutNodeSnapshot {
80    /// Target scene node handle.
81    pub(crate) id: NodeId,
82    /// Pre-layout border-box rectangle in layout coordinates.
83    pub(crate) old_bounds: Rect,
84    /// Pre-layout content-box rectangle in layout coordinates.
85    pub(crate) old_content_bounds: Rect,
86    /// Pre-layout intrinsic content dimensions.
87    pub(crate) old_content_size: Size,
88    /// Whether `old_screen` holds a valid pre-layout conservative logical screen rectangle.
89    pub(crate) has_old_screen: bool,
90    /// Pre-layout conservative logical screen bounds (including shadow, border, scroll, and transform).
91    pub(crate) old_screen: Rect,
92}
93
94/// Outcome of surgical pre/post-layout conservative bounds diffing.
95#[derive(Clone, Copy, Debug, Default, PartialEq)]
96pub(crate) struct LayoutDamageReport {
97    /// Tight physical damage rectangles unioning old and new bounds of geometry-changed nodes.
98    pub(crate) damage: DamageRegion,
99    /// Fallback trigger (`LAYOUT_FALLBACK_*`) requesting full-viewport damage when non-zero.
100    pub(crate) fallback_kind: u8,
101}
102
103/// Immutable hit-test query context passed across recursive spatial traversal frames.
104#[derive(Clone, Copy)]
105pub(crate) struct HitTestQuery<'a> {
106    /// Retained scene tree being hit-tested.
107    pub(crate) tree: &'a SceneTree,
108    /// Target logical pointer coordinates in root space.
109    pub(crate) point: Point,
110    /// Whether traversal is already inside the top-layer portal pass.
111    pub(crate) in_portal_pass: bool,
112    /// Optional synced spatial layout cache providing `subtree_bounds` and `has_nonzero_z_child`.
113    pub(crate) active_cache: Option<&'a SplitLayoutCache>,
114}
115
116/// Compact z-order sort record for zero-allocation multi-child hit testing.
117#[derive(Clone, Copy, Debug, Default)]
118pub(crate) struct ZItem {
119    /// Child `LayoutStyle::z_index`.
120    pub(crate) z_index: i32,
121    /// Original child paint order index breaking z-index ties deterministically.
122    pub(crate) order: usize,
123    /// Child scene node handle.
124    pub(crate) node_id: NodeId,
125}
126
127/// Compact sort record for zero-allocation top-layer portal hit testing.
128#[derive(Clone, Copy, Debug, Default)]
129pub(crate) struct PortalZItem {
130    /// Portal `LayoutStyle::z_index`.
131    pub(crate) z_index: i32,
132    /// Top-layer portal or `Position::Fixed` node handle.
133    pub(crate) node_id: NodeId,
134}
135
136/// Thread-local reusable overflow scratch buffers used by `hit_test` only above stack thresholds.
137#[derive(Debug, Default)]
138pub(crate) struct HitTestScratch {
139    /// Flat stack of z-sorted child records when a container exceeds `HIT_TEST_STACK_Z_CAP`.
140    pub(crate) z_items: Vec<ZItem>,
141    /// Reusable buffer of active top-layer portals when exceeding `HIT_TEST_STACK_PORTAL_CAP`.
142    pub(crate) portals: Vec<PortalZItem>,
143    /// Reusable ancestor path buffer A for `tree_order_pair` when depth exceeds `HIT_TEST_STACK_PATH_CAP`.
144    pub(crate) path_a: Vec<NodeId>,
145    /// Reusable ancestor path buffer B for `tree_order_pair` when depth exceeds `HIT_TEST_STACK_PATH_CAP`.
146    pub(crate) path_b: Vec<NodeId>,
147}