Merge branch 'drm_gpu37' into 'main'
drivers/graphics: Couple of tweaks See merge request redox-os/base!260
This commit is contained in:
@@ -9,7 +9,7 @@ use drm_sys::{
|
||||
use syscall::Result;
|
||||
|
||||
use crate::kms::objects::{KmsObjectId, KmsObjects};
|
||||
use crate::kms::properties::{define_object_props, KmsPropertyData, CRTC_ID, DPMS, EDID};
|
||||
use crate::kms::properties::{define_object_props, KmsPropertyData, CRTC_ID, DPMS, EDID, TILE};
|
||||
use crate::GraphicsAdapter;
|
||||
|
||||
impl<T: GraphicsAdapter> KmsObjects<T> {
|
||||
@@ -125,6 +125,13 @@ define_object_props!(object, KmsConnector<T: GraphicsAdapter> {
|
||||
DPMS {
|
||||
get => object.state.dpms as u64,
|
||||
}
|
||||
TILE {
|
||||
get => {
|
||||
// FIXME set this property once we support DP MST
|
||||
let _ = object;
|
||||
0
|
||||
},
|
||||
}
|
||||
CRTC_ID {
|
||||
get => u64::from(object.state.crtc_id.0),
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use syscall::{Error, Result, EINVAL};
|
||||
|
||||
use crate::kms::connector::{KmsConnector, KmsEncoder};
|
||||
use crate::kms::properties::{
|
||||
define_object_props, init_standard_props, KmsBlob, KmsProperty, KmsPropertyData,
|
||||
define_object_props, init_standard_props, KmsBlob, KmsProperty, KmsPropertyData, ACTIVE,
|
||||
};
|
||||
use crate::GraphicsAdapter;
|
||||
|
||||
@@ -41,20 +41,17 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
|
||||
objects
|
||||
}
|
||||
|
||||
pub(super) fn add<U: Into<KmsObject<T>>>(&mut self, data: U) -> KmsObjectId {
|
||||
pub(super) fn add<U: KmsObjectKind<T>>(&mut self, data: U) -> KmsObjectId {
|
||||
let id = self.next_id;
|
||||
self.objects.insert(id, data.into());
|
||||
self.objects.insert(id, data.into_object());
|
||||
self.next_id.0 += 1;
|
||||
|
||||
id
|
||||
}
|
||||
|
||||
pub(super) fn get<'a, U: 'a>(&'a self, id: KmsObjectId) -> Result<&'a U>
|
||||
where
|
||||
&'a U: TryFrom<&'a KmsObject<T>>,
|
||||
{
|
||||
pub(super) fn get<U: KmsObjectKind<T>>(&self, id: KmsObjectId) -> Result<&U> {
|
||||
let object = self.objects.get(&id).ok_or(Error::new(EINVAL))?;
|
||||
if let Ok(object) = object.try_into() {
|
||||
if let Some(object) = U::try_from_object(object) {
|
||||
Ok(object)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
@@ -142,6 +139,11 @@ impl From<KmsObjectId> for u64 {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) trait KmsObjectKind<T: GraphicsAdapter> {
|
||||
fn into_object(self) -> KmsObject<T>;
|
||||
fn try_from_object(object: &KmsObject<T>) -> Option<&Self>;
|
||||
}
|
||||
|
||||
macro_rules! define_object_kinds {
|
||||
(<$T:ident> $(
|
||||
$variant:ident($data:ty) = $type:ident,
|
||||
@@ -160,19 +162,15 @@ macro_rules! define_object_kinds {
|
||||
}
|
||||
|
||||
$(
|
||||
impl<$T: GraphicsAdapter> From<$data> for KmsObject<$T> {
|
||||
fn from(value: $data) -> Self {
|
||||
Self::$variant(value)
|
||||
impl<$T: GraphicsAdapter> KmsObjectKind<$T> for $data {
|
||||
fn into_object(self) -> KmsObject<$T> {
|
||||
KmsObject::$variant(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, $T: GraphicsAdapter> TryFrom<&'a KmsObject<$T>> for &'a $data {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: &'a KmsObject<T>) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
KmsObject::$variant(data) => Ok(data),
|
||||
_ => Err(()),
|
||||
fn try_from_object(object: &KmsObject<$T>) -> Option<&$data> {
|
||||
match object {
|
||||
KmsObject::$variant(data) => Some(data),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,7 +221,11 @@ impl<T: GraphicsAdapter> Clone for KmsCrtcState<T> {
|
||||
}
|
||||
}
|
||||
|
||||
define_object_props!(object, KmsCrtc<T: GraphicsAdapter> {});
|
||||
define_object_props!(object, KmsCrtc<T: GraphicsAdapter> {
|
||||
ACTIVE {
|
||||
get => u64::from(object.state.mode.is_some()),
|
||||
}
|
||||
});
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct KmsFramebuffer<T: GraphicsAdapter> {
|
||||
|
||||
@@ -55,25 +55,19 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
|
||||
match object {
|
||||
KmsObject::Crtc(crtc) => {
|
||||
let crtc = crtc.lock().unwrap();
|
||||
let props = &crtc.properties;
|
||||
Ok((
|
||||
props.iter().map(|prop| prop.id.0).collect::<Vec<_>>(),
|
||||
props
|
||||
.iter()
|
||||
.map(|prop| (prop.getter)(&crtc))
|
||||
.collect::<Vec<_>>(),
|
||||
))
|
||||
Ok(crtc
|
||||
.properties
|
||||
.iter()
|
||||
.map(|prop| (prop.id.0, (prop.getter)(&crtc)))
|
||||
.unzip())
|
||||
}
|
||||
KmsObject::Connector(connector) => {
|
||||
let connector = connector.lock().unwrap();
|
||||
let props = &connector.properties;
|
||||
Ok((
|
||||
props.iter().map(|prop| prop.id.0).collect::<Vec<_>>(),
|
||||
props
|
||||
.iter()
|
||||
.map(|prop| (prop.getter)(&connector))
|
||||
.collect::<Vec<_>>(),
|
||||
))
|
||||
Ok(connector
|
||||
.properties
|
||||
.iter()
|
||||
.map(|prop| (prop.id.0, (prop.getter)(&connector)))
|
||||
.unzip())
|
||||
}
|
||||
KmsObject::Encoder(_)
|
||||
| KmsObject::Property(_)
|
||||
@@ -199,6 +193,7 @@ define_properties! {
|
||||
Suspend = u64::from(DRM_MODE_DPMS_SUSPEND),
|
||||
Off = u64::from(DRM_MODE_DPMS_OFF),
|
||||
} [],
|
||||
TILE: blob [immutable],
|
||||
|
||||
// CRTC
|
||||
ACTIVE: range { 0,1 } [atomic],
|
||||
|
||||
@@ -6,7 +6,8 @@ use driver_graphics::kms::objects::{
|
||||
};
|
||||
use driver_graphics::{Buffer, CursorPlane, Damage, GraphicsAdapter};
|
||||
use drm_sys::{
|
||||
DRM_CAP_DUMB_BUFFER, DRM_CAP_DUMB_PREFER_SHADOW, DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT,
|
||||
DRM_CAP_DUMB_BUFFER, DRM_CAP_DUMB_PREFERRED_DEPTH, DRM_CAP_DUMB_PREFER_SHADOW,
|
||||
DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT,
|
||||
};
|
||||
use syscall::error::EINVAL;
|
||||
|
||||
@@ -50,6 +51,7 @@ impl GraphicsAdapter for Device {
|
||||
fn get_cap(&self, cap: u32) -> syscall::Result<u64> {
|
||||
match cap {
|
||||
DRM_CAP_DUMB_BUFFER => Ok(1),
|
||||
DRM_CAP_DUMB_PREFERRED_DEPTH => Ok(24),
|
||||
DRM_CAP_DUMB_PREFER_SHADOW => Ok(1),
|
||||
_ => Err(syscall::Error::new(EINVAL)),
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ use driver_graphics::kms::connector::{KmsConnectorDriver, KmsConnectorStatus};
|
||||
use driver_graphics::kms::objects::{KmsCrtc, KmsCrtcState, KmsObjectId, KmsObjects};
|
||||
use driver_graphics::{Buffer, CursorPlane, Damage, GraphicsAdapter};
|
||||
use drm_sys::{
|
||||
DRM_CAP_DUMB_BUFFER, DRM_CAP_DUMB_PREFER_SHADOW, DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT,
|
||||
DRM_CAP_DUMB_BUFFER, DRM_CAP_DUMB_PREFERRED_DEPTH, DRM_CAP_DUMB_PREFER_SHADOW,
|
||||
DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT,
|
||||
};
|
||||
use syscall::{EINVAL, PAGE_SIZE};
|
||||
|
||||
@@ -61,6 +62,7 @@ impl GraphicsAdapter for FbAdapter {
|
||||
fn get_cap(&self, cap: u32) -> syscall::Result<u64> {
|
||||
match cap {
|
||||
DRM_CAP_DUMB_BUFFER => Ok(1),
|
||||
DRM_CAP_DUMB_PREFERRED_DEPTH => Ok(24),
|
||||
DRM_CAP_DUMB_PREFER_SHADOW => Ok(0),
|
||||
_ => Err(syscall::Error::new(EINVAL)),
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ use driver_graphics::kms::connector::{KmsConnectorDriver, KmsConnectorStatus};
|
||||
use driver_graphics::kms::objects::{KmsCrtc, KmsCrtcState, KmsObjectId, KmsObjects};
|
||||
use driver_graphics::{Buffer as DrmBuffer, CursorPlane, Damage, GraphicsAdapter, GraphicsScheme};
|
||||
use drm_sys::{
|
||||
DRM_CAP_CURSOR_HEIGHT, DRM_CAP_CURSOR_WIDTH, DRM_CAP_DUMB_BUFFER, DRM_CAP_DUMB_PREFER_SHADOW,
|
||||
DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT,
|
||||
DRM_CAP_CURSOR_HEIGHT, DRM_CAP_CURSOR_WIDTH, DRM_CAP_DUMB_BUFFER, DRM_CAP_DUMB_PREFERRED_DEPTH,
|
||||
DRM_CAP_DUMB_PREFER_SHADOW, DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT,
|
||||
};
|
||||
|
||||
use syscall::{EINVAL, PAGE_SIZE};
|
||||
@@ -293,6 +293,7 @@ impl<'a> GraphicsAdapter for VirtGpuAdapter<'a> {
|
||||
fn get_cap(&self, cap: u32) -> syscall::Result<u64> {
|
||||
match cap {
|
||||
DRM_CAP_DUMB_BUFFER => Ok(1),
|
||||
DRM_CAP_DUMB_PREFERRED_DEPTH => Ok(24),
|
||||
DRM_CAP_DUMB_PREFER_SHADOW => Ok(0),
|
||||
DRM_CAP_CURSOR_WIDTH => Ok(64),
|
||||
DRM_CAP_CURSOR_HEIGHT => Ok(64),
|
||||
|
||||
Reference in New Issue
Block a user