From 64c535464af39c654f496fd5731ae186cd990fdb Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Tue, 28 Dec 2021 13:06:11 +0100 Subject: [PATCH] swapchain: Keep buffers on reset and wipe metadata We make no guarantees about the buffer contents after a fresh allocation in smithay anyway, so to avoid expensive recreation of a bunch of resources, try to keep the buffers on reset and just wipe all its metadata (most importantly the age). --- src/backend/allocator/swapchain.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/backend/allocator/swapchain.rs b/src/backend/allocator/swapchain.rs index 0603cc9..60783bf 100644 --- a/src/backend/allocator/swapchain.rs +++ b/src/backend/allocator/swapchain.rs @@ -196,6 +196,15 @@ where /// Remove all internally cached buffers to e.g. reset age values pub fn reset_buffers(&mut self) { - self.slots = Default::default(); + for slot in &mut self.slots { + if let Some(internal_slot) = Arc::get_mut(slot) { + *internal_slot = InternalSlot { + buffer: internal_slot.buffer.take(), + ..Default::default() + }; + } else { + *slot = Default::default(); + } + } } }