diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-07-13 11:06:54 +0400 |
---|---|---|
committer | Kirill Chibisov <contact@kchibisov.com> | 2023-09-04 03:01:12 +0400 |
commit | a189861880aafcce760e3a142bc2d391f2801f64 (patch) | |
tree | 5a9e82c1577ef60deb328e369cf56122f2088933 /alacritty/src/display/mod.rs | |
parent | bbc02004b85c8b2c0c65c7031527fded4efe6c04 (diff) | |
download | r-alacritty-a189861880aafcce760e3a142bc2d391f2801f64.tar.gz r-alacritty-a189861880aafcce760e3a142bc2d391f2801f64.tar.bz2 r-alacritty-a189861880aafcce760e3a142bc2d391f2801f64.zip |
Update winit to 0.29.1-beta
Make use of new winit frame throttling mechanism used in RedrawRequested,
which removes the need for having Wayland queue to ask for the frame
callbacks.
Fixes #7011.
Diffstat (limited to 'alacritty/src/display/mod.rs')
-rw-r--r-- | alacritty/src/display/mod.rs | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs index c992e9cc..4037cd2e 100644 --- a/alacritty/src/display/mod.rs +++ b/alacritty/src/display/mod.rs @@ -6,7 +6,6 @@ use std::fmt::{self, Formatter}; use std::mem::{self, ManuallyDrop}; use std::num::NonZeroU32; use std::ops::{Deref, DerefMut}; -use std::sync::atomic::Ordering; use std::time::{Duration, Instant}; use glutin::context::{NotCurrentContext, PossiblyCurrentContext}; @@ -15,10 +14,10 @@ use glutin::surface::{Rect as DamageRect, Surface, SwapInterval, WindowSurface}; use log::{debug, info}; use parking_lot::MutexGuard; -use raw_window_handle::RawWindowHandle; use serde::{Deserialize, Serialize}; use winit::dpi::PhysicalSize; use winit::keyboard::ModifiersState; +use winit::window::raw_window_handle::RawWindowHandle; use winit::window::CursorIcon; use crossfont::{self, Rasterize, Rasterizer}; @@ -347,7 +346,7 @@ pub struct Display { /// Hint highlighted by the vi mode cursor. pub vi_highlighted_hint: Option<HintMatch>, - pub is_wayland: bool, + pub raw_window_handle: RawWindowHandle, /// UI cursor visibility for blinking. pub cursor_hidden: bool, @@ -394,7 +393,7 @@ impl Display { gl_context: NotCurrentContext, config: &UiConfig, ) -> Result<Display, Error> { - let is_wayland = matches!(window.raw_window_handle(), RawWindowHandle::Wayland(_)); + let raw_window_handle = window.raw_window_handle(); let scale_factor = window.scale_factor as f32; let rasterizer = Rasterizer::new(scale_factor)?; @@ -408,7 +407,7 @@ impl Display { // Resize the window to account for the user configured size. if let Some(dimensions) = config.window.dimensions() { let size = window_size(config, dimensions, cell_width, cell_height, scale_factor); - window.set_inner_size(size); + window.request_inner_size(size); } // Create the GL surface to draw into. @@ -459,9 +458,10 @@ impl Display { #[cfg(target_os = "macos")] window.set_has_shadow(config.window_opacity() >= 1.0); + let is_wayland = matches!(raw_window_handle, RawWindowHandle::Wayland(_)); + // On Wayland we can safely ignore this call, since the window isn't visible until you // actually draw something into it and commit those changes. - #[cfg(not(any(target_os = "macos", windows)))] if !is_wayland { surface.swap_buffers(&context).expect("failed to swap buffers."); renderer.finish(); @@ -479,7 +479,6 @@ impl Display { match config.window.startup_mode { #[cfg(target_os = "macos")] StartupMode::SimpleFullscreen => window.set_simple_fullscreen(true), - #[cfg(not(any(target_os = "macos", windows)))] StartupMode::Maximized if !is_wayland => window.set_maximized(true), _ => (), } @@ -511,7 +510,6 @@ impl Display { ime: Ime::new(), highlighted_hint: None, vi_highlighted_hint: None, - is_wayland, cursor_hidden: false, frame_timer: FrameTimer::new(), visual_bell: VisualBell::from(&config.bell), @@ -520,6 +518,7 @@ impl Display { pending_renderer_update: Default::default(), debug_damage, damage_rects, + raw_window_handle, next_frame_damage_rects, hint_mouse_point: None, }) @@ -552,7 +551,8 @@ impl Display { let res = match (self.surface.deref(), &self.context.get()) { #[cfg(not(any(target_os = "macos", windows)))] (Surface::Egl(surface), PossiblyCurrentContext::Egl(context)) - if self.is_wayland && !self.debug_damage => + if matches!(self.raw_window_handle, RawWindowHandle::Wayland(_)) + && !self.debug_damage => { surface.swap_buffers_with_damage(context, &self.damage_rects) }, @@ -972,17 +972,13 @@ impl Display { self.draw_hyperlink_preview(config, cursor_point, display_offset); } - // Frame event should be requested before swapping buffers on Wayland, since it requires - // surface `commit`, which is done by swap buffers under the hood. - if self.is_wayland { - self.request_frame(scheduler); - } + // Notify winit that we're about to present. + self.window.pre_present_notify(); // Clearing debug highlights from the previous frame requires full redraw. self.swap_buffers(); - #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))] - if !self.is_wayland { + if matches!(self.raw_window_handle, RawWindowHandle::Xcb(_) | RawWindowHandle::Xlib(_)) { // On X11 `swap_buffers` does not block for vsync. However the next OpenGl command // will block to synchronize (this is `glClear` in Alacritty), which causes a // permanent one frame delay. @@ -991,7 +987,10 @@ impl Display { // XXX: Request the new frame after swapping buffers, so the // time to finish OpenGL operations is accounted for in the timeout. - if !self.is_wayland { + if matches!( + self.raw_window_handle, + RawWindowHandle::AppKit(_) | RawWindowHandle::Xlib(_) | RawWindowHandle::Xcb(_) + ) { self.request_frame(scheduler); } @@ -1364,7 +1363,7 @@ impl Display { /// Returns `true` if damage information should be collected, `false` otherwise. #[inline] fn collect_damage(&self) -> bool { - self.is_wayland || self.debug_damage + matches!(self.raw_window_handle, RawWindowHandle::Wayland(_)) || self.debug_damage } /// Highlight damaged rects. @@ -1385,18 +1384,7 @@ impl Display { /// Requst a new frame for a window on Wayland. fn request_frame(&mut self, scheduler: &mut Scheduler) { // Mark that we've used a frame. - self.window.has_frame.store(false, Ordering::Relaxed); - - #[cfg(all(feature = "wayland", not(any(target_os = "macos", windows))))] - if let Some(surface) = self.window.wayland_surface() { - let has_frame = self.window.has_frame.clone(); - // Request a new frame. - surface.frame().quick_assign(move |_, _, _| { - has_frame.store(true, Ordering::Relaxed); - }); - - return; - } + self.window.has_frame = false; // Get the display vblank interval. let monitor_vblank_interval = 1_000_000. |