From 46348367b1f8d14443c3c1d7bc1bcb39f631b9b1 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 3 Feb 2020 08:39:28 +0300 Subject: [PATCH] backend.egl: add egl_buffer_dimensions Allows to retrieve just the dimensions, without creating images and whatnot. --- src/backend/egl/mod.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/backend/egl/mod.rs b/src/backend/egl/mod.rs index 316df5d..6ecdde3 100644 --- a/src/backend/egl/mod.rs +++ b/src/backend/egl/mod.rs @@ -472,6 +472,42 @@ impl EGLDisplay { 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")]