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 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}
66
67/// Pre-layout geometry snapshot used for surgical partial-layout damage diffing.
68#[derive(Clone, Copy, Debug, Default, PartialEq)]
69pub(crate) struct LayoutNodeSnapshot {
70    /// Target scene node handle.
71    pub(crate) id: NodeId,
72    /// Pre-layout border-box rectangle in layout coordinates.
73    pub(crate) old_bounds: Rect,
74    /// Pre-layout content-box rectangle in layout coordinates.
75    pub(crate) old_content_bounds: Rect,
76    /// Pre-layout intrinsic content dimensions.
77    pub(crate) old_content_size: Size,
78    /// Whether `old_screen` holds a valid pre-layout conservative logical screen rectangle.
79    pub(crate) has_old_screen: bool,
80    /// Pre-layout conservative logical screen bounds (including shadow, border, scroll, and transform).
81    pub(crate) old_screen: Rect,
82}
83
84/// Outcome of surgical pre/post-layout conservative bounds diffing.
85#[derive(Clone, Copy, Debug, Default, PartialEq)]
86pub(crate) struct LayoutDamageReport {
87    /// Tight physical damage rectangles unioning old and new bounds of geometry-changed nodes.
88    pub(crate) damage: DamageRegion,
89    /// Fallback trigger (`LAYOUT_FALLBACK_*`) requesting full-viewport damage when non-zero.
90    pub(crate) fallback_kind: u8,
91}