Skip to content

Commit

Permalink
WIP Update to gbm.rs without DeviceDestroyedError
Browse files Browse the repository at this point in the history
Depends on Smithay/gbm.rs#25.
  • Loading branch information
ids1024 committed Nov 21, 2024
1 parent eef0768 commit 1e09c12
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,6 @@ harness = false
[profile.release-with-debug]
inherits = "release"
debug = true

[patch.crates-io]
gbm = { git = "https://github.com/ids1024/gbm.rs", branch = "strong-ref" }
18 changes: 7 additions & 11 deletions src/backend/allocator/gbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ impl GbmBuffer {
/// Gbm might otherwise give us the underlying or a non-sensical modifier,
/// which can fail in various other apis.
pub fn from_bo(bo: BufferObject<()>, implicit: bool) -> Self {
let size = (bo.width().unwrap_or(0) as i32, bo.height().unwrap_or(0) as i32).into();
let size = (bo.width() as i32, bo.height() as i32).into();
let format = Format {
code: bo.format().unwrap_or(Fourcc::Argb8888), // we got to return something, but this should never happen anyway
code: bo.format(),
modifier: if implicit {
Modifier::Invalid
} else {
bo.modifier().unwrap_or(Modifier::Invalid)
bo.modifier()
},
};
Self { bo, size, format }
Expand Down Expand Up @@ -242,9 +242,6 @@ impl Buffer for GbmBuffer {
/// Errors during conversion to a dmabuf handle from a gbm buffer object
#[derive(thiserror::Error, Debug)]
pub enum GbmConvertError {
/// The gbm device was destroyed
#[error("The gbm device was destroyed")]
DeviceDestroyed(#[from] gbm::DeviceDestroyedError),
/// The buffer consists out of multiple file descriptions, which is currently unsupported
#[error("Buffer consists out of multiple file descriptors, which is currently unsupported")]
UnsupportedBuffer,
Expand All @@ -257,7 +254,6 @@ impl From<gbm::FdError> for GbmConvertError {
#[inline]
fn from(err: gbm::FdError) -> Self {
match err {
gbm::FdError::DeviceDestroyed(err) => err.into(),
gbm::FdError::InvalidFd(err) => err.into(),
}
}
Expand All @@ -269,7 +265,7 @@ impl AsDmabuf for GbmBuffer {
#[cfg(feature = "backend_gbm_has_fd_for_plane")]
#[profiling::function]
fn export(&self) -> Result<Dmabuf, GbmConvertError> {
let planes = self.plane_count()? as i32;
let planes = self.plane_count() as i32;

let mut builder = Dmabuf::builder_from_buffer(self, DmabufFlags::empty());
for idx in 0..planes {
Expand All @@ -279,13 +275,13 @@ impl AsDmabuf for GbmBuffer {
// SAFETY: `gbm_bo_get_fd_for_plane` returns a new fd owned by the caller.
fd,
idx as u32,
self.offset(idx)?,
self.stride_for_plane(idx)?,
self.offset(idx),
self.stride_for_plane(idx),
);
}

#[cfg(feature = "backend_drm")]
if let Some(node) = self.device_fd().ok().and_then(|fd| DrmNode::from_file(fd).ok()) {
if let Ok(node) = DrmNode::from_file(self.device_fd()) {
builder.set_node(node);
}

Expand Down
6 changes: 2 additions & 4 deletions src/backend/drm/compositor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4365,13 +4365,11 @@ where
}

let bo_format = bo.format().code;
let Ok(bo_stride) = bo.stride() else {
return false;
};
let bo_stride = bo.stride();

let mut copy_to_bo = |src, src_stride, src_height| {
if src_stride == bo_stride as i32 {
matches!(bo.write(src), Ok(Ok(_)))
matches!(bo.write(src), Ok(_))
} else {
let res = bo.map_mut(device, 0, 0, cursor_size.w as u32, cursor_size.h as u32, |mbo| {
let dst = mbo.buffer_mut();
Expand Down
2 changes: 1 addition & 1 deletion src/backend/drm/gbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ where
// We only support this as a fallback of last resort like xf86-video-modesetting does.
warn_legacy_fb_export();

if bo.plane_count().unwrap() > 1 {
if bo.plane_count() > 1 {
return Err(AccessError {
errmsg: "Failed to add framebuffer",
dev: drm.dev_path(),
Expand Down
8 changes: 4 additions & 4 deletions src/backend/drm/surface/gbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ where
};
let format = Format {
code,
modifier: buffer.modifier().unwrap(), // no guarantee
// that this is stable across allocations, but
// we want to print that here for debugging proposes.
// It has no further use.
modifier: buffer.modifier(), // no guarantee
// that this is stable across allocations, but
// we want to print that here for debugging proposes.
// It has no further use.
};

let use_opaque = !plane_formats.iter().any(|f| f.code == code);
Expand Down

0 comments on commit 1e09c12

Please sign in to comment.