Skip to content

Commit

Permalink
Fix Surface::lock_front_buffer failing when ffi::gbm_surface_lock_fro…
Browse files Browse the repository at this point in the history
…nt_buffer succeeds

With the proprietary vivante driver it's been observed that
gbm_surface_has_free_buffers() fails even though
gbm_surface_lock_front_buffer() succeeds. Since C/C++ based programs
like Weston, kmscube, mutter, or Qt's eglfs renderer don't check for
has_free_buffers() before lock_front_buffer() and they work with said
drivers, work around it by removing the check.

Fixes #36
  • Loading branch information
tronical authored and Drakulix committed Mar 20, 2024
1 parent 606c426 commit 754a957
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ impl<T: 'static> fmt::Debug for Surface<T> {
/// Errors that may happen when locking the front buffer
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FrontBufferError {
/// No free buffers are currently available
NoFreeBuffers,
/// An unknown error happened
Unknown,
/// Device was already released
Expand All @@ -33,7 +31,6 @@ pub enum FrontBufferError {
impl fmt::Display for FrontBufferError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
FrontBufferError::NoFreeBuffers => write!(f, "No free buffers remaining"),
FrontBufferError::Unknown => write!(f, "Unknown error"),
FrontBufferError::Destroyed(ref err) => write!(f, "Buffer was destroyed: {}", err),
}
Expand Down Expand Up @@ -81,25 +78,21 @@ impl<T: 'static> Surface<T> {
pub unsafe fn lock_front_buffer(&self) -> Result<BufferObject<T>, FrontBufferError> {
let device = self._device.upgrade();
if device.is_some() {
if ffi::gbm_surface_has_free_buffers(*self.ffi) != 0 {
let buffer_ptr = ffi::gbm_surface_lock_front_buffer(*self.ffi);
if !buffer_ptr.is_null() {
let surface_ptr = self.ffi.downgrade();
let buffer = BufferObject {
ffi: Ptr::new(buffer_ptr, move |ptr| {
if let Some(surface) = surface_ptr.upgrade() {
ffi::gbm_surface_release_buffer(*surface, ptr);
}
}),
_device: self._device.clone(),
_userdata: std::marker::PhantomData,
};
Ok(buffer)
} else {
Err(FrontBufferError::Unknown)
}
let buffer_ptr = ffi::gbm_surface_lock_front_buffer(*self.ffi);
if !buffer_ptr.is_null() {
let surface_ptr = self.ffi.downgrade();
let buffer = BufferObject {
ffi: Ptr::new(buffer_ptr, move |ptr| {
if let Some(surface) = surface_ptr.upgrade() {
ffi::gbm_surface_release_buffer(*surface, ptr);
}
}),
_device: self._device.clone(),
_userdata: std::marker::PhantomData,
};
Ok(buffer)
} else {
Err(FrontBufferError::NoFreeBuffers)
Err(FrontBufferError::Unknown)
}
} else {
Err(FrontBufferError::Destroyed(DeviceDestroyedError))
Expand Down

0 comments on commit 754a957

Please sign in to comment.