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    /// Persistent scratch buffer of ancestor handles leading to live `Portal` / `Position::Fixed` nodes across frames.
28    #[get(skip)]
29    #[get_mut(skip)]
30    #[set(skip)]
31    pub(crate) portal_ancestors_scratch: Vec<NodeId>,
32}
33
34/// Cross-frame retained `DrawCommand` fragment captured for one clean clipped container/list-row subtree.
35#[derive(Clone, Debug)]
36pub(crate) struct RetainedPaintFragment {
37    /// Stable node identity (index and generation) owning this fragment.
38    pub(crate) node_id: NodeId,
39    /// Bit representation of DPI scale factor at capture time.
40    pub(crate) scale_bits: u32,
41    /// Bit representation of accumulated ancestor opacity at capture time.
42    pub(crate) opacity_bits: u32,
43    /// Physical displacement `(offset_x_phys, offset_y_phys)` at capture time.
44    pub(crate) offset_phys: Point,
45    /// Deterministic fingerprint of container and child layout geometry.
46    pub(crate) geom_hash: u64,
47    /// Deterministic fingerprint of container and child paint/text styles and content.
48    pub(crate) style_text_hash: u64,
49    /// Exact ordered `DrawCommand` slice emitted for this subtree.
50    pub(crate) commands: Vec<DrawCommand>,
51}
52
53/// Whole-frame scene snapshot signature used for O(1) full-`DisplayList` retention when `SceneTree` is unchanged.
54#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
55pub(crate) struct PaintSceneSignature {
56    /// Address of the rendered `SceneTree` instance to prevent cross-tree aliasing.
57    pub(crate) tree_ptr: usize,
58    /// Monotonic `SceneTree::revision` at last paint.
59    pub(crate) tree_revision: u64,
60    /// Viewport width bits.
61    pub(crate) viewport_w_bits: u32,
62    /// Viewport height bits.
63    pub(crate) viewport_h_bits: u32,
64    /// Active DPI scale bits.
65    pub(crate) scale_bits: u32,
66    /// Packed RGBA clear color.
67    pub(crate) clear_rgba: u32,
68    /// Packed focused node handle (`u64::MAX` when `None`).
69    pub(crate) focused_packed: u64,
70    /// Packed hovered node handle (`u64::MAX` when `None`).
71    pub(crate) hovered_packed: u64,
72    /// Packed pressed node handle (`u64::MAX` when `None`).
73    pub(crate) pressed_packed: u64,
74    /// Active caret blink visibility flag.
75    pub(crate) caret_visible: bool,
76    /// Deterministic digest of active text selection range.
77    pub(crate) text_sel_sig: u64,
78}
79
80/// Bounded cross-frame cache retaining whole display lists and clean clipped subtree `DrawCommand` fragments.
81#[derive(Clone, Debug, Default, Getter)]
82pub struct PaintFragmentCache {
83    /// True once `last_scene_sig` has been populated for the current `DisplayList`.
84    #[get(skip)]
85    pub(crate) has_last_scene: bool,
86    /// Last rendered whole-scene signature for O(1) zero-rebuild display list reuse.
87    #[get(skip)]
88    pub(crate) last_scene_sig: PaintSceneSignature,
89    /// True when the last rendered frame visited at least one dynamic `NodeKind::Canvas`.
90    #[get(skip)]
91    pub(crate) last_has_canvas: bool,
92    /// Bounded power-of-two direct-mapped table of retained subtree `DrawCommand` fragments.
93    #[get(skip)]
94    pub(crate) slots: Vec<Option<RetainedPaintFragment>>,
95    /// Cumulative count of whole-frame `DisplayList` retention hits.
96    #[get(type(copy))]
97    pub(crate) whole_list_hits: u64,
98    /// Cumulative count of retained subtree fragment reuse hits.
99    #[get(type(copy))]
100    pub(crate) fragment_hits: u64,
101    /// Cumulative count of retained subtree fragment capture misses.
102    #[get(type(copy))]
103    pub(crate) fragment_misses: u64,
104    /// Cumulative count of direct-mapped fragment slot displacements.
105    #[get(type(copy))]
106    pub(crate) fragment_evictions: u64,
107}
108
109/// Stateless scene-to-display-list compiler supporting z-order sorting, scroll clipping, frustum culling, and retained fragment caching.
110#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
111pub struct PaintPass;
112
113/// Borrowed reusable scratch buffers threaded through recursive `PaintPass::emit_node` calls.
114#[derive(Debug)]
115pub(crate) struct PaintScratch<'a> {
116    /// Optional deferred top-layer portal queue (`None` while painting top-layer portals).
117    pub(crate) portals: Option<&'a mut Vec<(i32, usize, NodeId)>>,
118    /// Stack-sliced scratch vector reused for nested z-index child sorting.
119    pub(crate) z_sort: &'a mut Vec<(i32, usize, NodeId)>,
120    /// Ancestor handles on paths to live `Portal` / `Position::Fixed` descendants for lossless clipped-subtree culling.
121    pub(crate) portal_ancestors: &'a [NodeId],
122    /// Optional cross-frame retained fragment cache (`Some` during retained builds).
123    pub(crate) fragments: Option<&'a mut PaintFragmentCache>,
124    /// Flag set whenever any visited node is `NodeKind::Canvas`.
125    pub(crate) saw_canvas: &'a mut bool,
126}