backend.egl: add egl_buffer_dimensions

Allows to retrieve just the dimensions, without creating images and
whatnot.
This commit is contained in:
Ivan Molodetskikh 2020-02-03 08:39:28 +03:00
parent e07a57885b
commit 46348367b1
No known key found for this signature in database
GPG Key ID: 02CE38DA47E9D691
1 changed files with 36 additions and 0 deletions

View File

@ -472,6 +472,42 @@ impl EGLDisplay {
Err(BufferAccessError::ContextLost) Err(BufferAccessError::ContextLost)
} }
} }
/// Try to receive the dimensions of a given [`WlBuffer`].
///
/// In case the buffer is not managed by EGL (but e.g. the [`wayland::shm` module](::wayland::shm)) or the
/// context has been lost, `None` is returned.
pub fn egl_buffer_dimensions(&self, buffer: &WlBuffer) -> Option<(i32, i32)> {
if let Some(display) = self.egl.upgrade() {
let mut width: i32 = 0;
if unsafe {
ffi::egl::QueryWaylandBufferWL(
*display,
buffer.as_ref().c_ptr() as *mut _,
ffi::egl::WIDTH as i32,
&mut width as *mut _,
) == 0
} {
return None;
}
let mut height: i32 = 0;
if unsafe {
ffi::egl::QueryWaylandBufferWL(
*display,
buffer.as_ref().c_ptr() as *mut _,
ffi::egl::HEIGHT as i32,
&mut height as *mut _,
) == 0
} {
return None;
}
Some((width, height))
} else {
None
}
}
} }
#[cfg(feature = "native_lib")] #[cfg(feature = "native_lib")]