feat: proper dmabuf import

This commit is contained in:
Nova
2023-06-26 20:09:20 -04:00
parent c05921fd71
commit 59d049e7bd
2 changed files with 20 additions and 7 deletions

View File

@@ -16,8 +16,10 @@ use global_counter::primitive::exact::CounterU32;
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use sk::StereoKitDraw;
use smithay::backend::allocator::dmabuf::Dmabuf;
use smithay::backend::egl::EGLContext;
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::backend::renderer::ImportDma;
use smithay::reexports::wayland_server::{backend::GlobalId, Display, ListeningSocket};
use std::os::unix::prelude::AsRawFd;
use std::{
@@ -26,6 +28,7 @@ use std::{
sync::Arc,
};
use stereokit as sk;
use tokio::sync::mpsc::UnboundedReceiver;
use tokio::{
io::unix::AsyncFd, net::UnixListener as AsyncUnixListener, sync::mpsc, task::JoinHandle,
};
@@ -63,6 +66,7 @@ pub struct Wayland {
pub socket_name: String,
join_handle: JoinHandle<Result<()>>,
renderer: GlesRenderer,
dmabuf_rx: UnboundedReceiver<Dmabuf>,
state: Arc<Mutex<WaylandState>>,
}
impl Wayland {
@@ -79,8 +83,9 @@ impl Wayland {
let display: Display<WaylandState> = Display::new()?;
let display_handle = display.handle();
let (dmabuf_tx, dmabuf_rx) = mpsc::unbounded_channel();
let display = Arc::new(Mutex::new(display));
let state = WaylandState::new(display.clone(), display_handle, &renderer);
let state = WaylandState::new(display.clone(), display_handle, &renderer, dmabuf_tx);
let (global_destroy_queue_in, global_destroy_queue) = mpsc::channel(8);
GLOBAL_DESTROY_QUEUE.set(global_destroy_queue_in).unwrap();
@@ -100,6 +105,7 @@ impl Wayland {
socket_name,
join_handle,
renderer,
dmabuf_rx,
state,
})
}
@@ -150,6 +156,9 @@ impl Wayland {
#[instrument(level = "debug", name = "Wayland frame", skip(self, sk))]
pub fn update(&mut self, sk: &impl StereoKitDraw) {
while let Ok(dmabuf) = self.dmabuf_rx.try_recv() {
let _ = self.renderer.import_dmabuf(&dmabuf, None);
}
for core_surface in CORE_SURFACES.get_valid_contents() {
core_surface.process(sk, &mut self.renderer);
}

View File

@@ -24,12 +24,13 @@ use smithay::{
wayland::{
buffer::BufferHandler,
compositor::{CompositorClientState, CompositorState},
dmabuf::{self, DmabufGlobal, DmabufHandler, DmabufState},
dmabuf::{self, DmabufGlobal, DmabufHandler, DmabufState, ImportError},
shell::kde::decoration::KdeDecorationState,
shm::{ShmHandler, ShmState},
},
};
use std::sync::{Arc, Weak};
use tokio::sync::mpsc::UnboundedSender;
use tracing::info;
#[derive(Default)]
@@ -58,8 +59,9 @@ pub struct WaylandState {
// pub xdg_activation_state: XdgActivationState,
pub kde_decoration_state: KdeDecorationState,
pub shm_state: ShmState,
pub dmabuf_state: DmabufState,
pub dmabuf_global: DmabufGlobal,
dmabuf_state: DmabufState,
_dmabuf_global: DmabufGlobal,
dmabuf_tx: UnboundedSender<Dmabuf>,
pub output: Output,
pub seats: FxHashMap<ClientId, Arc<SeatData>>,
}
@@ -69,6 +71,7 @@ impl WaylandState {
display: Arc<Mutex<Display<WaylandState>>>,
display_handle: DisplayHandle,
renderer: &GlesRenderer,
dmabuf_tx: UnboundedSender<Dmabuf>,
) -> Arc<Mutex<Self>> {
let compositor_state = CompositorState::new::<Self>(&display_handle);
// let xdg_activation_state = XdgActivationState::new::<Self, _>(&display_handle);
@@ -118,7 +121,8 @@ impl WaylandState {
kde_decoration_state,
shm_state,
dmabuf_state,
dmabuf_global,
_dmabuf_global: dmabuf_global,
dmabuf_tx,
output,
seats: FxHashMap::default(),
})
@@ -151,9 +155,9 @@ impl DmabufHandler for WaylandState {
fn dmabuf_imported(
&mut self,
_global: &DmabufGlobal,
_dmabuf: Dmabuf,
dmabuf: Dmabuf,
) -> Result<(), dmabuf::ImportError> {
Ok(())
self.dmabuf_tx.send(dmabuf).map_err(|_| ImportError::Failed)
}
}
delegate_dmabuf!(WaylandState);