Skip to main content

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    /// True when direct-GPU hardware scene passes (`OceanFluid` / `World3d`) are active on the target compositor.
41    #[get(type(copy))]
42    pub(crate) direct_gpu_scene_enabled: bool,
43    /// Optional offscreen GPU scene pass submitted by an active game viewport during this frame.
44    #[get(skip)]
45    #[get_mut(skip)]
46    #[set(skip)]
47    pub(crate) gpu_scene_pass: Option<DirectGpuScenePass>,
48    /// Persistent per-frame arena holding recycled strings, scratch queues, and O(1) streaming digests.
49    #[get(skip)]
50    #[get_mut(skip)]
51    #[set(skip)]
52    pub(crate) arena: DisplayListFrameArena,
53}
54
55/// Cross-frame retained `CachedDrawCommand` fragment descriptor referencing ranges inside `PaintFragmentCache`'s flat slabs.
56#[derive(Clone, Copy, Debug, Default)]
57pub(crate) struct RetainedPaintFragment {
58    /// True once this slot holds an active cached subtree fragment.
59    pub(crate) occupied: bool,
60    /// Stable node identity (index and generation) owning this fragment.
61    pub(crate) node_id: NodeId,
62    /// Quantized physical DPI scale (`(scale * 1000.0).round() as u32`) supporting fractional DPRs (`1.25x`, `1.5x`, `2.625x`, `3.0x`).
63    pub(crate) phys_scale_milli: u32,
64    /// Bit representation of accumulated ancestor opacity at capture time.
65    pub(crate) opacity_bits: u32,
66    /// Physical displacement `(offset_x_phys, offset_y_phys)` at capture time.
67    pub(crate) offset_phys: Point,
68    /// Deterministic fingerprint of container and descendant layout geometry.
69    pub(crate) geom_hash: u64,
70    /// Deterministic fingerprint of container and descendant paint/text styles and content.
71    pub(crate) style_text_hash: u64,
72    /// Start index into `PaintFragmentCache::cmd_slab`.
73    pub(crate) cmd_start: u32,
74    /// Active command count stored inside `cmd_slab`.
75    pub(crate) cmd_len: u32,
76    /// Reserved command capacity owned by this slot for zero-growth in-place updates.
77    pub(crate) cmd_cap: u32,
78    /// Start byte offset into `PaintFragmentCache::text_slab`.
79    pub(crate) text_start: u32,
80    /// Reserved UTF-8 byte capacity owned by this slot for zero-growth in-place updates.
81    pub(crate) text_cap: u32,
82}
83
84/// Per-canvas output stability record distinguishing static icon/brand vector canvases from animated/dynamic canvases.
85#[derive(Clone, Copy, Debug, Default)]
86pub(crate) struct CanvasStabilityEntry {
87    /// Canvas scene node identity.
88    pub(crate) node_id: NodeId,
89    /// Quantized physical DPI scale at observation time.
90    pub(crate) phys_scale_milli: u32,
91    /// Canvas logical bounds at observation time.
92    pub(crate) bounds: Rect,
93    /// `SceneTree::revision` at last observation.
94    pub(crate) tree_revision: u64,
95    /// Deterministic 64-bit hash of vector commands emitted by the canvas callback.
96    pub(crate) cmd_hash: u64,
97    /// Consecutive identical observations confirming static pure-vector output.
98    pub(crate) stable_hits: u16,
99    /// Set permanently when the canvas emits raster images or mutates output at the same tree revision.
100    pub(crate) proven_dynamic: bool,
101    /// True once this slot holds an active record.
102    pub(crate) occupied: bool,
103}
104
105/// Whole-frame scene snapshot signature used for O(1) full-`DisplayList` retention when `SceneTree` is unchanged.
106#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
107pub(crate) struct PaintSceneSignature {
108    /// Address of the rendered `SceneTree` instance to prevent cross-tree aliasing.
109    pub(crate) tree_ptr: usize,
110    /// Monotonic `SceneTree::revision` at last paint.
111    pub(crate) tree_revision: u64,
112    /// Viewport width bits.
113    pub(crate) viewport_w_bits: u32,
114    /// Viewport height bits.
115    pub(crate) viewport_h_bits: u32,
116    /// Active DPI scale bits.
117    pub(crate) scale_bits: u32,
118    /// Packed RGBA clear color.
119    pub(crate) clear_rgba: u32,
120    /// Packed focused node handle (`u64::MAX` when `None`).
121    pub(crate) focused_packed: u64,
122    /// Packed hovered node handle (`u64::MAX` when `None`).
123    pub(crate) hovered_packed: u64,
124    /// Packed pressed node handle (`u64::MAX` when `None`).
125    pub(crate) pressed_packed: u64,
126    /// Active caret blink visibility flag.
127    pub(crate) caret_visible: bool,
128    /// Deterministic digest of active text selection range.
129    pub(crate) text_sel_sig: u64,
130    /// True when host-level scrollbar suppression (mobile/tablet/wearable/miniapp) is active.
131    pub(crate) scrollbars_suppressed: bool,
132}
133
134/// Bounded cross-frame cache retaining whole display lists and clean nested subtree `DrawCommand` fragments.
135#[derive(Clone, Debug, Default, Getter)]
136pub struct PaintFragmentCache {
137    /// True once `last_scene_sig` has been populated for the current `DisplayList`.
138    #[get(skip)]
139    pub(crate) has_last_scene: bool,
140    /// Last rendered whole-scene signature for O(1) zero-rebuild display list reuse.
141    #[get(skip)]
142    pub(crate) last_scene_sig: PaintSceneSignature,
143    /// True when the last rendered frame visited at least one dynamic (non-static) `NodeKind::Canvas`.
144    #[get(skip)]
145    pub(crate) last_has_canvas: bool,
146    /// Bounded power-of-two direct-mapped table of retained subtree fragment descriptors.
147    #[get(skip)]
148    pub(crate) slots: Vec<RetainedPaintFragment>,
149    /// Pre-allocated contiguous slab storing cached fragment commands without per-slot `Vec` allocations.
150    #[get(skip)]
151    pub(crate) cmd_slab: Vec<CachedDrawCommand>,
152    /// Pre-allocated contiguous UTF-8 byte slab storing cached fragment text without per-text `String` allocations.
153    #[get(skip)]
154    pub(crate) text_slab: Vec<u8>,
155    /// Direct-mapped stability table allowing static vector icon/brand canvases to preserve whole-list reuse.
156    #[get(skip)]
157    pub(crate) canvas_stability: [CanvasStabilityEntry; CANVAS_STABILITY_SLOTS],
158    /// Cumulative count of whole-frame `DisplayList` retention hits.
159    #[get(type(copy))]
160    pub(crate) whole_list_hits: u64,
161    /// Cumulative count of retained subtree fragment reuse hits.
162    #[get(type(copy))]
163    pub(crate) fragment_hits: u64,
164    /// Cumulative count of retained subtree fragment capture misses.
165    #[get(type(copy))]
166    pub(crate) fragment_misses: u64,
167    /// Cumulative count of direct-mapped fragment slot displacements.
168    #[get(type(copy))]
169    pub(crate) fragment_evictions: u64,
170}
171
172/// Stateless scene-to-display-list compiler supporting z-order sorting, scroll clipping, frustum culling, and retained fragment caching.
173#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
174pub struct PaintPass;
175
176/// Borrowed reusable scratch buffers threaded through recursive `PaintPass::emit_node` calls.
177#[derive(Debug)]
178pub(crate) struct PaintScratch<'a> {
179    /// Optional deferred top-layer portal queue (`None` while painting top-layer portals).
180    pub(crate) portals: Option<&'a mut Vec<(i32, usize, NodeId)>>,
181    /// Stack-sliced scratch vector reused for nested z-index child sorting.
182    pub(crate) z_sort: &'a mut Vec<(i32, usize, NodeId)>,
183    /// Ancestor handles on paths to live `Portal` / `Position::Fixed` descendants for lossless clipped-subtree culling.
184    pub(crate) portal_ancestors: &'a [NodeId],
185    /// Optional cross-frame retained fragment cache (`Some` during retained builds).
186    pub(crate) fragments: Option<&'a mut PaintFragmentCache>,
187    /// Flag set whenever any visited `NodeKind::Canvas` is dynamic or still awaiting static verification.
188    pub(crate) saw_canvas: &'a mut bool,
189}