Update Smithay

For the `drm` protocol, we can't construct an `ImportNotifier`, since
that is specifically based around `ZwpLinuxBufferParamsv1`. So we need a
new method for importing with that protocol.

This could be improved, but should match current behavior.
This commit is contained in:
Ian Douglas Scott 2023-11-22 13:27:12 -08:00 committed by Victoria Brekenfeld
parent 2ffb8068b8
commit 41a69cfc9f
7 changed files with 282 additions and 306 deletions

499
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -32,7 +32,7 @@ xkbcommon = "0.7"
indexmap = "2.0" indexmap = "2.0"
xdg = "^2.1" xdg = "^2.1"
ron = "0.8" ron = "0.8"
libsystemd = { version = "0.6", optional = true } libsystemd = { version = "0.7", optional = true }
wayland-backend = "0.3.2" wayland-backend = "0.3.2"
wayland-scanner = "0.31.0" wayland-scanner = "0.31.0"
cosmic-comp-config = { path = "cosmic-comp-config" } cosmic-comp-config = { path = "cosmic-comp-config" }
@ -88,4 +88,4 @@ debug = true
lto = "fat" lto = "fat"
[patch."https://github.com/Smithay/smithay.git"] [patch."https://github.com/Smithay/smithay.git"]
smithay = { git = "https://github.com/smithay//smithay", rev = "d5b352b" } smithay = { git = "https://github.com/smithay//smithay", rev = "bb2aacd" }

View file

@ -30,6 +30,7 @@ use rust_embed::RustEmbed;
use smithay::utils::Rectangle; use smithay::utils::Rectangle;
use smithay::{ use smithay::{
backend::{ backend::{
allocator::dmabuf::Dmabuf,
drm::DrmNode, drm::DrmNode,
input::Device, input::Device,
renderer::{ renderer::{
@ -38,6 +39,7 @@ use smithay::{
RenderElementStates, RenderElementStates,
}, },
glow::GlowRenderer, glow::GlowRenderer,
ImportDma,
}, },
}, },
desktop::utils::{ desktop::utils::{
@ -60,7 +62,7 @@ use smithay::{
utils::{Clock, IsAlive, Monotonic}, utils::{Clock, IsAlive, Monotonic},
wayland::{ wayland::{
compositor::{CompositorClientState, CompositorState}, compositor::{CompositorClientState, CompositorState},
dmabuf::{DmabufFeedback, DmabufState}, dmabuf::{DmabufFeedback, DmabufGlobal, DmabufState},
fractional_scale::{with_fractional_scale, FractionalScaleManagerState}, fractional_scale::{with_fractional_scale, FractionalScaleManagerState},
input_method::InputMethodManagerState, input_method::InputMethodManagerState,
keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitState, keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitState,
@ -274,6 +276,24 @@ impl BackendData {
_ => unreachable!("No backend was initialized"), _ => unreachable!("No backend was initialized"),
} }
} }
pub fn dmabuf_imported(
&mut self,
global: &DmabufGlobal,
dmabuf: Dmabuf,
) -> Result<(), anyhow::Error> {
match self {
BackendData::Kms(ref mut state) => state.dmabuf_imported(global, dmabuf)?,
BackendData::Winit(ref mut state) => {
state.backend.renderer().import_dmabuf(&dmabuf, None)?;
}
BackendData::X11(ref mut state) => {
state.renderer.import_dmabuf(&dmabuf, None)?;
}
_ => unreachable!("No backend set when importing dmabuf"),
}
Ok(())
}
} }
pub fn client_has_no_security_context(client: &Client) -> bool { pub fn client_has_no_security_context(client: &Client) -> bool {

View file

@ -1,10 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
use crate::state::{BackendData, State}; use crate::state::State;
use smithay::{ use smithay::{
backend::{allocator::dmabuf::Dmabuf, renderer::ImportDma}, backend::allocator::dmabuf::Dmabuf,
delegate_dmabuf, delegate_dmabuf,
wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportError}, wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier},
}; };
impl DmabufHandler for State { impl DmabufHandler for State {
@ -16,23 +16,10 @@ impl DmabufHandler for State {
&mut self, &mut self,
global: &DmabufGlobal, global: &DmabufGlobal,
dmabuf: Dmabuf, dmabuf: Dmabuf,
) -> Result<(), ImportError> { import_notifier: ImportNotifier,
match &mut self.backend { ) {
BackendData::Kms(ref mut state) => state if self.backend.dmabuf_imported(global, dmabuf).is_err() {
.dmabuf_imported(global, dmabuf) import_notifier.failed();
.map_err(|_| ImportError::Failed),
BackendData::Winit(ref mut state) => state
.backend
.renderer()
.import_dmabuf(&dmabuf, None)
.map(|_| ())
.map_err(|_| ImportError::Failed),
BackendData::X11(ref mut state) => state
.renderer
.import_dmabuf(&dmabuf, None)
.map(|_| ())
.map_err(|_| ImportError::Failed),
_ => unreachable!("No backend set when importing dmabuf"),
} }
} }
} }

View file

@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::{
state::State,
wayland::protocols::drm::{DrmHandler, ImportError},
};
use smithay::{backend::allocator::dmabuf::Dmabuf, wayland::dmabuf::DmabufGlobal};
impl DrmHandler for State {
fn dmabuf_imported(
&mut self,
global: &DmabufGlobal,
dmabuf: Dmabuf,
) -> Result<(), ImportError> {
self.backend
.dmabuf_imported(global, dmabuf)
.map_err(|_| ImportError::Failed)
}
}

View file

@ -6,6 +6,7 @@ pub mod data_control;
pub mod data_device; pub mod data_device;
pub mod decoration; pub mod decoration;
pub mod dmabuf; pub mod dmabuf;
pub mod drm;
pub mod drm_lease; pub mod drm_lease;
pub mod fractional_scale; pub mod fractional_scale;
pub mod input_method; pub mod input_method;

View file

@ -31,13 +31,23 @@ use smithay::{
}, },
wayland::{ wayland::{
buffer::BufferHandler, buffer::BufferHandler,
dmabuf::{DmabufGlobal, DmabufHandler, ImportError}, dmabuf::{DmabufGlobal, DmabufHandler},
}, },
}; };
use tracing::trace; use tracing::trace;
use std::{convert::TryFrom, path::PathBuf, sync::Arc}; use std::{convert::TryFrom, path::PathBuf, sync::Arc};
pub enum ImportError {
Failed,
InvalidFormat,
}
pub trait DrmHandler {
fn dmabuf_imported(&mut self, global: &DmabufGlobal, dmabuf: Dmabuf)
-> Result<(), ImportError>;
}
#[derive(Debug)] #[derive(Debug)]
pub struct WlDrmState; pub struct WlDrmState;
@ -98,7 +108,7 @@ where
+ Dispatch<wl_drm::WlDrm, DrmInstanceData> + Dispatch<wl_drm::WlDrm, DrmInstanceData>
+ Dispatch<WlBuffer, Dmabuf> + Dispatch<WlBuffer, Dmabuf>
+ BufferHandler + BufferHandler
+ DmabufHandler + DrmHandler
+ 'static, + 'static,
{ {
fn request( fn request(
@ -163,7 +173,7 @@ where
match dma.build() { match dma.build() {
Some(dmabuf) => { Some(dmabuf) => {
match state.dmabuf_imported(&data.dmabuf_global, dmabuf.clone()) { match state.dmabuf_imported(&data.dmabuf_global, dmabuf.clone()) {
Ok(_) => { Ok(()) => {
// import was successful // import was successful
data_init.init(id, dmabuf); data_init.init(id, dmabuf);
trace!("Created a new validated dma wl_buffer via wl_drm."); trace!("Created a new validated dma wl_buffer via wl_drm.");