From 3e7b757f0bb622e3231c58c60cfb4c5f8719e31c Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 14 May 2026 17:40:43 +0200 Subject: [PATCH] drivers/graphics/driver-graphics: Deduplicate code between MODE_CURSOR and MODE_CURSOR2 --- .../driver-graphics/src/ioctl/cursor.rs | 86 ++++++++++++------- 1 file changed, 53 insertions(+), 33 deletions(-) diff --git a/drivers/graphics/driver-graphics/src/ioctl/cursor.rs b/drivers/graphics/driver-graphics/src/ioctl/cursor.rs index a60c17f72b..5781fc69bb 100644 --- a/drivers/graphics/driver-graphics/src/ioctl/cursor.rs +++ b/drivers/graphics/driver-graphics/src/ioctl/cursor.rs @@ -11,31 +11,20 @@ pub(super) fn mode_cursor( handle: &mut DrmHandle, data: redox_ioctl::drm::DrmModeCursor<'_>, ) -> Result { - let vt_state = vts.get_mut(&handle.vt).unwrap(); - - let Some(cursor_plane) = &mut vt_state.cursor_plane else { - return Err(Error::new(ENXIO)); - }; - - let update_buffer = data.flags() & DRM_MODE_CURSOR_BO != 0; - if update_buffer { - cursor_plane.buffer = if data.handle() == 0 { - None - } else if let Some(buffer) = handle.buffers.get(&data.handle()) { - Some(buffer.clone()) - } else { - return Err(Error::new(ENOENT)); - }; - } - - if data.flags() & DRM_MODE_CURSOR_MOVE != 0 { - cursor_plane.x = data.x(); - cursor_plane.y = data.y(); - } - - adapter.handle_cursor(cursor_plane, update_buffer); - - Ok(0) + cursor_inner( + adapter, + vts, + handle, + data.flags(), + data.crtc_id(), + data.x(), + data.y(), + data.width(), + data.height(), + data.handle(), + 0, + 0, + ) } pub(super) fn mode_cursor2( @@ -43,6 +32,37 @@ pub(super) fn mode_cursor2( vts: &mut HashMap>, handle: &mut DrmHandle, data: redox_ioctl::drm::DrmModeCursor2<'_>, +) -> Result { + cursor_inner( + adapter, + vts, + handle, + data.flags(), + data.crtc_id(), + data.x(), + data.y(), + data.width(), + data.height(), + data.handle(), + data.hot_x(), + data.hot_y(), + ) +} + +fn cursor_inner( + adapter: &mut T, + vts: &mut HashMap>, + handle: &mut DrmHandle, + + flags: u32, + _crtc_id: u32, + x: i32, + y: i32, + _width: u32, + _height: u32, + handle_id: u32, + hot_x: i32, + hot_y: i32, ) -> Result { let vt_state = vts.get_mut(&handle.vt).unwrap(); @@ -50,22 +70,22 @@ pub(super) fn mode_cursor2( return Err(Error::new(ENXIO)); }; - let update_buffer = data.flags() & DRM_MODE_CURSOR_BO != 0; + let update_buffer = flags & DRM_MODE_CURSOR_BO != 0; if update_buffer { - cursor_plane.buffer = if data.handle() == 0 { + cursor_plane.buffer = if handle_id == 0 { None - } else if let Some(buffer) = handle.buffers.get(&data.handle()) { + } else if let Some(buffer) = handle.buffers.get(&handle_id) { Some(buffer.clone()) } else { return Err(Error::new(ENOENT)); }; - cursor_plane.hot_x = data.hot_x(); - cursor_plane.hot_y = data.hot_y(); + cursor_plane.hot_x = hot_x; + cursor_plane.hot_y = hot_y; } - if data.flags() & DRM_MODE_CURSOR_MOVE != 0 { - cursor_plane.x = data.x(); - cursor_plane.y = data.y(); + if flags & DRM_MODE_CURSOR_MOVE != 0 { + cursor_plane.x = x; + cursor_plane.y = y; } adapter.handle_cursor(cursor_plane, update_buffer);