[PATCH 1/5] panoramiX: consolidate common id assignment code.

Dave Airlie airlied at gmail.com
Tue Mar 8 21:29:49 PST 2011


From: Dave Airlie <airlied at redhat.com>

This adds a new FOR_NSCREENS_FORWARD_SKIP, which skips the first
element and is a common idiom throughout panoramiX code.

It then adds a new inline function to hide id assignment to a
panoramiX resource and cleans up lots of common repeated code.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 Xext/panoramiX.h      |    3 ++-
 Xext/panoramiXprocs.c |   20 +++++---------------
 Xext/panoramiXsrv.h   |   11 +++++++++++
 Xext/shm.c            |    4 +---
 composite/compext.c   |    5 +----
 render/render.c       |   25 +++++--------------------
 6 files changed, 25 insertions(+), 43 deletions(-)

diff --git a/Xext/panoramiX.h b/Xext/panoramiX.h
index a8684f0..fcfac0e 100644
--- a/Xext/panoramiX.h
+++ b/Xext/panoramiX.h
@@ -44,7 +44,7 @@ Equipment Corporation.
 #include <X11/extensions/panoramiXproto.h>
 #undef _PANORAMIX_SERVER
 #include "gcstruct.h"
-
+#include "dixstruct.h"
 
 typedef struct _PanoramiXInfo {
     XID id ;
@@ -70,6 +70,7 @@ typedef struct {
 } PanoramiXRes;
 
 #define FOR_NSCREENS_FORWARD(j) for(j = 0; j < PanoramiXNumScreens; j++)
+#define FOR_NSCREENS_FORWARD_SKIP(j) for(j = 1; j < PanoramiXNumScreens; j++)
 #define FOR_NSCREENS_BACKWARD(j) for(j = PanoramiXNumScreens - 1; j >= 0; j--)
 #define FOR_NSCREENS(j) FOR_NSCREENS_FORWARD(j)
 
diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index d843168..6c5c6e8 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -120,9 +120,7 @@ int PanoramiXCreateWindow(ClientPtr client)
     newWin->u.win.visibility = VisibilityNotViewable;
     newWin->u.win.class = stuff->class;
     newWin->u.win.root = FALSE;
-    newWin->info[0].id = stuff->wid;
-    for(j = 1; j < PanoramiXNumScreens; j++)
-        newWin->info[j].id = FakeClientID(client->index);
+    panoramix_setup_ids(newWin, client, stuff->wid);
 
     if (stuff->class == InputOnly)
 	stuff->visual = CopyFromParent;
@@ -663,9 +661,7 @@ int PanoramiXCreatePixmap(ClientPtr client)
 
     newPix->type = XRT_PIXMAP;
     newPix->u.pix.shared = FALSE;
-    newPix->info[0].id = stuff->pid;
-    for(j = 1; j < PanoramiXNumScreens; j++)
-	newPix->info[j].id = FakeClientID(client->index);
+    panoramix_setup_ids(newPix, client, stuff->pid);
    
     FOR_NSCREENS_BACKWARD(j) {
 	stuff->pid = newPix->info[j].id;
@@ -767,9 +763,7 @@ int PanoramiXCreateGC(ClientPtr client)
         return BadAlloc;
 
     newGC->type = XRT_GC;
-    newGC->info[0].id = stuff->gc;
-    for(j = 1; j < PanoramiXNumScreens; j++)
-        newGC->info[j].id = FakeClientID(client->index);
+    panoramix_setup_ids(newGC, client, stuff->gc);
 
     FOR_NSCREENS_BACKWARD(j) {
         stuff->gc = newGC->info[j].id;
@@ -2121,9 +2115,7 @@ int PanoramiXCreateColormap(ClientPtr client)
         return BadAlloc;
 
     newCmap->type = XRT_COLORMAP;
-    newCmap->info[0].id = stuff->mid;
-    for(j = 1; j < PanoramiXNumScreens; j++)
-        newCmap->info[j].id = FakeClientID(client->index);
+    panoramix_setup_ids(newCmap, client, stuff->mid);
 
     orig_visual = stuff->visual;
     FOR_NSCREENS_BACKWARD(j){
@@ -2192,9 +2184,7 @@ PanoramiXCopyColormapAndFree(ClientPtr client)
         return BadAlloc;
 
     newCmap->type = XRT_COLORMAP;
-    newCmap->info[0].id = stuff->mid;
-    for(j = 1; j < PanoramiXNumScreens; j++)
-        newCmap->info[j].id = FakeClientID(client->index);
+    panoramix_setup_ids(newCmap, client, stuff->mid);
 
     FOR_NSCREENS_BACKWARD(j){
         stuff->srcCmap = cmap->info[j].id;
diff --git a/Xext/panoramiXsrv.h b/Xext/panoramiXsrv.h
index b0a5a6e..5dd02e8 100644
--- a/Xext/panoramiXsrv.h
+++ b/Xext/panoramiXsrv.h
@@ -51,4 +51,15 @@ extern _X_EXPORT void XineramaGetImageData(
     Bool isRoot
 );
 
+static inline void panoramix_setup_ids(PanoramiXRes *resource, 
+                                       ClientPtr client, XID base_id)
+{
+    int j;
+
+    resource->info[0].id = base_id;
+    FOR_NSCREENS_FORWARD_SKIP(j) {
+        resource->info[j].id = FakeClientID(client->index);
+    }
+}
+
 #endif /* _PANORAMIXSRV_H_ */
diff --git a/Xext/shm.c b/Xext/shm.c
index 23afe6b..6294720 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -972,9 +972,7 @@ CreatePmap:
 
     newPix->type = XRT_PIXMAP;
     newPix->u.pix.shared = TRUE;
-    newPix->info[0].id = stuff->pid;
-    for(j = 1; j < PanoramiXNumScreens; j++)
-	newPix->info[j].id = FakeClientID(client->index);
+    panoramix_setup_ids(newPix, client, stuff->pid);
 
     result = Success;
 
diff --git a/composite/compext.c b/composite/compext.c
index fbd36b5..e0d8e75 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -703,10 +703,7 @@ PanoramiXCompositeNameWindowPixmap (ClientPtr client)
 
     newPix->type = XRT_PIXMAP;
     newPix->u.pix.shared = FALSE;
-    newPix->info[0].id = stuff->pixmap;
-
-    for (i = 1; i < PanoramiXNumScreens; i++)
-	newPix->info[i].id = FakeClientID (client->index);
+    panoramix_setup_ids(newPix, client, stuff->pixmap);
 
     FOR_NSCREENS(i) {
 	rc = dixLookupResourceByType ((void **) &pWin, win->info[i].id,
diff --git a/render/render.c b/render/render.c
index 7029558..3cb1b54 100644
--- a/render/render.c
+++ b/render/render.c
@@ -2690,7 +2690,7 @@ PanoramiXRenderCreatePicture (ClientPtr client)
     if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes))))
 	return BadAlloc;
     newPict->type = XRT_PICTURE;
-    newPict->info[0].id = stuff->pid;
+    panoramix_setup_ids(newPict, client, stuff->pid);
     
     if (refDraw->type == XRT_WINDOW &&
 	stuff->drawable == screenInfo.screens[0]->root->drawable.id)
@@ -2699,9 +2699,6 @@ PanoramiXRenderCreatePicture (ClientPtr client)
     }
     else
 	newPict->u.pict.root = FALSE;
-
-    for(j = 1; j < PanoramiXNumScreens; j++)
-	newPict->info[j].id = FakeClientID(client->index);
     
     FOR_NSCREENS_BACKWARD(j) {
 	stuff->pid = newPict->info[j].id;
@@ -3225,11 +3222,8 @@ PanoramiXRenderCreateSolidFill (ClientPtr client)
 	return BadAlloc;
 
     newPict->type = XRT_PICTURE;
-    newPict->info[0].id = stuff->pid;
+    panoramix_setup_ids(newPict, client, stuff->pid);
     newPict->u.pict.root = FALSE;
-
-    for(j = 1; j < PanoramiXNumScreens; j++)
-	newPict->info[j].id = FakeClientID(client->index);
 	
     FOR_NSCREENS_BACKWARD(j) {
 	stuff->pid = newPict->info[j].id;
@@ -3258,12 +3252,9 @@ PanoramiXRenderCreateLinearGradient (ClientPtr client)
 	return BadAlloc;
 
     newPict->type = XRT_PICTURE;
-    newPict->info[0].id = stuff->pid;
+    panoramix_setup_ids(newPict, client, stuff->pid);
     newPict->u.pict.root = FALSE;
 
-    for(j = 1; j < PanoramiXNumScreens; j++)
-	newPict->info[j].id = FakeClientID(client->index);
-
     FOR_NSCREENS_BACKWARD(j) {
 	stuff->pid = newPict->info[j].id;
 	result = (*PanoramiXSaveRenderVector[X_RenderCreateLinearGradient]) (client);
@@ -3291,12 +3282,9 @@ PanoramiXRenderCreateRadialGradient (ClientPtr client)
 	return BadAlloc;
 
     newPict->type = XRT_PICTURE;
-    newPict->info[0].id = stuff->pid;
+    panoramix_setup_ids(newPict, client, stuff->pid);
     newPict->u.pict.root = FALSE;
 
-    for(j = 1; j < PanoramiXNumScreens; j++)
-	newPict->info[j].id = FakeClientID(client->index);
-
     FOR_NSCREENS_BACKWARD(j) {
 	stuff->pid = newPict->info[j].id;
 	result = (*PanoramiXSaveRenderVector[X_RenderCreateRadialGradient]) (client);
@@ -3324,12 +3312,9 @@ PanoramiXRenderCreateConicalGradient (ClientPtr client)
 	return BadAlloc;
 
     newPict->type = XRT_PICTURE;
-    newPict->info[0].id = stuff->pid;
+    panoramix_setup_ids(newPict, client, stuff->pid);
     newPict->u.pict.root = FALSE;
 
-    for(j = 1; j < PanoramiXNumScreens; j++)
-	newPict->info[j].id = FakeClientID(client->index);
-
     FOR_NSCREENS_BACKWARD(j) {
 	stuff->pid = newPict->info[j].id;
 	result = (*PanoramiXSaveRenderVector[X_RenderCreateConicalGradient]) (client);
-- 
1.7.3.4



More information about the xorg-devel mailing list