euv_core/render/command/struct.rs
1use super::*;
2
3/// Persistent per-frame scratch and string-recycling arena retained inside `DisplayList` for zero-alloc steady-state frames.
4#[derive(Debug)]
5pub(crate) struct DisplayListFrameArena {
6 /// Recycled `String` backing buffers reused for `DrawCommand::TextRun` and `DrawCommand::TextCaret`.
7 pub(crate) string_pool: Vec<String>,
8 /// Persistent scratch queue collecting deferred top-layer portal/fixed nodes across frames.
9 pub(crate) portals_scratch: Vec<(i32, usize, NodeId)>,
10 /// Persistent stack-allocated scratch buffer for nested z-index child sorting across frames.
11 pub(crate) z_sort_scratch: Vec<(i32, usize, NodeId)>,
12 /// Persistent scratch buffer of ancestor handles leading to live `Portal` / `Position::Fixed` nodes across frames.
13 pub(crate) portal_ancestors_scratch: Vec<NodeId>,
14 /// Monotonic version counter bumped only when the base scene slice `[0..portal_split_index]` changes.
15 pub(crate) base_layer_version: u64,
16 /// Previous frame's streaming digest over the base scene slice for O(1) portal backdrop cache matching.
17 pub(crate) prev_base_digest: u64,
18 /// Current frame's incrementally folded digest over the base scene slice.
19 pub(crate) cur_base_digest: u64,
20 /// Current frame's incrementally folded fast digest over all emitted commands.
21 pub(crate) running_fast_hash: u64,
22 /// True once `portal_split_index` has been finalized for the current frame.
23 pub(crate) base_layer_finalized: bool,
24}
25
26/// Reusable backend-agnostic command buffer emitted once per frame for Software, Hardware, or Hybrid execution.
27#[derive(Clone, Data, Debug, Default, PartialEq)]
28pub struct DisplayList {
29 /// Ordered drawing commands.
30 pub(crate) commands: Vec<DrawCommand>,
31 /// Logical viewport size associated with this display list.
32 #[get(type(copy))]
33 pub(crate) viewport: Size,
34 /// Scale factor mapping logical coordinates to physical pixels.
35 #[get(type(copy))]
36 pub(crate) scale_factor: f32,
37 /// Command index separating base-scene commands `[0..portal_split_index]` from top-layer portal/fixed overlays.
38 #[get(type(copy))]
39 pub(crate) portal_split_index: usize,
40 /// Persistent per-frame arena holding recycled strings, scratch queues, and O(1) streaming digests.
41 #[get(skip)]
42 #[get_mut(skip)]
43 #[set(skip)]
44 pub(crate) arena: DisplayListFrameArena,
45}
46
47/// Cross-frame retained `CachedDrawCommand` fragment descriptor referencing ranges inside `PaintFragmentCache`'s flat slabs.
48#[derive(Clone, Copy, Debug, Default)]
49pub(crate) struct RetainedPaintFragment {
50 /// True once this slot holds an active cached subtree fragment.
51 pub(crate) occupied: bool,
52 /// Stable node identity (index and generation) owning this fragment.
53 pub(crate) node_id: NodeId,
54 /// Quantized physical DPI scale (`(scale * 1000.0).round() as u32`) supporting fractional DPRs (`1.25x`, `1.5x`, `2.625x`, `3.0x`).
55 pub(crate) phys_scale_milli: u32,
56 /// Bit representation of accumulated ancestor opacity at capture time.
57 pub(crate) opacity_bits: u32,
58 /// Physical displacement `(offset_x_phys, offset_y_phys)` at capture time.
59 pub(crate) offset_phys: Point,
60 /// Deterministic fingerprint of container and descendant layout geometry.
61 pub(crate) geom_hash: u64,
62 /// Deterministic fingerprint of container and descendant paint/text styles and content.
63 pub(crate) style_text_hash: u64,
64 /// Start index into `PaintFragmentCache::cmd_slab`.
65 pub(crate) cmd_start: u32,
66 /// Active command count stored inside `cmd_slab`.
67 pub(crate) cmd_len: u32,
68 /// Reserved command capacity owned by this slot for zero-growth in-place updates.
69 pub(crate) cmd_cap: u32,
70 /// Start byte offset into `PaintFragmentCache::text_slab`.
71 pub(crate) text_start: u32,
72 /// Reserved UTF-8 byte capacity owned by this slot for zero-growth in-place updates.
73 pub(crate) text_cap: u32,
74}
75
76/// Per-canvas output stability record distinguishing static icon/brand vector canvases from animated/dynamic canvases.
77#[derive(Clone, Copy, Debug, Default)]
78pub(crate) struct CanvasStabilityEntry {
79 /// Canvas scene node identity.
80 pub(crate) node_id: NodeId,
81 /// Quantized physical DPI scale at observation time.
82 pub(crate) phys_scale_milli: u32,
83 /// Canvas logical bounds at observation time.
84 pub(crate) bounds: Rect,
85 /// `SceneTree::revision` at last observation.
86 pub(crate) tree_revision: u64,
87 /// Deterministic 64-bit hash of vector commands emitted by the canvas callback.
88 pub(crate) cmd_hash: u64,
89 /// Consecutive identical observations confirming static pure-vector output.
90 pub(crate) stable_hits: u16,
91 /// Set permanently when the canvas emits raster images or mutates output at the same tree revision.
92 pub(crate) proven_dynamic: bool,
93 /// True once this slot holds an active record.
94 pub(crate) occupied: bool,
95}
96
97/// Whole-frame scene snapshot signature used for O(1) full-`DisplayList` retention when `SceneTree` is unchanged.
98#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
99pub(crate) struct PaintSceneSignature {
100 /// Address of the rendered `SceneTree` instance to prevent cross-tree aliasing.
101 pub(crate) tree_ptr: usize,
102 /// Monotonic `SceneTree::revision` at last paint.
103 pub(crate) tree_revision: u64,
104 /// Viewport width bits.
105 pub(crate) viewport_w_bits: u32,
106 /// Viewport height bits.
107 pub(crate) viewport_h_bits: u32,
108 /// Active DPI scale bits.
109 pub(crate) scale_bits: u32,
110 /// Packed RGBA clear color.
111 pub(crate) clear_rgba: u32,
112 /// Packed focused node handle (`u64::MAX` when `None`).
113 pub(crate) focused_packed: u64,
114 /// Packed hovered node handle (`u64::MAX` when `None`).
115 pub(crate) hovered_packed: u64,
116 /// Packed pressed node handle (`u64::MAX` when `None`).
117 pub(crate) pressed_packed: u64,
118 /// Active caret blink visibility flag.
119 pub(crate) caret_visible: bool,
120 /// Deterministic digest of active text selection range.
121 pub(crate) text_sel_sig: u64,
122}
123
124/// Bounded cross-frame cache retaining whole display lists and clean nested subtree `DrawCommand` fragments.
125#[derive(Clone, Debug, Default, Getter)]
126pub struct PaintFragmentCache {
127 /// True once `last_scene_sig` has been populated for the current `DisplayList`.
128 #[get(skip)]
129 pub(crate) has_last_scene: bool,
130 /// Last rendered whole-scene signature for O(1) zero-rebuild display list reuse.
131 #[get(skip)]
132 pub(crate) last_scene_sig: PaintSceneSignature,
133 /// True when the last rendered frame visited at least one dynamic (non-static) `NodeKind::Canvas`.
134 #[get(skip)]
135 pub(crate) last_has_canvas: bool,
136 /// Bounded power-of-two direct-mapped table of retained subtree fragment descriptors.
137 #[get(skip)]
138 pub(crate) slots: Vec<RetainedPaintFragment>,
139 /// Pre-allocated contiguous slab storing cached fragment commands without per-slot `Vec` allocations.
140 #[get(skip)]
141 pub(crate) cmd_slab: Vec<CachedDrawCommand>,
142 /// Pre-allocated contiguous UTF-8 byte slab storing cached fragment text without per-text `String` allocations.
143 #[get(skip)]
144 pub(crate) text_slab: Vec<u8>,
145 /// Direct-mapped stability table allowing static vector icon/brand canvases to preserve whole-list reuse.
146 #[get(skip)]
147 pub(crate) canvas_stability: [CanvasStabilityEntry; CANVAS_STABILITY_SLOTS],
148 /// Cumulative count of whole-frame `DisplayList` retention hits.
149 #[get(type(copy))]
150 pub(crate) whole_list_hits: u64,
151 /// Cumulative count of retained subtree fragment reuse hits.
152 #[get(type(copy))]
153 pub(crate) fragment_hits: u64,
154 /// Cumulative count of retained subtree fragment capture misses.
155 #[get(type(copy))]
156 pub(crate) fragment_misses: u64,
157 /// Cumulative count of direct-mapped fragment slot displacements.
158 #[get(type(copy))]
159 pub(crate) fragment_evictions: u64,
160}
161
162/// Stateless scene-to-display-list compiler supporting z-order sorting, scroll clipping, frustum culling, and retained fragment caching.
163#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
164pub struct PaintPass;
165
166/// Borrowed reusable scratch buffers threaded through recursive `PaintPass::emit_node` calls.
167#[derive(Debug)]
168pub(crate) struct PaintScratch<'a> {
169 /// Optional deferred top-layer portal queue (`None` while painting top-layer portals).
170 pub(crate) portals: Option<&'a mut Vec<(i32, usize, NodeId)>>,
171 /// Stack-sliced scratch vector reused for nested z-index child sorting.
172 pub(crate) z_sort: &'a mut Vec<(i32, usize, NodeId)>,
173 /// Ancestor handles on paths to live `Portal` / `Position::Fixed` descendants for lossless clipped-subtree culling.
174 pub(crate) portal_ancestors: &'a [NodeId],
175 /// Optional cross-frame retained fragment cache (`Some` during retained builds).
176 pub(crate) fragments: Option<&'a mut PaintFragmentCache>,
177 /// Flag set whenever any visited `NodeKind::Canvas` is dynamic or still awaiting static verification.
178 pub(crate) saw_canvas: &'a mut bool,
179}