Introduce per-object per-screen privates.
This replaces dixCreatePrivateKey and the only uses, which were in midispcur. Commit by Jamey Sharp and Josh Triplett. Signed-off-by: Jamey Sharp <jamey@minilop.net> Signed-off-by: Josh Triplett <josh@joshtriplett.org> Reviewed-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
e4d4d6ddd5
commit
402942cdbc
|
@ -237,28 +237,35 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
Bool
|
||||||
* Allocate a new private key.
|
dixRegisterScreenPrivateKey(DevScreenPrivateKey screenKey, ScreenPtr pScreen, DevPrivateType type, unsigned size)
|
||||||
*
|
|
||||||
* This manages the storage of the key object itself, freeing it when the
|
|
||||||
* privates system is restarted at server reset time. All other keys
|
|
||||||
* are expected to be statically allocated as the privates must be
|
|
||||||
* reset after all objects have been freed
|
|
||||||
*/
|
|
||||||
DevPrivateKey
|
|
||||||
dixCreatePrivateKey(DevPrivateType type, unsigned size)
|
|
||||||
{
|
{
|
||||||
DevPrivateKey key;
|
DevPrivateKey key;
|
||||||
|
|
||||||
|
if (!dixRegisterPrivateKey(&screenKey->screenKey, PRIVATE_SCREEN, 0))
|
||||||
|
return FALSE;
|
||||||
|
key = dixGetPrivate(&pScreen->devPrivates, &screenKey->screenKey);
|
||||||
|
if (key != NULL) {
|
||||||
|
assert(key->size == size);
|
||||||
|
assert(key->type == type);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
key = calloc(sizeof (DevPrivateKeyRec), 1);
|
key = calloc(sizeof (DevPrivateKeyRec), 1);
|
||||||
if (!key)
|
if (!key)
|
||||||
return NULL;
|
return FALSE;
|
||||||
if (!dixRegisterPrivateKey(key, type, size)) {
|
if (!dixRegisterPrivateKey(key, type, size)) {
|
||||||
free(key);
|
free(key);
|
||||||
return NULL;
|
return FALSE;
|
||||||
}
|
}
|
||||||
key->allocated = TRUE;
|
key->allocated = TRUE;
|
||||||
return key;
|
dixSetPrivate(&pScreen->devPrivates, &screenKey->screenKey, key);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
DevPrivateKey
|
||||||
|
_dixGetScreenPrivateKey(const DevScreenPrivateKey key, ScreenPtr pScreen)
|
||||||
|
{
|
||||||
|
return dixGetPrivate(&pScreen->devPrivates, &key->screenKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -4854,16 +4854,16 @@ If the function is called more than once on the same key, all calls must use
|
||||||
the same value for <type>size</type> or the server will abort.</para>
|
the same value for <type>size</type> or the server will abort.</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To request private space and have the server manage the key, use
|
To request per-screen private space in an object, use
|
||||||
<blockquote><programlisting>
|
<blockquote><programlisting>
|
||||||
DevPrivateKey dixCreatePrivateKey(DevPrivateType type, unsigned size);
|
Bool dixRegisterScreenPrivateKey(DevScreenPrivateKey key, ScreenPtr pScreen, DevPrivateType type, unsigned size);
|
||||||
</programlisting></blockquote>
|
</programlisting></blockquote>
|
||||||
The <parameter>type</parameter> and <parameter>size</parameter> arguments are
|
The <parameter>type</parameter> and <parameter>size</parameter> arguments are
|
||||||
the same as those to <function>dixRegisterPrivateKey</function> but this
|
the same as those to <function>dixRegisterPrivateKey</function> but this
|
||||||
function allocates a <type>DevPrivateKeyRec</type> and returns a pointer to it
|
function ensures the given <parameter>key</parameter> exists on objects of
|
||||||
instead of requiring the caller to pass a pointer to an existing structure.
|
the specified type with distinct storage for the given
|
||||||
The server will free it automatically when the privates system is restarted
|
<parameter>pScreen</parameter>. The key is usable on ScreenPrivate variants
|
||||||
at server reset time.</para>
|
that are otherwise equivalent to the following Private functions.</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To attach a piece of private data to an object, use:
|
To attach a piece of private data to an object, use:
|
||||||
|
|
|
@ -65,6 +65,10 @@ typedef struct _DevPrivateKeyRec {
|
||||||
struct _DevPrivateKeyRec *next;
|
struct _DevPrivateKeyRec *next;
|
||||||
} DevPrivateKeyRec, *DevPrivateKey;
|
} DevPrivateKeyRec, *DevPrivateKey;
|
||||||
|
|
||||||
|
typedef struct _DevScreenPrivateKeyRec {
|
||||||
|
DevPrivateKeyRec screenKey;
|
||||||
|
} DevScreenPrivateKeyRec, *DevScreenPrivateKey;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Let drivers know how to initialize private keys
|
* Let drivers know how to initialize private keys
|
||||||
*/
|
*/
|
||||||
|
@ -99,17 +103,6 @@ dixPrivateKeyRegistered(DevPrivateKey key)
|
||||||
return key->initialized;
|
return key->initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate a new private key.
|
|
||||||
*
|
|
||||||
* This manages the storage of the key object itself, freeing it when the
|
|
||||||
* privates system is restarted at server reset time. All other keys
|
|
||||||
* are expected to be statically allocated as the privates must be
|
|
||||||
* reset after all objects have been freed
|
|
||||||
*/
|
|
||||||
extern _X_EXPORT DevPrivateKey
|
|
||||||
dixCreatePrivateKey(DevPrivateType type, unsigned size);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the address of the private storage.
|
* Get the address of the private storage.
|
||||||
*
|
*
|
||||||
|
@ -180,6 +173,42 @@ dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key)
|
||||||
return (pointer *)dixGetPrivateAddr(privates, key);
|
return (pointer *)dixGetPrivateAddr(privates, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern _X_EXPORT Bool
|
||||||
|
dixRegisterScreenPrivateKey(DevScreenPrivateKey key, ScreenPtr pScreen, DevPrivateType type, unsigned size);
|
||||||
|
|
||||||
|
extern _X_EXPORT DevPrivateKey
|
||||||
|
_dixGetScreenPrivateKey(const DevScreenPrivateKey key, ScreenPtr pScreen);
|
||||||
|
|
||||||
|
static inline void *
|
||||||
|
dixGetScreenPrivateAddr(PrivatePtr *privates, const DevScreenPrivateKey key, ScreenPtr pScreen)
|
||||||
|
{
|
||||||
|
return dixGetPrivateAddr(privates, _dixGetScreenPrivateKey(key, pScreen));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void *
|
||||||
|
dixGetScreenPrivate(PrivatePtr *privates, const DevScreenPrivateKey key, ScreenPtr pScreen)
|
||||||
|
{
|
||||||
|
return dixGetPrivate(privates, _dixGetScreenPrivateKey(key, pScreen));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
dixSetScreenPrivate(PrivatePtr *privates, const DevScreenPrivateKey key, ScreenPtr pScreen, pointer val)
|
||||||
|
{
|
||||||
|
return dixSetPrivate(privates, _dixGetScreenPrivateKey(key, pScreen), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline pointer
|
||||||
|
dixLookupScreenPrivate(PrivatePtr *privates, const DevScreenPrivateKey key, ScreenPtr pScreen)
|
||||||
|
{
|
||||||
|
return dixLookupPrivate(privates, _dixGetScreenPrivateKey(key, pScreen));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline pointer *
|
||||||
|
dixLookupScreenPrivateAddr(PrivatePtr *privates, const DevScreenPrivateKey key, ScreenPtr pScreen)
|
||||||
|
{
|
||||||
|
return dixLookupPrivateAddr(privates, _dixGetScreenPrivateKey(key, pScreen));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocates private data separately from main object.
|
* Allocates private data separately from main object.
|
||||||
*
|
*
|
||||||
|
|
|
@ -56,6 +56,10 @@ in this Software without prior written authorization from The Open Group.
|
||||||
/* per-screen private data */
|
/* per-screen private data */
|
||||||
static DevPrivateKeyRec miDCScreenKeyRec;
|
static DevPrivateKeyRec miDCScreenKeyRec;
|
||||||
#define miDCScreenKey (&miDCScreenKeyRec)
|
#define miDCScreenKey (&miDCScreenKeyRec)
|
||||||
|
static DevScreenPrivateKeyRec miDCCursorBitsKeyRec;
|
||||||
|
#define miDCCursorBitsKey (&miDCCursorBitsKeyRec)
|
||||||
|
static DevScreenPrivateKeyRec miDCDeviceKeyRec;
|
||||||
|
#define miDCDeviceKey (&miDCDeviceKeyRec)
|
||||||
|
|
||||||
static Bool miDCCloseScreen(int index, ScreenPtr pScreen);
|
static Bool miDCCloseScreen(int index, ScreenPtr pScreen);
|
||||||
|
|
||||||
|
@ -71,8 +75,8 @@ typedef struct {
|
||||||
|
|
||||||
#define miGetDCDevice(dev, screen) \
|
#define miGetDCDevice(dev, screen) \
|
||||||
((DevHasCursor(dev)) ? \
|
((DevHasCursor(dev)) ? \
|
||||||
(miDCBufferPtr)dixLookupPrivate(&dev->devPrivates, miDCDeviceKey(screen)) : \
|
(miDCBufferPtr)dixLookupScreenPrivate(&dev->devPrivates, miDCDeviceKey, screen) : \
|
||||||
(miDCBufferPtr)dixLookupPrivate(&dev->u.master->devPrivates, miDCDeviceKey(screen)))
|
(miDCBufferPtr)dixLookupScreenPrivate(&dev->u.master->devPrivates, miDCDeviceKey, screen))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The core pointer buffer will point to the index of the virtual core pointer
|
* The core pointer buffer will point to the index of the virtual core pointer
|
||||||
|
@ -80,13 +84,9 @@ typedef struct {
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
CloseScreenProcPtr CloseScreen;
|
CloseScreenProcPtr CloseScreen;
|
||||||
DevPrivateKey device_key;
|
|
||||||
DevPrivateKey cursor_bits_key;
|
|
||||||
} miDCScreenRec, *miDCScreenPtr;
|
} miDCScreenRec, *miDCScreenPtr;
|
||||||
|
|
||||||
#define miGetDCScreen(s) ((miDCScreenPtr)(dixLookupPrivate(&(s)->devPrivates, miDCScreenKey)))
|
#define miGetDCScreen(s) ((miDCScreenPtr)(dixLookupPrivate(&(s)->devPrivates, miDCScreenKey)))
|
||||||
#define miDCDeviceKey(s) (miGetDCScreen(s)->device_key)
|
|
||||||
#define miDCCursorBitsKey(s) (miGetDCScreen(s)->cursor_bits_key)
|
|
||||||
|
|
||||||
/* per-cursor per-screen private data */
|
/* per-cursor per-screen private data */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -102,19 +102,15 @@ miDCInitialize (ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
|
||||||
{
|
{
|
||||||
miDCScreenPtr pScreenPriv;
|
miDCScreenPtr pScreenPriv;
|
||||||
|
|
||||||
if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0))
|
if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0) ||
|
||||||
|
!dixRegisterScreenPrivateKey(&miDCCursorBitsKeyRec, pScreen, PRIVATE_CURSOR_BITS, 0) ||
|
||||||
|
!dixRegisterScreenPrivateKey(&miDCDeviceKeyRec, pScreen, PRIVATE_DEVICE, 0))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
pScreenPriv = malloc(sizeof (miDCScreenRec));
|
pScreenPriv = malloc(sizeof (miDCScreenRec));
|
||||||
if (!pScreenPriv)
|
if (!pScreenPriv)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
pScreenPriv->cursor_bits_key = dixCreatePrivateKey(PRIVATE_CURSOR_BITS, 0);
|
|
||||||
pScreenPriv->device_key = dixCreatePrivateKey(PRIVATE_DEVICE, 0);
|
|
||||||
if (!pScreenPriv->cursor_bits_key || !pScreenPriv->device_key) {
|
|
||||||
free(pScreenPriv);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
pScreenPriv->CloseScreen = pScreen->CloseScreen;
|
pScreenPriv->CloseScreen = pScreen->CloseScreen;
|
||||||
pScreen->CloseScreen = miDCCloseScreen;
|
pScreen->CloseScreen = miDCCloseScreen;
|
||||||
|
|
||||||
|
@ -144,7 +140,7 @@ Bool
|
||||||
miDCRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
|
miDCRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
|
||||||
{
|
{
|
||||||
if (pCursor->bits->refcnt <= 1)
|
if (pCursor->bits->refcnt <= 1)
|
||||||
dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), NULL);
|
dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, NULL);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +239,7 @@ miDCRealize (ScreenPtr pScreen, CursorPtr pCursor)
|
||||||
free((pointer) pPriv);
|
free((pointer) pPriv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), pPriv);
|
dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, pPriv);
|
||||||
return pPriv;
|
return pPriv;
|
||||||
}
|
}
|
||||||
pPriv->pPicture = 0;
|
pPriv->pPicture = 0;
|
||||||
|
@ -261,7 +257,7 @@ miDCRealize (ScreenPtr pScreen, CursorPtr pCursor)
|
||||||
free((pointer) pPriv);
|
free((pointer) pPriv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), pPriv);
|
dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, pPriv);
|
||||||
|
|
||||||
/* create the two sets of bits, clipping as appropriate */
|
/* create the two sets of bits, clipping as appropriate */
|
||||||
|
|
||||||
|
@ -305,8 +301,8 @@ miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
|
||||||
{
|
{
|
||||||
miDCCursorPtr pPriv;
|
miDCCursorPtr pPriv;
|
||||||
|
|
||||||
pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates,
|
pPriv = (miDCCursorPtr)dixLookupScreenPrivate(&pCursor->bits->devPrivates,
|
||||||
miDCCursorBitsKey(pScreen));
|
miDCCursorBitsKey, pScreen);
|
||||||
if (pPriv && (pCursor->bits->refcnt <= 1))
|
if (pPriv && (pCursor->bits->refcnt <= 1))
|
||||||
{
|
{
|
||||||
if (pPriv->sourceBits)
|
if (pPriv->sourceBits)
|
||||||
|
@ -318,7 +314,7 @@ miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
|
||||||
FreePicture (pPriv->pPicture, 0);
|
FreePicture (pPriv->pPicture, 0);
|
||||||
#endif
|
#endif
|
||||||
free((pointer) pPriv);
|
free((pointer) pPriv);
|
||||||
dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), NULL);
|
dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, NULL);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -406,8 +402,8 @@ miDCPutUpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
|
||||||
miDCBufferPtr pBuffer;
|
miDCBufferPtr pBuffer;
|
||||||
WindowPtr pWin;
|
WindowPtr pWin;
|
||||||
|
|
||||||
pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates,
|
pPriv = (miDCCursorPtr)dixLookupScreenPrivate(&pCursor->bits->devPrivates,
|
||||||
miDCCursorBitsKey(pScreen));
|
miDCCursorBitsKey, pScreen);
|
||||||
if (!pPriv)
|
if (!pPriv)
|
||||||
{
|
{
|
||||||
pPriv = miDCRealize(pScreen, pCursor);
|
pPriv = miDCRealize(pScreen, pCursor);
|
||||||
|
@ -523,7 +519,7 @@ miDCDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
|
||||||
if (!pBuffer)
|
if (!pBuffer)
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
dixSetPrivate(&pDev->devPrivates, miDCDeviceKey(pScreen), pBuffer);
|
dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen, pBuffer);
|
||||||
pWin = pScreen->root;
|
pWin = pScreen->root;
|
||||||
|
|
||||||
pBuffer->pSourceGC = miDCMakeGC(pWin);
|
pBuffer->pSourceGC = miDCMakeGC(pWin);
|
||||||
|
@ -589,7 +585,7 @@ miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
|
||||||
if (pBuffer->pSave) (*pScreen->DestroyPixmap)(pBuffer->pSave);
|
if (pBuffer->pSave) (*pScreen->DestroyPixmap)(pBuffer->pSave);
|
||||||
|
|
||||||
free(pBuffer);
|
free(pBuffer);
|
||||||
dixSetPrivate(&pDev->devPrivates, miDCDeviceKey(pScreen), NULL);
|
dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue