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
use cranpose_render_common::Renderer;
use cranpose_ui::request_render_invalidation;
use crate::AppShell;
/// How the shell paces its frames against the display.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum FramePacingMode {
/// Pace frames to the display refresh interval. The production default:
/// animations advance once per vsync instead of re-rendering uncapped.
#[default]
Vsync,
/// Cap frames at 60 per second with a timer, whatever the display refresh rate is.
Hard60,
/// Cap frames at 120 per second with a timer, whatever the display refresh rate is.
Hard120,
/// Render as fast as possible. For perf harnesses and robot drivers that
/// measure work throughput; saturates the GPU if used in a real app.
NoVsync,
}
impl FramePacingMode {
/// Every pacing mode, in the order the dev overlay lists them.
pub const ALL: [Self; 4] = [Self::Vsync, Self::Hard60, Self::Hard120, Self::NoVsync];
/// Returns the short name the dev overlay shows for this mode.
pub fn label(self) -> &'static str {
match self {
Self::Vsync => "VSync",
Self::Hard60 => "60fps",
Self::Hard120 => "120fps",
Self::NoVsync => "NoVSync",
}
}
/// Returns the frames per second this mode caps at with a timer, or `None` when the mode sets
/// no cap.
pub fn target_fps(self) -> Option<u32> {
match self {
Self::Hard60 => Some(60),
Self::Hard120 => Some(120),
Self::Vsync | Self::NoVsync => None,
}
}
}
/// Development options for debugging and performance monitoring.
///
/// These are rendered directly by the renderer (not via composition)
/// to avoid affecting performance measurements.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct DevOptions {
/// Show FPS counter overlay
pub fps_counter: bool,
/// Show recomposition count
pub recomposition_counter: bool,
/// Show layout timing breakdown
pub layout_timing: bool,
/// Show buttons in the dev overlay that switch the frame pacing mode.
pub frame_pacing_controls: bool,
/// How the shell paces its frames.
pub frame_pacing_mode: FramePacingMode,
}
#[expect(clippy::multiple_inherent_impl, reason = "one file per shell concern")]
impl<R: Renderer> AppShell<R>
where
R::Error: std::fmt::Debug,
{
/// Set development options for debugging and performance monitoring.
///
/// The FPS counter and other overlays are rendered directly by the renderer
/// (not via composition) to avoid affecting performance measurements.
pub fn set_dev_options(&mut self, options: DevOptions) {
if self.app.dev_options == options {
return;
}
self.app.dev_options = options;
self.invalidate_dev_overlay_text();
self.app.app_context.enter(request_render_invalidation);
self.mark_all_dirty();
}
/// Get a reference to the current dev options.
pub fn dev_options(&self) -> &DevOptions {
&self.app.dev_options
}
/// Returns the frame pacing mode set in the dev options.
pub fn frame_pacing_mode(&self) -> FramePacingMode {
self.app.dev_options.frame_pacing_mode
}
/// Sets the frame pacing mode and redraws the dev overlay. Platforms read the mode back with
/// `frame_pacing_mode`.
pub fn set_frame_pacing_mode(&mut self, mode: FramePacingMode) {
if self.app.dev_options.frame_pacing_mode == mode {
return;
}
self.app.dev_options.frame_pacing_mode = mode;
self.invalidate_dev_overlay_text();
self.app.app_context.enter(request_render_invalidation);
self.mark_all_dirty();
}
}