Skip to content

Commit

Permalink
egl: handle DRM_FORMAT_MOD_INVALID specially
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Mar 5, 2024
1 parent fe6ee46 commit 716d9a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
6 changes: 4 additions & 2 deletions wayrs-egl/src/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fmt;
use wayrs_client::Connection;
use wayrs_protocols::linux_dmabuf_unstable_v1::*;

use crate::{egl_ffi, gbm, Buffer, Error, Fourcc, GraphicsApi, Result};
use crate::{egl_ffi, gbm, Buffer, Error, Fourcc, GraphicsApi, Result, DRM_FORMAT_MOD_INVALID};

/// GBM-based EGL display
///
Expand Down Expand Up @@ -151,7 +151,9 @@ impl EglDisplay {
/// Check whether a fourcc/modifier pair is supported
pub fn is_format_supported(&self, fourcc: Fourcc, modifier: u64) -> bool {
match self.supported_formats.get(&fourcc) {
Some(mods) => mods.contains(&modifier),
Some(mods) => {
(mods.is_empty() && modifier == DRM_FORMAT_MOD_INVALID) || mods.contains(&modifier)
}
None => false,
}
}
Expand Down
34 changes: 23 additions & 11 deletions wayrs-egl/src/gbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ffi::CStr;
use std::io;
use std::os::fd::{FromRawFd, OwnedFd, RawFd};

use crate::{Error, Fourcc, Result};
use crate::{Error, Fourcc, Result, DRM_FORMAT_MOD_INVALID};

#[derive(Debug)]
pub struct Device {
Expand Down Expand Up @@ -36,16 +36,28 @@ impl Device {
fourcc: Fourcc,
modifiers: &[u64],
) -> Result<Buffer> {
let ptr = unsafe {
gbm_sys::gbm_bo_create_with_modifiers2(
self.raw,
width,
height,
fourcc.0,
modifiers.as_ptr(),
modifiers.len() as u32,
gbm_sys::gbm_bo_flags::GBM_BO_USE_RENDERING,
)
let ptr = if modifiers == &[DRM_FORMAT_MOD_INVALID] {
unsafe {
gbm_sys::gbm_bo_create(
self.raw,
width,
height,
fourcc.0,
gbm_sys::gbm_bo_flags::GBM_BO_USE_RENDERING,
)
}
} else {
unsafe {
gbm_sys::gbm_bo_create_with_modifiers2(
self.raw,
width,
height,
fourcc.0,
modifiers.as_ptr(),
modifiers.len() as u32,
gbm_sys::gbm_bo_flags::GBM_BO_USE_RENDERING,
)
}
};
if ptr.is_null() {
Err(Error::BadGbmAlloc)
Expand Down
2 changes: 2 additions & 0 deletions wayrs-egl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ impl fmt::Debug for Fourcc {
)
}
}

const DRM_FORMAT_MOD_INVALID: u64 = 72057594037927935;

0 comments on commit 716d9a5

Please sign in to comment.