X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihed-cros-libva%2Fsrc%2Fusage_hint.rs;h=66549452e1eb09fe6bc8503bbcce731bb5223bd0;hb=49bf1d79384ecf1b28822101233719fb1c1b29b1;hp=1e159682491233b994e02410c78e8da155900841;hpb=683627242f69bed0b818d976d4b03d651e529697;p=nihav-player.git diff --git a/nihed-cros-libva/src/usage_hint.rs b/nihed-cros-libva/src/usage_hint.rs dissimilarity index 86% index 1e15968..6654945 100644 --- a/nihed-cros-libva/src/usage_hint.rs +++ b/nihed-cros-libva/src/usage_hint.rs @@ -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 for UsageHints { + type Output = Self; + + fn bitor(self, rhs: UsageHint) -> Self { + Self(self.0 | rhs.bits()) + } +} + +impl BitOrAssign for UsageHints { + fn bitor_assign(&mut self, rhs: UsageHint) { + self.0 |= rhs.bits(); + } +} + +impl BitXor for UsageHints { + type Output = Self; + + fn bitxor(self, rhs: UsageHint) -> Self { + Self(self.0 ^ rhs.bits()) + } +} + +impl BitXorAssign for UsageHints { + fn bitxor_assign(&mut self, rhs: UsageHint) { + self.0 ^= rhs.bits(); + } +} + +impl BitAnd for UsageHints { + type Output = Self; + + fn bitand(self, rhs: UsageHint) -> Self { + Self(self.0 & rhs.bits()) + } +} + +impl BitAndAssign 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 for UsageHints { + fn from(val: UsageHint) -> Self { + Self(val.bits()) + } +} + +impl From for u32 { + fn from(val: UsageHint) -> u32 { + val.bits() + } +} + +impl UsageHint { + pub(crate) fn bits(self) -> u32 { + self as u32 + } +}