xf86-video-amdgpu: Branch 'master' - 2 commits

Michel Dänzer daenzer at kemper.freedesktop.org
Wed Dec 27 16:03:10 UTC 2017


 src/amdgpu_dri2.c     |    2 -
 src/amdgpu_drv.h      |   13 +++++++++
 src/amdgpu_kms.c      |   72 ++++++++++++++++++++++++++++++++++++--------------
 src/amdgpu_present.c  |    2 -
 src/drmmode_display.c |   52 ++++++++++++++++++++++++++++++++++++
 src/drmmode_display.h |    4 ++
 6 files changed, 124 insertions(+), 21 deletions(-)

New commits:
commit 69e20839bfeb3ee0b0a732d72de0a32d6c5435fc
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Fri Dec 22 18:33:58 2017 +0100

    Keep track of how many SW cursors are visible on each screen
    
    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
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/src/amdgpu_dri2.c b/src/amdgpu_dri2.c
index a8ccd22..4ffa346 100644
--- a/src/amdgpu_dri2.c
+++ b/src/amdgpu_dri2.c
@@ -603,7 +603,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))
diff --git a/src/amdgpu_drv.h b/src/amdgpu_drv.h
index 055c3c3..f60b192 100644
--- a/src/amdgpu_drv.h
+++ b/src/amdgpu_drv.h
@@ -234,6 +234,13 @@ struct amdgpu_client_priv {
 	uint_fast32_t needs_flush;
 };
 
+struct amdgpu_device_priv {
+	CursorPtr cursor;
+	Bool sprite_visible;
+};
+
+extern DevScreenPrivateKeyRec amdgpu_device_private_key;
+
 typedef struct {
 	EntityInfoPtr pEnt;
 	struct pci_device *PciInfo;
@@ -274,6 +281,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;
 
diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index 58531bf..49044f5 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -37,6 +37,7 @@
 #include "amdgpu_glamor.h"
 #include "amdgpu_probe.h"
 #include "micmap.h"
+#include "mipointrst.h"
 
 #include "amdgpu_version.h"
 #include "shadow.h"
@@ -62,6 +63,7 @@
 #include <gbm.h>
 
 static DevScreenPrivateKeyRec amdgpu_client_private_key;
+DevScreenPrivateKeyRec amdgpu_device_private_key;
 
 static Bool amdgpu_setup_kernel_mem(ScreenPtr pScreen);
 
@@ -1532,6 +1534,23 @@ static Bool AMDGPUCursorInit_KMS(ScreenPtr pScreen)
 	/* Cursor setup */
 	miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
+	if (info->allowPageFlip) {
+		miPointerScreenPtr PointPriv =
+			dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
+
+		if (!dixRegisterScreenPrivateKey(&amdgpu_device_private_key, pScreen,
+						 PRIVATE_DEVICE,
+						 sizeof(struct amdgpu_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;
 
@@ -1701,6 +1720,15 @@ static Bool AMDGPUCloseScreen_KMS(ScreenPtr pScreen)
 	amdgpu_glamor_fini(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);
diff --git a/src/amdgpu_present.c b/src/amdgpu_present.c
index cef93c0..4e74bfa 100644
--- a/src/amdgpu_present.c
+++ b/src/amdgpu_present.c
@@ -273,7 +273,7 @@ amdgpu_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)
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 55551ee..0471794 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -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"
@@ -2431,6 +2432,57 @@ void drmmode_fini(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 		drmmode_crtc_scanout_free(config->crtc[c]->driver_private);
 }
 
+static void drmmode_sprite_do_set_cursor(struct amdgpu_device_priv *device_priv,
+					 ScrnInfoPtr scrn, int x, int y)
+{
+	AMDGPUInfoPtr info = AMDGPUPTR(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);
+	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
+	struct amdgpu_device_priv *device_priv =
+		dixLookupScreenPrivate(&pDev->devPrivates,
+				       &amdgpu_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);
+	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
+	struct amdgpu_device_priv *device_priv =
+		dixLookupScreenPrivate(&pDev->devPrivates,
+				       &amdgpu_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 amdgpu_buffer *bo)
 {
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index 03134f0..4e6f707 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -198,6 +198,10 @@ extern int drmmode_page_flip_target_relative(AMDGPUEntPtr pAMDGPUEnt,
 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 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 amdgpu_buffer *bo);
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
commit dfccaa7043ccb157a1f8be7313123792bb7e7001
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Fri Dec 22 17:09:07 2017 +0100

    Move cursor related ScreenInit calls into AMDGPUCursorInit_KMS
    
    And bail if xf86_cursors_init fails.
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index c157112..58531bf 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -1523,12 +1523,29 @@ static Bool AMDGPUCursorInit_KMS(ScreenPtr pScreen)
 	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 	AMDGPUInfoPtr info = AMDGPUPTR(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, AMDGPU_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 AMDGPUBlank(ScrnInfoPtr pScrn)
@@ -1858,19 +1875,8 @@ Bool AMDGPUScreenInit_KMS(ScreenPtr pScreen, int argc, char **argv)
 		       "Initializing DPMS\n");
 	xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
-	xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, AMDGPU_LOGLEVEL_DEBUG,
-		       "Initializing Cursor\n");
-
-	/* Set Silken Mouse */
-	xf86SetSilkenMouse(pScreen);
-
-	/* Cursor setup */
-	miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
-
-	if (!xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE)) {
-		if (AMDGPUCursorInit_KMS(pScreen)) {
-		}
-	}
+	if (!AMDGPUCursorInit_KMS(pScreen))
+		return FALSE;
 
 	/* DGA setup */
 #ifdef XFreeXDGA


More information about the xorg-commit mailing list