diff --git a/src/backend/allocator/swapchain.rs b/src/backend/allocator/swapchain.rs index 60783bf..1a385cf 100644 --- a/src/backend/allocator/swapchain.rs +++ b/src/backend/allocator/swapchain.rs @@ -154,11 +154,13 @@ where /// Mark a given buffer as submitted. /// /// This might effect internal data (e.g. buffer age) and may only be called, - /// if the buffer was actually used for display. + /// the buffer may not be used for rendering anymore. + /// You may hold on to it, if you require keeping it alive. + /// /// Buffers can always just be safely discarded by dropping them, but not - /// calling this function may affect performance characteristics + /// calling this function before may affect performance characteristics /// (e.g. by not tracking the buffer age). - pub fn submitted(&self, slot: Slot) { + pub fn submitted(&self, slot: &Slot) { // don't mess up the state, if the user submitted and old buffer, after e.g. a resize if !self.slots.iter().any(|other| Arc::ptr_eq(&slot.0, other)) { return; @@ -167,7 +169,7 @@ where slot.0.age.store(1, Ordering::SeqCst); for other_slot in &self.slots { if !Arc::ptr_eq(other_slot, &slot.0) && other_slot.buffer.is_some() { - assert!(other_slot + let res = other_slot .age .fetch_update(Ordering::SeqCst, Ordering::SeqCst, |age| { if age > 0 { @@ -175,8 +177,8 @@ where } else { Some(0) } - }) - .is_ok()); + }); + assert!(res.is_ok()); } } } diff --git a/src/backend/drm/surface/gbm.rs b/src/backend/drm/surface/gbm.rs index d5d646e..7fc16c5 100644 --- a/src/backend/drm/surface/gbm.rs +++ b/src/backend/drm/surface/gbm.rs @@ -213,7 +213,6 @@ where pub fn frame_submitted(&mut self) -> Result<(), Error> { if let Some(mut pending) = self.pending_fb.take() { std::mem::swap(&mut pending, &mut self.current_fb); - self.swapchain.submitted(pending); if self.queued_fb.is_some() { self.submit()?; } @@ -233,6 +232,7 @@ where self.drm.page_flip([(fb, self.drm.plane())].iter(), true) }; if flip.is_ok() { + self.swapchain.submitted(&slot); self.pending_fb = Some(slot); } flip.map_err(Error::DrmError) diff --git a/src/backend/x11/surface.rs b/src/backend/x11/surface.rs index 5a3a2a8..4d8f9ba 100644 --- a/src/backend/x11/surface.rs +++ b/src/backend/x11/surface.rs @@ -123,7 +123,7 @@ impl X11Surface { // Now present the current buffer let _ = pixmap.present(&*connection, window.as_ref())?; - self.swapchain.submitted(next); + self.swapchain.submitted(&next); // Flush the connection after presenting to the window to ensure we don't run out of buffer space in the X11 connection. let _ = connection.flush();