par_term_render/cell_renderer/
surface.rs1use super::CellRenderer;
2use crate::wgpu_conversions::VsyncModeWgpu;
3
4impl CellRenderer {
5 pub fn reconfigure_surface(&mut self) {
6 self.surface.configure(&self.device, &self.config);
7 }
8
9 pub fn supported_present_modes(&self) -> &[wgpu::PresentMode] {
11 &self.supported_present_modes
12 }
13
14 pub fn is_vsync_mode_supported(&self, mode: par_term_config::VsyncMode) -> bool {
16 self.supported_present_modes
17 .contains(&mode.to_present_mode())
18 }
19
20 pub fn update_vsync_mode(
23 &mut self,
24 mode: par_term_config::VsyncMode,
25 ) -> (par_term_config::VsyncMode, bool) {
26 let requested = mode.to_present_mode();
27 let current = self.config.present_mode;
28
29 let actual = if self.supported_present_modes.contains(&requested) {
31 requested
32 } else {
33 log::warn!(
34 "Requested present mode {:?} not supported, falling back to Fifo",
35 requested
36 );
37 wgpu::PresentMode::Fifo
38 };
39
40 if actual != current {
42 self.config.present_mode = actual;
43 self.surface.configure(&self.device, &self.config);
44 log::info!("VSync mode changed to {:?}", actual);
45 }
46
47 let actual_vsync = match actual {
49 wgpu::PresentMode::Immediate => par_term_config::VsyncMode::Immediate,
50 wgpu::PresentMode::Mailbox => par_term_config::VsyncMode::Mailbox,
51 wgpu::PresentMode::Fifo | wgpu::PresentMode::FifoRelaxed => {
52 par_term_config::VsyncMode::Fifo
53 }
54 _ => par_term_config::VsyncMode::Fifo,
55 };
56
57 (actual_vsync, actual != current)
58 }
59
60 pub fn current_vsync_mode(&self) -> par_term_config::VsyncMode {
62 match self.config.present_mode {
63 wgpu::PresentMode::Immediate => par_term_config::VsyncMode::Immediate,
64 wgpu::PresentMode::Mailbox => par_term_config::VsyncMode::Mailbox,
65 wgpu::PresentMode::Fifo | wgpu::PresentMode::FifoRelaxed => {
66 par_term_config::VsyncMode::Fifo
67 }
68 _ => par_term_config::VsyncMode::Fifo,
69 }
70 }
71}