forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

proc_pipeline.rs198 lines, 6.8 KiBHistoryRawDownload
1// Copyright 2025 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//! Wrappers around `VAProcPipeline` types.
6
7use crate::bindings;
8use std::{marker::PhantomData, ptr};
9
10/// Wrapper over the `VABlendState` ffi type.
11pub struct BlendState(bindings::VABlendState);
12
13impl BlendState {
14 /// Creates the bindgen field
15 pub fn new(flags: u32, global_alpha: f32, min_luma: f32, max_luma: f32) -> Self {
16 Self(bindings::VABlendState {
17 flags,
18 global_alpha,
19 min_luma,
20 max_luma,
21 })
22 }
23}
24
25/// Wrapper over the `VAProcColorProperties` ffi type.
26pub struct ProcColorProperties(bindings::VAProcColorProperties);
27
28impl ProcColorProperties {
29 /// Creates the bindgen field
30 pub fn new(
31 chroma_sample_location: u8,
32 color_range: u8,
33 colour_primaries: u8,
34 transfer_characteristics: u8,
35 matrix_coefficients: u8,
36 ) -> Self {
37 Self(bindings::VAProcColorProperties {
38 chroma_sample_location,
39 color_range,
40 colour_primaries,
41 transfer_characteristics,
42 matrix_coefficients,
43 reserved: Default::default(),
44 })
45 }
46}
47
48impl Default for ProcColorProperties {
49 fn default() -> Self {
50 Self::new(0, 0, 0, 0, 0)
51 }
52}
53
54/// Wrapper over the `VAHdrMetaData` ffi type.
55pub struct HdrMetaData(bindings::VAHdrMetaData);
56
57impl<'a> HdrMetaData {
58 /// Creates the bindgen field
59 pub fn new(metadata_type: u32, metadata: Option<&'a [u8]>, metadata_size: u32) -> Self {
60 Self(bindings::VAHdrMetaData {
61 metadata_type: metadata_type as _,
62 metadata: metadata.map_or(ptr::null_mut(), |f| f.as_ptr() as *mut _),
63 metadata_size,
64 reserved: Default::default(),
65 })
66 }
67}
68
69/// Wrapper over the `VAProcPipelineParameterBuffer` FFI type.
70pub struct ProcPipelineParameterBuffer {
71 c_params: Box<bindings::VAProcPipelineParameterBuffer>,
72
73 // Fields that own the data for the pointers in `c_params`.
74 surface_region: Option<Box<bindings::VARectangle>>,
75 output_region: Option<Box<bindings::VARectangle>>,
76 filters: Option<Vec<bindings::VABufferID>>,
77 forward_references: Option<Vec<bindings::VASurfaceID>>,
78 backward_references: Option<Vec<bindings::VASurfaceID>>,
79 blend_state: Option<Vec<BlendState>>,
80 additional_outputs: Option<Vec<bindings::VASurfaceID>>,
81 output_hdr_metadata: Option<Vec<HdrMetaData>>,
82}
83
84impl ProcPipelineParameterBuffer {
85 /// Creates the wrapper.
86 #[allow(clippy::too_many_arguments)]
87 pub fn new(
88 surface: bindings::VASurfaceID,
89 surface_region: Option<bindings::VARectangle>,
90 surface_color_standard: u8,
91 output_region: Option<bindings::VARectangle>,
92 output_background_color: u32,
93 output_color_standard: u8,
94 pipeline_flags: u32,
95 filter_flags: u32,
96 filters: Option<Vec<bindings::VABufferID>>,
97 forward_references: Option<Vec<bindings::VASurfaceID>>,
98 backward_references: Option<Vec<bindings::VASurfaceID>>,
99 rotation_state: u32,
100 blend_state: Option<Vec<BlendState>>,
101 mirror_state: u32,
102 additional_outputs: Option<Vec<bindings::VASurfaceID>>,
103 input_surface_flag: u32,
104 output_surface_flag: u32,
105 input_color_properties: ProcColorProperties,
106 output_color_properties: ProcColorProperties,
107 processing_mode: u32,
108 output_hdr_metadata: Option<Vec<HdrMetaData>>,
109 ) -> Self {
110 let mut slf = Self {
111 // SAFETY: The VA-API structures are C-compatible so zeroing is safe.
112 c_params: Box::new(unsafe { std::mem::zeroed() }),
113 surface_region: surface_region.map(Box::new),
114 output_region: output_region.map(Box::new),
115 filters,
116 forward_references,
117 backward_references,
118 blend_state,
119 additional_outputs,
120 output_hdr_metadata,
121 };
122
123 slf.c_params = Box::new(bindings::VAProcPipelineParameterBuffer {
124 surface,
125 surface_region: slf
126 .surface_region
127 .as_deref()
128 .map_or(ptr::null_mut(), |r| r as *const _ as *mut _),
129 surface_color_standard: surface_color_standard as _,
130 output_region: slf
131 .output_region
132 .as_deref()
133 .map_or(ptr::null_mut(), |r| r as *const _ as *mut _),
134 output_background_color,
135 output_color_standard: output_color_standard as _,
136 pipeline_flags,
137 filter_flags,
138 filters: slf
139 .filters
140 .as_deref()
141 .map_or(ptr::null_mut(), |f| f.as_ptr() as *mut _),
142 num_filters: slf.filters.as_ref().map_or(0, |f| f.len() as u32),
143 forward_references: slf
144 .forward_references
145 .as_deref()
146 .map_or(ptr::null_mut(), |r| r.as_ptr() as *mut _),
147 num_forward_references: slf
148 .forward_references
149 .as_ref()
150 .map_or(0, |f| f.len() as u32),
151 backward_references: slf
152 .backward_references
153 .as_deref()
154 .map_or(ptr::null_mut(), |r| r.as_ptr() as *mut _),
155 num_backward_references: slf
156 .backward_references
157 .as_ref()
158 .map_or(0, |b| b.len() as u32),
159 rotation_state,
160 blend_state: slf
161 .blend_state
162 .as_deref()
163 .map_or(ptr::null(), |b| b.as_ptr() as *const bindings::VABlendState),
164 mirror_state,
165 additional_outputs: slf
166 .additional_outputs
167 .as_deref()
168 .map_or(ptr::null_mut(), |a| a.as_ptr() as *mut _),
169 num_additional_outputs: slf
170 .additional_outputs
171 .as_ref()
172 .map_or(0, |a| a.len() as u32),
173 input_surface_flag,
174 output_surface_flag,
175 input_color_properties: input_color_properties.0,
176 output_color_properties: output_color_properties.0,
177 processing_mode,
178 output_hdr_metadata: slf
179 .output_hdr_metadata
180 .as_deref()
181 .map_or(ptr::null_mut(), |o| {
182 o.as_ptr() as *mut bindings::VAHdrMetaData
183 }),
184 va_reserved: Default::default(),
185 });
186
187 slf
188 }
189
190 pub(crate) fn inner_mut(&mut self) -> &mut bindings::VAProcPipelineParameterBuffer {
191 self.c_params.as_mut()
192 }
193
194 /// Returns the inner FFI type. Useful for testing purposes.
195 pub fn inner(&self) -> &bindings::VAProcPipelineParameterBuffer {
196 self.c_params.as_ref()
197 }
198}