Skip to main content

euv_core/render/command/
struct.rs

1use super::*;
2
3/// Reusable backend-agnostic command buffer emitted once per frame for Software, Hardware, or Hybrid execution.
4#[derive(Clone, Data, Debug, Default, PartialEq)]
5pub struct DisplayList {
6    /// Ordered drawing commands.
7    pub(crate) commands: Vec<DrawCommand>,
8    /// Logical viewport size associated with this display list.
9    #[get(type(copy))]
10    pub(crate) viewport: Size,
11    /// Scale factor mapping logical coordinates to physical pixels.
12    #[get(type(copy))]
13    pub(crate) scale_factor: f32,
14    /// Command index separating base-scene commands `[0..portal_split_index]` from top-layer portal/fixed overlays.
15    #[get(type(copy))]
16    pub(crate) portal_split_index: usize,
17    /// Persistent scratch queue collecting deferred top-layer portal/fixed nodes across frames (cleared after `PaintPass::build`).
18    #[get(skip)]
19    #[get_mut(skip)]
20    #[set(skip)]
21    pub(crate) portals_scratch: Vec<(i32, usize, NodeId)>,
22    /// Persistent stack-allocated scratch buffer for nested z-index child sorting across frames (cleared after `PaintPass::build`).
23    #[get(skip)]
24    #[get_mut(skip)]
25    #[set(skip)]
26    pub(crate) z_sort_scratch: Vec<(i32, usize, NodeId)>,
27}
28
29/// Cross-frame retained `DrawCommand` fragment captured for one clean clipped container/list-row subtree.
30#[derive(Clone, Debug)]
31pub(crate) struct RetainedPaintFragment {
32    /// Stable node identity (index and generation) owning this fragment.
33    pub(crate) node_id: NodeId,
34    /// Bit representation of DPI scale factor at capture time.
35    pub(crate) scale_bits: u32,
36    /// Bit representation of accumulated ancestor opacity at capture time.
37    pub(crate) opacity_bits: u32,
38    /// Physical displacement `(offset_x_phys, offset_y_phys)` at capture time.
39    pub(crate) offset_phys: Point,
40    /// Deterministic fingerprint of container and child layout geometry.
41    pub(crate) geom_hash: u64,
42    /// Deterministic fingerprint of container and child paint/text styles and content.
43    pub(crate) style_text_hash: u64,
44    /// Exact ordered `DrawCommand` slice emitted for this subtree.
45    pub(crate) commands: Vec<DrawCommand>,
46}
47
48/// Whole-frame scene snapshot signature used for O(1) full-`DisplayList` retention when `SceneTree` is unchanged.
49#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
50pub(crate) struct PaintSceneSignature {
51    /// Address of the rendered `SceneTree` instance to prevent cross-tree aliasing.
52    pub(crate) tree_ptr: usize,
53    /// Monotonic `SceneTree::revision` at last paint.
54    pub(crate) tree_revision: u64,
55    /// Viewport width bits.
56    pub(crate) viewport_w_bits: u32,
57    /// Viewport height bits.
58    pub(crate) viewport_h_bits: u32,
59    /// Active DPI scale bits.
60    pub(crate) scale_bits: u32,
61    /// Packed RGBA clear color.
62    pub(crate) clear_rgba: u32,
63    /// Packed focused node handle (`u64::MAX` when `None`).
64    pub(crate) focused_packed: u64,
65    /// Packed hovered node handle (`u64::MAX` when `None`).
66    pub(crate) hovered_packed: u64,
67    /// Packed pressed node handle (`u64::MAX` when `None`).
68    pub(crate) pressed_packed: u64,
69    /// Active caret blink visibility flag.
70    pub(crate) caret_visible: bool,
71    /// Deterministic digest of active text selection range.
72    pub(crate) text_sel_sig: u64,
73}
74
75/// Bounded cross-frame cache retaining whole display lists and clean clipped subtree `DrawCommand` fragments.
76#[derive(Clone, Debug, Default, Getter)]
77pub struct PaintFragmentCache {
78    /// True once `last_scene_sig` has been populated for the current `DisplayList`.
79    #[get(skip)]
80    pub(crate) has_last_scene: bool,
81    /// Last rendered whole-scene signature for O(1) zero-rebuild display list reuse.
82    #[get(skip)]
83    pub(crate) last_scene_sig: PaintSceneSignature,
84    /// True when the last rendered frame visited at least one dynamic `NodeKind::Canvas`.
85    #[get(skip)]
86    pub(crate) last_has_canvas: bool,
87    /// Bounded power-of-two direct-mapped table of retained subtree `DrawCommand` fragments.
88    #[get(skip)]
89    pub(crate) slots: Vec<Option<RetainedPaintFragment>>,
90    /// Cumulative count of whole-frame `DisplayList` retention hits.
91    #[get(type(copy))]
92    pub(crate) whole_list_hits: u64,
93    /// Cumulative count of retained subtree fragment reuse hits.
94    #[get(type(copy))]
95    pub(crate) fragment_hits: u64,
96    /// Cumulative count of retained subtree fragment capture misses.
97    #[get(type(copy))]
98    pub(crate) fragment_misses: u64,
99    /// Cumulative count of direct-mapped fragment slot displacements.
100    #[get(type(copy))]
101    pub(crate) fragment_evictions: u64,
102}
103
104/// Stateless scene-to-display-list compiler supporting z-order sorting, scroll clipping, frustum culling, and retained fragment caching.
105#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
106pub struct PaintPass;
107
108/// Borrowed reusable scratch buffers threaded through recursive `PaintPass::emit_node` calls.
109#[derive(Debug)]
110pub(crate) struct PaintScratch<'a> {
111    /// Optional deferred top-layer portal queue (`None` while painting top-layer portals).
112    pub(crate) portals: Option<&'a mut Vec<(i32, usize, NodeId)>>,
113    /// Stack-sliced scratch vector reused for nested z-index child sorting.
114    pub(crate) z_sort: &'a mut Vec<(i32, usize, NodeId)>,
115    /// Optional cross-frame retained fragment cache (`Some` during retained builds).
116    pub(crate) fragments: Option<&'a mut PaintFragmentCache>,
117    /// Flag set whenever any visited node is `NodeKind::Canvas`.
118    pub(crate) saw_canvas: &'a mut bool,
119}