diff --git a/src/backend/allocator/mod.rs b/src/backend/allocator/mod.rs index 108f0bf..4f53369 100644 --- a/src/backend/allocator/mod.rs +++ b/src/backend/allocator/mod.rs @@ -22,6 +22,12 @@ pub mod dumb; pub mod gbm; mod swapchain; +use std::{ + cell::RefCell, + rc::Rc, + sync::{Arc, Mutex}, +}; + use crate::utils::{Buffer as BufferCoords, Size}; pub use swapchain::{Slot, Swapchain}; @@ -60,3 +66,34 @@ pub trait Allocator { modifiers: &[Modifier], ) -> Result; } + +// General implementations for interior mutability. + +impl, B: Buffer> Allocator for Arc> { + type Error = A::Error; + + fn create_buffer( + &mut self, + width: u32, + height: u32, + fourcc: Fourcc, + modifiers: &[Modifier], + ) -> Result { + let mut guard = self.lock().unwrap(); + guard.create_buffer(width, height, fourcc, modifiers) + } +} + +impl, B: Buffer> Allocator for Rc> { + type Error = A::Error; + + fn create_buffer( + &mut self, + width: u32, + height: u32, + fourcc: Fourcc, + modifiers: &[Modifier], + ) -> Result { + self.borrow_mut().create_buffer(width, height, fourcc, modifiers) + } +}