Merge pull request #480 from Smithay/fix/winit_buffer_age

winit: Fix returned buffer age
This commit is contained in:
Victoria Brekenfeld 2022-01-25 18:59:45 +01:00 committed by GitHub
commit adb7553888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 10 deletions

View File

@ -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.

View File

@ -874,6 +874,7 @@ impl Bind<Rc<EGLSurface>> for Gles2Renderer {
fn bind(&mut self, surface: Rc<EGLSurface>) -> Result<(), Gles2Error> {
self.unbind()?;
self.target_surface = Some(surface);
self.make_current()?;
Ok(())
}
}
@ -881,9 +882,7 @@ impl Bind<Rc<EGLSurface>> for Gles2Renderer {
impl Bind<Dmabuf> for Gles2Renderer {
fn bind(&mut self, dmabuf: Dmabuf) -> Result<(), Gles2Error> {
self.unbind()?;
unsafe {
self.egl.make_current()?;
}
self.make_current()?;
// Free outdated buffer resources
// TODO: Replace with `drain_filter` once it lands

View File

@ -302,12 +302,19 @@ impl WinitGraphicsBackend {
Ok(())
}
/// Retrieve the buffer age of the current backbuffer of the window
pub fn buffer_age(&self) -> usize {
/// Retrieve the buffer age of the current backbuffer of the window.
///
/// This will only return a meaningful value, if this `WinitGraphicsBackend`
/// is currently bound (by previously calling [`WinitGraphicsBackend::bind`]).
///
/// 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)
}
}