euv-core 0.47.1

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
use super::*;

/// Query and conversion helpers for `PresentOutcome`.
impl PresentOutcome {
    /// Returns `true` when this outcome represents a verified frame presentation.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Present outcome reference.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` only for `PresentOutcome::Presented`.
    #[must_use]
    pub const fn is_presented(&self) -> bool {
        matches!(*self, Self::Presented)
    }

    /// Returns `true` when the pending frame must be retried on the active surface generation.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Present outcome reference.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` only for `PresentOutcome::PresentFailedRetry`.
    #[must_use]
    pub const fn should_retry(&self) -> bool {
        matches!(*self, Self::PresentFailedRetry)
    }

    /// Returns `true` when no frame was presented because of zero damage or bounded in-flight backpressure.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Present outcome reference.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` for `SkippedNoDamage` or `WaitInFlight`.
    #[must_use]
    pub const fn is_idle_or_waiting(&self) -> bool {
        matches!(*self, Self::SkippedNoDamage | Self::WaitInFlight)
    }

    /// Maps this `PresentOutcome` to the legacy `FrameSubmitOutcome` classification.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Present outcome reference.
    ///
    /// # Returns
    ///
    /// - `FrameSubmitOutcome` - Equivalent submission outcome.
    #[must_use]
    pub const fn to_submit_outcome(&self) -> FrameSubmitOutcome {
        match *self {
            Self::Presented => FrameSubmitOutcome::Submitted,
            Self::SkippedNoDamage | Self::WaitInFlight => FrameSubmitOutcome::SkippedNoDamage,
            Self::PresentFailedRetry => FrameSubmitOutcome::SubmitFailed,
        }
    }

    /// Constructs a `PresentOutcome` from a legacy `FrameSubmitOutcome`.
    ///
    /// # Arguments
    ///
    /// - `FrameSubmitOutcome` - Submission outcome to convert.
    ///
    /// # Returns
    ///
    /// - `Self` - Corresponding `PresentOutcome`.
    #[must_use]
    pub const fn from_submit_outcome(outcome: FrameSubmitOutcome) -> Self {
        match outcome {
            FrameSubmitOutcome::Submitted => Self::Presented,
            FrameSubmitOutcome::SkippedNoDamage => Self::SkippedNoDamage,
            FrameSubmitOutcome::SubmitFailed => Self::PresentFailedRetry,
        }
    }
}

/// Lossless conversion from `FrameSubmitOutcome` into `PresentOutcome`.
impl From<FrameSubmitOutcome> for PresentOutcome {
    /// Converts `outcome` into its corresponding `PresentOutcome` variant.
    ///
    /// # Arguments
    ///
    /// - `FrameSubmitOutcome` - Legacy frame submission outcome.
    ///
    /// # Returns
    ///
    /// - `Self` - Equivalent `PresentOutcome`.
    fn from(outcome: FrameSubmitOutcome) -> Self {
        Self::from_submit_outcome(outcome)
    }
}

/// Lossy conversion from `PresentOutcome` into `FrameSubmitOutcome`.
impl From<PresentOutcome> for FrameSubmitOutcome {
    /// Converts `outcome` into its corresponding `FrameSubmitOutcome` variant.
    ///
    /// # Arguments
    ///
    /// - `PresentOutcome` - Detailed present outcome.
    ///
    /// # Returns
    ///
    /// - `Self` - Equivalent `FrameSubmitOutcome`.
    fn from(outcome: PresentOutcome) -> Self {
        outcome.to_submit_outcome()
    }
}

/// Stage stamping and elapsed-millisecond breakdown helpers for `StartupTelemetry`.
impl StartupTelemetry {
    /// Creates a new `StartupTelemetry` anchored at process boot timestamp `t0_process_boot_ns`.
    ///
    /// # Arguments
    ///
    /// - `u64` - Monotonic process boot timestamp in nanoseconds.
    ///
    /// # Returns
    ///
    /// - `Self` - Initialized telemetry record with `t0_process_boot_ns` stamped.
    #[must_use]
    pub const fn with_boot_ns(t0_process_boot_ns: u64) -> Self {
        Self {
            t0_process_boot_ns,
            t1_runtime_ready_ns: STARTUP_TIMESTAMP_UNSET,
            t2_font_ready_ns: STARTUP_TIMESTAMP_UNSET,
            t3_mount_done_ns: STARTUP_TIMESTAMP_UNSET,
            t4_layout_done_ns: STARTUP_TIMESTAMP_UNSET,
            t5_paint_done_ns: STARTUP_TIMESTAMP_UNSET,
            t6_gpu_submit_ns: STARTUP_TIMESTAMP_UNSET,
            t7_first_present_ns: STARTUP_TIMESTAMP_UNSET,
        }
    }

    /// Computes a non-negative elapsed duration in milliseconds between two monotonic nanosecond timestamps.
    ///
    /// # Arguments
    ///
    /// - `u64` - Earlier monotonic timestamp in nanoseconds.
    /// - `u64` - Later monotonic timestamp in nanoseconds.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Elapsed milliseconds when both timestamps are recorded (`!= 0`) and `end_ns >= start_ns`.
    #[must_use]
    pub fn elapsed_ms_between(start_ns: u64, end_ns: u64) -> Option<f64> {
        if start_ns == STARTUP_TIMESTAMP_UNSET
            || end_ns == STARTUP_TIMESTAMP_UNSET
            || end_ns < start_ns
        {
            return None;
        }
        Some(((end_ns - start_ns) as f64) / TELEMETRY_NS_PER_MS)
    }

    /// Records the first-observed monotonic nanosecond timestamp for `stage` without overwriting an existing stamp.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Mutable startup telemetry record.
    /// - `StartupStage` - Milestone stage being stamped.
    /// - `u64` - Monotonic timestamp in nanoseconds.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when the timestamp was recorded; `false` if `timestamp_ns == 0` or the stage was already stamped.
    pub fn record_stage_once(&mut self, stage: StartupStage, timestamp_ns: u64) -> bool {
        if timestamp_ns == STARTUP_TIMESTAMP_UNSET {
            return false;
        }
        match stage {
            StartupStage::ProcessBoot => {
                if self.get_t0_process_boot_ns() != STARTUP_TIMESTAMP_UNSET {
                    return false;
                }
                self.set_t0_process_boot_ns(timestamp_ns);
            }
            StartupStage::RuntimeReady => {
                if self.get_t1_runtime_ready_ns() != STARTUP_TIMESTAMP_UNSET {
                    return false;
                }
                self.set_t1_runtime_ready_ns(timestamp_ns);
            }
            StartupStage::FontReady => {
                if self.get_t2_font_ready_ns() != STARTUP_TIMESTAMP_UNSET {
                    return false;
                }
                self.set_t2_font_ready_ns(timestamp_ns);
            }
            StartupStage::MountDone => {
                if self.get_t3_mount_done_ns() != STARTUP_TIMESTAMP_UNSET {
                    return false;
                }
                self.set_t3_mount_done_ns(timestamp_ns);
            }
            StartupStage::LayoutDone => {
                if self.get_t4_layout_done_ns() != STARTUP_TIMESTAMP_UNSET {
                    return false;
                }
                self.set_t4_layout_done_ns(timestamp_ns);
            }
            StartupStage::PaintDone => {
                if self.get_t5_paint_done_ns() != STARTUP_TIMESTAMP_UNSET {
                    return false;
                }
                self.set_t5_paint_done_ns(timestamp_ns);
            }
            StartupStage::GpuSubmit => {
                if self.get_t6_gpu_submit_ns() != STARTUP_TIMESTAMP_UNSET {
                    return false;
                }
                self.set_t6_gpu_submit_ns(timestamp_ns);
            }
            StartupStage::FirstPresent => {
                if self.get_t7_first_present_ns() != STARTUP_TIMESTAMP_UNSET {
                    return false;
                }
                self.set_t7_first_present_ns(timestamp_ns);
            }
        }
        true
    }

    /// Returns the recorded nanosecond timestamp for `stage`, if set.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    /// - `StartupStage` - Milestone stage to read.
    ///
    /// # Returns
    ///
    /// - `Option<u64>` - Recorded timestamp in nanoseconds, or `None` when unset.
    #[must_use]
    pub fn stage_timestamp_ns(&self, stage: StartupStage) -> Option<u64> {
        let raw: u64 = match stage {
            StartupStage::ProcessBoot => self.get_t0_process_boot_ns(),
            StartupStage::RuntimeReady => self.get_t1_runtime_ready_ns(),
            StartupStage::FontReady => self.get_t2_font_ready_ns(),
            StartupStage::MountDone => self.get_t3_mount_done_ns(),
            StartupStage::LayoutDone => self.get_t4_layout_done_ns(),
            StartupStage::PaintDone => self.get_t5_paint_done_ns(),
            StartupStage::GpuSubmit => self.get_t6_gpu_submit_ns(),
            StartupStage::FirstPresent => self.get_t7_first_present_ns(),
        };
        if raw == STARTUP_TIMESTAMP_UNSET {
            None
        } else {
            Some(raw)
        }
    }

    /// Returns `true` when both process boot (`t0`) and verified first present (`t7`) timestamps are recorded.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when full TTFF is available.
    #[must_use]
    pub fn is_complete(&self) -> bool {
        self.get_t0_process_boot_ns() != STARTUP_TIMESTAMP_UNSET
            && self.get_t7_first_present_ns() != STARTUP_TIMESTAMP_UNSET
            && self.get_t7_first_present_ns() >= self.get_t0_process_boot_ns()
    }

    /// Returns total cold-start time-to-first-frame (`t7 - t0`) in milliseconds.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Total TTFF in milliseconds.
    #[must_use]
    pub fn total_ttff_ms(&self) -> Option<f64> {
        Self::elapsed_ms_between(
            self.get_t0_process_boot_ns(),
            self.get_t7_first_present_ns(),
        )
    }

    /// Returns runtime and renderer initialization duration (`t1 - t0`) in milliseconds.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Runtime ready duration in milliseconds.
    #[must_use]
    pub fn runtime_ready_ms(&self) -> Option<f64> {
        Self::elapsed_ms_between(
            self.get_t0_process_boot_ns(),
            self.get_t1_runtime_ready_ns(),
        )
    }

    /// Returns default font initialization duration (`t2 - t1`) in milliseconds.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Font ready stage duration in milliseconds.
    #[must_use]
    pub fn font_ready_ms(&self) -> Option<f64> {
        Self::elapsed_ms_between(self.get_t1_runtime_ready_ns(), self.get_t2_font_ready_ns())
    }

    /// Returns initial route scene mount duration (`t3 - t2`) in milliseconds.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Initial mount duration in milliseconds.
    #[must_use]
    pub fn mount_ms(&self) -> Option<f64> {
        Self::elapsed_ms_between(self.get_t2_font_ready_ns(), self.get_t3_mount_done_ns())
    }

    /// Returns initial layout pass duration (`t4 - t3`) in milliseconds.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - First layout pass duration in milliseconds.
    #[must_use]
    pub fn layout_ms(&self) -> Option<f64> {
        Self::elapsed_ms_between(self.get_t3_mount_done_ns(), self.get_t4_layout_done_ns())
    }

    /// Returns initial display list paint and visible glyph upload duration (`t5 - t4`) in milliseconds.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - First paint stage duration in milliseconds.
    #[must_use]
    pub fn paint_ms(&self) -> Option<f64> {
        Self::elapsed_ms_between(self.get_t4_layout_done_ns(), self.get_t5_paint_done_ns())
    }

    /// Returns first GPU/surface draw submission duration (`t6 - t5`) in milliseconds.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - First submit stage duration in milliseconds.
    #[must_use]
    pub fn gpu_submit_ms(&self) -> Option<f64> {
        Self::elapsed_ms_between(self.get_t5_paint_done_ns(), self.get_t6_gpu_submit_ns())
    }

    /// Returns verified first presentation latency (`t7 - t6`) in milliseconds.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - First present stage duration in milliseconds.
    #[must_use]
    pub fn first_present_ms(&self) -> Option<f64> {
        Self::elapsed_ms_between(self.get_t6_gpu_submit_ns(), self.get_t7_first_present_ns())
    }

    /// Returns cumulative elapsed milliseconds from `t0` to `stage`.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Startup telemetry reference.
    /// - `StartupStage` - Target milestone stage.
    ///
    /// # Returns
    ///
    /// - `Option<f64>` - Elapsed milliseconds since `t0_process_boot_ns`.
    #[must_use]
    pub fn elapsed_since_boot_ms(&self, stage: StartupStage) -> Option<f64> {
        let stage_ns: u64 = self.stage_timestamp_ns(stage)?;
        Self::elapsed_ms_between(self.get_t0_process_boot_ns(), stage_ns)
    }
}