]> git.nihav.org Git - nihav-player.git/commitdiff
nihed-cros-libva: rework UsageHint and drop bitflags dependency
authorKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 20 Oct 2023 16:33:27 +0000 (18:33 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Fri, 20 Oct 2023 16:33:27 +0000 (18:33 +0200)
nihed-cros-libva/Cargo.toml
nihed-cros-libva/src/display.rs
nihed-cros-libva/src/surface.rs
nihed-cros-libva/src/usage_hint.rs

index cc5096b52d854f9d59cc02d3e813b025d2f6e617..c265e880fc17126387d28b0934985e9f4a31db95 100644 (file)
@@ -6,9 +6,6 @@ description = "Safe bindings over libva"
 authors = ["The Chromium OS Authors", "random nobody"]
 edition = "2021"
 
-[dependencies]
-bitflags = "1.3"
-
 [build-dependencies]
 pkg-config = "0.3.26"
 
index f5a5b66200318985f3fc5b096acf6bfa2b609318..9e7c3e0d91135daf809ba95fb6ed5f2e09fdef6b 100644 (file)
@@ -14,7 +14,7 @@ use crate::config::Config;
 use crate::context::Context;
 use crate::status::*;
 use crate::surface::Surface;
-use crate::UsageHint;
+use crate::UsageHints;
 
 /// Iterates over existing DRM devices.
 ///
@@ -242,7 +242,7 @@ impl Display {
         va_fourcc: Option<u32>,
         width: u32,
         height: u32,
-        usage_hint: Option<UsageHint>,
+        usage_hints: Option<UsageHints>,
         num_surfaces: u32,
     ) -> VAResult<Vec<Surface>> {
         Surface::new(
@@ -251,7 +251,7 @@ impl Display {
             va_fourcc,
             width,
             height,
-            usage_hint,
+            usage_hints,
             num_surfaces,
         )
     }
index d16fedc127f0589abe675acc0c05c36648b037be..ddc1f157d3b591bc7091c087baa647fa94f9e9f3 100644 (file)
@@ -7,7 +7,7 @@ use std::rc::Rc;
 use crate::bindings;
 use crate::display::Display;
 use crate::status::*;
-use crate::UsageHint;
+use crate::UsageHints;
 
 /// An owned VA surface that is tied to the lifetime of a particular VADisplay
 pub struct Surface {
@@ -26,19 +26,19 @@ impl Surface {
         va_fourcc: Option<u32>,
         width: u32,
         height: u32,
-        usage_hint: Option<UsageHint>,
+        usage_hints: Option<UsageHints>,
         num_surfaces: u32,
     ) -> 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,
                     },
                 },
             };
dissimilarity index 86%
index 1e159682491233b994e02410c78e8da155900841..66549452e1eb09fe6bc8503bbcce731bb5223bd0 100644 (file)
@@ -1,27 +1,98 @@
-// Copyright 2022 The ChromiumOS Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-use bitflags::bitflags;
-
-use crate::constants;
-
-bitflags! {
-    /// Gives the driver a hint of intended usage to optimize allocation (e.g. tiling).
-    pub struct UsageHint: u32 {
-        /// Surface usage not indicated.
-        const USAGE_HINT_GENERIC = constants::VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC;
-        /// Surface used by video decoder.
-        const USAGE_HINT_DECODER = constants::VA_SURFACE_ATTRIB_USAGE_HINT_DECODER;
-        /// Surface used by video encoder.
-        const USAGE_HINT_ENCODER = constants::VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER;
-        /// Surface read by video post-processing.
-        const USAGE_HINT_VPP_READ = constants::VA_SURFACE_ATTRIB_USAGE_HINT_VPP_READ;
-        /// Surface written by video post-processing.
-        const USAGE_HINT_VPP_WRITE = constants::VA_SURFACE_ATTRIB_USAGE_HINT_VPP_WRITE;
-        /// Surface used for display.
-        const USAGE_HINT_DISPLAY = constants::VA_SURFACE_ATTRIB_USAGE_HINT_DISPLAY;
-        /// Surface used for export to third-party APIs, e.g. via `vaExportSurfaceHandle()`.
-        const USAGE_HINT_EXPORT = constants::VA_SURFACE_ATTRIB_USAGE_HINT_EXPORT;
-    }
-}
+// Copyright 2022 The ChromiumOS Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign};
+
+use crate::constants;
+
+/// Usage hint flags structure.
+#[derive(Default, Clone, Copy, Debug, PartialEq)]
+pub struct UsageHints(u32);
+
+impl UsageHints {
+    /// Returns usage hint flags value as 32-bit integer.
+    pub fn bits(self) -> u32 {
+        self.0
+    }
+}
+
+impl BitOr<UsageHint> for UsageHints {
+    type Output = Self;
+
+    fn bitor(self, rhs: UsageHint) -> Self {
+        Self(self.0 | rhs.bits())
+    }
+}
+
+impl BitOrAssign<UsageHint> for UsageHints {
+    fn bitor_assign(&mut self, rhs: UsageHint) {
+        self.0 |= rhs.bits();
+    }
+}
+
+impl BitXor<UsageHint> for UsageHints {
+    type Output = Self;
+
+    fn bitxor(self, rhs: UsageHint) -> Self {
+        Self(self.0 ^ rhs.bits())
+    }
+}
+
+impl BitXorAssign<UsageHint> for UsageHints {
+    fn bitxor_assign(&mut self, rhs: UsageHint) {
+        self.0 ^= rhs.bits();
+    }
+}
+
+impl BitAnd<UsageHint> for UsageHints {
+    type Output = Self;
+
+    fn bitand(self, rhs: UsageHint) -> Self {
+        Self(self.0 & rhs.bits())
+    }
+}
+
+impl BitAndAssign<UsageHint> for UsageHints {
+    fn bitand_assign(&mut self, rhs: UsageHint) {
+        self.0 &= rhs.bits();
+    }
+}
+
+/// Gives the driver a hint of intended usage to optimize allocation (e.g. tiling).
+#[repr(u32)]
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub enum UsageHint {
+    /// Surface usage not indicated.
+    Generic = constants::VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC,
+    /// Surface used by video decoder.
+    Decoder = constants::VA_SURFACE_ATTRIB_USAGE_HINT_DECODER,
+    /// Surface used by video encoder.
+    Encoder = constants::VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER,
+    /// Surface read by video post-processing.
+    VppRead = constants::VA_SURFACE_ATTRIB_USAGE_HINT_VPP_READ,
+    /// Surface written by video post-processing.
+    VppWrite = constants::VA_SURFACE_ATTRIB_USAGE_HINT_VPP_WRITE,
+    /// Surface used for display.
+    Display = constants::VA_SURFACE_ATTRIB_USAGE_HINT_DISPLAY,
+    /// Surface used for export to third-party APIs, e.g. via `vaExportSurfaceHandle()`.
+    Export = constants::VA_SURFACE_ATTRIB_USAGE_HINT_EXPORT,
+}
+
+impl From<UsageHint> for UsageHints {
+    fn from(val: UsageHint) -> Self {
+        Self(val.bits())
+    }
+}
+
+impl From<UsageHint> for u32 {
+    fn from(val: UsageHint) -> u32 {
+        val.bits()
+    }
+}
+
+impl UsageHint {
+    pub(crate) fn bits(self) -> u32 {
+        self as u32
+    }
+}