feat(wayland): dmabuf

This commit is contained in:
Nova
2022-12-07 14:30:48 -05:00
parent 48719c9862
commit 0dc9dc23e9
3 changed files with 59 additions and 19 deletions

22
src/wayland/dmabuf.rs Normal file
View File

@@ -0,0 +1,22 @@
use super::state::WaylandState;
use smithay::{
backend::allocator::dmabuf::Dmabuf,
delegate_dmabuf,
wayland::dmabuf::{self, DmabufGlobal, DmabufHandler, DmabufState},
};
impl DmabufHandler for WaylandState {
fn dmabuf_state(&mut self) -> &mut DmabufState {
&mut self.dmabuf_state
}
fn dmabuf_imported(
&mut self,
_global: &DmabufGlobal,
dmabuf: Dmabuf,
) -> Result<(), dmabuf::ImportError> {
self.pending_dmabufs.push(dmabuf);
Ok(())
}
}
delegate_dmabuf!(WaylandState);

View File

@@ -1,13 +1,14 @@
pub mod compositor; mod compositor;
mod data_device; mod data_device;
pub mod decoration; mod decoration;
pub mod panel_item; pub mod panel_item;
pub mod seat; mod seat;
pub mod shaders; mod shaders;
pub mod state; mod state;
pub mod surface; mod surface;
pub mod xdg_activation; mod xdg_activation;
pub mod xdg_shell; mod xdg_shell;
mod dmabuf;
use self::{panel_item::PanelItem, state::WaylandState, surface::CORE_SURFACES}; use self::{panel_item::PanelItem, state::WaylandState, surface::CORE_SURFACES};
use crate::wayland::state::ClientState; use crate::wayland::state::ClientState;
@@ -16,7 +17,7 @@ use once_cell::sync::OnceCell;
use parking_lot::Mutex; use parking_lot::Mutex;
use slog::Drain; use slog::Drain;
use smithay::{ use smithay::{
backend::{egl::EGLContext, renderer::gles2::Gles2Renderer}, backend::{egl::EGLContext, renderer::{gles2::Gles2Renderer, ImportDma}},
reexports::wayland_server::{backend::GlobalId, Display, ListeningSocket, Resource}, reexports::wayland_server::{backend::GlobalId, Display, ListeningSocket, Resource},
}; };
use tracing::info; use tracing::info;
@@ -84,7 +85,7 @@ impl Wayland {
let display_handle = display.handle(); let display_handle = display.handle();
let display = Arc::new(Mutex::new(display)); let display = Arc::new(Mutex::new(display));
let state = WaylandState::new(log.clone(), display.clone(), display_handle); let state = WaylandState::new(log.clone(), display.clone(), display_handle, &renderer);
let (global_destroy_queue_in, global_destroy_queue) = mpsc::channel(8); let (global_destroy_queue_in, global_destroy_queue) = mpsc::channel(8);
GLOBAL_DESTROY_QUEUE.set(global_destroy_queue_in).unwrap(); GLOBAL_DESTROY_QUEUE.set(global_destroy_queue_in).unwrap();
@@ -152,7 +153,10 @@ impl Wayland {
.wl_surface() .wl_surface()
.and_then(|surf| surf.client()) .and_then(|surf| surf.client())
.map(|c| c.id()) else { continue }; .map(|c| c.id()) else { continue };
let state = self.state.lock(); let mut state = self.state.lock();
for dmabuf in state.pending_dmabufs.drain(1..) {
let _ = self.renderer.import_dmabuf(&dmabuf, None);
}
let Some(seat_data) = state.seats.get(&client_id).cloned() else { continue }; let Some(seat_data) = state.seats.get(&client_id).cloned() else { continue };
let output = state.output.clone(); let output = state.output.clone();
core_surface.process( core_surface.process(

View File

@@ -3,13 +3,17 @@ use parking_lot::Mutex;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use slog::Logger; use slog::Logger;
use smithay::{ use smithay::{
backend::{
allocator::dmabuf::Dmabuf,
renderer::{gles2::Gles2Renderer, ImportDma},
},
delegate_output, delegate_shm, delegate_output, delegate_shm,
output::{Mode, Output, Scale, Subpixel}, output::{Mode, Output, Scale, Subpixel},
reexports::{ reexports::{
wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as DecorationMode, wayland_protocols_misc::server_decoration::server::org_kde_kwin_server_decoration_manager::Mode as DecorationMode,
wayland_server::{ wayland_server::{
backend::{ClientData, ClientId, DisconnectReason}, backend::{ClientData, ClientId, DisconnectReason},
protocol::wl_data_device_manager::WlDataDeviceManager, protocol::{wl_buffer::WlBuffer, wl_data_device_manager::WlDataDeviceManager},
Display, DisplayHandle, Display, DisplayHandle,
}, },
}, },
@@ -17,6 +21,7 @@ use smithay::{
wayland::{ wayland::{
buffer::BufferHandler, buffer::BufferHandler,
compositor::CompositorState, compositor::CompositorState,
dmabuf::{DmabufGlobal, DmabufState},
output::OutputManagerState, output::OutputManagerState,
shell::{ shell::{
kde::decoration::KdeDecorationState, kde::decoration::KdeDecorationState,
@@ -55,6 +60,9 @@ pub struct WaylandState {
pub kde_decoration_state: KdeDecorationState, pub kde_decoration_state: KdeDecorationState,
pub xdg_shell_state: XdgShellState, pub xdg_shell_state: XdgShellState,
pub shm_state: ShmState, pub shm_state: ShmState,
pub dmabuf_state: DmabufState,
pub dmabuf_global: DmabufGlobal,
pub pending_dmabufs: Vec<Dmabuf>,
pub output_manager_state: OutputManagerState, pub output_manager_state: OutputManagerState,
pub output: Output, pub output: Output,
pub seats: FxHashMap<ClientId, SeatData>, pub seats: FxHashMap<ClientId, SeatData>,
@@ -65,6 +73,7 @@ impl WaylandState {
log: Logger, log: Logger,
display: Arc<Mutex<Display<WaylandState>>>, display: Arc<Mutex<Display<WaylandState>>>,
display_handle: DisplayHandle, display_handle: DisplayHandle,
renderer: &Gles2Renderer,
) -> Arc<Mutex<Self>> { ) -> Arc<Mutex<Self>> {
let compositor_state = CompositorState::new::<Self, _>(&display_handle, log.clone()); let compositor_state = CompositorState::new::<Self, _>(&display_handle, log.clone());
let xdg_activation_state = XdgActivationState::new::<Self, _>(&display_handle, log.clone()); let xdg_activation_state = XdgActivationState::new::<Self, _>(&display_handle, log.clone());
@@ -76,6 +85,12 @@ impl WaylandState {
log.clone(), log.clone(),
); );
let shm_state = ShmState::new::<Self, _>(&display_handle, vec![], log.clone()); let shm_state = ShmState::new::<Self, _>(&display_handle, vec![], log.clone());
let mut dmabuf_state = DmabufState::new();
let dmabuf_global = dmabuf_state.create_global::<Self, _>(
&display_handle,
renderer.dmabuf_formats().cloned().collect::<Vec<_>>(),
log.clone(),
);
let output_manager_state = OutputManagerState::new_with_xdg_output::<Self>(&display_handle); let output_manager_state = OutputManagerState::new_with_xdg_output::<Self>(&display_handle);
let output = Output::new( let output = Output::new(
"1x".to_owned(), "1x".to_owned(),
@@ -87,7 +102,7 @@ impl WaylandState {
}, },
log.clone(), log.clone(),
); );
let _global = output.create_global::<Self>(&display_handle); let _output_global = output.create_global::<Self>(&display_handle);
output.change_current_state( output.change_current_state(
Some(Mode { Some(Mode {
size: (4096, 4096).into(), size: (4096, 4096).into(),
@@ -114,6 +129,9 @@ impl WaylandState {
kde_decoration_state, kde_decoration_state,
xdg_shell_state, xdg_shell_state,
shm_state, shm_state,
dmabuf_state,
dmabuf_global,
pending_dmabufs: Vec::new(),
output_manager_state, output_manager_state,
output, output,
seats: FxHashMap::default(), seats: FxHashMap::default(),
@@ -132,14 +150,10 @@ impl Drop for WaylandState {
} }
} }
impl BufferHandler for WaylandState { impl BufferHandler for WaylandState {
fn buffer_destroyed( fn buffer_destroyed(&mut self, _buffer: &WlBuffer) {}
&mut self,
_buffer: &smithay::reexports::wayland_server::protocol::wl_buffer::WlBuffer,
) {
}
} }
impl ShmHandler for WaylandState { impl ShmHandler for WaylandState {
fn shm_state(&self) -> &smithay::wayland::shm::ShmState { fn shm_state(&self) -> &ShmState {
&self.shm_state &self.shm_state
} }
} }