Skip to main content

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/// Shared read-only frame dispatch state consumed lock-free by persistent band workers during a single `render` call.
28#[cfg(not(target_arch = "wasm32"))]
29#[derive(Debug)]
30pub(crate) struct BandJob {
31    /// Base address of the caller-owned `BandTaskSlice` slice.
32    pub(crate) tasks_ptr: usize,
33    /// Number of horizontal strips in the frame job.
34    pub(crate) tasks_len: usize,
35    /// Base address of `DisplayList::commands`.
36    pub(crate) commands_ptr: usize,
37    /// Length of `DisplayList::commands`.
38    pub(crate) commands_len: usize,
39    /// Base address of the pre-processed `PreppedCommand` slice.
40    pub(crate) prepped_ptr: usize,
41    /// Length of the pre-processed `PreppedCommand` slice.
42    pub(crate) prepped_len: usize,
43    /// Base address of the pre-measured `TextLayoutResult` slice.
44    pub(crate) layouts_ptr: usize,
45    /// Length of the pre-measured `TextLayoutResult` slice.
46    pub(crate) layouts_len: usize,
47    /// Base address of the shared read-only `GlyphAtlas`.
48    pub(crate) atlas_ptr: usize,
49    /// Active physical DPI scale factor.
50    pub(crate) scale: f32,
51    /// Active anti-aliasing policy.
52    pub(crate) aa: AntialiasingMode,
53    /// Atomic work-stealing strip cursor shared by the caller and all worker threads.
54    pub(crate) next_idx: AtomicUsize,
55    /// Atomic count of worker threads that finished observing this epoch.
56    pub(crate) workers_done: AtomicUsize,
57    /// Atomic accumulated shaded pixel count across all strips.
58    pub(crate) total_shaded: AtomicUsize,
59}
60
61/// Synchronized dispatch generation and active job pointer shared between the caller and persistent band workers.
62#[cfg(not(target_arch = "wasm32"))]
63#[derive(Clone, Copy, Data, Debug, Default)]
64pub(crate) struct BandPoolState {
65    /// Monotonically increasing dispatch epoch counter.
66    #[get(type(copy))]
67    pub(crate) epoch: u64,
68    /// Raw pointer address of the active `BandJob` (`0` while idle).
69    #[get(type(copy))]
70    pub(crate) active_job: usize,
71}
72
73/// Persistent native worker pool eliminating per-frame `pthread_create` overhead on high-refresh mobile and desktop targets.
74#[cfg(not(target_arch = "wasm32"))]
75#[derive(Debug)]
76pub(crate) struct BandWorkerPool {
77    /// Number of background worker threads (excluding the calling main thread).
78    pub(crate) worker_count: usize,
79    /// Non-blocking guard ensuring only one frame dispatches through the pool at a time.
80    pub(crate) dispatch_lock: Mutex<()>,
81    /// Shared dispatch state mutex and worker/caller condition variables.
82    pub(crate) shared: Arc<(Mutex<BandPoolState>, Condvar, Condvar)>,
83}
84
85/// Preprocessed draw-command metadata computed once on the main thread before parallel band rasterization.
86#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
87pub(crate) struct PreppedCommand {
88    /// Original index inside `DisplayList::commands`.
89    #[get(type(copy))]
90    pub(crate) cmd_index: usize,
91    /// Active intersected physical clip rectangle for this command.
92    #[get(type(copy))]
93    pub(crate) active_clip: Rect,
94    /// Inclusive top physical Y row affected by this command.
95    #[get(type(copy))]
96    pub(crate) y0: u32,
97    /// Exclusive bottom physical Y row affected by this command.
98    #[get(type(copy))]
99    pub(crate) y1: u32,
100    /// Optional opaque inner vertical-span cutout for a `BoxShadow` followed immediately by an opaque `FillRoundedRect`.
101    #[get(type(copy))]
102    pub(crate) opaque_cutout_h: Rect,
103    /// Optional opaque inner horizontal-span cutout for a `BoxShadow` followed immediately by an opaque `FillRoundedRect`.
104    #[get(type(copy))]
105    pub(crate) opaque_cutout_v: Rect,
106    /// Optional index into the per-frame pre-resolved `TextLayoutResult` slice (`u32::MAX` when unused).
107    #[get(type(copy))]
108    pub(crate) text_layout_idx: u32,
109}
110
111/// High-performance CPU tile and analytical-SDF software rasterizer with zero GPU dependencies.
112#[derive(Clone, Data, Debug, Default)]
113pub struct SoftwareRenderer {
114    /// Persistent RGBA8 framebuffer reused across frames.
115    pub(crate) framebuffer: Framebuffer,
116    /// Shared glyph rasterization atlas.
117    pub(crate) glyph_atlas: GlyphAtlas,
118    /// Native or deterministic font rasterization provider.
119    pub(crate) font_provider: NativeSystemFont,
120    /// Deterministic text measurer matching `LayoutEngine` metrics.
121    #[get(type(copy))]
122    pub(crate) measurer: DeterministicTextMeasurer,
123    /// Cached word-wrapped `TextLayoutResult` map eliminating per-frame text layout allocations during scrolling.
124    #[get(pub(crate))]
125    #[get_mut(pub(crate))]
126    pub(crate) text_layout_cache: HashMap<(u64, u32), TextLayoutResult>,
127    /// Active physical clip-rectangle stack.
128    #[get(pub(crate))]
129    #[get_mut(pub(crate))]
130    #[set(pub(crate))]
131    pub(crate) clip_stack: Vec<Rect>,
132    /// Active anti-aliasing policy.
133    #[get(type(copy))]
134    pub(crate) antialiasing: AntialiasingMode,
135    /// Tile edge length in physical pixels for damage tile accounting.
136    #[get(type(copy))]
137    pub(crate) tile_size: u32,
138    /// Cached physical width of the static base-scene snapshot behind active portals.
139    #[get(pub(crate), type(copy))]
140    #[set(pub(crate))]
141    pub(crate) base_cache_width: u32,
142    /// Cached physical height of the static base-scene snapshot behind active portals.
143    #[get(pub(crate), type(copy))]
144    #[set(pub(crate))]
145    pub(crate) base_cache_height: u32,
146    /// Full base-layer command hash for the cached static backdrop (`0` when invalid).
147    #[get(pub(crate), type(copy))]
148    #[set(pub(crate))]
149    pub(crate) base_cache_hash: u64,
150    /// Saved RGBA8 pixels of the static base scene beneath active portals for fast overlay compositing.
151    #[get(pub(crate))]
152    #[get_mut(pub(crate))]
153    #[set(pub(crate))]
154    pub(crate) base_cache_pixels: Vec<u8>,
155}