autocommit 2022-03-11 20:04:41 CET
This commit is contained in:
parent
0ae73ab9c4
commit
eb1d500561
10 changed files with 93 additions and 75 deletions
|
|
@ -2,12 +2,11 @@ use crate::drm::dma::{DmaBuf, DmaBufPlane};
|
|||
use crate::drm::drm::{Drm, DrmError};
|
||||
use crate::drm::{ModifiedFormat, INVALID_MODIFIER};
|
||||
use crate::format::formats;
|
||||
use crate::utils::oserror::OsError;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use uapi::{c, Errno, OwnedFd};
|
||||
use uapi::{c, OwnedFd};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GbmError {
|
||||
|
|
@ -21,8 +20,6 @@ pub enum GbmError {
|
|||
UnknownFormat,
|
||||
#[error("Could not retrieve a drm-buf fd")]
|
||||
DrmFd,
|
||||
#[error("Could not retrieve a GEM handle")]
|
||||
GemHandle(#[source] OsError),
|
||||
}
|
||||
|
||||
type Device = u8;
|
||||
|
|
@ -39,16 +36,6 @@ pub const GBM_BO_USE_LINEAR: u32 = 1 << 4;
|
|||
#[allow(dead_code)]
|
||||
pub const GBM_BO_USE_PROTECTED: u32 = 1 << 5;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(C)]
|
||||
union gbm_bo_handle {
|
||||
ptr: *mut u8,
|
||||
s32: i32,
|
||||
u32: u32,
|
||||
s64: i64,
|
||||
u64: u64,
|
||||
}
|
||||
|
||||
#[link(name = "gbm")]
|
||||
extern "C" {
|
||||
fn gbm_create_device(fd: c::c_int) -> *mut Device;
|
||||
|
|
@ -72,7 +59,6 @@ extern "C" {
|
|||
fn gbm_bo_get_modifier(bo: *mut Bo) -> u64;
|
||||
fn gbm_bo_get_stride_for_plane(bo: *mut Bo, plane: c::c_int) -> u32;
|
||||
fn gbm_bo_get_fd_for_plane(bo: *mut Bo, plane: c::c_int) -> c::c_int;
|
||||
fn gbm_bo_get_handle_for_plane(bo: *mut Bo, plane: c::c_int) -> gbm_bo_handle;
|
||||
fn gbm_bo_get_offset(bo: *mut Bo, plane: c::c_int) -> u32;
|
||||
fn gbm_bo_get_format(bo: *mut Bo) -> u32;
|
||||
#[allow(dead_code)]
|
||||
|
|
@ -97,7 +83,6 @@ struct BoHolder {
|
|||
pub struct GbmBo {
|
||||
_bo: BoHolder,
|
||||
dma: DmaBuf,
|
||||
handles: Vec<u32>,
|
||||
}
|
||||
|
||||
unsafe fn export_bo(bo: *mut Bo) -> Result<DmaBuf, GbmError> {
|
||||
|
|
@ -132,18 +117,6 @@ unsafe fn export_bo(bo: *mut Bo) -> Result<DmaBuf, GbmError> {
|
|||
})
|
||||
}
|
||||
|
||||
unsafe fn export_handles(bo: *mut Bo) -> Result<Vec<u32>, GbmError> {
|
||||
let mut planes = vec![];
|
||||
for plane in 0..gbm_bo_get_plane_count(bo) {
|
||||
let handle = gbm_bo_get_handle_for_plane(bo, plane);
|
||||
if handle.s32 < 0 {
|
||||
return Err(GbmError::GemHandle(Errno::default().into()));
|
||||
}
|
||||
planes.push(handle.u32);
|
||||
}
|
||||
Ok(planes)
|
||||
}
|
||||
|
||||
impl GbmDevice {
|
||||
pub fn new(drm: &Drm) -> Result<Self, GbmError> {
|
||||
let drm = drm.dup_unprivileged()?;
|
||||
|
|
@ -182,11 +155,9 @@ impl GbmDevice {
|
|||
}
|
||||
let bo = BoHolder { bo };
|
||||
let dma = export_bo(bo.bo)?;
|
||||
let handles = export_handles(bo.bo)?;
|
||||
Ok(GbmBo {
|
||||
_bo: bo,
|
||||
dma,
|
||||
handles,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -204,10 +175,6 @@ impl GbmBo {
|
|||
pub fn dma(&self) -> &DmaBuf {
|
||||
&self.dma
|
||||
}
|
||||
|
||||
pub fn gem(&self) -> &[u32] {
|
||||
&self.handles
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for BoHolder {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue