]> git.nihav.org Git - nihav-player.git/blobdiff - nihed-cros-libva/src/surface.rs
nihed-cros-libva: re-export VA_INVALID_ID for convenience
[nihav-player.git] / nihed-cros-libva / src / surface.rs
index 8c626ce36ed2f58d83eda34b6a15f3ade9f0c66e..2a77a39d7d61b4839a806b7677427595e7bc7f4f 100644 (file)
@@ -4,12 +4,11 @@
 
 use std::rc::Rc;
 
-use anyhow::Result;
-
 use crate::bindings;
 use crate::display::Display;
-use crate::status::Status;
-use crate::UsageHint;
+use crate::formats::{RTFormat, VAFourcc};
+use crate::status::*;
+use crate::UsageHints;
 
 /// An owned VA surface that is tied to the lifetime of a particular VADisplay
 pub struct Surface {
@@ -24,23 +23,23 @@ impl Surface {
     /// [`Display::create_surfaces`].
     pub(crate) fn new(
         display: Rc<Display>,
-        rt_format: u32,
-        va_fourcc: Option<u32>,
+        rt_format: RTFormat,
+        va_fourcc: Option<VAFourcc>,
         width: u32,
         height: u32,
-        usage_hint: Option<UsageHint>,
+        usage_hints: Option<UsageHints>,
         num_surfaces: u32,
-    ) -> Result<Vec<Self>> {
+    ) -> VAResult<Vec<Self>> {
         let mut attrs = vec![];
 
-        if let Some(usage_hint) = usage_hint {
+        if let Some(usage_hints) = usage_hints {
             let attr = bindings::VASurfaceAttrib {
                 type_: bindings::VASurfaceAttribType::VASurfaceAttribUsageHint,
                 flags: bindings::constants::VA_SURFACE_ATTRIB_SETTABLE,
                 value: bindings::VAGenericValue {
                     type_: bindings::VAGenericValueType::VAGenericValueTypeInteger,
                     value: bindings::_VAGenericValue__bindgen_ty_1 {
-                        i: usage_hint.bits() as i32,
+                        i: usage_hints.bits() as i32,
                     },
                 },
             };
@@ -66,10 +65,10 @@ impl Surface {
         // Safe because `self` represents a valid VADisplay. The `surface` and `attrs` vectors are
         // properly initialized and valid sizes are passed to the C function, so it is impossible to
         // write past the end of their storage by mistake.
-        Status(unsafe {
+        (unsafe {
             bindings::vaCreateSurfaces(
                 display.handle(),
-                rt_format,
+                rt_format.into(),
                 width,
                 height,
                 surfaces.as_mut_ptr(),
@@ -101,9 +100,9 @@ impl Surface {
 
     /// Blocks until all pending operations on the render target have been completed. Upon return it
     /// is safe to use the render target for a different picture.
-    pub fn sync(&self) -> Result<()> {
+    pub fn sync(&self) -> VAResult<()> {
         // Safe because `self` represents a valid VASurface.
-        Status(unsafe { bindings::vaSyncSurface(self.display.handle(), self.id) }).check()
+        (unsafe { bindings::vaSyncSurface(self.display.handle(), self.id) }).check()
     }
 
     /// Convenience function to return a VASurfaceID vector. Useful to interface with the C API
@@ -113,14 +112,20 @@ impl Surface {
     }
 
     /// Wrapper over `vaQuerySurfaceStatus` to find out any pending ops on the render target.
-    pub fn query_status(&self) -> Result<bindings::VASurfaceStatus::Type> {
+    pub fn query_status(&self) -> VAResult<VASurfaceStatus> {
         let mut status: bindings::VASurfaceStatus::Type = 0;
         // Safe because `self` represents a valid VASurface.
-        Status(unsafe {
+        (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.