[PATCH xf86-video-ati 12/13] Update cursor position in drmmode_show_cursor if hotspot changed

Michel Dänzer michel at daenzer.net
Fri Dec 21 17:49:06 UTC 2018


From: Michel Dänzer <michel.daenzer at amd.com>

The cursor position is updated to be consistent with the new hotspot in
the same ioctl call.

(Ported from amdgpu commit b04697de5270e8e45744a7025c24df1f454a4cf0)

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/drmmode_display.c | 75 +++++++++++++++++++++++++------------------
 src/drmmode_display.h |  5 +++
 2 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index c2a59da7b..bec309e5e 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -1017,6 +1017,9 @@ drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
 	}
 #endif
 
+	drmmode_crtc->cursor_x = x;
+	drmmode_crtc->cursor_y = y;
+
 	drmModeMoveCursor(pRADEONEnt->fd, drmmode_crtc->mode_crtc->crtc_id, x, y);
 }
 
@@ -1202,6 +1205,10 @@ drmmode_show_cursor (xf86CrtcPtr crtc)
 	RADEONInfoPtr info = RADEONPTR(pScrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn);
+	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	CursorPtr cursor = xf86_config->cursor;
+	int xhot = cursor->bits->xhot;
+	int yhot = cursor->bits->yhot;
 	static Bool use_set_cursor2 = TRUE;
 	struct drm_mode_cursor2 arg;
 
@@ -1213,41 +1220,45 @@ drmmode_show_cursor (xf86CrtcPtr crtc)
 	arg.width = info->cursor_w;
 	arg.height = info->cursor_h;
 
+	if (crtc->rotation != RR_Rotate_0 &&
+	    crtc->rotation != (RR_Rotate_180 | RR_Reflect_X |
+			       RR_Reflect_Y)) {
+	    int t;
+
+	    /* Reflect & rotate hotspot position */
+	    if (crtc->rotation & RR_Reflect_X)
+		xhot = info->cursor_w - xhot - 1;
+	    if (crtc->rotation & RR_Reflect_Y)
+		yhot = info->cursor_h - yhot - 1;
+
+	    switch (crtc->rotation & 0xf) {
+	    case RR_Rotate_90:
+		t = xhot;
+		xhot = yhot;
+		yhot = info->cursor_w - t - 1;
+		break;
+	    case RR_Rotate_180:
+		xhot = info->cursor_w - xhot - 1;
+		yhot = info->cursor_h - yhot - 1;
+		break;
+	    case RR_Rotate_270:
+		t = xhot;
+		xhot = info->cursor_h - yhot - 1;
+		yhot = t;
+	    }
+	}
+
+	if (xhot != drmmode_crtc->cursor_xhot || yhot != drmmode_crtc->cursor_yhot) {
+	    arg.flags |= DRM_MODE_CURSOR_MOVE;
+	    arg.x = drmmode_crtc->cursor_x += drmmode_crtc->cursor_xhot - xhot;
+	    arg.y = drmmode_crtc->cursor_y += drmmode_crtc->cursor_yhot - yhot;
+	    drmmode_crtc->cursor_xhot = xhot;
+	    drmmode_crtc->cursor_yhot = yhot;
+	}
+
 	if (use_set_cursor2) {
-	    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-	    CursorPtr cursor = xf86_config->cursor;
-	    int xhot = cursor->bits->xhot;
-	    int yhot = cursor->bits->yhot;
 	    int ret;
 
-	    if (crtc->rotation != RR_Rotate_0 &&
-		crtc->rotation != (RR_Rotate_180 | RR_Reflect_X |
-				   RR_Reflect_Y)) {
-		int t;
-
-		/* Reflect & rotate hotspot position */
-		if (crtc->rotation & RR_Reflect_X)
-		    xhot = info->cursor_w - xhot - 1;
-		if (crtc->rotation & RR_Reflect_Y)
-		    yhot = info->cursor_h - yhot - 1;
-
-		switch (crtc->rotation & 0xf) {
-		case RR_Rotate_90:
-		    t = xhot;
-		    xhot = yhot;
-		    yhot = info->cursor_w - t - 1;
-		    break;
-		case RR_Rotate_180:
-		    xhot = info->cursor_w - xhot - 1;
-		    yhot = info->cursor_h - yhot - 1;
-		    break;
-		case RR_Rotate_270:
-		    t = xhot;
-		    xhot = info->cursor_h - yhot - 1;
-		    yhot = t;
-		}
-	    }
-
 	    arg.hot_x = xhot;
 	    arg.hot_y = yhot;
 
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index d7ab9d7e9..49893ab04 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -87,6 +87,11 @@ typedef struct {
     drmmode_ptr drmmode;
     drmModeCrtcPtr mode_crtc;
     int hw_id;
+
+    int cursor_x;
+    int cursor_y;
+    int cursor_xhot;
+    int cursor_yhot;
     struct radeon_bo *cursor_bo;
     struct drmmode_scanout rotate;
     struct drmmode_scanout scanout[2];
-- 
2.20.1



More information about the amd-gfx mailing list