[PATCH 4/4] devPrivates rework (v3): composite example

Eamon Walsh ewalsh at tycho.nsa.gov
Thu Mar 8 13:54:16 PST 2007


Example of converting composite code to new mechanism.

--
 compalloc.c |   10 +++++-----
 compext.c   |   11 ++++++-----
 compinit.c  |   33 ++++++++-------------------------
 compint.h   |   16 ++++++++++------
 4 files changed, 29 insertions(+), 41 deletions(-)

--
diff --git a/composite/compalloc.c b/composite/compalloc.c
index 5bbf0a2..3a3586c 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -139,7 +139,7 @@ compRedirectWindow (ClientPtr pClient, WindowPtr pWin, int update)
 	cw->oldy = COMP_ORIGIN_INVALID;
 	cw->damageRegistered = FALSE;
 	cw->damaged = FALSE;
-	pWin->devPrivates[CompWindowPrivateIndex].ptr = cw;
+	dixSetPrivate(DEVPRIV_PTR(pWin), CompWindowPrivateKey, cw);
     }
     ccw->next = cw->clients;
     cw->clients = ccw;
@@ -214,7 +214,7 @@ compFreeClientWindow (WindowPtr pWin, XID id)
 	
 	REGION_UNINIT (pScreen, &cw->borderClip);
     
-	pWin->devPrivates[CompWindowPrivateIndex].ptr = 0;
+	dixSetPrivate(DEVPRIV_PTR(pWin), CompWindowPrivateKey, NULL);
 	xfree (cw);
     }
     else if (cw->update == CompositeRedirectAutomatic &&
@@ -298,7 +298,7 @@ compRedirectSubwindows (ClientPtr pClient, WindowPtr pWin, int update)
 	}
 	csw->update = CompositeRedirectAutomatic;
 	csw->clients = 0;
-	pWin->devPrivates[CompSubwindowsPrivateIndex].ptr = csw;
+	dixSetPrivate(DEVPRIV_PTR(pWin), CompSubwindowsPrivateKey, csw);
     }
     /*
      * Redirect all existing windows
@@ -313,7 +313,7 @@ compRedirectSubwindows (ClientPtr pClient, WindowPtr pWin, int update)
 	    if (!csw->clients)
 	    {
 		xfree (csw);
-		pWin->devPrivates[CompSubwindowsPrivateIndex].ptr = 0;
+		dixSetPrivate(DEVPRIV_PTR(pWin), CompSubwindowsPrivateKey, 0);
 	    }
 	    xfree (ccw);
 	    return ret;
@@ -386,7 +386,7 @@ compFreeClientSubwindows (WindowPtr pWin, XID id)
      */
     if (!csw->clients)
     {
-	pWin->devPrivates[CompSubwindowsPrivateIndex].ptr = 0;
+	dixSetPrivate(DEVPRIV_PTR(pWin), CompSubwindowsPrivateKey, NULL);
 	xfree (csw);
     }
 }
diff --git a/composite/compext.c b/composite/compext.c
index 13936fa..8752dbc 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -50,7 +50,8 @@
 #include "compint.h"
 
 static CARD8	CompositeReqCode;
-int		CompositeClientPrivateIndex;
+static devprivate_key_t CompositeClientPrivateVar;
+devprivate_key_t *const CompositeClientPrivateKey = &CompositeClientPrivateVar;
 RESTYPE		CompositeClientWindowType;
 RESTYPE		CompositeClientSubwindowsType;
 RESTYPE		CompositeClientOverlayType;
@@ -63,7 +64,8 @@ typedef struct _CompositeClient {
     int	    minor_version;
 } CompositeClientRec, *CompositeClientPtr;
 
-#define GetCompositeClient(pClient)    ((CompositeClientPtr) (pClient)->devPrivates[CompositeClientPrivateIndex].ptr)
+#define GetCompositeClient(pClient) ((CompositeClientPtr) \
+    dixLookupPrivate(DEVPRIV_PTR(pClient), CompositeClientPrivateKey))
 
 static void
 CompositeClientCallback (CallbackListPtr	*list,
@@ -690,9 +692,8 @@ CompositeExtensionInit (void)
     if (!CompositeClientOverlayType)
 	return;
 
-    CompositeClientPrivateIndex = AllocateClientPrivateIndex ();
-    if (!AllocateClientPrivate (CompositeClientPrivateIndex, 
-				sizeof (CompositeClientRec)))
+    if (!dixRequestPrivate(CompositeClientPrivateKey,
+			   sizeof(CompositeClientRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, CompositeClientCallback, 0))
 	return;
diff --git a/composite/compinit.c b/composite/compinit.c
index 1d5cc7b..c8a5b33 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -48,10 +48,12 @@
 
 #include "compint.h"
 
-int	CompScreenPrivateIndex;
-int	CompWindowPrivateIndex;
-int	CompSubwindowsPrivateIndex;
-int	CompGeneration;
+static devprivate_key_t CompScreenPrivateVar;
+devprivate_key_t *const CompScreenPrivateKey = &CompScreenPrivateVar;
+static devprivate_key_t CompWindowPrivateVar;
+devprivate_key_t *const CompWindowPrivateKey = &CompWindowPrivateVar;
+static devprivate_key_t CompSubwindowsPrivateVar;
+devprivate_key_t *const CompSubwindowsPrivateKey = &CompSubwindowsPrivateVar;
 
 
 static Bool
@@ -88,7 +90,7 @@ compCloseScreen (int index, ScreenPtr pScreen)
     cs->pOverlayWin = NULL;
 
     xfree (cs);
-    pScreen->devPrivates[CompScreenPrivateIndex].ptr = 0;
+    dixSetPrivate(DEVPRIV_PTR(pScreen), CompScreenPrivateKey, NULL);
     ret = (*pScreen->CloseScreen) (index, pScreen);
 
     return ret;
@@ -373,25 +375,6 @@ compScreenInit (ScreenPtr pScreen)
 {
     CompScreenPtr   cs;
 
-    if (CompGeneration != serverGeneration)
-    {
-	CompScreenPrivateIndex = AllocateScreenPrivateIndex ();
-	if (CompScreenPrivateIndex == -1)
-	    return FALSE;
-	CompWindowPrivateIndex = AllocateWindowPrivateIndex ();
-	if (CompWindowPrivateIndex == -1)
-	    return FALSE;
-	CompSubwindowsPrivateIndex = AllocateWindowPrivateIndex ();
-	if (CompSubwindowsPrivateIndex == -1)
-	    return FALSE;
-	CompGeneration = serverGeneration;
-    }
-    if (!AllocateWindowPrivate (pScreen, CompWindowPrivateIndex, 0))
-	return FALSE;
-
-    if (!AllocateWindowPrivate (pScreen, CompSubwindowsPrivateIndex, 0))
-	return FALSE;
-
     if (GetCompScreen (pScreen))
 	return TRUE;
     cs = (CompScreenPtr) xalloc (sizeof (CompScreenRec));
@@ -456,7 +439,7 @@ compScreenInit (ScreenPtr pScreen)
     cs->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = compCloseScreen;
 
-    pScreen->devPrivates[CompScreenPrivateIndex].ptr = (pointer) cs;
+    dixSetPrivate(DEVPRIV_PTR(pScreen), CompScreenPrivateKey, cs);
 
     RegisterRealChildHeadProc(CompositeRealChildHead);
 
diff --git a/composite/compint.h b/composite/compint.h
index 3958b3b..a504701 100644
--- a/composite/compint.h
+++ b/composite/compint.h
@@ -66,6 +66,7 @@
 #include "globals.h"
 #include "picturestr.h"
 #include "extnsionst.h"
+#include "privates.h"
 #include "mi.h"
 #include "damage.h"
 #include "damageextint.h"
@@ -156,13 +157,16 @@ typedef struct _CompScreen {
     
 } CompScreenRec, *CompScreenPtr;
 
-extern int  CompScreenPrivateIndex;
-extern int  CompWindowPrivateIndex;
-extern int  CompSubwindowsPrivateIndex;
+extern devprivate_key_t *const CompScreenPrivateKey;
+extern devprivate_key_t *const CompWindowPrivateKey;
+extern devprivate_key_t *const CompSubwindowsPrivateKey;
 
-#define GetCompScreen(s) ((CompScreenPtr) ((s)->devPrivates[CompScreenPrivateIndex].ptr))
-#define GetCompWindow(w) ((CompWindowPtr) ((w)->devPrivates[CompWindowPrivateIndex].ptr))
-#define GetCompSubwindows(w) ((CompSubwindowsPtr) ((w)->devPrivates[CompSubwindowsPrivateIndex].ptr))
+#define GetCompScreen(s) ((CompScreenPtr) \
+    dixLookupPrivate(DEVPRIV_PTR(s), CompScreenPrivateKey))
+#define GetCompWindow(w) ((CompWindowPtr) \
+    dixLookupPrivate(DEVPRIV_PTR(w), CompWindowPrivateKey))
+#define GetCompSubwindows(w) ((CompSubwindowsPtr) \
+    dixLookupPrivate(DEVPRIV_PTR(w), CompSubwindowsPrivateKey))
 
 extern RESTYPE		CompositeClientWindowType;
 extern RESTYPE		CompositeClientSubwindowsType;





More information about the xorg mailing list