diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2020-05-01 23:57:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-01 20:57:25 +0000 |
commit | 38d20d0c391c250953ce3c72a35c8d1156f06000 (patch) | |
tree | de0871a1200076cd1f647f3a5b525b52d834bc37 | |
parent | 6b45780f3afa23e9e4277bf43e6bf381172fa1ea (diff) | |
download | alacritty-38d20d0c391c250953ce3c72a35c8d1156f06000.tar.gz alacritty-38d20d0c391c250953ce3c72a35c8d1156f06000.zip |
Call glFinish right after swap_buffers on X11
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.
Calling `glFinish` after swapping buffers forces Alacritty to finish the buffer
swap before returning control to the event loop.
Fixes #3061.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | alacritty/src/display.rs | 26 | ||||
-rw-r--r-- | alacritty/src/renderer/mod.rs | 6 |
3 files changed, 32 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index cbe1ab17..4534989b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Tabstops not being reset with `reset` - Selection not cleared when switching between main and alt grid - Fallback to `LC_CTYPE=UTF-8` on macOS without valid system locale +- Resize lag on launch under some X11 wms +- Increased input latency due to vsync behavior on X11 ## 0.4.2 diff --git a/alacritty/src/display.rs b/alacritty/src/display.rs index eafab8c2..980b0ea0 100644 --- a/alacritty/src/display.rs +++ b/alacritty/src/display.rs @@ -118,6 +118,8 @@ pub struct Display { renderer: QuadRenderer, glyph_cache: GlyphCache, meter: Meter, + #[cfg(not(any(target_os = "macos", windows)))] + is_x11: bool, } impl Display { @@ -198,14 +200,20 @@ impl Display { api.clear(background_color); }); + #[cfg(not(any(target_os = "macos", windows)))] + let is_x11 = event_loop.is_x11(); + // We should call `clear` when window is offscreen, so when `window.show()` happens it // would be with background color instead of uninitialized surface. #[cfg(not(any(target_os = "macos", windows)))] { // On Wayland we can safely ignore this call, since the window isn't visible until you // actually draw something into it. - if event_loop.is_x11() { - window.swap_buffers() + if is_x11 { + window.swap_buffers(); + renderer.with_api(&config, &size_info, |api| { + api.finish(); + }); } } @@ -237,6 +245,8 @@ impl Display { size_info, urls: Urls::new(), highlighted_url: None, + #[cfg(not(any(target_os = "macos", windows)))] + is_x11, }) } @@ -499,6 +509,18 @@ impl Display { } self.window.swap_buffers(); + + #[cfg(not(any(target_os = "macos", windows)))] + { + if self.is_x11 { + // 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. + self.renderer.with_api(&config, &size_info, |api| { + api.finish(); + }); + } + } } } diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index 764b5ec5..f62e6f8d 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -923,6 +923,12 @@ impl<'a, C> RenderApi<'a, C> { } } + pub fn finish(&self) { + unsafe { + gl::Finish(); + } + } + fn render_batch(&mut self) { unsafe { gl::BufferSubData( |