use NAPacketiser::attach_stream() where appropriate
[nihav-player.git] / nihed-cros-libva / src / usage_hint.rs
1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign};
6
7 use crate::constants;
8
9 /// Usage hint flags structure.
10 #[derive(Default, Clone, Copy, Debug, PartialEq)]
11 pub struct UsageHints(u32);
12
13 impl UsageHints {
14 /// Returns usage hint flags value as 32-bit integer.
15 pub fn bits(self) -> u32 {
16 self.0
17 }
18 }
19
20 impl BitOr<UsageHint> for UsageHints {
21 type Output = Self;
22
23 fn bitor(self, rhs: UsageHint) -> Self {
24 Self(self.0 | rhs.bits())
25 }
26 }
27
28 impl BitOrAssign<UsageHint> for UsageHints {
29 fn bitor_assign(&mut self, rhs: UsageHint) {
30 self.0 |= rhs.bits();
31 }
32 }
33
34 impl BitXor<UsageHint> for UsageHints {
35 type Output = Self;
36
37 fn bitxor(self, rhs: UsageHint) -> Self {
38 Self(self.0 ^ rhs.bits())
39 }
40 }
41
42 impl BitXorAssign<UsageHint> for UsageHints {
43 fn bitxor_assign(&mut self, rhs: UsageHint) {
44 self.0 ^= rhs.bits();
45 }
46 }
47
48 impl BitAnd<UsageHint> for UsageHints {
49 type Output = Self;
50
51 fn bitand(self, rhs: UsageHint) -> Self {
52 Self(self.0 & rhs.bits())
53 }
54 }
55
56 impl BitAndAssign<UsageHint> for UsageHints {
57 fn bitand_assign(&mut self, rhs: UsageHint) {
58 self.0 &= rhs.bits();
59 }
60 }
61
62 /// Gives the driver a hint of intended usage to optimize allocation (e.g. tiling).
63 #[repr(u32)]
64 #[derive(Clone, Copy, Debug, PartialEq)]
65 pub enum UsageHint {
66 /// Surface usage not indicated.
67 Generic = constants::VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC,
68 /// Surface used by video decoder.
69 Decoder = constants::VA_SURFACE_ATTRIB_USAGE_HINT_DECODER,
70 /// Surface used by video encoder.
71 Encoder = constants::VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER,
72 /// Surface read by video post-processing.
73 VppRead = constants::VA_SURFACE_ATTRIB_USAGE_HINT_VPP_READ,
74 /// Surface written by video post-processing.
75 VppWrite = constants::VA_SURFACE_ATTRIB_USAGE_HINT_VPP_WRITE,
76 /// Surface used for display.
77 Display = constants::VA_SURFACE_ATTRIB_USAGE_HINT_DISPLAY,
78 /// Surface used for export to third-party APIs, e.g. via `vaExportSurfaceHandle()`.
79 Export = constants::VA_SURFACE_ATTRIB_USAGE_HINT_EXPORT,
80 }
81
82 impl From<UsageHint> for UsageHints {
83 fn from(val: UsageHint) -> Self {
84 Self(val.bits())
85 }
86 }
87
88 impl From<UsageHint> for u32 {
89 fn from(val: UsageHint) -> u32 {
90 val.bits()
91 }
92 }
93
94 impl UsageHint {
95 pub(crate) fn bits(self) -> u32 {
96 self as u32
97 }
98 }