From 55cf1c1496a51ad221901e6f6aa4b8a21adcbf54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 19 Mar 2020 09:01:03 +0100 Subject: [PATCH] kms/plane-assignment: Add API to set cursor hotspot metadata The transactional KMS API has been modelled after atomic KMS. Atomic KMS currently doesn't support forwarding cursor hotspot metadata, thus it was left out of the transactional KMS API having the user set the simply create a plane assigment with the cursor sprite assigned to a cursor plane using regular coordinates. This, however, proved to be inadequate for virtual machines using "seamless mouse mode" where they rely on the cursor position to correspond to the actual cursor position of the virtual machine, not the cursor plane. In effect, this caused cursor positions to look "shifted". Fix this by adding back the hotspot metadata, right now as a optional field to the plane assignment. In the legacy KMS implementation, this is translated into drmModeSetCursor2() just as before, while still falling back to drmModeSetCursor() with the plane coordinates, if either there was no hotspot set, or if drmModeSetCursor2() failed. Eventually, the atomic KMS API will learn about hotspots, but when adding our own atomic KMS backend to the transacitonal KMS API, we must until then still fall back to legacy KMS for virtual machines. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1136 --- src/backends/native/meta-kms-impl-simple.c | 21 +++++++++++++++---- src/backends/native/meta-kms-update-private.h | 6 ++++++ src/backends/native/meta-kms-update.c | 10 +++++++++ src/backends/native/meta-kms-update.h | 4 ++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/backends/native/meta-kms-impl-simple.c b/src/backends/native/meta-kms-impl-simple.c index ddc31b938..e50b1c888 100644 --- a/src/backends/native/meta-kms-impl-simple.c +++ b/src/backends/native/meta-kms-impl-simple.c @@ -771,14 +771,27 @@ process_cursor_plane_assignment (MetaKmsImpl *impl, if (!(plane_assignment->flags & META_KMS_ASSIGN_PLANE_FLAG_FB_UNCHANGED)) { int width, height; - int ret; + int ret = -1; width = meta_fixed_16_to_int (plane_assignment->dst_rect.width); height = meta_fixed_16_to_int (plane_assignment->dst_rect.height); - ret = drmModeSetCursor (fd, meta_kms_crtc_get_id (plane_assignment->crtc), - plane_assignment->fb_id, - width, height); + if (plane_assignment->cursor_hotspot.is_valid) + { + ret = drmModeSetCursor2 (fd, meta_kms_crtc_get_id (plane_assignment->crtc), + plane_assignment->fb_id, + width, height, + plane_assignment->cursor_hotspot.x, + plane_assignment->cursor_hotspot.y); + } + + if (ret != 0) + { + ret = drmModeSetCursor (fd, meta_kms_crtc_get_id (plane_assignment->crtc), + plane_assignment->fb_id, + width, height); + } + if (ret != 0) { g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret), diff --git a/src/backends/native/meta-kms-update-private.h b/src/backends/native/meta-kms-update-private.h index 91a1de6dc..4d4d4a276 100644 --- a/src/backends/native/meta-kms-update-private.h +++ b/src/backends/native/meta-kms-update-private.h @@ -51,6 +51,12 @@ typedef struct _MetaKmsPlaneAssignment MetaKmsAssignPlaneFlag flags; GList *plane_properties; + + struct { + gboolean is_valid; + int x; + int y; + } cursor_hotspot; } MetaKmsPlaneAssignment; typedef struct _MetaKmsModeSet diff --git a/src/backends/native/meta-kms-update.c b/src/backends/native/meta-kms-update.c index 0371782b7..5ace83021 100644 --- a/src/backends/native/meta-kms-update.c +++ b/src/backends/native/meta-kms-update.c @@ -340,6 +340,16 @@ meta_kms_plane_assignment_set_plane_property (MetaKmsPlaneAssignment *plane_assi g_list_prepend (plane_assignment->plane_properties, plane_prop); } +void +meta_kms_plane_assignment_set_cursor_hotspot (MetaKmsPlaneAssignment *plane_assignment, + int x, + int y) +{ + plane_assignment->cursor_hotspot.is_valid = TRUE; + plane_assignment->cursor_hotspot.x = x; + plane_assignment->cursor_hotspot.y = y; +} + MetaKmsPlaneAssignment * meta_kms_update_get_primary_plane_assignment (MetaKmsUpdate *update, MetaKmsCrtc *crtc) diff --git a/src/backends/native/meta-kms-update.h b/src/backends/native/meta-kms-update.h index cd1822e4a..13dff16dd 100644 --- a/src/backends/native/meta-kms-update.h +++ b/src/backends/native/meta-kms-update.h @@ -108,6 +108,10 @@ void meta_kms_update_custom_page_flip (MetaKmsUpdate *update, MetaKmsCustomPageFlipFunc custom_page_flip_func, gpointer custom_page_flip_user_data); +void meta_kms_plane_assignment_set_cursor_hotspot (MetaKmsPlaneAssignment *plane_assignment, + int x, + int y); + static inline MetaFixed16 meta_fixed_16_from_int (int16_t d) {