Skip to main content

par_term_render/cell_renderer/
surface.rs

1use super::CellRenderer;
2
3impl CellRenderer {
4    pub fn reconfigure_surface(&mut self) {
5        self.surface.configure(&self.device, &self.config);
6    }
7
8    /// Get the list of supported present modes for this surface
9    pub fn supported_present_modes(&self) -> &[wgpu::PresentMode] {
10        &self.supported_present_modes
11    }
12
13    /// Check if a vsync mode is supported
14    pub fn is_vsync_mode_supported(&self, mode: par_term_config::VsyncMode) -> bool {
15        self.supported_present_modes
16            .contains(&mode.to_present_mode())
17    }
18
19    /// Update the vsync mode. Returns the actual mode applied (may differ if requested mode unsupported).
20    /// Also returns whether the mode was changed.
21    pub fn update_vsync_mode(
22        &mut self,
23        mode: par_term_config::VsyncMode,
24    ) -> (par_term_config::VsyncMode, bool) {
25        let requested = mode.to_present_mode();
26        let current = self.config.present_mode;
27
28        // Determine the actual mode to use
29        let actual = if self.supported_present_modes.contains(&requested) {
30            requested
31        } else {
32            log::warn!(
33                "Requested present mode {:?} not supported, falling back to Fifo",
34                requested
35            );
36            wgpu::PresentMode::Fifo
37        };
38
39        // Only reconfigure if the mode actually changed
40        if actual != current {
41            self.config.present_mode = actual;
42            self.surface.configure(&self.device, &self.config);
43            log::info!("VSync mode changed to {:?}", actual);
44        }
45
46        // Convert back to VsyncMode for return
47        let actual_vsync = match actual {
48            wgpu::PresentMode::Immediate => par_term_config::VsyncMode::Immediate,
49            wgpu::PresentMode::Mailbox => par_term_config::VsyncMode::Mailbox,
50            wgpu::PresentMode::Fifo | wgpu::PresentMode::FifoRelaxed => {
51                par_term_config::VsyncMode::Fifo
52            }
53            _ => par_term_config::VsyncMode::Fifo,
54        };
55
56        (actual_vsync, actual != current)
57    }
58
59    /// Get the current vsync mode
60    pub fn current_vsync_mode(&self) -> par_term_config::VsyncMode {
61        match self.config.present_mode {
62            wgpu::PresentMode::Immediate => par_term_config::VsyncMode::Immediate,
63            wgpu::PresentMode::Mailbox => par_term_config::VsyncMode::Mailbox,
64            wgpu::PresentMode::Fifo | wgpu::PresentMode::FifoRelaxed => {
65                par_term_config::VsyncMode::Fifo
66            }
67            _ => par_term_config::VsyncMode::Fifo,
68        }
69    }
70}