summaryrefslogtreecommitdiff
path: root/dix
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2013-05-15 19:01:11 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2013-05-15 19:17:57 +1000
commit9a5ad65330693b3273972b63d10f2907d9ab954a (patch)
tree3717cb1f7b1373bc4a1d29a03739e7b275fc61e2 /dix
parent35c2e263db01b2b61354298e5e85aa3cae8ac317 (diff)
Abstract cursor refcounting
Too many callers relied on the refcnt being handled correctly. Use a simple wrapper to handle that case. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'dix')
-rw-r--r--dix/cursor.c33
-rw-r--r--dix/events.c20
-rw-r--r--dix/grabs.c8
-rw-r--r--dix/window.c15
4 files changed, 45 insertions, 31 deletions
diff --git a/dix/cursor.c b/dix/cursor.c
index 1ee127ac5..0820b18ad 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -114,9 +114,13 @@ FreeCursor(pointer value, XID cid)
ScreenPtr pscr;
DeviceIntPtr pDev = NULL; /* unused anyway */
- if (--pCurs->refcnt != 0)
+
+ UnrefCursor(pCurs);
+ if (CursorRefCount(pCurs) != 0)
return Success;
+ BUG_WARN(CursorRefCount(pCurs) < 0);
+
for (nscr = 0; nscr < screenInfo.numScreens; nscr++) {
pscr = screenInfo.screens[nscr];
(void) (*pscr->UnrealizeCursor) (pDev, pscr, pCurs);
@@ -127,6 +131,33 @@ FreeCursor(pointer value, XID cid)
return Success;
}
+CursorPtr
+RefCursor(CursorPtr cursor)
+{
+ ErrorF("%s ::::: cursor is %p", __func__, cursor);
+ if (cursor) {
+ xorg_backtrace();
+ cursor->refcnt++;
+ }
+ ErrorF("\n");
+ return cursor;
+}
+
+CursorPtr
+UnrefCursor(CursorPtr cursor)
+{
+ if (cursor)
+ cursor->refcnt--;
+ return cursor;
+}
+
+int
+CursorRefCount(const CursorPtr cursor)
+{
+ return cursor ? cursor->refcnt : 0;
+}
+
+
/*
* We check for empty cursors so that we won't have to display them
*/
diff --git a/dix/events.c b/dix/events.c
index 8124ca93d..e5db348c6 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -931,8 +931,7 @@ ChangeToCursor(DeviceIntPtr pDev, CursorPtr cursor)
(*pScreen->DisplayCursor) (pDev, pScreen, cursor);
FreeCursor(pSprite->current, (Cursor) 0);
- pSprite->current = cursor;
- pSprite->current->refcnt++;
+ pSprite->current = RefCursor(cursor);
}
}
@@ -3210,11 +3209,10 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin)
pSprite->pEnqueueScreen = screenInfo.screens[0];
pSprite->pDequeueScreen = pSprite->pEnqueueScreen;
}
- if (pCursor)
- pCursor->refcnt++;
+ pCursor = RefCursor(pCursor);
if (pSprite->current)
FreeCursor(pSprite->current, None);
- pSprite->current = pCursor;
+ pSprite->current = RefCursor(pCursor);
if (pScreen) {
(*pScreen->RealizeCursor) (pDev, pScreen, pSprite->current);
@@ -3293,9 +3291,7 @@ UpdateSpriteForScreen(DeviceIntPtr pDev, ScreenPtr pScreen)
pSprite->hotLimits.x2 = pScreen->width;
pSprite->hotLimits.y2 = pScreen->height;
pSprite->win = win;
- pCursor = wCursor(win);
- if (pCursor)
- pCursor->refcnt++;
+ pCursor = RefCursor(wCursor(win));
if (pSprite->current)
FreeCursor(pSprite->current, 0);
pSprite->current = pCursor;
@@ -4945,9 +4941,7 @@ ProcChangeActivePointerGrab(ClientPtr client)
(CompareTimeStamps(time, device->deviceGrab.grabTime) == EARLIER))
return Success;
oldCursor = grab->cursor;
- grab->cursor = newCursor;
- if (newCursor)
- newCursor->refcnt++;
+ grab->cursor = RefCursor(newCursor);
PostNewCursor(device);
if (oldCursor)
FreeCursor(oldCursor, (Cursor) 0);
@@ -5092,9 +5086,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
else
xi2mask_merge(tempGrab->xi2mask, mask->xi2mask);
tempGrab->device = dev;
- tempGrab->cursor = cursor;
- if (cursor)
- tempGrab->cursor->refcnt++;
+ tempGrab->cursor = RefCursor(cursor);
tempGrab->confineTo = confineTo;
tempGrab->grabtype = grabtype;
(*grabInfo->ActivateGrab) (dev, tempGrab, time, FALSE);
diff --git a/dix/grabs.c b/dix/grabs.c
index b254ddcf1..a03897af4 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -241,13 +241,11 @@ CreateGrab(int client, DeviceIntPtr device, DeviceIntPtr modDevice,
grab->detail.exact = keybut;
grab->detail.pMask = NULL;
grab->confineTo = confineTo;
- grab->cursor = cursor;
+ grab->cursor = RefCursor(cursor);
grab->next = NULL;
if (grabtype == XI2)
xi2mask_merge(grab->xi2mask, mask->xi2mask);
- if (cursor)
- cursor->refcnt++;
return grab;
}
@@ -274,9 +272,6 @@ CopyGrab(GrabPtr dst, const GrabPtr src)
Mask *details_mask = NULL;
XI2Mask *xi2mask;
- if (src->cursor)
- src->cursor->refcnt++;
-
if (src->modifiersDetail.pMask) {
int len = MasksPerDetailMask * sizeof(Mask);
@@ -314,6 +309,7 @@ CopyGrab(GrabPtr dst, const GrabPtr src)
dst->modifiersDetail.pMask = mdetails_mask;
dst->detail.pMask = details_mask;
dst->xi2mask = xi2mask;
+ dst->cursor = RefCursor(src->cursor);
xi2mask_merge(dst->xi2mask, src->xi2mask);
diff --git a/dix/window.c b/dix/window.c
index a9297f3c8..8950f9766 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -547,8 +547,7 @@ InitRootWindow(WindowPtr pWin)
(*pScreen->PositionWindow) (pWin, 0, 0);
pWin->cursorIsNone = FALSE;
- pWin->optional->cursor = rootCursor;
- rootCursor->refcnt++;
+ pWin->optional->cursor = RefCursor(rootCursor);
if (party_like_its_1989) {
MakeRootTile(pWin);
@@ -1416,8 +1415,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
else if (pWin->parent && pCursor == wCursor(pWin->parent))
checkOptional = TRUE;
pOldCursor = pWin->optional->cursor;
- pWin->optional->cursor = pCursor;
- pCursor->refcnt++;
+ pWin->optional->cursor = RefCursor(pCursor);
pWin->cursorIsNone = FALSE;
/*
* check on any children now matching the new cursor
@@ -3323,8 +3321,7 @@ MakeWindowOptional(WindowPtr pWin)
parentOptional = FindWindowWithOptional(pWin)->optional;
optional->visual = parentOptional->visual;
if (!pWin->cursorIsNone) {
- optional->cursor = parentOptional->cursor;
- optional->cursor->refcnt++;
+ optional->cursor = RefCursor(parentOptional->cursor);
}
else {
optional->cursor = None;
@@ -3412,8 +3409,7 @@ ChangeWindowDeviceCursor(WindowPtr pWin, DeviceIntPtr pDev, CursorPtr pCursor)
if (pCursor && WindowParentHasDeviceCursor(pWin, pDev, pCursor))
pNode->cursor = None;
else {
- pNode->cursor = pCursor;
- pCursor->refcnt++;
+ pNode->cursor = RefCursor(pCursor);
}
pNode = pPrev = NULL;
@@ -3421,8 +3417,7 @@ ChangeWindowDeviceCursor(WindowPtr pWin, DeviceIntPtr pDev, CursorPtr pCursor)
for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) {
if (WindowSeekDeviceCursor(pChild, pDev, &pNode, &pPrev)) {
if (pNode->cursor == None) { /* inherited from parent */
- pNode->cursor = pOldCursor;
- pOldCursor->refcnt++;
+ pNode->cursor = RefCursor(pOldCursor);
}
else if (pNode->cursor == pCursor) {
pNode->cursor = None;