x11: require wrapping gbm device in an Arc<Mutex<_>>

This commit is contained in:
i509VCB 2021-11-29 13:26:35 -06:00
parent 210ab8fb21
commit 4f26641f8c
2 changed files with 12 additions and 6 deletions

View File

@ -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; use slog::Logger;
#[cfg(feature = "egl")] #[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"); let device = gbm::Device::new(drm_node).expect("Failed to create gbm device");
// Initialize EGL using the GBM device setup earlier. // Initialize EGL using the GBM device setup earlier.
let egl = EGLDisplay::new(&device, log.clone()).expect("Failed to create EGLDisplay"); 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 context = EGLContext::new(&egl, log.clone()).expect("Failed to create EGLContext");
let surface = X11Surface::new( let surface = X11Surface::new(
&mut backend, &mut backend,

View File

@ -100,7 +100,7 @@ use std::{
sync::{ sync::{
atomic::{AtomicU32, Ordering}, atomic::{AtomicU32, Ordering},
mpsc::{self, Receiver, Sender}, mpsc::{self, Receiver, Sender},
Arc, Weak, Arc, Mutex, MutexGuard, Weak,
}, },
}; };
use x11rb::{ use x11rb::{
@ -345,7 +345,7 @@ pub struct X11Surface {
connection: Weak<RustConnection>, connection: Weak<RustConnection>,
window: Window, window: Window,
resize: Receiver<Size<u16, Logical>>, resize: Receiver<Size<u16, Logical>>,
swapchain: Swapchain<gbm::Device<DrmNode>, BufferObject<()>>, swapchain: Swapchain<Arc<Mutex<gbm::Device<DrmNode>>>, BufferObject<()>>,
format: DrmFourcc, format: DrmFourcc,
width: u16, width: u16,
height: u16, height: u16,
@ -441,7 +441,7 @@ impl X11Surface {
/// This will fail if the backend has already been used to create a surface. /// This will fail if the backend has already been used to create a surface.
pub fn new( pub fn new(
backend: &mut X11Backend, backend: &mut X11Backend,
device: gbm::Device<DrmNode>, device: Arc<Mutex<gbm::Device<DrmNode>>>,
modifiers: impl Iterator<Item = DrmModifier>, modifiers: impl Iterator<Item = DrmModifier>,
) -> Result<X11Surface, X11Error> { ) -> Result<X11Surface, X11Error> {
if backend.resize.is_some() { if backend.resize.is_some() {
@ -472,8 +472,8 @@ impl X11Surface {
} }
/// Returns a handle to the GBM device used to allocate buffers. /// Returns a handle to the GBM device used to allocate buffers.
pub fn device(&self) -> &gbm::Device<DrmNode> { pub fn device(&self) -> MutexGuard<'_, gbm::Device<DrmNode>> {
&self.swapchain.allocator self.swapchain.allocator.lock().unwrap()
} }
/// Returns the format of the buffers the surface accepts. /// Returns the format of the buffers the surface accepts.