From c8c5a3e240409b3bf543839b38be14fe61c0387e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 12 Mar 2026 22:37:16 +0100 Subject: [PATCH] drivers/graphics: Remove separate cursor framebuffer create/map methods --- drivers/graphics/driver-graphics/src/lib.rs | 20 +++++++------------- drivers/graphics/ihdgd/src/device/scheme.rs | 12 ++---------- drivers/graphics/vesad/src/scheme.rs | 12 ++---------- drivers/graphics/virtio-gpud/src/scheme.rs | 21 +++++++++------------ 4 files changed, 20 insertions(+), 45 deletions(-) diff --git a/drivers/graphics/driver-graphics/src/lib.rs b/drivers/graphics/driver-graphics/src/lib.rs index 5c4a04f763..2fc4b028bc 100644 --- a/drivers/graphics/driver-graphics/src/lib.rs +++ b/drivers/graphics/driver-graphics/src/lib.rs @@ -67,9 +67,7 @@ pub trait GraphicsAdapter: Sized + Debug { fn update_plane(&mut self, display_id: usize, framebuffer: &Self::Buffer, damage: Damage); - fn supports_hw_cursor(&self) -> bool; - fn create_cursor_framebuffer(&mut self) -> Self::Buffer; - fn map_cursor_framebuffer(&mut self, cursor: &Self::Buffer) -> *mut u8; + fn hw_cursor_size(&self) -> Option<(u32, u32)>; fn handle_cursor(&mut self, cursor: Option<&CursorPlane>, dirty_fb: bool); } @@ -222,7 +220,7 @@ impl GraphicsScheme { ); } - if self.inner.adapter.supports_hw_cursor() { + if self.inner.adapter.hw_cursor_size().is_some() { self.inner .adapter .handle_cursor(vt_state.cursor_plane.as_ref(), true); @@ -349,16 +347,16 @@ impl GraphicsSchemeInner { ) -> Result<()> { let vt_state = self.vts.get_mut(&vt).unwrap(); - if !self.adapter.supports_hw_cursor() { + let Some((width, height)) = self.adapter.hw_cursor_size() else { return Err(Error::new(EINVAL)); - } + }; let cursor_plane = vt_state.cursor_plane.get_or_insert_with(|| CursorPlane { x: 0, y: 0, hot_x: 0, hot_y: 0, - framebuffer: self.adapter.create_cursor_framebuffer(), + framebuffer: self.adapter.create_dumb_buffer(width, height), }); cursor_plane.x = cursor_damage.x; @@ -377,9 +375,7 @@ impl GraphicsSchemeInner { let w: i32 = cursor_damage.width; let h: i32 = cursor_damage.height; let cursor_image = cursor_damage.cursor_img_bytes; - let cursor_ptr = self - .adapter - .map_cursor_framebuffer(&cursor_plane.framebuffer); + let cursor_ptr = self.adapter.map_dumb_buffer(&cursor_plane.framebuffer); //Clear previous image from backing storage unsafe { @@ -752,9 +748,7 @@ impl SchemeSync for GraphicsSchemeInner { return Err(Error::new(EINVAL)); } - let fb = self - .adapter - .create_dumb_buffer(data.width(), data.height()); + let fb = self.adapter.create_dumb_buffer(data.width(), data.height()); *next_id += 1; fbs.insert(*next_id, Arc::new(fb)); diff --git a/drivers/graphics/ihdgd/src/device/scheme.rs b/drivers/graphics/ihdgd/src/device/scheme.rs index d04208d682..8cd6256199 100644 --- a/drivers/graphics/ihdgd/src/device/scheme.rs +++ b/drivers/graphics/ihdgd/src/device/scheme.rs @@ -99,16 +99,8 @@ impl GraphicsAdapter for Device { framebuffer.sync(&mut self.framebuffers[display_id], damage) } - fn supports_hw_cursor(&self) -> bool { - false - } - - fn create_cursor_framebuffer(&mut self) -> Self::Buffer { - unimplemented!("ihdgd does not support this function"); - } - - fn map_cursor_framebuffer(&mut self, _cursor: &Self::Buffer) -> *mut u8 { - unimplemented!("ihdgd does not support this function"); + fn hw_cursor_size(&self) -> Option<(u32, u32)> { + None } fn handle_cursor(&mut self, _cursor: Option<&CursorPlane>, _dirty_fb: bool) { diff --git a/drivers/graphics/vesad/src/scheme.rs b/drivers/graphics/vesad/src/scheme.rs index 3a5232f4f5..0ee38f3919 100644 --- a/drivers/graphics/vesad/src/scheme.rs +++ b/drivers/graphics/vesad/src/scheme.rs @@ -100,16 +100,8 @@ impl GraphicsAdapter for FbAdapter { framebuffer.sync(&mut self.framebuffers[display_id], damage) } - fn supports_hw_cursor(&self) -> bool { - false - } - - fn create_cursor_framebuffer(&mut self) -> Self::Buffer { - unimplemented!("Vesad does not support this function"); - } - - fn map_cursor_framebuffer(&mut self, _cursor: &Self::Buffer) -> *mut u8 { - unimplemented!("Vesad does not support this function"); + fn hw_cursor_size(&self) -> Option<(u32, u32)> { + None } fn handle_cursor(&mut self, _cursor: Option<&CursorPlane>, _dirty_fb: bool) { diff --git a/drivers/graphics/virtio-gpud/src/scheme.rs b/drivers/graphics/virtio-gpud/src/scheme.rs index 24700f1782..d40568b4ec 100644 --- a/drivers/graphics/virtio-gpud/src/scheme.rs +++ b/drivers/graphics/virtio-gpud/src/scheme.rs @@ -238,9 +238,14 @@ impl VirtGpuAdapter<'_> { fn disable_cursor(&mut self) { if self.hidden_cursor.is_none() { - let cursor = self.create_dumb_buffer(64, 64); + let (width, height) = self.hw_cursor_size().unwrap(); + let cursor = self.create_dumb_buffer(width, height); unsafe { - core::ptr::write_bytes(cursor.sgl.as_ptr() as *mut u8, 0, 64 * 64 * 4); + core::ptr::write_bytes( + cursor.sgl.as_ptr() as *mut u8, + 0, + (width * height * 4) as usize, + ); } self.hidden_cursor = Some(Arc::new(cursor)); } @@ -474,16 +479,8 @@ impl<'a> GraphicsAdapter for VirtGpuAdapter<'a> { }); } - fn supports_hw_cursor(&self) -> bool { - true - } - - fn create_cursor_framebuffer(&mut self) -> Self::Buffer { - self.create_dumb_buffer(64, 64) - } - - fn map_cursor_framebuffer(&mut self, cursor: &Self::Buffer) -> *mut u8 { - cursor.sgl.as_ptr() + fn hw_cursor_size(&self) -> Option<(u32, u32)> { + Some((64, 64)) } fn handle_cursor(&mut self, cursor: Option<&CursorPlane>, dirty_fb: bool) {