Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DrmCompositor direct bind #1671

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/backend/allocator/dumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ impl DumbBuffer {
pub fn handle(&self) -> &Handle {
&self.handle
}

/// Map the dumb buffer for read/write access
pub fn map(&mut self) -> std::io::Result<drm::control::dumbbuffer::DumbMapping<'_>> {
self.fd.map_dumb_buffer(&mut self.handle)
}
}

impl AsDmabuf for DumbBuffer {
Expand Down
17 changes: 13 additions & 4 deletions src/backend/allocator/swapchain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
cell::UnsafeCell,
fmt,
ops::Deref,
ops::{Deref, DerefMut},
sync::{
atomic::{AtomicBool, AtomicU8, Ordering},
Arc,
Expand Down Expand Up @@ -75,12 +76,14 @@ pub struct Slot<B: Buffer>(Arc<InternalSlot<B>>);

#[derive(Debug)]
struct InternalSlot<B: Buffer> {
buffer: Option<B>,
buffer: Option<UnsafeCell<B>>,
acquired: AtomicBool,
age: AtomicU8,
userdata: UserDataMap,
}

unsafe impl<B: Buffer> Sync for InternalSlot<B> where B: Sync {}

impl<B: Buffer> Slot<B> {
/// Retrieve userdata for this slot.
pub fn userdata(&self) -> &UserDataMap {
Expand All @@ -107,7 +110,13 @@ impl<B: Buffer> Default for InternalSlot<B> {
impl<B: Buffer> Deref for Slot<B> {
type Target = B;
fn deref(&self) -> &B {
Option::as_ref(&self.0.buffer).unwrap()
unsafe { &*Option::as_ref(&self.0.buffer).unwrap().get() }
}
}

impl<B: Buffer> DerefMut for Slot<B> {
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *Option::as_ref(&self.0.buffer).unwrap().get() }
}
}

Expand Down Expand Up @@ -171,7 +180,7 @@ where
.allocator
.create_buffer(self.width, self.height, self.fourcc, &self.modifiers)
{
Ok(buffer) => free_slot.buffer = Some(buffer),
Ok(buffer) => free_slot.buffer = Some(UnsafeCell::new(buffer)),
Err(err) => {
free_slot.acquired.store(false, Ordering::SeqCst);
return Err(err);
Expand Down
Loading
Loading