diff --git a/drivers/graphics/driver-graphics/src/lib.rs b/drivers/graphics/driver-graphics/src/lib.rs index eab0be9c3e..9fdb6d40bb 100644 --- a/drivers/graphics/driver-graphics/src/lib.rs +++ b/drivers/graphics/driver-graphics/src/lib.rs @@ -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, dirty_fb: bool); } @@ -273,7 +275,7 @@ struct GraphicsSchemeInner { struct VtState { connector_state: Vec>, crtc_state: Vec>, - cursor_plane: CursorPlane, + cursor_plane: Option>, } enum Handle { @@ -287,6 +289,7 @@ enum Handle { impl GraphicsSchemeInner { fn get_or_create_vt<'a>( + adapter: &T, objects: &KmsObjects, vts: &'a mut HashMap>, vt: usize, @@ -300,13 +303,13 @@ impl GraphicsSchemeInner { .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 GraphicsSchemeInner { 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 GraphicsSchemeInner { .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 SchemeSync for GraphicsSchemeInner { .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 SchemeSync for GraphicsSchemeInner { 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 SchemeSync for GraphicsSchemeInner { 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 { diff --git a/drivers/graphics/ihdgd/src/device/scheme.rs b/drivers/graphics/ihdgd/src/device/scheme.rs index e2655aae27..7a90d6933e 100644 --- a/drivers/graphics/ihdgd/src/device/scheme.rs +++ b/drivers/graphics/ihdgd/src/device/scheme.rs @@ -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, _dirty_fb: bool) { diff --git a/drivers/graphics/vesad/src/scheme.rs b/drivers/graphics/vesad/src/scheme.rs index 5bf2be9125..9c9713b229 100644 --- a/drivers/graphics/vesad/src/scheme.rs +++ b/drivers/graphics/vesad/src/scheme.rs @@ -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, _dirty_fb: bool) { diff --git a/drivers/graphics/virtio-gpud/src/scheme.rs b/drivers/graphics/virtio-gpud/src/scheme.rs index 22a985ee4e..0f88a66e91 100644 --- a/drivers/graphics/virtio-gpud/src/scheme.rs +++ b/drivers/graphics/virtio-gpud/src/scheme.rs @@ -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, dirty_fb: bool) {