Skip to content

Commit

Permalink
Update gbm to 0.18
Browse files Browse the repository at this point in the history
Eliminates `DeviceDestroyedError` and related error variants.
  • Loading branch information
ids1024 authored and Drakulix committed Dec 3, 2024
1 parent 17abcb2 commit 0eba496
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ drm-fourcc = "^2.2.0"
drm = { version = "0.14.0", optional = true }
drm-ffi = { version = "0.9.0", optional = true }
errno = "0.3.5"
gbm = { version = "0.16.0", optional = true, default-features = false, features = ["drm-support"] }
gbm = { version = "0.18.0", optional = true, default-features = false, features = ["drm-support"] }
glow = { version = "0.14", optional = true }
input = { version = "0.9.0", default-features = false, features=["libinput_1_19"], optional = true }
indexmap = "2.0"
Expand Down
27 changes: 7 additions & 20 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 @@ -253,23 +250,13 @@ pub enum GbmConvertError {
InvalidFD(#[from] gbm::InvalidFdError),
}

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(),
}
}
}

impl AsDmabuf for GbmBuffer {
type Error = GbmConvertError;

#[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 +266,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
34 changes: 10 additions & 24 deletions src/backend/drm/compositor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3431,7 +3431,6 @@ where
element_size,
cursor_plane_size,
output_transform,
&cursor_state.framebuffer_exporter,
&mut cursor_buffer,
) {
tracing::trace!("failed to copy element to cursor bo, skipping element on cursor plane");
Expand All @@ -3445,7 +3444,6 @@ where
element_size,
cursor_plane_size,
output_transform,
&cursor_state.framebuffer_exporter,
&mut cursor_buffer,
) {
profiling::scope!("render cursor plane");
Expand Down Expand Up @@ -3493,8 +3491,7 @@ where
}?;

let ret = cursor_buffer
.map_mut::<_, _, Result<_, <PixmanRenderer as Renderer>::Error>>(
&cursor_state.framebuffer_exporter,
.map_mut::<_, Result<_, <PixmanRenderer as Renderer>::Error>>(
0,
0,
cursor_buffer_size.w as u32,
Expand Down Expand Up @@ -3538,17 +3535,10 @@ where

_ = pixman_renderer.unbind();

match ret {
Err(err) => {
debug!("{err}");
return None;
}
Ok(Err(err)) => {
debug!("{err}");
return None;
}
Ok(Ok(_)) => (),
};
if let Err(err) = ret {
debug!("{err}");
return None;
}
};

let src = Rectangle::from_loc_and_size(Point::default(), cursor_buffer_size).to_f64();
Expand Down Expand Up @@ -4375,19 +4365,17 @@ fn apply_output_transform(transform: Transform, output_transform: Transform) ->
}

#[profiling::function]
fn copy_element_to_cursor_bo<R, E, T>(
fn copy_element_to_cursor_bo<R, E>(
renderer: &mut R,
element: &E,
element_size: Size<i32, Physical>,
cursor_size: Size<i32, Physical>,
output_transform: Transform,
device: &GbmDevice<T>,
bo: &mut GbmBuffer,
) -> bool
where
R: Renderer,
E: RenderElement<R>,
T: AsFd + 'static,
{
// Without access to the underlying storage we can not copy anything
let Some(underlying_storage) = element.underlying_storage(renderer) else {
Expand All @@ -4407,15 +4395,13 @@ 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(_)))
bo.write(src).is_ok()
} else {
let res = bo.map_mut(device, 0, 0, cursor_size.w as u32, cursor_size.h as u32, |mbo| {
let res = bo.map_mut(0, 0, cursor_size.w as u32, cursor_size.h as u32, |mbo| {
let dst = mbo.buffer_mut();
for row in 0..src_height {
let src_row_start = (row * src_stride) as usize;
Expand All @@ -4427,7 +4413,7 @@ where
dst_row.copy_from_slice(src_row);
}
});
matches!(res, Ok(Ok(_)))
res.is_ok()
}
};

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 0eba496

Please sign in to comment.