backend.egl: Early return on dead buffers (#352)

This commit is contained in:
Poly 2021-07-28 23:31:43 +02:00 committed by GitHub
parent c136cd5f34
commit e3522dfb34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -2,6 +2,10 @@
## Unreleased
### Bugfixes
- EGLBufferReader now checks if buffers are alive before using them.
## version 0.3.0 (2021-07-25)
Large parts of Smithay were changed with numerous API changes. It is thus recommended to

View File

@ -535,7 +535,7 @@ impl EGLDisplay {
ffi::egl::BindWaylandDisplayWL(**self.display, display.c_ptr() as *mut _)
})
.map_err(Error::OtherEGLDisplayAlreadyBound)?;
let reader = EGLBufferReader::new(self.display.clone(), display.c_ptr());
let reader = EGLBufferReader::new(self.display.clone(), display.c_ptr(), self.logger.clone());
let mut global = BUFFER_READER.lock().unwrap();
if global.as_ref().and_then(|x| x.upgrade()).is_some() {
warn!(
@ -545,6 +545,7 @@ impl EGLDisplay {
}
*global = Some(WeakBufferReader {
display: Arc::downgrade(&self.display),
logger: self.logger.clone(),
});
Ok(reader)
}
@ -672,11 +673,13 @@ fn get_dmabuf_formats(
pub struct EGLBufferReader {
display: Arc<EGLDisplayHandle>,
wayland: Option<Arc<*mut wl_display>>,
logger: ::slog::Logger,
}
#[cfg(feature = "use_system_lib")]
pub(crate) struct WeakBufferReader {
display: Weak<EGLDisplayHandle>,
logger: ::slog::Logger,
}
#[cfg(feature = "use_system_lib")]
@ -685,6 +688,7 @@ impl WeakBufferReader {
Some(EGLBufferReader {
display: self.display.upgrade()?,
wayland: None,
logger: self.logger.clone(),
})
}
}
@ -694,10 +698,16 @@ unsafe impl Send for EGLBufferReader {}
#[cfg(feature = "use_system_lib")]
impl EGLBufferReader {
fn new(display: Arc<EGLDisplayHandle>, wayland: *mut wl_display) -> Self {
fn new<L>(display: Arc<EGLDisplayHandle>, wayland: *mut wl_display, log: L) -> Self
where
L: Into<Option<::slog::Logger>>,
{
let logger = crate::slog_or_fallback(log.into()).new(o!("smithay_module" => "egl_buffer_reader"));
Self {
display,
wayland: Some(Arc::new(wayland)),
logger,
}
}
@ -709,6 +719,11 @@ impl EGLBufferReader {
&self,
buffer: &WlBuffer,
) -> ::std::result::Result<EGLBuffer, BufferAccessError> {
if !buffer.as_ref().is_alive() {
debug!(self.logger, "Suplied buffer is no longer alive");
return Err(BufferAccessError::NotManaged(EGLError::BadParameter));
}
let mut format: i32 = 0;
let query = wrap_egl_call(|| unsafe {
ffi::egl::QueryWaylandBufferWL(
@ -825,6 +840,11 @@ impl EGLBufferReader {
&self,
buffer: &WlBuffer,
) -> Option<crate::utils::Size<i32, crate::utils::Physical>> {
if !buffer.as_ref().is_alive() {
debug!(self.logger, "Suplied buffer is no longer alive");
return None;
}
let mut width: i32 = 0;
if unsafe {
ffi::egl::QueryWaylandBufferWL(