| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | use crate::bindings; |
| 8 | use std::{marker::PhantomData, ptr}; |
| 9 | |
| 10 | |
| 11 | pub struct BlendState(bindings::VABlendState); |
| 12 | |
| 13 | impl BlendState { |
| 14 | |
| 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 | |
| 26 | pub struct ProcColorProperties(bindings::VAProcColorProperties); |
| 27 | |
| 28 | impl ProcColorProperties { |
| 29 | |
| 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 | |
| 48 | impl Default for ProcColorProperties { |
| 49 | fn default() -> Self { |
| 50 | Self::new(0, 0, 0, 0, 0) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | |
| 55 | pub struct HdrMetaData(bindings::VAHdrMetaData); |
| 56 | |
| 57 | impl<'a> HdrMetaData { |
| 58 | |
| 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 | |
| 70 | pub struct ProcPipelineParameterBuffer { |
| 71 | c_params: Box<bindings::VAProcPipelineParameterBuffer>, |
| 72 | |
| 73 | |
| 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 | |
| 84 | impl ProcPipelineParameterBuffer { |
| 85 | |
| 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 | |
| 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 | |
| 195 | pub fn inner(&self) -> &bindings::VAProcPipelineParameterBuffer { |
| 196 | self.c_params.as_ref() |
| 197 | } |
| 198 | } |