Skip to main content

argui_inspect/
frames.rs

1use crate::{FrameRecord, InspectorHandle};
2
3/// Position of a frontend snapshot in the bounded recording history.
4#[derive(Clone, Copy, Debug, Default)]
5pub struct FrameCursor {
6    sequence: u64,
7    epoch: u64,
8}
9
10impl InspectorHandle {
11    /// Enables detailed renderer measurements independently of tree inspection.
12    pub fn set_gpu_profiling(&self, enabled: bool) {
13        self.0.borrow_mut().gpu_profiling = enabled;
14    }
15
16    #[must_use]
17    pub fn gpu_profiling(&self) -> bool {
18        let state = self.0.borrow();
19        state.gpu_profiling && state.recording && !state.paused
20    }
21
22    /// Synchronizes new frames and delayed render results without cloning unchanged records.
23    pub fn sync_frames(
24        &self,
25        destination: &mut Vec<FrameRecord>,
26        cursor: &mut FrameCursor,
27    ) -> bool {
28        let state = self.0.borrow();
29        let added = if cursor.epoch == state.frame_epoch {
30            state
31                .frame_sequence
32                .wrapping_sub(cursor.sequence)
33                .min(usize::MAX as u64) as usize
34        } else {
35            state.frames.len()
36        };
37        let retained = destination
38            .len()
39            .min(state.frames.len().saturating_sub(added));
40        let removed = destination.len() - retained;
41        let mut changed = removed > 0 || destination.len() != state.frames.len() || added > 0;
42        destination.drain(..removed);
43        for (existing, recorded) in destination.iter_mut().zip(&state.frames) {
44            if existing != recorded {
45                existing.clone_from(recorded);
46                changed = true;
47            }
48        }
49        destination.extend(state.frames.iter().skip(retained).cloned());
50        cursor.sequence = state.frame_sequence;
51        cursor.epoch = state.frame_epoch;
52        changed
53    }
54
55    /// Whether tree inspection is attached, independently of recording pause.
56    #[must_use]
57    pub fn enabled(&self) -> bool {
58        self.0.borrow().recording
59    }
60}