1
0
Fork 0
forked from wry/wry

video: always use correct modifiers

This commit is contained in:
Julian Orth 2023-11-04 14:06:18 +01:00
parent 283774ae4c
commit bf90204db6
17 changed files with 196 additions and 55 deletions

View file

@ -17,6 +17,7 @@ use {
},
ahash::AHashMap,
bstr::{BString, ByteSlice},
indexmap::IndexSet,
std::{
cell::RefCell,
ffi::CString,
@ -181,7 +182,7 @@ impl Drm {
pub struct InFormat {
pub format: u32,
pub modifiers: Vec<Modifier>,
pub modifiers: IndexSet<Modifier>,
}
pub struct DrmMaster {
@ -418,7 +419,7 @@ impl DrmMaster {
.unwrap()
.map(|f| InFormat {
format: f,
modifiers: vec![],
modifiers: IndexSet::new(),
})
.collect();
let modifiers =
@ -435,7 +436,7 @@ impl DrmMaster {
log::error!("Modifier offset is out of bounds");
return Err(DrmError::InFormats);
}
formats[idx].modifiers.push(modifier.modifier);
formats[idx].modifiers.insert(modifier.modifier);
}
}
Ok(formats)

View file

@ -7,7 +7,7 @@ use {
video::{
dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
drm::{Drm, DrmError},
Modifier,
Modifier, INVALID_MODIFIER,
},
},
std::{
@ -34,6 +34,8 @@ pub enum GbmError {
DrmFd,
#[error("Could not map bo")]
MapBo(#[source] OsError),
#[error("Tried to allocate a buffer with no modifier")]
NoModifier,
}
pub type Device = u8;
@ -195,18 +197,23 @@ impl GbmDevice {
self.dev
}
pub fn create_bo(
pub fn create_bo<'a>(
&self,
width: i32,
height: i32,
format: &Format,
modifiers: &[Modifier],
usage: u32,
modifiers: impl IntoIterator<Item = &'a Modifier>,
mut usage: u32,
) -> Result<GbmBo, GbmError> {
unsafe {
let (modifiers, n_modifiers) = if modifiers.is_empty() {
let modifiers: Vec<Modifier> = modifiers.into_iter().copied().collect();
if modifiers.is_empty() {
return Err(GbmError::NoModifier);
}
let (modifiers, n_modifiers) = if modifiers == [INVALID_MODIFIER] {
(ptr::null(), 0)
} else {
usage &= !GBM_BO_USE_LINEAR;
(modifiers.as_ptr() as _, modifiers.len() as _)
};
let bo = gbm_bo_create_with_modifiers2(