Merge branch 'drm_gpu35' into 'main'

drivers/graphics/driver-graphics: Couple of minor cleanups

See merge request redox-os/base!256
This commit is contained in:
Jeremy Soller
2026-05-07 14:37:11 -06:00
7 changed files with 34 additions and 26 deletions
@@ -178,7 +178,7 @@ impl<T: GraphicsAdapter> KmsConnector<T> {
}
}
pub(crate) fn modeinfo_for_size(width: u32, height: u32) -> drm_mode_modeinfo {
fn modeinfo_for_size(width: u32, height: u32) -> drm_mode_modeinfo {
let mut modeinfo = drm_mode_modeinfo {
// The actual visible display size
hdisplay: width as u16,
@@ -18,11 +18,11 @@ use crate::GraphicsAdapter;
#[derive(Debug)]
pub struct KmsObjects<T: GraphicsAdapter> {
next_id: KmsObjectId,
pub(crate) connectors: Vec<KmsObjectId>,
pub(crate) encoders: Vec<KmsObjectId>,
pub(super) connectors: Vec<KmsObjectId>,
pub(super) encoders: Vec<KmsObjectId>,
crtcs: Vec<KmsObjectId>,
framebuffers: Vec<KmsObjectId>,
pub(crate) objects: HashMap<KmsObjectId, KmsObject<T>>,
pub(super) objects: HashMap<KmsObjectId, KmsObject<T>>,
_marker: PhantomData<T>,
}
@@ -41,7 +41,7 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
objects
}
pub(crate) fn add<U: Into<KmsObject<T>>>(&mut self, data: U) -> KmsObjectId {
pub(super) fn add<U: Into<KmsObject<T>>>(&mut self, data: U) -> KmsObjectId {
let id = self.next_id;
self.objects.insert(id, data.into());
self.next_id.0 += 1;
@@ -49,7 +49,7 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
id
}
pub(crate) fn get<'a, U: 'a>(&'a self, id: KmsObjectId) -> Result<&'a U>
pub(super) fn get<'a, U: 'a>(&'a self, id: KmsObjectId) -> Result<&'a U>
where
&'a U: TryFrom<&'a KmsObject<T>>,
{
@@ -61,7 +61,7 @@ impl<T: GraphicsAdapter> KmsObjects<T> {
}
}
pub fn object_type(&self, id: KmsObjectId) -> Result<u32> {
pub(crate) fn object_type(&self, id: KmsObjectId) -> Result<u32> {
let object = self.objects.get(&id).ok_or(Error::new(EINVAL))?;
Ok(object.object_type())
}
@@ -147,7 +147,7 @@ macro_rules! define_object_kinds {
$variant:ident($data:ty) = $type:ident,
)*) => {
#[derive(Debug)]
pub(crate) enum KmsObject<$T: GraphicsAdapter> {
pub(super) enum KmsObject<$T: GraphicsAdapter> {
$($variant($data),)*
}
@@ -229,7 +229,7 @@ macro_rules! define_object_props {
}
)* }) => {
impl$(<$($T$(: $bound)?),*>)? $obj$(<$($T),*>)? {
pub(super) fn base_properties() -> Vec<KmsPropertyData<Self>> {
fn base_properties() -> Vec<KmsPropertyData<Self>> {
vec![$(KmsPropertyData {
id: $prop,
getter: |$object| $get
+18 -10
View File
@@ -108,7 +108,9 @@ pub trait GraphicsAdapter: Sized + Debug {
damage: Damage,
) -> syscall::Result<()>;
fn hw_cursor_size(&self) -> Option<(u32, u32)>;
// FIXME replace this with an actual plane marked as cursor plane once we
// support planes internally.
fn has_cursor_plane(&self) -> bool;
fn handle_cursor(&mut self, cursor: &CursorPlane<Self::Buffer>, dirty_fb: bool);
}
@@ -273,7 +275,7 @@ struct GraphicsSchemeInner<T: GraphicsAdapter> {
struct VtState<T: GraphicsAdapter> {
connector_state: Vec<KmsConnectorState<T>>,
crtc_state: Vec<KmsCrtcState<T>>,
cursor_plane: CursorPlane<T::Buffer>,
cursor_plane: Option<CursorPlane<T::Buffer>>,
}
enum Handle<T: GraphicsAdapter> {
@@ -287,6 +289,7 @@ enum Handle<T: GraphicsAdapter> {
impl<T: GraphicsAdapter> GraphicsSchemeInner<T> {
fn get_or_create_vt<'a>(
adapter: &T,
objects: &KmsObjects<T>,
vts: &'a mut HashMap<usize, VtState<T>>,
vt: usize,
@@ -300,13 +303,13 @@ impl<T: GraphicsAdapter> GraphicsSchemeInner<T> {
.crtcs()
.map(|crtc| crtc.lock().unwrap().state.clone())
.collect(),
cursor_plane: CursorPlane {
cursor_plane: adapter.has_cursor_plane().then(|| CursorPlane {
x: 0,
y: 0,
hot_x: 0,
hot_y: 0,
buffer: None,
},
}),
})
}
@@ -323,7 +326,8 @@ impl<T: GraphicsAdapter> GraphicsSchemeInner<T> {
self.active_vt = vt;
let vt_state = GraphicsSchemeInner::get_or_create_vt(&self.objects, &mut self.vts, vt);
let vt_state =
GraphicsSchemeInner::get_or_create_vt(&self.adapter, &self.objects, &mut self.vts, vt);
for (connector_idx, connector_state) in vt_state.connector_state.iter().enumerate() {
let connector_id = self.objects.connector_ids()[connector_idx];
@@ -370,8 +374,8 @@ impl<T: GraphicsAdapter> GraphicsSchemeInner<T> {
.crtc_id = crtc_id;
}
if self.adapter.hw_cursor_size().is_some() {
self.adapter.handle_cursor(&vt_state.cursor_plane, true);
if let Some(cursor_plane) = &vt_state.cursor_plane {
self.adapter.handle_cursor(cursor_plane, true);
}
}
}
@@ -406,7 +410,7 @@ impl<T: GraphicsAdapter> SchemeSync for GraphicsSchemeInner<T> {
.map_err(|_| Error::new(EINVAL))?;
// Ensure the VT exists such that the rest of the methods can freely access it.
Self::get_or_create_vt(&self.objects, &mut self.vts, vt);
Self::get_or_create_vt(&self.adapter, &self.objects, &mut self.vts, vt);
Handle::V2 {
vt,
@@ -597,7 +601,9 @@ impl<T: GraphicsAdapter> SchemeSync for GraphicsSchemeInner<T> {
ipc::MODE_CURSOR => ipc::DrmModeCursor::with(payload, |data| {
let vt_state = self.vts.get_mut(vt).unwrap();
let cursor_plane = &mut vt_state.cursor_plane;
let Some(cursor_plane) = &mut vt_state.cursor_plane else {
return Err(Error::new(EINVAL));
};
let update_buffer = data.flags() & DRM_MODE_CURSOR_BO != 0;
if update_buffer {
@@ -909,7 +915,9 @@ impl<T: GraphicsAdapter> SchemeSync for GraphicsSchemeInner<T> {
ipc::MODE_CURSOR2 => ipc::DrmModeCursor2::with(payload, |data| {
let vt_state = self.vts.get_mut(vt).unwrap();
let cursor_plane = &mut vt_state.cursor_plane;
let Some(cursor_plane) = &mut vt_state.cursor_plane else {
return Err(Error::new(EINVAL));
};
let update_buffer = data.flags() & DRM_MODE_CURSOR_BO != 0;
if update_buffer {
+2 -2
View File
@@ -102,8 +102,8 @@ impl GraphicsAdapter for Device {
Ok(())
}
fn hw_cursor_size(&self) -> Option<(u32, u32)> {
None
fn has_cursor_plane(&self) -> bool {
false
}
fn handle_cursor(&mut self, _cursor: &CursorPlane<Self::Buffer>, _dirty_fb: bool) {
+2 -2
View File
@@ -138,8 +138,8 @@ impl GraphicsAdapter for FbAdapter {
Ok(())
}
fn hw_cursor_size(&self) -> Option<(u32, u32)> {
None
fn has_cursor_plane(&self) -> bool {
false
}
fn handle_cursor(&mut self, _cursor: &CursorPlane<Self::Buffer>, _dirty_fb: bool) {
+3 -3
View File
@@ -246,7 +246,7 @@ impl VirtGpuAdapter<'_> {
fn disable_cursor(&mut self) {
if self.hidden_cursor.is_none() {
let (width, height) = self.hw_cursor_size().unwrap();
let (width, height) = (64, 64);
let (cursor, stride) = self.create_dumb_buffer(width, height);
unsafe {
core::ptr::write_bytes(
@@ -480,8 +480,8 @@ impl<'a> GraphicsAdapter for VirtGpuAdapter<'a> {
})
}
fn hw_cursor_size(&self) -> Option<(u32, u32)> {
Some((64, 64))
fn has_cursor_plane(&self) -> bool {
true
}
fn handle_cursor(&mut self, cursor: &CursorPlane<Self::Buffer>, dirty_fb: bool) {