Error handling when creating gbm buffers
This commit is contained in:
parent
295fee8796
commit
7f1f46c9c7
3 changed files with 46 additions and 31 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -104,6 +104,12 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.75"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "apply"
|
name = "apply"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|
@ -757,6 +763,7 @@ dependencies = [
|
||||||
name = "cosmic-workspaces"
|
name = "cosmic-workspaces"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"calloop",
|
"calloop",
|
||||||
"cosmic-client-toolkit",
|
"cosmic-client-toolkit",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.75"
|
||||||
calloop = "0.12.3"
|
calloop = "0.12.3"
|
||||||
cctk = { package = "cosmic-client-toolkit", git = "https://github.com/pop-os/cosmic-protocols" }
|
cctk = { package = "cosmic-client-toolkit", git = "https://github.com/pop-os/cosmic-protocols" }
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
|
|
|
||||||
|
|
@ -60,12 +60,14 @@ impl AppData {
|
||||||
&self,
|
&self,
|
||||||
buffer_info: &BufferInfo,
|
buffer_info: &BufferInfo,
|
||||||
needs_linear: bool,
|
needs_linear: bool,
|
||||||
) -> Option<(BufferBacking, wl_buffer::WlBuffer)> {
|
) -> anyhow::Result<Option<(BufferBacking, wl_buffer::WlBuffer)>> {
|
||||||
// TODO Handle errors in some way
|
let (Some((node, gbm)), Some(feedback)) =
|
||||||
let (node, gbm) = self.gbm.as_ref()?;
|
(self.gbm.as_ref(), self.dmabuf_feedback.as_ref())
|
||||||
let feedback = self.dmabuf_feedback.as_ref()?;
|
else {
|
||||||
|
return Ok(None);
|
||||||
|
};
|
||||||
let formats = feedback.format_table();
|
let formats = feedback.format_table();
|
||||||
let format_info = feedback
|
let Some(format_info) = feedback
|
||||||
.tranches()
|
.tranches()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|x| &x.formats)
|
.flat_map(|x| &x.formats)
|
||||||
|
|
@ -73,25 +75,26 @@ impl AppData {
|
||||||
.find(|x| {
|
.find(|x| {
|
||||||
x.format == buffer_info.format
|
x.format == buffer_info.format
|
||||||
&& (!needs_linear || x.modifier == u64::from(gbm::Modifier::Linear))
|
&& (!needs_linear || x.modifier == u64::from(gbm::Modifier::Linear))
|
||||||
})?;
|
})
|
||||||
let format = gbm::Format::try_from(buffer_info.format).ok()?;
|
else {
|
||||||
let modifier = gbm::Modifier::try_from(format_info.modifier).ok()?;
|
return Ok(None);
|
||||||
let bo = gbm
|
};
|
||||||
.create_buffer_object_with_modifiers::<()>(
|
let format = gbm::Format::try_from(buffer_info.format)?;
|
||||||
buffer_info.width,
|
let modifier = gbm::Modifier::try_from(format_info.modifier)?;
|
||||||
buffer_info.height,
|
let bo = gbm.create_buffer_object_with_modifiers::<()>(
|
||||||
format,
|
buffer_info.width,
|
||||||
[modifier].into_iter(),
|
buffer_info.height,
|
||||||
)
|
format,
|
||||||
.ok()?;
|
[modifier].into_iter(),
|
||||||
|
)?;
|
||||||
|
|
||||||
let fd = bo.fd().ok()?;
|
let fd = bo.fd()?;
|
||||||
let stride = bo.stride().ok()?;
|
let stride = bo.stride()?;
|
||||||
let params = self.dmabuf_state.create_params(&self.qh).ok()?;
|
let params = self.dmabuf_state.create_params(&self.qh)?;
|
||||||
for i in 0..bo.plane_count().ok()? as i32 {
|
for i in 0..bo.plane_count()? as i32 {
|
||||||
let plane_fd = bo.fd_for_plane(i).ok()?;
|
let plane_fd = bo.fd_for_plane(i)?;
|
||||||
let plane_offset = bo.offset(i).ok()?;
|
let plane_offset = bo.offset(i)?;
|
||||||
let plane_stride = bo.stride_for_plane(i).ok()?;
|
let plane_stride = bo.stride_for_plane(i)?;
|
||||||
params.add(
|
params.add(
|
||||||
plane_fd.as_fd(),
|
plane_fd.as_fd(),
|
||||||
i as u32,
|
i as u32,
|
||||||
|
|
@ -110,14 +113,14 @@ impl AppData {
|
||||||
)
|
)
|
||||||
.0;
|
.0;
|
||||||
|
|
||||||
Some((
|
Ok(Some((
|
||||||
BufferBacking::Dmabuf {
|
BufferBacking::Dmabuf {
|
||||||
fd,
|
fd,
|
||||||
node: node.clone(),
|
node: node.clone(),
|
||||||
stride,
|
stride,
|
||||||
},
|
},
|
||||||
buffer,
|
buffer,
|
||||||
))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_buffer(&self, buffer_infos: &[BufferInfo]) -> Buffer {
|
pub fn create_buffer(&self, buffer_infos: &[BufferInfo]) -> Buffer {
|
||||||
|
|
@ -129,12 +132,16 @@ impl AppData {
|
||||||
.iter()
|
.iter()
|
||||||
.find(|x| x.type_ == WEnum::Value(BufferType::Dmabuf) && x.format == format)
|
.find(|x| x.type_ == WEnum::Value(BufferType::Dmabuf) && x.format == format)
|
||||||
{
|
{
|
||||||
if let Some((backing, buffer)) = self.create_gbm_backing(buffer_info, true) {
|
match self.create_gbm_backing(buffer_info, true) {
|
||||||
return Buffer {
|
Ok(Some((backing, buffer))) => {
|
||||||
backing,
|
return Buffer {
|
||||||
buffer,
|
backing,
|
||||||
buffer_info: buffer_info.clone(),
|
buffer,
|
||||||
};
|
buffer_info: buffer_info.clone(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Ok(None) => {}
|
||||||
|
Err(err) => eprintln!("Failed to create gbm buffer: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue