diff --git a/anvil/src/x11.rs b/anvil/src/x11.rs index 567eb1c..a07ef22 100644 --- a/anvil/src/x11.rs +++ b/anvil/src/x11.rs @@ -1,4 +1,9 @@ -use std::{cell::RefCell, rc::Rc, sync::atomic::Ordering, time::Duration}; +use std::{ + cell::RefCell, + rc::Rc, + sync::{atomic::Ordering, Arc, Mutex}, + time::Duration, +}; use slog::Logger; #[cfg(feature = "egl")] @@ -64,6 +69,7 @@ pub fn run_x11(log: Logger) { let device = gbm::Device::new(drm_node).expect("Failed to create gbm device"); // Initialize EGL using the GBM device setup earlier. let egl = EGLDisplay::new(&device, log.clone()).expect("Failed to create EGLDisplay"); + let device = Arc::new(Mutex::new(device)); let context = EGLContext::new(&egl, log.clone()).expect("Failed to create EGLContext"); let surface = X11Surface::new( &mut backend, diff --git a/src/backend/x11/mod.rs b/src/backend/x11/mod.rs index 6c13096..e43ffc6 100644 --- a/src/backend/x11/mod.rs +++ b/src/backend/x11/mod.rs @@ -100,7 +100,7 @@ use std::{ sync::{ atomic::{AtomicU32, Ordering}, mpsc::{self, Receiver, Sender}, - Arc, Weak, + Arc, Mutex, MutexGuard, Weak, }, }; use x11rb::{ @@ -345,7 +345,7 @@ pub struct X11Surface { connection: Weak, window: Window, resize: Receiver>, - swapchain: Swapchain, BufferObject<()>>, + swapchain: Swapchain>>, BufferObject<()>>, format: DrmFourcc, width: u16, height: u16, @@ -441,7 +441,7 @@ impl X11Surface { /// This will fail if the backend has already been used to create a surface. pub fn new( backend: &mut X11Backend, - device: gbm::Device, + device: Arc>>, modifiers: impl Iterator, ) -> Result { if backend.resize.is_some() { @@ -472,8 +472,8 @@ impl X11Surface { } /// Returns a handle to the GBM device used to allocate buffers. - pub fn device(&self) -> &gbm::Device { - &self.swapchain.allocator + pub fn device(&self) -> MutexGuard<'_, gbm::Device> { + self.swapchain.allocator.lock().unwrap() } /// Returns the format of the buffers the surface accepts.