Skip to contentSkip to conversation

Move cursor related ScreenInit calls into AMDGPUCursorInit_KMS

PATCH In review Michel Dänzer 2 participants 3 messages Dec 27, 2017 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Move cursor related ScreenInit calls into AMDGPUCursorInit_KMS

From: Michel Dänzer <[email protected]>

And bail if xf86_cursors_init fails.

(Ported from amdgpu commit dfccaa7043ccb157a1f8be7313123792bb7e7001)

---
 src/radeon_kms.c | 44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)
src/radeon_kms.c +25 -19
index a9300d400..602a8fb7c 100644
@@ -1982,12 +1982,29 @@ static Bool RADEONCursorInit_KMS(ScreenPtr pScreen)
     ScrnInfoPtr    pScrn = xf86ScreenToScrn(pScreen);
     RADEONInfoPtr  info  = RADEONPTR(pScrn);
 
-    return xf86_cursors_init (pScreen, info->cursor_w, info->cursor_h,
-			      (HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
-			       HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
-			       HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 |
-			       HARDWARE_CURSOR_UPDATE_UNHIDDEN |
-			       HARDWARE_CURSOR_ARGB));
+    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG,
+		   "Initializing Cursor\n");
+
+    /* Set Silken Mouse */
+    xf86SetSilkenMouse(pScreen);
+
+    /* Cursor setup */
+    miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
+
+    if (xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE))
+	return TRUE;
+
+    if (!xf86_cursors_init(pScreen, info->cursor_w, info->cursor_h,
+			   HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
+			   HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
+			   HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 |
+			   HARDWARE_CURSOR_UPDATE_UNHIDDEN |
+			   HARDWARE_CURSOR_ARGB)) {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "xf86_cursors_init failed\n");
+	return FALSE;
+    }
+
+    return TRUE;
 }
 
 void
@@ -2330,19 +2347,8 @@ Bool RADEONScreenInit_KMS(ScreenPtr pScreen, int argc, char **argv)
 		   "Initializing DPMS\n");
     xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
-    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG,
-		   "Initializing Cursor\n");
-
-    /* Set Silken Mouse */
-    xf86SetSilkenMouse(pScreen);
-
-    /* Cursor setup */
-    miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
-
-    if (!xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE)) {
-	if (RADEONCursorInit_KMS(pScreen)) {
-	}
-    }
+    if (!RADEONCursorInit_KMS(pScreen))
+	return FALSE;
 
     /* DGA setup */
 #ifdef XFreeXDGA
Signature · 6 lines
2.15.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20171227164321.14752-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org

#2 lore raw

PATCH 2/2 Keep track of how many SW cursors are visible on each screen

From: Michel Dänzer <[email protected]>

And use this to determine when we cannot use page flipping for DRI clients. We previously did this based on whether the HW cursor cannot be used on at least one CRTC, which had at least two issues:

* Even while the HW cursor cannot be used, no SW cursor may actually be visible (e.g. because all cursors are disabled), in which case we can use page flipping for DRI clients anyway
* Even while the HW cursor can be used, there may be SW cursors visible from non-core pointer devices, in which case we cannot use page flipping for DRI clients anyway

(Ported from amdgpu commit 69e20839bfeb3ee0b0a732d72de0a32d6c5435fc)

---
 src/drmmode_display.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/drmmode_display.h |  4 ++++
 src/radeon.h          | 13 +++++++++++++
 src/radeon_dri2.c     |  2 +-
 src/radeon_kms.c      | 28 ++++++++++++++++++++++++++++
 src/radeon_present.c  |  2 +-
 6 files changed, 98 insertions(+), 2 deletions(-)
src/drmmode_display.c +51 -0
index 7ad3235a5..f55677f65 100644
@@ -34,6 +34,7 @@
 #include <time.h>
 #include "cursorstr.h"
 #include "damagestr.h"
+#include "inputstr.h"
 #include "list.h"
 #include "micmap.h"
 #include "xf86cmap.h"
@@ -2628,6 +2629,56 @@ Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, struct radeon_bo
 }
 
 
+static void drmmode_sprite_do_set_cursor(struct radeon_device_priv *device_priv,
+					 ScrnInfoPtr scrn, int x, int y)
+{
+	RADEONInfoPtr info = RADEONPTR(scrn);
+	CursorPtr cursor = device_priv->cursor;
+	Bool sprite_visible = device_priv->sprite_visible;
+
+	if (cursor) {
+		x -= cursor->bits->xhot;
+		y -= cursor->bits->yhot;
+
+		device_priv->sprite_visible =
+			x < scrn->virtualX && y < scrn->virtualY &&
+			(x + cursor->bits->width > 0) &&
+			(y + cursor->bits->height > 0);
+	} else {
+		device_priv->sprite_visible = FALSE;
+	}
+
+	info->sprites_visible += device_priv->sprite_visible - sprite_visible;
+}
+
+void drmmode_sprite_set_cursor(DeviceIntPtr pDev, ScreenPtr pScreen,
+			       CursorPtr pCursor, int x, int y)
+{
+	ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
+	RADEONInfoPtr info = RADEONPTR(scrn);
+	struct radeon_device_priv *device_priv =
+		dixLookupScreenPrivate(&pDev->devPrivates,
+				       &radeon_device_private_key, pScreen);
+
+	device_priv->cursor = pCursor;
+	drmmode_sprite_do_set_cursor(device_priv, scrn, x, y);
+
+	info->SetCursor(pDev, pScreen, pCursor, x, y);
+}
+
+void drmmode_sprite_move_cursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x,
+				int y)
+{
+	ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
+	RADEONInfoPtr info = RADEONPTR(scrn);
+	struct radeon_device_priv *device_priv =
+		dixLookupScreenPrivate(&pDev->devPrivates,
+				       &radeon_device_private_key, pScreen);
+
+	drmmode_sprite_do_set_cursor(device_priv, scrn, x, y);
+
+	info->MoveCursor(pDev, pScreen, x, y);
+}
 
 void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo)
 {
src/drmmode_display.h +4 -0
index 8387279f6..39d2d94a1 100644
@@ -206,6 +206,10 @@ extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
 extern void drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 extern void drmmode_fini(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, struct radeon_bo_manager *bufmgr);
+extern void drmmode_sprite_set_cursor(DeviceIntPtr pDev, ScreenPtr pScreen,
+				      CursorPtr pCursor, int x, int y);
+extern void drmmode_sprite_move_cursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x,
+				       int y);
 extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo);
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
 extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode,
src/radeon.h +13 -0
index cc5dc09f1..9658e029a 100644
@@ -500,6 +500,13 @@ struct radeon_client_priv {
     uint_fast32_t     needs_flush;
 };
 
+struct radeon_device_priv {
+    CursorPtr cursor;
+    Bool sprite_visible;
+};
+
+extern DevScreenPrivateKeyRec radeon_device_private_key;
+
 typedef struct {
     EntityInfoPtr     pEnt;
     pciVideoPtr       PciInfo;
@@ -550,6 +557,12 @@ typedef struct {
     CreateScreenResourcesProcPtr CreateScreenResources;
     CreateWindowProcPtr CreateWindow;
     WindowExposuresProcPtr WindowExposures;
+    void (*SetCursor) (DeviceIntPtr pDev, ScreenPtr pScreen,
+		       CursorPtr pCursor, int x, int y);
+    void (*MoveCursor) (DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y);
+
+    /* Number of SW cursors currently visible on this screen */
+    int sprites_visible;
 
     Bool              IsSecondary;
 
src/radeon_dri2.c +1 -1
index b569bb4f7..8376848cb 100644
@@ -723,7 +723,7 @@ can_flip(xf86CrtcPtr crtc, DrawablePtr draw,
 
     if (draw->type != DRAWABLE_WINDOW ||
 	!info->allowPageFlip ||
-	info->hwcursor_disabled ||
+	info->sprites_visible > 0 ||
 	info->drmmode.present_flipping ||
 	!pScrn->vtSema ||
 	!DRI2CanFlip(draw))
src/radeon_kms.c +28 -0
index 602a8fb7c..c1f885ebd 100644
@@ -38,6 +38,7 @@
 #include "radeon_reg.h"
 #include "radeon_probe.h"
 #include "micmap.h"
+#include "mipointrst.h"
 
 #include "radeon_version.h"
 #include "shadow.h"
@@ -66,6 +67,7 @@
 #include "radeon_vbo.h"
 
 static DevScreenPrivateKeyRec radeon_client_private_key;
+DevScreenPrivateKeyRec radeon_device_private_key;
 
 extern SymTabRec RADEONChipsets[];
 static Bool radeon_setup_kernel_mem(ScreenPtr pScreen);
@@ -1991,6 +1993,23 @@ static Bool RADEONCursorInit_KMS(ScreenPtr pScreen)
     /* Cursor setup */
     miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
+    if (info->allowPageFlip) {
+	miPointerScreenPtr PointPriv =
+	    dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
+
+	if (!dixRegisterScreenPrivateKey(&radeon_device_private_key, pScreen,
+					 PRIVATE_DEVICE,
+					 sizeof(struct radeon_device_priv))) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "dixRegisterScreenPrivateKey failed\n");
+	    return FALSE;
+	}
+
+	info->SetCursor = PointPriv->spriteFuncs->SetCursor;
+	info->MoveCursor = PointPriv->spriteFuncs->MoveCursor;
+	PointPriv->spriteFuncs->SetCursor = drmmode_sprite_set_cursor;
+	PointPriv->spriteFuncs->MoveCursor = drmmode_sprite_move_cursor;
+    }
+
     if (xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE))
 	return TRUE;
 
@@ -2147,6 +2166,15 @@ static Bool RADEONCloseScreen_KMS(ScreenPtr pScreen)
 
     pScrn->vtSema = FALSE;
     xf86ClearPrimInitDone(info->pEnt->index);
+
+    if (info->allowPageFlip) {
+	miPointerScreenPtr PointPriv =
+	    dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
+
+	PointPriv->spriteFuncs->SetCursor = info->SetCursor;
+	PointPriv->spriteFuncs->MoveCursor = info->MoveCursor;
+    }
+
     pScreen->BlockHandler = info->BlockHandler;
     pScreen->CloseScreen = info->CloseScreen;
     return pScreen->CloseScreen(pScreen);
src/radeon_present.c +1 -1
index 176853d92..d734b9d44 100644
@@ -289,7 +289,7 @@ radeon_present_check_flip(RRCrtcPtr crtc, WindowPtr window, PixmapPtr pixmap,
     if (!info->allowPageFlip)
 	return FALSE;
 
-    if (info->hwcursor_disabled)
+    if (info->sprites_visible > 0)
 	return FALSE;
 
     if (info->drmmode.dri2_flipping)
Signature · 6 lines
2.15.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by
#3 lore raw
In reply to a message not in the archive
Quoted 7 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

And bail if xf86_cursors_init fails.

(Ported from amdgpu commit dfccaa7043ccb157a1f8be7313123792bb7e7001)

Series is:

Quoted 69 lines
---
 src/radeon_kms.c | 44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)
src/radeon_kms.c +25 -20
index a9300d400..602a8fb7c 100644
@@ -1982,12 +1982,29 @@ static Bool RADEONCursorInit_KMS(ScreenPtr pScreen)
     ScrnInfoPtr    pScrn = xf86ScreenToScrn(pScreen);
     RADEONInfoPtr  info  = RADEONPTR(pScrn);
 
-    return xf86_cursors_init (pScreen, info->cursor_w, info->cursor_h,
-                             (HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
-                              HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
-                              HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 |
-                              HARDWARE_CURSOR_UPDATE_UNHIDDEN |
-                              HARDWARE_CURSOR_ARGB));
+    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG,
+                  "Initializing Cursor\n");
+
+    /* Set Silken Mouse */
+    xf86SetSilkenMouse(pScreen);
+
+    /* Cursor setup */
+    miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
+
+    if (xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE))
+       return TRUE;
+
+    if (!xf86_cursors_init(pScreen, info->cursor_w, info->cursor_h,
+                          HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
+                          HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
+                          HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 |
+                          HARDWARE_CURSOR_UPDATE_UNHIDDEN |
+                          HARDWARE_CURSOR_ARGB)) {
+       xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "xf86_cursors_init failed\n");
+       return FALSE;
+    }
+
+    return TRUE;
 }
 
 void
@@ -2330,19 +2347,8 @@ Bool RADEONScreenInit_KMS(ScreenPtr pScreen, int argc, char **argv)
                   "Initializing DPMS\n");
     xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
-    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG,
-                  "Initializing Cursor\n");
-
-    /* Set Silken Mouse */
-    xf86SetSilkenMouse(pScreen);
-
-    /* Cursor setup */
-    miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
-
-    if (!xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE)) {
-       if (RADEONCursorInit_KMS(pScreen)) {
-       }
-    }
+    if (!RADEONCursorInit_KMS(pScreen))
+       return FALSE;
 
     /* DGA setup */
 #ifdef XFreeXDGA
--

2.15.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx