gbm: split out clear_framebuffers

This commit is contained in:
Victor Brekenfeld 2020-05-03 16:53:02 +02:00
parent eaa3a0ca87
commit 0a716438e3
1 changed files with 12 additions and 28 deletions

View File

@ -106,6 +106,17 @@ impl<D: RawDevice + 'static> GbmSurfaceInternal<D> {
.map_err(Error::SurfaceCreationFailed)?; .map_err(Error::SurfaceCreationFailed)?;
// Clean up buffers // 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 Some(Ok(Some(fb))) = self.next_buffer.take().map(|mut bo| bo.take_userdata()) {
if let Err(err) = self.crtc.destroy_framebuffer(fb) { if let Err(err) = self.crtc.destroy_framebuffer(fb) {
warn!( warn!(
@ -123,13 +134,6 @@ impl<D: RawDevice + 'static> GbmSurfaceInternal<D> {
); );
} }
} }
// Drop the old surface after cleanup
*self.surface.borrow_mut() = surface;
self.recreated.set(true);
Ok(())
} }
} }
@ -228,27 +232,7 @@ impl<D: RawDevice + 'static> Drop for GbmSurfaceInternal<D> {
fn drop(&mut self) { fn drop(&mut self) {
// Drop framebuffers attached to the userdata of the gbm surface buffers. // Drop framebuffers attached to the userdata of the gbm surface buffers.
// (They don't implement drop, as they need the device) // (They don't implement drop, as they need the device)
if let Ok(Some(fb)) = { self.clear_framebuffers();
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);
}
} }
} }