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.
5 use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign};
9 /// Usage hint flags structure.
10 #[derive(Default, Clone, Copy, Debug, PartialEq)]
11 pub struct UsageHints(u32);
14 /// Returns usage hint flags value as 32-bit integer.
15 pub fn bits(self) -> u32 {
20 impl BitOr<UsageHint> for UsageHints {
23 fn bitor(self, rhs: UsageHint) -> Self {
24 Self(self.0 | rhs.bits())
28 impl BitOrAssign<UsageHint> for UsageHints {
29 fn bitor_assign(&mut self, rhs: UsageHint) {
34 impl BitXor<UsageHint> for UsageHints {
37 fn bitxor(self, rhs: UsageHint) -> Self {
38 Self(self.0 ^ rhs.bits())
42 impl BitXorAssign<UsageHint> for UsageHints {
43 fn bitxor_assign(&mut self, rhs: UsageHint) {
48 impl BitAnd<UsageHint> for UsageHints {
51 fn bitand(self, rhs: UsageHint) -> Self {
52 Self(self.0 & rhs.bits())
56 impl BitAndAssign<UsageHint> for UsageHints {
57 fn bitand_assign(&mut self, rhs: UsageHint) {
62 /// Gives the driver a hint of intended usage to optimize allocation (e.g. tiling).
64 #[derive(Clone, Copy, Debug, PartialEq)]
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,
82 impl From<UsageHint> for UsageHints {
83 fn from(val: UsageHint) -> Self {
88 impl From<UsageHint> for u32 {
89 fn from(val: UsageHint) -> u32 {
95 pub(crate) fn bits(self) -> u32 {