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(); } }