wayland drm fixup

This commit is contained in:
Victoria Brekenfeld 2022-03-22 12:37:46 +01:00
parent 8e1c1af6a9
commit 2fb0fa8aef
3 changed files with 62 additions and 61 deletions

View file

@ -1,12 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
extern crate wayland_scanner; extern crate wayland_scanner;
use wayland_scanner::{Side, generate_code}; use std::{env, path::PathBuf, process::Command};
use std::{ use wayland_scanner::{generate_code, Side};
env,
process::Command,
path::PathBuf,
};
fn main() { fn main() {
if let Some(output) = Command::new("git") if let Some(output) = Command::new("git")
@ -18,14 +14,9 @@ fn main() {
println!("cargo:rustc-env=GIT_HASH={}", git_hash); println!("cargo:rustc-env=GIT_HASH={}", git_hash);
} }
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap()); let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());
// Location of the xml file, relative to the `Cargo.toml` // Location of the xml file, relative to the `Cargo.toml`
let drm_protocol_file = "resources/wayland-drm.xml"; let drm_protocol_file = "resources/wayland-drm.xml";
// Target directory for the generate files // Target directory for the generate files
generate_code( generate_code(drm_protocol_file, &dest.join("wl_drm.rs"), Side::Server);
drm_protocol_file,
&dest.join("wl_drm.rs"),
Side::Server,
);
} }

View file

@ -10,36 +10,33 @@ pub use generated::server::wl_drm;
mod generated { mod generated {
// The generated code tends to trigger a lot of warnings // The generated code tends to trigger a lot of warnings
// so we isolate it into a very permissive module // so we isolate it into a very permissive module
#![allow(dead_code,non_camel_case_types,unused_unsafe,unused_variables)] #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)]
#![allow(non_upper_case_globals,non_snake_case,unused_imports)] #![allow(non_upper_case_globals, non_snake_case, unused_imports)]
pub mod server { pub mod server {
use smithay::reexports::{wayland_commons, wayland_server}; use smithay::reexports::{wayland_commons, wayland_server};
// These imports are used by the generated code // These imports are used by the generated code
pub(crate) use wayland_server::{Main, AnonymousObject, Resource, ResourceMap};
pub(crate) use wayland_commons::map::{Object, ObjectMetadata}; pub(crate) use wayland_commons::map::{Object, ObjectMetadata};
pub(crate) use wayland_commons::{Interface, MessageGroup};
pub(crate) use wayland_commons::wire::{Argument, MessageDesc, ArgumentType, Message};
pub(crate) use wayland_commons::smallvec; pub(crate) use wayland_commons::smallvec;
pub(crate) use wayland_server::sys; pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc};
pub(crate) use wayland_commons::{Interface, MessageGroup};
pub(crate) use wayland_server::protocol::wl_buffer; pub(crate) use wayland_server::protocol::wl_buffer;
pub(crate) use wayland_server::sys;
pub(crate) use wayland_server::{AnonymousObject, Main, Resource, ResourceMap};
include!(concat!(env!("OUT_DIR"), "/wl_drm.rs")); include!(concat!(env!("OUT_DIR"), "/wl_drm.rs"));
} }
} }
use smithay::{ use smithay::{
backend::allocator::{ backend::allocator::{
Format, Fourcc, Modifier,
dmabuf::{Dmabuf, DmabufFlags}, dmabuf::{Dmabuf, DmabufFlags},
Format, Fourcc, Modifier,
}, },
reexports::wayland_server::{Client, Display, Filter, Global, Main}, reexports::wayland_server::{Client, Display, Filter, Global, Main},
}; };
use std::{ use std::{convert::TryFrom, path::PathBuf};
convert::TryFrom,
path::PathBuf,
};
pub fn init_wl_drm_global<F>( pub fn init_wl_drm_global<F>(
display: &mut Display, display: &mut Display,
@ -48,48 +45,60 @@ pub fn init_wl_drm_global<F>(
client_filter: F, client_filter: F,
) -> Global<wl_drm::WlDrm> ) -> Global<wl_drm::WlDrm>
where where
F: FnMut(Client) -> bool + 'static F: FnMut(Client) -> bool + 'static,
{ {
formats.dedup_by(|f1, f2| f1.code == f2.code); formats.dedup_by(|f1, f2| f1.code == f2.code);
let global = Filter::new(move |(drm, version): (Main<wl_drm::WlDrm>, u32), _, _| { let global = Filter::new(move |(drm, version): (Main<wl_drm::WlDrm>, u32), _, _| {
drm.quick_assign(move |drm, req, _| { drm.quick_assign(move |drm, req, _| match req {
match req { wl_drm::Request::Authenticate { .. } => drm.authenticated(),
wl_drm::Request::Authenticate { .. } => drm.authenticated(), wl_drm::Request::CreateBuffer { id, .. } => {
wl_drm::Request::CreateBuffer { id, .. } => { id.as_ref().post_error(
id.as_ref().post_error(wl_drm::Error::InvalidName.to_raw(), String::from("Flink handles are unsupported, use PRIME")); wl_drm::Error::InvalidName.to_raw(),
}, String::from("Flink handles are unsupported, use PRIME"),
wl_drm::Request::CreatePlanarBuffer { id, .. } => { );
id.as_ref().post_error(wl_drm::Error::InvalidName.to_raw(), String::from("Flink handles are unsupported, use PRIME")); }
}, wl_drm::Request::CreatePlanarBuffer { id, .. } => {
wl_drm::Request::CreatePrimeBuffer { id.as_ref().post_error(
id, wl_drm::Error::InvalidName.to_raw(),
name, String::from("Flink handles are unsupported, use PRIME"),
width, );
height, }
format, wl_drm::Request::CreatePrimeBuffer {
offset0, id,
stride0, name,
.. width,
} => { height,
let format = match Fourcc::try_from(format) { format,
Ok(format) => format, offset0,
Err(_) => { stride0,
id.as_ref().post_error(wl_drm::Error::InvalidFormat.to_raw(), String::from("Format not advertised by wl_drm")); ..
return; } => {
} let format = match Fourcc::try_from(format) {
}; Ok(format) => format,
Err(_) => {
if width < 1 || height < 1 { id.as_ref().post_error(
id.as_ref().post_error(wl_drm::Error::InvalidFormat.to_raw(), String::from("width or height not positive")); wl_drm::Error::InvalidFormat.to_raw(),
String::from("Format not advertised by wl_drm"),
);
return; return;
} }
};
let mut dma = Dmabuf::builder((width, height), format, DmabufFlags::empty()); if width < 1 || height < 1 {
dma.add_plane(name, 0, offset0 as u32, stride0 as u32, Modifier::Invalid); id.as_ref().post_error(
id.as_ref().user_data().set_threadsafe(|| dma.build().unwrap()); wl_drm::Error::InvalidFormat.to_raw(),
id.quick_assign(|_, _, _| {}); String::from("width or height not positive"),
slog_scope::trace!("Created a new validated dma wl_buffer via wl_drm."); );
}, return;
}
let mut dma = Dmabuf::builder((width, height), format, DmabufFlags::empty());
dma.add_plane(name, 0, offset0 as u32, stride0 as u32, Modifier::Invalid);
id.as_ref()
.user_data()
.set_threadsafe(|| dma.build().unwrap());
id.quick_assign(|_, _, _| {});
slog_scope::trace!("Created a new validated dma wl_buffer via wl_drm.");
} }
}); });
drm.device(device_path.to_string_lossy().into_owned()); drm.device(device_path.to_string_lossy().into_owned());

View file

@ -1,2 +1,3 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
pub mod drm; mod drm;
pub use drm::*;