Merge pull request #480 from Smithay/fix/winit_buffer_age
winit: Fix returned buffer age
This commit is contained in:
commit
adb7553888
|
@ -81,18 +81,28 @@ impl EGLSurface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the buffer age of the underlying back buffer
|
/// 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 surface = self.surface.load(Ordering::SeqCst);
|
||||||
let mut age = 0;
|
let mut age = 0;
|
||||||
unsafe {
|
let ret = unsafe {
|
||||||
ffi::egl::QuerySurface(
|
ffi::egl::QuerySurface(
|
||||||
**self.display,
|
**self.display,
|
||||||
surface as *const _,
|
surface as *const _,
|
||||||
ffi::egl::BUFFER_AGE_EXT as i32,
|
ffi::egl::BUFFER_AGE_EXT as i32,
|
||||||
&mut age as *mut _,
|
&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.
|
/// Swaps buffers at the end of a frame.
|
||||||
|
|
|
@ -874,6 +874,7 @@ impl Bind<Rc<EGLSurface>> for Gles2Renderer {
|
||||||
fn bind(&mut self, surface: Rc<EGLSurface>) -> Result<(), Gles2Error> {
|
fn bind(&mut self, surface: Rc<EGLSurface>) -> Result<(), Gles2Error> {
|
||||||
self.unbind()?;
|
self.unbind()?;
|
||||||
self.target_surface = Some(surface);
|
self.target_surface = Some(surface);
|
||||||
|
self.make_current()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -881,9 +882,7 @@ impl Bind<Rc<EGLSurface>> for Gles2Renderer {
|
||||||
impl Bind<Dmabuf> for Gles2Renderer {
|
impl Bind<Dmabuf> for Gles2Renderer {
|
||||||
fn bind(&mut self, dmabuf: Dmabuf) -> Result<(), Gles2Error> {
|
fn bind(&mut self, dmabuf: Dmabuf) -> Result<(), Gles2Error> {
|
||||||
self.unbind()?;
|
self.unbind()?;
|
||||||
unsafe {
|
self.make_current()?;
|
||||||
self.egl.make_current()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Free outdated buffer resources
|
// Free outdated buffer resources
|
||||||
// TODO: Replace with `drain_filter` once it lands
|
// TODO: Replace with `drain_filter` once it lands
|
||||||
|
|
|
@ -302,12 +302,19 @@ impl WinitGraphicsBackend {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the buffer age of the current backbuffer of the window
|
/// Retrieve the buffer age of the current backbuffer of the window.
|
||||||
pub fn buffer_age(&self) -> usize {
|
///
|
||||||
|
/// 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 {
|
if self.damage_tracking {
|
||||||
self.egl.buffer_age() as usize
|
self.egl.buffer_age().map(|x| x as usize)
|
||||||
} else {
|
} else {
|
||||||
0
|
Some(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue