dix: move cursor realize code to its own function
The semantic remains, only code was moved: reuse chunk of code to realize cursor on both AllocARGBCursor and AllocGlyphCursor. Signed-off-by: Tiago Vignatti <tiago.vignatti@nokia.com> Reviewed-by: Keith Packard <keithp@keithp.com> Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
f818f22236
commit
d9c20ee419
201
dix/cursor.c
201
dix/cursor.c
|
@ -159,6 +159,64 @@ CheckForEmptyMask(CursorBitsPtr bits)
|
||||||
bits->emptyMask = TRUE;
|
bits->emptyMask = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* realize the cursor for every screen. Do not change the refcnt, this will be
|
||||||
|
* changed when ChangeToCursor actually changes the sprite.
|
||||||
|
*
|
||||||
|
* @return Success if all cursors realize on all screens, BadAlloc if realize
|
||||||
|
* failed for a device on a given screen.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
RealizeCursorAllScreens(CursorPtr pCurs)
|
||||||
|
{
|
||||||
|
DeviceIntPtr pDev;
|
||||||
|
ScreenPtr pscr;
|
||||||
|
int nscr;
|
||||||
|
|
||||||
|
for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
|
||||||
|
{
|
||||||
|
pscr = screenInfo.screens[nscr];
|
||||||
|
for (pDev = inputInfo.devices; pDev; pDev = pDev->next)
|
||||||
|
{
|
||||||
|
if (DevHasCursor(pDev))
|
||||||
|
{
|
||||||
|
if (!( *pscr->RealizeCursor)(pDev, pscr, pCurs))
|
||||||
|
{
|
||||||
|
/* Realize failed for device pDev on screen pscr.
|
||||||
|
* We have to assume that for all devices before, realize
|
||||||
|
* worked. We need to rollback all devices so far on the
|
||||||
|
* current screen and then all devices on previous
|
||||||
|
* screens.
|
||||||
|
*/
|
||||||
|
DeviceIntPtr pDevIt = inputInfo.devices; /*dev iterator*/
|
||||||
|
while(pDevIt && pDevIt != pDev)
|
||||||
|
{
|
||||||
|
if (DevHasCursor(pDevIt))
|
||||||
|
( *pscr->UnrealizeCursor)(pDevIt, pscr, pCurs);
|
||||||
|
pDevIt = pDevIt->next;
|
||||||
|
}
|
||||||
|
while (--nscr >= 0)
|
||||||
|
{
|
||||||
|
pscr = screenInfo.screens[nscr];
|
||||||
|
/* now unrealize all devices on previous screens */
|
||||||
|
pDevIt = inputInfo.devices;
|
||||||
|
while (pDevIt)
|
||||||
|
{
|
||||||
|
if (DevHasCursor(pDevIt))
|
||||||
|
( *pscr->UnrealizeCursor)(pDevIt, pscr, pCurs);
|
||||||
|
pDevIt = pDevIt->next;
|
||||||
|
}
|
||||||
|
( *pscr->UnrealizeCursor)(pDev, pscr, pCurs);
|
||||||
|
}
|
||||||
|
return BadAlloc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Success;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* does nothing about the resource table, just creates the data structure.
|
* does nothing about the resource table, just creates the data structure.
|
||||||
* does not copy the src and mask bits
|
* does not copy the src and mask bits
|
||||||
|
@ -176,9 +234,7 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
|
||||||
{
|
{
|
||||||
CursorBitsPtr bits;
|
CursorBitsPtr bits;
|
||||||
CursorPtr pCurs;
|
CursorPtr pCurs;
|
||||||
int rc, nscr;
|
int rc;
|
||||||
ScreenPtr pscr;
|
|
||||||
DeviceIntPtr pDev;
|
|
||||||
|
|
||||||
*ppCurs = NULL;
|
*ppCurs = NULL;
|
||||||
pCurs = (CursorPtr)xcalloc(sizeof(CursorRec) + sizeof(CursorBits), 1);
|
pCurs = (CursorPtr)xcalloc(sizeof(CursorRec) + sizeof(CursorBits), 1);
|
||||||
|
@ -222,62 +278,21 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
|
||||||
/* security creation/labeling check */
|
/* security creation/labeling check */
|
||||||
rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
|
rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
|
||||||
pCurs, RT_NONE, NULL, DixCreateAccess);
|
pCurs, RT_NONE, NULL, DixCreateAccess);
|
||||||
if (rc != Success) {
|
if (rc != Success)
|
||||||
dixFreePrivates(pCurs->devPrivates);
|
goto error;
|
||||||
FreeCursorBits(bits);
|
|
||||||
xfree(pCurs);
|
rc = RealizeCursorAllScreens(pCurs);
|
||||||
return rc;
|
if (rc != Success)
|
||||||
}
|
goto error;
|
||||||
|
|
||||||
/*
|
|
||||||
* realize the cursor for every screen
|
|
||||||
* Do not change the refcnt, this will be changed when ChangeToCursor
|
|
||||||
* actually changes the sprite.
|
|
||||||
*/
|
|
||||||
for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
|
|
||||||
{
|
|
||||||
pscr = screenInfo.screens[nscr];
|
|
||||||
for (pDev = inputInfo.devices; pDev; pDev = pDev->next)
|
|
||||||
{
|
|
||||||
if (DevHasCursor(pDev))
|
|
||||||
{
|
|
||||||
if (!( *pscr->RealizeCursor)(pDev, pscr, pCurs))
|
|
||||||
{
|
|
||||||
/* Realize failed for device pDev on screen pscr.
|
|
||||||
* We have to assume that for all devices before, realize
|
|
||||||
* worked. We need to rollback all devices so far on the
|
|
||||||
* current screen and then all devices on previous
|
|
||||||
* screens.
|
|
||||||
*/
|
|
||||||
DeviceIntPtr pDevIt = inputInfo.devices; /*dev iterator*/
|
|
||||||
while(pDevIt && pDevIt != pDev)
|
|
||||||
{
|
|
||||||
if (DevHasCursor(pDevIt))
|
|
||||||
( *pscr->UnrealizeCursor)(pDevIt, pscr, pCurs);
|
|
||||||
pDevIt = pDevIt->next;
|
|
||||||
}
|
|
||||||
while (--nscr >= 0)
|
|
||||||
{
|
|
||||||
pscr = screenInfo.screens[nscr];
|
|
||||||
/* now unrealize all devices on previous screens */
|
|
||||||
pDevIt = inputInfo.devices;
|
|
||||||
while (pDevIt)
|
|
||||||
{
|
|
||||||
if (DevHasCursor(pDevIt))
|
|
||||||
( *pscr->UnrealizeCursor)(pDevIt, pscr, pCurs);
|
|
||||||
pDevIt = pDevIt->next;
|
|
||||||
}
|
|
||||||
( *pscr->UnrealizeCursor)(pDev, pscr, pCurs);
|
|
||||||
}
|
|
||||||
dixFreePrivates(pCurs->devPrivates);
|
|
||||||
FreeCursorBits(bits);
|
|
||||||
xfree(pCurs);
|
|
||||||
return BadAlloc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*ppCurs = pCurs;
|
*ppCurs = pCurs;
|
||||||
|
return Success;
|
||||||
|
|
||||||
|
error:
|
||||||
|
dixFreePrivates(pCurs->devPrivates);
|
||||||
|
FreeCursorBits(bits);
|
||||||
|
xfree(pCurs);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,10 +309,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
|
||||||
int rc;
|
int rc;
|
||||||
CursorBitsPtr bits;
|
CursorBitsPtr bits;
|
||||||
CursorPtr pCurs;
|
CursorPtr pCurs;
|
||||||
int nscr;
|
|
||||||
ScreenPtr pscr;
|
|
||||||
GlyphSharePtr pShare;
|
GlyphSharePtr pShare;
|
||||||
DeviceIntPtr pDev;
|
|
||||||
|
|
||||||
rc = dixLookupResourceByType((pointer *)&sourcefont, source, RT_FONT, client,
|
rc = dixLookupResourceByType((pointer *)&sourcefont, source, RT_FONT, client,
|
||||||
DixUseAccess);
|
DixUseAccess);
|
||||||
|
@ -444,67 +456,22 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
|
||||||
/* security creation/labeling check */
|
/* security creation/labeling check */
|
||||||
rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
|
rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
|
||||||
pCurs, RT_NONE, NULL, DixCreateAccess);
|
pCurs, RT_NONE, NULL, DixCreateAccess);
|
||||||
if (rc != Success) {
|
if (rc != Success)
|
||||||
dixFreePrivates(pCurs->devPrivates);
|
goto error;
|
||||||
FreeCursorBits(bits);
|
|
||||||
xfree(pCurs);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
rc = RealizeCursorAllScreens(pCurs);
|
||||||
* realize the cursor for every screen
|
if (rc != Success)
|
||||||
*/
|
goto error;
|
||||||
for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
|
|
||||||
{
|
|
||||||
pscr = screenInfo.screens[nscr];
|
|
||||||
|
|
||||||
for (pDev = inputInfo.devices; pDev; pDev = pDev->next)
|
|
||||||
{
|
|
||||||
if (DevHasCursor(pDev))
|
|
||||||
{
|
|
||||||
if (!( *pscr->RealizeCursor)(pDev, pscr, pCurs))
|
|
||||||
{
|
|
||||||
/* Realize failed for device pDev on screen pscr.
|
|
||||||
* We have to assume that for all devices before, realize
|
|
||||||
* worked. We need to rollback all devices so far on the
|
|
||||||
* current screen and then all devices on previous
|
|
||||||
* screens.
|
|
||||||
*/
|
|
||||||
DeviceIntPtr pDevIt = inputInfo.devices; /*dev iterator*/
|
|
||||||
while(pDevIt && pDevIt != pDev)
|
|
||||||
{
|
|
||||||
if (DevHasCursor(pDevIt))
|
|
||||||
( *pscr->UnrealizeCursor)(pDevIt, pscr, pCurs);
|
|
||||||
pDevIt = pDevIt->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*pscr->UnrealizeCursor)(inputInfo.pointer, pscr, pCurs);
|
|
||||||
|
|
||||||
while (--nscr >= 0)
|
|
||||||
{
|
|
||||||
pscr = screenInfo.screens[nscr];
|
|
||||||
/* now unrealize all devices on previous screens */
|
|
||||||
( *pscr->UnrealizeCursor)(inputInfo.pointer, pscr, pCurs);
|
|
||||||
|
|
||||||
pDevIt = inputInfo.devices;
|
|
||||||
while (pDevIt)
|
|
||||||
{
|
|
||||||
if (DevHasCursor(pDevIt))
|
|
||||||
( *pscr->UnrealizeCursor)(pDevIt, pscr, pCurs);
|
|
||||||
pDevIt = pDevIt->next;
|
|
||||||
}
|
|
||||||
( *pscr->UnrealizeCursor)(pDev, pscr, pCurs);
|
|
||||||
}
|
|
||||||
dixFreePrivates(pCurs->devPrivates);
|
|
||||||
FreeCursorBits(bits);
|
|
||||||
xfree(pCurs);
|
|
||||||
return BadAlloc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*ppCurs = pCurs;
|
*ppCurs = pCurs;
|
||||||
return Success;
|
return Success;
|
||||||
|
|
||||||
|
error:
|
||||||
|
dixFreePrivates(pCurs->devPrivates);
|
||||||
|
FreeCursorBits(bits);
|
||||||
|
xfree(pCurs);
|
||||||
|
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** CreateRootCursor
|
/** CreateRootCursor
|
||||||
|
|
Loading…
Reference in New Issue