From 65572860840d32bee3ad2b0c0774fb28b77620e7 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 28 Feb 2024 16:13:48 +0100 Subject: [PATCH] xfree86: use own dev-privates key for per-screen cursor Since it's storing an locally defined (ddx-internal) data, it's better not to abuse some globally defined key for this. It just happened to work before, since CursorScreenKey is only used by DDX (and there's only one DDX per executable) and they currently (!) have the same size (pointer) - but that's a fragile programming style, so clean it up. Signed-off-by: Enrico Weigelt, metux IT consult Part-of: --- hw/xfree86/modes/xf86Cursors.c | 3 ++- hw/xfree86/ramdac/xf86CursorPriv.h | 2 ++ hw/xfree86/ramdac/xf86CursorRD.c | 15 ++++++++++----- hw/xfree86/ramdac/xf86HWCurs.c | 12 ++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c index dba5f8877..6805f725a 100644 --- a/hw/xfree86/modes/xf86Cursors.c +++ b/hw/xfree86/modes/xf86Cursors.c @@ -301,7 +301,8 @@ xf86_set_cursor_colors(ScrnInfoPtr scrn, int bg, int fg) CursorPtr cursor = xf86CurrentCursor(screen); int c; CARD8 *bits = cursor ? - dixLookupScreenPrivate(&cursor->devPrivates, CursorScreenKey, screen) + dixLookupScreenPrivate(&cursor->devPrivates, + &xf86ScreenCursorBitsKeyRec, screen) : NULL; /* Save ARGB versions of these colors */ diff --git a/hw/xfree86/ramdac/xf86CursorPriv.h b/hw/xfree86/ramdac/xf86CursorPriv.h index 397d2a14b..cb8669733 100644 --- a/hw/xfree86/ramdac/xf86CursorPriv.h +++ b/hw/xfree86/ramdac/xf86CursorPriv.h @@ -48,4 +48,6 @@ extern _X_EXPORT DevPrivateKeyRec xf86CursorScreenKeyRec; #define xf86CursorScreenKey (&xf86CursorScreenKeyRec) +extern DevScreenPrivateKeyRec xf86ScreenCursorBitsKeyRec; + #endif /* _XF86CURSORPRIV_H */ diff --git a/hw/xfree86/ramdac/xf86CursorRD.c b/hw/xfree86/ramdac/xf86CursorRD.c index c8362d169..d423ad204 100644 --- a/hw/xfree86/ramdac/xf86CursorRD.c +++ b/hw/xfree86/ramdac/xf86CursorRD.c @@ -18,6 +18,7 @@ #include "inputstr.h" DevPrivateKeyRec xf86CursorScreenKeyRec; +DevScreenPrivateKeyRec xf86ScreenCursorBitsKeyRec; /* sprite functions */ @@ -68,6 +69,10 @@ xf86InitCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr) if (!ScreenPriv) return FALSE; + if (!dixRegisterScreenPrivateKey(&xf86ScreenCursorBitsKeyRec, pScreen, + PRIVATE_CURSOR, 0)) + return FALSE; + dixSetPrivate(&pScreen->devPrivates, xf86CursorScreenKey, ScreenPriv); ScreenPriv->SWCursor = TRUE; @@ -273,8 +278,8 @@ xf86CursorRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCurs) xf86CursorScreenKey); if (CursorRefCount(pCurs) <= 1) - dixSetScreenPrivate(&pCurs->devPrivates, CursorScreenKey, pScreen, - NULL); + dixSetScreenPrivate(&pCurs->devPrivates, &xf86ScreenCursorBitsKeyRec, + pScreen, NULL); return (*ScreenPriv->spriteFuncs->RealizeCursor) (pDev, pScreen, pCurs); } @@ -288,9 +293,9 @@ xf86CursorUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCurs) if (CursorRefCount(pCurs) <= 1) { free(dixLookupScreenPrivate - (&pCurs->devPrivates, CursorScreenKey, pScreen)); - dixSetScreenPrivate(&pCurs->devPrivates, CursorScreenKey, pScreen, - NULL); + (&pCurs->devPrivates, &xf86ScreenCursorBitsKeyRec, pScreen)); + dixSetScreenPrivate(&pCurs->devPrivates, &xf86ScreenCursorBitsKeyRec, + pScreen, NULL); } return (*ScreenPriv->spriteFuncs->UnrealizeCursor) (pDev, pScreen, pCurs); diff --git a/hw/xfree86/ramdac/xf86HWCurs.c b/hw/xfree86/ramdac/xf86HWCurs.c index ddba5e6c6..eba503d51 100644 --- a/hw/xfree86/ramdac/xf86HWCurs.c +++ b/hw/xfree86/ramdac/xf86HWCurs.c @@ -197,15 +197,15 @@ xf86ScreenSetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y) } /* - * Hot plugged GPU's do not have a CursorScreenKey, force sw cursor. + * Hot plugged GPU's do not have a xf86ScreenCursorBitsKeyRec, force sw cursor. * This check can be removed once dix/privates.c gets relocation code for * PRIVATE_CURSOR. Also see the related comment in AddGPUScreen(). */ - if (!_dixGetScreenPrivateKey(CursorScreenKey, pScreen)) + if (!_dixGetScreenPrivateKey(&xf86ScreenCursorBitsKeyRec, pScreen)) return FALSE; - bits = - dixLookupScreenPrivate(&pCurs->devPrivates, CursorScreenKey, pScreen); + bits = dixLookupScreenPrivate(&pCurs->devPrivates, + &xf86ScreenCursorBitsKeyRec, pScreen); x -= infoPtr->pScrn->frameX0; y -= infoPtr->pScrn->frameY0; @@ -213,8 +213,8 @@ xf86ScreenSetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y) if (!pCurs->bits->argb || !xf86DriverHasLoadCursorARGB(infoPtr)) if (!bits) { bits = (*infoPtr->RealizeCursor) (infoPtr, pCurs); - dixSetScreenPrivate(&pCurs->devPrivates, CursorScreenKey, pScreen, - bits); + dixSetScreenPrivate(&pCurs->devPrivates, + &xf86ScreenCursorBitsKeyRec, pScreen, bits); } if (!(infoPtr->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN))