Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui_linux: Fix Wayland flickering under CPU load by skipping redundant surface commit (#54214)
b5l923f315f2621
diff --git a/crates/gpui_linux/src/linux/wayland/window.rs b/crates/gpui_linux/src/linux/wayland/window.rsindex 857289a1d97..37d0f492d25 100644--- a/crates/gpui_linux/src/linux/wayland/window.rs+++ b/crates/gpui_linux/src/linux/wayland/window.rs@@ -117,6 +117,7 @@ pub struct WaylandWindowState {active: bool,hovered: bool,pub(crate) force_render_after_recovery: bool,+ renderer_presented: bool,in_progress_configure: Option<InProgressConfigure>,resize_throttle: bool,in_progress_window_controls: Option<WindowControls>,@@ -392,6 +393,7 @@ impl WaylandWindowState {active: false,hovered: false,force_render_after_recovery: false,+ renderer_presented: false,in_progress_window_controls: None,window_controls: WindowControls::default(),client_inset: None,@@ -1398,7 +1400,7 @@ impl PlatformWindow for WaylandWindow {return;}- state.renderer.draw(scene);+ state.renderer_presented = state.renderer.draw(scene);if state.renderer.needs_redraw() {state.force_render_after_recovery = true;@@ -1406,8 +1408,15 @@ impl PlatformWindow for WaylandWindow {}fn completed_frame(&self) {- let state = self.borrow();- state.surface.commit();+ let mut state = self.borrow_mut();++ // Work around a bug in old versions of wlroots where committing without a buffer attached+ // can cause invalid synchronization that leads to graphical corruption.+ if !state.renderer_presented {+ state.surface.commit();+ }++ state.renderer_presented = false;}fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> {diff --git a/crates/gpui_wgpu/src/wgpu_renderer.rs b/crates/gpui_wgpu/src/wgpu_renderer.rsindex da7e71c726b..08f30dc0090 100644--- a/crates/gpui_wgpu/src/wgpu_renderer.rs+++ b/crates/gpui_wgpu/src/wgpu_renderer.rs@@ -1079,13 +1079,13 @@ impl WgpuRenderer {self.max_texture_size}- pub fn draw(&mut self, scene: &Scene) {+ pub fn draw(&mut self, scene: &Scene) -> bool {// Bail out early if the surface has been unconfigured (e.g. during// Android background/rotation transitions). Attempting to acquire// a texture from an unconfigured surface can block indefinitely on// some drivers (Adreno).if !self.surface_configured {- return;+ return false;}let last_error = self.last_error.lock().unwrap().take();@@ -1106,7 +1106,7 @@ impl WgpuRenderer {self.atlas.clear();self.needs_redraw = true;self.failed_frame_count = 0;- return;+ return false;}} else {self.failed_frame_count = 0;@@ -1124,7 +1124,7 @@ impl WgpuRenderer {resources.surface.configure(&resources.device, &surface_config);- return;+ return false;}wgpu::CurrentSurfaceTexture::Lost | wgpu::CurrentSurfaceTexture::Outdated => {let surface_config = self.surface_config.clone();@@ -1132,15 +1132,15 @@ impl WgpuRenderer {resources.surface.configure(&resources.device, &surface_config);- return;+ return false;}wgpu::CurrentSurfaceTexture::Timeout | wgpu::CurrentSurfaceTexture::Occluded => {- return;+ return false;}wgpu::CurrentSurfaceTexture::Validation => {*self.last_error.lock().unwrap() =Some("Surface texture validation error".to_string());- return;+ return false;}};@@ -1321,7 +1321,7 @@ impl WgpuRenderer {self.instance_buffer_capacity);frame.present();- return;+ return true;}self.grow_instance_buffer();continue;@@ -1331,7 +1331,7 @@ impl WgpuRenderer {.queue.submit(std::iter::once(encoder.finish()));frame.present();- return;+ return true;}}