egl: Handle buffer age query errors
This commit is contained in:
parent
6ae0a3510a
commit
cd26ac1507
|
@ -81,18 +81,28 @@ impl EGLSurface {
|
|||
}
|
||||
|
||||
/// Returns the buffer age of the underlying back buffer
|
||||
pub fn buffer_age(&self) -> i32 {
|
||||
pub fn buffer_age(&self) -> Option<i32> {
|
||||
let surface = self.surface.load(Ordering::SeqCst);
|
||||
let mut age = 0;
|
||||
unsafe {
|
||||
let ret = unsafe {
|
||||
ffi::egl::QuerySurface(
|
||||
**self.display,
|
||||
surface as *const _,
|
||||
ffi::egl::BUFFER_AGE_EXT as i32,
|
||||
&mut age as *mut _,
|
||||
)
|
||||
};
|
||||
if ret == ffi::egl::FALSE {
|
||||
slog::debug!(
|
||||
self.logger,
|
||||
"Failed to query buffer age value for surface {:?}: {}",
|
||||
self,
|
||||
EGLError::from_last_call().unwrap_err()
|
||||
);
|
||||
None
|
||||
} else {
|
||||
Some(age)
|
||||
}
|
||||
age
|
||||
}
|
||||
|
||||
/// Swaps buffers at the end of a frame.
|
||||
|
|
|
@ -306,12 +306,15 @@ impl WinitGraphicsBackend {
|
|||
///
|
||||
/// This will only return a meaningful value, if this `WinitGraphicsBackend`
|
||||
/// is currently bound (by previously calling [`WinitGraphicsBackend::bind`]).
|
||||
/// Otherwise the contents of the return value are undefined.
|
||||
pub fn buffer_age(&self) -> usize {
|
||||
///
|
||||
/// Otherwise and on error this function returns `None`.
|
||||
/// If you are using this value actively e.g. for damage-tracking you should
|
||||
/// likely interpret an error just as if "0" was returned.
|
||||
pub fn buffer_age(&self) -> Option<usize> {
|
||||
if self.damage_tracking {
|
||||
self.egl.buffer_age() as usize
|
||||
self.egl.buffer_age().map(|x| x as usize)
|
||||
} else {
|
||||
0
|
||||
Some(0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue