From 0a716438e394ab9d8018b8b2bed865e7c153cd45 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sun, 3 May 2020 16:53:02 +0200 Subject: [PATCH] gbm: split out clear_framebuffers --- src/backend/drm/gbm/surface.rs | 40 ++++++++++------------------------ 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/backend/drm/gbm/surface.rs b/src/backend/drm/gbm/surface.rs index 1668d17..80bcaf8 100644 --- a/src/backend/drm/gbm/surface.rs +++ b/src/backend/drm/gbm/surface.rs @@ -106,6 +106,17 @@ impl GbmSurfaceInternal { .map_err(Error::SurfaceCreationFailed)?; // Clean up buffers + self.clear_framebuffers(); + + // Drop the old surface after cleanup + *self.surface.borrow_mut() = surface; + + self.recreated.set(true); + + Ok(()) + } + + pub fn clear_framebuffers(&self) { if let Some(Ok(Some(fb))) = self.next_buffer.take().map(|mut bo| bo.take_userdata()) { if let Err(err) = self.crtc.destroy_framebuffer(fb) { warn!( @@ -123,13 +134,6 @@ impl GbmSurfaceInternal { ); } } - - // Drop the old surface after cleanup - *self.surface.borrow_mut() = surface; - - self.recreated.set(true); - - Ok(()) } } @@ -228,27 +232,7 @@ impl Drop for GbmSurfaceInternal { fn drop(&mut self) { // Drop framebuffers attached to the userdata of the gbm surface buffers. // (They don't implement drop, as they need the device) - if let Ok(Some(fb)) = { - if let Some(mut next) = self.next_buffer.take() { - next.take_userdata() - } else { - Ok(None) - } - } { - // ignore failure at this point - let _ = self.crtc.destroy_framebuffer(fb); - } - - if let Ok(Some(fb)) = { - if let Some(mut next) = self.front_buffer.take() { - next.take_userdata() - } else { - Ok(None) - } - } { - // ignore failure at this point - let _ = self.crtc.destroy_framebuffer(fb); - } + self.clear_framebuffers(); } }