euv_core/render/software/struct.rs
1use super::*;
2
3/// Single disjoint horizontal framebuffer strip dispatched to a persistent rasterization worker thread.
4#[cfg(not(target_arch = "wasm32"))]
5#[derive(Clone, Copy, Data, Debug, Default)]
6pub(crate) struct BandTaskSlice {
7 /// Raw mutable pixel buffer base address encoded as `usize` for `Send` transfer.
8 #[get(type(copy))]
9 pub(crate) pixels_ptr: usize,
10 /// Byte length of the disjoint horizontal pixel strip.
11 #[get(type(copy))]
12 pub(crate) pixels_len: usize,
13 /// Full framebuffer physical width in pixels.
14 #[get(type(copy))]
15 pub(crate) width: u32,
16 /// Inclusive top physical Y row of this strip.
17 #[get(type(copy))]
18 pub(crate) y_start: u32,
19 /// Number of physical rows inside this strip.
20 #[get(type(copy))]
21 pub(crate) height: u32,
22 /// Optional raw source pointer for parallel base-scene backdrop restore (`0` when unused).
23 #[get(type(copy))]
24 pub(crate) base_src_ptr: usize,
25}
26
27/// Active rounded-rectangle clip mask in physical pixels applied during software band rasterization.
28#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
29pub(crate) struct RoundedClipMask {
30 /// Physical clip rectangle bounds.
31 #[get(type(copy))]
32 pub(crate) rect: Rect,
33 /// Physical corner radii.
34 #[get(type(copy))]
35 pub(crate) radius: CornerRadius,
36}
37
38/// Shared read-only frame dispatch state consumed lock-free by persistent band workers during a single `render` call.
39#[cfg(not(target_arch = "wasm32"))]
40#[derive(Debug)]
41pub(crate) struct BandJob {
42 /// Base address of the caller-owned `BandTaskSlice` slice.
43 pub(crate) tasks_ptr: usize,
44 /// Number of horizontal strips in the frame job.
45 pub(crate) tasks_len: usize,
46 /// Base address of `DisplayList::commands`.
47 pub(crate) commands_ptr: usize,
48 /// Length of `DisplayList::commands`.
49 pub(crate) commands_len: usize,
50 /// Base address of the pre-processed `PreppedCommand` slice.
51 pub(crate) prepped_ptr: usize,
52 /// Length of the pre-processed `PreppedCommand` slice.
53 pub(crate) prepped_len: usize,
54 /// Base address of the pre-measured `TextLayoutResult` slice.
55 pub(crate) layouts_ptr: usize,
56 /// Length of the pre-measured `TextLayoutResult` slice.
57 pub(crate) layouts_len: usize,
58 /// Base address of the per-frame active `RoundedClipMask` slice.
59 pub(crate) rounded_clips_ptr: usize,
60 /// Length of the per-frame active `RoundedClipMask` slice.
61 pub(crate) rounded_clips_len: usize,
62 /// Base address of the shared read-only `GlyphAtlas`.
63 pub(crate) atlas_ptr: usize,
64 /// Active physical DPI scale factor.
65 pub(crate) scale: f32,
66 /// Active anti-aliasing policy.
67 pub(crate) aa: AntialiasingMode,
68 /// Atomic work-stealing strip cursor shared by the caller and all worker threads.
69 pub(crate) next_idx: AtomicUsize,
70 /// Atomic count of worker threads that finished observing this epoch.
71 pub(crate) workers_done: AtomicUsize,
72 /// Atomic accumulated shaded pixel count across all strips.
73 pub(crate) total_shaded: AtomicUsize,
74}
75
76/// Synchronized dispatch generation and active job pointer shared between the caller and persistent band workers.
77#[cfg(not(target_arch = "wasm32"))]
78#[derive(Clone, Copy, Data, Debug, Default)]
79pub(crate) struct BandPoolState {
80 /// Monotonically increasing dispatch epoch counter.
81 #[get(type(copy))]
82 pub(crate) epoch: u64,
83 /// Raw pointer address of the active `BandJob` (`0` while idle).
84 #[get(type(copy))]
85 pub(crate) active_job: usize,
86}
87
88/// Persistent native worker pool eliminating per-frame `pthread_create` overhead on high-refresh mobile and desktop targets.
89#[cfg(not(target_arch = "wasm32"))]
90#[derive(Debug)]
91pub(crate) struct BandWorkerPool {
92 /// Number of background worker threads (excluding the calling main thread).
93 pub(crate) worker_count: usize,
94 /// Non-blocking guard ensuring only one frame dispatches through the pool at a time.
95 pub(crate) dispatch_lock: Mutex<()>,
96 /// Shared dispatch state mutex and worker/caller condition variables.
97 pub(crate) shared: Arc<(Mutex<BandPoolState>, Condvar, Condvar)>,
98}
99
100/// Preprocessed draw-command metadata computed once on the main thread before parallel band rasterization.
101#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
102pub(crate) struct PreppedCommand {
103 /// Original index inside `DisplayList::commands`.
104 #[get(type(copy))]
105 pub(crate) cmd_index: usize,
106 /// Active intersected physical clip rectangle for this command.
107 #[get(type(copy))]
108 pub(crate) active_clip: Rect,
109 /// Inclusive top physical Y row affected by this command.
110 #[get(type(copy))]
111 pub(crate) y0: u32,
112 /// Exclusive bottom physical Y row affected by this command.
113 #[get(type(copy))]
114 pub(crate) y1: u32,
115 /// Optional opaque inner vertical-span cutout for a `BoxShadow` followed immediately by an opaque `FillRoundedRect`.
116 #[get(type(copy))]
117 pub(crate) opaque_cutout_h: Rect,
118 /// Optional opaque inner horizontal-span cutout for a `BoxShadow` followed immediately by an opaque `FillRoundedRect`.
119 #[get(type(copy))]
120 pub(crate) opaque_cutout_v: Rect,
121 /// Optional index into the per-frame pre-resolved `TextLayoutResult` slice (`u32::MAX` when unused).
122 #[get(type(copy))]
123 pub(crate) text_layout_idx: u32,
124 /// Start index into the per-frame `RoundedClipMask` slice (`0` when unused).
125 #[get(type(copy))]
126 pub(crate) rounded_clip_start: u32,
127 /// Count of active `RoundedClipMask` entries touching this command (`0` on fast path).
128 #[get(type(copy))]
129 pub(crate) rounded_clip_len: u16,
130}
131
132/// High-performance CPU tile and analytical-SDF software rasterizer with zero GPU dependencies.
133#[derive(Clone, Data, Debug, Default)]
134pub struct SoftwareRenderer {
135 /// Persistent RGBA8 framebuffer reused across frames.
136 pub(crate) framebuffer: Framebuffer,
137 /// Shared glyph rasterization atlas.
138 pub(crate) glyph_atlas: GlyphAtlas,
139 /// Native or deterministic font rasterization provider.
140 pub(crate) font_provider: NativeSystemFont,
141 /// Deterministic text measurer matching `LayoutEngine` metrics.
142 #[get(type(copy))]
143 pub(crate) measurer: DeterministicTextMeasurer,
144 /// Cached word-wrapped `TextLayoutResult` map eliminating per-frame text layout allocations during scrolling.
145 #[get(pub(crate))]
146 #[get_mut(pub(crate))]
147 pub(crate) text_layout_cache: HashMap<(u64, u32), TextLayoutResult>,
148 /// Active physical clip-rectangle stack.
149 #[get(pub(crate))]
150 #[get_mut(pub(crate))]
151 #[set(pub(crate))]
152 pub(crate) clip_stack: Vec<Rect>,
153 /// Parallel stack of optional rounded-rectangle clip masks aligned 1:1 with `clip_stack`.
154 #[get(pub(crate))]
155 #[get_mut(pub(crate))]
156 #[set(pub(crate))]
157 pub(crate) rounded_clip_stack: Vec<Option<RoundedClipMask>>,
158 /// Active anti-aliasing policy.
159 #[get(type(copy))]
160 pub(crate) antialiasing: AntialiasingMode,
161 /// Tile edge length in physical pixels for damage tile accounting.
162 #[get(type(copy))]
163 pub(crate) tile_size: u32,
164 /// Cached physical width of the static base-scene snapshot behind active portals.
165 #[get(pub(crate), type(copy))]
166 #[set(pub(crate))]
167 pub(crate) base_cache_width: u32,
168 /// Cached physical height of the static base-scene snapshot behind active portals.
169 #[get(pub(crate), type(copy))]
170 #[set(pub(crate))]
171 pub(crate) base_cache_height: u32,
172 /// Full base-layer command hash for the cached static backdrop (`0` when invalid).
173 #[get(pub(crate), type(copy))]
174 #[set(pub(crate))]
175 pub(crate) base_cache_hash: u64,
176 /// Base-layer command hash observed on the immediately preceding frame to avoid copying active scroll frames.
177 #[get(pub(crate), type(copy))]
178 #[set(pub(crate))]
179 pub(crate) prev_base_hash: u64,
180 /// Saved RGBA8 pixels of the static base scene beneath active portals for fast overlay compositing.
181 #[get(pub(crate))]
182 #[get_mut(pub(crate))]
183 #[set(pub(crate))]
184 pub(crate) base_cache_pixels: Vec<u8>,
185}