From 402942cdbc518395a2943fd226b9f3071f24d39f Mon Sep 17 00:00:00 2001 From: Jamey Sharp Date: Fri, 17 Sep 2010 02:11:44 +0200 Subject: 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 Signed-off-by: Josh Triplett Reviewed-by: Keith Packard --- dix/privates.c | 33 +++++++++++++++++++------------ doc/xml/Xserver-spec.xml | 12 ++++++------ include/privates.h | 51 +++++++++++++++++++++++++++++++++++++----------- mi/midispcur.c | 42 ++++++++++++++++++--------------------- 4 files changed, 85 insertions(+), 53 deletions(-) diff --git a/dix/privates.c b/dix/privates.c index 17e1050d9..687fa7aa0 100644 --- a/dix/privates.c +++ b/dix/privates.c @@ -237,28 +237,35 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size) return TRUE; } -/* - * 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 - */ -DevPrivateKey -dixCreatePrivateKey(DevPrivateType type, unsigned size) +Bool +dixRegisterScreenPrivateKey(DevScreenPrivateKey screenKey, ScreenPtr pScreen, DevPrivateType type, unsigned size) { 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); if (!key) - return NULL; + return FALSE; if (!dixRegisterPrivateKey(key, type, size)) { free(key); - return NULL; + return FALSE; } 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); } /* diff --git a/doc/xml/Xserver-spec.xml b/doc/xml/Xserver-spec.xml index 563705fb9..4811a30a4 100644 --- a/doc/xml/Xserver-spec.xml +++ b/doc/xml/Xserver-spec.xml @@ -4854,16 +4854,16 @@ If the function is called more than once on the same key, all calls must use the same value for size or the server will abort. -To request private space and have the server manage the key, use +To request per-screen private space in an object, use
- DevPrivateKey dixCreatePrivateKey(DevPrivateType type, unsigned size); + Bool dixRegisterScreenPrivateKey(DevScreenPrivateKey key, ScreenPtr pScreen, DevPrivateType type, unsigned size);
The type and size arguments are the same as those to dixRegisterPrivateKey but this -function allocates a DevPrivateKeyRec and returns a pointer to it -instead of requiring the caller to pass a pointer to an existing structure. -The server will free it automatically when the privates system is restarted -at server reset time.
+function ensures the given key exists on objects of +the specified type with distinct storage for the given +pScreen. The key is usable on ScreenPrivate variants +that are otherwise equivalent to the following Private functions. To attach a piece of private data to an object, use: diff --git a/include/privates.h b/include/privates.h index d3c0e1325..9fb6ae84e 100644 --- a/include/privates.h +++ b/include/privates.h @@ -65,6 +65,10 @@ typedef struct _DevPrivateKeyRec { struct _DevPrivateKeyRec *next; } DevPrivateKeyRec, *DevPrivateKey; +typedef struct _DevScreenPrivateKeyRec { + DevPrivateKeyRec screenKey; +} DevScreenPrivateKeyRec, *DevScreenPrivateKey; + /* * Let drivers know how to initialize private keys */ @@ -99,17 +103,6 @@ dixPrivateKeyRegistered(DevPrivateKey key) 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. * @@ -180,6 +173,42 @@ dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey 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. * diff --git a/mi/midispcur.c b/mi/midispcur.c index 323ee028b..48feb8823 100644 --- a/mi/midispcur.c +++ b/mi/midispcur.c @@ -56,6 +56,10 @@ in this Software without prior written authorization from The Open Group. /* per-screen private data */ static DevPrivateKeyRec miDCScreenKeyRec; #define miDCScreenKey (&miDCScreenKeyRec) +static DevScreenPrivateKeyRec miDCCursorBitsKeyRec; +#define miDCCursorBitsKey (&miDCCursorBitsKeyRec) +static DevScreenPrivateKeyRec miDCDeviceKeyRec; +#define miDCDeviceKey (&miDCDeviceKeyRec) static Bool miDCCloseScreen(int index, ScreenPtr pScreen); @@ -71,8 +75,8 @@ typedef struct { #define miGetDCDevice(dev, screen) \ ((DevHasCursor(dev)) ? \ - (miDCBufferPtr)dixLookupPrivate(&dev->devPrivates, miDCDeviceKey(screen)) : \ - (miDCBufferPtr)dixLookupPrivate(&dev->u.master->devPrivates, miDCDeviceKey(screen))) + (miDCBufferPtr)dixLookupScreenPrivate(&dev->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 @@ -80,13 +84,9 @@ typedef struct { */ typedef struct { CloseScreenProcPtr CloseScreen; - DevPrivateKey device_key; - DevPrivateKey cursor_bits_key; } miDCScreenRec, *miDCScreenPtr; #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 */ typedef struct { @@ -102,19 +102,15 @@ miDCInitialize (ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs) { 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; pScreenPriv = malloc(sizeof (miDCScreenRec)); if (!pScreenPriv) 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; pScreen->CloseScreen = miDCCloseScreen; @@ -144,7 +140,7 @@ Bool miDCRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor) { if (pCursor->bits->refcnt <= 1) - dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), NULL); + dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, NULL); return TRUE; } @@ -243,7 +239,7 @@ miDCRealize (ScreenPtr pScreen, CursorPtr pCursor) free((pointer) pPriv); return NULL; } - dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), pPriv); + dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, pPriv); return pPriv; } pPriv->pPicture = 0; @@ -261,7 +257,7 @@ miDCRealize (ScreenPtr pScreen, CursorPtr pCursor) free((pointer) pPriv); 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 */ @@ -305,8 +301,8 @@ miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor) { miDCCursorPtr pPriv; - pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates, - miDCCursorBitsKey(pScreen)); + pPriv = (miDCCursorPtr)dixLookupScreenPrivate(&pCursor->bits->devPrivates, + miDCCursorBitsKey, pScreen); if (pPriv && (pCursor->bits->refcnt <= 1)) { if (pPriv->sourceBits) @@ -318,7 +314,7 @@ miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor) FreePicture (pPriv->pPicture, 0); #endif free((pointer) pPriv); - dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), NULL); + dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen, NULL); } return TRUE; } @@ -406,8 +402,8 @@ miDCPutUpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, miDCBufferPtr pBuffer; WindowPtr pWin; - pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates, - miDCCursorBitsKey(pScreen)); + pPriv = (miDCCursorPtr)dixLookupScreenPrivate(&pCursor->bits->devPrivates, + miDCCursorBitsKey, pScreen); if (!pPriv) { pPriv = miDCRealize(pScreen, pCursor); @@ -523,7 +519,7 @@ miDCDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen) if (!pBuffer) goto failure; - dixSetPrivate(&pDev->devPrivates, miDCDeviceKey(pScreen), pBuffer); + dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen, pBuffer); pWin = pScreen->root; pBuffer->pSourceGC = miDCMakeGC(pWin); @@ -589,7 +585,7 @@ miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen) if (pBuffer->pSave) (*pScreen->DestroyPixmap)(pBuffer->pSave); free(pBuffer); - dixSetPrivate(&pDev->devPrivates, miDCDeviceKey(pScreen), NULL); + dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen, NULL); } } } -- cgit v1.2.3