From 4017d3190234e189a0bbd33193a148d4d3c7556b Mon Sep 17 00:00:00 2001 From: Eamon Walsh Date: Tue, 28 Aug 2007 09:28:25 -0400 Subject: devPrivates rework: since API is already broken, switch everything over to new system. Need to update documentation and address some remaining vestiges of old system such as CursorRec structure, fb "offman" structure, and FontRec privates. --- dbe/dbe.c | 226 ++++++-------------------------------------------------- dbe/dbestruct.h | 37 +++------- dbe/midbe.c | 37 +++------- dbe/midbestr.h | 12 +-- 4 files changed, 44 insertions(+), 268 deletions(-) (limited to 'dbe') diff --git a/dbe/dbe.c b/dbe/dbe.c index aec626b79..223b0c983 100644 --- a/dbe/dbe.c +++ b/dbe/dbe.c @@ -58,19 +58,16 @@ /* GLOBALS */ /* Per-screen initialization functions [init'ed by DbeRegisterFunction()] */ -static Bool (* DbeInitFunct[MAXSCREENS])(); /* pScreen, pDbeScreenPriv */ +static Bool (* DbeInitFunct[MAXSCREENS])(); /* pScreen, pDbeScreenPriv */ /* These are static globals copied to DBE's screen private for use by DDX */ -static int dbeScreenPrivIndex; -static int dbeWindowPrivIndex; +static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKey; +static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKey; /* These are static globals copied to DBE's screen private for use by DDX */ static RESTYPE dbeDrawableResType; static RESTYPE dbeWindowPrivResType; -/* This global is used by DbeAllocWinPrivPrivIndex() */ -static int winPrivPrivCount = 0; - /* Used to generate DBE's BadBuffer error. */ static int dbeErrorBase; @@ -112,146 +109,6 @@ DbeRegisterFunction(ScreenPtr pScreen, Bool (*funct) (/* ??? */)) } /* DbeRegisterFunction() */ - -/****************************************************************************** - * - * DBE DIX Procedure: DbeAllocWinPriv - * - * Description: - * - * This function was cloned from AllocateWindow() in window.c. - * This function allocates a window priv structure to be associated - * with a double-buffered window. - * - *****************************************************************************/ -static DbeWindowPrivPtr -DbeAllocWinPriv(ScreenPtr pScreen) -{ - DbeWindowPrivPtr pDbeWindowPriv; - DbeScreenPrivPtr pDbeScreenPriv; - register char *ptr; - register DevUnion *ppriv; - register unsigned int *sizes; - register unsigned int size; - register int i; - - pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen); - pDbeWindowPriv = (DbeWindowPrivPtr)xalloc(pDbeScreenPriv->totalWinPrivSize); - - if (pDbeWindowPriv) - { - ppriv = (DevUnion *)(pDbeWindowPriv + 1); - pDbeWindowPriv->devPrivates = ppriv; - sizes = pDbeScreenPriv->winPrivPrivSizes; - ptr = (char *)(ppriv + pDbeScreenPriv->winPrivPrivLen); - for (i = pDbeScreenPriv->winPrivPrivLen; --i >= 0; ppriv++, sizes++) - { - if ((size = *sizes)) - { - ppriv->ptr = (pointer)ptr; - ptr += size; - } - else - ppriv->ptr = (pointer)NULL; - } - } - - return(pDbeWindowPriv); - -} /* DbeAllocWinPriv() */ - - -/****************************************************************************** - * - * DBE DIX Procedure: DbeFallbackAllocWinPriv - * - * Description: - * - * This is a fallback function for AllocWinPriv(). - * - *****************************************************************************/ - -#if 0 /* NOT USED */ -static DbeWindowPrivPtr -DbeFallbackAllocWinPriv(pScreen) - ScreenPtr pScreen; -{ - return (NULL); -} /* DbeFallbackAllocWinPriv() */ -#endif - - -/****************************************************************************** - * - * DBE DIX Procedure: DbeAllocWinPrivPrivIndex - * - * Description: - * - * This function was cloned from AllocateWindowPrivateIndex() in window.c. - * This function allocates a new window priv priv index by simply returning - * an incremented private counter. - * - *****************************************************************************/ - -static int -DbeAllocWinPrivPrivIndex(void) -{ - return winPrivPrivCount++; - -} /* DbeAllocWinPrivPrivIndex() */ - - -/****************************************************************************** - * - * DBE DIX Procedure: DbeAllocWinPrivPriv - * - * Description: - * - * This function was cloned from AllocateWindowPrivate() in privates.c. - * This function allocates a private structure to be hung off - * a window private. - * - *****************************************************************************/ - -static Bool -DbeAllocWinPrivPriv(register ScreenPtr pScreen, int index, unsigned int amount) -{ - DbeScreenPrivPtr pDbeScreenPriv; - unsigned int oldamount; - - - pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen); - - if (index >= pDbeScreenPriv->winPrivPrivLen) - { - unsigned *nsizes; - nsizes = (unsigned *)xrealloc(pDbeScreenPriv->winPrivPrivSizes, - (index + 1) * sizeof(unsigned)); - if (!nsizes) - { - return(FALSE); - } - - while (pDbeScreenPriv->winPrivPrivLen <= index) - { - nsizes[pDbeScreenPriv->winPrivPrivLen++] = 0; - pDbeScreenPriv->totalWinPrivSize += sizeof(DevUnion); - } - - pDbeScreenPriv->winPrivPrivSizes = nsizes; - } - - oldamount = pDbeScreenPriv->winPrivPrivSizes[index]; - - if (amount > oldamount) - { - pDbeScreenPriv->winPrivPrivSizes[index] = amount; - pDbeScreenPriv->totalWinPrivSize += (amount - oldamount); - } - return(TRUE); - -} /* DbeAllocWinPrivPriv() */ - /****************************************************************************** * @@ -269,9 +126,6 @@ DbeStubScreen(DbeScreenPrivPtr pDbeScreenPriv, int *nStubbedScreens) { /* Stub DIX. */ pDbeScreenPriv->SetupBackgroundPainter = NULL; - pDbeScreenPriv->AllocWinPriv = NULL; - pDbeScreenPriv->AllocWinPrivPrivIndex = NULL; - pDbeScreenPriv->AllocWinPrivPriv = NULL; /* Do not unwrap PositionWindow nor DestroyWindow. If the DDX * initialization function failed, we assume that it did not wrap @@ -439,11 +293,10 @@ ProcDbeAllocateBackBufferName(ClientPtr client) * Allocate a window priv. */ - if (!(pDbeWindowPriv = - (*pDbeScreenPriv->AllocWinPriv)(pWin->drawable.pScreen))) - { + pDbeWindowPriv = (DbeWindowPrivPtr)xalloc(sizeof(DbeWindowPrivRec)); + if (!pDbeWindowPriv) return(BadAlloc); - } + bzero(pDbeWindowPriv, sizeof(DbeWindowPrivRec)); /* Make the window priv a DBE window priv resource. */ if (!AddResource(stuff->buffer, dbeWindowPrivResType, @@ -474,7 +327,7 @@ ProcDbeAllocateBackBufferName(ClientPtr client) /* Actually connect the window priv to the window. */ - pWin->devPrivates[dbeWindowPrivIndex].ptr = (pointer)pDbeWindowPriv; + dixSetPrivate(&pWin->devPrivates, dbeWindowPrivKey, pDbeWindowPriv); } /* if -- There is no buffer associated with the window. */ @@ -1592,10 +1445,11 @@ DbeWindowPrivDelete(pointer pDbeWinPriv, XID id) if (pDbeWindowPriv->nBufferIDs == 0) { /* Reset the DBE window priv pointer. */ - pDbeWindowPriv->pWindow->devPrivates[dbeWindowPrivIndex].ptr = - (pointer)NULL; + dixSetPrivate(&pDbeWindowPriv->pWindow->devPrivates, dbeWindowPrivKey, + NULL); /* We are done with the window priv. */ + dixFreePrivates(pDbeWindowPriv->devPrivates); xfree(pDbeWindowPriv); } @@ -1622,12 +1476,6 @@ DbeResetProc(ExtensionEntry *extEntry) ScreenPtr pScreen; DbeScreenPrivPtr pDbeScreenPriv; - - if (dbeScreenPrivIndex < 0) - { - return; - } - for (i = 0; i < screenInfo.numScreens; i++) { pScreen = screenInfo.screens[i]; @@ -1641,11 +1489,7 @@ DbeResetProc(ExtensionEntry *extEntry) if (pDbeScreenPriv->ResetProc) (*pDbeScreenPriv->ResetProc)(pScreen); - if (pDbeScreenPriv->winPrivPrivSizes) - { - xfree(pDbeScreenPriv->winPrivPrivSizes); - } - + dixFreePrivates(pDbeScreenPriv->devPrivates); xfree(pDbeScreenPriv); } } @@ -1766,21 +1610,6 @@ DbeExtensionInit(void) if(!noPanoramiXExtension) return; #endif - /* Allocate private pointers in windows and screens. */ - - if ((dbeScreenPrivIndex = AllocateScreenPrivateIndex()) < 0) - { - return; - } - - if ((dbeWindowPrivIndex = AllocateWindowPrivateIndex()) < 0) - { - return; - } - - /* Initialize the priv priv counts between server generations. */ - winPrivPrivCount = 0; - /* Create the resource types. */ dbeDrawableResType = CreateNewResourceType(DbeDrawableDelete) | RC_DRAWABLE; @@ -1795,8 +1624,7 @@ DbeExtensionInit(void) pScreen = screenInfo.screens[i]; - if (!AllocateWindowPrivate(pScreen, dbeWindowPrivIndex, 0) || - !(pDbeScreenPriv = + if (!(pDbeScreenPriv = (DbeScreenPrivPtr)Xcalloc(sizeof(DbeScreenPrivRec)))) { /* If we can not alloc a window or screen private, @@ -1805,28 +1633,23 @@ DbeExtensionInit(void) for (j = 0; j < i; j++) { - xfree(screenInfo.screens[j]->devPrivates[dbeScreenPrivIndex].ptr); - screenInfo.screens[j]->devPrivates[dbeScreenPrivIndex].ptr = NULL; + xfree(dixLookupPrivate(&screenInfo.screens[j]->devPrivates, + dbeScreenPrivKey)); + dixSetPrivate(&screenInfo.screens[j]->devPrivates, + dbeScreenPrivKey, NULL); } return; } - pScreen->devPrivates[dbeScreenPrivIndex].ptr = (pointer)pDbeScreenPriv; - - /* Store the DBE priv priv size info for later use when allocating - * priv privs at the driver level. - */ - pDbeScreenPriv->winPrivPrivLen = 0; - pDbeScreenPriv->winPrivPrivSizes = (unsigned *)NULL; - pDbeScreenPriv->totalWinPrivSize = sizeof(DbeWindowPrivRec); + dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, pDbeScreenPriv); /* Copy the resource types */ pDbeScreenPriv->dbeDrawableResType = dbeDrawableResType; pDbeScreenPriv->dbeWindowPrivResType = dbeWindowPrivResType; /* Copy the private indices */ - pDbeScreenPriv->dbeScreenPrivIndex = dbeScreenPrivIndex; - pDbeScreenPriv->dbeWindowPrivIndex = dbeWindowPrivIndex; + pDbeScreenPriv->dbeScreenPrivKey = dbeScreenPrivKey; + pDbeScreenPriv->dbeWindowPrivKey = dbeWindowPrivKey; if(DbeInitFunct[i]) { @@ -1834,9 +1657,6 @@ DbeExtensionInit(void) /* Setup DIX. */ pDbeScreenPriv->SetupBackgroundPainter = DbeSetupBackgroundPainter; - pDbeScreenPriv->AllocWinPriv = DbeAllocWinPriv; - pDbeScreenPriv->AllocWinPrivPrivIndex = DbeAllocWinPrivPrivIndex; - pDbeScreenPriv->AllocWinPrivPriv = DbeAllocWinPrivPriv; /* Setup DDX. */ ddxInitSuccess = (*DbeInitFunct[i])(pScreen, pDbeScreenPriv); @@ -1868,9 +1688,6 @@ DbeExtensionInit(void) #ifndef DISABLE_MI_DBE_BY_DEFAULT /* Setup DIX. */ pDbeScreenPriv->SetupBackgroundPainter = DbeSetupBackgroundPainter; - pDbeScreenPriv->AllocWinPriv = DbeAllocWinPriv; - pDbeScreenPriv->AllocWinPrivPrivIndex = DbeAllocWinPrivPrivIndex; - pDbeScreenPriv->AllocWinPrivPriv = DbeAllocWinPrivPriv; /* Setup DDX. */ ddxInitSuccess = miDbeInit(pScreen, pDbeScreenPriv); @@ -1909,8 +1726,9 @@ DbeExtensionInit(void) for (i = 0; i < screenInfo.numScreens; i++) { - xfree(screenInfo.screens[i]->devPrivates[dbeScreenPrivIndex].ptr); - pScreen->devPrivates[dbeScreenPrivIndex].ptr = NULL; + xfree(dixLookupPrivate(&screenInfo.screens[i]->devPrivates, + dbeScreenPrivKey)); + dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, NULL); } return; } diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h index 90f13428a..7d5a115ad 100644 --- a/dbe/dbestruct.h +++ b/dbe/dbestruct.h @@ -39,14 +39,13 @@ #define NEED_DBE_PROTOCOL #include #include "windowstr.h" +#include "privates.h" /* DEFINES */ -#define DBE_SCREEN_PRIV(pScreen) \ - ((dbeScreenPrivIndex < 0) ? \ - NULL : \ - ((DbeScreenPrivPtr)((pScreen)->devPrivates[dbeScreenPrivIndex].ptr))) +#define DBE_SCREEN_PRIV(pScreen) ((DbeScreenPrivPtr) \ + dixLookupPrivate(&(pScreen)->devPrivates, dbeScreenPrivKey)) #define DBE_SCREEN_PRIV_FROM_DRAWABLE(pDrawable) \ DBE_SCREEN_PRIV((pDrawable)->pScreen) @@ -63,10 +62,8 @@ #define DBE_SCREEN_PRIV_FROM_GC(pGC)\ DBE_SCREEN_PRIV((pGC)->pScreen) -#define DBE_WINDOW_PRIV(pWindow)\ - ((dbeWindowPrivIndex < 0) ? \ - NULL : \ - ((DbeWindowPrivPtr)(pWindow->devPrivates[dbeWindowPrivIndex].ptr))) +#define DBE_WINDOW_PRIV(pWin) ((DbeWindowPrivPtr) \ + dixLookupPrivate(&(pWin)->devPrivates, dbeWindowPrivKey)) /* Initial size of the buffer ID array in the window priv. */ #define DBE_INIT_MAX_IDS 2 @@ -142,7 +139,7 @@ typedef struct _DbeWindowPrivRec /* Device-specific private information. */ - DevUnion *devPrivates; + PrivateRec *devPrivates; } DbeWindowPrivRec, *DbeWindowPrivPtr; @@ -155,18 +152,13 @@ typedef struct _DbeWindowPrivRec typedef struct _DbeScreenPrivRec { - /* Info for creating window privs */ - int winPrivPrivLen; /* Length of privs in DbeWindowPrivRec */ - unsigned int *winPrivPrivSizes; /* Array of private record sizes */ - unsigned int totalWinPrivSize; /* PrivRec + size of all priv priv ptrs */ - /* Resources created by DIX to be used by DDX */ RESTYPE dbeDrawableResType; RESTYPE dbeWindowPrivResType; /* Private indices created by DIX to be used by DDX */ - int dbeScreenPrivIndex; - int dbeWindowPrivIndex; + DevPrivateKey dbeScreenPrivKey; + DevPrivateKey dbeWindowPrivKey; /* Wrapped functions * It is the responsibilty of the DDX layer to wrap PositionWindow(). @@ -180,17 +172,6 @@ typedef struct _DbeScreenPrivRec WindowPtr /*pWin*/, GCPtr /*pGC*/ ); - DbeWindowPrivPtr (*AllocWinPriv)( - ScreenPtr /*pScreen*/ -); - int (*AllocWinPrivPrivIndex)( - void -); - Bool (*AllocWinPrivPriv)( - ScreenPtr /*pScreen*/, - int /*index*/, - unsigned /*amount*/ -); /* Per-screen DDX routines */ Bool (*GetVisualInfo)( @@ -223,7 +204,7 @@ typedef struct _DbeScreenPrivRec /* Device-specific private information. */ - DevUnion *devPrivates; + PrivateRec *devPrivates; } DbeScreenPrivRec, *DbeScreenPrivPtr; diff --git a/dbe/midbe.c b/dbe/midbe.c index 014e365ce..f26a09c6d 100644 --- a/dbe/midbe.c +++ b/dbe/midbe.c @@ -59,12 +59,11 @@ #include -static int miDbePrivPrivGeneration = 0; -static int miDbeWindowPrivPrivIndex = -1; +static DevPrivateKey miDbeWindowPrivPrivKey = &miDbeWindowPrivPrivKey; static RESTYPE dbeDrawableResType; static RESTYPE dbeWindowPrivResType; -static int dbeScreenPrivIndex = -1; -static int dbeWindowPrivIndex = -1; +static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKey; +static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKey; /****************************************************************************** @@ -204,8 +203,8 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction) /* Attach the priv priv to the priv. */ - pDbeWindowPriv->devPrivates[miDbeWindowPrivPrivIndex].ptr = - (pointer)pDbeWindowPrivPriv; + dixSetPrivate(&pDbeWindowPriv->devPrivates, miDbeWindowPrivPrivKey, + pDbeWindowPrivPriv); /* Clear the back buffer. */ @@ -778,30 +777,12 @@ miDbeInit(ScreenPtr pScreen, DbeScreenPrivPtr pDbeScreenPriv) dbeWindowPrivResType = pDbeScreenPriv->dbeWindowPrivResType; /* Copy private indices created by DIX */ - dbeScreenPrivIndex = pDbeScreenPriv->dbeScreenPrivIndex; - dbeWindowPrivIndex = pDbeScreenPriv->dbeWindowPrivIndex; + dbeScreenPrivKey = pDbeScreenPriv->dbeScreenPrivKey; + dbeWindowPrivKey = pDbeScreenPriv->dbeWindowPrivKey; - /* Reset the window priv privs if generations do not match. */ - if (miDbePrivPrivGeneration != serverGeneration) - { - /* - ********************************************************************** - ** Allocate the window priv priv. - ********************************************************************** - */ - - miDbeWindowPrivPrivIndex = (*pDbeScreenPriv->AllocWinPrivPrivIndex)(); - - /* Make sure we only do this code once. */ - miDbePrivPrivGeneration = serverGeneration; - - } /* if -- Reset priv privs. */ - - if (!(*pDbeScreenPriv->AllocWinPrivPriv)(pScreen, - miDbeWindowPrivPrivIndex, sizeof(MiDbeWindowPrivPrivRec))) - { + if (!dixRequestPrivate(miDbeWindowPrivPrivKey, + sizeof(MiDbeWindowPrivPrivRec))) return(FALSE); - } /* Wrap functions. */ pDbeScreenPriv->PositionWindow = pScreen->PositionWindow; diff --git a/dbe/midbestr.h b/dbe/midbestr.h index 1ad0104aa..ae9f206fc 100644 --- a/dbe/midbestr.h +++ b/dbe/midbestr.h @@ -42,19 +42,15 @@ /* DEFINES */ #define MI_DBE_WINDOW_PRIV_PRIV(pDbeWindowPriv) \ - (((miDbeWindowPrivPrivIndex < 0) || (!pDbeWindowPriv)) ? \ - NULL : \ - ((MiDbeWindowPrivPrivPtr) \ - ((pDbeWindowPriv)->devPrivates[miDbeWindowPrivPrivIndex].ptr))) + (!(pDbeWindowPriv) ? NULL : (MiDbeWindowPrivPrivPtr) \ + dixLookupPrivate(&(pDbeWindowPriv)->devPrivates, miDbeWindowPrivPrivKey)) #define MI_DBE_WINDOW_PRIV_PRIV_FROM_WINDOW(pWin)\ MI_DBE_WINDOW_PRIV_PRIV(DBE_WINDOW_PRIV(pWin)) #define MI_DBE_SCREEN_PRIV_PRIV(pDbeScreenPriv) \ - (((miDbeScreenPrivPrivIndex < 0) || (!pDbeScreenPriv)) ? \ - NULL : \ - ((MiDbeScreenPrivPrivPtr) \ - ((pDbeScreenPriv)->devPrivates[miDbeScreenPrivPrivIndex].ptr))) + (!(pDbeScreenPriv) ? NULL : (MiDbeScreenPrivPrivPtr) \ + dixLookupPrivate(&(pDbeScreenPriv)->devPrivates, miDbeScreenPrivPrivKey)) /* TYPEDEFS */ -- cgit v1.2.3