gbm: expose buffer age

This commit is contained in:
Victor Brekenfeld 2021-11-23 17:28:48 +01:00
parent 6c57e27e5e
commit a4f2729608
3 changed files with 7 additions and 5 deletions

View File

@ -26,6 +26,7 @@
- Remove `InputBackend::dispatch_new_events`, turning `InputBackend` into a definition of backend event types. Future input backends should be a `calloop::EventSource`. - Remove `InputBackend::dispatch_new_events`, turning `InputBackend` into a definition of backend event types. Future input backends should be a `calloop::EventSource`.
- Remove `InputBackend::EventError` associated type as it is unneeded since `dispatch_new_events` was removed. - Remove `InputBackend::EventError` associated type as it is unneeded since `dispatch_new_events` was removed.
- `Swapchain` does not have a generic Userdata-parameter anymore, but utilizes `UserDataMap` instead - `Swapchain` does not have a generic Userdata-parameter anymore, but utilizes `UserDataMap` instead
- `GbmBufferedSurface::next_buffer` now additionally returns the age of the buffer
### Additions ### Additions

View File

@ -738,7 +738,7 @@ fn render_surface(
return Ok(()); return Ok(());
}; };
let dmabuf = surface.surface.next_buffer()?; let (dmabuf, _age) = surface.surface.next_buffer()?;
renderer.bind(dmabuf)?; renderer.bind(dmabuf)?;
// and draw to our buffer // and draw to our buffer
@ -867,7 +867,7 @@ fn schedule_initial_render<Data: 'static>(
} }
fn initial_render(surface: &mut RenderSurface, renderer: &mut Gles2Renderer) -> Result<(), SwapBuffersError> { fn initial_render(surface: &mut RenderSurface, renderer: &mut Gles2Renderer) -> Result<(), SwapBuffersError> {
let dmabuf = surface.next_buffer()?; let (dmabuf, _age) = surface.next_buffer()?;
renderer.bind(dmabuf)?; renderer.bind(dmabuf)?;
// Does not matter if we render an empty frame // Does not matter if we render an empty frame
renderer renderer

View File

@ -167,11 +167,11 @@ where
} }
} }
/// Retrieves the next buffer to be rendered into. /// Retrieves the next buffer to be rendered into and it's age.
/// ///
/// *Note*: This function can be called multiple times and /// *Note*: This function can be called multiple times and
/// will return the same buffer until it is queued (see [`GbmBufferedSurface::queue_buffer`]). /// will return the same buffer until it is queued (see [`GbmBufferedSurface::queue_buffer`]).
pub fn next_buffer(&mut self) -> Result<Dmabuf, Error> { pub fn next_buffer(&mut self) -> Result<(Dmabuf, u8), Error> {
if self.next_fb.is_none() { if self.next_fb.is_none() {
let slot = self.swapchain.acquire()?.ok_or(Error::NoFreeSlotsError)?; let slot = self.swapchain.acquire()?.ok_or(Error::NoFreeSlotsError)?;
@ -189,7 +189,7 @@ where
} }
let slot = self.next_fb.as_ref().unwrap(); let slot = self.next_fb.as_ref().unwrap();
Ok(slot.userdata().get::<Dmabuf>().unwrap().clone()) Ok((slot.userdata().get::<Dmabuf>().unwrap().clone(), slot.age()))
} }
/// Queues the current buffer for rendering. /// Queues the current buffer for rendering.
@ -213,6 +213,7 @@ where
pub fn frame_submitted(&mut self) -> Result<(), Error> { pub fn frame_submitted(&mut self) -> Result<(), Error> {
if let Some(mut pending) = self.pending_fb.take() { if let Some(mut pending) = self.pending_fb.take() {
std::mem::swap(&mut pending, &mut self.current_fb); std::mem::swap(&mut pending, &mut self.current_fb);
self.swapchain.submitted(pending);
if self.queued_fb.is_some() { if self.queued_fb.is_some() {
self.submit()?; self.submit()?;
} }