From 36e9827eab662e7145fb0dd0a9176a06932895fd Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Fri, 20 Oct 2023 18:33:27 +0200 Subject: [PATCH] nihed-cros-libva: convert surface query status to enum --- nihed-cros-libva/src/lib.rs | 1 - nihed-cros-libva/src/picture.rs | 2 +- nihed-cros-libva/src/status.rs | 22 ++++++++++++++++++++++ nihed-cros-libva/src/surface.rs | 10 ++++++++-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/nihed-cros-libva/src/lib.rs b/nihed-cros-libva/src/lib.rs index 83b459a..953b57c 100644 --- a/nihed-cros-libva/src/lib.rs +++ b/nihed-cros-libva/src/lib.rs @@ -29,7 +29,6 @@ pub use bindings::VAImageFormat; pub use bindings::VAProfile; pub use bindings::VASurfaceAttribType; pub use bindings::VASurfaceID; -pub use bindings::VASurfaceStatus; pub use buffer::*; pub use config::*; pub use context::*; diff --git a/nihed-cros-libva/src/picture.rs b/nihed-cros-libva/src/picture.rs index adf6a94..0d28b51 100644 --- a/nihed-cros-libva/src/picture.rs +++ b/nihed-cros-libva/src/picture.rs @@ -219,7 +219,7 @@ impl Picture { /// /// This call can be used to implement a non-blocking path, wherein a decoder queries the status /// of the surface after each decode operation instead of blocking on it. - pub fn query_status(&self) -> VAResult { + pub fn query_status(&self) -> VAResult { self.inner.surface.borrow_mut().query_status() } } diff --git a/nihed-cros-libva/src/status.rs b/nihed-cros-libva/src/status.rs index 0cf3f5b..5dac0bf 100644 --- a/nihed-cros-libva/src/status.rs +++ b/nihed-cros-libva/src/status.rs @@ -132,3 +132,25 @@ impl ConvertStatus for bindings::VAStatus { } } } + +/// Surface status. +#[repr(u32)] +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum VASurfaceStatus { + /// Rendering in progress. + Rendering = 1, + /// Displaying in progress (not safe to render into it). + /// + /// This status is useful if surface is used as the source of an overlay. + Displaying = 2, + /// Not being rendered or displayed. + Ready = 3, + /// Indicate a skipped frame during encode. + Skipped = 8, +} + +impl std::fmt::Display for VASurfaceStatus { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} diff --git a/nihed-cros-libva/src/surface.rs b/nihed-cros-libva/src/surface.rs index ddc1f15..fe11749 100644 --- a/nihed-cros-libva/src/surface.rs +++ b/nihed-cros-libva/src/surface.rs @@ -111,14 +111,20 @@ impl Surface { } /// Wrapper over `vaQuerySurfaceStatus` to find out any pending ops on the render target. - pub fn query_status(&self) -> VAResult { + pub fn query_status(&self) -> VAResult { let mut status: bindings::VASurfaceStatus::Type = 0; // Safe because `self` represents a valid VASurface. (unsafe { bindings::vaQuerySurfaceStatus(self.display.handle(), self.id, &mut status) }) .check()?; - Ok(status) + match status { + bindings::VASurfaceStatus::VASurfaceRendering => Ok(VASurfaceStatus::Rendering), + bindings::VASurfaceStatus::VASurfaceDisplaying => Ok(VASurfaceStatus::Displaying), + bindings::VASurfaceStatus::VASurfaceReady => Ok(VASurfaceStatus::Ready), + bindings::VASurfaceStatus::VASurfaceSkipped => Ok(VASurfaceStatus::Skipped), + _ => Err(VAError::Unknown), + } } /// Returns the ID of this surface. -- 2.39.5