diff --git a/src/backend/drm/atomic/surface.rs b/src/backend/drm/atomic/surface.rs index d756fba..b35735d 100644 --- a/src/backend/drm/atomic/surface.rs +++ b/src/backend/drm/atomic/surface.rs @@ -44,7 +44,7 @@ pub(super) struct AtomicDrmSurfaceInternal { pub(super) state: RwLock, pub(super) pending: RwLock, pub(super) logger: ::slog::Logger, - pub(super) init_buffer: Cell>, + pub(super) test_buffer: Cell>, } impl AsRawFd for AtomicDrmSurfaceInternal { @@ -155,16 +155,36 @@ impl AtomicDrmSurfaceInternal { state: RwLock::new(state), pending: RwLock::new(pending), logger, - init_buffer: Cell::new(None), + test_buffer: Cell::new(None), }; Ok(surface) } + + fn create_test_buffer(&self, mode: &Mode) -> Result { + let (w, h) = mode.size(); + let db = self.create_dumb_buffer((w as u32, h as u32), drm::buffer::format::PixelFormat::ARGB8888).compat().map_err(|source| Error::Access { + errmsg: "Failed to create dumb buffer", + dev: self.dev_path(), + source + })?; + let fb = self.add_framebuffer(&db).compat().map_err(|source| Error::Access { + errmsg: "Failed to create framebuffer", + dev: self.dev_path(), + source + })?; + if let Some((old_db, old_fb)) = self.test_buffer.replace(Some((db, fb))) { + let _ = self.destroy_framebuffer(old_fb); + let _ = self.destroy_dumb_buffer(old_db); + }; + + Ok(fb) + } } impl Drop for AtomicDrmSurfaceInternal { fn drop(&mut self) { - if let Some((db, fb)) = self.init_buffer.take() { + if let Some((db, fb)) = self.test_buffer.take() { let _ = self.destroy_framebuffer(fb); let _ = self.destroy_dumb_buffer(db); } @@ -257,7 +277,7 @@ impl Surface for AtomicDrmSurfaceInternal { &mut [conn].iter(), &mut [].iter(), &self.planes, - None, + Some(self.create_test_buffer(&pending.mode)?), Some(pending.mode), Some(pending.blob), )?; @@ -294,7 +314,7 @@ impl Surface for AtomicDrmSurfaceInternal { &mut [].iter(), &mut [conn].iter(), &self.planes, - None, + Some(self.create_test_buffer(&pending.mode)?), Some(pending.mode), Some(pending.blob), )?; @@ -331,7 +351,7 @@ impl Surface for AtomicDrmSurfaceInternal { &mut added, &mut removed, &self.planes, - None, + Some(self.create_test_buffer(&pending.mode)?), Some(pending.mode), Some(pending.blob), )?; @@ -363,12 +383,13 @@ impl Surface for AtomicDrmSurfaceInternal { dev: self.dev_path(), source, })?; - + + let test_fb = Some(self.create_test_buffer(&pending.mode)?); let req = self.build_request( &mut pending.connectors.iter(), &mut [].iter(), &self.planes, - None, + test_fb, Some(mode), Some(new_blob), )?;