From 375d7da2f28fbd734b235e2775b859f8df2773e1 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 1 Jun 2022 22:24:57 +0200 Subject: [PATCH] cursor: don't overwrite busy hardware buffers --- src/backends/metal/video.rs | 7 ++++++- src/ifs/wl_surface.rs | 1 + src/ifs/wl_surface/cursor.rs | 9 ++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/backends/metal/video.rs b/src/backends/metal/video.rs index 5a841809..233926da 100644 --- a/src/backends/metal/video.rs +++ b/src/backends/metal/video.rs @@ -178,6 +178,7 @@ pub struct MetalConnector { pub cursor_enabled: Cell, pub cursor_buffers: CloneCell>>, pub cursor_front_buffer: NumCell, + pub cursor_swap_buffer: Cell, } #[derive(Debug)] @@ -228,7 +229,7 @@ impl HardwareCursor for MetalHardwareCursor { self.connector.cursor_x.set(self.cursor_x_pending.get()); self.connector.cursor_y.set(self.cursor_y_pending.get()); if self.cursor_swap_buffer.take() { - self.connector.cursor_front_buffer.fetch_add(1); + self.connector.cursor_swap_buffer.set(true); } self.connector.cursor_changed.set(true); if self.connector.can_present.get() { @@ -363,6 +364,9 @@ impl MetalConnector { if self.cursor_changed.get() && cursor.is_some() { let plane = cursor.unwrap(); if self.cursor_enabled.get() { + if self.cursor_swap_buffer.take() { + self.cursor_front_buffer.fetch_add(1); + } let buffers = self.cursor_buffers.get().unwrap(); let buffer = &buffers[self.cursor_front_buffer.get() % buffers.len()]; changes.change_object(plane.id, |c| { @@ -545,6 +549,7 @@ fn create_connector( connect_sent: Cell::new(false), cursor_changed: Cell::new(false), cursor_front_buffer: Default::default(), + cursor_swap_buffer: Cell::new(false), }); let futures = ConnectorFutures { present: backend diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index 6f1049f2..d89b5b79 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -832,6 +832,7 @@ impl WlSurface { if buffer_changed || transform_changed { for (_, cursor) in &self.cursors { cursor.handle_buffer_change(); + cursor.update_hardware_cursor(); } } ext.post_commit(); diff --git a/src/ifs/wl_surface/cursor.rs b/src/ifs/wl_surface/cursor.rs index 6df8b60f..146a4695 100644 --- a/src/ifs/wl_surface/cursor.rs +++ b/src/ifs/wl_surface/cursor.rs @@ -34,9 +34,6 @@ impl CursorSurface { let (hot_x, hot_y) = self.hotspot.get(); self.extents .set(self.surface.extents.get().move_(-hot_x, -hot_y)); - if self.seat.hardware_cursor() { - self.seat.update_hardware_cursor(); - } } pub fn handle_surface_destroy(&self) { @@ -57,6 +54,12 @@ impl CursorSurface { self.hotspot.set((hot_x - hotspot_dx, hot_y - hotspot_dy)); self.update_extents(); } + + pub fn update_hardware_cursor(&self) { + if self.seat.hardware_cursor() { + self.seat.update_hardware_cursor(); + } + } } impl Cursor for CursorSurface {