[Xquartz-changes] xserver: Branch 'server-1.9-apple' - 32 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Mon Jun 7 11:22:19 PDT 2010


Rebased ref, commits from common ancestor:
commit 7a983fb7cdafb1c88766a38a143f04da6db53713
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Feb 12 19:48:52 2010 -0800

    fb: Revert fb changes that broke XQuartz
    
    http://bugs.freedesktop.org/show_bug.cgi?id=26124
    
    Revert "Fix source pictures getting random transforms after 2d6a8f668342a5190cdf43b5."
    Revert "fb: Adjust transform or composite coordinates for pixman operations"
    
    http://bugs.freedesktop.org/26124
    
    This reverts commit a72c65e9176c51de95db2fdbf4c5d946a4911695.
    This reverts commit a6bd5d2e482a5aa84acb3d4932e2a166d8670ef1.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/fb/fb.h b/fb/fb.h
index a06f98b..3b9efea 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -2080,11 +2080,8 @@ fbFillRegionSolid (DrawablePtr	pDrawable,
 		   FbBits	xor);
 
 extern _X_EXPORT pixman_image_t *
-image_from_pict (PicturePtr	pict,
-		 Bool		has_clip,
-		 int		*xoff,
-		 int		*yoff);
-
+image_from_pict (PicturePtr pict,
+		 Bool       has_clip);
 extern _X_EXPORT void free_pixman_pict (PicturePtr, pixman_image_t *);
 
 #endif /* _FB_H_ */
diff --git a/fb/fbpict.c b/fb/fbpict.c
index 26cdc0d..f2ddb63 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -156,24 +156,19 @@ fbComposite (CARD8      op,
 	     CARD16     height)
 {
     pixman_image_t *src, *mask, *dest;
-    int src_xoff, src_yoff;
-    int msk_xoff, msk_yoff;
-    int dst_xoff, dst_yoff;
     
     miCompositeSourceValidate (pSrc, xSrc - xDst, ySrc - yDst, width, height);
     if (pMask)
 	miCompositeSourceValidate (pMask, xMask - xDst, yMask - yDst, width, height);
     
-    src = image_from_pict (pSrc, FALSE, &src_xoff, &src_yoff);
-    mask = image_from_pict (pMask, FALSE, &msk_xoff, &msk_yoff);
-    dest = image_from_pict (pDst, TRUE, &dst_xoff, &dst_yoff);
+    src = image_from_pict (pSrc, TRUE);
+    mask = image_from_pict (pMask, TRUE);
+    dest = image_from_pict (pDst, TRUE);
 
     if (src && dest && !(pMask && !mask))
     {
 	pixman_image_composite (op, src, mask, dest,
-				xSrc + src_xoff, ySrc + src_yoff,
-				xMask + msk_xoff, yMask + msk_yoff,
-				xDst + dst_xoff, yDst + dst_yoff,
+				xSrc, ySrc, xMask, yMask, xDst, yDst,
 				width, height);
     }
 
@@ -271,22 +266,22 @@ create_conical_gradient_image (PictGradient *gradient)
 
 static pixman_image_t *
 create_bits_picture (PicturePtr pict,
-		     Bool       has_clip,
-		     int	*xoff,
-		     int	*yoff)
+		     Bool       has_clip)
 {
-    PixmapPtr pixmap;
     FbBits *bits;
     FbStride stride;
-    int bpp;
+    int bpp, xoff, yoff;
     pixman_image_t *image;
     
-    fbGetDrawablePixmap (pict->pDrawable, pixmap, *xoff, *yoff);
-    fbGetPixmapBitsData(pixmap, bits, stride, bpp);
+    fbGetDrawable (pict->pDrawable, bits, stride, bpp, xoff, yoff);
+
+    bits = (FbBits*)((CARD8*)bits +
+		     (pict->pDrawable->y + yoff) * stride * sizeof(FbBits) +
+		     (pict->pDrawable->x + xoff) * (bpp / 8));
 
     image = pixman_image_create_bits (
 	pict->format,
-	pixmap->drawable.width, pixmap->drawable.height,
+	pict->pDrawable->width, pict->pDrawable->height,
 	(uint32_t *)bits, stride * sizeof (FbStride));
     
     
@@ -312,52 +307,30 @@ create_bits_picture (PicturePtr pict,
 	if (pict->clientClipType != CT_NONE)
 	    pixman_image_set_has_client_clip (image, TRUE);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, *xoff, *yoff);
+	pixman_region_translate (pict->pCompositeClip, - pict->pDrawable->x, - pict->pDrawable->y);
 
 	pixman_image_set_clip_region (image, pict->pCompositeClip);
 
-	if (*xoff || *yoff)
-	    pixman_region_translate (pict->pCompositeClip, -*xoff, -*yoff);
+	pixman_region_translate (pict->pCompositeClip, pict->pDrawable->x, pict->pDrawable->y);
     }
     
     /* Indexed table */
     if (pict->pFormat->index.devPrivate)
 	pixman_image_set_indexed (image, pict->pFormat->index.devPrivate);
 
-    /* Add in drawable origin to position within the image */
-    *xoff += pict->pDrawable->x;
-    *yoff += pict->pDrawable->y;
-
     return image;
 }
 
 static void
-set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+set_image_properties (pixman_image_t *image, PicturePtr pict)
 {
     pixman_repeat_t repeat;
     pixman_filter_t filter;
     
     if (pict->transform)
     {
-	/* For source images, adjust the transform to account
-	 * for the drawable offset within the pixman image,
-	 * then set the offset to 0 as it will be used
-	 * to compute positions within the transformed image.
-	 */
-	if (!has_clip) {
-	    struct pixman_transform	adjusted;
-
-	    adjusted = *pict->transform;
-	    pixman_transform_translate(&adjusted,
-				       NULL,
-				       pixman_int_to_fixed(*xoff),
-				       pixman_int_to_fixed(*yoff));
-	    pixman_image_set_transform (image, &adjusted);
-	    *xoff = 0;
-	    *yoff = 0;
-	} else
-	    pixman_image_set_transform (image, pict->transform);
+	pixman_image_set_transform (
+	    image, (pixman_transform_t *)pict->transform);
     }
     
     switch (pict->repeatType)
@@ -384,8 +357,7 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
     
     if (pict->alphaMap)
     {
-	int alpha_xoff, alpha_yoff;
-	pixman_image_t *alpha_map = image_from_pict (pict->alphaMap, FALSE, &alpha_xoff, &alpha_yoff);
+	pixman_image_t *alpha_map = image_from_pict (pict->alphaMap, TRUE);
 	
 	pixman_image_set_alpha_map (
 	    image, alpha_map, pict->alphaOrigin.x, pict->alphaOrigin.y);
@@ -418,7 +390,8 @@ set_image_properties (pixman_image_t *image, PicturePtr pict, Bool has_clip, int
 }
 
 pixman_image_t *
-image_from_pict (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+image_from_pict (PicturePtr pict,
+		 Bool has_clip)
 {
     pixman_image_t *image = NULL;
 
@@ -427,7 +400,7 @@ image_from_pict (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
 
     if (pict->pDrawable)
     {
-	image = create_bits_picture (pict, has_clip, xoff, yoff);
+	image = create_bits_picture (pict, has_clip);
     }
     else if (pict->pSourcePict)
     {
@@ -448,11 +421,10 @@ image_from_pict (PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
 	    else if (sp->type == SourcePictTypeConical)
 		image = create_conical_gradient_image (gradient);
 	}
-	*xoff = *yoff = 0;
     }
     
     if (image)
-	set_image_properties (image, pict, has_clip, xoff, yoff);
+	set_image_properties (image, pict);
     
     return image;
 }
diff --git a/fb/fbtrap.c b/fb/fbtrap.c
index 9f5c39f..9c55236 100644
--- a/fb/fbtrap.c
+++ b/fb/fbtrap.c
@@ -38,8 +38,7 @@ fbAddTraps (PicturePtr	pPicture,
 	    int		ntrap,
 	    xTrap	*traps)
 {
-    int image_xoff, image_yoff;
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, &image_xoff, &image_yoff);
+    pixman_image_t *image = image_from_pict (pPicture, FALSE);
 
     if (!image)
 	return;
@@ -55,8 +54,7 @@ fbRasterizeTrapezoid (PicturePtr    pPicture,
 		      int	    x_off,
 		      int	    y_off)
 {
-    int	mask_xoff, mask_yoff;
-    pixman_image_t *image = image_from_pict (pPicture, FALSE, &mask_xoff, &mask_yoff);
+    pixman_image_t *image = image_from_pict (pPicture, FALSE);
 
     if (!image)
 	return;
commit a4dadc1b2da128a6ce05e3557ac585f7ae961dc7
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 30 13:08:25 2010 -0700

    Workaround the GC clipping problem in miPaintWindow and add some debugging output.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/mi/miexpose.c b/mi/miexpose.c
index 94258b8..4f25c23 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -521,6 +521,7 @@ void RootlessSetPixmapOfAncestors(WindowPtr pWin);
 void RootlessStartDrawing(WindowPtr pWin);
 void RootlessDamageRegion(WindowPtr pWin, RegionPtr prgn);
 Bool IsFramedWindow(WindowPtr pWin);
+#include "../fb/fb.h"
 #endif 
 
 void
@@ -548,24 +549,37 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     Bool	solid = TRUE;
     DrawablePtr	drawable = &pWin->drawable;
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("START %d BS %d (pR = %ld)\n", what, pWin->backgroundState, ParentRelative);
+    ErrorF("      Rgn: %d %d %d %d\n", prgn->extents.x1, prgn->extents.y1,
+	                               prgn->extents.x2 - prgn->extents.x1,
+	                               prgn->extents.y2 - prgn->extents.y1);
+    ErrorF("      Win: %d %d (%d %d) %d %d\n", pWin->origin.x, pWin->origin.y,
+	                                       pWin->winSize.extents.x1, pWin->winSize.extents.y1,
+	                                       pWin->winSize.extents.x2 - pWin->winSize.extents.x1,
+					       pWin->winSize.extents.y2 - pWin->winSize.extents.y1);
+    ErrorF("     Draw: %d %d %d %d\n", pWin->drawable.x, pWin->drawable.y,
+				       pWin->drawable.width, pWin->drawable.height);
+#endif
+
 #ifdef ROOTLESS
     if(!drawable || drawable->type == UNDRAWABLE_WINDOW)
 	return;
-
-    if(IsFramedWindow(pWin)) {
-        RootlessStartDrawing(pWin);
-        RootlessDamageRegion(pWin, prgn);
-    
-        if(pWin->backgroundState == ParentRelative) {
-            if((what == PW_BACKGROUND) || 
-               (what == PW_BORDER && !pWin->borderIsPixel))
-                RootlessSetPixmapOfAncestors(pWin);
-        }
-    }
 #endif
     
     if (what == PW_BACKGROUND)
     {
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+
+	    if(pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	while (pWin->backgroundState == ParentRelative)
 	    pWin = pWin->parent;
 
@@ -587,6 +601,18 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     {
 	PixmapPtr   pixmap;
 
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+	    
+	    if(!pWin->borderIsPixel &&
+		pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
 	tile_x_off = drawable->x;
 	tile_y_off = drawable->y;
 	
@@ -595,6 +621,12 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
 	    return;
 	pixmap = (*pScreen->GetWindowPixmap) ((WindowPtr) drawable);
 	drawable = &pixmap->drawable;
+
+#ifdef XQUARTZ_CLIP_DEBUG
+	ErrorF("     Draw: %d %d %d %d\n",
+	       drawable->x, drawable->y, drawable->width, drawable->height);    
+#endif
+	
 #ifdef COMPOSITE
 	draw_x_off = pixmap->screen_x;
 	draw_y_off = pixmap->screen_y;
@@ -657,6 +689,57 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     ChangeGC (NullClient, pGC, gcmask, gcval);
     ValidateGC (drawable, pGC);
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);
+#endif
+    
+#ifdef XQUARTZ
+    /* Looks like our clipping isn't set right for some reason:
+     * http://xquartz.macosforge.org/trac/ticket/290
+     */
+    if(what == PW_BORDER) {
+
+#if 0
+	if(solid) {
+#if 1
+	    fbFillRegionSolid(&pWin->drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       pWin->drawable.bitsPerPixel));
+#else
+	    fbFillRegionSolid(drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       drawable->bitsPerPixel));
+#endif
+	    return;
+	}
+#endif
+    
+	pGC->pCompositeClip->extents.x1 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y1 += prgn->extents.y1;
+	pGC->pCompositeClip->extents.x2 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y2 += prgn->extents.y1;
+	
+	if(pGC->pCompositeClip->extents.x2 > drawable->pScreen->width)
+	    pGC->pCompositeClip->extents.x2 = drawable->pScreen->width;
+	if(pGC->pCompositeClip->extents.y2 > drawable->pScreen->height)
+	    pGC->pCompositeClip->extents.y2 = drawable->pScreen->height;
+    }
+#endif
+
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);    
+#endif
+
     numRects = RegionNumRects(prgn);
     pbox = RegionRects(prgn);
     for (i= numRects; --i >= 0; pbox++, prect++)
commit d4cc799d506f3a68df3142f82ca69941f6d0f3bd
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sun Jun 6 16:31:19 2010 -0700

    XQuartz: Fix build regression from faeebead7bfcc78535757ca7acc1faf7554c03b7
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/xpr/dri.c b/hw/xquartz/xpr/dri.c
index 72a7ecf..aa5687b 100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@ -205,14 +205,14 @@ DRIScreenInit(ScreenPtr pScreen)
     DRIScreenPrivPtr    pDRIPriv;
     int                 i;
 
-    if (!dixRegisterPrivateKey(&DRIScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
-	return FALSE:
-    if (!dixRegisterPrivateKey(&DRIWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
-	return FALSE:
-    if (!dixRegisterPrivateKey(&DRIPixmapPrivateKeyRec, PRIVATE_PIXMAP, 0))
-	return FALSE:
-    if (!dixRegisterPrivateKey(&DRIPixmapBufferPrivateKeyRec, PRIVATE_PIXMAP, 0))
-	return FALSE:
+    if (!dixRegisterPrivateKey(&DRIScreenPrivKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&DRIWindowPrivKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&DRIPixmapPrivKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&DRIPixmapBufferPrivKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE;
 
     pDRIPriv = (DRIScreenPrivPtr) calloc(1, sizeof(DRIScreenPrivRec));
     if (!pDRIPriv) {
diff --git a/hw/xquartz/xpr/driWrap.c b/hw/xquartz/xpr/driWrap.c
index efbae3c..65843b8 100644
--- a/hw/xquartz/xpr/driWrap.c
+++ b/hw/xquartz/xpr/driWrap.c
@@ -530,18 +530,12 @@ DRIWrapInit(ScreenPtr pScreen) {
     if(!dixRegisterPrivateKey(&driGCKeyRec, PRIVATE_GC, sizeof(DRIGCRec)))
 	return FALSE;
 
-    if(!dixRegisterPrivateKey(&driWrapScreenKeyRec, PRIVATE_WINDOW, sizeof(DRIWrapScreenRec)))
-	return FALSE;
-    
-    pScreenPriv = malloc(sizeof(*pScreenPriv));
-
-    if(NULL == pScreenPriv)
+    if(!dixRegisterPrivateKey(&driWrapScreenKeyRec, PRIVATE_SCREEN, sizeof(DRIWrapScreenRec)))
 	return FALSE;
 
+    pScreenPriv = dixGetPrivateAddr(&pScreen->devPrivates, &driWrapScreenKeyRec);
     pScreenPriv->CreateGC = pScreen->CreateGC;
     pScreen->CreateGC = DRICreateGC;
     
-    dixSetPrivate(&pScreen->devPrivates, driWrapScreenKey, pScreenPriv);
-        
     return TRUE;
 }
diff --git a/hw/xquartz/xpr/xprCursor.c b/hw/xquartz/xpr/xprCursor.c
index c268c2c..67fcbe7 100644
--- a/hw/xquartz/xpr/xprCursor.c
+++ b/hw/xquartz/xpr/xprCursor.c
@@ -58,7 +58,7 @@ typedef struct {
 } QuartzCursorScreenRec, *QuartzCursorScreenPtr;
 
 static DevPrivateKeyRec darwinCursorScreenKeyRec;
-#define darwinCursorScreenKey (&darwinCursorScreenKey)
+#define darwinCursorScreenKey (&darwinCursorScreenKeyRec)
 
 #define CURSOR_PRIV(pScreen) ((QuartzCursorScreenPtr) \
     dixLookupPrivate(&pScreen->devPrivates, darwinCursorScreenKey))
@@ -359,7 +359,7 @@ QuartzInitCursor(ScreenPtr pScreen)
     if (!miDCInitialize(pScreen, &quartzScreenFuncsRec))
         return FALSE;
 
-    if (!dixRegisterPrivate(&darwinCursorScreenKeyRec, PRIVATE_SCREEN, 0))
+    if (!dixRegisterPrivateKey(&darwinCursorScreenKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
     ScreenPriv = calloc(1, sizeof(QuartzCursorScreenRec));
commit bc26665661565918af484ccd17caad951010df60
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Jun 6 20:45:53 2010 -0700

    Initialize private keys in test suite
    
    Make sure all of the private keys used by the test code are
    initialized before being used.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Tested-by: Robert Hooker <sarvatt at ubuntu.com>

diff --git a/Xext/xtest.c b/Xext/xtest.c
index 0a6b1c5..6ee8430 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -99,10 +99,16 @@ static DISPATCH_PROC(SProcXTestFakeInput);
 static DISPATCH_PROC(SProcXTestGetVersion);
 static DISPATCH_PROC(SProcXTestGrabControl);
 
+Bool
+XTestInitPrivates(void)
+{
+    return dixRegisterPrivateKey(&XTestDevicePrivateKeyRec, PRIVATE_DEVICE, 0);
+}
+
 void
 XTestExtensionInit(INITARGS)
 {
-    if (!dixRegisterPrivateKey(&XTestDevicePrivateKeyRec, PRIVATE_DEVICE, 0))
+    if (!XTestInitPrivates())
 	return;
 
     AddExtension(XTestExtensionName, 0, 0,
diff --git a/include/input.h b/include/input.h
index c68a284..3b29855 100644
--- a/include/input.h
+++ b/include/input.h
@@ -237,6 +237,7 @@ extern int key_is_down(DeviceIntPtr pDev, int key_code, int type);
 
 extern void InitCoreDevices(void);
 extern void InitXTestDevices(void);
+extern Bool XTestInitPrivates(void);
 
 extern _X_EXPORT DeviceIntPtr AddInputDevice(
     ClientPtr /*client*/,
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index 7c92f64..5847e63 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -321,6 +321,8 @@ extern _X_EXPORT int XkbProcessArguments(
     int				/* i */
 );
 
+extern _X_EXPORT Bool   XkbInitPrivates(void);
+
 extern _X_EXPORT void	XkbSetExtension(DeviceIntPtr device, ProcessInputProc proc);
 
 extern _X_EXPORT void	XkbFreeCompatMap(
diff --git a/test/xi2/protocol-common.c b/test/xi2/protocol-common.c
index fd93e15..ad18042 100644
--- a/test/xi2/protocol-common.c
+++ b/test/xi2/protocol-common.c
@@ -27,6 +27,7 @@
 
 #include <stdint.h>
 #include "extinit.h" /* for XInputExtensionInit */
+#include "exglobals.h"
 #include <glib.h>
 
 #include "protocol-common.h"
@@ -107,7 +108,6 @@ ClientRec init_client(int len, void *data)
     /* we store the privates now and reassign it after the memset. this way
      * we can share them across multiple test runs and don't have to worry
      * about freeing them after each test run. */
-    PrivateRec *privates = client.devPrivates;
 
     client.index = CLIENT_INDEX;
     client.clientAsMask = CLIENT_MASK;
@@ -115,7 +115,7 @@ ClientRec init_client(int len, void *data)
     client.req_len = len;
 
     client.requestBuffer = data;
-    client.devPrivates = privates;
+    dixAllocatePrivates(&client.devPrivates, PRIVATE_CLIENT);
     return client;
 }
 
@@ -136,6 +136,9 @@ void init_window(WindowPtr window, WindowPtr parent, int id)
     g_assert(window->optional);
 }
 
+extern DevPrivateKeyRec miPointerScreenKeyRec;
+extern DevPrivateKeyRec miPointerPrivKeyRec;
+
 /* Needed for the screen setup, otherwise we crash during sprite initialization */
 static Bool device_cursor_init(DeviceIntPtr dev, ScreenPtr screen) { return TRUE; }
 static Bool set_cursor_pos(DeviceIntPtr dev, ScreenPtr screen, int x, int y, Bool event) { return TRUE; }
@@ -153,7 +156,13 @@ void init_simple(void)
 
     dixResetPrivates();
     InitAtoms();
+    XkbInitPrivates();
+    XTestInitPrivates();
+    dixRegisterPrivateKey(&XIClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XIClientRec));
+    dixRegisterPrivateKey(&miPointerScreenKeyRec, PRIVATE_SCREEN, 0);
+    dixRegisterPrivateKey(&miPointerPrivKeyRec, PRIVATE_DEVICE, 0);
     XInputExtensionInit();
+
     init_window(&root, NULL, ROOT_WINDOW_ID);
     init_window(&window, &root, CLIENT_WINDOW_ID);
 
diff --git a/test/xtest.c b/test/xtest.c
index cc1188d..af75f0c 100644
--- a/test/xtest.c
+++ b/test/xtest.c
@@ -30,6 +30,7 @@
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "exevents.h"
+#include "xkbsrv.h"
 #include "xserver-properties.h"
 
 #include <glib.h>
@@ -59,6 +60,9 @@ static void xtest_init_devices(void)
     dixResetPrivates();
     InitAtoms();
 
+    XkbInitPrivates();
+    XTestInitPrivates();
+
     /* this also inits the xtest devices */
     InitCoreDevices();
 
diff --git a/xkb/xkb.c b/xkb/xkb.c
index 04a137f..cbb46c6 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -6707,7 +6707,7 @@ XkbExtensionInit(void)
     if (!RT_XKBCLIENT)
 	return;
 
-    if (!dixRegisterPrivateKey(&xkbDevicePrivateKeyRec, PRIVATE_DEVICE, 0))
+    if (!XkbInitPrivates())
 	return;
 
     if ((extEntry = AddExtension(XkbName, XkbNumberEvents, XkbNumberErrors,
diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c
index afc44ac..c5030d0 100644
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@ -63,6 +63,11 @@ xkbUnwrapProc(DeviceIntPtr device, DeviceHandleProc proc,
 				 backupproc,xkbUnwrapProc);
 }
 
+Bool
+XkbInitPrivates(void)
+{
+    return dixRegisterPrivateKey(&xkbDevicePrivateKeyRec, PRIVATE_DEVICE, 0);
+}
 
 void
 XkbSetExtension(DeviceIntPtr device, ProcessInputProc proc)
commit f03be727d647183a2176355ad0ac9a6735067be9
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Jun 6 16:04:42 2010 -0700

    Place glyph privates at correct location within the allocate storage
    
    A glyph allocation consists of :
    
      GlyphRec
      numScreens * PicturePtr
      glyph privates
    
    Tell the dix private bits to start past the picture pointers.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/render/glyph.c b/render/glyph.c
index 948a20a..7193d47 100644
--- a/render/glyph.c
+++ b/render/glyph.c
@@ -368,8 +368,6 @@ FindGlyph (GlyphSetPtr glyphSet, Glyph id)
     return glyph;
 }
 
-#define GLYPH_SIZE	(sizeof (GlyphRec) + dixPrivatesSize(PRIVATE_GLYPH))
-
 GlyphPtr
 AllocateGlyph (xGlyphInfo *gi, int fdepth)
 {
@@ -377,15 +375,17 @@ AllocateGlyph (xGlyphInfo *gi, int fdepth)
     int		     size;
     GlyphPtr	     glyph;
     int		     i;
+    int		     head_size;
 
-    size = screenInfo.numScreens * sizeof (PicturePtr);
-    glyph = (GlyphPtr) malloc (size + GLYPH_SIZE);
+    head_size = sizeof (GlyphRec) + screenInfo.numScreens * sizeof (PicturePtr);
+    size = (head_size + dixPrivatesSize(PRIVATE_GLYPH));
+    glyph = (GlyphPtr) malloc (size);
     if (!glyph)
 	return 0;
     glyph->refcnt = 0;
     glyph->size = size + sizeof (xGlyphInfo);
     glyph->info = *gi;
-    dixInitPrivates(glyph, glyph + 1, PRIVATE_GLYPH);
+    dixInitPrivates(glyph, (char *) glyph + head_size, PRIVATE_GLYPH);
 
     for (i = 0; i < screenInfo.numScreens; i++)
     {
commit 67b824a81bb8254827023de351a4a094031f0e94
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sun Jun 6 20:37:07 2010 +0700

    randr: Make deletion of output properties more robust
    
    Previously there was two branches of code with small discrepancies between them
    (especially prop->valid_values field was not free(3)ed). Extract the common
    routine and fix double-free prop->valid_values in RRDestroyOutputProperty by
    the way.
    
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index a4402e1..481eb86 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -53,25 +53,39 @@ static void RRDeliverPropertyEvent(ScreenPtr pScreen, xEvent *event)
 	WalkTree(pScreen, DeliverPropertyEvent, event);
 }
 
+static void
+RRDestroyOutputProperty (RRPropertyPtr prop)
+{
+    free(prop->valid_values);
+    free(prop->current.data);
+    free(prop->pending.data);
+    free(prop);
+}
+
+static void
+RRDeleteProperty(RROutputRec *output, RRPropertyRec *prop)
+{
+    xRROutputPropertyNotifyEvent event;
+    event.type = RREventBase + RRNotify;
+    event.subCode = RRNotify_OutputProperty;
+    event.output = output->id;
+    event.state = PropertyDelete;
+    event.atom = prop->propertyName;
+    event.timestamp = currentTime.milliseconds;
+
+    RRDeliverPropertyEvent(output->pScreen, (xEvent *)&event);
+
+    RRDestroyOutputProperty(prop);
+}
+
 void
-RRDeleteAllOutputProperties (RROutputPtr output)
+RRDeleteAllOutputProperties(RROutputPtr output)
 {
     RRPropertyPtr prop, next;
-    xRROutputPropertyNotifyEvent    event;
 
-    for (prop = output->properties; prop; prop = next)
-    {
+    for (prop = output->properties; prop; prop = next) {
 	next = prop->next;
-	event.type = RREventBase + RRNotify;
-	event.subCode = RRNotify_OutputProperty;
-	event.output = output->id;
-	event.state = PropertyDelete;
-	event.atom = prop->propertyName;
-	event.timestamp = currentTime.milliseconds;
-	RRDeliverPropertyEvent (output->pScreen, (xEvent *)&event);
-	free(prop->current.data);
-	free(prop->pending.data);
-	free(prop);
+        RRDeleteProperty(output, prop);
     }
 }
 
@@ -104,37 +118,17 @@ RRCreateOutputProperty (Atom property)
     return prop;
 }
 
-static void
-RRDestroyOutputProperty (RRPropertyPtr prop)
-{
-    free(prop->valid_values);
-    free(prop->current.data);
-    free(prop->pending.data);
-    free(prop->valid_values);
-    free(prop);
-}
-
 void
-RRDeleteOutputProperty (RROutputPtr output, Atom property)
+RRDeleteOutputProperty(RROutputPtr output, Atom property)
 {
-    RRPropertyPtr	prop, *prev;
-    xRROutputPropertyNotifyEvent    event;
+    RRPropertyRec *prop, **prev;
 
     for (prev = &output->properties; (prop = *prev); prev = &(prop->next))
-	if (prop->propertyName == property)
-	    break;
-    if (prop)
-    {
-	*prev = prop->next;
-	event.type = RREventBase + RRNotify;
-	event.subCode = RRNotify_OutputProperty;
-	event.output = output->id;
-	event.state = PropertyDelete;
-	event.atom = prop->propertyName;
-	event.timestamp = currentTime.milliseconds;
-	RRDeliverPropertyEvent (output->pScreen, (xEvent *)&event);
-	RRDestroyOutputProperty (prop);
-    }
+	if (prop->propertyName == property) {
+            *prev = prop->next;
+            RRDeleteProperty(output, prop);
+            return;
+        }
 }
 
 int
commit 0a4d8cbdcd7b25313fb29ccdb498044af95f7de6
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Sun Jun 6 15:28:30 2010 +0700

    Remove more superfluous if(p) checks around free(p)
    
    This patch has been generated by the following Coccinelle semantic patch:
    
    @@
    expression E;
    @@
    
    -if(E) { free(E); }
    +free(E);
    
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Fernando Carrijo <fcarrijo at yahoo.com.br>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 1cb58b5..27ca01f 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -1276,8 +1276,7 @@ XineramaGetImageData(
 	
     }
 
-    if(ScratchMem)
-	free(ScratchMem);
+    free(ScratchMem);
 
     RegionUninit(&SrcRegion);
     RegionUninit(&GrabRegion);
diff --git a/Xext/security.c b/Xext/security.c
index 12210f8..9ef6d19 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -604,7 +604,7 @@ bailout:
     if (removeAuth)
 	RemoveAuthorization(stuff->nbytesAuthProto, protoname,
 			    authdata_len, pAuthdata);
-    if (pAuth) free(pAuth);
+    free(pAuth);
     return err;
 
 } /* ProcSecurityGenerateAuthorization */
diff --git a/Xext/xace.c b/Xext/xace.c
index abd4690..e10d837 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -323,7 +323,7 @@ XaceCensorImage(
 	     */
 	    memset(pBuf, 0, (int)(widthBytesLine * h));
 	}
-	if (pRects)     free(pRects);
+	free(pRects);
 	if (pScratchGC) FreeScratchGC(pScratchGC);
 	if (pPix)       FreeScratchPixmapHeader(pPix);
     }
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 982fad1..8fbdfae 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -259,8 +259,7 @@ ProcXvMCCreateContext(ClientPtr client)
       WriteToClient(client, dwords << 2, (char*)data); 
     AddResource(pContext->context_id, XvMCRTContext, pContext);
 
-    if(data)
-	free(data);
+    free(data);
 
     return Success;
 }
@@ -327,8 +326,7 @@ ProcXvMCCreateSurface(ClientPtr client)
       WriteToClient(client, dwords << 2, (char*)data);
     AddResource(pSurface->surface_id, XvMCRTSurface, pSurface);
 
-    if(data)
-        free(data);
+    free(data);
 
     pContext->refcnt++;
 
@@ -444,8 +442,7 @@ ProcXvMCCreateSubpicture(ClientPtr client)
       WriteToClient(client, dwords << 2, (char*)data);
     AddResource(pSubpicture->subpicture_id, XvMCRTSubpicture, pSubpicture);
 
-    if(data)
-        free(data);
+    free(data);
 
     pContext->refcnt++;
 
diff --git a/Xi/gtmotion.c b/Xi/gtmotion.c
index 32d80ee..9132f4f 100644
--- a/Xi/gtmotion.c
+++ b/Xi/gtmotion.c
@@ -153,8 +153,7 @@ ProcXGetDeviceMotionEvents(ClientPtr client)
 	}
 	WriteToClient(client, length * 4, (char *)coords);
     }
-    if (coords)
-	free(coords);
+    free(coords);
     return Success;
 }
 
diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index b4d939f..c1839aa 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -622,8 +622,7 @@ XIFetchDeviceProperty(DeviceIntPtr dev, Atom property)
 static void
 XIDestroyDeviceProperty (XIPropertyPtr prop)
 {
-    if (prop->value.data)
-        free(prop->value.data);
+    free(prop->value.data);
     free(prop);
 }
 
@@ -798,8 +797,7 @@ XIChangeDeviceProperty (DeviceIntPtr dev, Atom property, Atom type,
                                 &new_value, checkonly);
                         if (checkonly && rc != Success)
                         {
-                            if (new_value.data)
-                                free(new_value.data);
+                            free(new_value.data);
                             return (rc);
                         }
                     }
@@ -808,8 +806,7 @@ XIChangeDeviceProperty (DeviceIntPtr dev, Atom property, Atom type,
                 checkonly = !checkonly;
             } while (!checkonly);
         }
-        if (prop_value->data)
-            free(prop_value->data);
+        free(prop_value->data);
         *prop_value = new_value;
     } else if (len == 0)
     {
diff --git a/config/dbus.c b/config/dbus.c
index 72a0a05..4888f62 100644
--- a/config/dbus.c
+++ b/config/dbus.c
@@ -184,10 +184,8 @@ unwind:
     while (options) {
         tmpo = options;
         options = options->next;
-        if (tmpo->key)
-            free(tmpo->key);
-        if (tmpo->value)
-            free(tmpo->value);
+        free(tmpo->key);
+        free(tmpo->value);
         free(tmpo);
     }
 
diff --git a/config/hal.c b/config/hal.c
index 6a22323..5938d4e 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -251,28 +251,23 @@ device_added(LibHalContext *hal_ctx, const char *udi)
                     {
                         if (!strcasecmp(&tmp[3], "layout"))
                         {
-                            if (xkb_opts.layout)
-                                free(xkb_opts.layout);
+                            free(xkb_opts.layout);
                             xkb_opts.layout = strdup(tmp_val);
                         } else if (!strcasecmp(&tmp[3], "model"))
                         {
-                            if (xkb_opts.model)
-                                free(xkb_opts.model);
+                            free(xkb_opts.model);
                             xkb_opts.model = strdup(tmp_val);
                         } else if (!strcasecmp(&tmp[3], "rules"))
                         {
-                            if (xkb_opts.rules)
-                                free(xkb_opts.rules);
+                            free(xkb_opts.rules);
                             xkb_opts.rules = strdup(tmp_val);
                         } else if (!strcasecmp(&tmp[3], "variant"))
                         {
-                            if (xkb_opts.variant)
-                                free(xkb_opts.variant);
+                            free(xkb_opts.variant);
                             xkb_opts.variant = strdup(tmp_val);
                         } else if (!strcasecmp(&tmp[3], "options"))
                         {
-                            if (xkb_opts.options)
-                                free(xkb_opts.options);
+                            free(xkb_opts.options);
                             xkb_opts.options = strdup(tmp_val);
                         }
                     } else
@@ -289,8 +284,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
                         (!strcasecmp(&tmp[3], "options")) &&
                         (tmp_val = get_prop_string_array(hal_ctx, udi, psi_key)))
                     {
-                        if (xkb_opts.options)
-                            free(xkb_opts.options);
+                        free(xkb_opts.options);
                         xkb_opts.options = strdup(tmp_val);
                     }
                 }
@@ -366,22 +360,17 @@ device_added(LibHalContext *hal_ctx, const char *udi)
     }
 
     for (; dev; dev = dev->next){
-        if (dev->config_info)
-            free(dev->config_info);
+        free(dev->config_info);
         dev->config_info = xstrdup(config_info);
     }
 
 unwind:
     if (set)
         libhal_free_property_set(set);
-    if (path)
-        free(path);
-    if (driver)
-        free(driver);
-    if (name)
-        free(name);
-    if (config_info)
-        free(config_info);
+    free(path);
+    free(driver);
+    free(name);
+    free(config_info);
     while (!dev && (tmpo = options)) {
         options = tmpo->next;
         free(tmpo->key);
@@ -401,16 +390,11 @@ unwind:
         free(attrs.tags);
     }
 
-    if (xkb_opts.layout)
-        free(xkb_opts.layout);
-    if (xkb_opts.rules)
-        free(xkb_opts.rules);
-    if (xkb_opts.model)
-        free(xkb_opts.model);
-    if (xkb_opts.variant)
-        free(xkb_opts.variant);
-    if (xkb_opts.options)
-        free(xkb_opts.options);
+    free(xkb_opts.layout);
+    free(xkb_opts.rules);
+    free(xkb_opts.model);
+    free(xkb_opts.variant);
+    free(xkb_opts.options);
 
     dbus_error_free(&error);
 
diff --git a/dbe/dbe.c b/dbe/dbe.c
index ef4b596..b4b7466 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -693,10 +693,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
     if (!(pScrVisInfo = (XdbeScreenVisualInfo *)malloc(count *
                         sizeof(XdbeScreenVisualInfo))))
     {
-        if (pDrawables)
-        {
-            free(pDrawables);
-        }
+        free(pDrawables);
 
         return(BadAlloc);
     }
@@ -722,10 +719,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
             }
 
             /* Free pDrawables if we needed to allocate it above. */
-            if (pDrawables)
-            {
-                free(pDrawables);
-            }
+            free(pDrawables);
 
             return (rc == Success) ? BadAlloc : rc;
         }
@@ -803,10 +797,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
     }
     free(pScrVisInfo);
 
-    if (pDrawables)
-    {
-        free(pDrawables);
-    }
+    free(pDrawables);
 
     return Success;
 
diff --git a/dix/colormap.c b/dix/colormap.c
index d530830..ae90690 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -1639,8 +1639,7 @@ AllocColorCells (int client, ColormapPtr pmap, int colors, int planes,
 	pcr->client = client;
 	if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr))
 	    ok = BadAlloc;
-    } else if (pcr)
-	free(pcr);
+    } else free(pcr);
 
     return (ok);
 }
@@ -1730,8 +1729,7 @@ AllocColorPlanes (int client, ColormapPtr pmap, int colors,
 	pcr->client = client;
 	if (!AddResource(FakeClientID(client), RT_CMAPENTRY, (pointer)pcr))
 	    ok = BadAlloc;
-    } else if (pcr)
-	free(pcr);
+    } else free(pcr);
 
     return (ok);
 }
@@ -1764,9 +1762,9 @@ AllocDirect (int client, ColormapPtr pmap, int c, int r, int g, int b, Bool cont
     ppixBlue = malloc(npixB * sizeof(Pixel));
     if (!ppixRed || !ppixGreen || !ppixBlue)
     {
-	if (ppixBlue) free(ppixBlue);
-	if (ppixGreen) free(ppixGreen);
-	if (ppixRed) free(ppixRed);
+	free(ppixBlue);
+	free(ppixGreen);
+	free(ppixRed);
 	return(BadAlloc);
     }
 
diff --git a/dix/devices.c b/dix/devices.c
index 427264d..8f9c8ff 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -740,8 +740,7 @@ FreeDeviceClass(int type, pointer *class)
         case ButtonClass:
             {
                 ButtonClassPtr *b = (ButtonClassPtr*)class;
-                if ((*b)->xkb_acts)
-                    free((*b)->xkb_acts);
+                free((*b)->xkb_acts);
                 free((*b));
                 break;
             }
@@ -749,8 +748,7 @@ FreeDeviceClass(int type, pointer *class)
             {
                 ValuatorClassPtr *v = (ValuatorClassPtr*)class;
 
-                if ((*v)->motion)
-                    free((*v)->motion);
+                free((*v)->motion);
                 free((*v));
                 break;
             }
@@ -1465,10 +1463,8 @@ InitStringFeedbackClassDeviceStruct (
     feedc->ctrl.symbols_displayed = malloc(sizeof (KeySym) * max_symbols);
     if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed)
     {
-	if (feedc->ctrl.symbols_supported)
-	    free(feedc->ctrl.symbols_supported);
-	if (feedc->ctrl.symbols_displayed)
-	    free(feedc->ctrl.symbols_displayed);
+	free(feedc->ctrl.symbols_supported);
+	free(feedc->ctrl.symbols_displayed);
 	free(feedc);
 	return FALSE;
     }
@@ -2283,8 +2279,7 @@ ProcGetMotionEvents(ClientPtr client)
 	WriteSwappedDataToClient(client, nEvents * sizeof(xTimecoord),
 				 (char *)coords);
     }
-    if (coords)
-	free(coords);
+    free(coords);
     return Success;
 }
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 79bdb55..44164f2 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -2837,7 +2837,7 @@ ProcQueryColors(ClientPtr client)
             return(BadAlloc);
 	if( (rc = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs, client)) )
 	{
-	    if (prgbs) free(prgbs);
+	    free(prgbs);
 	    return rc;
 	}
 	memset(&qcr, 0, sizeof(xQueryColorsReply));
@@ -2851,7 +2851,7 @@ ProcQueryColors(ClientPtr client)
 	    client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend;
 	    WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs);
 	}
-	if (prgbs) free(prgbs);
+	free(prgbs);
 	return Success;
 	
     }
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 51c7ab6..e321177 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -677,7 +677,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
 		    return TRUE;
 		}
 		if (err == FontNameAlias) {
-		    if (resolved) free(resolved);
+		    free(resolved);
 		    resolved = malloc(resolvedlen + 1);
 		    if (resolved)
 			memmove(resolved, tmpname, resolvedlen + 1);
@@ -731,8 +731,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
 		{
 		    c->saved = c->current;
 		    c->haveSaved = TRUE;
-		    if (c->savedName)
-			free(c->savedName);
+		    free(c->savedName);
 		    c->savedName = malloc(namelen + 1);
 		    if (c->savedName)
 			memmove(c->savedName, name, namelen + 1);
@@ -828,10 +827,10 @@ bail:
     for (i = 0; i < c->num_fpes; i++)
 	FreeFPE(c->fpe_list[i]);
     free(c->fpe_list);
-    if (c->savedName) free(c->savedName);
+    free(c->savedName);
     FreeFontNames(names);
     free(c);
-    if (resolved) free(resolved);
+    free(resolved);
     return TRUE;
 }
 
@@ -994,8 +993,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
 		c->saved = c->current;
 		c->haveSaved = TRUE;
 		c->savedNumFonts = numFonts;
-		if (c->savedName)
-		  free(c->savedName);
+		free(c->savedName);
 		c->savedName = malloc(namelen + 1);
 		if (c->savedName)
 		  memmove(c->savedName, name, namelen + 1);
@@ -1106,7 +1104,7 @@ bail:
 	FreeFPE(c->fpe_list[i]);
     free(c->reply);
     free(c->fpe_list);
-    if (c->savedName) free(c->savedName);
+    free(c->savedName);
     free(c);
     return TRUE;
 }
diff --git a/dix/dixutils.c b/dix/dixutils.c
index 51dbd14..cb1c97c 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -893,7 +893,7 @@ InitCallbackManager(void)
     {
 	DeleteCallbackList(listsToCleanup[i]);
     }
-    if (listsToCleanup) free(listsToCleanup);
+    free(listsToCleanup);
 
     numCallbackListsToCleanup = 0;
     listsToCleanup = NULL;
diff --git a/dix/events.c b/dix/events.c
index 1be212f..2dc0e98 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3793,10 +3793,8 @@ DeliverFocusedEvent(DeviceIntPtr keybd, InternalEvent *event, WindowPtr window)
     }
 
 unwind:
-    if (xE)
-        free(xE);
-    if (xi2)
-        free(xi2);
+    free(xE);
+    free(xi2);
     return;
 }
 
@@ -3976,10 +3974,8 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
 	}
     }
 
-    if (xi)
-        free(xi);
-    if (xi2)
-        free(xi2);
+    free(xi);
+    free(xi2);
 }
 
 /* This function is used to set the key pressed or key released state -
diff --git a/dix/getevents.c b/dix/getevents.c
index 3892f6f..f9d65e9 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -327,8 +327,7 @@ void
 AllocateMotionHistory(DeviceIntPtr pDev)
 {
     int size;
-    if (pDev->valuator->motion)
-        free(pDev->valuator->motion);
+    free(pDev->valuator->motion);
 
     if (pDev->valuator->numMotionEvents < 1)
         return;
diff --git a/dix/grabs.c b/dix/grabs.c
index 2931631..f850e3d 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -441,10 +441,10 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
     details = malloc(i * sizeof(Mask *));
     if (!deletes || !adds || !updates || !details)
     {
-	if (details) free(details);
-	if (updates) free(updates);
-	if (adds) free(adds);
-	if (deletes) free(deletes);
+	free(details);
+	free(updates);
+	free(adds);
+	free(deletes);
 	return FALSE;
     }
 
diff --git a/dix/region.c b/dix/region.c
index 911fe16..a77d17b 100644
--- a/dix/region.c
+++ b/dix/region.c
@@ -762,8 +762,7 @@ RegionOp(
 	AppendRegions(newReg, r2BandEnd, r2End);
     }
 
-    if (oldData)
-	free(oldData);
+    free(oldData);
 
     if (!(numRects = newReg->data->numRects))
     {
diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c
index 89cb137..7fa771d 100644
--- a/exa/exa_mixed.c
+++ b/exa/exa_mixed.c
@@ -257,8 +257,7 @@ exaDestroyPixmap_mixed(PixmapPtr pPixmap)
 	pExaPixmap->driverPriv = NULL;
 
 	if (pExaPixmap->pDamage) {
-	    if (pExaPixmap->sys_ptr)
-		free(pExaPixmap->sys_ptr);
+	    free(pExaPixmap->sys_ptr);
 	    pExaPixmap->sys_ptr = NULL;
 	    pExaPixmap->pDamage = NULL;
 	}
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 25346f9..1d3be49 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2431,8 +2431,7 @@ int __glXDisp_ClientInfo(__GLXclientState *cl, GLbyte *pc)
    
     cl->GLClientmajorVersion = req->major;
     cl->GLClientminorVersion = req->minor;
-    if (cl->GLClientextensions)
-	free(cl->GLClientextensions);
+    free(cl->GLClientextensions);
     buf = (const char *)(req+1);
     cl->GLClientextensions = xstrdup(buf);
 
diff --git a/glx/glxext.c b/glx/glxext.c
index 4d02b47..e203156 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -205,8 +205,8 @@ GLboolean __glXFreeContext(__GLXcontext *cx)
 {
     if (cx->idExists || cx->isCurrent) return GL_FALSE;
     
-    if (cx->feedbackBuf) free(cx->feedbackBuf);
-    if (cx->selectBuf) free(cx->selectBuf);
+    free(cx->feedbackBuf);
+    free(cx->selectBuf);
     if (cx == __glXLastContext) {
 	__glXFlushContextCache();
     }
@@ -323,10 +323,10 @@ glxClientCallback (CallbackListPtr	*list,
 	    }
 	}
 
-	if (cl->returnBuf) free(cl->returnBuf);
-	if (cl->largeCmdBuf) free(cl->largeCmdBuf);
-	if (cl->currentContexts) free(cl->currentContexts);
-	if (cl->GLClientextensions) free(cl->GLClientextensions);
+	free(cl->returnBuf);
+	free(cl->largeCmdBuf);
+	free(cl->currentContexts);
+	free(cl->GLClientextensions);
 	break;
 
     default:
diff --git a/glx/single2.c b/glx/single2.c
index 0700626..56ad86d 100644
--- a/glx/single2.c
+++ b/glx/single2.c
@@ -272,10 +272,8 @@ char *__glXcombine_strings(const char *cext_string, const char *sext_string)
 	s2 = sext_string;
    }
    if (!combo_string || !s1) {
-	if (combo_string)
-	    free(combo_string);
-	if (s1)
-	    free(s1);
+	free(combo_string);
+	free(s1);
 	return NULL;
    }
    combo_string[0] = '\0';
diff --git a/glx/xfont.c b/glx/xfont.c
index f0b5644..b4081cf 100644
--- a/glx/xfont.c
+++ b/glx/xfont.c
@@ -97,9 +97,7 @@ static int __glXMakeBitmapFromGlyph(FontPtr font, CharInfoPtr pci)
 				  pci->metrics.characterWidth, 0, 
 				  allocbuf ? allocbuf : buf) );
 
-    if (allocbuf) {
-	free(allocbuf);
-    }
+    free(allocbuf);
     return Success;
 #undef __GL_CHAR_BUF_SIZE
 }
diff --git a/hw/dmx/config/dmxparse.c b/hw/dmx/config/dmxparse.c
index 28a1835..35f1c21 100644
--- a/hw/dmx/config/dmxparse.c
+++ b/hw/dmx/config/dmxparse.c
@@ -98,7 +98,7 @@ const char *dmxConfigCopyString(const char *string, int length)
 
 void dmxConfigFree(void *area)
 {
-    if (area) free(area);
+    free(area);
 }
 
 DMXConfigTokenPtr dmxConfigCreateToken(int token, int line,
@@ -370,7 +370,7 @@ DMXConfigOptionPtr dmxConfigCreateOption(DMXConfigTokenPtr pStart,
 void dmxConfigFreeOption(DMXConfigOptionPtr p)
 {
     if (!p) return;
-    if (p->string) free(p->string);
+    free(p->string);
     dmxConfigFreeToken(p->start);
     dmxConfigFreeString(p->option);
     dmxConfigFreeToken(p->end);
diff --git a/hw/dmx/dmx.h b/hw/dmx/dmx.h
index 4532960..bf4b92c 100644
--- a/hw/dmx/dmx.h
+++ b/hw/dmx/dmx.h
@@ -351,7 +351,7 @@ do {									\
         
 #define MAXSCREENSFREE(o)                                               \
     do {                                                                \
-        if (o) free(o);                                                \
+        free(o);                                                \
         o = NULL;                                                       \
     } while (0)
 
diff --git a/hw/dmx/dmxinit.c b/hw/dmx/dmxinit.c
index 8a03c65..7cd50da 100644
--- a/hw/dmx/dmxinit.c
+++ b/hw/dmx/dmxinit.c
@@ -606,8 +606,8 @@ void InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[])
             dmxScreens[i].stat = NULL;
         }
         for (i = 0; i < dmxNumInputs; i++) dmxInputFree(&dmxInputs[i]);
-        if (dmxScreens) free(dmxScreens);
-        if (dmxInputs)  free(dmxInputs);
+        free(dmxScreens);
+        free(dmxInputs);
         dmxScreens    = NULL;
         dmxInputs     = NULL;
         dmxNumScreens = 0;
diff --git a/hw/dmx/dmxstat.c b/hw/dmx/dmxstat.c
index 41b0eb2..c3f1d3b 100644
--- a/hw/dmx/dmxstat.c
+++ b/hw/dmx/dmxstat.c
@@ -122,7 +122,7 @@ DMXStatInfo *dmxStatAlloc(void)
 /** Free the memory used by a \a DMXStatInfo structure. */
 void dmxStatFree(DMXStatInfo *pt)
 {
-    if (pt) free(pt);
+    free(pt);
 }
 
 static void dmxStatValue(DMXStatAvg *data, unsigned long value)
diff --git a/hw/dmx/glxProxy/glxutil.c b/hw/dmx/glxProxy/glxutil.c
index cfd0269..18fd43a 100644
--- a/hw/dmx/glxProxy/glxutil.c
+++ b/hw/dmx/glxProxy/glxutil.c
@@ -105,7 +105,5 @@ __glXRealloc(void *addr, size_t newSize)
 void
 __glXFree(void *addr)
 {
-    if (addr) {
-	free(addr);
-    }
+    free(addr);
 }
diff --git a/hw/dmx/glxProxy/glxvisuals.c b/hw/dmx/glxProxy/glxvisuals.c
index 58151b7..4c64db2 100644
--- a/hw/dmx/glxProxy/glxvisuals.c
+++ b/hw/dmx/glxProxy/glxvisuals.c
@@ -531,8 +531,7 @@ Bool glxInitVisuals(int *nvisualp, VisualPtr *visualp,
     __glXFree(pNewVisualConfigs);
 
     /* Free the private list created by DDX HW driver */
-    if (visualPrivates)
-        free(visualPrivates);
+    free(visualPrivates);
     visualPrivates = NULL;
 
     return TRUE;
diff --git a/hw/dmx/input/dmxbackend.c b/hw/dmx/input/dmxbackend.c
index 55615cf..e917a5c 100644
--- a/hw/dmx/input/dmxbackend.c
+++ b/hw/dmx/input/dmxbackend.c
@@ -114,7 +114,7 @@ pointer dmxBackendCreatePrivate(DeviceIntPtr pDevice)
  * #dmxBackendCreatePrivate. */
 void dmxBackendDestroyPrivate(pointer private)
 {
-    if (private) free(private);
+    free(private);
 }
 
 static void *dmxBackendTestScreen(DMXScreenInfo *dmxScreen, void *closure)
diff --git a/hw/dmx/input/dmxconsole.c b/hw/dmx/input/dmxconsole.c
index 80df064..7ec209d 100644
--- a/hw/dmx/input/dmxconsole.c
+++ b/hw/dmx/input/dmxconsole.c
@@ -148,7 +148,7 @@ pointer dmxConsoleCreatePrivate(DeviceIntPtr pDevice)
 /** If \a private is non-NULL, free its associated memory. */
 void dmxConsoleDestroyPrivate(pointer private)
 {
-    if (private) free(private);
+    free(private);
 }
 
 static void dmxConsoleDrawFineCursor(myPrivate *priv, XRectangle *rect)
diff --git a/hw/dmx/input/dmxinputinit.c b/hw/dmx/input/dmxinputinit.c
index 814fc1a..b2e16fb 100644
--- a/hw/dmx/input/dmxinputinit.c
+++ b/hw/dmx/input/dmxinputinit.c
@@ -1084,9 +1084,9 @@ static void dmxInputFreeLocal(DMXLocalInputInfoRec *local)
     if (local->isCore && local->type == DMX_LOCAL_KEYBOARD)
         dmxLocalCoreKeyboard = NULL;
     if (local->destroy_private) local->destroy_private(local->private);
-    if (local->history)         free(local->history);
-    if (local->valuators)       free(local->valuators);
-    if (local->deviceName)      free(local->deviceName);
+    free(local->history);
+    free(local->valuators);
+    free(local->deviceName);
     local->private    = NULL;
     local->history    = NULL;
     local->deviceName = NULL;
@@ -1100,9 +1100,9 @@ void dmxInputFree(DMXInputInfo *dmxInput)
     
     if (!dmxInput) return;
 
-    if (dmxInput->keycodes) free(dmxInput->keycodes);
-    if (dmxInput->symbols)  free(dmxInput->symbols);
-    if (dmxInput->geometry) free(dmxInput->geometry);
+    free(dmxInput->keycodes);
+    free(dmxInput->symbols);
+    free(dmxInput->geometry);
 
     for (i = 0; i < dmxInput->numDevs; i++) {
         dmxInputFreeLocal(dmxInput->devs[i]);
diff --git a/hw/dmx/input/lnx-keyboard.c b/hw/dmx/input/lnx-keyboard.c
index 050c80e..5bfb881 100644
--- a/hw/dmx/input/lnx-keyboard.c
+++ b/hw/dmx/input/lnx-keyboard.c
@@ -368,7 +368,7 @@ pointer kbdLinuxCreatePrivate(DeviceIntPtr pKeyboard)
 /** Destroy a private structure. */
 void kbdLinuxDestroyPrivate(pointer priv)
 {
-    if (priv) free(priv);
+    free(priv);
 }
 
 /** Ring the bell.
diff --git a/hw/dmx/input/lnx-ms.c b/hw/dmx/input/lnx-ms.c
index 549df46..ee18707 100644
--- a/hw/dmx/input/lnx-ms.c
+++ b/hw/dmx/input/lnx-ms.c
@@ -301,7 +301,7 @@ pointer msLinuxCreatePrivate(DeviceIntPtr pMouse)
 /** Destroy a private structure. */
 void msLinuxDestroyPrivate(pointer priv)
 {
-    if (priv) free(priv);
+    free(priv);
 }
 
 /** Fill the \a info structure with information needed to initialize \a
diff --git a/hw/dmx/input/lnx-ps2.c b/hw/dmx/input/lnx-ps2.c
index 70918ee..3a220cf 100644
--- a/hw/dmx/input/lnx-ps2.c
+++ b/hw/dmx/input/lnx-ps2.c
@@ -269,7 +269,7 @@ pointer ps2LinuxCreatePrivate(DeviceIntPtr pMouse)
 /** Destroy a private structure. */
 void ps2LinuxDestroyPrivate(pointer priv)
 {
-    if (priv) free(priv);
+    free(priv);
 }
 
 /** Fill the \a info structure with information needed to initialize \a
diff --git a/hw/dmx/input/usb-common.c b/hw/dmx/input/usb-common.c
index 95c00b8..25479ae 100644
--- a/hw/dmx/input/usb-common.c
+++ b/hw/dmx/input/usb-common.c
@@ -377,5 +377,5 @@ pointer usbCreatePrivate(DeviceIntPtr pDevice)
 /** Destroy a private structure. */
 void usbDestroyPrivate(pointer priv)
 {
-    if (priv) free(priv);
+    free(priv);
 }
diff --git a/hw/kdrive/fake/fake.c b/hw/kdrive/fake/fake.c
index 1cf0f2e..b8306db 100644
--- a/hw/kdrive/fake/fake.c
+++ b/hw/kdrive/fake/fake.c
@@ -168,8 +168,7 @@ fakeMapFramebuffer (KdScreenInfo *screen)
     KdSetPointerMatrix (&m);
     
     priv->bytes_per_line = ((screen->width * screen->fb.bitsPerPixel + 31) >> 5) << 2;
-    if (priv->base)
-	free (priv->base);
+    free(priv->base);
     priv->base = malloc (priv->bytes_per_line * screen->height);
     
     if (scrpriv->shadow)
diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index 5b236af..167bc78 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -120,8 +120,7 @@ FreeList(const char ***list, int *lines)
     int i;
 
     for (i = 0; i < *lines; i++) {
-	if ((*list)[i])
-	    free((*list)[i]);
+	free((*list)[i]);
     }
     free(*list);
     *list = NULL;
diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
index f6c5633..0d27fd5 100644
--- a/hw/xfree86/common/xf86Cursor.c
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -848,10 +848,10 @@ xf86ReconfigureLayout(void)
     for (i = 0; i < MAXSCREENS; i++) {
 	xf86ScreenLayoutPtr sl = &xf86ScreenLayout[i];
 	/* we don't have to zero these, xf86InitOrigins() takes care of that */
-	if (sl->left) free(sl->left);
-	if (sl->right) free(sl->right);
-	if (sl->up) free(sl->up);
-	if (sl->down) free(sl->down);
+	free(sl->left);
+	free(sl->right);
+	free(sl->up);
+	free(sl->down);
     }
 
     xf86InitOrigins();
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index ac1f283..394fb06 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -234,8 +234,7 @@ xf86DeleteScreen(int scrnIndex, int flags)
     if (pScrn->drv)
 	pScrn->drv->refCount--;
 
-    if (pScrn->privates)
-	free(pScrn->privates);
+    free(pScrn->privates);
 
     xf86ClearEntityListForScreen(scrnIndex);
 
@@ -327,8 +326,7 @@ xf86DeleteInput(InputInfoPtr pInp, int flags)
     /* This should *really* be handled in drv->UnInit(dev) call instead, but
      * if the driver forgets about it make sure we free it or at least crash
      * with flying colors */
-    if (pInp->private)
-	free(pInp->private);
+    free(pInp->private);
 
     FreeInputAttributes(pInp->attrs);
 
@@ -2017,8 +2015,7 @@ xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type,
        */
       pNewProp->next = NULL;
     } else {
-      if (pNewProp->name)
-	free(pNewProp->name);
+      free(pNewProp->name);
       existing = TRUE;
     }
 
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index 356ddab..c3a1ddd 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -844,10 +844,8 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
 unwind:
     if (is_auto && !xf86Info.autoAddDevices)
         xf86Msg(X_INFO, "AutoAddDevices is off - not adding device.\n");
-    if(idev->driver)
-        free(idev->driver);
-    if(idev->identifier)
-        free(idev->identifier);
+    free(idev->driver);
+    free(idev->identifier);
     xf86optionListFree(idev->commonOptions);
     free(idev);
     return rval;
diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index f26c22c..d2a8f12 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -327,7 +327,7 @@ CMapDestroyColormap (ColormapPtr cmap)
     CMapLinkPtr prevLink = NULL, pLink = pScreenPriv->maps;
 
     if(pColPriv) {
-	if(pColPriv->colors) free(pColPriv->colors);
+	free(pColPriv->colors);
 	free(pColPriv);
     }
    
diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c
index ea8c3e1..30a4202 100644
--- a/hw/xfree86/common/xf86sbusBus.c
+++ b/hw/xfree86/common/xf86sbusBus.c
@@ -478,8 +478,7 @@ xf86MatchSbusInstances(const char *driverName, int sbusDevId,
 	    instances[i].claimed = TRUE;
 	    instances[i].dev = dev;
 	}
-	if (promPath)
-	    free(promPath);
+	free(promPath);
     }
 
     DebugF("%s instances found: %d\n", driverName, numClaimedInstances);
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index b02fdaf..3631369 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -1102,8 +1102,7 @@ ProcXF86VidModeValidateModeLine(ClientPtr client)
     status = VidModeCheckModeForDriver(stuff->screen, modetmp);
 
 status_reply:
-    if(modetmp)
-      free(modetmp);
+    free(modetmp);
 
     rep.type = X_Reply;
     rep.length = bytes_to_int32(SIZEOF(xXF86VidModeValidateModeLineReply)
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index db4cd7b..61bbe9a 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -578,10 +578,8 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD)
 	      drmInstallSIGIOHandler(pDRIPriv->drmFD, DRISwapContext))) {
 	    DRIDrvMsg(pScreen->myNum, X_ERROR,
 		      "[drm] failed to setup DRM signal handler\n");
-	    if (pDRIPriv->hiddenContextStore)
-		free(pDRIPriv->hiddenContextStore);
-	    if (pDRIPriv->partial3DContextStore)
-		free(pDRIPriv->partial3DContextStore);
+	    free(pDRIPriv->hiddenContextStore);
+	    free(pDRIPriv->partial3DContextStore);
 	    DRIDestroyContextPriv(pDRIContextPriv);
 	    return FALSE;
 	} else {
@@ -1618,7 +1616,7 @@ DRICreateInfoRec(void)
 void
 DRIDestroyInfoRec(DRIInfoPtr DRIInfo)
 {
-    if (DRIInfo->busIdString) free(DRIInfo->busIdString);
+    free(DRIInfo->busIdString);
     free((char*)DRIInfo);
 }
 
diff --git a/hw/xfree86/loader/loadext.c b/hw/xfree86/loader/loadext.c
index 39a92c8..8ac50a6 100644
--- a/hw/xfree86/loader/loadext.c
+++ b/hw/xfree86/loader/loadext.c
@@ -378,10 +378,8 @@ tsort(void)
 	if (n == NULL)
 	    ErrorF("tsort: internal error -- could not find cycle");
     }
-    if (cycle_buf)
-	free(cycle_buf);
-    if (longest_cycle)
-	free(longest_cycle);
+    free(cycle_buf);
+    free(longest_cycle);
     if (graph)
 	free_nodes(graph);
 }
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 871bfda..defe560 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -315,16 +315,14 @@ InitSubdirs(const char **subdirlist)
 		if (**s == '/' || **s == '\\' || strchr(*s, ':') ||
 		    strstr(*s, "..")) {
 		    xf86Msg(X_ERROR, "InitSubdirs: Bad subdir: \"%s\"\n", *s);
-		    if (tmp_subdirlist)
-			free(tmp_subdirlist);
+		    free(tmp_subdirlist);
 		    return NULL;
 		}
 	    }
 	}
 	subdirs = malloc((i * 2 + 1) * sizeof(char *));
 	if (!subdirs) {
-	    if (tmp_subdirlist)
-		free(tmp_subdirlist);
+	    free(tmp_subdirlist);
 	    return NULL;
 	}
 	i = 0;
@@ -348,8 +346,7 @@ InitSubdirs(const char **subdirlist)
 		while (--i >= 0)
 		    free(subdirs[i]);
 		free(subdirs);
-		if (tmp_subdirlist)
-		    free(tmp_subdirlist);
+		free(tmp_subdirlist);
 		return NULL;
 	    }
 	    /* tack on the OS name */
@@ -367,8 +364,7 @@ InitSubdirs(const char **subdirlist)
 	}
 	subdirs[i] = NULL;
     }
-    if (tmp_subdirlist)
-	free(tmp_subdirlist);
+    free(tmp_subdirlist);
     return (const char **)subdirs;
 }
 
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 60003d5..304d503 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -157,8 +157,7 @@ xf86CrtcDestroy (xf86CrtcPtr crtc)
 	    xf86_config->num_crtc--;
 	    break;
 	}
-    if (crtc->params)
-	free(crtc->params);
+    free(crtc->params);
     free(crtc->gamma_red);
     free(crtc);
 }
@@ -382,8 +381,7 @@ done:
 	crtc->transformPresent = saved_transform_present;
     }
 
-    if (adjusted_mode->name)
-	    free(adjusted_mode->name);
+    free(adjusted_mode->name);
     free(adjusted_mode);
 
     if (didLock)
@@ -482,8 +480,7 @@ xf86OutputSetMonitor (xf86OutputPtr output)
     if (!output->name)
 	return;
 
-    if (output->options)
-	free(output->options);
+    free(output->options);
 
     output->options = xnfalloc (sizeof (xf86OutputOptions));
     memcpy (output->options, xf86OutputOptions, sizeof (xf86OutputOptions));
diff --git a/hw/xfree86/modes/xf86DiDGA.c b/hw/xfree86/modes/xf86DiDGA.c
index a4cf4f0..ca419ec 100644
--- a/hw/xfree86/modes/xf86DiDGA.c
+++ b/hw/xfree86/modes/xf86DiDGA.c
@@ -103,8 +103,7 @@ xf86_dga_get_modes (ScreenPtr pScreen)
 	if (display_mode == scrn->modes)
 	    break;
     }
-    if (xf86_config->dga_modes)
-	free(xf86_config->dga_modes);
+    free(xf86_config->dga_modes);
     xf86_config->dga_nmode = num;
     xf86_config->dga_modes = modes;
     return TRUE;
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 4cc99ad..fdc38c5 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -405,8 +405,7 @@ xf86CrtcRotate (xf86CrtcPtr crtc)
 	 */
 	xf86RotateDestroy (crtc);
 	crtc->transform_in_use = FALSE;
-	if (new_params)
-	    free(new_params);
+	free(new_params);
 	new_params = NULL;
 	new_nparams = 0;
 	new_filter = NULL;
@@ -506,8 +505,7 @@ xf86CrtcRotate (xf86CrtcPtr crtc)
     crtc->crtc_to_framebuffer = crtc_to_fb;
     crtc->f_crtc_to_framebuffer = f_crtc_to_fb;
     crtc->f_framebuffer_to_crtc = f_fb_to_crtc;
-    if (crtc->params)
-	free(crtc->params);
+    free(crtc->params);
     crtc->params = new_params;
     crtc->nparams = new_nparams;
     crtc->filter = new_filter;
diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c
index 699f15c..f4fea28 100644
--- a/hw/xfree86/parser/Flags.c
+++ b/hw/xfree86/parser/Flags.c
@@ -451,8 +451,7 @@ xf86parseOption(XF86OptionPtr head)
 
 	if ((token = xf86getSubToken(&comment)) != STRING) {
 		xf86parseError(BAD_OPTION_MSG, NULL);
-		if (comment)
-			free(comment);
+		free(comment);
 		return (head);
 	}
 
diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index 52e80a9..05fbc89 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -923,8 +923,7 @@ OpenConfigDir(const char *path, const char *cmdline, const char *projroot,
 		if (!found) {
 			free(dirpath);
 			dirpath = NULL;
-			if (list)
-				free(list);
+			free(list);
 		}
 	}
 
@@ -1088,8 +1087,7 @@ xf86validationError (char *format,...)
 void
 xf86setSection (char *section)
 {
-	if (configSection)
-		free(configSection);
+	free(configSection);
 	configSection = malloc(strlen (section) + 1);
 	strcpy (configSection, section);
 }
diff --git a/hw/xfree86/ramdac/xf86RamDac.c b/hw/xfree86/ramdac/xf86RamDac.c
index 0015b76..f4d1274 100644
--- a/hw/xfree86/ramdac/xf86RamDac.c
+++ b/hw/xfree86/ramdac/xf86RamDac.c
@@ -132,12 +132,10 @@ RamDacFreeRec(ScrnInfoPtr pScrn)
     ramdacScrPtr = ((RamDacScreenRecPtr)
 				(pScrn)->privates[RamDacGetScreenIndex()].ptr);
     
-    if (ramdacHWPtr)
-	free(ramdacHWPtr);
+    free(ramdacHWPtr);
     ramdacHWPtr = NULL;
 
-    if (ramdacScrPtr)
-	free(ramdacScrPtr);
+    free(ramdacScrPtr);
     ramdacScrPtr = NULL;
 }
 
diff --git a/hw/xfree86/vgahw/vgaHW.c b/hw/xfree86/vgahw/vgaHW.c
index 3ae2dfa..b6832c3 100644
--- a/hw/xfree86/vgahw/vgaHW.c
+++ b/hw/xfree86/vgahw/vgaHW.c
@@ -1479,8 +1479,7 @@ vgaHWGetHWRecPrivate(void)
 static void
 vgaHWFreeRegs(vgaRegPtr regp)
 {
-    if (regp->CRTC)
-        free(regp->CRTC);
+    free(regp->CRTC);
 
     regp->CRTC =
     regp->Sequencer =
diff --git a/hw/xfree86/xaa/xaaCpyArea.c b/hw/xfree86/xaa/xaaCpyArea.c
index 443a0e1..bcf81ee 100644
--- a/hw/xfree86/xaa/xaaCpyArea.c
+++ b/hw/xfree86/xaa/xaaCpyArea.c
@@ -148,8 +148,8 @@ XAADoBitBlt(
 	    pboxNew2 = (BoxPtr)malloc(sizeof(BoxRec) * nbox);
 	    pptNew2 = (DDXPointPtr)malloc(sizeof(DDXPointRec) * nbox);
 	    if(!pboxNew2 || !pptNew2) {
-		if (pptNew2) free(pptNew2);
-		if (pboxNew2) free(pboxNew2);
+		free(pptNew2);
+		free(pboxNew2);
 		if (pboxNew1) {
 		    free(pptNew1);
 		    free(pboxNew1);
diff --git a/hw/xfree86/xaa/xaaGC.c b/hw/xfree86/xaa/xaaGC.c
index 8c9d0ed..fbef88d 100644
--- a/hw/xfree86/xaa/xaaGC.c
+++ b/hw/xfree86/xaa/xaaGC.c
@@ -243,8 +243,7 @@ XAADestroyGC(GCPtr pGC)
     if(pGCPriv->XAAOps != &XAAFallbackOps)
 	free(pGCPriv->XAAOps);
 
-    if(pGCPriv->DashPattern)
-	free(pGCPriv->DashPattern);
+    free(pGCPriv->DashPattern);
 
     (*pGC->funcs->DestroyGC)(pGC);
     XAA_GC_FUNC_EPILOGUE (pGC);
diff --git a/hw/xfree86/xaa/xaaInit.c b/hw/xfree86/xaa/xaaInit.c
index d0a66b8..ec55632 100644
--- a/hw/xfree86/xaa/xaaInit.c
+++ b/hw/xfree86/xaa/xaaInit.c
@@ -84,11 +84,9 @@ XAADestroyInfoRec(XAAInfoRecPtr infoRec)
     if(infoRec->ClosePixmapCache)
 	(*infoRec->ClosePixmapCache)(infoRec->pScrn->pScreen);
    
-    if(infoRec->PreAllocMem)
-	free(infoRec->PreAllocMem);
+    free(infoRec->PreAllocMem);
 
-    if(infoRec->PixmapCachePrivate)
-	free(infoRec->PixmapCachePrivate);
+    free(infoRec->PixmapCachePrivate);
 
     free(infoRec);
 }
diff --git a/hw/xfree86/xaa/xaaLineMisc.c b/hw/xfree86/xaa/xaaLineMisc.c
index e017c22..ed3cd48 100644
--- a/hw/xfree86/xaa/xaaLineMisc.c
+++ b/hw/xfree86/xaa/xaaLineMisc.c
@@ -74,8 +74,7 @@ XAAComputeDash(GCPtr pGC)
     int shift, value, direction;
     Bool set;
 
-    if(pGCPriv->DashPattern)
-	free(pGCPriv->DashPattern);
+    free(pGCPriv->DashPattern);
 
     pGCPriv->DashPattern = NULL;
     pGCPriv->DashLength = 0; 
diff --git a/hw/xfree86/xaa/xaaPCache.c b/hw/xfree86/xaa/xaaPCache.c
index f7f6a29..86ac1cd 100644
--- a/hw/xfree86/xaa/xaaPCache.c
+++ b/hw/xfree86/xaa/xaaPCache.c
@@ -144,18 +144,12 @@ FreePixmapCachePrivate(XAAPixmapCachePrivatePtr pPriv)
 {
     if(!pPriv) return;
 
-    if(pPriv->Info512)
-	free(pPriv->Info512);
-    if(pPriv->Info256)
-	free(pPriv->Info256);
-    if(pPriv->Info128)
-	free(pPriv->Info128);
-    if(pPriv->InfoColor)
-	free(pPriv->InfoColor);
-    if(pPriv->InfoMono)
-	free(pPriv->InfoMono);
-    if(pPriv->InfoPartial)
-	free(pPriv->InfoPartial);
+    free(pPriv->Info512);
+    free(pPriv->Info256);
+    free(pPriv->Info128);
+    free(pPriv->InfoColor);
+    free(pPriv->InfoMono);
+    free(pPriv->InfoPartial);
      
     free(pPriv);
 }
diff --git a/hw/xfree86/xaa/xaaTEText.c b/hw/xfree86/xaa/xaaTEText.c
index 729e8a8..41c0ebc 100644
--- a/hw/xfree86/xaa/xaaTEText.c
+++ b/hw/xfree86/xaa/xaaTEText.c
@@ -299,8 +299,7 @@ XAAGlyphBltTEColorExpansion(
 		skippix, ytop - Top, glyphs + skipglyphs, glyphWidth, 
 		fg, bg, rop, planemask);
 
-	    if (fallbackBits)
-		free(fallbackBits);
+	    free(fallbackBits);
 	}
 
 	nbox--; pbox++;
diff --git a/hw/xnest/Color.c b/hw/xnest/Color.c
index 3b60cc9..883b77c 100644
--- a/hw/xnest/Color.c
+++ b/hw/xnest/Color.c
@@ -214,8 +214,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
   free(icws.cmapIDs);
   
   if (!xnestSameInstalledColormapWindows(icws.windows, icws.numWindows)) {
-    if (xnestOldInstalledColormapWindows)
-      free(xnestOldInstalledColormapWindows);
+    free(xnestOldInstalledColormapWindows);
 
 #ifdef _XSERVER64
     {
@@ -264,14 +263,13 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
 #endif /* DUMB_WINDOW_MANAGERS */
   }
   else
-    if (icws.windows) free(icws.windows);
+    free(icws.windows);
 }
 
 void
 xnestSetScreenSaverColormapWindow(ScreenPtr pScreen)
 {
-  if (xnestOldInstalledColormapWindows)
-    free(xnestOldInstalledColormapWindows);
+  free(xnestOldInstalledColormapWindows);
   
 #ifdef _XSERVER64
   {
diff --git a/hw/xwin/winclipboardxevents.c b/hw/xwin/winclipboardxevents.c
index ae8262e..edb6ac4 100644
--- a/hw/xwin/winclipboardxevents.c
+++ b/hw/xwin/winclipboardxevents.c
@@ -411,8 +411,7 @@ winClipboardFlushXEvents (HWND hwnd,
 	    xtpText.value = NULL;
 	    xtpText.nitems = 0;
 	  }
-	  if (pszConvertData)
-	    free (pszConvertData);
+	  free(pszConvertData);
 	  if (hGlobal && pszGlobalData)
 	    GlobalUnlock (hGlobal);
 	  
@@ -773,10 +772,8 @@ winClipboardFlushXEvents (HWND hwnd,
 	    xtpText.value = NULL;
 	    xtpText.nitems = 0;
 	  }
-	  if (pszConvertData)
-	    free (pszConvertData);
-	  if (pwszUnicodeStr)
-	    free (pwszUnicodeStr);
+	  free(pszConvertData);
+	  free(pwszUnicodeStr);
 	  if (hGlobal && pszGlobalData)
 	    GlobalUnlock (hGlobal);
 	  if (fSetClipboardData && g_fUnicodeSupport)
diff --git a/hw/xwin/winerror.c b/hw/xwin/winerror.c
index 2ff65bc..cb69c57 100644
--- a/hw/xwin/winerror.c
+++ b/hw/xwin/winerror.c
@@ -144,9 +144,7 @@ winMessageBoxF (const char *pszError, UINT uType, ...)
 	      MB_OK | uType);
 
  winMessageBoxF_Cleanup:
-  if (pszErrorF)
-    free(pszErrorF);
-  if (pszMsgBox)
-    free(pszMsgBox);
+  free(pszErrorF);
+  free(pszMsgBox);
 #undef MESSAGEBOXF
 }
diff --git a/hw/xwin/winprefs.c b/hw/xwin/winprefs.c
index 93901ca..1996ef0 100644
--- a/hw/xwin/winprefs.c
+++ b/hw/xwin/winprefs.c
@@ -672,8 +672,7 @@ winOverrideIcon (unsigned long longWin)
       {
 	free (res_name);
 	free (res_class);
-	if (wmName)
-	  free (wmName);
+	free(wmName);
 
 	if (pref.icon[i].hicon)
 	  return pref.icon[i].hicon;
@@ -691,8 +690,7 @@ winOverrideIcon (unsigned long longWin)
   /* Didn't find the icon, fail gracefully */
   free (res_name);
   free (res_class);
-  if (wmName)
-    free (wmName);
+  free(wmName);
 
   return 0;
 }
@@ -849,8 +847,7 @@ winOverrideStyle (unsigned long longpWin)
       {
 	free (res_name);
 	free (res_class);
-	if (wmName)
-	  free (wmName);
+	free(wmName);
 
 	if (pref.style[i].type)
 	  return pref.style[i].type;
@@ -860,8 +857,7 @@ winOverrideStyle (unsigned long longpWin)
   /* Didn't find the style, fail gracefully */
   free (res_name);
   free (res_class);
-  if (wmName)
-    free (wmName);
+  free(wmName);
 
   return STYLE_NONE;
 }
diff --git a/mi/miarc.c b/mi/miarc.c
index 5143d2a..db21165 100644
--- a/mi/miarc.c
+++ b/mi/miarc.c
@@ -3081,10 +3081,8 @@ fillSpans (
 	    (*pGC->ops->FillSpans) (pDrawable, pGC, i, xSpans, xWidths, TRUE);
 	}
 	disposeFinalSpans ();
-	if (xSpans)
-	    free(xSpans);
-	if (xWidths)
-	    free(xWidths);
+	free(xSpans);
+	free(xWidths);
 	finalMiny = 0;
 	finalMaxy = -1;
 	finalSize = 0;
diff --git a/mi/mibitblt.c b/mi/mibitblt.c
index 8448483..98857e8 100644
--- a/mi/mibitblt.c
+++ b/mi/mibitblt.c
@@ -150,12 +150,9 @@ miCopyArea(DrawablePtr  pSrcDrawable,
     ordering = malloc(numRects * sizeof(unsigned int));
     if(!pptFirst || !pwidthFirst || !ordering)
     {
-       if (ordering)
-	   free(ordering);
-       if (pwidthFirst)
-           free(pwidthFirst);
-       if (pptFirst)
-           free(pptFirst);
+       free(ordering);
+       free(pwidthFirst);
+       free(pptFirst);
        return NULL;
     }
 
@@ -433,8 +430,8 @@ miOpqStipDrawable(DrawablePtr pDraw, GCPtr pGC, RegionPtr prgnSrc,
     pwidth = pwidthFirst = malloc(h * sizeof(int));
     if(!pptFirst || !pwidthFirst)
     {
-	if (pwidthFirst) free(pwidthFirst);
-	if (pptFirst) free(pptFirst);
+	free(pwidthFirst);
+	free(pptFirst);
 	FreeScratchGC(pGCT);
 	return;
     }
@@ -801,10 +798,8 @@ miPutImage( DrawablePtr pDraw, GCPtr pGC, int depth,
         pwidth = pwidthFirst = malloc(h * sizeof(int));
 	if(!pptFirst || !pwidthFirst)
         {
-	   if (pwidthFirst)
-               free(pwidthFirst);
-           if (pptFirst)
-               free(pptFirst);
+	   free(pwidthFirst);
+           free(pptFirst);
            return;
         }
 	if (pGC->miTranslate)
diff --git a/mi/micopy.c b/mi/micopy.c
index b1a7a08..027c461 100644
--- a/mi/micopy.c
+++ b/mi/micopy.c
@@ -108,8 +108,7 @@ miCopyRegion (DrawablePtr   pSrcDrawable,
 	    pboxNew2 = (BoxPtr)malloc(sizeof(BoxRec) * nbox);
 	    if(!pboxNew2)
 	    {
-		if (pboxNew1)
-		    free(pboxNew1);
+		free(pboxNew1);
 		return;
 	    }
 	    pboxBase = pboxNext = pbox;
@@ -143,10 +142,8 @@ miCopyRegion (DrawablePtr   pSrcDrawable,
 		 dx, dy,
 		 reverse, upsidedown, bitPlane, closure);
     
-    if (pboxNew1)
-	free(pboxNew1);
-    if (pboxNew2)
-	free(pboxNew2);
+    free(pboxNew1);
+    free(pboxNew2);
 }
 
 RegionPtr
diff --git a/mi/mifillrct.c b/mi/mifillrct.c
index e2bd7c9..1c63a35 100644
--- a/mi/mifillrct.c
+++ b/mi/mifillrct.c
@@ -111,8 +111,8 @@ miPolyFillRect(
     pwFirst = malloc(maxheight * sizeof(int));
     if(!pptFirst || !pwFirst)
     {
-	if (pwFirst) free(pwFirst);
-	if (pptFirst) free(pptFirst);
+	free(pwFirst);
+	free(pptFirst);
 	return;
     }
 
diff --git a/mi/mifpolycon.c b/mi/mifpolycon.c
index 13b5a48..1be0150 100644
--- a/mi/mifpolycon.c
+++ b/mi/mifpolycon.c
@@ -122,9 +122,9 @@ miFillSppPoly(
 
     if(!ptsOut || !width || !Marked)
     {
-	if (Marked) free(Marked);
-	if (width) free(width);
-	if (ptsOut) free(ptsOut);
+	free(Marked);
+	free(width);
+	free(ptsOut);
 	return;
     }
 
diff --git a/mi/mipolycon.c b/mi/mipolycon.c
index 40671df..2404c56 100644
--- a/mi/mipolycon.c
+++ b/mi/mipolycon.c
@@ -109,8 +109,8 @@ miFillConvexPoly(
     width = FirstWidth = malloc(sizeof(int) * dy);
     if(!FirstPoint || !FirstWidth)
     {
-	if (FirstWidth) free(FirstWidth);
-	if (FirstPoint) free(FirstPoint);
+	free(FirstWidth);
+	free(FirstPoint);
 	return(FALSE);
     }
 
diff --git a/mi/mispans.c b/mi/mispans.c
index 8ac66cc..9f56e3c 100644
--- a/mi/mispans.c
+++ b/mi/mispans.c
@@ -410,10 +410,8 @@ void miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup *spanGroup)
 
 	if (!yspans || !ysizes)
 	{
-	    if (yspans)
-		free(yspans);
-	    if (ysizes)
-		free(ysizes);
+	    free(yspans);
+	    free(ysizes);
 	    miDisposeSpanGroup (spanGroup);
 	    return;
 	}
@@ -492,10 +490,8 @@ void miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup *spanGroup)
 	    }
 	    free(yspans);
 	    free(ysizes);
-	    if (points)
-		free(points);
-	    if (widths)
-		free(widths);
+	    free(points);
+	    free(widths);
 	    return;
 	}
 	count = 0;
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 987f772..f5fe765 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -190,8 +190,7 @@ RRCrtcNotify (RRCrtcPtr	    crtc,
 	}
 	else
 	{
-	    if (crtc->outputs)
-		free(crtc->outputs);
+	    free(crtc->outputs);
 	    newoutputs = NULL;
 	}
 	crtc->outputs = newoutputs;
@@ -440,8 +439,7 @@ RRCrtcDestroyResource (pointer value, XID pid)
 	    }
 	}
     }
-    if (crtc->gammaRed)
-	free(crtc->gammaRed);
+    free(crtc->gammaRed);
     if (crtc->mode)
 	RRModeDestroy (crtc->mode);
     free(crtc);
@@ -563,8 +561,7 @@ RRCrtcGammaSetSize (RRCrtcPtr	crtc,
     }
     else
 	gamma = NULL;
-    if (crtc->gammaRed)
-	free(crtc->gammaRed);
+    free(crtc->gammaRed);
     crtc->gammaRed = gamma;
     crtc->gammaGreen = gamma + size;
     crtc->gammaBlue = gamma + size*2;
@@ -805,8 +802,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 				     RROutputType, client, DixSetAttrAccess);
 	if (rc != Success)
 	{
-	    if (outputs)
-		free(outputs);
+	    free(outputs);
 	    return rc;
 	}
 	/* validate crtc for this output */
@@ -815,8 +811,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 		break;
 	if (j == outputs[i]->numCrtcs)
 	{
-	    if (outputs)
-		free(outputs);
+	    free(outputs);
 	    return BadMatch;
 	}
 	/* validate mode for this output */
@@ -830,8 +825,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	}
 	if (j == outputs[i]->numModes + outputs[i]->numUserModes)
 	{
-	    if (outputs)
-		free(outputs);
+	    free(outputs);
 	    return BadMatch;
 	}
     }
@@ -850,8 +844,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	    }
 	    if (k == outputs[i]->numClones)
 	    {
-		if (outputs)
-		    free(outputs);
+		free(outputs);
 		return BadMatch;
 	    }
 	}
@@ -900,8 +893,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	 * Invalid rotation
 	 */
 	client->errorValue = stuff->rotation;
-	if (outputs)
-	    free(outputs);
+	free(outputs);
 	return BadValue;
     }
 
@@ -913,8 +905,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	     * requested rotation or reflection not supported by screen
 	     */
 	    client->errorValue = stuff->rotation;
-	    if (outputs)
-		free(outputs);
+	    free(outputs);
 	    return BadMatch;
 	}
     
@@ -943,16 +934,14 @@ ProcRRSetCrtcConfig (ClientPtr client)
 	    if (stuff->x + source_width > pScreen->width)
 	    {
 		client->errorValue = stuff->x;
-		if (outputs)
-		    free(outputs);
+		free(outputs);
 		return BadValue;
 	    }
 	    
 	    if (stuff->y + source_height > pScreen->height)
 	    {
 		client->errorValue = stuff->y;
-		if (outputs)
-		    free(outputs);
+		free(outputs);
 		return BadValue;
 	    }
 	}
@@ -979,8 +968,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
     pScrPriv->lastSetTime = time;
     
 sendReply:
-    if (outputs)
-	free(outputs);
+    free(outputs);
     
     rep.type = X_Reply;
     /* rep.status has already been filled in */
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 7822c0d..937b14d 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -134,8 +134,7 @@ RROutputSetClones (RROutputPtr  output,
     }
     else
 	newClones = NULL;
-    if (output->clones)
-	free(output->clones);
+    free(output->clones);
     memcpy (newClones, clones, numClones * sizeof (RROutputPtr));
     output->clones = newClones;
     output->numClones = numClones;
@@ -280,8 +279,7 @@ RROutputSetCrtcs (RROutputPtr	output,
     }
     else
 	newCrtcs = NULL;
-    if (output->crtcs)
-	free(output->crtcs);
+    free(output->crtcs);
     memcpy (newCrtcs, crtcs, numCrtcs * sizeof (RRCrtcPtr));
     output->crtcs = newCrtcs;
     output->numCrtcs = numCrtcs;
@@ -402,13 +400,10 @@ RROutputDestroyResource (pointer value, XID pid)
     
     for (m = 0; m < output->numUserModes; m++)
 	RRModeDestroy (output->userModes[m]);
-    if (output->userModes)
-	free(output->userModes);
+    free(output->userModes);
 
-    if (output->crtcs)
-	free(output->crtcs);
-    if (output->clones)
-	free(output->clones);
+    free(output->crtcs);
+    free(output->clones);
     RRDeleteAllOutputProperties (output);
     free(output);
     return 1;
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index 5e37577..a4402e1 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -69,10 +69,8 @@ RRDeleteAllOutputProperties (RROutputPtr output)
 	event.atom = prop->propertyName;
 	event.timestamp = currentTime.milliseconds;
 	RRDeliverPropertyEvent (output->pScreen, (xEvent *)&event);
-	if (prop->current.data)
-	    free(prop->current.data);
-	if (prop->pending.data)
-	    free(prop->pending.data);
+	free(prop->current.data);
+	free(prop->pending.data);
 	free(prop);
     }
 }
@@ -109,14 +107,10 @@ RRCreateOutputProperty (Atom property)
 static void
 RRDestroyOutputProperty (RRPropertyPtr prop)
 {
-    if (prop->valid_values)
-	free(prop->valid_values);
-    if (prop->current.data)
-	free(prop->current.data);
-    if (prop->pending.data)
-	free(prop->pending.data);
-    if (prop->valid_values)
-	free(prop->valid_values);
+    free(prop->valid_values);
+    free(prop->current.data);
+    free(prop->pending.data);
+    free(prop->valid_values);
     free(prop);
 }
 
@@ -232,12 +226,10 @@ RRChangeOutputProperty (RROutputPtr output, Atom property, Atom type,
 	    !pScrPriv->rrOutputSetProperty(output->pScreen, output,
 					   prop->propertyName, &new_value))
 	{
-	    if (new_value.data)
-		free(new_value.data);
+	    free(new_value.data);
 	    return (BadValue);
 	}
-	if (prop_value->data)
-	    free(prop_value->data);
+	free(prop_value->data);
 	*prop_value = new_value;
     }
 
@@ -378,8 +370,7 @@ RRConfigureOutputProperty (RROutputPtr output, Atom property,
      */
     if (prop->is_pending && !pending)
     {
-	if (prop->pending.data)
-	    free(prop->pending.data);
+	free(prop->pending.data);
 	RRInitOutputPropertyValue (&prop->pending);
     }
 
@@ -387,8 +378,7 @@ RRConfigureOutputProperty (RROutputPtr output, Atom property,
     prop->range = range;
     prop->immutable = immutable;
     prop->num_valid = num_values;
-    if (prop->valid_values)
-	free(prop->valid_values);
+    free(prop->valid_values);
     prop->valid_values = new_values;
 
     if (add) {
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index a2a0f36..f58e657 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -951,8 +951,7 @@ ProcRRSetScreenConfig (ClientPtr client)
     
 sendReply:
     
-    if (pData)
-	free(pData);
+    free(pData);
 
     rep.type = X_Reply;
     /* rep.status has already been filled in */
diff --git a/randr/rrtransform.c b/randr/rrtransform.c
index 7fd4fa0..a470e1e 100644
--- a/randr/rrtransform.c
+++ b/randr/rrtransform.c
@@ -37,8 +37,7 @@ RRTransformInit (RRTransformPtr transform)
 void
 RRTransformFini (RRTransformPtr transform)
 {
-    if (transform->params)
-	free(transform->params);
+    free(transform->params);
 }
 
 Bool
@@ -82,8 +81,7 @@ RRTransformSetFilter (RRTransformPtr	dst,
     }
     else
 	new_params = NULL;
-    if (dst->params)
-	free(dst->params);
+    free(dst->params);
     dst->filter = filter;
     dst->params = new_params;
     dst->nparams = nparams;
diff --git a/record/record.c b/record/record.c
index 5bd46c2..53bdfec 100644
--- a/record/record.c
+++ b/record/record.c
@@ -1868,8 +1868,7 @@ bailout:
     if (si)
     {
 	for (i = 0; i < maxSets; i++)
-	    if (si[i].intervals)
-		free(si[i].intervals);
+	    free(si[i].intervals);
 	free(si);
     }
     if (pCanonClients && pCanonClients != (XID *)&stuff[1])
@@ -1955,8 +1954,7 @@ ProcRecordCreateContext(ClientPtr client)
 	err = BadAlloc;
     }
 bailout:
-    if (pContext)
-	free(pContext);
+    free(pContext);
     return err;
 } /* ProcRecordCreateContext */
 
@@ -2352,7 +2350,7 @@ ProcRecordGetContext(ClientPtr client)
 bailout:
     for (i = 0; i < nRCAPs; i++)
     {
-	if (pRangeInfo[i].pRanges) free(pRangeInfo[i].pRanges);
+	free(pRangeInfo[i].pRanges);
     }
     free(pRangeInfo);
     return err;
diff --git a/record/set.c b/record/set.c
index f2064fd..a9a6a44 100644
--- a/record/set.c
+++ b/record/set.c
@@ -360,7 +360,7 @@ IntervalListCreateSet(RecordSetInterval *pIntervals, int nIntervals,
     memcpy(&prls[1], stackIntervals, nIntervals * sizeof(RecordSetInterval));
     prls->nIntervals = nIntervals;
 bailout:
-    if (stackIntervals) free(stackIntervals);
+    free(stackIntervals);
     return (RecordSetPtr)prls;
 }
 
diff --git a/render/picture.c b/render/picture.c
index f55711d..7fda6b9 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -1524,8 +1524,7 @@ FreePicture (pointer	value,
 
     if (--pPicture->refcnt == 0)
     {
-	if (pPicture->transform)
-	    free(pPicture->transform);
+	free(pPicture->transform);
 
 	if (pPicture->pSourcePict)
 	{
diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
index f155cc8..796931c 100644
--- a/xkb/XKBGAlloc.c
+++ b/xkb/XKBGAlloc.c
@@ -183,8 +183,7 @@ _XkbClearColor(char *color_in)
 {
 XkbColorPtr	color= (XkbColorPtr)color_in;
 
-    if (color->spec)
-	free(color->spec);
+    free(color->spec);
     return;
 }
 
@@ -663,8 +662,7 @@ register XkbPropertyPtr prop;
 	return NULL;
     for (i=0,prop=geom->properties;i<geom->num_properties;i++,prop++) {
 	if ((prop->name)&&(strcmp(name,prop->name)==0)) {
-	    if (prop->value)
-		free(prop->value);
+	    free(prop->value);
 	    prop->value= malloc(strlen(value)+1);
 	    if (prop->value)
 		strcpy(prop->value,value);
diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c
index abe0018..197523f 100644
--- a/xkb/XKBMAlloc.c
+++ b/xkb/XKBMAlloc.c
@@ -312,8 +312,7 @@ KeyCode		matchingKeys[XkbMaxKeyCount],nMatchingKeys;
 	if ((map_count>type->map_count)||(type->map==NULL))
 	    type->map = realloc(type->map,map_count * sizeof(XkbKTMapEntryRec));
 	if (!type->map) {
-	    if (prev_map) 
-		free(prev_map);
+	    free(prev_map);
 	    return BadAlloc;
 	}
 	if (want_preserve) {
@@ -324,8 +323,7 @@ KeyCode		matchingKeys[XkbMaxKeyCount],nMatchingKeys;
 					  map_count * sizeof(XkbModsRec));
 	    }
 	    if (!type->preserve) {
-		if (prev_preserve) 
-		    free(prev_preserve);
+		free(prev_preserve);
 		return BadAlloc;
 	    }
 	}
@@ -342,8 +340,7 @@ KeyCode		matchingKeys[XkbMaxKeyCount],nMatchingKeys;
 	type->level_names = realloc(type->level_names,
 				     new_num_lvls * sizeof(Atom));
 	if (!type->level_names) {
-	    if (prev_level_names) 
-		free(prev_level_names);
+	    free(prev_level_names);
 	    return BadAlloc;
 	}
     }
diff --git a/xkb/maprules.c b/xkb/maprules.c
index 5aabd1c..c683c0d 100644
--- a/xkb/maprules.c
+++ b/xkb/maprules.c
@@ -553,9 +553,9 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
 static void
 FreeMultiDefs(XkbRF_MultiDefsPtr defs)
 {
-  if (defs->options) free(defs->options);
-  if (defs->layout[1])  free(defs->layout[1]);
-  if (defs->variant[1])  free(defs->variant[1]);
+  free(defs->options);
+  free(defs->layout[1]);
+  free(defs->variant[1]);
 }
 
 static void
@@ -988,15 +988,15 @@ XkbRF_GroupPtr	group;
 	return;
     if (rules->rules) {
 	for (i=0,rule=rules->rules;i<rules->num_rules;i++,rule++) {
-	    if (rule->model)	free(rule->model);
-	    if (rule->layout)	free(rule->layout);
-	    if (rule->variant)	free(rule->variant);
-	    if (rule->option)	free(rule->option);
-	    if (rule->keycodes)	free(rule->keycodes);
-	    if (rule->symbols)	free(rule->symbols);
-	    if (rule->types)	free(rule->types);
-	    if (rule->compat)	free(rule->compat);
-	    if (rule->geometry)	free(rule->geometry);
+	    free(rule->model);
+	    free(rule->layout);
+	    free(rule->variant);
+	    free(rule->option);
+	    free(rule->keycodes);
+	    free(rule->symbols);
+	    free(rule->types);
+	    free(rule->compat);
+	    free(rule->geometry);
 	    memset((char *)rule, 0, sizeof(XkbRF_RuleRec));
 	}
 	free(rules->rules);
@@ -1006,8 +1006,8 @@ XkbRF_GroupPtr	group;
 
     if (rules->groups) {
 	for (i=0, group=rules->groups;i<rules->num_groups;i++,group++) {
-	    if (group->name)	free(group->name);
-	    if (group->words)	free(group->words);
+	    free(group->name);
+	    free(group->words);
 	}
 	free(rules->groups);
 	rules->num_groups= 0;
diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c
index 0f3ffa4..bd58243 100644
--- a/xkb/xkbInit.c
+++ b/xkb/xkbInit.c
@@ -220,20 +220,15 @@ char *			pval;
 static void
 XkbSetRulesUsed(XkbRMLVOSet *rmlvo)
 {
-    if (XkbRulesUsed)
-        free(XkbRulesUsed);
+    free(XkbRulesUsed);
     XkbRulesUsed= (rmlvo->rules?_XkbDupString(rmlvo->rules):NULL);
-    if (XkbModelUsed)
-	free(XkbModelUsed);
+    free(XkbModelUsed);
     XkbModelUsed= (rmlvo->model?_XkbDupString(rmlvo->model):NULL);
-    if (XkbLayoutUsed)
-	free(XkbLayoutUsed);
+    free(XkbLayoutUsed);
     XkbLayoutUsed= (rmlvo->layout?_XkbDupString(rmlvo->layout):NULL);
-    if (XkbVariantUsed)
-	free(XkbVariantUsed);
+    free(XkbVariantUsed);
     XkbVariantUsed= (rmlvo->variant?_XkbDupString(rmlvo->variant):NULL);
-    if (XkbOptionsUsed)
-	free(XkbOptionsUsed);
+    free(XkbOptionsUsed);
     XkbOptionsUsed= (rmlvo->options?_XkbDupString(rmlvo->options):NULL);
     if (XkbWantRulesProp)
 	QueueWorkProc(XkbWriteRulesProp,NULL,NULL);
@@ -244,28 +239,23 @@ void
 XkbSetRulesDflts(XkbRMLVOSet *rmlvo)
 {
     if (rmlvo->rules) {
-        if (XkbRulesDflt)
-	    free(XkbRulesDflt);
+        free(XkbRulesDflt);
         XkbRulesDflt= _XkbDupString(rmlvo->rules);
     }
     if (rmlvo->model) {
-	if (XkbModelDflt)
-	    free(XkbModelDflt);
+	free(XkbModelDflt);
 	XkbModelDflt= _XkbDupString(rmlvo->model);
     }
     if (rmlvo->layout) {
-	if (XkbLayoutDflt)
-	    free(XkbLayoutDflt);
+	free(XkbLayoutDflt);
 	XkbLayoutDflt= _XkbDupString(rmlvo->layout);
     }
     if (rmlvo->variant) {
-	if (XkbVariantDflt)
-	    free(XkbVariantDflt);
+	free(XkbVariantDflt);
 	XkbVariantDflt= _XkbDupString(rmlvo->variant);
     }
     if (rmlvo->options) {
-	if (XkbOptionsDflt)
-	    free(XkbOptionsDflt);
+	free(XkbOptionsDflt);
 	XkbOptionsDflt= _XkbDupString(rmlvo->options);
     }
     return;
diff --git a/xkb/xkbLEDs.c b/xkb/xkbLEDs.c
index d75f920..ae3666f 100644
--- a/xkb/xkbLEDs.c
+++ b/xkb/xkbLEDs.c
@@ -605,8 +605,8 @@ void
 XkbFreeSrvLedInfo(XkbSrvLedInfoPtr sli)
 {
     if ((sli->flags&XkbSLI_IsDefault)==0) {
-	if (sli->maps)	free(sli->maps);
-	if (sli->names)	free(sli->names);
+	free(sli->maps);
+	free(sli->names);
     }
     sli->maps= NULL;
     sli->names= NULL;
commit 5a0fc0ad21d562612676ef88ef2d533b2391810a
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Fri Jun 4 15:35:31 2010 +0700

    Replace deprecated bzero with memset
    
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Marcin Baczyński <marbacz at gmail.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>

diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 3cd2969..aac417c 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -1897,7 +1897,7 @@ int PanoramiXGetImage(ClientPtr client)
 	    nlines = min(linesPerBuf, h - linesDone);
 
 	    if(pDraw->depth == 1)
-		bzero(pBuf, nlines * widthBytesLine);
+		memset(pBuf, 0, nlines * widthBytesLine);
 
 	    XineramaGetImageData(drawables, x, y + linesDone, w, nlines,
 			format, planemask, pBuf, widthBytesLine, isRoot);
@@ -1914,7 +1914,7 @@ int PanoramiXGetImage(ClientPtr client)
 	        while (h - linesDone > 0) {
 		    nlines = min(linesPerBuf, h - linesDone);
 
-		    bzero(pBuf, nlines * widthBytesLine);
+		    memset(pBuf, 0, nlines * widthBytesLine);
 
 		    XineramaGetImageData(drawables, x, y + linesDone, w, 
 					nlines, format, plane, pBuf,
diff --git a/Xext/xace.c b/Xext/xace.c
index 94b5b37..abd4690 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -321,7 +321,7 @@ XaceCensorImage(
 	    /* Censoring was not completed above.  To be safe, wipe out
 	     * all the image data so that nothing trusted gets out.
 	     */
-	    bzero(pBuf, (int)(widthBytesLine * h));
+	    memset(pBuf, 0, (int)(widthBytesLine * h));
 	}
 	if (pRects)     free(pRects);
 	if (pScratchGC) FreeScratchGC(pScratchGC);
diff --git a/dix/colormap.c b/dix/colormap.c
index eb6c491..d530830 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -309,8 +309,8 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
     if ((class | DynamicClass) == DirectColor)
 	size = NUMRED(pVisual);
     pmap->freeRed = size;
-    bzero ((char *) pmap->red, (int)sizebytes);
-    bzero((char *) pmap->numPixelsRed, MAXCLIENTS * sizeof(int));
+    memset((char *) pmap->red, 0, (int)sizebytes);
+    memset((char *) pmap->numPixelsRed, 0, MAXCLIENTS * sizeof(int));
     for (pptr = &pmap->clientPixelsRed[MAXCLIENTS]; --pptr >= pmap->clientPixelsRed; )
 	*pptr = (Pixel *)NULL;
     if (alloc == AllocAll)
@@ -347,8 +347,8 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 	pmap->numPixelsBlue = (int *)((char *)pmap->clientPixelsBlue +
 				      (MAXCLIENTS * sizeof(Pixel *)));
 
-	bzero ((char *) pmap->green, (int)sizebytes);
-	bzero ((char *) pmap->blue, (int)sizebytes);
+	memset((char *) pmap->green, 0, (int)sizebytes);
+	memset((char *) pmap->blue, 0, (int)sizebytes);
 
 	memmove((char *) pmap->clientPixelsGreen,
 		(char *) pmap->clientPixelsRed,
@@ -356,8 +356,8 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 	memmove((char *) pmap->clientPixelsBlue,
 		(char *) pmap->clientPixelsRed,
 	      MAXCLIENTS * sizeof(Pixel *));
-	bzero((char *) pmap->numPixelsGreen, MAXCLIENTS * sizeof(int));
-	bzero((char *) pmap->numPixelsBlue, MAXCLIENTS * sizeof(int));
+	memset((char *) pmap->numPixelsGreen, 0, MAXCLIENTS * sizeof(int));
+	memset((char *) pmap->numPixelsBlue, 0, MAXCLIENTS * sizeof(int));
 
 	/* If every cell is allocated, mark its refcnt */
 	if (alloc == AllocAll)
diff --git a/dix/dispatch.c b/dix/dispatch.c
index d32950d..79bdb55 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -2971,7 +2971,7 @@ ProcCreateCursor (ClientPtr client)
     else
     {
 	/* zeroing the (pad) bits helps some ddx cursor handling */
-	bzero((char *)mskbits, n);
+	memset((char *)mskbits, 0, n);
 	(* msk->drawable.pScreen->GetImage)( (DrawablePtr)msk, 0, 0, width,
 					height, XYPixmap, 1, (pointer)mskbits);
     }
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index b6d54f8..51c7ab6 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -1093,7 +1093,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
     }
 finish:
     length = sizeof(xListFontsWithInfoReply);
-    bzero((char *) &finalReply, sizeof(xListFontsWithInfoReply));
+    memset((char *) &finalReply, 0, sizeof(xListFontsWithInfoReply));
     finalReply.type = X_Reply;
     finalReply.sequenceNumber = client->sequence;
     finalReply.length = bytes_to_int32(sizeof(xListFontsWithInfoReply)
diff --git a/dix/events.c b/dix/events.c
index 3ea639e..1be212f 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4310,7 +4310,7 @@ CoreEnterLeaveEvent(
         xKeymapEvent ke;
         ClientPtr client = grab ? rClient(grab) : wClient(pWin);
         if (XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess))
-            bzero((char *)&ke.map[0], 31);
+            memset((char *)&ke.map[0], 0, 31);
         else
             memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31);
 
@@ -4420,7 +4420,7 @@ CoreFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin)
         xKeymapEvent ke;
         ClientPtr client = wClient(pWin);
         if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess))
-            bzero((char *)&ke.map[0], 31);
+            memset((char *)&ke.map[0], 0, 31);
         else
             memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31);
 
diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index 2f41955..be8c036 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -570,7 +570,7 @@ vfbAllocateMmappedFramebuffer(vfbScreenInfoPtr pvfb)
 
     /* Extend the file to be the proper size */
 
-    bzero(dummyBuffer, DUMMY_BUFFER_SIZE);
+    memset(dummyBuffer, 0, DUMMY_BUFFER_SIZE);
     for (currentFileSize = 0;
 	 currentFileSize < pvfb->sizeInBytes;
 	 currentFileSize += writeThisTime)
diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index 8276257..7876ba9 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -654,7 +654,7 @@ xf86AllocateEntityPrivateIndex(void)
 	nprivs = xnfrealloc(pEnt->entityPrivates,
 			    xf86EntityPrivateCount * sizeof(DevUnion));
 	/* Zero the new private */
-	bzero(&nprivs[idx], sizeof(DevUnion));
+	memset(&nprivs[idx], 0, sizeof(DevUnion));
 	pEnt->entityPrivates = nprivs;
     }
     return idx;
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 7acb6af..c7a68e5 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1252,7 +1252,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 
     /* 5. Built-in default. */
     if (!foundPointer && !xf86Info.allowEmptyInput) {
-	bzero(&defPtr, sizeof(defPtr));
+	memset(&defPtr, 0, sizeof(defPtr));
 	defPtr.inp_identifier = strdup("<default pointer>");
 	defPtr.inp_driver = strdup("mouse");
 	confInput = &defPtr;
@@ -1303,7 +1303,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
     }
     if (!found && !xf86Info.allowEmptyInput) {
 	xf86Msg(X_INFO, "No default mouse found, adding one\n");
-	bzero(&defPtr, sizeof(defPtr));
+	memset(&defPtr, 0, sizeof(defPtr));
 	defPtr.inp_identifier = strdup("<default pointer>");
 	defPtr.inp_driver = strdup("mouse");
 	confInput = &defPtr;
@@ -1392,7 +1392,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
 
     /* 5. Built-in default. */
     if (!foundKeyboard && !xf86Info.allowEmptyInput) {
-	bzero(&defKbd, sizeof(defKbd));
+	memset(&defKbd, 0, sizeof(defKbd));
 	defKbd.inp_identifier = strdup("<default keyboard>");
 	defKbd.inp_driver = strdup("kbd");
 	confInput = &defKbd;
@@ -1851,7 +1851,7 @@ configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
     if (!conf_screen->scrn_monitor) {
 	XF86ConfMonitorRec defMon;
 
-	bzero(&defMon, sizeof(defMon));
+	memset(&defMon, 0, sizeof(defMon));
 	defMon.mon_identifier = "<default monitor>";
 	if (!configMonitor(screenp->monitor, &defMon))
 	    return FALSE;
diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
index 714743a..f6c5633 100644
--- a/hw/xfree86/common/xf86Cursor.c
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -590,7 +590,7 @@ xf86InitOrigins(void)
     /* need to have this set up with a config file option */
     HardEdges = FALSE;
 
-    bzero(xf86ScreenLayout, MAXSCREENS * sizeof(xf86ScreenLayoutRec));
+    memset(xf86ScreenLayout, 0, MAXSCREENS * sizeof(xf86ScreenLayoutRec));
 	
     screensLeft = prevScreensLeft = (1 << xf86NumScreens) - 1;
 
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 7867a42..ac1f283 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -269,7 +269,7 @@ xf86AllocateScrnInfoPrivateIndex(void)
 	nprivs = xnfrealloc(pScr->privates,
 			    xf86ScrnInfoPrivateCount * sizeof(DevUnion));
 	/* Zero the new private */
-	bzero(&nprivs[idx], sizeof(DevUnion));
+	memset(&nprivs[idx], 0, sizeof(DevUnion));
 	pScr->privates = nprivs;
     }
     return idx;
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 18df8c9..98bbd5d 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -203,8 +203,8 @@ xf86PrintBanner(void)
     struct tm t;
     char buf[100];
 
-    bzero(&t, sizeof(t));
-    bzero(buf, sizeof(buf));
+    memset(&t, 0, sizeof(t));
+    memset(buf, 0, sizeof(buf));
     t.tm_mday = BUILD_DATE % 100;
     t.tm_mon = (BUILD_DATE / 100) % 100 - 1;
     t.tm_year = BUILD_DATE / 10000 - 1900;
diff --git a/hw/xfree86/os-support/solaris/sun_bell.c b/hw/xfree86/os-support/solaris/sun_bell.c
index 05d1749..bab3913 100644
--- a/hw/xfree86/os-support/solaris/sun_bell.c
+++ b/hw/xfree86/os-support/solaris/sun_bell.c
@@ -64,7 +64,7 @@ xf86OSRingBell(int loudness, int pitch, int duration)
     }
 
     lastFreq = 0;
-    bzero(silence, sizeof(silence));
+    memset(silence, 0, sizeof(silence));
 
     audioFD = open(AUDIO_DEVICE, O_WRONLY | O_NONBLOCK);
     if (audioFD == -1) {
diff --git a/hw/xfree86/vbe/vbe.c b/hw/xfree86/vbe/vbe.c
index 3840bfe..2ace752 100644
--- a/hw/xfree86/vbe/vbe.c
+++ b/hw/xfree86/vbe/vbe.c
@@ -345,7 +345,7 @@ VBEGetVBEInfo(vbeInfoPtr pVbe)
     char *str;
     CARD16 major, *modes;
 
-    bzero(pVbe->memory, sizeof(VbeInfoBlock));
+    memset(pVbe->memory, 0, sizeof(VbeInfoBlock));
 
     /*
     Input:
@@ -504,7 +504,7 @@ VBEGetModeInfo(vbeInfoPtr pVbe, int mode)
 {
     VbeModeInfoBlock *block = NULL;
 
-    bzero(pVbe->memory, sizeof(VbeModeInfoBlock));
+    memset(pVbe->memory, 0, sizeof(VbeModeInfoBlock));
 
     /*
     Input:
diff --git a/mi/miarc.c b/mi/miarc.c
index 7e8ec1f..5143d2a 100644
--- a/mi/miarc.c
+++ b/mi/miarc.c
@@ -3135,9 +3135,9 @@ realFindSpan (int y)
 			free(finalSpans);
 		}
 		if ((i = finalMiny - newMiny) > 0)
-			bzero ((char *)newSpans, i * sizeof (struct finalSpan *));
+			memset((char *)newSpans, 0, i * sizeof (struct finalSpan *));
 		if ((i = newMaxy - finalMaxy) > 0)
-			bzero ((char *)(newSpans + newSize - i),
+			memset((char *)(newSpans + newSize - i), 0,
 			       i * sizeof (struct finalSpan *));
 		finalSpans = newSpans;
 		finalMaxy = newMaxy;
diff --git a/miext/cw/cw.c b/miext/cw/cw.c
index 7623de7..58816c9 100644
--- a/miext/cw/cw.c
+++ b/miext/cw/cw.c
@@ -325,7 +325,7 @@ cwCreateGC(GCPtr pGC)
     ScreenPtr	pScreen = pGC->pScreen;
     Bool	ret;
 
-    bzero(pPriv, sizeof(cwGCRec));
+    memset(pPriv, 0, sizeof(cwGCRec));
     SCREEN_PROLOGUE(pScreen, CreateGC);
 
     if ( (ret = (*pScreen->CreateGC)(pGC)) )
diff --git a/os/access.c b/os/access.c
index 2473ba4..36e1b81 100644
--- a/os/access.c
+++ b/os/access.c
@@ -311,7 +311,7 @@ ifioctl (int fd, int cmd, char *arg)
     struct strioctl ioc;
     int ret;
 
-    bzero((char *) &ioc, sizeof(ioc));
+    memset((char *) &ioc, 0, sizeof(ioc));
     ioc.ic_cmd = cmd;
     ioc.ic_timout = 0;
     if (cmd == SIOCGIFCONF)
@@ -1038,7 +1038,7 @@ ResetHosts (char *display)
 		len = sizeof(saddr.sa);
 		if (ConvertAddr (&saddr.sa, &len, (pointer *)&addr) == FamilyDECnet)
 		{
-		    bzero ((char *) &dnaddr, sizeof (dnaddr));
+		    memset((char *) &dnaddr, 0, sizeof (dnaddr));
 		    dnaddr.a_len = np->n_length;
 		    acopy (np->n_addr, dnaddr.a_addr, np->n_length);
 		    dnaddrp = &dnaddr;
diff --git a/os/connection.c b/os/connection.c
index bbcfa51..293f31a 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -183,7 +183,7 @@ struct _ct_node *ct_head[256];
 
 void InitConnectionTranslation(void)
 {
-    bzero(ct_head, sizeof(ct_head));
+    memset(ct_head, 0, sizeof(ct_head));
 }
 
 int GetConnectionTranslation(int conn)
diff --git a/os/utils.c b/os/utils.c
index 7aa392a..b4a954f 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -979,7 +979,7 @@ set_font_authorizations(char **authorizations, int *authlen, pointer client)
 
 	gethostname(hname, 1024);
 #if defined(IPv6) && defined(AF_INET6)
-	bzero(&hints, sizeof(hints));
+	memset(&hints, 0, sizeof(hints));
 	hints.ai_flags = AI_CANONNAME;
 	if (getaddrinfo(hname, NULL, &hints, &ai) == 0) {
 	    hnameptr = ai->ai_canonname;
@@ -1178,7 +1178,7 @@ SmartScheduleInit (void)
     if (SmartScheduleDisable)
 	return TRUE;
     
-    bzero ((char *) &act, sizeof(struct sigaction));
+    memset((char *) &act, 0, sizeof(struct sigaction));
 
     /* Set up the timer signal function */
     act.sa_handler = SmartScheduleTimer;
diff --git a/os/xdmauth.c b/os/xdmauth.c
index 31c1b4c..b8cbada 100644
--- a/os/xdmauth.c
+++ b/os/xdmauth.c
@@ -139,7 +139,7 @@ HexToBinary (const char *in, char *out, int len)
 void
 XdmAuthenticationInit (const char *cookie, int cookie_len)
 {
-    bzero (privateKey.data, 8);
+    memset(privateKey.data, 0, 8);
     if (!strncmp (cookie, "0x", 2) || !strncmp (cookie, "0X", 2))
     {
 	if (cookie_len > 2 + 2 * 8)
diff --git a/os/xdmcp.c b/os/xdmcp.c
index 38b2197..e03f17e 100644
--- a/os/xdmcp.c
+++ b/os/xdmcp.c
@@ -338,7 +338,7 @@ XdmcpRegisterBroadcastAddress (const struct sockaddr_in *addr)
     if (NumBroadcastAddresses >= MAX_BROADCAST)
 	return;
     bcast = &BroadcastAddresses[NumBroadcastAddresses++];
-    bzero (bcast, sizeof (struct sockaddr_in));
+    memset(bcast, 0, sizeof (struct sockaddr_in));
 #ifdef BSD44SOCKETS
     bcast->sin_len = addr->sin_len;
 #endif
@@ -1483,7 +1483,7 @@ get_addr_by_name(
     char *pport = portstr;
     int gaierr;
 
-    bzero(&hints, sizeof(hints));
+    memset(&hints, 0, sizeof(hints));
     hints.ai_socktype = socktype;
 
     if (port == 0) {
@@ -1616,7 +1616,7 @@ get_mcast_options(int argc, char **argv, int i)
     } else {
 	FatalError("Xserver: port out of range: %d\n", xdm_udp_port);
     }
-    bzero(&hints, sizeof(hints));
+    memset(&hints, 0, sizeof(hints));
     hints.ai_socktype = SOCK_DGRAM;
 
     if ((gaierr = getaddrinfo(address, portstr, &hints, &firstai)) == 0) {
diff --git a/record/record.c b/record/record.c
index 82d5f9f..5bd46c2 100644
--- a/record/record.c
+++ b/record/record.c
@@ -1495,7 +1495,7 @@ RecordAllocIntervals(SetInfoPtr psi, int nIntervals)
 			malloc(nIntervals * sizeof(RecordSetInterval));
     if (!psi->intervals)
 	return BadAlloc;
-    bzero(psi->intervals, nIntervals * sizeof(RecordSetInterval));
+    memset(psi->intervals, 0, nIntervals * sizeof(RecordSetInterval));
     psi->size = nIntervals;
     return Success;
 } /* end RecordAllocIntervals */
@@ -1669,7 +1669,7 @@ RecordRegisterClients(RecordContextPtr pContext, ClientPtr client, xRecordRegist
 	err = BadAlloc;
 	goto bailout;
     }
-    bzero(si, sizeof(SetInfoRec) * maxSets);
+    memset(si, 0, sizeof(SetInfoRec) * maxSets);
 
     /* theoretically you must do this because NULL may not be all-bits-zero */
     for (i = 0; i < maxSets; i++)
@@ -2053,7 +2053,7 @@ RecordAllocRanges(GetContextRangeInfoPtr pri, int nRanges)
 
     pri->pRanges = pNewRange;
     pri->size = newsize;
-    bzero(&pri->pRanges[pri->size - SZINCR], SZINCR * sizeof(xRecordRange));
+    memset(&pri->pRanges[pri->size - SZINCR], 0, SZINCR * sizeof(xRecordRange));
     if (pri->nRanges < nRanges)
 	pri->nRanges = nRanges;
     return Success;
diff --git a/xkb/XKBAlloc.c b/xkb/XKBAlloc.c
index 0e3c6f4..c52e091 100644
--- a/xkb/XKBAlloc.c
+++ b/xkb/XKBAlloc.c
@@ -82,7 +82,7 @@ XkbSymInterpretRec *prev_interpret;
     }
     compat->size_si= nSI;
     compat->num_si= 0;
-    bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
+    memset((char *)&compat->groups[0], 0, XkbNumKbdGroups*sizeof(XkbModsRec));
     xkb->compat= compat;
     return Success;
 }
@@ -99,7 +99,7 @@ register XkbCompatMapPtr compat;
     if (freeMap)
 	which= XkbAllCompatMask;
     if (which&XkbGroupCompatMask)
-	bzero((char *)&compat->groups[0],XkbNumKbdGroups*sizeof(XkbModsRec));
+	memset((char *)&compat->groups[0], 0, XkbNumKbdGroups*sizeof(XkbModsRec));
     if (which&XkbSymInterpMask) {
 	if ((compat->sym_interpret)&&(compat->size_si>0))
 	    free(compat->sym_interpret);
diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
index 7a3659f..f155cc8 100644
--- a/xkb/XKBGAlloc.c
+++ b/xkb/XKBGAlloc.c
@@ -478,7 +478,7 @@ _XkbGeomAlloc(	void **		old,
 
     if (*num>0) {
 	char *tmp= (char *)(*old);
-	bzero(&tmp[sz_elem*(*num)],(num_new*sz_elem));
+	memset(&tmp[sz_elem*(*num)], 0, (num_new*sz_elem));
     }
     return Success;
 }
@@ -701,7 +701,7 @@ register XkbKeyAliasPtr alias;
 	return NULL;
     for (i=0,alias=geom->key_aliases;i<geom->num_key_aliases;i++,alias++) {
 	if (strncmp(alias->alias,aliasStr,XkbKeyNameLength)==0) {
-	    bzero(alias->real,XkbKeyNameLength);
+	    memset(alias->real, 0, XkbKeyNameLength);
 	    strncpy(alias->real,realStr,XkbKeyNameLength);
 	    return alias;
 	}
@@ -711,7 +711,7 @@ register XkbKeyAliasPtr alias;
 	return NULL;
     }
     alias= &geom->key_aliases[geom->num_key_aliases];
-    bzero(alias,sizeof(XkbKeyAliasRec));
+    memset(alias, 0, sizeof(XkbKeyAliasRec));
     strncpy(alias->alias,aliasStr,XkbKeyNameLength);
     strncpy(alias->real,realStr,XkbKeyNameLength);
     geom->num_key_aliases++;
@@ -758,7 +758,7 @@ XkbOutlinePtr	outline;
 	return NULL;
     }
     outline= &shape->outlines[shape->num_outlines];
-    bzero(outline,sizeof(XkbOutlineRec));
+    memset(outline, 0, sizeof(XkbOutlineRec));
     if ((sz_points>0)&&(_XkbAllocPoints(outline,sz_points)!=Success))
 	return NULL;
     shape->num_outlines++;
@@ -783,7 +783,7 @@ register int	i;
 					(_XkbAllocShapes(geom,1)!=Success))
 	return NULL;
     shape= &geom->shapes[geom->num_shapes];
-    bzero(shape,sizeof(XkbShapeRec));
+    memset(shape, 0, sizeof(XkbShapeRec));
     if ((sz_outlines>0)&&(_XkbAllocOutlines(shape,sz_outlines)!=Success))
 	return NULL;
     shape->name= name;
@@ -801,7 +801,7 @@ XkbKeyPtr	key;
     if ((row->num_keys>=row->sz_keys)&&(_XkbAllocKeys(row,1)!=Success))
 	return NULL;
     key= &row->keys[row->num_keys++];
-    bzero(key,sizeof(XkbKeyRec));
+    memset(key, 0, sizeof(XkbKeyRec));
     return key;
 }
 
@@ -816,7 +816,7 @@ XkbRowPtr	row;
     					(_XkbAllocRows(section,1)!=Success))
 	return NULL;
     row= &section->rows[section->num_rows];
-    bzero(row,sizeof(XkbRowRec));
+    memset(row, 0, sizeof(XkbRowRec));
     if ((sz_keys>0)&&(_XkbAllocKeys(row,sz_keys)!=Success))
 	return NULL;
     section->num_rows++;
@@ -896,7 +896,7 @@ register int	i,nDoodads;
 	    return NULL;
 	doodad= &geom->doodads[geom->num_doodads++];
     }
-    bzero(doodad,sizeof(XkbDoodadRec));
+    memset(doodad, 0, sizeof(XkbDoodadRec));
     doodad->any.name= name;
     return doodad;
 }
@@ -960,7 +960,7 @@ XkbOverlayRowPtr	row;
 				(_XkbAllocOverlayRows(overlay,1)!=Success))
 	return NULL;
     row= &overlay->rows[overlay->num_rows];
-    bzero(row,sizeof(XkbOverlayRowRec));
+    memset(row, 0, sizeof(XkbOverlayRowRec));
     if ((sz_keys>0)&&(_XkbAllocOverlayKeys(row,sz_keys)!=Success))
 	return NULL;
     row->row_under= row_under;
diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c
index 27151b8..abe0018 100644
--- a/xkb/XKBMAlloc.c
+++ b/xkb/XKBMAlloc.c
@@ -84,7 +84,7 @@ XkbClientMapPtr map;
 		return BadAlloc;
 	    }
 	    map->size_types= nTotalTypes;
-	    bzero(&map->types[map->num_types], 
+	    memset(&map->types[map->num_types], 0,
 		  ((map->size_types-map->num_types)*sizeof(XkbKeyTypeRec)));
 	}
     }
@@ -177,7 +177,7 @@ XkbServerMapPtr map;
 	        return BadAlloc;
 	    }
 	    map->size_acts= need;
-	    bzero(&map->acts[map->num_acts], 
+	    memset(&map->acts[map->num_acts], 0,
 		    ((map->size_acts-map->num_acts)*sizeof(XkbAction)));
 	}
 	if (map->key_acts==NULL) {
@@ -368,7 +368,7 @@ KeyCode		matchingKeys[XkbMaxKeyCount],nMatchingKeys;
      * The possibilities marked with '+' require us to examine the key types
      * associated with each group for the key.
      */
-    bzero(matchingKeys,XkbMaxKeyCount*sizeof(KeyCode));
+    memset(matchingKeys, 0, XkbMaxKeyCount*sizeof(KeyCode));
     nMatchingKeys= 0;
     if (new_num_lvls>type->num_levels) {
 	int	 		nTotal;
@@ -461,7 +461,7 @@ KeyCode		matchingKeys[XkbMaxKeyCount],nMatchingKeys;
 	    for (g=XkbKeyNumGroups(xkb,key)-1;g>=0;g--) {
 		if (XkbKeyKeyTypeIndex(xkb,key,g)==type_ndx) {
 		    if (nClear>0)
-			bzero(&pSyms[g*width+firstClear],nClear*sizeof(KeySym));
+			memset(&pSyms[g*width+firstClear], 0, nClear*sizeof(KeySym));
 		}
 	    }
 	}
@@ -491,8 +491,8 @@ KeySym	*newSyms;
 						nOldSyms*sizeof(KeySym));
 	}
 	if ((needed-nOldSyms)>0) {
-	    bzero(&xkb->map->syms[xkb->map->num_syms+XkbKeyNumSyms(xkb,key)],
-					(needed-nOldSyms)*sizeof(KeySym));
+	    memset(&xkb->map->syms[xkb->map->num_syms+XkbKeyNumSyms(xkb, key)],
+                   0, (needed-nOldSyms)*sizeof(KeySym));
 	}
 	xkb->map->key_sym_map[key].offset = xkb->map->num_syms;
 	xkb->map->num_syms+= needed;
@@ -515,7 +515,7 @@ KeySym	*newSyms;
 	if (nCopy!=0)
 	   memcpy(&newSyms[nSyms],XkbKeySymsPtr(xkb,i),nCopy*sizeof(KeySym));
 	if (nKeySyms>nCopy)
-	    bzero(&newSyms[nSyms+nCopy],(nKeySyms-nCopy)*sizeof(KeySym));
+	    memset(&newSyms[nSyms+nCopy], 0, (nKeySyms-nCopy)*sizeof(KeySym));
 	xkb->map->key_sym_map[i].offset = nSyms;
 	nSyms+= nKeySyms;
     }
@@ -568,7 +568,7 @@ int	tmp;
 	tmp= xkb->min_key_code-minKC;
 	if (xkb->map)  {
 	    if (xkb->map->key_sym_map) {
-		bzero((char *)&xkb->map->key_sym_map[minKC],
+		memset((char *)&xkb->map->key_sym_map[minKC], 0,
 					tmp*sizeof(XkbSymMapRec));
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
@@ -578,7 +578,7 @@ int	tmp;
 		}
 	    }
 	    if (xkb->map->modmap) {
-		bzero((char *)&xkb->map->modmap[minKC],tmp);
+		memset((char *)&xkb->map->modmap[minKC], 0, tmp);
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
 		    				XkbModifierMapMask,minKC,
@@ -589,7 +589,7 @@ int	tmp;
 	}
 	if (xkb->server) {
 	    if (xkb->server->behaviors) {
-		bzero((char *)&xkb->server->behaviors[minKC],
+		memset((char *)&xkb->server->behaviors[minKC], 0,
 						tmp*sizeof(XkbBehavior));
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
@@ -599,7 +599,7 @@ int	tmp;
 		}
 	    }
 	    if (xkb->server->key_acts) {
-		bzero((char *)&xkb->server->key_acts[minKC],
+		memset((char *)&xkb->server->key_acts[minKC], 0,
 						tmp*sizeof(unsigned short));
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
@@ -609,7 +609,7 @@ int	tmp;
 		}
 	    }
 	    if (xkb->server->vmodmap) {
-		bzero((char *)&xkb->server->vmodmap[minKC],
+		memset((char *)&xkb->server->vmodmap[minKC], 0,
 						tmp*sizeof(unsigned short));
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
@@ -620,7 +620,7 @@ int	tmp;
 	    }
 	}
 	if ((xkb->names)&&(xkb->names->keys)) {
-	    bzero((char *)&xkb->names->keys[minKC],tmp*sizeof(XkbKeyNameRec));
+	    memset((char *)&xkb->names->keys[minKC], 0, tmp*sizeof(XkbKeyNameRec));
 	    if (changes) {
 		changes->names.changed= _ExtendRange(changes->names.changed,
 					XkbKeyNamesMask,minKC,
@@ -644,7 +644,7 @@ int	tmp;
 		    free(prev_key_sym_map);
 		    return BadAlloc;
 		}
-		bzero((char *)&xkb->map->key_sym_map[xkb->max_key_code],
+		memset((char *)&xkb->map->key_sym_map[xkb->max_key_code], 0,
 					tmp*sizeof(XkbSymMapRec));
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
@@ -662,7 +662,7 @@ int	tmp;
 		    free(prev_modmap);
 		    return BadAlloc;
 		}
-		bzero((char *)&xkb->map->modmap[xkb->max_key_code],tmp);
+		memset((char *)&xkb->map->modmap[xkb->max_key_code], 0, tmp);
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
 		    				XkbModifierMapMask,maxKC,
@@ -681,7 +681,7 @@ int	tmp;
 		    free(prev_behaviors);
 		    return BadAlloc;
 		}
-		bzero((char *)&xkb->server->behaviors[xkb->max_key_code],
+		memset((char *)&xkb->server->behaviors[xkb->max_key_code], 0,
 						tmp*sizeof(XkbBehavior));
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
@@ -699,7 +699,7 @@ int	tmp;
 		    free(prev_key_acts);
 		    return BadAlloc;
 		}
-		bzero((char *)&xkb->server->key_acts[xkb->max_key_code],
+		memset((char *)&xkb->server->key_acts[xkb->max_key_code], 0,
 						tmp*sizeof(unsigned short));
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
@@ -717,7 +717,7 @@ int	tmp;
 		    free(prev_vmodmap);
 		    return BadAlloc;
 		}
-		bzero((char *)&xkb->server->vmodmap[xkb->max_key_code],
+		memset((char *)&xkb->server->vmodmap[xkb->max_key_code], 0,
 						tmp*sizeof(unsigned short));
 		if (changes) {
 		    changes->map.changed= _ExtendRange(changes->map.changed,
@@ -736,7 +736,7 @@ int	tmp;
 		free(prev_keys);
 		return BadAlloc;
 	    }
-	    bzero((char *)&xkb->names->keys[xkb->max_key_code],
+	    memset((char *)&xkb->names->keys[xkb->max_key_code], 0,
 	    					tmp*sizeof(XkbKeyNameRec));
 	    if (changes) {
 		changes->names.changed= _ExtendRange(changes->names.changed,
@@ -790,7 +790,7 @@ XkbAction *newActs;
 	    memcpy(&newActs[nActs],XkbKeyActionsPtr(xkb,i),
 						nCopy*sizeof(XkbAction));
 	if (nCopy<nKeyActs)
-	    bzero(&newActs[nActs+nCopy],(nKeyActs-nCopy)*sizeof(XkbAction));
+	    memset(&newActs[nActs+nCopy], 0, (nKeyActs-nCopy)*sizeof(XkbAction));
 	xkb->server->key_acts[i]= nActs;
 	nActs+= nKeyActs;
     }
diff --git a/xkb/XKBMisc.c b/xkb/XKBMisc.c
index ee3dfcc..efe2911 100644
--- a/xkb/XKBMisc.c
+++ b/xkb/XKBMisc.c
@@ -580,7 +580,7 @@ int		width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups];
 	pSyms= XkbResizeKeySyms(xkb,key,width*nGroups);
 	if (pSyms==NULL)
 	    return BadAlloc;
-	bzero(pSyms,width*nGroups*sizeof(KeySym));
+	memset(pSyms, 0, width*nGroups*sizeof(KeySym));
 	for (i=0;(i<nGroups)&&(i<nOldGroups);i++) {
 	    pOldType= XkbKeyKeyType(xkb,key,i);
 	    pNewType= &xkb->map->types[newTypes[i]];
@@ -596,7 +596,7 @@ int		width,nOldGroups,oldWidth,newTypes[XkbNumKbdGroups];
 	    pActs= XkbResizeKeyActions(xkb,key,width*nGroups);
 	    if (pActs==NULL)
 		return BadAlloc;
-	    bzero(pActs,width*nGroups*sizeof(XkbAction));
+	    memset(pActs, 0, width*nGroups*sizeof(XkbAction));
 	    for (i=0;(i<nGroups)&&(i<nOldGroups);i++) {
 		pOldType= XkbKeyKeyType(xkb,key,i);
 		pNewType= &xkb->map->types[newTypes[i]];
diff --git a/xkb/maprules.c b/xkb/maprules.c
index 3b15a47..5aabd1c 100644
--- a/xkb/maprules.c
+++ b/xkb/maprules.c
@@ -270,7 +270,7 @@ Bool		found;
    l_ndx_present = v_ndx_present = present= 0;
    str= &line->line[1];
    len = remap->number;
-   bzero((char *)remap,sizeof(RemapSpec));
+   memset((char *)remap, 0, sizeof(RemapSpec));
    remap->number = len;
    while ((tok=_XStrtok(str," ",strtok_buf))!=NULL) {
 	found= FALSE;
@@ -412,7 +412,7 @@ Bool 		append = FALSE;
 	DebugF("Illegal line of data ignored\n");
 	return FALSE;
     }
-    bzero((char *)&tmp,sizeof(FileSpec));
+    memset((char *)&tmp, 0, sizeof(FileSpec));
     str= line->line;
     for (nread= 0;(tok=_XStrtok(str," ",strtok_buf))!=NULL;nread++) {
 	str= NULL;
@@ -495,7 +495,7 @@ static Bool
 MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
 {
 
-   bzero((char *)mdefs,sizeof(XkbRF_MultiDefsRec));
+   memset((char *)mdefs, 0, sizeof(XkbRF_MultiDefsRec));
    mdefs->model = defs->model;
    mdefs->options = _XkbDupString(defs->options);
    if (mdefs->options) squeeze_spaces(mdefs->options); 
@@ -834,7 +834,7 @@ XkbRF_GetComponents(	XkbRF_RulesPtr		rules,
 
     MakeMultiDefs(&mdefs, defs);
 
-    bzero((char *)names,sizeof(XkbComponentNamesRec));
+    memset((char *)names, 0, sizeof(XkbComponentNamesRec));
     XkbRF_ClearPartialMatches(rules);
     XkbRF_CheckApplyRules(rules, &mdefs, names, XkbRF_Normal);
     XkbRF_ApplyPartialMatches(rules, names);
@@ -876,7 +876,7 @@ XkbRF_AddRule(XkbRF_RulesPtr	rules)
 	DebugF("Allocation failure in XkbRF_AddRule\n");
 	return NULL;
     }
-    bzero((char *)&rules->rules[rules->num_rules],sizeof(XkbRF_RuleRec));
+    memset((char *)&rules->rules[rules->num_rules], 0, sizeof(XkbRF_RuleRec));
     return &rules->rules[rules->num_rules++];
 }
 
@@ -898,7 +898,7 @@ XkbRF_AddGroup(XkbRF_RulesPtr	rules)
 	return NULL;
     }
 
-    bzero((char *)&rules->groups[rules->num_groups],sizeof(XkbRF_GroupRec));
+    memset((char *)&rules->groups[rules->num_groups], 0, sizeof(XkbRF_GroupRec));
     return &rules->groups[rules->num_groups++];
 }
 
@@ -912,20 +912,20 @@ XkbRF_GroupRec  tgroup,*group;
 
     if (!(rules && file))
 	return FALSE;
-    bzero((char *)&remap,sizeof(RemapSpec));
-    bzero((char *)&tgroup,sizeof(XkbRF_GroupRec));
+    memset((char *)&remap, 0, sizeof(RemapSpec));
+    memset((char *)&tgroup, 0, sizeof(XkbRF_GroupRec));
     InitInputLine(&line);
     while (GetInputLine(file,&line,TRUE)) {
 	if (CheckLine(&line,&remap,&trule,&tgroup)) {
             if (tgroup.number) {
 	        if ((group= XkbRF_AddGroup(rules))!=NULL) {
 		    *group= tgroup;
-		    bzero((char *)&tgroup,sizeof(XkbRF_GroupRec));
+		    memset((char *)&tgroup, 0, sizeof(XkbRF_GroupRec));
 	        }
 	    } else {
 	        if ((rule= XkbRF_AddRule(rules))!=NULL) {
 		    *rule= trule;
-		    bzero((char *)&trule,sizeof(XkbRF_RuleRec));
+		    memset((char *)&trule, 0, sizeof(XkbRF_RuleRec));
 	        }
 	    }
 	}
@@ -997,7 +997,7 @@ XkbRF_GroupPtr	group;
 	    if (rule->types)	free(rule->types);
 	    if (rule->compat)	free(rule->compat);
 	    if (rule->geometry)	free(rule->geometry);
-	    bzero((char *)rule,sizeof(XkbRF_RuleRec));
+	    memset((char *)rule, 0, sizeof(XkbRF_RuleRec));
 	}
 	free(rules->rules);
 	rules->num_rules= rules->sz_rules= 0;
diff --git a/xkb/xkb.c b/xkb/xkb.c
index 0dab694..04a137f 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -557,7 +557,7 @@ ProcXkbGetState(ClientPtr client)
     CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
 
     xkb= &dev->key->xkbInfo->state;
-    bzero(&rep,sizeof(xkbGetStateReply));
+    memset(&rep, 0, sizeof(xkbGetStateReply));
     rep.type= X_Reply;
     rep.sequenceNumber= client->sequence;
     rep.length = 0;
@@ -1429,7 +1429,7 @@ ProcXkbGetMap(ClientPtr client)
     CHK_MASK_LEGAL(0x03,stuff->partial,XkbAllMapComponentsMask);
 
     xkb= dev->key->xkbInfo->desc;
-    bzero(&rep,sizeof(xkbGetMapReply));
+    memset(&rep, 0, sizeof(xkbGetMapReply));
     rep.type= X_Reply;
     rep.sequenceNumber= client->sequence;
     rep.length = (SIZEOF(xkbGetMapReply)-SIZEOF(xGenericReply))>>2;
@@ -2172,7 +2172,7 @@ unsigned	 first,last;
 
     first= req->firstKeyBehavior;
     last= req->firstKeyBehavior+req->nKeyBehaviors-1;
-    bzero(&server->behaviors[first],req->nKeyBehaviors*sizeof(XkbBehavior));
+    memset(&server->behaviors[first], 0, req->nKeyBehaviors*sizeof(XkbBehavior));
     for (i=0;i<req->totalKeyBehaviors;i++) {
 	if ((server->behaviors[wire->key].type&XkbKB_Permanent)==0) {
 	    server->behaviors[wire->key].type= wire->type;
@@ -2190,7 +2190,7 @@ unsigned	 first,last;
         else xkbi->radioGroups= calloc(1, sz);
         if (xkbi->radioGroups) {
              if (xkbi->nRadioGroups)
-                bzero(&xkbi->radioGroups[xkbi->nRadioGroups],
+                 memset(&xkbi->radioGroups[xkbi->nRadioGroups], 0,
                         (maxRG-xkbi->nRadioGroups)*sizeof(XkbRadioGroupRec));
              xkbi->nRadioGroups= maxRG;
         }
@@ -2245,7 +2245,7 @@ CARD8 *			start;
     start= wire;
     first= req->firstKeyExplicit;
     last=  req->firstKeyExplicit+req->nKeyExplicit-1;
-    bzero(&xkb->explicit[first],req->nKeyExplicit);
+    memset(&xkb->explicit[first], 0, req->nKeyExplicit);
     for (i=0;i<req->totalKeyExplicit;i++,wire+= 2) {
 	xkb->explicit[wire[0]]= wire[1];
     }
@@ -2279,7 +2279,7 @@ CARD8 *			start;
     start= wire;
     first= req->firstModMapKey;
     last=  req->firstModMapKey+req->nModMapKeys-1;
-    bzero(&xkb->modmap[first],req->nModMapKeys);
+    memset(&xkb->modmap[first], 0, req->nModMapKeys);
     for (i=0;i<req->totalModMapKeys;i++,wire+= 2) {
 	xkb->modmap[wire[0]]= wire[1];
     }
@@ -2311,7 +2311,7 @@ XkbServerMapPtr		srv = xkbi->desc->server;
 
     first= req->firstVModMapKey;
     last=  req->firstVModMapKey+req->nVModMapKeys-1;
-    bzero(&srv->vmodmap[first],req->nVModMapKeys*sizeof(unsigned short));
+    memset(&srv->vmodmap[first], 0, req->nVModMapKeys*sizeof(unsigned short));
     for (i=0;i<req->totalVModMapKeys;i++,wire++) {
 	srv->vmodmap[wire->key]= wire->vmods;
     }
@@ -2438,7 +2438,7 @@ _XkbSetMap(ClientPtr client, DeviceIntPtr dev, xkbSetMapReq *req, char *values)
     xkb = xkbi->desc;
 
     XkbSetCauseXkbReq(&cause,X_kbSetMap,client);
-    bzero(&change, sizeof(change));
+    memset(&change, 0, sizeof(change));
     sentNKN = FALSE;
     if ((xkb->min_key_code!=req->minKeyCode)||
         (xkb->max_key_code!=req->maxKeyCode)) {
@@ -2851,7 +2851,7 @@ _XkbSetCompatMap(ClientPtr client, DeviceIntPtr dev,
 	XkbEventCauseRec	cause;
 
 	XkbSetCauseXkbReq(&cause,X_kbSetCompatMap,client);
-	bzero(&change,sizeof(XkbChangesRec));
+	memset(&change, 0, sizeof(XkbChangesRec));
 	XkbUpdateActions(dev,xkb->min_key_code,XkbNumKeys(xkb),&change,&check,
 									&cause);
 	if (check)
@@ -3384,8 +3384,8 @@ _XkbSetNamedIndicator(ClientPtr client, DeviceIntPtr dev,
         statec |= ((sli->effectiveState ^ sli->explicitState) & (1 << led));
     }
 
-    bzero((char *)&ed,sizeof(xkbExtensionDeviceNotify));
-    bzero((char *)&changes,sizeof(XkbChangesRec));
+    memset((char *)&ed, 0, sizeof(xkbExtensionDeviceNotify));
+    memset((char *)&changes, 0, sizeof(XkbChangesRec));
     XkbSetCauseXkbReq(&cause,X_kbSetNamedIndicator,client);
     if (namec)
         XkbApplyLedNameChanges(dev,sli,namec,&ed,&changes,&cause);
@@ -4038,7 +4038,7 @@ _XkbSetNames(ClientPtr client, DeviceIntPtr dev, xkbSetNamesReq *stuff)
         return BadAlloc;
     }
 
-    bzero(&nn,sizeof(xkbNamesNotify));
+    memset(&nn, 0, sizeof(xkbNamesNotify));
     nn.changed= stuff->which;
     tmp = (CARD32 *)&stuff[1];
     if (stuff->which&XkbKeycodesNameMask)
@@ -4160,7 +4160,7 @@ _XkbSetNames(ClientPtr client, DeviceIntPtr dev, xkbSetNamesReq *stuff)
                 if (names->indicators[i]!=None)
                     sli->namesPresent|= bit;
             }
-            bzero(&edev,sizeof(xkbExtensionDeviceNotify));
+            memset(&edev, 0, sizeof(xkbExtensionDeviceNotify));
             edev.reason=	XkbXI_IndicatorNamesMask;
             edev.ledClass=	KbdFeedbackClass;
             edev.ledID=		dev->kbdfeed->ctrl.id;
@@ -4478,7 +4478,7 @@ xkbDoodadWireDesc *	doodadWire;
     for (i=0;i<num_doodads;i++,doodad++) {
 	doodadWire= (xkbDoodadWireDesc *)wire;
 	wire= (char *)&doodadWire[1];
-	bzero(doodadWire,SIZEOF(xkbDoodadWireDesc));
+	memset(doodadWire, 0, SIZEOF(xkbDoodadWireDesc));
 	doodadWire->any.name= doodad->any.name;
 	doodadWire->any.type= doodad->any.type;
 	doodadWire->any.priority= doodad->any.priority;
@@ -5290,7 +5290,7 @@ _XkbSetGeometry(ClientPtr client, DeviceIntPtr dev, xkbSetGeometryReq *stuff)
         XkbFreeGeometry(old,XkbGeomAllMask,TRUE);
     if (new_name) {
         xkbNamesNotify	nn;
-        bzero(&nn,sizeof(xkbNamesNotify));
+        memset(&nn, 0, sizeof(xkbNamesNotify));
         nn.changed= XkbGeometryNameMask;
         XkbSendNamesNotify(dev,&nn);
     }
@@ -5497,7 +5497,7 @@ ProcXkbListComponents(ClientPtr client)
 
     status= Success;
     str= (unsigned char *)&stuff[1];
-    bzero(&list,sizeof(XkbSrvListInfoRec));
+    memset(&list, 0, sizeof(XkbSrvListInfoRec));
     list.maxRtrn= stuff->maxNames;
     list.pattern[_XkbListKeycodes]= GetComponentSpec(&str,FALSE,&status);
     list.pattern[_XkbListTypes]= GetComponentSpec(&str,FALSE,&status);
@@ -5516,7 +5516,7 @@ ProcXkbListComponents(ClientPtr client)
 	}
 	return status;
     }
-    bzero(&rep,sizeof(xkbListComponentsReply));
+    memset(&rep, 0, sizeof(xkbListComponentsReply));
     rep.type= X_Reply;
     rep.deviceID = dev->id;
     rep.sequenceNumber = client->sequence;
@@ -5622,7 +5622,7 @@ ProcXkbGetKbdByName(ClientPtr client)
         geom_changed= FALSE;
     }
 
-    bzero(mapFile,PATH_MAX);
+    memset(mapFile, 0, PATH_MAX);
     rep.type= X_Reply;
     rep.deviceID = dev->id;
     rep.sequenceNumber = client->sequence;
@@ -5657,7 +5657,7 @@ ProcXkbGetKbdByName(ClientPtr client)
 	if (stuff->load || 
 		((rep.reported&XkbGBN_SymbolsMask) && (new->compat))) {
 	    XkbChangesRec changes;
-	    bzero(&changes,sizeof(changes));
+	    memset(&changes, 0, sizeof(changes));
 	    XkbUpdateDescActions(new,
 			new->min_key_code,XkbNumKeys(new),
 			&changes);
@@ -6121,7 +6121,7 @@ char *			str;
 	wanted&= ~XkbXI_IndicatorsMask;
 
     nameLen= XkbSizeCountedString(dev->name);
-    bzero((char *)&rep,SIZEOF(xkbGetDeviceInfoReply));
+    memset((char *)&rep, 0, SIZEOF(xkbGetDeviceInfoReply));
     rep.type = X_Reply;
     rep.deviceID= dev->id;
     rep.sequenceNumber = client->sequence;
@@ -6329,8 +6329,8 @@ xkbExtensionDeviceNotify	ed;
 XkbChangesRec			changes;
 DeviceIntPtr			kbd;
 
-    bzero((char *)&ed,sizeof(xkbExtensionDeviceNotify));
-    bzero((char *)&changes,sizeof(XkbChangesRec));
+    memset((char *)&ed, 0, sizeof(xkbExtensionDeviceNotify));
+    memset((char *)&changes, 0, sizeof(XkbChangesRec));
     XkbSetCauseXkbReq(&cause,X_kbSetDeviceInfo,client);
     ledWire= (xkbDeviceLedsWireDesc *)wire;
     for (i=0;i<num;i++) {
@@ -6351,11 +6351,11 @@ DeviceIntPtr			kbd;
 	atomWire= (CARD32 *)&ledWire[1];
 	if (changed&XkbXI_IndicatorNamesMask) {
 	    namec= sli->namesPresent|ledWire->namesPresent;
-	    bzero((char *)sli->names,XkbNumIndicators*sizeof(Atom));
+	    memset((char *)sli->names, 0, XkbNumIndicators*sizeof(Atom));
 	}
 	if (ledWire->namesPresent) {
 	    sli->namesPresent= ledWire->namesPresent;
-	    bzero((char *)sli->names,XkbNumIndicators*sizeof(Atom));
+	    memset((char *)sli->names, 0, XkbNumIndicators*sizeof(Atom));
 	    for (n=0,bit=1;n<XkbNumIndicators;n++,bit<<=1) {
 		if (ledWire->namesPresent&bit) {
 		     sli->names[n]= (Atom)*atomWire;
@@ -6369,7 +6369,7 @@ DeviceIntPtr			kbd;
 	if (changed&XkbXI_IndicatorMapsMask) {
 	    mapc= sli->mapsPresent|ledWire->mapsPresent;
 	    sli->mapsPresent= ledWire->mapsPresent;
-	    bzero((char*)sli->maps,XkbNumIndicators*sizeof(XkbIndicatorMapRec));
+	    memset((char*)sli->maps, 0, XkbNumIndicators*sizeof(XkbIndicatorMapRec));
 	}
 	if (ledWire->mapsPresent) {
 	    for (n=0,bit=1;n<XkbNumIndicators;n++,bit<<=1) {
@@ -6448,7 +6448,7 @@ _XkbSetDeviceInfoCheck(ClientPtr client, DeviceIntPtr dev,
     char                       *wire;
     xkbExtensionDeviceNotify    ed;
 
-    bzero((char *)&ed,SIZEOF(xkbExtensionDeviceNotify));
+    memset((char *)&ed, 0, SIZEOF(xkbExtensionDeviceNotify));
     ed.deviceID=	dev->id;
     wire= (char *)&stuff[1];
     if (stuff->change&XkbXI_ButtonActionsMask) {
diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c
index 3f0b766..afc44ac 100644
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@ -1032,7 +1032,7 @@ register int	i;
     xkbi->filters= realloc(xkbi->filters,
                             xkbi->szFilters * sizeof(XkbFilterRec));
     /* 6/21/93 (ef) -- XXX! deal with allocation failure */
-    bzero(&xkbi->filters[xkbi->szFilters/2],
+    memset(&xkbi->filters[xkbi->szFilters/2], 0,
             (xkbi->szFilters/2)*sizeof(XkbFilterRec));
     return &xkbi->filters[xkbi->szFilters/2];
 }
diff --git a/xkb/xkbLEDs.c b/xkb/xkbLEDs.c
index 6097f85..d75f920 100644
--- a/xkb/xkbLEDs.c
+++ b/xkb/xkbLEDs.c
@@ -263,7 +263,7 @@ unsigned			oldState;
 
     if (ed==NULL) {
 	ed= &my_ed;
-	bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
+	memset((char *)ed, 0, sizeof(xkbExtensionDeviceNotify));
     }
     else if ((ed->reason&XkbXI_IndicatorsMask)&&
 	     ((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
@@ -273,7 +273,7 @@ unsigned			oldState;
     if ((kbd==dev)&&(sli->flags&XkbSLI_IsDefault)) {
 	if (changes==NULL) {
 	    changes= &my_changes;
-	    bzero((char *)changes,sizeof(XkbChangesRec));
+	    memset((char *)changes, 0, sizeof(XkbChangesRec));
 	}
 	changes->indicators.state_changes|= affected;
     }
@@ -362,8 +362,8 @@ XkbChangesRec			changes;
 xkbExtensionDeviceNotify	ed;
 unsigned 			side_affected;
 
-    bzero((char *)&changes,sizeof(XkbChangesRec));
-    bzero((char *)&ed,sizeof(xkbExtensionDeviceNotify));
+    memset((char *)&changes, 0, sizeof(XkbChangesRec));
+    memset((char *)&ed, 0, sizeof(xkbExtensionDeviceNotify));
     sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0);
     sli->explicitState&= ~affect;
     sli->explicitState|= (affect&values);
@@ -735,7 +735,7 @@ XkbFlushLedEvents(	DeviceIntPtr			dev,
 	if (changes->indicators.state_changes)
 	    XkbDDXUpdateDeviceIndicators(dev,sli,sli->effectiveState);
 	XkbSendNotification(kbd,changes,cause);
-	bzero((char *)changes,sizeof(XkbChangesRec));
+	memset((char *)changes, 0, sizeof(XkbChangesRec));
 
 	if (XkbAX_NeedFeedback(kbd->key->xkbInfo->desc->ctrls, XkbAX_IndicatorFBMask)) {
 		if (sli->effectiveState)
@@ -751,7 +751,7 @@ XkbFlushLedEvents(	DeviceIntPtr			dev,
 		XkbDDXUpdateDeviceIndicators(dev,sli,sli->effectiveState);
 	    XkbSendExtensionDeviceNotify(dev,cause->client,ed);
 	}
-	bzero((char *)ed,sizeof(XkbExtensionDeviceNotify));
+	memset((char *)ed, 0, sizeof(XkbExtensionDeviceNotify));
     }
     return;
 }
@@ -778,7 +778,7 @@ xkbExtensionDeviceNotify	my_ed;
 
     if (ed==NULL) {
 	ed= &my_ed;
-	bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
+	memset((char *)ed, 0, sizeof(xkbExtensionDeviceNotify));
     }
     else if ((ed->reason&XkbXI_IndicatorsMask)&&
 	     ((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
@@ -788,7 +788,7 @@ xkbExtensionDeviceNotify	my_ed;
     if ((kbd==dev)&&(sli->flags&XkbSLI_IsDefault)) { 
 	if (changes==NULL) {
 	   changes= &my_changes;
-	   bzero((char *)changes,sizeof(XkbChangesRec));
+	   memset((char *)changes, 0, sizeof(XkbChangesRec));
 	}
 	changes->names.changed|= XkbIndicatorNamesMask;
 	changes->names.changed_indicators|= changed_names;
@@ -855,7 +855,7 @@ xkbExtensionDeviceNotify	my_ed;
 
     if (ed==NULL) {
 	ed= &my_ed;
-	bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
+	memset((char *)ed, 0, sizeof(xkbExtensionDeviceNotify));
     }
     else if ((ed->reason&XkbXI_IndicatorsMask)&&
 	     ((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
@@ -865,7 +865,7 @@ xkbExtensionDeviceNotify	my_ed;
     if ((kbd==dev)&&(sli->flags&XkbSLI_IsDefault)) {
 	if (changes==NULL) {
 	    changes= &my_changes;
-	    bzero((char *)changes,sizeof(XkbChangesRec));
+	    memset((char *)changes, 0, sizeof(XkbChangesRec));
 	}
 	changes->indicators.map_changes|= changed_maps;
     }
@@ -917,7 +917,7 @@ Bool				kb_changed;
 
     if (changes==NULL) {
 	changes= &my_changes;
-	bzero((char *)changes,sizeof(XkbChangesRec));
+	memset((char *)changes, 0, sizeof(XkbChangesRec));
     }
 
     kb_changed= FALSE;
@@ -943,7 +943,7 @@ Bool				kb_changed;
 
     if (ed==NULL) {
 	ed= &my_ed;
-	bzero((char *)ed,sizeof(xkbExtensionDeviceNotify));
+	memset((char *)ed, 0, sizeof(xkbExtensionDeviceNotify));
     }
     else if (affected&&(ed->reason&XkbXI_IndicatorsMask)&&
 	     ((ed->ledClass!=sli->class)||(ed->ledID!=sli->id))) {
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 87f7a0c..72dd546 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -282,7 +282,7 @@ register unsigned	key;
         register  unsigned      bit,i;
         unsigned                present;
 
-        bzero(newVMods,XkbNumVirtualMods);
+        memset(newVMods, 0, XkbNumVirtualMods);
         present= 0;
         for (key=xkb->min_key_code;key<=xkb->max_key_code;key++) {
             if (xkb->server->vmodmap[key]==0)
@@ -588,7 +588,7 @@ XkbSrvInfoPtr	xkbi = dev->key->xkbInfo;
 xkbMapNotify	mn;
 
     xkbi->desc->server->explicit[key]|= XkbExplicitAutoRepeatMask;
-    bzero(&mn,sizeof(mn));
+    memset(&mn, 0, sizeof(mn));
     mn.changed= XkbExplicitComponentsMask;
     mn.firstKeyExplicit= key;
     mn.nKeyExplicit= 1;
@@ -961,7 +961,7 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
                     if (!tmp)
                         return FALSE;
                     dst->map->types = tmp;
-                    bzero(dst->map->types + dst->map->num_types,
+                    memset(dst->map->types + dst->map->num_types, 0,
                           (src->map->num_types - dst->map->num_types) *
                             sizeof(XkbKeyTypeRec));
                 }
@@ -1426,7 +1426,7 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
             dst->geom->sz_properties = src->geom->num_properties;
 
             if (dst->geom->sz_properties > dst->geom->num_properties) {
-                bzero(dst->geom->properties + dst->geom->num_properties,
+                memset(dst->geom->properties + dst->geom->num_properties, 0,
                       (dst->geom->sz_properties - dst->geom->num_properties) *
                       sizeof(XkbPropertyRec));
             }
@@ -1504,7 +1504,7 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
             dst->geom->sz_colors = src->geom->num_colors;
 
             if (dst->geom->sz_colors > dst->geom->num_colors) {
-                bzero(dst->geom->colors + dst->geom->num_colors,
+                memset(dst->geom->colors + dst->geom->num_colors, 0,
                       (dst->geom->sz_colors - dst->geom->num_colors) *
                       sizeof(XkbColorRec));
             }
diff --git a/xkb/xkmread.c b/xkb/xkmread.c
index 5d3372d..814bb1d 100644
--- a/xkb/xkmread.c
+++ b/xkb/xkmread.c
@@ -80,7 +80,7 @@ int	newCount= *newCountRtrn;
 	oldPtr= realloc(oldPtr,newCount*elemSize);
 	if (oldPtr!=NULL) {
 	    char *tmp= (char *)oldPtr;
-	    bzero(&tmp[oldCount*elemSize],(newCount-oldCount)*elemSize);
+	    memset(&tmp[oldCount*elemSize], 0, (newCount-oldCount)*elemSize);
 	}
     }
     else if (newCount<oldCount) {
@@ -725,8 +725,8 @@ int			nRead=0;
 	    return -1;
 	}
 	nRead+= tmp*SIZEOF(xkmKeySymMapDesc);
-	bzero((char *)typeName,XkbNumKbdGroups*sizeof(Atom));
-	bzero((char *)type,XkbNumKbdGroups*sizeof(XkbKeyTypePtr));
+	memset((char *)typeName, 0, XkbNumKbdGroups*sizeof(Atom));
+	memset((char *)type, 0, XkbNumKbdGroups*sizeof(XkbKeyTypePtr));
 	if (wireMap.flags&XkmKeyHasTypes) {
 	    register int g;
 	    for (g=0;g<XkbNumKbdGroups;g++) {
commit f9810ba914877b379cb36f1b9755f7923ceca14c
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Fri Jun 4 14:26:31 2010 +0700

    xkb: Remove superfluous if(x) x = realloc(x, sz); else x = malloc(sz); logic
    
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Marcin Baczyński <marbacz at gmail.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index cef73fe..87f7a0c 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -919,11 +919,8 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->map->syms) {
             if (src->map->size_syms != dst->map->size_syms) {
-                if (dst->map->syms)
-                    tmp = realloc(dst->map->syms,
-                                   src->map->size_syms * sizeof(KeySym));
-                else
-                    tmp = malloc(src->map->size_syms * sizeof(KeySym));
+                tmp = realloc(dst->map->syms,
+                              src->map->size_syms * sizeof(KeySym));
                 if (!tmp)
                     return FALSE;
                 dst->map->syms = tmp;
@@ -941,13 +938,8 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->map->key_sym_map) {
             if (src->max_key_code != dst->max_key_code) {
-                if (dst->map->key_sym_map)
-                    tmp = realloc(dst->map->key_sym_map,
-                                   (src->max_key_code + 1) *
-                                     sizeof(XkbSymMapRec));
-                else
-                    tmp = malloc((src->max_key_code + 1) *
-                                 sizeof(XkbSymMapRec));
+                tmp = realloc(dst->map->key_sym_map,
+                              (src->max_key_code + 1) * sizeof(XkbSymMapRec));
                 if (!tmp)
                     return FALSE;
                 dst->map->key_sym_map = tmp;
@@ -1123,10 +1115,7 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->map->modmap) {
             if (src->max_key_code != dst->max_key_code) {
-                if (dst->map->modmap)
-                    tmp = realloc(dst->map->modmap, src->max_key_code + 1);
-                else
-                    tmp = malloc(src->max_key_code + 1);
+                tmp = realloc(dst->map->modmap, src->max_key_code + 1);
                 if (!tmp)
                     return FALSE;
                 dst->map->modmap = tmp;
@@ -1162,10 +1151,7 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->server->explicit) {
             if (src->max_key_code != dst->max_key_code) {
-                if (dst->server->explicit)
-                    tmp = realloc(dst->server->explicit, src->max_key_code + 1);
-                else
-                    tmp = malloc(src->max_key_code + 1);
+                tmp = realloc(dst->server->explicit, src->max_key_code + 1);
                 if (!tmp)
                     return FALSE;
                 dst->server->explicit = tmp;
@@ -1180,11 +1166,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->server->acts) {
             if (src->server->size_acts != dst->server->size_acts) {
-                if (dst->server->acts)
-                    tmp = realloc(dst->server->acts,
-                                   src->server->size_acts * sizeof(XkbAction));
-                else
-                    tmp = malloc(src->server->size_acts * sizeof(XkbAction));
+                tmp = realloc(dst->server->acts,
+                              src->server->size_acts * sizeof(XkbAction));
                 if (!tmp)
                     return FALSE;
                 dst->server->acts = tmp;
@@ -1201,13 +1184,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->server->key_acts) {
             if (src->max_key_code != dst->max_key_code) {
-                if (dst->server->key_acts)
-                    tmp = realloc(dst->server->key_acts,
-                                   (src->max_key_code + 1) *
-                                     sizeof(unsigned short));
-                else
-                    tmp = malloc((src->max_key_code + 1) *
-                                 sizeof(unsigned short));
+                tmp = realloc(dst->server->key_acts,
+                              (src->max_key_code + 1) * sizeof(unsigned short));
                 if (!tmp)
                     return FALSE;
                 dst->server->key_acts = tmp;
@@ -1222,13 +1200,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->server->behaviors) {
             if (src->max_key_code != dst->max_key_code) {
-                if (dst->server->behaviors)
-                    tmp = realloc(dst->server->behaviors,
-                                   (src->max_key_code + 1) *
-                                   sizeof(XkbBehavior));
-                else
-                    tmp = malloc((src->max_key_code + 1) *
-                                 sizeof(XkbBehavior));
+                tmp = realloc(dst->server->behaviors,
+                              (src->max_key_code + 1) * sizeof(XkbBehavior));
                 if (!tmp)
                     return FALSE;
                 dst->server->behaviors = tmp;
@@ -1245,13 +1218,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->server->vmodmap) {
             if (src->max_key_code != dst->max_key_code) {
-                if (dst->server->vmodmap)
-                    tmp = realloc(dst->server->vmodmap,
-                                   (src->max_key_code + 1) *
-                                   sizeof(unsigned short));
-                else
-                    tmp = malloc((src->max_key_code + 1) *
-                                 sizeof(unsigned short));
+                tmp = realloc(dst->server->vmodmap,
+                              (src->max_key_code + 1) * sizeof(unsigned short));
                 if (!tmp)
                     return FALSE;
                 dst->server->vmodmap = tmp;
@@ -1287,12 +1255,8 @@ _XkbCopyNames(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->names->keys) {
             if (src->max_key_code != dst->max_key_code) {
-                if (dst->names->keys)
-                    tmp = realloc(dst->names->keys, (src->max_key_code + 1) *
-                                   sizeof(XkbKeyNameRec));
-                else
-                    tmp = malloc((src->max_key_code + 1) *
-                                 sizeof(XkbKeyNameRec));
+                tmp = realloc(dst->names->keys,
+                              (src->max_key_code + 1) * sizeof(XkbKeyNameRec));
                 if (!tmp)
                     return FALSE;
                 dst->names->keys = tmp;
@@ -1307,13 +1271,9 @@ _XkbCopyNames(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->names->num_key_aliases) {
             if (src->names->num_key_aliases != dst->names->num_key_aliases) {
-                if (dst->names->key_aliases)
-                    tmp = realloc(dst->names->key_aliases,
-                                   src->names->num_key_aliases *
-                                     sizeof(XkbKeyAliasRec));
-                else
-                    tmp = malloc(src->names->num_key_aliases *
-                                 sizeof(XkbKeyAliasRec));
+                tmp = realloc(dst->names->key_aliases,
+                              src->names->num_key_aliases *
+                              sizeof(XkbKeyAliasRec));
                 if (!tmp)
                     return FALSE;
                 dst->names->key_aliases = tmp;
@@ -1329,11 +1289,8 @@ _XkbCopyNames(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->names->num_rg) {
             if (src->names->num_rg != dst->names->num_rg) {
-                if (dst->names->radio_groups)
-                    tmp = realloc(dst->names->radio_groups,
-                                   src->names->num_rg * sizeof(Atom));
-                else
-                    tmp = malloc(src->names->num_rg * sizeof(Atom));
+                tmp = realloc(dst->names->radio_groups,
+                              src->names->num_rg * sizeof(Atom));
                 if (!tmp)
                     return FALSE;
                 dst->names->radio_groups = tmp;
@@ -1383,13 +1340,8 @@ _XkbCopyCompat(XkbDescPtr src, XkbDescPtr dst)
 
         if (src->compat->sym_interpret && src->compat->num_si) {
             if (src->compat->num_si != dst->compat->size_si) {
-                if (dst->compat->sym_interpret)
-                    tmp = realloc(dst->compat->sym_interpret,
-                                   src->compat->num_si *
-                                     sizeof(XkbSymInterpretRec));
-                else
-                    tmp = malloc(src->compat->num_si *
-                                 sizeof(XkbSymInterpretRec));
+                tmp = realloc(dst->compat->sym_interpret,
+                              src->compat->num_si * sizeof(XkbSymInterpretRec));
                 if (!tmp)
                     return FALSE;
                 dst->compat->sym_interpret = tmp;
commit 77ea20895ca1d163e14c6b767d8c287c94ba3114
Author: Mikhail Gusarov <dottedmag at dottedmag.net>
Date:   Fri Jun 4 14:22:06 2010 +0700

    xkb: Remove superfluous if(p) checks around free(p)
    
    Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 0766922..cef73fe 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -933,10 +933,8 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
                    src->map->size_syms * sizeof(KeySym));
         }
         else {
-            if (dst->map->syms) {
-                free(dst->map->syms);
-                dst->map->syms = NULL;
-            }
+            free(dst->map->syms);
+            dst->map->syms = NULL;
         }
         dst->map->num_syms = src->map->num_syms;
         dst->map->size_syms = src->map->size_syms;
@@ -958,10 +956,8 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(XkbSymMapRec));
         }
         else {
-            if (dst->map->key_sym_map) {
-                free(dst->map->key_sym_map);
-                dst->map->key_sym_map = NULL;
-            }
+            free(dst->map->key_sym_map);
+            dst->map->key_sym_map = NULL;
         }
 
         if (src->map->types && src->map->num_types) {
@@ -988,15 +984,12 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
                      dst->map->types) {
                 for (i = src->map->num_types, dtype = (dst->map->types + i);
                      i < dst->map->num_types; i++, dtype++) {
-                    if (dtype->level_names)
-                        free(dtype->level_names);
+                    free(dtype->level_names);
                     dtype->level_names = NULL;
                     dtype->num_levels = 0;
                     if (dtype->map_count) {
-                        if (dtype->map)
-                            free(dtype->map);
-                        if (dtype->preserve)
-                            free(dtype->preserve);
+                        free(dtype->map);
+                        free(dtype->preserve);
                     }
                 }
             }
@@ -1099,10 +1092,8 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
                 }
                 else {
                     if (dtype->map_count && i < dst->map->num_types) {
-                        if (dtype->map)
-                            free(dtype->map);
-                        if (dtype->preserve)
-                            free(dtype->preserve);
+                        free(dtype->map);
+                        free(dtype->preserve);
                     }
                     dtype->map_count = 0;
                     dtype->map = NULL;
@@ -1117,16 +1108,15 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
             if (dst->map->types) {
                 for (i = 0, dtype = dst->map->types; i < dst->map->num_types;
                      i++, dtype++) {
-                    if (dtype->level_names)
-                        free(dtype->level_names);
+                    free(dtype->level_names);
                     if (dtype->map && dtype->map_count)
                         free(dtype->map);
                     if (dtype->preserve && dtype->map_count)
                         free(dtype->preserve);
                 }
-                free(dst->map->types);
-                dst->map->types = NULL;
             }
+            free(dst->map->types);
+            dst->map->types = NULL;
             dst->map->num_types = 0;
             dst->map->size_types = 0;
         }
@@ -1144,10 +1134,8 @@ _XkbCopyClientMap(XkbDescPtr src, XkbDescPtr dst)
             memcpy(dst->map->modmap, src->map->modmap, src->max_key_code + 1);
         }
         else {
-            if (dst->map->modmap) {
-                free(dst->map->modmap);
-                dst->map->modmap = NULL;
-            }
+            free(dst->map->modmap);
+            dst->map->modmap = NULL;
         }
     }
     else {
@@ -1186,10 +1174,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    src->max_key_code + 1);
         }
         else {
-            if (dst->server->explicit) {
-                free(dst->server->explicit);
-                dst->server->explicit = NULL;
-            }
+            free(dst->server->explicit);
+            dst->server->explicit = NULL;
         }
 
         if (src->server->acts) {
@@ -1207,10 +1193,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    src->server->size_acts * sizeof(XkbAction));
         }
         else {
-            if (dst->server->acts) {
-                free(dst->server->acts);
-                dst->server->acts = NULL;
-            }
+            free(dst->server->acts);
+            dst->server->acts = NULL;
         }
        dst->server->size_acts = src->server->size_acts;
        dst->server->num_acts = src->server->num_acts;
@@ -1232,10 +1216,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(unsigned short));
         }
         else {
-            if (dst->server->key_acts) {
-                free(dst->server->key_acts);
-                dst->server->key_acts = NULL;
-            }
+            free(dst->server->key_acts);
+            dst->server->key_acts = NULL;
         }
 
         if (src->server->behaviors) {
@@ -1255,10 +1237,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(XkbBehavior));
         }
         else {
-            if (dst->server->behaviors) {
-                free(dst->server->behaviors);
-                dst->server->behaviors = NULL;
-            }
+            free(dst->server->behaviors);
+            dst->server->behaviors = NULL;
         }
 
         memcpy(dst->server->vmods, src->server->vmods, XkbNumVirtualMods);
@@ -1280,10 +1260,8 @@ _XkbCopyServerMap(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(unsigned short));
         }
         else {
-            if (dst->server->vmodmap) {
-                free(dst->server->vmodmap);
-                dst->server->vmodmap = NULL;
-            }
+            free(dst->server->vmodmap);
+            dst->server->vmodmap = NULL;
         }
     }
     else {
@@ -1323,10 +1301,8 @@ _XkbCopyNames(XkbDescPtr src, XkbDescPtr dst)
                    (src->max_key_code + 1) * sizeof(XkbKeyNameRec));
         }
         else {
-            if (dst->names->keys) {
-                free(dst->names->keys);
-                dst->names->keys = NULL;
-            }
+            free(dst->names->keys);
+            dst->names->keys = NULL;
         }
 
         if (src->names->num_key_aliases) {
@@ -1346,10 +1322,8 @@ _XkbCopyNames(XkbDescPtr src, XkbDescPtr dst)
                    src->names->num_key_aliases * sizeof(XkbKeyAliasRec));
         }
         else {
-            if (dst->names->key_aliases) {
-                free(dst->names->key_aliases);
-                dst->names->key_aliases = NULL;
-            }
+            free(dst->names->key_aliases);
+            dst->names->key_aliases = NULL;
         }
         dst->names->num_key_aliases = src->names->num_key_aliases;
 
@@ -1368,8 +1342,7 @@ _XkbCopyNames(XkbDescPtr src, XkbDescPtr dst)
                    src->names->num_rg * sizeof(Atom));
         }
         else {
-            if (dst->names->radio_groups)
-                free(dst->names->radio_groups);
+            free(dst->names->radio_groups);
         }
         dst->names->num_rg = src->names->num_rg;
 
@@ -1750,25 +1723,18 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
                      j < dsection->num_doodads;
                      j++, ddoodad++) {
                     if (ddoodad->any.type == XkbTextDoodad) {
-                        if (ddoodad->text.text) {
-                            free(ddoodad->text.text);
-                            ddoodad->text.text = NULL;
-                        }
-                        if (ddoodad->text.font) {
-                            free(ddoodad->text.font);
-                            ddoodad->text.font = NULL;
-                        }
+                        free(ddoodad->text.text);
+                        ddoodad->text.text = NULL;
+                        free(ddoodad->text.font);
+                        ddoodad->text.font = NULL;
                      }
                      else if (ddoodad->any.type == XkbLogoDoodad) {
-                        if (ddoodad->logo.logo_name) {
-                            free(ddoodad->logo.logo_name);
-                            ddoodad->logo.logo_name = NULL;
-                        }
+                         free(ddoodad->logo.logo_name);
+                         ddoodad->logo.logo_name = NULL;
                     }
                 }
 
-                if (dsection->num_doodads)
-                    free(dsection->doodads);
+                free(dsection->doodads);
             }
 
             dst->geom->num_sections = 0;
@@ -1877,20 +1843,14 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
                  i < dst->geom->num_doodads;
                  i++, ddoodad++) {
                  if (ddoodad->any.type == XkbTextDoodad) {
-                    if (ddoodad->text.text) {
-                        free(ddoodad->text.text);
-                        ddoodad->text.text = NULL;
-                    }
-                    if (ddoodad->text.font) {
-                        free(ddoodad->text.font);
-                        ddoodad->text.font = NULL;
-                    }
+                     free(ddoodad->text.text);
+                     ddoodad->text.text = NULL;
+                     free(ddoodad->text.font);
+                     ddoodad->text.font = NULL;
                  }
                  else if (ddoodad->any.type == XkbLogoDoodad) {
-                    if (ddoodad->logo.logo_name) {
-                        free(ddoodad->logo.logo_name);
-                        ddoodad->logo.logo_name = NULL;
-                    }
+                     free(ddoodad->logo.logo_name);
+                     ddoodad->logo.logo_name = NULL;
                 }
             }
             dst->geom->num_doodads = 0;
@@ -1966,9 +1926,7 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
             dst->geom->num_key_aliases = dst->geom->sz_key_aliases;
         }
         else {
-            if (dst->geom->key_aliases) {
-                free(dst->geom->key_aliases);
-            }
+            free(dst->geom->key_aliases);
             dst->geom->key_aliases = NULL;
             dst->geom->num_key_aliases = 0;
             dst->geom->sz_key_aliases = 0;
@@ -1998,9 +1956,7 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
             dst->geom->base_color = &(dst->geom->colors[i]);
         }
         else {
-            if (dst->geom->label_font) {
-                free(dst->geom->label_font);
-            }
+            free(dst->geom->label_font);
             dst->geom->label_font = NULL;
             dst->geom->label_color = NULL;
             dst->geom->base_color = NULL;
@@ -2035,10 +1991,8 @@ _XkbCopyIndicators(XkbDescPtr src, XkbDescPtr dst)
         memcpy(dst->indicators, src->indicators, sizeof(XkbIndicatorRec));
     }
     else {
-        if (dst->indicators) {
-            free(dst->indicators);
-            dst->indicators = NULL;
-        }
+        free(dst->indicators);
+        dst->indicators = NULL;
     }
     return TRUE;
 }
@@ -2056,10 +2010,8 @@ _XkbCopyControls(XkbDescPtr src, XkbDescPtr dst)
         memcpy(dst->ctrls, src->ctrls, sizeof(XkbControlsRec));
     }
     else {
-        if (dst->ctrls) {
-            free(dst->ctrls);
-            dst->ctrls = NULL;
-        }
+        free(dst->ctrls);
+        dst->ctrls = NULL;
     }
     return TRUE;
 }
commit 5d4e2c594059ffb536c8e506c2623320d3c6a787
Merge: eacc421... 793dd39...
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Jun 5 22:20:28 2010 -0700

    Merge remote branch 'jamey/for-keith'

commit 793dd399468ff3ba22ffa9c62fa54fc87261fbe7
Author: Jamey Sharp <jamey at minilop.net>
Date:   Tue May 25 15:08:38 2010 -0700

    dmx: Split glx scalar swap variables from array swap variables.
    
    This makes hw/dmx/glxProxy/unpack.h more closely resemble glx/unpack.h,
    and fixes the "unused variable 'swapEnd'" and "unused variable 'swapPC'"
    warnings.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/dmx/glxProxy/g_renderswap.c b/hw/dmx/glxProxy/g_renderswap.c
index b6bede3..e675696 100644
--- a/hw/dmx/glxProxy/g_renderswap.c
+++ b/hw/dmx/glxProxy/g_renderswap.c
@@ -64,6 +64,7 @@ void __glXDispSwap_Color3bv(GLbyte *pc)
 void __glXDispSwap_Color3dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -79,6 +80,7 @@ void __glXDispSwap_Color3dv(GLbyte *pc)
 void __glXDispSwap_Color3fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
 }
@@ -86,6 +88,7 @@ void __glXDispSwap_Color3fv(GLbyte *pc)
 void __glXDispSwap_Color3iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 3);
 
@@ -94,6 +97,7 @@ void __glXDispSwap_Color3iv(GLbyte *pc)
 void __glXDispSwap_Color3sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
 
@@ -106,6 +110,7 @@ void __glXDispSwap_Color3ubv(GLbyte *pc)
 void __glXDispSwap_Color3uiv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 3);
 }
@@ -113,6 +118,7 @@ void __glXDispSwap_Color3uiv(GLbyte *pc)
 void __glXDispSwap_Color3usv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
 }
@@ -124,6 +130,7 @@ void __glXDispSwap_Color4bv(GLbyte *pc)
 void __glXDispSwap_Color4dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -138,6 +145,7 @@ void __glXDispSwap_Color4dv(GLbyte *pc)
 void __glXDispSwap_Color4fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 4);
 
@@ -146,6 +154,7 @@ void __glXDispSwap_Color4fv(GLbyte *pc)
 void __glXDispSwap_Color4iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 4);
 
@@ -154,6 +163,7 @@ void __glXDispSwap_Color4iv(GLbyte *pc)
 void __glXDispSwap_Color4sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
 
@@ -167,6 +177,7 @@ void __glXDispSwap_Color4ubv(GLbyte *pc)
 void __glXDispSwap_Color4uiv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 4);
 
@@ -175,6 +186,7 @@ void __glXDispSwap_Color4uiv(GLbyte *pc)
 void __glXDispSwap_Color4usv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
 
@@ -191,6 +203,7 @@ void __glXDispSwap_End(GLbyte *pc)
 void __glXDispSwap_Indexdv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -206,6 +219,7 @@ void __glXDispSwap_Indexdv(GLbyte *pc)
 void __glXDispSwap_Indexfv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 1);
 
@@ -214,6 +228,7 @@ void __glXDispSwap_Indexfv(GLbyte *pc)
 void __glXDispSwap_Indexiv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 1);
 
@@ -222,6 +237,7 @@ void __glXDispSwap_Indexiv(GLbyte *pc)
 void __glXDispSwap_Indexsv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 1);
 
@@ -234,6 +250,7 @@ void __glXDispSwap_Normal3bv(GLbyte *pc)
 void __glXDispSwap_Normal3dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -249,6 +266,7 @@ void __glXDispSwap_Normal3dv(GLbyte *pc)
 void __glXDispSwap_Normal3fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
 
@@ -257,6 +275,7 @@ void __glXDispSwap_Normal3fv(GLbyte *pc)
 void __glXDispSwap_Normal3iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 3);
 
@@ -265,6 +284,7 @@ void __glXDispSwap_Normal3iv(GLbyte *pc)
 void __glXDispSwap_Normal3sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
 
@@ -273,6 +293,7 @@ void __glXDispSwap_Normal3sv(GLbyte *pc)
 void __glXDispSwap_RasterPos2dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -288,6 +309,7 @@ void __glXDispSwap_RasterPos2dv(GLbyte *pc)
 void __glXDispSwap_RasterPos2fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
 
@@ -296,6 +318,7 @@ void __glXDispSwap_RasterPos2fv(GLbyte *pc)
 void __glXDispSwap_RasterPos2iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 2);
 
@@ -304,6 +327,7 @@ void __glXDispSwap_RasterPos2iv(GLbyte *pc)
 void __glXDispSwap_RasterPos2sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 2);
 
@@ -312,6 +336,7 @@ void __glXDispSwap_RasterPos2sv(GLbyte *pc)
 void __glXDispSwap_RasterPos3dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -327,6 +352,7 @@ void __glXDispSwap_RasterPos3dv(GLbyte *pc)
 void __glXDispSwap_RasterPos3fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
 
@@ -335,6 +361,7 @@ void __glXDispSwap_RasterPos3fv(GLbyte *pc)
 void __glXDispSwap_RasterPos3iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 3);
 
@@ -343,6 +370,7 @@ void __glXDispSwap_RasterPos3iv(GLbyte *pc)
 void __glXDispSwap_RasterPos3sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
 
@@ -351,6 +379,7 @@ void __glXDispSwap_RasterPos3sv(GLbyte *pc)
 void __glXDispSwap_RasterPos4dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -366,6 +395,7 @@ void __glXDispSwap_RasterPos4dv(GLbyte *pc)
 void __glXDispSwap_RasterPos4fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 4);
 
@@ -374,6 +404,7 @@ void __glXDispSwap_RasterPos4fv(GLbyte *pc)
 void __glXDispSwap_RasterPos4iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 4);
 
@@ -382,6 +413,7 @@ void __glXDispSwap_RasterPos4iv(GLbyte *pc)
 void __glXDispSwap_RasterPos4sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
 
@@ -390,6 +422,7 @@ void __glXDispSwap_RasterPos4sv(GLbyte *pc)
 void __glXDispSwap_Rectdv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -406,6 +439,7 @@ void __glXDispSwap_Rectdv(GLbyte *pc)
 void __glXDispSwap_Rectfv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
 	__GLX_SWAP_FLOAT_ARRAY(pc + 8, 2);
@@ -415,6 +449,7 @@ void __glXDispSwap_Rectfv(GLbyte *pc)
 void __glXDispSwap_Rectiv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 2);
 	__GLX_SWAP_INT_ARRAY(pc + 8, 2);
@@ -424,6 +459,7 @@ void __glXDispSwap_Rectiv(GLbyte *pc)
 void __glXDispSwap_Rectsv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 2);
 	__GLX_SWAP_SHORT_ARRAY(pc + 4, 2);
@@ -433,6 +469,7 @@ void __glXDispSwap_Rectsv(GLbyte *pc)
 void __glXDispSwap_TexCoord1dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -448,6 +485,7 @@ void __glXDispSwap_TexCoord1dv(GLbyte *pc)
 void __glXDispSwap_TexCoord1fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 1);
 
@@ -456,6 +494,7 @@ void __glXDispSwap_TexCoord1fv(GLbyte *pc)
 void __glXDispSwap_TexCoord1iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 1);
 
@@ -464,6 +503,7 @@ void __glXDispSwap_TexCoord1iv(GLbyte *pc)
 void __glXDispSwap_TexCoord1sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 1);
 
@@ -472,6 +512,7 @@ void __glXDispSwap_TexCoord1sv(GLbyte *pc)
 void __glXDispSwap_TexCoord2dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -487,6 +528,7 @@ void __glXDispSwap_TexCoord2dv(GLbyte *pc)
 void __glXDispSwap_TexCoord2fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
 
@@ -495,6 +537,7 @@ void __glXDispSwap_TexCoord2fv(GLbyte *pc)
 void __glXDispSwap_TexCoord2iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 2);
 
@@ -503,6 +546,7 @@ void __glXDispSwap_TexCoord2iv(GLbyte *pc)
 void __glXDispSwap_TexCoord2sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 2);
 
@@ -511,6 +555,7 @@ void __glXDispSwap_TexCoord2sv(GLbyte *pc)
 void __glXDispSwap_TexCoord3dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -526,6 +571,7 @@ void __glXDispSwap_TexCoord3dv(GLbyte *pc)
 void __glXDispSwap_TexCoord3fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
 
@@ -534,6 +580,7 @@ void __glXDispSwap_TexCoord3fv(GLbyte *pc)
 void __glXDispSwap_TexCoord3iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 3);
 
@@ -542,6 +589,7 @@ void __glXDispSwap_TexCoord3iv(GLbyte *pc)
 void __glXDispSwap_TexCoord3sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
 
@@ -550,6 +598,7 @@ void __glXDispSwap_TexCoord3sv(GLbyte *pc)
 void __glXDispSwap_TexCoord4dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -565,6 +614,7 @@ void __glXDispSwap_TexCoord4dv(GLbyte *pc)
 void __glXDispSwap_TexCoord4fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 4);
 
@@ -573,6 +623,7 @@ void __glXDispSwap_TexCoord4fv(GLbyte *pc)
 void __glXDispSwap_TexCoord4iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 4);
 
@@ -581,6 +632,7 @@ void __glXDispSwap_TexCoord4iv(GLbyte *pc)
 void __glXDispSwap_TexCoord4sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
 
@@ -589,6 +641,7 @@ void __glXDispSwap_TexCoord4sv(GLbyte *pc)
 void __glXDispSwap_Vertex2dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -604,6 +657,7 @@ void __glXDispSwap_Vertex2dv(GLbyte *pc)
 void __glXDispSwap_Vertex2fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
 
@@ -612,6 +666,7 @@ void __glXDispSwap_Vertex2fv(GLbyte *pc)
 void __glXDispSwap_Vertex2iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 2);
 
@@ -620,6 +675,7 @@ void __glXDispSwap_Vertex2iv(GLbyte *pc)
 void __glXDispSwap_Vertex2sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 2);
 
@@ -628,6 +684,7 @@ void __glXDispSwap_Vertex2sv(GLbyte *pc)
 void __glXDispSwap_Vertex3dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -643,6 +700,7 @@ void __glXDispSwap_Vertex3dv(GLbyte *pc)
 void __glXDispSwap_Vertex3fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 3);
 
@@ -651,6 +709,7 @@ void __glXDispSwap_Vertex3fv(GLbyte *pc)
 void __glXDispSwap_Vertex3iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 3);
 
@@ -659,6 +718,7 @@ void __glXDispSwap_Vertex3iv(GLbyte *pc)
 void __glXDispSwap_Vertex3sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 3);
 
@@ -667,6 +727,7 @@ void __glXDispSwap_Vertex3sv(GLbyte *pc)
 void __glXDispSwap_Vertex4dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -682,6 +743,7 @@ void __glXDispSwap_Vertex4dv(GLbyte *pc)
 void __glXDispSwap_Vertex4fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 4);
 
@@ -690,6 +752,7 @@ void __glXDispSwap_Vertex4fv(GLbyte *pc)
 void __glXDispSwap_Vertex4iv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT_ARRAY(pc + 0, 4);
 
@@ -698,6 +761,7 @@ void __glXDispSwap_Vertex4iv(GLbyte *pc)
 void __glXDispSwap_Vertex4sv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_SHORT_ARRAY(pc + 0, 4);
 
@@ -706,6 +770,7 @@ void __glXDispSwap_Vertex4sv(GLbyte *pc)
 void __glXDispSwap_ClipPlane(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -750,6 +815,7 @@ void __glXDispSwap_Fogfv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	pname = *(GLenum *)(pc + 0);
@@ -773,6 +839,7 @@ void __glXDispSwap_Fogiv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	pname = *(GLenum *)(pc + 0);
@@ -814,6 +881,7 @@ void __glXDispSwap_Lightfv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -839,6 +907,7 @@ void __glXDispSwap_Lightiv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -863,6 +932,7 @@ void __glXDispSwap_LightModelfv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	pname = *(GLenum *)(pc + 0);
@@ -886,6 +956,7 @@ void __glXDispSwap_LightModeliv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	pname = *(GLenum *)(pc + 0);
@@ -927,6 +998,7 @@ void __glXDispSwap_Materialfv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -952,6 +1024,7 @@ void __glXDispSwap_Materialiv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -1013,6 +1086,7 @@ void __glXDispSwap_TexParameterfv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -1038,6 +1112,7 @@ void __glXDispSwap_TexParameteriv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -1063,6 +1138,7 @@ void __glXDispSwap_TexEnvfv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -1088,6 +1164,7 @@ void __glXDispSwap_TexEnviv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -1121,6 +1198,7 @@ void __glXDispSwap_TexGendv(GLbyte *pc)
 	GLint cmdlen;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -1154,6 +1232,7 @@ void __glXDispSwap_TexGenfv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -1179,6 +1258,7 @@ void __glXDispSwap_TexGeniv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -1414,6 +1494,7 @@ void __glXDispSwap_MapGrid2f(GLbyte *pc)
 void __glXDispSwap_EvalCoord1dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -1429,6 +1510,7 @@ void __glXDispSwap_EvalCoord1dv(GLbyte *pc)
 void __glXDispSwap_EvalCoord1fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 1);
 
@@ -1437,6 +1519,7 @@ void __glXDispSwap_EvalCoord1fv(GLbyte *pc)
 void __glXDispSwap_EvalCoord2dv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -1452,6 +1535,7 @@ void __glXDispSwap_EvalCoord2dv(GLbyte *pc)
 void __glXDispSwap_EvalCoord2fv(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 2);
 
@@ -1581,6 +1665,7 @@ void __glXDispSwap_PixelMapfv(GLbyte *pc)
 {
 	GLint mapsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	mapsize = *(GLint *)(pc + 4);
@@ -1593,6 +1678,7 @@ void __glXDispSwap_PixelMapuiv(GLbyte *pc)
 {
 	GLint mapsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	mapsize = *(GLint *)(pc + 4);
@@ -1605,6 +1691,7 @@ void __glXDispSwap_PixelMapusv(GLbyte *pc)
 {
 	GLint mapsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	mapsize = *(GLint *)(pc + 4);
@@ -1676,6 +1763,7 @@ void __glXDispSwap_LoadIdentity(GLbyte *pc)
 void __glXDispSwap_LoadMatrixf(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 16);
 
@@ -1684,6 +1772,7 @@ void __glXDispSwap_LoadMatrixf(GLbyte *pc)
 void __glXDispSwap_LoadMatrixd(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -1707,6 +1796,7 @@ void __glXDispSwap_MatrixMode(GLbyte *pc)
 void __glXDispSwap_MultMatrixf(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_FLOAT_ARRAY(pc + 0, 16);
 
@@ -1715,6 +1805,7 @@ void __glXDispSwap_MultMatrixf(GLbyte *pc)
 void __glXDispSwap_MultMatrixd(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -1928,6 +2019,7 @@ void __glXDispSwap_PrioritizeTextures(GLbyte *pc)
 {
 	GLsizei n;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	n = *(GLsizei *)(pc + 0);
@@ -1964,6 +2056,7 @@ void __glXDispSwap_ColorTableParameterfv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -1979,6 +2072,7 @@ void __glXDispSwap_ColorTableParameteriv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -2028,6 +2122,7 @@ void __glXDispSwap_ConvolutionParameterfv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -2053,6 +2148,7 @@ void __glXDispSwap_ConvolutionParameteriv(GLbyte *pc)
 	GLenum pname;
 	GLint compsize;
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 4);
 	pname = *(GLenum *)(pc + 4);
@@ -2150,6 +2246,7 @@ void __glXDispSwap_ActiveTextureARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord1dvARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -2166,6 +2263,7 @@ void __glXDispSwap_MultiTexCoord1dvARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord1fvARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_FLOAT_ARRAY(pc + 4, 1);
@@ -2175,6 +2273,7 @@ void __glXDispSwap_MultiTexCoord1fvARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord1ivARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_INT_ARRAY(pc + 4, 1);
@@ -2184,6 +2283,7 @@ void __glXDispSwap_MultiTexCoord1ivARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord1svARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_SHORT_ARRAY(pc + 4, 1);
@@ -2193,6 +2293,7 @@ void __glXDispSwap_MultiTexCoord1svARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord2dvARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -2209,6 +2310,7 @@ void __glXDispSwap_MultiTexCoord2dvARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord2fvARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_FLOAT_ARRAY(pc + 4, 2);
@@ -2218,6 +2320,7 @@ void __glXDispSwap_MultiTexCoord2fvARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord2ivARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_INT_ARRAY(pc + 4, 2);
@@ -2227,6 +2330,7 @@ void __glXDispSwap_MultiTexCoord2ivARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord2svARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_SHORT_ARRAY(pc + 4, 2);
@@ -2236,6 +2340,7 @@ void __glXDispSwap_MultiTexCoord2svARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord3dvARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -2252,6 +2357,7 @@ void __glXDispSwap_MultiTexCoord3dvARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord3fvARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_FLOAT_ARRAY(pc + 4, 3);
@@ -2261,6 +2367,7 @@ void __glXDispSwap_MultiTexCoord3fvARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord3ivARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_INT_ARRAY(pc + 4, 3);
@@ -2270,6 +2377,7 @@ void __glXDispSwap_MultiTexCoord3ivARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord3svARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_SHORT_ARRAY(pc + 4, 3);
@@ -2279,6 +2387,7 @@ void __glXDispSwap_MultiTexCoord3svARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord4dvARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 
 #ifdef __GLX_ALIGN64
@@ -2295,6 +2404,7 @@ void __glXDispSwap_MultiTexCoord4dvARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord4fvARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_FLOAT_ARRAY(pc + 4, 4);
@@ -2304,6 +2414,7 @@ void __glXDispSwap_MultiTexCoord4fvARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord4ivARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_INT_ARRAY(pc + 4, 4);
@@ -2313,6 +2424,7 @@ void __glXDispSwap_MultiTexCoord4ivARB(GLbyte *pc)
 void __glXDispSwap_MultiTexCoord4svARB(GLbyte *pc)
 {
 	__GLX_DECLARE_SWAP_VARIABLES;
+	__GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
 	__GLX_SWAP_INT(pc + 0);
 	__GLX_SWAP_SHORT_ARRAY(pc + 4, 4);
diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index 389aa3d..c559ce7 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -2841,6 +2841,7 @@ int __glXGetFBConfigs(__GLXclientState *cl, GLbyte *pc)
 
 	if (client->swapped) {
 	    __GLX_DECLARE_SWAP_VARIABLES;
+	    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 	    __GLX_SWAP_INT_ARRAY((int *)buf, 2*numAttribs);
 	}
 	WriteToClient(client, 2*numAttribs * __GLX_SIZE_CARD32, (char *)buf);
diff --git a/hw/dmx/glxProxy/glxcmdsswap.c b/hw/dmx/glxProxy/glxcmdsswap.c
index b3720f6..960c60d 100644
--- a/hw/dmx/glxProxy/glxcmdsswap.c
+++ b/hw/dmx/glxProxy/glxcmdsswap.c
@@ -248,6 +248,7 @@ int __glXSwapGetVisualConfigs(__GLXclientState *cl, GLbyte *pc)
     unsigned int screen;
     int i, p;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     __GLX_SWAP_INT(&req->screen);
     screen = req->screen;
@@ -481,6 +482,7 @@ void glxSwapQueryExtensionsStringReply(ClientPtr client,
 {
     int length = reply->length;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
@@ -507,6 +509,7 @@ void __glXSwapQueryContextInfoEXTReply(ClientPtr client, xGLXQueryContextInfoEXT
 {
     int length = reply->length;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
@@ -521,6 +524,7 @@ void __glXSwapQueryContextReply(ClientPtr client,
 {
     int length = reply->length;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
@@ -533,6 +537,7 @@ void __glXSwapGetDrawableAttributesReply(ClientPtr client,
                                  xGLXGetDrawableAttributesReply *reply, int *buf) 
 {
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->numAttribs);
@@ -564,6 +569,7 @@ int __glXSwapRender(__GLXclientState *cl, GLbyte *pc)
     __GLXrenderHeader *hdr;
     ClientPtr client = cl->client;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     /*
     ** NOTE: much of this code also appears in the nonswapping version of this
@@ -647,6 +653,7 @@ int __glXSwapRenderLarge(__GLXclientState *cl, GLbyte *pc)
     xGLXRenderLargeReq *req;
     __GLXrenderLargeHeader *hdr;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     req = (xGLXRenderLargeReq *) pc;
     __GLX_SWAP_SHORT(&req->length);
@@ -1003,6 +1010,7 @@ int __glXSwapCreatePbuffer(__GLXclientState *cl, GLbyte *pc)
     xGLXCreatePbufferReq *req = (xGLXCreatePbufferReq *)pc;
     int nattr = req->numAttribs;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     __GLX_SWAP_SHORT(&req->length);
     __GLX_SWAP_INT(&req->screen);
@@ -1040,6 +1048,7 @@ int __glXSwapChangeDrawableAttributes(__GLXclientState *cl, GLbyte *pc)
 {
    xGLXChangeDrawableAttributesReq *req = (xGLXChangeDrawableAttributesReq *)pc;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     __GLX_SWAP_SHORT(&req->length);
     __GLX_SWAP_INT(&req->drawable);
diff --git a/hw/dmx/glxProxy/glxsingle.c b/hw/dmx/glxProxy/glxsingle.c
index a076134..7a732cc 100644
--- a/hw/dmx/glxProxy/glxsingle.c
+++ b/hw/dmx/glxProxy/glxsingle.c
@@ -397,6 +397,7 @@ int __glXForwardSingleReqSwap( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXSingleReq *req = (xGLXSingleReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->contextTag);
@@ -420,6 +421,7 @@ int __glXForwardPipe0WithReplySwap( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXSingleReq *req = (xGLXSingleReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->contextTag);
@@ -443,6 +445,7 @@ int __glXForwardPipe0WithReplySwapsv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXSingleReq *req = (xGLXSingleReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->contextTag);
@@ -467,6 +470,7 @@ int __glXForwardPipe0WithReplySwapiv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXSingleReq *req = (xGLXSingleReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->contextTag);
@@ -491,6 +495,7 @@ int __glXForwardPipe0WithReplySwapdv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXSingleReq *req = (xGLXSingleReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->contextTag);
@@ -515,6 +520,7 @@ int __glXForwardAllWithReplySwap( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXSingleReq *req = (xGLXSingleReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->contextTag);
@@ -539,6 +545,7 @@ int __glXForwardAllWithReplySwapsv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXSingleReq *req = (xGLXSingleReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->contextTag);
@@ -563,6 +570,7 @@ int __glXForwardAllWithReplySwapiv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXSingleReq *req = (xGLXSingleReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->contextTag);
@@ -587,6 +595,7 @@ int __glXForwardAllWithReplySwapdv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXSingleReq *req = (xGLXSingleReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->contextTag);
diff --git a/hw/dmx/glxProxy/glxvendor.c b/hw/dmx/glxProxy/glxvendor.c
index cf864c2..5e0fb88 100644
--- a/hw/dmx/glxProxy/glxvendor.c
+++ b/hw/dmx/glxProxy/glxvendor.c
@@ -392,6 +392,7 @@ int __glXVForwardPipe0WithReplySwap( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->vendorCode);
@@ -416,6 +417,7 @@ int __glXVForwardPipe0WithReplySwapsv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->vendorCode);
@@ -440,6 +442,7 @@ int __glXVForwardPipe0WithReplySwapiv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->vendorCode);
@@ -464,6 +467,7 @@ int __glXVForwardPipe0WithReplySwapdv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->vendorCode);
@@ -488,6 +492,7 @@ int __glXVForwardAllWithReplySwap( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->vendorCode);
@@ -512,6 +517,7 @@ int __glXVForwardAllWithReplySwapsv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->vendorCode);
@@ -536,6 +542,7 @@ int __glXVForwardAllWithReplySwapiv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->vendorCode);
@@ -560,6 +567,7 @@ int __glXVForwardAllWithReplySwapdv( __GLXclientState *cl, GLbyte *pc )
 {
    xGLXVendorPrivateReq *req = (xGLXVendorPrivateReq *)pc;
    __GLX_DECLARE_SWAP_VARIABLES;
+   __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->vendorCode);
diff --git a/hw/dmx/glxProxy/render2swap.c b/hw/dmx/glxProxy/render2swap.c
index 0daeed1..5754ff4 100644
--- a/hw/dmx/glxProxy/render2swap.c
+++ b/hw/dmx/glxProxy/render2swap.c
@@ -69,6 +69,7 @@ void __glXDispSwap_Map1f(GLbyte *pc)
     GLenum target;
     GLint compsize;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     __GLX_SWAP_INT(pc + 0);
     __GLX_SWAP_INT(pc + 12);
@@ -99,6 +100,7 @@ void __glXDispSwap_Map2f(GLbyte *pc)
     GLenum target;
     GLint compsize;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     __GLX_SWAP_INT(pc + 0);
     __GLX_SWAP_INT(pc + 12);
@@ -137,6 +139,7 @@ void __glXDispSwap_Map1d(GLbyte *pc)
     GLenum target;
     GLdouble u1, u2, *points;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     __GLX_SWAP_DOUBLE(pc + 0);
     __GLX_SWAP_DOUBLE(pc + 8);
@@ -179,6 +182,7 @@ void __glXDispSwap_Map2d(GLbyte *pc)
     GLint uorder, vorder, ustride, vstride, k, compsize;
     GLenum target;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     __GLX_SWAP_DOUBLE(pc + 0);
     __GLX_SWAP_DOUBLE(pc + 8);
@@ -228,6 +232,7 @@ void __glXDispSwap_CallLists(GLbyte *pc)
     GLenum type;
     GLsizei n;
     __GLX_DECLARE_SWAP_VARIABLES;
+    __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
 
     __GLX_SWAP_INT(pc + 4);
     __GLX_SWAP_INT(pc + 0);
diff --git a/hw/dmx/glxProxy/unpack.h b/hw/dmx/glxProxy/unpack.h
index 880f9ae..f34b6fd 100644
--- a/hw/dmx/glxProxy/unpack.h
+++ b/hw/dmx/glxProxy/unpack.h
@@ -138,7 +138,9 @@ extern xGLXSingleReply __glXReply;
 ** conceivably be replaced with routines that do the job faster.
 */
 #define __GLX_DECLARE_SWAP_VARIABLES \
-	GLbyte sw; \
+	GLbyte sw
+
+#define __GLX_DECLARE_SWAP_ARRAY_VARIABLES \
   	GLbyte *swapPC;		\
   	GLbyte *swapEnd
 
commit eacc42132ed0f1e8f4a4d65a4b6637ab06f7e2aa
Author: Kim Woelders <kim at woelders.dk>
Date:   Fri Jun 4 20:20:47 2010 +0200

    dix: Remove test for obsolete NO_XINERAMA_PORT macro.
    
    Signed-off-by: Kim Woelders <kim at woelders.dk>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/window.c b/dix/window.c
index 8ccbf65..8f3ffa3 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -3015,9 +3015,8 @@ void
 SendVisibilityNotify(WindowPtr pWin)
 {
     xEvent event;
-#ifndef NO_XINERAMA_PORT
     unsigned int visibility = pWin->visibility;
-#endif
+
     if (!MapUnmapEventsEnabled(pWin))
         return;
 #ifdef PANORAMIX
commit a0fe6987b55b5326157b50e169b8d6b9ae26a1ae
Author: Jamey Sharp <jamey at minilop.net>
Date:   Sat Jun 5 20:55:29 2010 -0700

    Clean up after removal of screen parameters from region macros.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 457e071..3cd2969 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -620,8 +620,7 @@ int PanoramiXTranslateCoords(ClientPtr client)
 		 * borderSize
 		 */
 		&& (!wBoundingShape(pWin) ||
-		    RegionContainsPoint(
-					wBoundingShape(pWin), 
+		    RegionContainsPoint(wBoundingShape(pWin),
 					x - pWin->drawable.x, 
 					y - pWin->drawable.y, &box))
 		)
@@ -1136,10 +1135,9 @@ int PanoramiXCopyArea(ClientPtr client)
 	}
 
 	if(pGC->graphicsExposures) {
-	    ScreenPtr pScreen = pDst->pScreen;
 	    Bool overlap;
 	    RegionValidate(&totalReg, &overlap);
-	    (*pScreen->SendGraphicsExpose)(
+	    (*pDst->pScreen->SendGraphicsExpose)(
 		client, &totalReg, stuff->dstDrawable, X_CopyArea, 0);
 	    RegionUninit(&totalReg);
 	}
@@ -1242,10 +1240,9 @@ int PanoramiXCopyPlane(ClientPtr client)
     }
 
     if(pGC->graphicsExposures) {
-	ScreenPtr pScreen = pdstDraw->pScreen;
 	Bool overlap;
 	RegionValidate(&totalReg, &overlap);
-	(*pScreen->SendGraphicsExpose)(
+	(*pdstDraw->pScreen->SendGraphicsExpose)(
 		client, &totalReg, stuff->dstDrawable, X_CopyPlane, 0);
 	RegionUninit(&totalReg);
     }
diff --git a/Xext/shape.c b/Xext/shape.c
index fb5b9a7..33c0cb3 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -150,8 +150,6 @@ RegionOperate (
 	int xoff, int yoff,
 	CreateDftPtr create)
 {
-    ScreenPtr	pScreen = pWin->drawable.pScreen;
-
     if (srcRgn && (xoff || yoff))
 	RegionTranslate(srcRgn, xoff, yoff);
     if (!pWin->parent)
@@ -220,7 +218,7 @@ RegionOperate (
     }
     if (srcRgn)
 	RegionDestroy(srcRgn);
-    (*pScreen->SetShape) (pWin, kind);
+    (*pWin->drawable.pScreen->SetShape) (pWin, kind);
     SendShapeNotify (pWin, kind);
     return Success;
 }
@@ -281,7 +279,6 @@ static int
 ProcShapeRectangles (ClientPtr client)
 {
     WindowPtr		pWin;
-    ScreenPtr		pScreen;
     REQUEST(xShapeRectanglesReq);
     xRectangle		*prects;
     int		        nrects, ctype, rc;
@@ -314,7 +311,6 @@ ProcShapeRectangles (ClientPtr client)
 	client->errorValue = stuff->ordering;
         return BadValue;
     }
-    pScreen = pWin->drawable.pScreen;
     nrects = ((stuff->length  << 2) - sizeof(xShapeRectanglesReq));
     if (nrects & 4)
 	return BadLength;
@@ -489,7 +485,6 @@ static int
 ProcShapeCombine (ClientPtr client)
 {
     WindowPtr		pSrcWin, pDestWin;
-    ScreenPtr		pScreen;
     REQUEST(xShapeCombineReq);
     RegionPtr		srcRgn;
     RegionPtr		*destRgn;
@@ -519,7 +514,6 @@ ProcShapeCombine (ClientPtr client)
 	client->errorValue = stuff->destKind;
 	return BadValue;
     }
-    pScreen = pDestWin->drawable.pScreen;
 
     rc = dixLookupWindow(&pSrcWin, stuff->src, client, DixGetAttrAccess);
     if (rc != Success)
@@ -541,7 +535,7 @@ ProcShapeCombine (ClientPtr client)
 	client->errorValue = stuff->srcKind;
 	return BadValue;
     }
-    if (pSrcWin->drawable.pScreen != pScreen)
+    if (pSrcWin->drawable.pScreen != pDestWin->drawable.pScreen)
     {
 	return BadMatch;
     }
@@ -614,7 +608,6 @@ static int
 ProcShapeOffset (ClientPtr client)
 {
     WindowPtr		pWin;
-    ScreenPtr		pScreen;
     REQUEST(xShapeOffsetReq);
     RegionPtr		srcRgn;
     int			rc;
@@ -638,11 +631,10 @@ ProcShapeOffset (ClientPtr client)
 	client->errorValue = stuff->destKind;
 	return BadValue;
     }
-    pScreen = pWin->drawable.pScreen;
     if (srcRgn)
     {
         RegionTranslate(srcRgn, stuff->xOff, stuff->yOff);
-        (*pScreen->SetShape) (pWin, stuff->destKind);
+        (*pWin->drawable.pScreen->SetShape) (pWin, stuff->destKind);
     }
     SendShapeNotify (pWin, (int)stuff->destKind);
     return Success;
diff --git a/Xext/xace.c b/Xext/xace.c
index 07e3da5..94b5b37 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -243,14 +243,11 @@ XaceCensorImage(
 	unsigned int format,
 	char *pBuf)
 {
-    ScreenPtr pScreen;
     RegionRec imageRegion;  /* region representing x,y,w,h */
     RegionRec censorRegion; /* region to obliterate */
     BoxRec imageBox;
     int nRects;
 
-    pScreen = pDraw->pScreen;
-
     imageBox.x1 = x;
     imageBox.y1 = y;
     imageBox.x2 = x + w;
diff --git a/damageext/damageext.c b/damageext/damageext.c
index 926504e..f5265dd 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -35,8 +35,6 @@ static RESTYPE		DamageExtWinType;
 static DevPrivateKeyRec DamageClientPrivateKeyRec;
 #define DamageClientPrivateKey (&DamageClientPrivateKeyRec)
 
-#define prScreen	screenInfo.screens[0]
-
 static void
 DamageExtNotify (DamageExtPtr pDamageExt, BoxPtr pBoxes, int nBoxes)
 {
diff --git a/dix/dispatch.c b/dix/dispatch.c
index ffb3764..d32950d 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1179,14 +1179,12 @@ ProcTranslateCoords(ClientPtr client)
 		 * borderSize
 		 */
 		&& (!wBoundingShape(pWin) ||
-		    RegionContainsPoint(
-					&pWin->borderSize, x, y, &box))
+		    RegionContainsPoint(&pWin->borderSize, x, y, &box))
 		
 		&& (!wInputShape(pWin) ||
-		    RegionContainsPoint(
-				    wInputShape(pWin),
-				    x - pWin->drawable.x,
-				    y - pWin->drawable.y, &box))
+		    RegionContainsPoint(wInputShape(pWin),
+					x - pWin->drawable.x,
+					y - pWin->drawable.y, &box))
 		)
             {
 		rep.child = pWin->drawable.id;
@@ -2151,8 +2149,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
 	pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw);
 	if (pVisibleRegion)
 	{
-	    RegionTranslate(pVisibleRegion,
-			     -pDraw->x, -pDraw->y);
+	    RegionTranslate(pVisibleRegion, -pDraw->x, -pDraw->y);
 	}
     }
 
diff --git a/dix/events.c b/dix/events.c
index 4c53b55..3ea639e 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -887,7 +887,6 @@ CheckVirtualMotion(
 static void
 ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents, Bool confineToScreen)
 {
-    ScreenPtr pScreen = pWin->drawable.pScreen;
     SpritePtr pSprite = pDev->spriteInfo->sprite;
 
     if (syncEvents.playingEvents)
@@ -907,7 +906,7 @@ ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents, Bo
 	pSprite->hotShape = wBoundingShape(pWin) ? &pWin->borderSize
 					       : NullRegion;
         CheckPhysLimits(pDev, pSprite->current, generateEvents,
-                        confineToScreen, pScreen);
+                        confineToScreen, pWin->drawable.pScreen);
     }
 }
 
@@ -2562,11 +2561,10 @@ PointInBorderSize(WindowPtr pWin, int x, int y)
 	int i;
 
 	for(i = 1; i < PanoramiXNumScreens; i++) {
-	   if(RegionContainsPoint(
-			&pSprite->windows[i]->borderSize,
-			x + screenInfo.screens[0]->x - screenInfo.screens[i]->x,
-			y + screenInfo.screens[0]->y - screenInfo.screens[i]->y,
-			&box))
+	   if(RegionContainsPoint(&pSprite->windows[i]->borderSize,
+				  x + screenInfo.screens[0]->x - screenInfo.screens[i]->x,
+				  y + screenInfo.screens[0]->y - screenInfo.screens[i]->y,
+				  &box))
 		return TRUE;
 	}
     }
@@ -2610,10 +2608,9 @@ XYToWindow(DeviceIntPtr pDev, int x, int y)
 	     */
 	    && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y))
 	    && (!wInputShape(pWin) ||
-		RegionContainsPoint(
-				wInputShape(pWin),
-				x - pWin->drawable.x,
-				y - pWin->drawable.y, &box))
+		RegionContainsPoint(wInputShape(pWin),
+				    x - pWin->drawable.x,
+				    y - pWin->drawable.y, &box))
 #ifdef ROOTLESS
     /* In rootless mode windows may be offscreen, even when
      * they're in X's stack. (E.g. if the native window system
@@ -2881,9 +2878,9 @@ void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff)
             pSprite->hotLimits.y2 -= yoff;
 
             if (RegionNotEmpty(&pSprite->Reg1))
-                RegionTranslate(&pSprite->Reg1,    xoff, yoff);
+                RegionTranslate(&pSprite->Reg1, xoff, yoff);
             if (RegionNotEmpty(&pSprite->Reg2))
-                RegionTranslate(&pSprite->Reg2,    xoff, yoff);
+                RegionTranslate(&pSprite->Reg2, xoff, yoff);
 
             /* FIXME: if we call ConfineCursorToWindow, must we do anything else? */
             if ((grab = pDev->deviceGrab.grab) && grab->confineTo) {
@@ -3151,7 +3148,6 @@ XineramaPointInWindowIsVisible(
     int y
 )
 {
-    ScreenPtr pScreen = pWin->drawable.pScreen;
     BoxRec box;
     int i, xoff, yoff;
 
@@ -3167,16 +3163,14 @@ XineramaPointInWindowIsVisible(
 
     for(i = 1; i < PanoramiXNumScreens; i++) {
 	pWin = inputInfo.pointer->spriteInfo->sprite->windows[i];
-	pScreen = pWin->drawable.pScreen;
 	x = xoff - screenInfo.screens[i]->x;
 	y = yoff - screenInfo.screens[i]->y;
 
 	if(RegionContainsPoint(&pWin->borderClip, x, y, &box)
 	   && (!wInputShape(pWin) ||
-	       RegionContainsPoint(
-			       wInputShape(pWin),
-			       x - pWin->drawable.x,
-			       y - pWin->drawable.y, &box)))
+	       RegionContainsPoint(wInputShape(pWin),
+				   x - pWin->drawable.x,
+				   y - pWin->drawable.y, &box)))
             return TRUE;
 
     }
@@ -3375,8 +3369,7 @@ BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin)
 	int i;
 
 	for(i = 1; i < PanoramiXNumScreens; i++) {
-	    if(RegionNotEmpty(
-                        &pDev->spriteInfo->sprite->windows[i]->borderSize))
+	    if(RegionNotEmpty(&pDev->spriteInfo->sprite->windows[i]->borderSize))
 		return TRUE;
 	}
      }
diff --git a/dix/window.c b/dix/window.c
index 7caa1cc..8ccbf65 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -489,12 +489,8 @@ ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn,
                      int x, int y,
                      int w, int h)
 {
-    ScreenPtr pScreen;
-    BoxRec box;
-
-    pScreen = pWin->drawable.pScreen;
+    BoxRec box = *RegionExtents(&pWin->winSize);
 
-    box = *(RegionExtents(&pWin->winSize));
     /* we do these calculations to avoid overflows */
     if (x > box.x1)
 	box.x1 = x;
@@ -1581,9 +1577,6 @@ SetWinSize (WindowPtr pWin)
 			 (int)pWin->drawable.width,
 			 (int)pWin->drawable.height);
     if (wBoundingShape (pWin) || wClipShape (pWin)) {
-	ScreenPtr pScreen;
-        pScreen = pWin->drawable.pScreen;
-
 	RegionTranslate(&pWin->winSize, - pWin->drawable.x,
 			 - pWin->drawable.y);
 	if (wBoundingShape (pWin))
@@ -1626,9 +1619,6 @@ SetBorderSize (WindowPtr pWin)
 		(int)(pWin->drawable.width + (bw<<1)),
 		(int)(pWin->drawable.height + (bw<<1)));
 	if (wBoundingShape (pWin)) {
-	    ScreenPtr pScreen;
-            pScreen = pWin->drawable.pScreen;
-
 	    RegionTranslate(&pWin->borderSize, - pWin->drawable.x,
 			     - pWin->drawable.y);
 	    RegionIntersect(&pWin->borderSize, &pWin->borderSize,
@@ -1639,8 +1629,7 @@ SetBorderSize (WindowPtr pWin)
 			 &pWin->winSize);
 	}
     } else {
-	RegionCopy(&pWin->borderSize,
-					       &pWin->winSize);
+	RegionCopy(&pWin->borderSize, &pWin->winSize);
     }
 }
 
@@ -1835,17 +1824,11 @@ MakeBoundingRegion (
     WindowPtr	pWin,
     BoxPtr	pBox)
 {
-    RegionPtr	pRgn;
-    ScreenPtr   pScreen;
-    pScreen = pWin->drawable.pScreen;
-
-    pRgn = RegionCreate(pBox, 1);
+    RegionPtr	pRgn = RegionCreate(pBox, 1);
     if (wBoundingShape (pWin)) {
-	    RegionTranslate(pRgn, -pWin->origin.x,
-						  -pWin->origin.y);
-	    RegionIntersect(pRgn, pRgn, wBoundingShape (pWin));
-	    RegionTranslate(pRgn, pWin->origin.x,
-						  pWin->origin.y);
+	RegionTranslate(pRgn, -pWin->origin.x, -pWin->origin.y);
+	RegionIntersect(pRgn, pRgn, wBoundingShape (pWin));
+	RegionTranslate(pRgn, pWin->origin.x, pWin->origin.y);
     }
     return pRgn;
 }
@@ -1858,12 +1841,10 @@ ShapeOverlap (
     BoxPtr	pSibBox)
 {
     RegionPtr	pWinRgn, pSibRgn;
-    ScreenPtr	pScreen;
     Bool	ret;
 
     if (!IS_SHAPED(pWin) && !IS_SHAPED(pSib))
 	return TRUE;
-    pScreen = pWin->drawable.pScreen;
     pWinRgn = MakeBoundingRegion (pWin, pWinBox);
     pSibRgn = MakeBoundingRegion (pSib, pSibBox);
     RegionIntersect(pWinRgn, pWinRgn, pSibRgn);
@@ -1959,7 +1940,6 @@ WhereDoIGoInTheStack(
     int smode)
 {
     BoxRec box;
-    ScreenPtr pScreen;
     WindowPtr pHead, pFirst;
 
     if ((pWin == pWin->parent->firstChild) &&
@@ -1967,7 +1947,6 @@ WhereDoIGoInTheStack(
 	return((WindowPtr ) NULL);
     pHead = RealChildHead(pWin->parent);
     pFirst = pHead ? pHead->nextSib : pWin->parent->firstChild;
-    pScreen = pWin->drawable.pScreen;
     box.x1 = x;
     box.y1 = y;
     box.x2 = x + (int)w;
@@ -3011,10 +2990,9 @@ PointInWindowIsVisible(WindowPtr pWin, int x, int y)
     if (RegionContainsPoint(&pWin->borderClip,
 						  x, y, &box)
 	&& (!wInputShape(pWin) ||
-	    RegionContainsPoint(
-			    wInputShape(pWin),
-			    x - pWin->drawable.x, 
-			    y - pWin->drawable.y, &box)))
+	    RegionContainsPoint(wInputShape(pWin),
+				x - pWin->drawable.x,
+				y - pWin->drawable.y, &box)))
 	return(TRUE);
     return(FALSE);
 }
@@ -3023,11 +3001,7 @@ PointInWindowIsVisible(WindowPtr pWin, int x, int y)
 RegionPtr
 NotClippedByChildren(WindowPtr pWin)
 {
-    ScreenPtr pScreen;
-    RegionPtr pReg;
-
-    pScreen = pWin->drawable.pScreen;
-    pReg = RegionCreate(NullBox, 1);
+    RegionPtr pReg = RegionCreate(NullBox, 1);
     if (pWin->parent ||
 	screenIsSaved != SCREEN_SAVER_ON ||
 	!HasSaverWindow (pWin->drawable.pScreen))
diff --git a/fb/fb.h b/fb/fb.h
index 4fde426..a06f98b 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -744,8 +744,7 @@ typedef struct {
  */
 
 #define fbWindowEnabled(pWin) \
-    RegionNotEmpty(\
-		    &(pWin)->drawable.pScreen->root->borderClip)
+    RegionNotEmpty(&(pWin)->drawable.pScreen->root->borderClip)
 
 #define fbDrawableEnabled(pDrawable) \
     ((pDrawable)->type == DRAWABLE_PIXMAP ? \
diff --git a/fb/fbglyph.c b/fb/fbglyph.c
index 44fe80f..8208081 100644
--- a/fb/fbglyph.c
+++ b/fb/fbglyph.c
@@ -29,8 +29,6 @@
 #include	<X11/fonts/fontstruct.h>
 #include	"dixfontstr.h"
 
-#define dummyScreen screenInfo.screens[0]
-      
 Bool
 fbGlyphIn (RegionPtr	pRegion,
 	   int		x,
diff --git a/fb/fboverlay.c b/fb/fboverlay.c
index cda7fc7..7fca89c 100644
--- a/fb/fboverlay.c
+++ b/fb/fboverlay.c
@@ -75,8 +75,7 @@ fbOverlayCreateWindow(WindowPtr pWin)
 	     */
 	    if (!pWin->parent)
 	    {
-		RegionEmpty(
-			      &pScrPriv->layer[i].u.run.region);
+		RegionEmpty(&pScrPriv->layer[i].u.run.region);
 	    }
 	    return TRUE;
 	}
@@ -182,30 +181,25 @@ fbOverlayUpdateLayerRegion (ScreenPtr	pScreen,
 	if (i == layer)
 	{
 	    /* add new piece to this fb */
-	    RegionUnion(
-			  &pScrPriv->layer[i].u.run.region,
-			  &pScrPriv->layer[i].u.run.region,
-			  prgn);
+	    RegionUnion(&pScrPriv->layer[i].u.run.region,
+			&pScrPriv->layer[i].u.run.region,
+			prgn);
 	}
-	else if (RegionNotEmpty(
-				  &pScrPriv->layer[i].u.run.region))
+	else if (RegionNotEmpty(&pScrPriv->layer[i].u.run.region))
 	{
 	    /* paint new piece with chroma key */
 	    RegionNull(&rgnNew);
-	    RegionIntersect(
-			      &rgnNew, 
-			      prgn, 
-			      &pScrPriv->layer[i].u.run.region);
+	    RegionIntersect(&rgnNew, prgn,
+			    &pScrPriv->layer[i].u.run.region);
 	    (*pScrPriv->PaintKey) (&pScrPriv->layer[i].u.run.pixmap->drawable,
 				   &rgnNew,
 				   pScrPriv->layer[i].key,
 				   i);
 	    RegionUninit(&rgnNew);
 	    /* remove piece from other fbs */
-	    RegionSubtract(
-			     &pScrPriv->layer[i].u.run.region,
-			     &pScrPriv->layer[i].u.run.region,
-			     prgn);
+	    RegionSubtract(&pScrPriv->layer[i].u.run.region,
+			   &pScrPriv->layer[i].u.run.region,
+			   prgn);
 	}
     }
 }
@@ -219,7 +213,7 @@ fbOverlayCopyWindow(WindowPtr	pWin,
 		    RegionPtr	prgnSrc)
 {
     ScreenPtr		pScreen = pWin->drawable.pScreen;
-    FbOverlayScrPrivPtr	pScrPriv = fbOverlayGetScrPriv(pWin->drawable.pScreen);
+    FbOverlayScrPrivPtr	pScrPriv = fbOverlayGetScrPriv(pScreen);
     RegionRec		rgnDst;
     int			dx, dy;
     int			i;
diff --git a/hw/dmx/dmxpixmap.c b/hw/dmx/dmxpixmap.c
index a058ae2..587a27d 100644
--- a/hw/dmx/dmxpixmap.c
+++ b/hw/dmx/dmxpixmap.c
@@ -189,8 +189,7 @@ Bool dmxDestroyPixmap(PixmapPtr pPixmap)
  *  pPixmap. */
 RegionPtr dmxBitmapToRegion(PixmapPtr pPixmap)
 {
-    ScreenPtr      pScreen = pPixmap->drawable.pScreen;
-    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+    DMXScreenInfo *dmxScreen = &dmxScreens[pPixmap->drawable.pScreen->myNum];
     dmxPixPrivPtr  pPixPriv = DMX_GET_PIXMAP_PRIV(pPixmap);
     XImage        *ximage;
     RegionPtr      pReg, pTmpReg;
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index a979dd3..3d5d9a6 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -641,14 +641,12 @@ xf86XVUpdateCompositeClip(XvPortRecPrivatePtr portPriv)
 {
    RegionPtr	pregWin, pCompositeClip;
    WindowPtr	pWin;
-   ScreenPtr	pScreen;
    Bool		freeCompClip = FALSE;
 
    if(portPriv->pCompositeClip)
 	return;
 
    pWin = (WindowPtr)portPriv->pDraw;
-   pScreen = pWin->drawable.pScreen;
 
    /* get window clip list */
    if(portPriv->subWindowMode == IncludeInferiors) {
@@ -714,11 +712,9 @@ xf86XVRegetVideo(XvPortRecPrivatePtr portPriv)
   RegionRec WinRegion;
   RegionRec ClipRegion;
   BoxRec WinBox;
-  ScreenPtr pScreen;
   int ret = Success;
   Bool clippedAway = FALSE;
 
-  pScreen = portPriv->pDraw->pScreen;
   xf86XVUpdateCompositeClip(portPriv);
 
   /* translate the video region to the screen */
@@ -778,12 +774,9 @@ xf86XVReputVideo(XvPortRecPrivatePtr portPriv)
   RegionRec WinRegion;
   RegionRec ClipRegion;
   BoxRec WinBox;
-  ScreenPtr pScreen;
   int ret = Success;
   Bool clippedAway = FALSE;
 
-  pScreen = portPriv->pDraw->pScreen;
-
   xf86XVUpdateCompositeClip(portPriv);
 
   /* translate the video region to the screen */
@@ -868,12 +861,9 @@ xf86XVReputImage(XvPortRecPrivatePtr portPriv)
   RegionRec WinRegion;
   RegionRec ClipRegion;
   BoxRec WinBox;
-  ScreenPtr pScreen;
   int ret = Success;
   Bool clippedAway = FALSE;
 
-  pScreen = portPriv->pDraw->pScreen;
-
   xf86XVUpdateCompositeClip(portPriv);
 
   /* translate the video region to the screen */
@@ -1418,7 +1408,6 @@ xf86XVPutStill(
    CARD16 drw_w, CARD16 drw_h
 ){
   XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
-  ScreenPtr pScreen;
   RegionRec WinRegion;
   RegionRec ClipRegion;
   BoxRec WinBox;
@@ -1430,8 +1419,6 @@ xf86XVPutStill(
 
   if(!portPriv->pScrn->vtSema) return Success; /* Success ? */
 
-  pScreen = pDraw->pScreen;
-
   WinBox.x1 = pDraw->x + drw_x;
   WinBox.y1 = pDraw->y + drw_y;
   WinBox.x2 = WinBox.x1 + drw_w;
@@ -1570,7 +1557,6 @@ xf86XVGetStill(
    CARD16 drw_w, CARD16 drw_h
 ){
   XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
-  ScreenPtr pScreen;
   RegionRec WinRegion;
   RegionRec ClipRegion;
   BoxRec WinBox;
@@ -1582,8 +1568,6 @@ xf86XVGetStill(
 
   if(!portPriv->pScrn->vtSema) return Success; /* Success ? */
 
-  pScreen = pDraw->pScreen;
-
   WinBox.x1 = pDraw->x + drw_x;
   WinBox.y1 = pDraw->y + drw_y;
   WinBox.x2 = WinBox.x1 + drw_w;
@@ -1718,7 +1702,6 @@ xf86XVPutImage(
    CARD16 width, CARD16 height
 ){
   XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr)(pPort->devPriv.ptr);
-  ScreenPtr pScreen;
   RegionRec WinRegion;
   RegionRec ClipRegion;
   BoxRec WinBox;
@@ -1730,8 +1713,6 @@ xf86XVPutImage(
 
   if(!portPriv->pScrn->vtSema) return Success; /* Success ? */
 
-  pScreen = pDraw->pScreen;
-
   WinBox.x1 = pDraw->x + drw_x;
   WinBox.y1 = pDraw->y + drw_y;
   WinBox.x2 = WinBox.x1 + drw_w;
@@ -1926,8 +1907,6 @@ xf86XVFillKeyHelper (ScreenPtr pScreen, CARD32 key, RegionPtr clipboxes)
    boundaries in 16.16 fixed point.
 */
 
-#define DummyScreen screenInfo.screens[0]
-
 Bool
 xf86XVClipVideoHelper(
     BoxPtr dst,
diff --git a/hw/xfree86/shadowfb/shadow.c b/hw/xfree86/shadowfb/shadow.c
index 2066f76..9773981 100644
--- a/hw/xfree86/shadowfb/shadow.c
+++ b/hw/xfree86/shadowfb/shadow.c
@@ -1356,38 +1356,32 @@ ShadowFontToBox(BoxPtr BB, DrawablePtr pDrawable, GCPtr pGC, int x, int y,
 	}
 	right += pFont->info.maxbounds.rightSideBearing;
 	BB->x1 =
-	    max(pDrawable->x + x - left, (RegionExtents(
-		&((WindowPtr) pDrawable)->winSize))->x1);
+	    max(pDrawable->x + x - left,
+		RegionExtents(&((WindowPtr) pDrawable)->winSize)->x1);
 	BB->y1 =
 	    max(pDrawable->y + y - ascent,
-	    (RegionExtents(
-             &((WindowPtr) pDrawable)->winSize))->y1);
+		RegionExtents(&((WindowPtr) pDrawable)->winSize)->y1);
 	BB->x2 =
 	    min(pDrawable->x + x + right,
-	    (RegionExtents(
-             &((WindowPtr) pDrawable)->winSize))->x2);
+		RegionExtents(&((WindowPtr) pDrawable)->winSize)->x2);
 	BB->y2 =
 	    min(pDrawable->y + y + descent,
-	    (RegionExtents(
-             &((WindowPtr) pDrawable)->winSize))->y2);
+		RegionExtents(&((WindowPtr) pDrawable)->winSize)->y2);
     } else {
     	ShadowTextExtent(pFont, count, chars, wide ? (FONTLASTROW(pFont) == 0)
                          ? Linear16Bit : TwoD16Bit : Linear8Bit, BB);
 	BB->x1 =
-	    max(pDrawable->x + x + BB->x1, (RegionExtents(
-		&((WindowPtr) pDrawable)->winSize))->x1);
+	    max(pDrawable->x + x + BB->x1,
+		RegionExtents(&((WindowPtr) pDrawable)->winSize)->x1);
 	BB->y1 =
 	    max(pDrawable->y + y + BB->y1,
-	    (RegionExtents(
-             &((WindowPtr) pDrawable)->winSize))->y1);
+		RegionExtents(&((WindowPtr) pDrawable)->winSize)->y1);
 	BB->x2 =
 	    min(pDrawable->x + x + BB->x2,
-	    (RegionExtents(
-	     &((WindowPtr) pDrawable)->winSize))->x2);
+		RegionExtents(&((WindowPtr) pDrawable)->winSize)->x2);
 	BB->y2 =
 	    min(pDrawable->y + y + BB->y2,
-	    (RegionExtents(
-	     &((WindowPtr) pDrawable)->winSize))->y2);
+		RegionExtents(&((WindowPtr) pDrawable)->winSize)->y2);
     }
 }
 
diff --git a/hw/xnest/Window.c b/hw/xnest/Window.c
index 659b135..9ed69ed 100644
--- a/hw/xnest/Window.c
+++ b/hw/xnest/Window.c
@@ -150,10 +150,8 @@ xnestDestroyWindow(WindowPtr pWin)
   if (pWin->nextSib)
     xnestWindowPriv(pWin->nextSib)->sibling_above = 
       xnestWindowPriv(pWin)->sibling_above;
-  RegionDestroy(
-				xnestWindowPriv(pWin)->bounding_shape);
-  RegionDestroy(
-				xnestWindowPriv(pWin)->clip_shape);
+  RegionDestroy(xnestWindowPriv(pWin)->bounding_shape);
+  RegionDestroy(xnestWindowPriv(pWin)->clip_shape);
   XDestroyWindow(xnestDisplay, xnestWindow(pWin));
   xnestWindowPriv(pWin)->window = None;
 
@@ -465,8 +463,7 @@ xnestShapeWindow(WindowPtr pWin)
 			wBoundingShape(pWin))) {
     
     if (wBoundingShape(pWin)) {
-      RegionCopy(
-		xnestWindowPriv(pWin)->bounding_shape, wBoundingShape(pWin));
+      RegionCopy(xnestWindowPriv(pWin)->bounding_shape, wBoundingShape(pWin));
       
       reg = XCreateRegion();
       pBox = RegionRects(xnestWindowPriv(pWin)->bounding_shape);
@@ -484,8 +481,7 @@ xnestShapeWindow(WindowPtr pWin)
       XDestroyRegion(reg);
     }
     else {
-      RegionEmpty(
-				xnestWindowPriv(pWin)->bounding_shape);
+      RegionEmpty(xnestWindowPriv(pWin)->bounding_shape);
       
       XShapeCombineMask(xnestDisplay, xnestWindow(pWin),
 			ShapeBounding, 0, 0, None, ShapeSet);
@@ -496,8 +492,7 @@ xnestShapeWindow(WindowPtr pWin)
 			wClipShape(pWin))) {
     
     if (wClipShape(pWin)) {
-      RegionCopy(
-			xnestWindowPriv(pWin)->clip_shape, wClipShape(pWin));
+      RegionCopy(xnestWindowPriv(pWin)->clip_shape, wClipShape(pWin));
       
       reg = XCreateRegion();
       pBox = RegionRects(xnestWindowPriv(pWin)->clip_shape);
@@ -515,8 +510,7 @@ xnestShapeWindow(WindowPtr pWin)
       XDestroyRegion(reg);
     }
     else {
-      RegionEmpty(
-				     xnestWindowPriv(pWin)->clip_shape);
+      RegionEmpty(xnestWindowPriv(pWin)->clip_shape);
       
       XShapeCombineMask(xnestDisplay, xnestWindow(pWin),
 			ShapeClip, 0, 0, None, ShapeSet);
diff --git a/hw/xwin/winmultiwindowshape.c b/hw/xwin/winmultiwindowshape.c
index 9b4910b..6b7042e 100644
--- a/hw/xwin/winmultiwindowshape.c
+++ b/hw/xwin/winmultiwindowshape.c
@@ -119,10 +119,7 @@ winReshapeMultiWindow (WindowPtr pWin)
 
   RegionNull(&rrNewShape);
   RegionCopy(&rrNewShape, wBoundingShape(pWin));
-  RegionTranslate(
-		   &rrNewShape,
-		   pWin->borderWidth,
-                   pWin->borderWidth);
+  RegionTranslate(&rrNewShape, pWin->borderWidth, pWin->borderWidth);
   
   nRects = RegionNumRects(&rrNewShape);
   pShape = RegionRects(&rrNewShape);
diff --git a/hw/xwin/winwindow.c b/hw/xwin/winwindow.c
index bc0614d..783760f 100644
--- a/hw/xwin/winwindow.c
+++ b/hw/xwin/winwindow.c
@@ -564,7 +564,6 @@ void
 winReshapeRootless (WindowPtr pWin)
 {
   int		nRects;
-  /* ScreenPtr	pScreen = pWin->drawable.pScreen;*/
   RegionRec	rrNewShape;
   BoxPtr	pShape, pRects, pEnd;
   HRGN		hRgn, hRgnRect;
diff --git a/hw/xwin/winwindowswm.c b/hw/xwin/winwindowswm.c
index 5935ac4..34d7f4b 100755
--- a/hw/xwin/winwindowswm.c
+++ b/hw/xwin/winwindowswm.c
@@ -425,7 +425,6 @@ ProcWindowsWMFrameDraw (register ClientPtr client)
   RECT rcNew;
   int nCmdShow, rc;
   RegionRec newShape;
-  ScreenPtr pScreen;
 
   REQUEST_SIZE_MATCH (xWindowsWMFrameDrawReq);
 
@@ -491,7 +490,6 @@ ProcWindowsWMFrameDraw (register ClientPtr client)
 
   if (wBoundingShape(pWin) != NULL)
     {
-      pScreen = pWin->drawable.pScreen;
       /* wBoundingShape is relative to *inner* origin of window.
 	 Translate by borderWidth to get the outside-relative position. */
       
diff --git a/mi/mi.h b/mi/mi.h
index fa32b6b..57837c4 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -463,7 +463,6 @@ extern _X_EXPORT DevPrivateKey miAllocateGCPrivateIndex(
 /* mivaltree.c */
 
 extern _X_EXPORT int miShapedWindowIn(
-    ScreenPtr /*pScreen*/,
     RegionPtr /*universe*/,
     RegionPtr /*bounding*/,
     BoxPtr /*rect*/,
diff --git a/mi/micopy.c b/mi/micopy.c
index 157e324..b1a7a08 100644
--- a/mi/micopy.c
+++ b/mi/micopy.c
@@ -209,8 +209,7 @@ miDoCopy (DrawablePtr	pSrcDrawable,
 	     * VT is inactive, make sure the region isn't empty
 	     */
 	    if (!((WindowPtr) pSrcDrawable)->parent &&
-		RegionNotEmpty(
-				 &((WindowPtr) pSrcDrawable)->borderClip))
+		RegionNotEmpty(&((WindowPtr) pSrcDrawable)->borderClip))
 	    {
 		/*
 		 * special case bitblt from root window in
diff --git a/mi/miexpose.c b/mi/miexpose.c
index 2fd070d..94258b8 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -131,7 +131,6 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
 		  GCPtr pGC, int srcx, int srcy, int width, int height,
 		  int dstx, int dsty, unsigned long plane)
 {
-    ScreenPtr pscr;
     RegionPtr prgnSrcClip;	/* drawable-relative source clip */
     RegionRec rgnSrcRec;
     RegionPtr prgnDstClip;	/* drawable-relative dest clip */
@@ -148,9 +147,6 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
     BoxRec expBox;
     Bool extents;
 
-    /* This prevents warning about pscr not being used. */
-    pGC->pScreen = pscr = pGC->pScreen;
-
     /* avoid work if we can */
     if (!pGC->graphicsExposures &&
 	(pDstDrawable->type == DRAWABLE_PIXMAP) &&
diff --git a/mi/migc.c b/mi/migc.c
index 778c4b4..6d734e1 100644
--- a/mi/migc.c
+++ b/mi/migc.c
@@ -117,8 +117,7 @@ miCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
 	break;
       case CT_REGION:
 	prgnNew = RegionCreate(NULL, 1);
-	RegionCopy(prgnNew,
-					(RegionPtr) (pgcSrc->clientClip));
+	RegionCopy(prgnNew, (RegionPtr) (pgcSrc->clientClip));
 	(*pgcDst->funcs->ChangeClip) (pgcDst, CT_REGION, (pointer) prgnNew, 0);
 	break;
     }
@@ -134,11 +133,6 @@ miCopyGC(GCPtr pGCSrc, unsigned long changes, GCPtr pGCDst)
 void
 miComputeCompositeClip( GCPtr pGC, DrawablePtr pDrawable)
 {
-    ScreenPtr       pScreen;
-
-    /* This prevents warnings about pScreen not being used. */
-    pGC->pScreen = pScreen = pGC->pScreen;
-
     if (pDrawable->type == DRAWABLE_WINDOW)
     {
 	WindowPtr       pWin = (WindowPtr) pDrawable;
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index aa00e23..e7a9401 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -329,7 +329,6 @@ miOverlayMarkOverlappedWindows(
     WindowPtr pFirst,
     WindowPtr *pLayerWin
 ){
-    ScreenPtr pScreen = pWin->drawable.pScreen;
     WindowPtr pChild, pLast;
     Bool overMarked, underMarked, doUnderlay, markAll;
     miOverlayTreePtr pTree = NULL, tLast, tChild;
@@ -440,6 +439,7 @@ miOverlayMarkOverlappedWindows(
     }
 
     if(underMarked) {
+	ScreenPtr pScreen = pWin->drawable.pScreen;
 	MARK_UNDERLAY(pTree->parent->pWin);
 	MIOVERLAY_GET_SCREEN_PRIVATE(pScreen)->underlayMarked = TRUE;	
     }
@@ -486,7 +486,7 @@ miOverlayComputeClips(
 		RegionPtr   pBounding;
 
 		if ((pBounding = wBoundingShape (pParent))) {
-		    switch (miShapedWindowIn (pScreen, universe, pBounding,
+		    switch (miShapedWindowIn (universe, pBounding,
 					      &borderSize,
 					      pParent->drawable.x,
  					      pParent->drawable.y))
@@ -535,10 +535,9 @@ miOverlayComputeClips(
 		    if (tChild->valdata) {
 			RegionNull(&tChild->valdata->borderExposed);
 			if (HasParentRelativeBorder(tChild->pWin)){
-			    RegionSubtract(
-					 &tChild->valdata->borderExposed,
-					 &tChild->borderClip,
-					 &tChild->pWin->winSize);
+			    RegionSubtract(&tChild->valdata->borderExposed,
+					   &tChild->borderClip,
+					   &tChild->pWin->winSize);
 			}
 			RegionNull(&tChild->valdata->exposed);
 		    }
@@ -1004,7 +1003,6 @@ miOverlayWindowExposures(
     RegionPtr other_exposed
 ){
     RegionPtr   exposures = prgn;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
 
     if ((prgn && !RegionNil(prgn)) ||
 	(exposures && !RegionNil(exposures)) || other_exposed)
@@ -1025,6 +1023,7 @@ miOverlayWindowExposures(
 	if (clientInterested && exposures && 
 	   (RegionNumRects(exposures) > RECTLIMIT))
 	{
+	    ScreenPtr pScreen = pWin->drawable.pScreen;
             miOverlayScreenPtr pPriv = MIOVERLAY_GET_SCREEN_PRIVATE(pScreen);
 	    BoxRec box;
 
@@ -1074,13 +1073,9 @@ miOverlayRecomputeExposures (
     WindowPtr	pWin,
     pointer	value 
 ){
-    ScreenPtr pScreen;
     miOverlayTwoRegions	*pValid = (miOverlayTwoRegions*)value;
     miOverlayTreePtr pTree = MIOVERLAY_GET_WINDOW_TREE(pWin);
 
-    /* This prevents warning about pScreen not being used. */
-    pWin->drawable.pScreen = pScreen = pWin->drawable.pScreen;
-
     if (pWin->valdata) {
 	/*
 	 * compute exposed regions of this window
@@ -1419,13 +1414,11 @@ miOverlayResizeWindow(
 	    if (oldpt.x != x || oldpt.y != y) {
 		if(gravitate2[g]) {
 		    pPriv->copyUnderlay = TRUE;
-		    (*pWin->drawable.pScreen->CopyWindow)(
-						pWin, oldpt, gravitate2[g]);
+		    (*pScreen->CopyWindow)(pWin, oldpt, gravitate2[g]);
 		}
 		if(gravitate[g]) {
 		    pPriv->copyUnderlay = FALSE;
-		    (*pWin->drawable.pScreen->CopyWindow)(
-						pWin, oldpt, gravitate[g]);
+		    (*pScreen->CopyWindow)(pWin, oldpt, gravitate[g]);
 		}
 	    }
 
@@ -1730,7 +1723,6 @@ miOverlayCopyUnderlay(ScreenPtr pScreen)
 void
 miOverlayComputeCompositeClip(GCPtr pGC, WindowPtr pWin)
 {
-    ScreenPtr       pScreen = pGC->pScreen;
     miOverlayTreePtr pTree = MIOVERLAY_GET_WINDOW_TREE(pWin);
     RegionPtr       pregWin;
     Bool            freeTmpClip, freeCompClip;
@@ -1744,7 +1736,7 @@ miOverlayComputeCompositeClip(GCPtr pGC, WindowPtr pWin)
 	pregWin = RegionCreate(NullBox, 1);
 	freeTmpClip = TRUE;
 	if (pWin->parent || (screenIsSaved != SCREEN_SAVER_ON) ||
-		!HasSaverWindow (pScreen))
+		!HasSaverWindow (pGC->pScreen))
 	{
             RegionIntersect(pregWin,&pTree->borderClip,&pWin->winSize);
 	}
diff --git a/mi/mivaltree.c b/mi/mivaltree.c
index dc88c4d..7e0c22a 100644
--- a/mi/mivaltree.c
+++ b/mi/mivaltree.c
@@ -107,7 +107,7 @@ Equipment Corporation.
  * Compute the visibility of a shaped window
  */
 int
-miShapedWindowIn (ScreenPtr pScreen, RegionPtr universe, RegionPtr bounding,
+miShapedWindowIn (RegionPtr universe, RegionPtr bounding,
                   BoxPtr rect, int x, int y)
 {
     BoxRec  	box;
@@ -272,7 +272,7 @@ miComputeClips (
 
 		if ((pBounding = wBoundingShape (pParent)))
 		{
-		    switch (miShapedWindowIn (pScreen, universe, pBounding,
+		    switch (miShapedWindowIn (universe, pBounding,
 					      &borderSize,
 					      pParent->drawable.x,
  					      pParent->drawable.y))
@@ -331,14 +331,12 @@ miComputeClips (
 		    }
 		    if (pChild->valdata)
 		    {
-			RegionNull(
-				    &pChild->valdata->after.borderExposed);
+			RegionNull(&pChild->valdata->after.borderExposed);
 			if (HasParentRelativeBorder(pChild))
 			{
-			    RegionSubtract(
-					 &pChild->valdata->after.borderExposed,
-					 &pChild->borderClip,
-					 &pChild->winSize);
+			    RegionSubtract(&pChild->valdata->after.borderExposed,
+					   &pChild->borderClip,
+					   &pChild->winSize);
 			}
 			RegionNull(&pChild->valdata->after.exposed);
 		    }
diff --git a/mi/miwindow.c b/mi/miwindow.c
index 02b4074..51c5cc8 100644
--- a/mi/miwindow.c
+++ b/mi/miwindow.c
@@ -67,7 +67,6 @@ miClearToBackground(WindowPtr pWin,
     BoxRec box;
     RegionRec	reg;
     RegionPtr pBSReg = NullRegion;
-    ScreenPtr	pScreen;
     BoxPtr  extents;
     int	    x1, y1, x2, y2;
 
@@ -111,12 +110,11 @@ miClearToBackground(WindowPtr pWin,
     box.y1 = y1;
     box.y2 = y2;
 
-    pScreen = pWin->drawable.pScreen;
     RegionInit(&reg, &box, 1);
 
     RegionIntersect(&reg, &reg, &pWin->clipList);
     if (generateExposures)
-	(*pScreen->WindowExposures)(pWin, &reg, pBSReg);
+	(*pWin->drawable.pScreen->WindowExposures)(pWin, &reg, pBSReg);
     else if (pWin->backgroundState != None)
 	miPaintWindow(pWin, &reg, PW_BACKGROUND);
     RegionUninit(&reg);
@@ -146,9 +144,6 @@ miMarkOverlappedWindows(WindowPtr pWin, WindowPtr pFirst, WindowPtr *ppLayerWin)
     WindowPtr pChild, pLast;
     Bool anyMarked = FALSE;
     MarkWindowProcPtr MarkWindow = pWin->drawable.pScreen->MarkWindow;
-    ScreenPtr pScreen;
-
-    pScreen = pWin->drawable.pScreen;
 
     /* single layered systems are easy */
     if (ppLayerWin) *ppLayerWin = pWin;
@@ -230,11 +225,8 @@ miHandleValidateExposures(WindowPtr pWin)
 {
     WindowPtr pChild;
     ValidatePtr val;
-    ScreenPtr pScreen;
     WindowExposuresProcPtr WindowExposures;
 
-    pScreen = pWin->drawable.pScreen;
-
     pChild = pWin;
     WindowExposures = pChild->drawable.pScreen->WindowExposures;
     while (1)
@@ -339,7 +331,6 @@ miRecomputeExposures (
     WindowPtr	pWin,
     pointer		value) /* must conform to VisitWindowProcPtr */
 {
-    ScreenPtr	pScreen;
     RegionPtr	pValid = (RegionPtr)value;
 
     if (pWin->valdata)
@@ -353,7 +344,6 @@ miRecomputeExposures (
 	if (pWin->redirectDraw != RedirectDrawNone)
 	    return WT_DONTWALKCHILDREN;
 #endif
-	pScreen = pWin->drawable.pScreen;
 	/*
 	 * compute exposed regions of this window
 	 */
@@ -824,11 +814,8 @@ miMarkUnrealizedWindow(WindowPtr pChild, WindowPtr pWin, Bool fromConfigure)
 void
 miSegregateChildren(WindowPtr pWin, RegionPtr pReg, int depth)
 {
-    ScreenPtr pScreen;
     WindowPtr pChild;
 
-    pScreen = pWin->drawable.pScreen;
-
     for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
     {
 	if (pChild->drawable.depth == depth)
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index ef7974e..7c2f8a0 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -593,8 +593,7 @@ damageDestroyClip(GCPtr pGC)
 
 #define checkGCDamage(d,g)	(getDrawableDamage(d) && \
 				 (!g->pCompositeClip ||\
-				  RegionNotEmpty(\
-						  g->pCompositeClip)))
+				  RegionNotEmpty(g->pCompositeClip)))
 
 #define TRIM_PICTURE_BOX(box, pDst) { \
     BoxPtr extents = &pDst->pCompositeClip->extents;\
diff --git a/miext/rootless/rootlessCommon.c b/miext/rootless/rootlessCommon.c
index 4fb0e49..82fe0b9 100644
--- a/miext/rootless/rootlessCommon.c
+++ b/miext/rootless/rootlessCommon.c
@@ -262,7 +262,6 @@ void RootlessStopDrawing(WindowPtr pWindow, Bool flush)
 void
 RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion)
 {
-    ScreenPtr pScreen = pWindow->drawable.pScreen;
     RootlessWindowRec *winRec;
     RegionRec clipped;
     WindowPtr pTop;
@@ -307,7 +306,8 @@ RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion)
                 RegionUnion(&winRec->damage,
                                  &winRec->damage, (pRegion));
 #else
-                SCREENREC(pScreen)->imp->DamageRects(winRec->wid,
+                SCREENREC(pWindow->drawable.pScreen)->imp->
+                    DamageRects(winRec->wid,
                                 RegionNumRects(pRegion),
                                 RegionRects(pRegion),
                                 -winRec->x, -winRec->y);
@@ -332,7 +332,8 @@ RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion)
         RegionUnion(&winRec->damage,
                      &winRec->damage, (pRegion));
 #else
-        SCREENREC(pScreen)->imp->DamageRects(winRec->wid,
+        SCREENREC(pWindow->drawable.pScreen)->imp->
+            DamageRects(winRec->wid,
                         RegionNumRects(&clipped),
                         RegionRects(&clipped),
                         -winRec->x, -winRec->y);
diff --git a/miext/rootless/rootlessValTree.c b/miext/rootless/rootlessValTree.c
index 0f62c28..e2c4ffe 100644
--- a/miext/rootless/rootlessValTree.c
+++ b/miext/rootless/rootlessValTree.c
@@ -104,16 +104,13 @@ Equipment Corporation.
 
 #include    "globals.h"
 
-int RootlessShapedWindowIn (ScreenPtr pScreen, RegionPtr universe,
-			RegionPtr bounding, BoxPtr rect, int x, int y);
-
 int RootlessMiValidateTree (WindowPtr pRoot, WindowPtr pChild, VTKind kind);
 
 /*
  * Compute the visibility of a shaped window
  */
-int
-RootlessShapedWindowIn (ScreenPtr pScreen, RegionPtr universe,
+static int
+RootlessShapedWindowIn (RegionPtr universe,
 			RegionPtr bounding, BoxPtr rect, int x, int y)
 {
     BoxRec  box;
@@ -236,7 +233,7 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 
 		if ((pBounding = wBoundingShape (pParent)))
 		{
-		    switch (RootlessShapedWindowIn (pScreen, universe, 
+		    switch (RootlessShapedWindowIn (universe,
 						    pBounding, &borderSize,
 						    pParent->drawable.x,
 						    pParent->drawable.y))
@@ -296,14 +293,12 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 		    }
 		    if (pChild->valdata)
 		    {
-			RegionNull(
-				    &pChild->valdata->after.borderExposed);
+			RegionNull(&pChild->valdata->after.borderExposed);
 			if (HasParentRelativeBorder(pChild))
 			  {
-			    RegionSubtract(
-					 &pChild->valdata->after.borderExposed,
-					 &pChild->borderClip,
-					 &pChild->winSize);
+			    RegionSubtract(&pChild->valdata->after.borderExposed,
+					   &pChild->borderClip,
+					   &pChild->winSize);
 			}
 			RegionNull(&pChild->valdata->after.exposed);
 		    }
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 7f03214..7fe5e1d 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -179,9 +179,7 @@ RootlessCreateWindow(WindowPtr pWin)
 static void
 RootlessDestroyFrame(WindowPtr pWin, RootlessWindowPtr winRec)
 {
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    SCREENREC(pScreen)->imp->DestroyFrame(winRec->wid);
+    SCREENREC(pWin->drawable.pScreen)->imp->DestroyFrame(winRec->wid);
 
 #ifdef ROOTLESS_TRACK_DAMAGE
     RegionUninit(&winRec->damage);
@@ -218,14 +216,6 @@ RootlessDestroyWindow(WindowPtr pWin)
 static Bool
 RootlessGetShape(WindowPtr pWin, RegionPtr pShape)
 {
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    /* 
-     * Avoid a warning.  
-     * REGION_NULL and the other macros don't actually seem to use pScreen.
-     */
-    (void)pScreen; 
-
     if (wBoundingShape(pWin) == NULL)
         return FALSE;
 
@@ -247,7 +237,6 @@ RootlessGetShape(WindowPtr pWin, RegionPtr pShape)
 static void RootlessReshapeFrame(WindowPtr pWin)
 {
     RootlessWindowRec *winRec = WINREC(pWin);
-    ScreenPtr pScreen = pWin->drawable.pScreen;
     RegionRec newShape;
     RegionPtr pShape;
 
@@ -274,7 +263,7 @@ static void RootlessReshapeFrame(WindowPtr pWin)
     }
 #endif
 
-    SCREENREC(pScreen)->imp->ReshapeFrame(winRec->wid, pShape);
+    SCREENREC(pWin->drawable.pScreen)->imp->ReshapeFrame(winRec->wid, pShape);
 
     if (pShape != NULL)
         RegionUninit(&newShape);
diff --git a/render/mirect.c b/render/mirect.c
index 6a3112a..4fb347a 100644
--- a/render/mirect.c
+++ b/render/mirect.c
@@ -42,7 +42,6 @@ miColorRects (PicturePtr    pDst,
 	      int	    xoff,
 	      int	    yoff)
 {
-    ScreenPtr		pScreen = pDst->pDrawable->pScreen;
     CARD32		pixel;
     GCPtr		pGC;
     ChangeGCVal		tmpval[5];
@@ -51,7 +50,7 @@ miColorRects (PicturePtr    pDst,
 
     miRenderColorToPixel (pDst->pFormat, color, &pixel);
 
-    pGC = GetScratchGC (pDst->pDrawable->depth, pScreen);
+    pGC = GetScratchGC (pDst->pDrawable->depth, pDst->pDrawable->pScreen);
     if (!pGC)
 	return;
     tmpval[0].val = GXcopy;
diff --git a/render/picture.c b/render/picture.c
index f6e3a9e..f55711d 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -1300,8 +1300,7 @@ SetPictureClipRects (PicturePtr	pPicture,
     RegionPtr		clientClip;
     int			result;
 
-    clientClip = RegionFromRects(
-				 nRect, rects, CT_UNSORTED);
+    clientClip = RegionFromRects(nRect, rects, CT_UNSORTED);
     if (!clientClip)
 	return BadAlloc;
     result =(*ps->ChangePictureClip) (pPicture, CT_REGION, 
@@ -1331,9 +1330,8 @@ SetPictureClipRegion (PicturePtr    pPicture,
     if (pRegion)
     {
         type = CT_REGION;
-        clientClip = RegionCreate(
-                                    RegionExtents(pRegion),
-                                    RegionNumRects(pRegion));
+        clientClip = RegionCreate(RegionExtents(pRegion),
+                                  RegionNumRects(pRegion));
         if (!clientClip)
             return BadAlloc;
         if (!RegionCopy(clientClip, pRegion))
diff --git a/xfixes/region.c b/xfixes/region.c
index 4fdfa20..4a3ec33 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -663,7 +663,6 @@ int
 ProcXFixesSetWindowShapeRegion (ClientPtr client)
 {
     WindowPtr	    pWin;
-    ScreenPtr	    pScreen;
     RegionPtr	    pRegion;
     RegionPtr	    *pDestRegion;
     int rc;
@@ -678,7 +677,6 @@ ProcXFixesSetWindowShapeRegion (ClientPtr client)
 	return rc;
     }
     VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, DixWriteAccess);
-    pScreen = pWin->drawable.pScreen;
     switch (stuff->destKind) {
     case ShapeBounding:
     case ShapeClip:
@@ -733,7 +731,7 @@ ProcXFixesSetWindowShapeRegion (ClientPtr client)
     if (*pDestRegion)
 	RegionDestroy(*pDestRegion);
     *pDestRegion = pRegion;
-    (*pScreen->SetShape) (pWin, stuff->destKind);
+    (*pWin->drawable.pScreen->SetShape) (pWin, stuff->destKind);
     SendShapeNotify (pWin, stuff->destKind);
     return Success;
 }
commit 424b593c7872a703d3d0c942b7e8acc0770eb023
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Jun 5 21:34:51 2010 -0700

    Damage pixmap private key was being mis-registered as a picture key
    
    This would cause all kinds of fun, in particular Xnest would crash at startup.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index e8a1191..ef7974e 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -1893,7 +1893,7 @@ DamageSetup (ScreenPtr pScreen)
     if (!dixRegisterPrivateKey(&damageGCPrivateKeyRec, PRIVATE_GC, sizeof(DamageGCPrivRec)))
 	return FALSE;
 
-    if (!dixRegisterPrivateKey(&damagePixPrivateKeyRec, PRIVATE_PICTURE, 0))
+    if (!dixRegisterPrivateKey(&damagePixPrivateKeyRec, PRIVATE_PIXMAP, 0))
 	return FALSE;
 
     if (!dixRegisterPrivateKey(&damageWinPrivateKeyRec, PRIVATE_WINDOW, 0))
commit 9c121ae45ae1d2ebd892c45e1631716ef5e7d649
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Jun 5 21:34:27 2010 -0700

    Register Xnest colormap screen private key
    
    This key is used to store the currently installed colormap and must be
    registered before we can use it.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xnest/Color.c b/hw/xnest/Color.c
index 6399e34..3b60cc9 100644
--- a/hw/xnest/Color.c
+++ b/hw/xnest/Color.c
@@ -469,6 +469,9 @@ xnestCreateDefaultColormap(ScreenPtr pScreen)
   unsigned short zero = 0, ones = 0xFFFF;  
   Pixel wp, bp;
 
+  if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+      return FALSE;
+
   for (pVisual = pScreen->visuals;
        pVisual->vid != pScreen->rootVisual;
        pVisual++);
commit df534d05208436e9ca8c9b42acff3fbe240e3ec4
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Jun 5 21:24:54 2010 -0700

    Make GetPictureScreenIfSet check if Render is running
    
    This macro originally checked to see if the Render screen private
    index had been allocated. When the privates were changed the first
    time, there wasn't any need to check as dixLookupPrivate would simply
    return NULL in that case. Now that we care, check to see if the key
    has been initialized before asking for the value.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/render/picturestr.h b/render/picturestr.h
index da69ff6..5c6c41e 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -407,7 +407,7 @@ extern _X_EXPORT RESTYPE	PictFormatType;
 extern _X_EXPORT RESTYPE	GlyphSetType;
 
 #define GetPictureScreen(s) ((PictureScreenPtr)dixLookupPrivate(&(s)->devPrivates, PictureScreenPrivateKey))
-#define GetPictureScreenIfSet(s) GetPictureScreen(s)
+#define GetPictureScreenIfSet(s) (dixPrivateKeyRegistered(PictureScreenPrivateKey) ? GetPictureScreen(s) : NULL)
 #define SetPictureScreen(s,p) dixSetPrivate(&(s)->devPrivates, PictureScreenPrivateKey, p)
 #define GetPictureWindow(w) ((PicturePtr)dixLookupPrivate(&(w)->devPrivates, PictureWindowPrivateKey))
 #define SetPictureWindow(w,p) dixSetPrivate(&(w)->devPrivates, PictureWindowPrivateKey, p)
commit e7fc8b32e41e10c057d2787fcc377296be67f2e9
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Jun 5 21:08:01 2010 -0700

    Move the shadow screen private key initialization to shadowSetup
    
    Some users of the shadow code don't call shadowInit, just shadowSetup
    and so make sure the key is initialized there.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index 111f46a..cb1b299 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -136,6 +136,9 @@ shadowSetup(ScreenPtr pScreen)
 {
     shadowBufPtr pBuf;
 
+    if (!dixRegisterPrivateKey(&shadowScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     if (!DamageSetup(pScreen))
 	return FALSE;
 
@@ -233,9 +236,6 @@ shadowInit(ScreenPtr pScreen, ShadowUpdateProc update, ShadowWindowProc window)
 {
     PixmapPtr pPixmap;
     
-    if (!dixRegisterPrivateKey(&shadowScrPrivateKeyRec, PRIVATE_SCREEN, 0))
-	return FALSE;
-
     pPixmap = pScreen->CreatePixmap(pScreen, pScreen->width, pScreen->height,
 				    pScreen->rootDepth, 0);
     if (!pPixmap)
commit 6bd5f0d75bca727c4686b20eee166c8cae472ba2
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Jun 5 21:07:15 2010 -0700

    Fix exa_priv.h declarations of privates
    
    exa_priv.h exposes the privates to the rest of the exa code, and yet
    the declarations of the privates wasn't fixed when the exa.c versions were.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/exa/exa.c b/exa/exa.c
index bbe93f6..118a110 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -37,12 +37,9 @@
 #include "exa_priv.h"
 #include "exa.h"
 
-static DevPrivateKeyRec exaScreenPrivateKeyRec;
-#define exaScreenPrivateKey (&exaScreenPrivateKeyRec)
-static DevPrivateKeyRec exaPixmapPrivateKeyRec;
-#define exaPixmapPrivateKey (&exaPixmapPrivateKeyRec)
-static DevPrivateKeyRec exaGCPrivateKeyRec;
-#define exaGCPrivateKey (&exaGCPrivateKeyRec)
+DevPrivateKeyRec exaScreenPrivateKeyRec;
+DevPrivateKeyRec exaPixmapPrivateKeyRec;
+DevPrivateKeyRec exaGCPrivateKeyRec;
 
 #ifdef MITSHM
 static ShmFuncs exaShmFuncs = { NULL, NULL };
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 14c99e9..58d04b0 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -221,9 +221,13 @@ typedef struct {
     (PixmapWidthPaddingInfo[d].padRoundUp+1)))
 #endif
 
-extern DevPrivateKey exaScreenPrivateKey;
-extern DevPrivateKey exaPixmapPrivateKey;
-extern DevPrivateKey exaGCPrivateKey;
+extern DevPrivateKeyRec exaScreenPrivateKeyRec;
+#define exaScreenPrivateKey (&exaScreenPrivateKeyRec)
+extern DevPrivateKeyRec exaPixmapPrivateKeyRec;
+#define exaPixmapPrivateKey (&exaPixmapPrivateKeyRec)
+extern DevPrivateKeyRec exaGCPrivateKeyRec;
+#define exaGCPrivateKey (&exaGCPrivateKeyRec)
+
 #define ExaGetScreenPriv(s) ((ExaScreenPrivPtr)dixLookupPrivate(&(s)->devPrivates, exaScreenPrivateKey))
 #define ExaScreenPriv(s)	ExaScreenPrivPtr    pExaScr = ExaGetScreenPriv(s)
 
commit 6b306f43384e5c2143197e746a5a39c4ebb2583c
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Jun 5 20:58:04 2010 -0700

    kdrive: Xv code uses shared screen private instead of kdrive-specific private
    
    When doing the devPrivate API conversion, I missed this as there was
    also a local private key which wasn't ever used.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 24ae89e..3af6acf 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -105,8 +105,7 @@ static Bool KdXVInitAdaptors(ScreenPtr, KdVideoAdaptorPtr*, int);
 
 static DevPrivateKeyRec KdXVWindowKeyRec;
 #define KdXVWindowKey (&KdXVWindowKeyRec)
-static DevPrivateKeyRec KdXvScreenKeyRec;
-#define KdXvScreenKey (&KdXvScreenKeyRec)
+static DevPrivateKey KdXvScreenKey;
 static unsigned long KdXVGeneration = 0;
 static unsigned long PortResource = 0;
 
@@ -202,9 +201,6 @@ KdXVScreenInit(
   if (!dixRegisterPrivateKey(&KdXVWindowKeyRec, PRIVATE_WINDOW, 0))
       return FALSE;
 
-  if (!dixRegisterPrivateKey(&KdXVScreenKeyRec, PRIVATE_SCREEN, 0))
-      return FALSE;
-
   if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
 
   KdXvScreenKey = (*XvGetScreenKeyProc)();
commit ab07e2b8ededaa2193fc199a8c09623d84032280
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 30 19:38:48 2010 -0700

    Allocate per-screen device/cursor-bits private keys in midispcur
    
    midispcur was abusing the CursorScreenKey to index the cursor_bits
    privates, it also had a MAXSCREENS array of keys to index device
    privates. Switch both of these to the new dixCreatePrivateKey API and
    store a pointer to that in the screen private.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/mi/midispcur.c b/mi/midispcur.c
index b412477..323ee02 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -59,14 +59,7 @@ static DevPrivateKeyRec miDCScreenKeyRec;
 
 static Bool	miDCCloseScreen(int index, ScreenPtr pScreen);
 
-/* per bits per-screen private data */
-static DevPrivateKeyRec miDCCursorBitsKeyRec[MAXSCREENS];
-#define miDCCursorBitsKey(screen)	(&miDCCursorBitsKeyRec[(screen)->myNum])
-
-/* per device per-screen private data */
-static DevPrivateKeyRec miDCDeviceKeyRec[MAXSCREENS];
-#define miDCDeviceKey(screen)		(&miDCDeviceKeyRec[(screen)->myNum])
-
+/* per device private data */
 typedef struct {
     GCPtr	    pSourceGC, pMaskGC;
     GCPtr	    pSaveGC, pRestoreGC;
@@ -86,9 +79,15 @@ typedef struct {
  * in the pCursorBuffers array. 
  */
 typedef struct {
-    CloseScreenProcPtr CloseScreen;
+    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 {
     PixmapPtr		sourceBits;	    /* source bits */
@@ -106,16 +105,16 @@ miDCInitialize (ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
     if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
-    if (!dixRegisterPrivateKey(&miDCDeviceKeyRec[pScreen->myNum], PRIVATE_DEVICE, 0))
-	return FALSE;
-
-    if (!dixRegisterPrivateKey(&miDCCursorBitsKeyRec[pScreen->myNum], PRIVATE_CURSOR_BITS, 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;
 
commit 34db537907c6cb2635dbefdce7dcfcae90f7c902
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 30 19:36:33 2010 -0700

    Add dixCreatePrivateKey API
    
    Keys need to persist through server reset so that the private system
    can be cleaned up in dixResetPrivates. In particular, this means that
    keys cannot live in objects freed at reset time. This API provides
    suitable object lifetime by having the privates code free the key in
    the reset path.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/dix/privates.c b/dix/privates.c
index 736e950..ec818d4 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -229,6 +229,7 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
     key->size = size;
     key->initialized = TRUE;
     key->type = type;
+    key->allocated = FALSE;
     key->next = keys[type].key;
     keys[type].key = key;
 
@@ -236,6 +237,30 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
 }
 
 /*
+ * 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)
+{
+    DevPrivateKey	key;
+
+    key = calloc(sizeof (DevPrivateKeyRec), 1);
+    if (!key)
+	return NULL;
+    if (!dixRegisterPrivateKey(key, type, size)) {
+	free(key);
+	return NULL;
+    }
+    key->allocated = TRUE;
+    return key;
+}
+
+/*
  * Initialize privates by zeroing them
  */
 void
@@ -444,13 +469,16 @@ dixResetPrivates(void)
     DevPrivateType	t;
 
     for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
-	DevPrivateKey	key;
+	DevPrivateKey	key, next;
 
-	for (key = keys[t].key; key; key = key->next) {
+	for (key = keys[t].key; key; key = next) {
+	    next = key->next;
 	    key->offset = 0;
 	    key->initialized = FALSE;
 	    key->size = 0;
 	    key->type = 0;
+	    if (key->allocated)
+		free(key);
 	}
 	if (keys[t].created) {
 	    ErrorF("%d %ss still allocated at reset\n",
diff --git a/include/privates.h b/include/privates.h
index e2bdafd..4fed7d0 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -60,6 +60,7 @@ typedef struct _DevPrivateKeyRec {
     int			offset;
     int			size;
     Bool		initialized;
+    Bool		allocated;
     DevPrivateType	type;
     struct _DevPrivateKeyRec	*next;
 } DevPrivateKeyRec, *DevPrivateKey;
@@ -99,6 +100,17 @@ dixPrivateKeyRegistered(DevPrivateKey key)
 }
 
 /*
+ * 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.
  *
  * For keys with pre-defined storage, this gets the base of that storage
commit 495fc3eb2d6c98bde82ae1278f89fcf131fd9bf8
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 30 19:38:38 2010 -0700

    Change devPrivates implementation.
    
    Each key now declares which object type it belongs to, this permits
    keys for different types to share the same offset within the allocated
    privates. As a special case for XSELinux, a key may be allocated as
    PRIVATE_XSELINUX which will allow it to continue to be used across the
    relevant object types.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/dix/privates.c b/dix/privates.c
index 87831c2..736e950 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -25,6 +25,28 @@ other dealings in this Software without prior written authorization
 from The Open Group.
 
 */
+/*
+ * Copyright © 2010, Keith Packard
+ * Copyright © 2010, Jamey Sharp
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
 
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
@@ -38,192 +60,300 @@ from The Open Group.
 #include "cursorstr.h"
 #include "colormapst.h"
 #include "inputstr.h"
-
-struct _Private {
-    int state;
-    pointer value;
+#include "scrnintstr.h"
+#include "extnsionst.h"
+
+static struct {
+    DevPrivateKey	key;
+    unsigned		offset;
+    int			created;
+    int			allocated;
+} keys[PRIVATE_LAST];
+
+static const Bool xselinux_private[PRIVATE_LAST] = {
+    [PRIVATE_CLIENT] = TRUE,
+    [PRIVATE_WINDOW] = TRUE,
+    [PRIVATE_PIXMAP] = TRUE,
+    [PRIVATE_GC] = TRUE,
+    [PRIVATE_CURSOR] = TRUE,
+    [PRIVATE_COLORMAP] = TRUE,
+    [PRIVATE_DEVICE] = TRUE,
+    [PRIVATE_EXTENSION] = TRUE,
+    [PRIVATE_SELECTION] = TRUE,
+    [PRIVATE_PROPERTY] = TRUE,
+    [PRIVATE_PICTURE] = TRUE,
+    [PRIVATE_GLYPHSET] = TRUE,
 };
 
-typedef struct _PrivateDesc {
-    DevPrivateKey key;
-    unsigned size;
-} PrivateDescRec;
+typedef Bool (*FixupFunc)(PrivatePtr *privates, int offset, unsigned bytes);
 
-#define PRIV_MAX 256
-#define PRIV_STEP 16
-
-static int number_privates_allocated;
-static int number_private_ptrs_allocated;
-static int bytes_private_data_allocated;
+static Bool
+dixReallocPrivates(PrivatePtr *privates, int old_offset, unsigned bytes)
+{
+    void	*new_privates;
 
-/* list of all allocated privates */
-static PrivateDescRec items[PRIV_MAX];
-static int nextPriv;
+    new_privates = realloc(*privates, old_offset + bytes);
+    if (!new_privates)
+	return FALSE;
+    memset((char *) new_privates + old_offset, '\0', bytes);
+    *privates = new_privates;
+    return TRUE;
+}
 
-static PrivateDescRec *
-findItem(const DevPrivateKey key)
+static Bool
+dixMovePrivates(PrivatePtr *privates, int new_offset, unsigned bytes)
 {
-    if (!key->key) {
-	if (nextPriv >= PRIV_MAX)
-	    return NULL;
+    memmove((char *) *privates + bytes, *privates, new_offset - bytes);
+    memset(*privates, '\0', bytes);
+    return TRUE;
+}
 
-	items[nextPriv].key = key;
-	key->key = nextPriv;
-	nextPriv++;
-    }
+static Bool
+fixupScreens(FixupFunc fixup, unsigned bytes)
+{
+    int s;
+    for (s = 0; s < screenInfo.numScreens; s++)
+	if (!fixup(&screenInfo.screens[s]->devPrivates, keys[PRIVATE_SCREEN].offset, bytes))
+	    return FALSE;
+    return TRUE;
+}
 
-    return items + key->key;
+static Bool
+fixupServerClient(FixupFunc fixup, unsigned bytes)
+{
+    if (serverClient)
+	return fixup(&serverClient->devPrivates, keys[PRIVATE_CLIENT].offset, bytes);
+    return TRUE;
 }
 
-static _X_INLINE int
-privateExists(PrivateRec **privates, const DevPrivateKey key)
+static Bool
+fixupExtensions(FixupFunc fixup, unsigned bytes)
 {
-    return key->key && *privates &&
-	(*privates)[0].state > key->key &&
-	(*privates)[key->key].state;
+    unsigned char 	major;
+    ExtensionEntry	*extension;
+    for (major = EXTENSION_BASE; (extension = GetExtensionEntry(major)); major++)
+	if (!fixup(&extension->devPrivates, keys[PRIVATE_EXTENSION].offset, bytes))
+	    return FALSE;
+    return TRUE;
 }
 
-/*
- * Request pre-allocated space.
- */
-int
-dixRegisterPrivateKey(const DevPrivateKey key, DevPrivateType type, unsigned size)
+static Bool
+fixupDefaultColormaps(FixupFunc fixup, unsigned bytes)
 {
-    PrivateDescRec *item = findItem(key);
-    if (!item)
-	return FALSE;
-    if (size > item->size)
-	item->size = size;
+    int s;
+    for (s = 0; s < screenInfo.numScreens; s++) {
+	ColormapPtr cmap;
+	dixLookupResourceByType((pointer *) &cmap, screenInfo.screens[s]->defColormap,
+	                        RT_COLORMAP, serverClient, DixCreateAccess);
+	if (cmap && !fixup(&cmap->devPrivates, keys[PRIVATE_COLORMAP].offset, bytes))
+	    return FALSE;
+    }
     return TRUE;
 }
 
+static Bool (* const allocated_early[PRIVATE_LAST])(FixupFunc, unsigned) = {
+    [PRIVATE_SCREEN] = fixupScreens,
+    [PRIVATE_CLIENT] = fixupServerClient,
+    [PRIVATE_EXTENSION] = fixupExtensions,
+    [PRIVATE_COLORMAP] = fixupDefaultColormaps,
+};
+
 /*
- * Allocate a private and attach it to an existing object.
+ * Register a private key. This takes the type of object the key will
+ * be used with, which may be PRIVATE_ALL indicating that this key
+ * will be used with all of the private objects. If 'size' is
+ * non-zero, then the specified amount of space will be allocated in
+ * the private storage. Otherwise, space for a single pointer will
+ * be allocated which can be set with dixSetPrivate
  */
-static pointer *
-dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
+Bool
+dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
 {
-    PrivateDescRec *item = findItem(key);
-    PrivateRec *ptr;
-    pointer value;
-    int oldsize, newsize;
+    DevPrivateType	t;
+    int			offset;
+    unsigned		bytes;
 
-    newsize = (key->key / PRIV_STEP + 1) * PRIV_STEP;
-
-    /* resize or init privates array */
-    if (!item)
-	return NULL;
-
-    /* initialize privates array if necessary */
-    if (!*privates) {
-	++number_privates_allocated;
-	number_private_ptrs_allocated += newsize;
-	ptr = calloc(newsize, sizeof(*ptr));
-	if (!ptr)
-	    return NULL;
-	*privates = ptr;
-	(*privates)[0].state = newsize;
+    if (key->initialized) {
+	assert (size == key->size);
+	return TRUE;
     }
 
-    oldsize = (*privates)[0].state;
-
-    /* resize privates array if necessary */
-    if (key->key >= oldsize) {
-	ptr = realloc(*privates, newsize * sizeof(*ptr));
-	if (!ptr)
-	    return NULL;
-	memset(ptr + oldsize, 0, (newsize - oldsize) * sizeof(*ptr));
-	*privates = ptr;
-	(*privates)[0].state = newsize;
-	number_private_ptrs_allocated -= oldsize;
-	number_private_ptrs_allocated += newsize;
-    }
+    /* Compute required space */
+    bytes = size;
+    if (size == 0)
+	bytes = sizeof (void *);
+
+    /* align to void * size */
+    bytes = (bytes + sizeof (void *) - 1) & ~(sizeof (void *) - 1);
+
+    /* Update offsets for all affected keys */
+    if (type == PRIVATE_XSELINUX) {
+	DevPrivateKey	k;
+
+	/* Resize if we can, or make sure nothing's allocated if we can't
+	 */
+	for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++)
+	    if (xselinux_private[t]) {
+		if (!allocated_early[t])
+		    assert (!keys[t].created);
+		else if (!allocated_early[t](dixReallocPrivates, bytes))
+		    return FALSE;
+	    }
 
-    /* initialize slot */
-    ptr = *privates + key->key;
-    ptr->state = 1;
-    if (item->size) {
-	value = calloc(item->size, 1);
-	if (!value)
-	    return NULL;
-	bytes_private_data_allocated += item->size;
-	ptr->value = value;
+	/* Move all existing keys up in the privates space to make
+	 * room for this new global key
+	 */
+	for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
+	    if (xselinux_private[t]) {
+		for (k = keys[t].key; k; k = k->next)
+		    k->offset += bytes;
+		keys[t].offset += bytes;
+		if (allocated_early[t])
+		    allocated_early[t](dixMovePrivates, bytes);
+	    }
+	}
+
+	offset = 0;
+    } else {
+	/* Resize if we can, or make sure nothing's allocated if we can't */
+	if (!allocated_early[type])
+	    assert(!keys[type].created);
+	else if (!allocated_early[type](dixReallocPrivates, bytes))
+	    return FALSE;
+	offset = keys[type].offset;
+	keys[type].offset += bytes;
     }
 
-    return &ptr->value;
+    /* Setup this key */
+    key->offset = offset;
+    key->size = size;
+    key->initialized = TRUE;
+    key->type = type;
+    key->next = keys[type].key;
+    keys[type].key = key;
+
+    return TRUE;
 }
 
 /*
- * Look up a private pointer.
+ * Initialize privates by zeroing them
  */
-pointer
-dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key)
+void
+_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type)
 {
-    pointer *ptr;
-
-    assert (key->key != 0);
-    if (privateExists(privates, key))
-	return (*privates)[key->key].value;
+    keys[type].created++;
+    if (xselinux_private[type])
+	keys[PRIVATE_XSELINUX].created++;
+    if (keys[type].offset == 0)
+	addr = 0;
+    *privates = addr;
+    memset(addr, '\0', keys[type].offset);
+}
 
-    ptr = dixAllocatePrivate(privates, key);
-    return ptr ? *ptr : NULL;
+/*
+ * Clean up privates
+ */
+void
+_dixFiniPrivates(PrivatePtr privates, DevPrivateType type)
+{
+    keys[type].created--;
+    if (xselinux_private[type])
+	keys[PRIVATE_XSELINUX].created--;
 }
 
 /*
- * Look up the address of a private pointer.
+ * Allocate new object with privates.
+ *
+ * This is expected to be invoked from the
+ * dixAllocateObjectWithPrivates macro
  */
-pointer *
-dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key)
+void *
+_dixAllocateObjectWithPrivates(unsigned baseSize, unsigned clear, unsigned offset, DevPrivateType type)
 {
-    assert (key->key != 0);
+    unsigned		totalSize;
+    void		*object;
+    PrivatePtr		privates;
+    PrivatePtr		*devPrivates;
+
+    assert (type > PRIVATE_SCREEN && type < PRIVATE_LAST);
+
+    /* round up so that void * is aligned */
+    baseSize = (baseSize + sizeof (void *) - 1) & ~(sizeof (void *) - 1);
+    totalSize = baseSize + keys[type].offset;
+    object = malloc(totalSize);
+    if (!object)
+	return NULL;
 
-    if (privateExists(privates, key))
-	return &(*privates)[key->key].value;
+    memset(object, '\0', clear);
+    privates = (PrivatePtr) (((char *) object) + baseSize);
+    devPrivates = (PrivatePtr *) ((char *) object + offset);
 
-    return dixAllocatePrivate(privates, key);
+    _dixInitPrivates(devPrivates, privates, type);
+
+    return object;
 }
 
 /*
- * Set a private pointer.
+ * Allocate privates separately from containing object.
+ * Used for clients and screens.
  */
-int
-dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
+Bool
+dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type)
 {
-    assert (key->key != 0);
- top:
-    if (privateExists(privates, key)) {
-	(*privates)[key->key].value = val;
-	return TRUE;
+    unsigned 	size;
+    PrivatePtr	p;
+
+    assert (type > PRIVATE_XSELINUX && type < PRIVATE_LAST);
+
+    size = keys[type].offset;
+    if (!size) {
+	p = NULL;
+    } else {
+	if (!(p = malloc(size)))
+	    return FALSE;
     }
 
-    if (!dixAllocatePrivate(privates, key))
-	return FALSE;
-    goto top;
+    _dixInitPrivates(privates, p, type);
+    ++keys[type].allocated;
+
+    return TRUE;
 }
 
 /*
- * Called to free privates at object deletion time.
+ * Free an object that has privates
+ *
+ * This is expected to be invoked from the
+ * dixFreeObjectWithPrivates macro
  */
 void
-dixFreePrivates(PrivateRec *privates, DevPrivateType type)
+_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type)
 {
-    int i;
-
-    if (privates) {
-	number_private_ptrs_allocated -= privates->state;
-	number_privates_allocated--;
-	for (i = 1; i < privates->state; i++)
-	    if (privates[i].state) {
-		/* free pre-allocated memory */
-		if (items[i].size)
-		    free(privates[i].value);
-		bytes_private_data_allocated -= items[i].size;
-	    }
-    }
+    _dixFiniPrivates(privates, type);
+    free(object);
+}
 
+/*
+ * Called to free screen or client privates
+ */
+void
+dixFreePrivates(PrivatePtr privates, DevPrivateType type)
+{
+    _dixFiniPrivates(privates, type);
+    --keys[type].allocated;
     free(privates);
 }
 
+/*
+ * Return size of privates for the specified type
+ */
+extern _X_EXPORT int
+dixPrivatesSize(DevPrivateType type)
+{
+    assert (type >= PRIVATE_SCREEN && type < PRIVATE_LAST);
+
+    return keys[type].offset;
+}
+
 /* Table of devPrivates offsets */
 static const int offsets[] = {
     -1,					/* RT_NONE */
@@ -256,32 +386,80 @@ dixLookupPrivateOffset(RESTYPE type)
     return -1;
 }
 
+static const char *key_names[PRIVATE_LAST] = {
+    /* XSELinux uses the same private keys for numerous objects */
+    [PRIVATE_XSELINUX] = "XSELINUX",
+
+    /* Otherwise, you get a private in just the requested structure
+     */
+    /* These can have objects created before all of the keys are registered */
+    [PRIVATE_SCREEN] = "SCREEN",
+    [PRIVATE_EXTENSION] = "EXTENSION",
+    [PRIVATE_COLORMAP] = "COLORMAP",
+
+    /* These cannot have any objects before all relevant keys are registered */
+    [PRIVATE_DEVICE] = "DEVICE",
+    [PRIVATE_CLIENT] = "CLIENT",
+    [PRIVATE_PROPERTY] = "PROPERTY",
+    [PRIVATE_SELECTION] = "SELECTION",
+    [PRIVATE_WINDOW] = "WINDOW",
+    [PRIVATE_PIXMAP] = "PIXMAP",
+    [PRIVATE_GC] = "GC",
+    [PRIVATE_CURSOR] = "CURSOR",
+    [PRIVATE_CURSOR_BITS] = "CURSOR_BITS",
+
+    /* extension privates */
+    [PRIVATE_DBE_WINDOW] = "DBE_WINDOW",
+    [PRIVATE_DAMAGE] = "DAMAGE",
+    [PRIVATE_GLYPH] = "GLYPH",
+    [PRIVATE_GLYPHSET] = "GLYPHSET",
+    [PRIVATE_PICTURE] = "PICTURE",
+};
+
 void
 dixPrivateUsage(void)
 {
-    ErrorF("number of private structures: %d\n",
-	   number_privates_allocated);
-    ErrorF("total number of private pointers: %d (%zd bytes)\n",
-	   number_private_ptrs_allocated,
-	   number_private_ptrs_allocated * sizeof (struct _Private));
-    ErrorF("bytes of extra private data: %d\n",
-	   bytes_private_data_allocated);
-    ErrorF("Total privates memory usage: %zd\n",
-	   bytes_private_data_allocated +
-	   number_private_ptrs_allocated * sizeof (struct _Private));
+    int objects = 0;
+    int	bytes = 0;
+    int alloc = 0;
+    DevPrivateType t;
+
+    for (t = PRIVATE_XSELINUX + 1; t < PRIVATE_LAST; t++) {
+	if (keys[t].offset) {
+	    ErrorF("%s: %d objects of %d bytes = %d total bytes %d private allocs\n",
+		   key_names[t], keys[t].created, keys[t].offset, keys[t].created * keys[t].offset,
+		   keys[t].allocated);
+	    bytes += keys[t].created * keys[t].offset;
+	    objects += keys[t].created;
+	    alloc += keys[t].allocated;
+	}
+    }
+    ErrorF("TOTAL: %d objects, %d bytes, %d allocs\n",
+	   objects, bytes, alloc);
 }
 
 void
 dixResetPrivates(void)
 {
-    int i;
-
-    /* reset private descriptors */
-    for (i = 1; i < nextPriv; i++) {
-	items[i].key->key = 0;
-	items[i].size = 0;
+    DevPrivateType	t;
+
+    for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
+	DevPrivateKey	key;
+
+	for (key = keys[t].key; key; key = key->next) {
+	    key->offset = 0;
+	    key->initialized = FALSE;
+	    key->size = 0;
+	    key->type = 0;
+	}
+	if (keys[t].created) {
+	    ErrorF("%d %ss still allocated at reset\n",
+		   keys[t].created, key_names[t]);
+	    dixPrivateUsage();
+	}
+	keys[t].key = NULL;
+	keys[t].offset = 0;
+	keys[t].created = 0;
+	keys[t].allocated = 0;
     }
-    nextPriv = 1;
-    if (number_privates_allocated)
-	dixPrivateUsage();
 }
diff --git a/include/privates.h b/include/privates.h
index 9412fd6..e2bdafd 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -57,7 +57,11 @@ typedef enum {
 } DevPrivateType;
 
 typedef struct _DevPrivateKeyRec {
-    int			key;
+    int			offset;
+    int			size;
+    Bool		initialized;
+    DevPrivateType	type;
+    struct _DevPrivateKeyRec	*next;
 } DevPrivateKeyRec, *DevPrivateKey;
 
 /*
@@ -91,17 +95,46 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size);
 static inline Bool
 dixPrivateKeyRegistered(DevPrivateKey key)
 {
-    return key->key != 0;
+    return key->initialized;
+}
+
+/*
+ * Get the address of the private storage.
+ *
+ * For keys with pre-defined storage, this gets the base of that storage
+ * Otherwise, it returns the place where the private pointer is stored.
+ */
+static inline void *
+dixGetPrivateAddr(PrivatePtr *privates, const DevPrivateKey key)
+{
+    assert(key->initialized);
+    return (char *) (*privates) + key->offset;
+}
+
+/*
+ * Fetch a private pointer stored in the object
+ *
+ * Returns the pointer stored with dixSetPrivate.
+ * This must only be used with keys that have
+ * no pre-defined storage
+ */
+static inline void *
+dixGetPrivate(PrivatePtr *privates, const DevPrivateKey key)
+{
+    assert (key->size == 0);
+    return *(void **) dixGetPrivateAddr(privates, key);
 }
 
 /*
  * Associate 'val' with 'key' in 'privates' so that later calls to
  * dixLookupPrivate(privates, key) will return 'val'.
- *
- * dixSetPrivate returns FALSE if a memory allocation fails.
  */
-extern _X_EXPORT int
-dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val);
+static inline void
+dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val)
+{
+    assert (key->size == 0);
+    *(pointer *) dixGetPrivateAddr(privates, key) = val;
+}
 
 #include "dix.h"
 #include "resource.h"
@@ -113,28 +146,42 @@ dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val);
  * storage. For privates without defined storage, return the pointer
  * contents
  */
-extern _X_EXPORT pointer
-dixLookupPrivate(PrivatePtr *privates, const DevPrivateKey key);
+static inline pointer
+dixLookupPrivate(PrivatePtr *privates, const DevPrivateKey key)
+{
+    if (key->size)
+	return dixGetPrivateAddr(privates, key);
+    else
+	return dixGetPrivate(privates, key);
+}
 
 /*
- * Look up the address of a private pointer.  If 'key' is not associated with a
- * value in 'privates', then dixLookupPrivateAddr calls dixAllocatePrivate and
- * returns a pointer to the resulting associated value.
+ * Look up the address of the pointer to the storage
  *
- * dixLookupPrivateAddr returns NULL if 'key' was not previously associated in
- * 'privates' and a memory allocation fails.
+ * This returns the place where the private pointer is stored,
+ * which is only valid for privates without predefined storage.
  */
-extern _X_EXPORT pointer *
-dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key);
+static inline pointer *
+dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key)
+{
+    assert (key->size == 0);
+    return dixGetPrivateAddr(privates, key);
+}
 
 /*
- * Allocates private data separately from main object (clients and colormaps)
+ * Allocates private data separately from main object.
+ *
+ * For objects created during server initialization, this allows those
+ * privates to be re-allocated as new private keys are registered.
+ *
+ * This includes screens, the serverClient, default colormaps and
+ * extensions entries.
  */
-static inline Bool
-dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type) { *privates = NULL; return TRUE; }
+extern _X_EXPORT Bool
+dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type);
 
 /*
- * Frees separately allocated private data (screens and clients)
+ * Frees separately allocated private data
  */
 extern _X_EXPORT void
 dixFreePrivates(PrivatePtr privates, DevPrivateType type);
@@ -142,48 +189,44 @@ dixFreePrivates(PrivatePtr privates, DevPrivateType type);
 /*
  * Initialize privates by zeroing them
  */
-static inline void
-_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type) { *privates = NULL; }
+extern _X_EXPORT void
+_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type);
 
 #define dixInitPrivates(o, v, type) _dixInitPrivates(&(o)->devPrivates, (v), type);
 
 /*
  * Clean up privates
  */
-static inline void
-_dixFiniPrivates(PrivatePtr privates, DevPrivateType type) { dixFreePrivates(privates, type); }
+extern _X_EXPORT void
+_dixFiniPrivates(PrivatePtr privates, DevPrivateType type);
 
 #define dixFiniPrivates(o,t)	_dixFiniPrivates((o)->devPrivates,t)
 
 /*
  * Allocates private data at object creation time. Required
- * for all objects other than ScreenRecs.
+ * for almost all objects, except for the list described
+ * above for dixAllocatePrivates.
  */
-static inline void *
-_dixAllocateObjectWithPrivates(unsigned size, unsigned clear, unsigned offset, DevPrivateType type) {
-    return calloc(size, 1);
-}
+extern _X_EXPORT void *
+_dixAllocateObjectWithPrivates(unsigned size, unsigned clear, unsigned offset, DevPrivateType type);
 
 #define dixAllocateObjectWithPrivates(t, type) (t *) _dixAllocateObjectWithPrivates(sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
 
-static inline void
-_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type) {
-    dixFreePrivates(privates, type);
-    free(object);
-}
+extern _X_EXPORT void
+_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type);
 
 #define dixFreeObjectWithPrivates(o,t) _dixFreeObjectWithPrivates(o, (o)->devPrivates, t)
 
 /*
  * Return size of privates for the specified type
  */
-static inline int
-dixPrivatesSize(DevPrivateType type) { return 0; }
+extern _X_EXPORT int
+dixPrivatesSize(DevPrivateType type);
 
 /*
  * Dump out private stats to ErrorF
  */
-void
+extern void
 dixPrivateUsage(void);
 
 /*
@@ -195,6 +238,7 @@ dixResetPrivates(void);
 
 /*
  * Looks up the offset where the devPrivates field is located.
+ *
  * Returns -1 if the specified resource has no dev privates.
  * The position of the devPrivates field varies by structure
  * and calling code might only know the resource type, not the
commit faeebead7bfcc78535757ca7acc1faf7554c03b7
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Apr 26 17:22:21 2010 -0700

    Change the devPrivates API to require dixRegisterPrivateKey
    
    This patch only changes the API, not the implementation of the
    devPrivates infrastructure. This will permit a new devPrivates
    implementation to be layed into the server without requiring
    simultaneous changes in every devPrivates user.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Tested-by: Tiago Vignatti <tiago.vignatti at nokia.com>

diff --git a/Xext/geext.c b/Xext/geext.c
index b7f32c0..e61989c 100644
--- a/Xext/geext.c
+++ b/Xext/geext.c
@@ -36,12 +36,10 @@
 
 #define rClient(obj) (clients[CLIENT_ID((obj)->resource)])
 
-static int GEClientPrivateKeyIndex;
-DevPrivateKey GEClientPrivateKey = &GEClientPrivateKeyIndex;
+DevPrivateKeyRec GEClientPrivateKeyRec;
 
 int RT_GECLIENT  = 0;
 
-
 GEExtension GEExtensions[MAXEXTENSIONS];
 
 /* Major available requests */
@@ -209,7 +207,7 @@ GEExtensionInit(void)
 {
     ExtensionEntry *extEntry;
 
-    if (!dixRequestPrivate(GEClientPrivateKey, sizeof(GEClientInfoRec)))
+    if (!dixRegisterPrivateKey(&GEClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(GEClientInfoRec)))
         FatalError("GEExtensionInit: GE private request failed.\n");
 
     if(!AddCallback(&ClientStateCallback, GEClientCallback, 0))
diff --git a/Xext/geint.h b/Xext/geint.h
index 10a33ce..3e2b8e1 100644
--- a/Xext/geint.h
+++ b/Xext/geint.h
@@ -37,7 +37,8 @@
 #include "extnsionst.h"
 #include <X11/extensions/geproto.h>
 
-extern _X_EXPORT DevPrivateKey GEClientPrivateKey;
+extern _X_EXPORT DevPrivateKeyRec GEClientPrivateKeyRec;
+#define GEClientPrivateKey (&GEClientPrivateKeyRec)
 
 typedef struct _GEClientInfo {
     CARD32  major_version;
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index c625438..1cb58b5 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -103,10 +103,10 @@ static void PanoramiXResetProc(ExtensionEntry*);
 
 int (* SavedProcVector[256]) (ClientPtr client) = { NULL, };
 
-static int PanoramiXGCKeyIndex;
-static DevPrivateKey PanoramiXGCKey = &PanoramiXGCKeyIndex;
-static int PanoramiXScreenKeyIndex;
-static DevPrivateKey PanoramiXScreenKey = &PanoramiXScreenKeyIndex;
+static DevPrivateKeyRec PanoramiXGCKeyRec;
+#define PanoramiXGCKey (&PanoramiXGCKeyRec)
+static DevPrivateKeyRec PanoramiXScreenKeyRec;
+#define PanoramiXScreenKey (&PanoramiXScreenKeyRec)
 
 typedef struct {
   DDXPointRec clipOrg;
@@ -443,6 +443,16 @@ void PanoramiXExtensionInit(int argc, char *argv[])
     if (noPanoramiXExtension) 
 	return;
 
+    if (!dixRegisterPrivateKey(&PanoramiXScreenKeyRec, PRIVATE_SCREEN, 0)) {
+	noPanoramiXExtension = TRUE;
+	return;
+    }
+
+    if (!dixRegisterPrivateKey(&PanoramiXGCKeyRec, PRIVATE_GC, sizeof(PanoramiXGCRec))) {
+	noPanoramiXExtension = TRUE;
+	return;
+    }
+
     PanoramiXNumScreens = screenInfo.numScreens;
     if (PanoramiXNumScreens == 1) {		/* Only 1 screen 	*/
 	noPanoramiXExtension = TRUE;
@@ -462,11 +472,6 @@ void PanoramiXExtensionInit(int argc, char *argv[])
 	 *	run in non-PanoramiXeen mode.
 	 */
 
-	if (!dixRequestPrivate(PanoramiXGCKey, sizeof(PanoramiXGCRec))) {
-		noPanoramiXExtension = TRUE;
-		return;
-	}
-	
 	for (i = 0; i < PanoramiXNumScreens; i++) {
 	   pScreen = screenInfo.screens[i];
 	   pScreenPriv = malloc(sizeof(PanoramiXScreenRec));
diff --git a/Xext/saver.c b/Xext/saver.c
index 696c4aa..6d91ddf 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -226,8 +226,8 @@ MakeScreenPrivate (
 	ScreenPtr /* pScreen */
 	);
 
-static int ScreenPrivateKeyIndex;
-static DevPrivateKey ScreenPrivateKey = &ScreenPrivateKeyIndex;
+static DevPrivateKeyRec ScreenPrivateKeyRec;
+#define ScreenPrivateKey (&ScreenPrivateKeyRec)
 
 #define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \
     dixLookupPrivate(&(s)->devPrivates, ScreenPrivateKey))
@@ -252,6 +252,9 @@ ScreenSaverExtensionInit(INITARGS)
     int		    i;
     ScreenPtr	    pScreen;
 
+    if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     AttrType = CreateNewResourceType(ScreenSaverFreeAttr, "SaverAttr");
     SaverEventType = CreateNewResourceType(ScreenSaverFreeEvents,
 					   "SaverEvent");
diff --git a/Xext/security.c b/Xext/security.c
index e58ba10..12210f8 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -51,8 +51,8 @@ static RESTYPE RTEventClient;
 static CallbackListPtr SecurityValidateGroupCallback = NULL;
 
 /* Private state record */
-static int stateKeyIndex;
-static DevPrivateKey stateKey = &stateKeyIndex;
+static DevPrivateKeyRec stateKeyRec;
+#define stateKey (&stateKeyRec)
 
 /* This is what we store as client security state */
 typedef struct {
@@ -1108,7 +1108,7 @@ SecurityExtensionInit(INITARGS)
     RTEventClient |= RC_NEVERRETAIN;
 
     /* Allocate the private storage */
-    if (!dixRequestPrivate(stateKey, sizeof(SecurityStateRec)))
+    if (!dixRegisterPrivateKey(stateKey, PRIVATE_CLIENT, sizeof(SecurityStateRec)))
 	FatalError("SecurityExtensionSetup: Can't allocate client private.\n");
 
     /* Register callbacks */
diff --git a/Xext/shm.c b/Xext/shm.c
index 322709c..dfd8723 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -141,10 +141,10 @@ int BadShmSegCode;
 RESTYPE ShmSegType;
 static ShmDescPtr Shmsegs;
 static Bool sharedPixmaps;
-static int shmScrPrivateKeyIndex;
-static DevPrivateKey shmScrPrivateKey = &shmScrPrivateKeyIndex;
-static int shmPixmapPrivateIndex;
-static DevPrivateKey shmPixmapPrivate = &shmPixmapPrivateIndex;
+static DevPrivateKeyRec shmScrPrivateKeyRec;
+#define shmScrPrivateKey (&shmScrPrivateKeyRec)
+static DevPrivateKeyRec shmPixmapPrivateKeyRec;
+#define shmPixmapPrivateKey (&shmPixmapPrivateKeyRec)
 static ShmFuncs miFuncs = {NULL, NULL};
 static ShmFuncs fbFuncs = {fbShmCreatePixmap, NULL};
 
@@ -244,6 +244,16 @@ ShmInitScreenPriv(ScreenPtr pScreen)
     return screen_priv;
 }
 
+static Bool
+ShmRegisterPrivates(void)
+{
+    if (!dixRegisterPrivateKey(&shmScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&shmPixmapPrivateKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE;
+    return TRUE;
+}
+
 void
 ShmExtensionInit(INITARGS)
 {
@@ -258,6 +268,9 @@ ShmExtensionInit(INITARGS)
     }
 #endif
 
+    if (!ShmRegisterPrivates())
+	return;
+
     sharedPixmaps = xFalse;
     {
       sharedPixmaps = xTrue;
@@ -303,6 +316,8 @@ ShmResetProc(ExtensionEntry *extEntry)
 void
 ShmRegisterFuncs(ScreenPtr pScreen, ShmFuncsPtr funcs)
 {
+    if (!ShmRegisterPrivates())
+	return;
     ShmInitScreenPriv(pScreen)->shmFuncs = funcs;
 }
 
@@ -316,7 +331,7 @@ ShmDestroyPixmap (PixmapPtr pPixmap)
     {
 	ShmDescPtr  shmdesc;
 	shmdesc = (ShmDescPtr)dixLookupPrivate(&pPixmap->devPrivates,
-					       shmPixmapPrivate);
+					       shmPixmapPrivateKey);
 	if (shmdesc)
 	    ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id);
     }
@@ -817,7 +832,7 @@ CreatePmap:
 				shmdesc->addr + stuff->offset);
 
 	if (pMap) {
-	    dixSetPrivate(&pMap->devPrivates, shmPixmapPrivate, shmdesc);
+	    dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc);
             shmdesc->refcnt++;
 	    pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	    pMap->drawable.id = newPix->info[j].id;
@@ -1156,7 +1171,7 @@ CreatePmap:
 	    pDraw->pScreen->DestroyPixmap(pMap);
 	    return rc;
 	}
-	dixSetPrivate(&pMap->devPrivates, shmPixmapPrivate, shmdesc);
+	dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc);
 	shmdesc->refcnt++;
 	pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	pMap->drawable.id = stuff->pid;
diff --git a/Xext/xselinux_hooks.c b/Xext/xselinux_hooks.c
index 13e5243..560e1e9 100644
--- a/Xext/xselinux_hooks.c
+++ b/Xext/xselinux_hooks.c
@@ -59,12 +59,9 @@ typedef struct {
 } SELinuxAuditRec;
 
 /* private state keys */
-static int subjectKeyIndex;
-DevPrivateKey subjectKey = &subjectKeyIndex;
-static int objectKeyIndex;
-DevPrivateKey objectKey = &objectKeyIndex;
-static int dataKeyIndex;
-DevPrivateKey dataKey = &dataKeyIndex;
+DevPrivateKeyRec subjectKeyRec;
+DevPrivateKeyRec objectKeyRec;
+DevPrivateKeyRec dataKeyRec;
 
 /* audit file descriptor */
 static int audit_fd;
@@ -896,9 +893,9 @@ SELinuxFlaskInit(void)
 	FatalError("SELinux: Failed to open the system audit log\n");
 
     /* Allocate private storage */
-    if (!dixRequestPrivate(subjectKey, sizeof(SELinuxSubjectRec)) ||
-	!dixRequestPrivate(objectKey, sizeof(SELinuxObjectRec)) ||
-	!dixRequestPrivate(dataKey, sizeof(SELinuxObjectRec)))
+    if (!dixRegisterPrivateKey(subjectKey, PRIVATE_XSELINUX, sizeof(SELinuxSubjectRec)) ||
+	!dixRegisterPrivateKey(objectKey, PRIVATE_XSELINUX, sizeof(SELinuxObjectRec)) ||
+	!dixRegisterPrivateKey(dataKey, PRIVATE_XSELINUX, sizeof(SELinuxObjectRec)))
 	FatalError("SELinux: Failed to allocate private storage.\n");
 
     /* Create atoms for doing window labeling */
diff --git a/Xext/xselinuxint.h b/Xext/xselinuxint.h
index e5dbe11..011a103 100644
--- a/Xext/xselinuxint.h
+++ b/Xext/xselinuxint.h
@@ -62,9 +62,12 @@ typedef struct {
  * Globals
  */
 
-extern DevPrivateKey subjectKey;
-extern DevPrivateKey objectKey;
-extern DevPrivateKey dataKey;
+extern DevPrivateKeyRec subjectKeyRec;
+#define subjectKey (&subjectKeyRec)
+extern DevPrivateKeyRec objectKeyRec;
+#define objectKey (&objectKeyRec)
+extern DevPrivateKeyRec dataKeyRec;
+#define dataKey (&dataKeyRec)
 
 /*
  * Label functions
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 263d0c1..0a6b1c5 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -63,8 +63,8 @@ extern int DeviceValuator;
 static EventListPtr xtest_evlist;
 
 /* Used to store if a device is an XTest Virtual device */
-static int XTestDevicePrivateKeyIndex;
-DevPrivateKey XTestDevicePrivateKey = &XTestDevicePrivateKeyIndex;
+static DevPrivateKeyRec XTestDevicePrivateKeyRec;
+#define XTestDevicePrivateKey (&XTestDevicePrivateKeyRec)
 
 /**
  * xtestpointer
@@ -102,6 +102,9 @@ static DISPATCH_PROC(SProcXTestGrabControl);
 void
 XTestExtensionInit(INITARGS)
 {
+    if (!dixRegisterPrivateKey(&XTestDevicePrivateKeyRec, PRIVATE_DEVICE, 0))
+	return;
+
     AddExtension(XTestExtensionName, 0, 0,
             ProcXTestDispatch, SProcXTestDispatch,
             NULL, StandardMinorOpcode);
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 9a367bd..0c34b16 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -105,8 +105,8 @@ SOFTWARE.
 #endif
 #include "xvdisp.h"
 
-static int XvScreenKeyIndex;
-static DevPrivateKey XvScreenKey = &XvScreenKeyIndex;
+static DevPrivateKeyRec XvScreenKeyRec;
+#define XvScreenKey (&XvScreenKeyRec)
 unsigned long XvExtensionGeneration = 0;
 unsigned long XvScreenGeneration = 0;
 unsigned long XvResourceGeneration = 0;
@@ -156,6 +156,9 @@ XvExtensionInit(void)
 {
   ExtensionEntry *extEntry;
 
+  if (!dixRegisterPrivateKey(&XvScreenKeyRec, PRIVATE_SCREEN, 0))
+      return;
+
   /* LOOK TO SEE IF ANY SCREENS WERE INITIALIZED; IF NOT THEN
      INIT GLOBAL VARIABLES SO THE EXTENSION CAN FUNCTION */
   if (XvScreenGeneration != serverGeneration)
@@ -269,6 +272,9 @@ XvScreenInit(ScreenPtr pScreen)
       XvScreenGeneration = serverGeneration; 
     }
 
+  if (!dixRegisterPrivateKey(&XvScreenKeyRec, PRIVATE_SCREEN, 0))
+      return BadAlloc;
+
   if (dixLookupPrivate(&pScreen->devPrivates, XvScreenKey))
     {
       ErrorF("XvScreenInit: screen devPrivates ptr non-NULL before init\n");
@@ -284,7 +290,6 @@ XvScreenInit(ScreenPtr pScreen)
     }
 
   dixSetPrivate(&pScreen->devPrivates, XvScreenKey, pxvs);
-
   
   pxvs->DestroyPixmap = pScreen->DestroyPixmap;
   pxvs->DestroyWindow = pScreen->DestroyWindow;
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 7550386..982fad1 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -33,8 +33,9 @@
 #define DR_CLIENT_DRIVER_NAME_SIZE 48
 #define DR_BUSID_SIZE 48
 
-static int XvMCScreenKeyIndex;
-static DevPrivateKey XvMCScreenKey;
+static DevPrivateKeyRec XvMCScreenKeyRec;
+#define XvMCScreenKey (&XvMCScreenKeyRec)
+static Bool XvMCInUse;
 
 unsigned long XvMCGeneration = 0;
 
@@ -138,7 +139,7 @@ ProcXvMCListSurfaceTypes(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if(XvMCScreenKey) { /* any adaptors at all */
+    if(XvMCInUse) { /* any adaptors at all */
        ScreenPtr pScreen = pPort->pAdaptor->pScreen;
        if((pScreenPriv = XVMC_GET_PRIVATE(pScreen))) {  /* any this screen */
           for(i = 0; i < pScreenPriv->num_adaptors; i++) {
@@ -193,7 +194,7 @@ ProcXvMCCreateContext(ClientPtr client)
 
     pScreen = pPort->pAdaptor->pScreen;
 
-    if(XvMCScreenKey == NULL) /* no XvMC adaptors */
+    if(!XvMCInUse) /* no XvMC adaptors */
        return BadMatch;
  
     if(!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) /* none this screen */
@@ -716,7 +717,8 @@ XvMCScreenInit(ScreenPtr pScreen, int num, XvMCAdaptorPtr pAdapt)
 {
    XvMCScreenPtr pScreenPriv;
 
-   XvMCScreenKey = &XvMCScreenKeyIndex;
+   if (!dixRegisterPrivateKey(&XvMCScreenKeyRec, PRIVATE_SCREEN, 0))
+       return BadAlloc;
 
    if(!(pScreenPriv = malloc(sizeof(XvMCScreenRec))))
 	return BadAlloc;
@@ -734,6 +736,8 @@ XvMCScreenInit(ScreenPtr pScreen, int num, XvMCAdaptorPtr pAdapt)
    pScreenPriv->minor = 0;
    pScreenPriv->patchLevel = 0;
 
+   XvMCInUse = TRUE;
+
    return Success;
 }
 
diff --git a/Xi/exglobals.h b/Xi/exglobals.h
index 2d2d25c..f755707 100644
--- a/Xi/exglobals.h
+++ b/Xi/exglobals.h
@@ -78,5 +78,7 @@ extern int DevicePropertyNotify;
 
 extern int RT_INPUTCLIENT;
 
-extern DevPrivateKey XIClientPrivateKey;
+extern DevPrivateKeyRec XIClientPrivateKeyRec;
+#define XIClientPrivateKey (&XIClientPrivateKeyRec)
+
 #endif /* EXGLOBALS_H */
diff --git a/Xi/extinit.c b/Xi/extinit.c
index f9d8dc8..eda4efb 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -377,9 +377,7 @@ Mask PropagateMask[MAXDEVICES];
  *
  */
 
-static int XIClientPrivateKeyIndex;
-DevPrivateKey XIClientPrivateKey = &XIClientPrivateKeyIndex;
-
+DevPrivateKeyRec XIClientPrivateKeyRec;
 
 /*****************************************************************
  *
@@ -1256,7 +1254,7 @@ XInputExtensionInit(void)
         SERVER_XI_MINOR_VERSION,
     };
 
-    if (!dixRequestPrivate(XIClientPrivateKey, sizeof(XIClientRec)))
+    if (!dixRegisterPrivateKey(&XIClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XIClientRec)))
         FatalError("Cannot request private for XI.\n");
 
     if (!AddCallback(&ClientStateCallback, XIClientCallback, 0))
diff --git a/composite/compext.c b/composite/compext.c
index d37d52a..30d9dc2 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -50,8 +50,8 @@
 #include "protocol-versions.h"
 
 static CARD8	CompositeReqCode;
-static int CompositeClientPrivateKeyIndex;
-static DevPrivateKey CompositeClientPrivateKey = &CompositeClientPrivateKeyIndex;
+static DevPrivateKeyRec CompositeClientPrivateKeyRec;
+#define CompositeClientPrivateKey (&CompositeClientPrivateKeyRec)
 RESTYPE		CompositeClientWindowType;
 RESTYPE		CompositeClientSubwindowsType;
 RESTYPE		CompositeClientOverlayType;
@@ -558,8 +558,8 @@ CompositeExtensionInit (void)
     if (!CompositeClientOverlayType)
 	return;
 
-    if (!dixRequestPrivate(CompositeClientPrivateKey,
-			   sizeof(CompositeClientRec)))
+    if (!dixRegisterPrivateKey(&CompositeClientPrivateKeyRec, PRIVATE_CLIENT,
+			       sizeof(CompositeClientRec)))
 	return;
 
     if (!AddCallback (&ClientStateCallback, CompositeClientCallback, 0))
diff --git a/composite/compinit.c b/composite/compinit.c
index b4deaf5..1b2cd8f 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -48,13 +48,9 @@
 #include "compint.h"
 #include "compositeext.h"
 
-static int CompScreenPrivateKeyIndex;
-DevPrivateKey CompScreenPrivateKey = &CompScreenPrivateKeyIndex;
-static int CompWindowPrivateKeyIndex;
-DevPrivateKey CompWindowPrivateKey = &CompWindowPrivateKeyIndex;
-static int CompSubwindowsPrivateKeyIndex;
-DevPrivateKey CompSubwindowsPrivateKey = &CompSubwindowsPrivateKeyIndex;
-
+DevPrivateKeyRec CompScreenPrivateKeyRec;
+DevPrivateKeyRec CompWindowPrivateKeyRec;
+DevPrivateKeyRec CompSubwindowsPrivateKeyRec;
 
 static Bool
 compCloseScreen (int index, ScreenPtr pScreen)
@@ -319,6 +315,13 @@ compScreenInit (ScreenPtr pScreen)
 {
     CompScreenPtr   cs;
 
+    if (!dixRegisterPrivateKey(&CompScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&CompWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&CompSubwindowsPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
     if (GetCompScreen (pScreen))
 	return TRUE;
     cs = (CompScreenPtr) malloc(sizeof (CompScreenRec));
diff --git a/composite/compint.h b/composite/compint.h
index 93da4df..9c1ffd5 100644
--- a/composite/compint.h
+++ b/composite/compint.h
@@ -157,9 +157,14 @@ typedef struct _CompScreen {
     
 } CompScreenRec, *CompScreenPtr;
 
-extern DevPrivateKey CompScreenPrivateKey;
-extern DevPrivateKey CompWindowPrivateKey;
-extern DevPrivateKey CompSubwindowsPrivateKey;
+extern DevPrivateKeyRec CompScreenPrivateKeyRec;
+#define CompScreenPrivateKey (&CompScreenPrivateKeyRec)
+
+extern DevPrivateKeyRec CompWindowPrivateKeyRec;
+#define CompWindowPrivateKey (&CompWindowPrivateKeyRec)
+
+extern DevPrivateKeyRec CompSubwindowsPrivateKeyRec;
+#define CompSubwindowsPrivateKey (&CompSubwindowsPrivateKeyRec)
 
 #define GetCompScreen(s) ((CompScreenPtr) \
     dixLookupPrivate(&(s)->devPrivates, CompScreenPrivateKey))
diff --git a/damageext/damageext.c b/damageext/damageext.c
index 7717a40..926504e 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -32,8 +32,8 @@ static int		DamageEventBase;
 static RESTYPE		DamageExtType;
 static RESTYPE		DamageExtWinType;
 
-static int DamageClientPrivateKeyIndex;
-static DevPrivateKey DamageClientPrivateKey = &DamageClientPrivateKeyIndex;
+static DevPrivateKeyRec DamageClientPrivateKeyRec;
+#define DamageClientPrivateKey (&DamageClientPrivateKeyRec)
 
 #define prScreen	screenInfo.screens[0]
 
@@ -502,8 +502,9 @@ DamageExtensionInit(void)
     if (!DamageExtWinType)
 	return;
 
-    if (!dixRequestPrivate(DamageClientPrivateKey, sizeof (DamageClientRec)))
+    if (!dixRegisterPrivateKey(&DamageClientPrivateKeyRec, PRIVATE_CLIENT, sizeof (DamageClientRec)))
 	return;
+
     if (!AddCallback (&ClientStateCallback, DamageClientCallback, 0))
 	return;
 
diff --git a/dbe/dbe.c b/dbe/dbe.c
index 9b5474c..ef4b596 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -57,15 +57,13 @@
 
 /* GLOBALS */
 
-/* These are static globals copied to DBE's screen private for use by DDX */
-static int dbeScreenPrivKeyIndex;
-static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKeyIndex;
-static int dbeWindowPrivKeyIndex;
-static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKeyIndex;
+/* These are globals for use by DDX */
+DevPrivateKeyRec dbeScreenPrivKeyRec;
+DevPrivateKeyRec dbeWindowPrivKeyRec;
 
-/* These are static globals copied to DBE's screen private for use by DDX */
-static RESTYPE	dbeDrawableResType;
-static RESTYPE	dbeWindowPrivResType;
+/* These are globals for use by DDX */
+RESTYPE	dbeDrawableResType;
+RESTYPE	dbeWindowPrivResType;
 
 /* Used to generate DBE's BadBuffer error. */
 static int	dbeErrorBase;
@@ -254,7 +252,7 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
          * Allocate a window priv.
          */
 
-        pDbeWindowPriv = calloc(1, sizeof(DbeWindowPrivRec));
+        pDbeWindowPriv = dixAllocateObjectWithPrivates(DbeWindowPrivRec, PRIVATE_DBE_WINDOW);
 	if (!pDbeWindowPriv)
             return(BadAlloc);
 
@@ -1410,8 +1408,7 @@ DbeWindowPrivDelete(pointer pDbeWinPriv, XID id)
 		      NULL);
 
         /* We are done with the window priv. */
-	dixFreePrivates(pDbeWindowPriv->devPrivates);
-        free(pDbeWindowPriv);
+	dixFreeObjectWithPrivates(pDbeWindowPriv, PRIVATE_DBE_WINDOW);
     }
 
     return(Success);
@@ -1576,6 +1573,12 @@ DbeExtensionInit(void)
     if (!dbeWindowPrivResType)
 	return;
 
+    if (!dixRegisterPrivateKey(&dbeScreenPrivKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
+    if (!dixRegisterPrivateKey(&dbeWindowPrivKeyRec, PRIVATE_WINDOW, 0))
+	return;
+
     for (i = 0; i < screenInfo.numScreens; i++)
     {
         /* For each screen, set up DBE screen privates and init DIX and DDX
@@ -1602,14 +1605,6 @@ DbeExtensionInit(void)
 
 	dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, pDbeScreenPriv);
 
-        /* Copy the resource types */
-        pDbeScreenPriv->dbeDrawableResType   = dbeDrawableResType;
-        pDbeScreenPriv->dbeWindowPrivResType = dbeWindowPrivResType;
-
-        /* Copy the private indices */
-        pDbeScreenPriv->dbeScreenPrivKey = dbeScreenPrivKey;
-        pDbeScreenPriv->dbeWindowPrivKey = dbeWindowPrivKey;
-
         {
             /* We don't have DDX support for DBE anymore */
 
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index ba6b56d..9c383ce 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -167,14 +167,6 @@ typedef struct _DbeWindowPrivRec
 
 typedef struct _DbeScreenPrivRec
 {
-    /* Resources created by DIX to be used by DDX */
-    RESTYPE	dbeDrawableResType;
-    RESTYPE	dbeWindowPrivResType;
-
-    /* Private indices created by DIX to be used by DDX */
-    DevPrivateKey dbeScreenPrivKey;
-    DevPrivateKey dbeWindowPrivKey;
-
     /* Wrapped functions
      * It is the responsibilty of the DDX layer to wrap PositionWindow().
      * DbeExtensionInit wraps DestroyWindow().
diff --git a/dbe/midbe.c b/dbe/midbe.c
index 49689c5..03e8e2e 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -58,14 +58,8 @@
 
 #include <stdio.h>
 
-static int miDbeWindowPrivPrivKeyIndex;
-static DevPrivateKey miDbeWindowPrivPrivKey = &miDbeWindowPrivPrivKeyIndex;
-static RESTYPE	dbeDrawableResType;
-static RESTYPE	dbeWindowPrivResType;
-static int dbeScreenPrivKeyIndex;
-static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKeyIndex;
-static int dbeWindowPrivKeyIndex;
-static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKeyIndex;
+static DevPrivateKeyRec miDbeWindowPrivPrivKeyRec;
+#define miDbeWindowPrivPrivKey (&miDbeWindowPrivPrivKeyRec)
 
 
 /******************************************************************************
@@ -787,16 +781,8 @@ miDbeResetProc(ScreenPtr pScreen)
 Bool
 miDbeInit(ScreenPtr pScreen, DbeScreenPrivPtr pDbeScreenPriv)
 {
-    /* Copy resource types created by DIX */
-    dbeDrawableResType   = pDbeScreenPriv->dbeDrawableResType;
-    dbeWindowPrivResType = pDbeScreenPriv->dbeWindowPrivResType;
-
-    /* Copy private indices created by DIX */
-    dbeScreenPrivKey = pDbeScreenPriv->dbeScreenPrivKey;
-    dbeWindowPrivKey = pDbeScreenPriv->dbeWindowPrivKey;
-
-    if (!dixRequestPrivate(miDbeWindowPrivPrivKey,
-			   sizeof(MiDbeWindowPrivPrivRec)))
+    if (!dixRegisterPrivateKey(&miDbeWindowPrivPrivKeyRec, PRIVATE_DBE_WINDOW,
+			       sizeof(MiDbeWindowPrivPrivRec)))
         return(FALSE);
 
     /* Wrap functions. */
diff --git a/dbe/midbe.h b/dbe/midbe.h
index 007f2e3..cff36d0 100644
--- a/dbe/midbe.h
+++ b/dbe/midbe.h
@@ -36,6 +36,8 @@
 #ifndef MIDBE_H
 #define MIDBE_H
 
+#include "privates.h"
+
 /* EXTERNS */
 
 extern Bool miDbeInit(
@@ -43,5 +45,14 @@ extern Bool miDbeInit(
     DbeScreenPrivPtr    pDbeScreenPriv
 );
 
+extern DevPrivateKeyRec dbeScreenPrivKeyRec;
+#define dbeScreenPrivKey (&dbeScreenPrivKeyRec)
+
+extern DevPrivateKeyRec dbeWindowPrivKeyRec;
+#define dbeWindowPrivKey (&dbeWindowPrivKeyRec)
+
+extern RESTYPE	dbeDrawableResType;
+extern RESTYPE	dbeWindowPrivResType;
+
 #endif /* MIDBE_H */
 
diff --git a/dix/colormap.c b/dix/colormap.c
index 12197ac..eb6c491 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -273,9 +273,20 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
     if ((class | DynamicClass) == DirectColor)
 	sizebytes *= 3;
     sizebytes += sizeof(ColormapRec);
-    pmap = malloc(sizebytes);
-    if (!pmap)
-	return (BadAlloc);
+    if (mid == pScreen->defColormap) {
+	pmap = malloc(sizebytes);
+	if (!pmap)
+	    return (BadAlloc);
+	if (!dixAllocatePrivates(&pmap->devPrivates, PRIVATE_COLORMAP)) {
+	    free (pmap);
+	    return (BadAlloc);
+	}
+    } else {
+	pmap = _dixAllocateObjectWithPrivates(sizebytes, sizebytes,
+					      offsetof(ColormapRec, devPrivates), PRIVATE_COLORMAP);
+	if (!pmap)
+	    return (BadAlloc);
+    }
 #if defined(_XSERVER64)
     pmap->pad0 = 0;
     pmap->pad1 = 0;
@@ -385,7 +396,6 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 	    pmap->numPixelsBlue[client] = size;
 	}
     }
-    pmap->devPrivates = NULL;
     pmap->flags |= BeingCreated;
 
     if (!AddResource(mid, RT_COLORMAP, (pointer)pmap))
@@ -467,8 +477,11 @@ FreeColormap (pointer value, XID mid)
         }
     }
 
-    dixFreePrivates(pmap->devPrivates);
-    free(pmap);
+    if (pmap->flags & IsDefault) {
+	dixFreePrivates(pmap->devPrivates, PRIVATE_COLORMAP);
+	free(pmap);
+    } else
+	dixFreeObjectWithPrivates(pmap, PRIVATE_COLORMAP);
     return(Success);
 }
 
diff --git a/dix/cursor.c b/dix/cursor.c
index 7ff0a93..67592c5 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -72,6 +72,8 @@ typedef struct _GlyphShare {
 
 static GlyphSharePtr sharedGlyphs = (GlyphSharePtr)NULL;
 
+DevPrivateKeyRec cursorScreenDevPriv[MAXSCREENS];
+
 #ifdef XFIXES
 static CARD32	cursorSerial;
 #endif
@@ -86,8 +88,7 @@ FreeCursorBits(CursorBitsPtr bits)
 #ifdef ARGB_CURSOR
     free(bits->argb);
 #endif
-    dixFreePrivates(bits->devPrivates);
-    bits->devPrivates = NULL;
+    dixFiniPrivates(bits, PRIVATE_CURSOR_BITS);
     if (bits->refcnt == 0)
     {
 	GlyphSharePtr *prev, this;
@@ -128,8 +129,8 @@ FreeCursor(pointer value, XID cid)
 	pscr = screenInfo.screens[nscr];
         (void)( *pscr->UnrealizeCursor)(pDev, pscr, pCurs);
     }
-    dixFreePrivates(pCurs->devPrivates);
     FreeCursorBits(pCurs->bits);
+    dixFiniPrivates(pCurs, PRIVATE_CURSOR);
     free( pCurs);
     return(Success);
 }
@@ -217,6 +218,7 @@ RealizeCursorAllScreens(CursorPtr pCurs)
     return Success;
 }
 
+
 /**
  * does nothing about the resource table, just creates the data structure.
  * does not copy the src and mask bits
@@ -237,14 +239,16 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     int rc;
 
     *ppCurs = NULL;
-    pCurs = (CursorPtr)calloc(sizeof(CursorRec) + sizeof(CursorBits), 1);
+    pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1);
     if (!pCurs)
     {
 	free(psrcbits);
 	free(pmaskbits);
 	return BadAlloc;
     }
-    bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
+    bits = (CursorBitsPtr)((char *)pCurs + CURSOR_REC_SIZE);
+    dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR);
+    dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS)
     bits->source = psrcbits;
     bits->mask = pmaskbits;
 #ifdef ARGB_CURSOR
@@ -255,7 +259,6 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     bits->xhot = cm->xhot;
     bits->yhot = cm->yhot;
     pCurs->refcnt = 1;		
-    bits->devPrivates = NULL;
     bits->refcnt = -1;
     CheckForEmptyMask(bits);
     pCurs->bits = bits;
@@ -273,7 +276,6 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     pCurs->backBlue = backBlue;
 
     pCurs->id = cid;
-    pCurs->devPrivates = NULL;
 
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
@@ -289,8 +291,8 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     return Success;
 
 error:
-    dixFreePrivates(pCurs->devPrivates);
     FreeCursorBits(bits);
+    dixFiniPrivates(pCurs, PRIVATE_CURSOR);
     free(pCurs);
 
     return rc;
@@ -339,9 +341,10 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     }
     if (pShare)
     {
-	pCurs = (CursorPtr)calloc(sizeof(CursorRec), 1);
+	pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE, 1);
 	if (!pCurs)
 	    return BadAlloc;
+	dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR);
 	bits = pShare->bits;
 	bits->refcnt++;
     }
@@ -382,17 +385,17 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 	if (sourcefont != maskfont)
 	{
 	    pCurs = 
-                (CursorPtr)calloc(sizeof(CursorRec) + sizeof(CursorBits), 1);
+                (CursorPtr)calloc(CURSOR_REC_SIZE + CURSOR_BITS_SIZE, 1);
 	    if (pCurs)
-		bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
+		bits = (CursorBitsPtr)((char *)pCurs + CURSOR_REC_SIZE);
 	    else
 		bits = (CursorBitsPtr)NULL;
 	}
 	else
 	{
-	    pCurs = (CursorPtr)calloc(sizeof(CursorRec), 1);
+	    pCurs = (CursorPtr)calloc(CURSOR_REC_SIZE, 1);
 	    if (pCurs)
-		bits = (CursorBitsPtr)calloc(sizeof(CursorBits), 1);
+		bits = (CursorBitsPtr)calloc(CURSOR_BITS_SIZE, 1);
 	    else
 		bits = (CursorBitsPtr)NULL;
 	}
@@ -403,6 +406,8 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 	    free(srcbits);
 	    return BadAlloc;
 	}
+	dixInitPrivates(pCurs, pCurs + 1, PRIVATE_CURSOR);
+	dixInitPrivates(bits, bits + 1, PRIVATE_CURSOR_BITS);
 	bits->source = srcbits;
 	bits->mask = mskbits;
 #ifdef ARGB_CURSOR
@@ -412,7 +417,6 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 	bits->height = cm.height;
 	bits->xhot = cm.xhot;
 	bits->yhot = cm.yhot;
-	bits->devPrivates = NULL;
 	if (sourcefont != maskfont)
 	    bits->refcnt = -1;
 	else
@@ -451,7 +455,6 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     pCurs->backBlue = backBlue;
 
     pCurs->id = cid;
-    pCurs->devPrivates = NULL;
 
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
@@ -467,8 +470,8 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     return Success;
 
 error:
-    dixFreePrivates(pCurs->devPrivates);
     FreeCursorBits(bits);
+    dixFiniPrivates(pCurs, PRIVATE_CURSOR);
     free(pCurs);
 
     return rc;
diff --git a/dix/devices.c b/dix/devices.c
index 998d22a..427264d 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -255,7 +255,9 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
 
     if (devid >= MAXDEVICES)
 	return (DeviceIntPtr)NULL;
-    dev =  calloc(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec), 1);
+    dev =  _dixAllocateObjectWithPrivates(sizeof(DeviceIntRec) + sizeof(SpriteInfoRec),
+					  sizeof(DeviceIntRec) + sizeof(SpriteInfoRec),
+					  offsetof(DeviceIntRec, devPrivates), PRIVATE_DEVICE);
     if (!dev)
 	return (DeviceIntPtr)NULL;
     dev->id = devid;
@@ -936,8 +938,7 @@ CloseDevice(DeviceIntPtr dev)
     }
 
     free(dev->deviceGrab.sync.event);
-    dixFreePrivates(dev->devPrivates);
-    free(dev);
+    dixFreeObjectWithPrivates(dev, PRIVATE_DEVICE);
 }
 
 /**
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 859b93e..ffb3764 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3498,8 +3498,7 @@ CloseDownClient(ClientPtr client)
 	    nextFreeClientID = client->index;
 	clients[client->index] = NullClient;
 	SmartLastClient = NullClient;
-	dixFreePrivates(client->devPrivates);
-	free(client);
+	dixFreeObjectWithPrivates(client, PRIVATE_CLIENT);
 
 	while (!clients[currentMaxClients-1])
 	    currentMaxClients--;
@@ -3520,7 +3519,6 @@ KillAllClients(void)
 
 void InitClient(ClientPtr client, int i, pointer ospriv)
 {
-    memset(client, 0, sizeof(*client));
     client->index = i;
     client->clientAsMask = ((Mask)i) << CLIENTOFFSET;
     client->closeDownMode = i ? DestroyAll : RetainPermanent;
@@ -3548,13 +3546,13 @@ ClientPtr NextAvailableClient(pointer ospriv)
     i = nextFreeClientID;
     if (i == MAXCLIENTS)
 	return (ClientPtr)NULL;
-    clients[i] = client = malloc(sizeof(ClientRec));
+    clients[i] = client = dixAllocateObjectWithPrivates(ClientRec, PRIVATE_CLIENT);
     if (!client)
 	return (ClientPtr)NULL;
     InitClient(client, i, ospriv);
     if (!InitClientResources(client))
     {
-	free(client);
+	dixFreeObjectWithPrivates(client, PRIVATE_CLIENT);
 	return (ClientPtr)NULL;
     }
     data.reqType = 1;
@@ -3562,7 +3560,7 @@ ClientPtr NextAvailableClient(pointer ospriv)
     if (!InsertFakeRequest(client, (char *)&data, sz_xReq))
     {
 	FreeClientResources(client);
-	free(client);
+	dixFreeObjectWithPrivates(client, PRIVATE_CLIENT);
 	return (ClientPtr)NULL;
     }
     if (i == currentMaxClients)
@@ -3868,9 +3866,12 @@ AddScreen(
     if (!pScreen)
 	return -1;
 
-    pScreen->devPrivates = NULL;
+    if (!dixAllocatePrivates(&pScreen->devPrivates, PRIVATE_SCREEN)) {
+	free (pScreen);
+	return -1;
+    }
     pScreen->myNum = i;
-    pScreen->totalPixmapSize = BitmapBytePad(sizeof(PixmapRec)*8);
+    pScreen->totalPixmapSize = 0;	/* computed in CreateScratchPixmapForScreen */
     pScreen->ClipNotify = 0;	/* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
 
@@ -3920,10 +3921,13 @@ AddScreen(
     screenInfo.numScreens++;
     if (!(*pfnInit)(i, pScreen, argc, argv))
     {
-	dixFreePrivates(pScreen->devPrivates);
+	dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
 	free(pScreen);
 	screenInfo.numScreens--;
 	return -1;
     }
+
+    dixRegisterPrivateKey(&cursorScreenDevPriv[i], PRIVATE_CURSOR, 0);
+
     return i;
 }
diff --git a/dix/extension.c b/dix/extension.c
index d3d4db0..f422ea3 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -89,15 +89,19 @@ AddExtension(char *name, int NumEvents, int NumErrors,
         return((ExtensionEntry *) NULL);
     }
 
-    ext = malloc(sizeof(ExtensionEntry));
+    ext = calloc(sizeof (ExtensionEntry), 1);
     if (!ext)
 	return(NULL);
+    if (!dixAllocatePrivates(&ext->devPrivates, PRIVATE_EXTENSION)) {
+	free(ext);
+	return(NULL);
+    }
     ext->name = malloc(strlen(name) + 1);
     ext->num_aliases = 0;
     ext->aliases = (char **)NULL;
-    ext->devPrivates = NULL;
     if (!ext->name)
     {
+	dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION);
 	free(ext);
 	return((ExtensionEntry *) NULL);
     }
@@ -108,6 +112,7 @@ AddExtension(char *name, int NumEvents, int NumErrors,
     if (!newexts)
     {
 	free(ext->name);
+	dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION);
 	free(ext);
 	return((ExtensionEntry *) NULL);
     }
@@ -253,7 +258,7 @@ CloseDownExtensions(void)
 	for (j = extensions[i]->num_aliases; --j >= 0;)
 	    free(extensions[i]->aliases[j]);
 	free(extensions[i]->aliases);
-	dixFreePrivates(extensions[i]->devPrivates);
+	dixFreePrivates(extensions[i]->devPrivates, PRIVATE_EXTENSION);
 	free(extensions[i]);
     }
     free(extensions);
diff --git a/dix/gc.c b/dix/gc.c
index 48a507d..6d022f1 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -479,7 +479,7 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
 {
     GCPtr pGC;
 
-    pGC = malloc(sizeof(GC));
+    pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
     if (!pGC)
     {
 	*pStatus = BadAlloc;
@@ -492,7 +492,6 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
     pGC->planemask = ~0;
     pGC->serialNumber = GC_CHANGE_SERIAL_BIT;
     pGC->funcs = 0;
-    pGC->devPrivates = NULL;
     pGC->fgPixel = 0;
     pGC->bgPixel = 1;
     pGC->lineWidth = 0;
@@ -785,8 +784,7 @@ FreeGC(pointer value, XID gid)
     (*pGC->funcs->DestroyGC) (pGC);
     if (pGC->dash != DefaultDash)
 	free(pGC->dash);
-    dixFreePrivates(pGC->devPrivates);
-    free(pGC);
+    dixFreeObjectWithPrivates(pGC, PRIVATE_GC);
     return(Success);
 }
 
@@ -808,7 +806,7 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth)
 {
     GCPtr pGC;
 
-    pGC = malloc(sizeof(GC));
+    pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
     if (!pGC)
 	return (GCPtr)NULL;
 
@@ -817,7 +815,6 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth)
     pGC->alu = GXcopy; /* dst <- src */
     pGC->planemask = ~0;
     pGC->serialNumber = 0;
-    pGC->devPrivates = NULL;
     pGC->fgPixel = 0;
     pGC->bgPixel = 1;
     pGC->lineWidth = 0;
diff --git a/dix/globals.c b/dix/globals.c
index 82a85c2..b128569 100644
--- a/dix/globals.c
+++ b/dix/globals.c
@@ -123,8 +123,6 @@ CursorPtr rootCursor;
 Bool party_like_its_1989 = FALSE;
 Bool whiteRoot = FALSE;
 
-int cursorScreenDevPriv[MAXSCREENS];
-
 TimeStamp currentTime;
 TimeStamp lastDeviceEventTime;
 
diff --git a/dix/main.c b/dix/main.c
index 982fedd..0f499dd 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -174,7 +174,7 @@ int main(int argc, char *argv[], char *envp[])
 	    InitProcVectors();
 	    for (i=1; i<MAXCLIENTS; i++)
 		clients[i] = NullClient;
-	    serverClient = malloc(sizeof(ClientRec));
+	    serverClient = calloc(sizeof(ClientRec), 1);
 	    if (!serverClient)
 		FatalError("couldn't create server client");
 	    InitClient(serverClient, 0, (pointer)NULL);
@@ -184,6 +184,12 @@ int main(int argc, char *argv[], char *envp[])
 	clients[0] = serverClient;
 	currentMaxClients = 1;
 
+	/* Initialize server client devPrivates, to be reallocated as
+	 * more client privates are registered
+	 */
+	if (!dixAllocatePrivates(&serverClient->devPrivates, PRIVATE_CLIENT))
+	    FatalError("failed to create server client privates");
+
 	if (!InitClientResources(serverClient))      /* for root resources */
 	    FatalError("couldn't init server resources");
 
@@ -194,8 +200,7 @@ int main(int argc, char *argv[], char *envp[])
 	InitEvents();
 	InitSelections();
 	InitGlyphCaching();
-	if (!dixResetPrivates())
-	    FatalError("couldn't init private data storage");
+	dixResetPrivates();
 	dixResetRegistry();
 	ResetFontPrivateIndex();
 	InitCallbackManager();
@@ -204,6 +209,7 @@ int main(int argc, char *argv[], char *envp[])
 	if (screenInfo.numScreens < 1)
 	    FatalError("no screens found");
 	InitExtensions(argc, argv);
+
 	for (i = 0; i < screenInfo.numScreens; i++)
 	{
 	    ScreenPtr pScreen = screenInfo.screens[i];
@@ -314,17 +320,18 @@ int main(int argc, char *argv[], char *envp[])
 	    FreeGCperDepth(i);
 	    FreeDefaultStipple(i);
 	    (* screenInfo.screens[i]->CloseScreen)(i, screenInfo.screens[i]);
-	    dixFreePrivates(screenInfo.screens[i]->devPrivates);
+	    dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN);
 	    free(screenInfo.screens[i]);
 	    screenInfo.numScreens = i;
 	}
+
+	dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT);
+	serverClient->devPrivates = NULL;
+
 	FreeFonts();
 
 	FreeAuditTimer();
 
-	dixFreePrivates(serverClient->devPrivates);
-	serverClient->devPrivates = NULL;
-
 	if (dispatchException & DE_TERMINATE)
 	{
 	    CloseWellKnownConnections();
diff --git a/dix/pixmap.c b/dix/pixmap.c
index a4ad255..cbb5e7f 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -91,6 +91,11 @@ FreeScratchPixmapHeader(PixmapPtr pPixmap)
 Bool
 CreateScratchPixmapsForScreen(int scrnum)
 {
+    unsigned int	pixmap_size;
+
+    pixmap_size = sizeof(PixmapRec) + dixPrivatesSize(PRIVATE_PIXMAP);
+    screenInfo.screens[scrnum]->totalPixmapSize = BitmapBytePad(pixmap_size * 8);
+
     /* let it be created on first use */
     screenInfo.screens[scrnum]->pScratchPixmap = NULL;
     return TRUE;
@@ -110,6 +115,8 @@ AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
 {
     PixmapPtr pPixmap;
 
+    assert(pScreen->totalPixmapSize > 0);
+
     if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize)
 	return NullPixmap;
     
@@ -117,6 +124,14 @@ AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
     if (!pPixmap)
 	return NullPixmap;
 
-    pPixmap->devPrivates = NULL;
+    dixInitPrivates(pPixmap, pPixmap + 1, PRIVATE_PIXMAP);
     return pPixmap;
 }
+
+/* callable by ddx */
+void
+FreePixmap(PixmapPtr pPixmap)
+{
+    dixFiniPrivates(pPixmap, PRIVATE_PIXMAP);
+    free(pPixmap);
+}
diff --git a/dix/privates.c b/dix/privates.c
index 9ec6c46..87831c2 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -52,6 +52,10 @@ typedef struct _PrivateDesc {
 #define PRIV_MAX 256
 #define PRIV_STEP 16
 
+static int number_privates_allocated;
+static int number_private_ptrs_allocated;
+static int bytes_private_data_allocated;
+
 /* list of all allocated privates */
 static PrivateDescRec items[PRIV_MAX];
 static int nextPriv;
@@ -59,31 +63,31 @@ static int nextPriv;
 static PrivateDescRec *
 findItem(const DevPrivateKey key)
 {
-    if (!*key) {
+    if (!key->key) {
 	if (nextPriv >= PRIV_MAX)
 	    return NULL;
 
 	items[nextPriv].key = key;
-	*key = nextPriv;
+	key->key = nextPriv;
 	nextPriv++;
     }
 
-    return items + *key;
+    return items + key->key;
 }
 
 static _X_INLINE int
 privateExists(PrivateRec **privates, const DevPrivateKey key)
 {
-    return *key && *privates &&
-	(*privates)[0].state > *key &&
-	(*privates)[*key].state;
+    return key->key && *privates &&
+	(*privates)[0].state > key->key &&
+	(*privates)[key->key].state;
 }
 
 /*
  * Request pre-allocated space.
  */
 int
-dixRequestPrivate(const DevPrivateKey key, unsigned size)
+dixRegisterPrivateKey(const DevPrivateKey key, DevPrivateType type, unsigned size)
 {
     PrivateDescRec *item = findItem(key);
     if (!item)
@@ -96,7 +100,7 @@ dixRequestPrivate(const DevPrivateKey key, unsigned size)
 /*
  * Allocate a private and attach it to an existing object.
  */
-pointer *
+static pointer *
 dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
 {
     PrivateDescRec *item = findItem(key);
@@ -104,7 +108,7 @@ dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
     pointer value;
     int oldsize, newsize;
 
-    newsize = (*key / PRIV_STEP + 1) * PRIV_STEP;
+    newsize = (key->key / PRIV_STEP + 1) * PRIV_STEP;
 
     /* resize or init privates array */
     if (!item)
@@ -112,6 +116,8 @@ dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
 
     /* initialize privates array if necessary */
     if (!*privates) {
+	++number_privates_allocated;
+	number_private_ptrs_allocated += newsize;
 	ptr = calloc(newsize, sizeof(*ptr));
 	if (!ptr)
 	    return NULL;
@@ -122,22 +128,25 @@ dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
     oldsize = (*privates)[0].state;
 
     /* resize privates array if necessary */
-    if (*key >= oldsize) {
+    if (key->key >= oldsize) {
 	ptr = realloc(*privates, newsize * sizeof(*ptr));
 	if (!ptr)
 	    return NULL;
 	memset(ptr + oldsize, 0, (newsize - oldsize) * sizeof(*ptr));
 	*privates = ptr;
 	(*privates)[0].state = newsize;
+	number_private_ptrs_allocated -= oldsize;
+	number_private_ptrs_allocated += newsize;
     }
 
     /* initialize slot */
-    ptr = *privates + *key;
+    ptr = *privates + key->key;
     ptr->state = 1;
     if (item->size) {
 	value = calloc(item->size, 1);
 	if (!value)
 	    return NULL;
+	bytes_private_data_allocated += item->size;
 	ptr->value = value;
     }
 
@@ -152,8 +161,9 @@ dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key)
 {
     pointer *ptr;
 
+    assert (key->key != 0);
     if (privateExists(privates, key))
-	return (*privates)[*key].value;
+	return (*privates)[key->key].value;
 
     ptr = dixAllocatePrivate(privates, key);
     return ptr ? *ptr : NULL;
@@ -165,8 +175,10 @@ dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key)
 pointer *
 dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key)
 {
+    assert (key->key != 0);
+
     if (privateExists(privates, key))
-	return &(*privates)[*key].value;
+	return &(*privates)[key->key].value;
 
     return dixAllocatePrivate(privates, key);
 }
@@ -177,9 +189,10 @@ dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key)
 int
 dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
 {
+    assert (key->key != 0);
  top:
     if (privateExists(privates, key)) {
-	(*privates)[*key].value = val;
+	(*privates)[key->key].value = val;
 	return TRUE;
     }
 
@@ -192,17 +205,21 @@ dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
  * Called to free privates at object deletion time.
  */
 void
-dixFreePrivates(PrivateRec *privates)
+dixFreePrivates(PrivateRec *privates, DevPrivateType type)
 {
     int i;
 
-    if (privates)
+    if (privates) {
+	number_private_ptrs_allocated -= privates->state;
+	number_privates_allocated--;
 	for (i = 1; i < privates->state; i++)
 	    if (privates[i].state) {
 		/* free pre-allocated memory */
 		if (items[i].size)
 		    free(privates[i].value);
+		bytes_private_data_allocated -= items[i].size;
 	    }
+    }
 
     free(privates);
 }
@@ -239,16 +256,32 @@ dixLookupPrivateOffset(RESTYPE type)
     return -1;
 }
 
-int
+void
+dixPrivateUsage(void)
+{
+    ErrorF("number of private structures: %d\n",
+	   number_privates_allocated);
+    ErrorF("total number of private pointers: %d (%zd bytes)\n",
+	   number_private_ptrs_allocated,
+	   number_private_ptrs_allocated * sizeof (struct _Private));
+    ErrorF("bytes of extra private data: %d\n",
+	   bytes_private_data_allocated);
+    ErrorF("Total privates memory usage: %zd\n",
+	   bytes_private_data_allocated +
+	   number_private_ptrs_allocated * sizeof (struct _Private));
+}
+
+void
 dixResetPrivates(void)
 {
     int i;
 
     /* reset private descriptors */
     for (i = 1; i < nextPriv; i++) {
-	*items[i].key = 0;
+	items[i].key->key = 0;
 	items[i].size = 0;
     }
     nextPriv = 1;
-    return TRUE;
+    if (number_privates_allocated)
+	dixPrivateUsage();
 }
diff --git a/dix/property.c b/dix/property.c
index 03b70ef..6523107 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -269,13 +269,13 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
     {
 	if (!pWin->optional && !MakeWindowOptional (pWin))
 	    return(BadAlloc);
-        pProp = malloc(sizeof(PropertyRec));
+	pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY);
 	if (!pProp)
 	    return(BadAlloc);
         data = malloc(totalSize);
 	if (!data && len)
 	{
-	    free(pProp);
+	    dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
 	    return(BadAlloc);
 	}
         memcpy(data, value, totalSize);
@@ -289,7 +289,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 				    DixCreateAccess|DixWriteAccess);
 	if (rc != Success) {
 	    free(data);
-	    free(pProp);
+	    dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
 	    pClient->errorValue = property;
 	    return rc;
 	}
@@ -405,9 +405,8 @@ DeleteProperty(ClientPtr client, WindowPtr pWin, Atom propName)
 	}
 
 	deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName);
-	dixFreePrivates(pProp->devPrivates);
 	free(pProp->data);
-        free(pProp);
+	dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
     }
     return rc;
 }
@@ -422,9 +421,8 @@ DeleteAllWindowProperties(WindowPtr pWin)
     {
 	deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName);
 	pNextProp = pProp->next;
-	dixFreePrivates(pProp->devPrivates);
         free(pProp->data);
-        free(pProp);
+	dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
 	pProp = pNextProp;
     }
 }
@@ -570,9 +568,8 @@ ProcGetProperty(ClientPtr client)
 	    prevProp->next = pProp->next;
 	}
 
-	dixFreePrivates(pProp->devPrivates);
 	free(pProp->data);
-	free(pProp);
+	dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY);
     }
     return Success;
 }
diff --git a/dix/selection.c b/dix/selection.c
index f52638c..bae3a30 100644
--- a/dix/selection.c
+++ b/dix/selection.c
@@ -94,8 +94,7 @@ InitSelections(void)
     pSel = CurrentSelections;
     while (pSel) {
 	pNextSel = pSel->next;
-	dixFreePrivates(pSel->devPrivates);
-	free(pSel);
+	dixFreeObjectWithPrivates(pSel, PRIVATE_SELECTION);
 	pSel = pNextSel;
     }
 
diff --git a/dix/window.c b/dix/window.c
index a98437b..7caa1cc 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -151,12 +151,8 @@ WindowSeekDeviceCursor(WindowPtr pWin,
 
 int screenIsSaved = SCREEN_SAVER_OFF;
 
-static int FocusPrivatesKeyIndex;
-DevPrivateKey FocusPrivatesKey = &FocusPrivatesKeyIndex;
-
 static Bool TileScreenSaver(ScreenPtr pScreen, int kind);
 
-
 #define INPUTONLY_LEGAL_MASK (CWWinGravity | CWEventMask | \
 			      CWDontPropagate | CWOverrideRedirect | CWCursor )
 
@@ -357,7 +353,7 @@ CreateRootWindow(ScreenPtr pScreen)
     BoxRec	box;
     PixmapFormatRec *format;
 
-    pWin = malloc(sizeof(WindowRec));
+    pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW);
     if (!pWin)
 	return FALSE;
 
@@ -370,7 +366,6 @@ CreateRootWindow(ScreenPtr pScreen)
 
     pWin->drawable.pScreen = pScreen;
     pWin->drawable.type = DRAWABLE_WINDOW;
-    pWin->devPrivates = NULL;
 
     pWin->drawable.depth = pScreen->rootDepth;
     for (format = screenInfo.formats;
@@ -637,14 +632,13 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
 	return NullWindow;
     }
 
-    pWin = malloc(sizeof(WindowRec));
+    pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW);
     if (!pWin)
     {
 	*error = BadAlloc;
 	return NullWindow;
     }
     pWin->drawable = pParent->drawable;
-    pWin->devPrivates = NULL;
     pWin->drawable.depth = depth;
     if (depth == pParent->drawable.depth)
 	pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel;
@@ -668,7 +662,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
     {
 	if (!MakeWindowOptional (pWin))
 	{
-	    free(pWin);
+	    dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW);
 	    *error = BadAlloc;
 	    return NullWindow;
 	}
@@ -683,7 +677,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
     *error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW, pWin,
 		RT_WINDOW, pWin->parent, DixCreateAccess|DixSetAttrAccess);
     if (*error != Success) {
-	free(pWin);
+	dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW);
 	return NullWindow;
     }
 
@@ -881,8 +875,7 @@ CrushTree(WindowPtr pWin)
 		(*UnrealizeWindow)(pChild);
 	    }
 	    FreeWindowResources(pChild);
-	    dixFreePrivates(pChild->devPrivates);
-	    free(pChild);
+	    dixFreeObjectWithPrivates(pChild, PRIVATE_WINDOW);
 	    if ( (pChild = pSib) )
 		break;
 	    pChild = pParent;
@@ -932,9 +925,7 @@ DeleteWindow(pointer value, XID wid)
 	if (pWin->prevSib)
 	    pWin->prevSib->nextSib = pWin->nextSib;
     }
-    free(dixLookupPrivate(&pWin->devPrivates, FocusPrivatesKey));
-    dixFreePrivates(pWin->devPrivates);
-    free(pWin);
+    dixFreeObjectWithPrivates(pWin, PRIVATE_WINDOW);
     return Success;
 }
 
diff --git a/exa/exa.c b/exa/exa.c
index 4e1ffd6..bbe93f6 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -37,12 +37,12 @@
 #include "exa_priv.h"
 #include "exa.h"
 
-static int exaScreenPrivateKeyIndex;
-DevPrivateKey exaScreenPrivateKey = &exaScreenPrivateKeyIndex;
-static int exaPixmapPrivateKeyIndex;
-DevPrivateKey exaPixmapPrivateKey = &exaPixmapPrivateKeyIndex;
-static int exaGCPrivateKeyIndex;
-DevPrivateKey exaGCPrivateKey = &exaGCPrivateKeyIndex;
+static DevPrivateKeyRec exaScreenPrivateKeyRec;
+#define exaScreenPrivateKey (&exaScreenPrivateKeyRec)
+static DevPrivateKeyRec exaPixmapPrivateKeyRec;
+#define exaPixmapPrivateKey (&exaPixmapPrivateKeyRec)
+static DevPrivateKeyRec exaGCPrivateKeyRec;
+#define exaGCPrivateKey (&exaGCPrivateKeyRec)
 
 #ifdef MITSHM
 static ShmFuncs exaShmFuncs = { NULL, NULL };
@@ -889,7 +889,13 @@ exaDriverInit (ScreenPtr		pScreen,
 
     ps = GetPictureScreenIfSet(pScreen);
 
-    pExaScr = calloc(sizeof (ExaScreenPrivRec), 1);
+    if (!dixRegisterPrivateKey(&exaScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) {
+        LogMessage(X_WARNING, "EXA(%d): Failed to register screen private\n",
+		   pScreen->myNum);
+	return FALSE;
+    }
+
+    pExaScr = calloc (sizeof (ExaScreenPrivRec), 1);
     if (!pExaScr) {
         LogMessage(X_WARNING, "EXA(%d): Failed to allocate screen private\n",
 		   pScreen->myNum);
@@ -904,7 +910,7 @@ exaDriverInit (ScreenPtr		pScreen,
 
     exaDDXDriverInit(pScreen);
 
-    if (!dixRequestPrivate(exaGCPrivateKey, sizeof(ExaGCPrivRec))) {
+    if (!dixRegisterPrivateKey(&exaGCPrivateKeyRec, PRIVATE_GC, sizeof(ExaGCPrivRec))) {
 	LogMessage(X_WARNING,
 	       "EXA(%d): Failed to allocate GC private\n",
 	       pScreen->myNum);
@@ -953,7 +959,7 @@ exaDriverInit (ScreenPtr		pScreen,
      */
     if (pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS)
     {
-	if (!dixRequestPrivate(exaPixmapPrivateKey, sizeof(ExaPixmapPrivRec))) {
+	if (!dixRegisterPrivateKey(&exaPixmapPrivateKeyRec, PRIVATE_PIXMAP, sizeof(ExaPixmapPrivRec))) {
             LogMessage(X_WARNING,
 		       "EXA(%d): Failed to allocate pixmap private\n",
 		       pScreen->myNum);
diff --git a/fb/fb.h b/fb/fb.h
index 7ab4adf..4fde426 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -603,8 +603,12 @@ extern _X_EXPORT void fbSetBits (FbStip *bits, int stride, FbStip data);
     }							    \
 }
 
-extern _X_EXPORT DevPrivateKey fbGetGCPrivateKey(void);
-extern _X_EXPORT DevPrivateKey fbGetWinPrivateKey(void);
+extern _X_EXPORT DevPrivateKey
+fbGetGCPrivateKey (void);
+
+extern _X_EXPORT DevPrivateKey
+fbGetWinPrivateKey (void);
+
 extern _X_EXPORT const GCOps	fbGCOps;
 extern _X_EXPORT const GCFuncs	fbGCFuncs;
 
@@ -639,7 +643,8 @@ typedef void (*FinishWrapProcPtr)(DrawablePtr pDraw);
 
 
 #ifdef FB_SCREEN_PRIVATE
-extern _X_EXPORT DevPrivateKey fbGetScreenPrivateKey(void);
+extern _X_EXPORT DevPrivateKey
+fbGetScreenPrivateKey(void);
 
 /* private field of a screen */
 typedef struct {
@@ -652,7 +657,7 @@ typedef struct {
 } FbScreenPrivRec, *FbScreenPrivPtr;
 
 #define fbGetScreenPrivate(pScreen) ((FbScreenPrivPtr) \
-	dixLookupPrivate(&(pScreen)->devPrivates, fbGetScreenPrivateKey()))
+				     dixLookupPrivate(&(pScreen)->devPrivates, fbGetScreenPrivateKey()))
 #endif
 
 /* private field of GC */
@@ -667,7 +672,7 @@ typedef struct {
 } FbGCPrivRec, *FbGCPrivPtr;
 
 #define fbGetGCPrivate(pGC)	((FbGCPrivPtr)\
-	dixLookupPrivate(&(pGC)->devPrivates, fbGetGCPrivateKey()))
+				 dixLookupPrivate(&(pGC)->devPrivates, fbGetGCPrivateKey()))
 
 #define fbGetCompositeClip(pGC) ((pGC)->pCompositeClip)
 #define fbGetExpose(pGC)	((pGC)->fExpose)
@@ -676,7 +681,7 @@ typedef struct {
 
 #define fbGetScreenPixmap(s)	((PixmapPtr) (s)->devPrivate)
 #define fbGetWindowPixmap(pWin)	((PixmapPtr)\
-    dixLookupPrivate(&((WindowPtr)(pWin))->devPrivates, fbGetWinPrivateKey()))
+				 dixLookupPrivate(&((WindowPtr)(pWin))->devPrivates, fbGetWinPrivateKey()))
 
 #ifdef ROOTLESS
 #define __fbPixDrawableX(pPix)	((pPix)->drawable.x)
@@ -830,8 +835,6 @@ fb24_32ModifyPixmapHeader (PixmapPtr   pPixmap,
 /*
  * fballpriv.c
  */
-extern _X_EXPORT DevPrivateKey fbGetWinPrivateKey(void);
-
 extern _X_EXPORT Bool
 fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCIndex);
     
diff --git a/fb/fballpriv.c b/fb/fballpriv.c
index 569391b..efeb268 100644
--- a/fb/fballpriv.c
+++ b/fb/fballpriv.c
@@ -27,46 +27,34 @@
 #include "fb.h"
 
 #ifdef FB_SCREEN_PRIVATE
-static int fbScreenPrivateKeyIndex;
-static DevPrivateKey fbScreenPrivateKey = &fbScreenPrivateKeyIndex;
-DevPrivateKey fbGetScreenPrivateKey(void)
-{
-    return fbScreenPrivateKey;
-}
+static DevPrivateKeyRec fbScreenPrivateKeyRec;
+DevPrivateKey
+fbGetScreenPrivateKey(void) { return &fbScreenPrivateKeyRec; }
 #endif
 
-static int fbGCPrivateKeyIndex;
-static DevPrivateKey fbGCPrivateKey = &fbGCPrivateKeyIndex;
-DevPrivateKey fbGetGCPrivateKey(void)
-{
-    return fbGCPrivateKey;
-}
+static DevPrivateKeyRec fbGCPrivateKeyRec;
+DevPrivateKey
+fbGetGCPrivateKey (void) { return &fbGCPrivateKeyRec; }
 
-static int fbWinPrivateKeyIndex;
-static DevPrivateKey fbWinPrivateKey = &fbWinPrivateKeyIndex;
-DevPrivateKey fbGetWinPrivateKey(void)
-{
-    return fbWinPrivateKey;
-}
+static DevPrivateKeyRec fbWinPrivateKeyRec;
+DevPrivateKey
+fbGetWinPrivateKey (void) { return &fbWinPrivateKeyRec; }
 
 Bool
 fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCKey)
 {
     if (pGCKey)
-	*pGCKey = fbGCPrivateKey;
+	*pGCKey = &fbGCPrivateKeyRec;
     
-    if (!dixRequestPrivate(fbGCPrivateKey, sizeof(FbGCPrivRec)))
+    if (!dixRegisterPrivateKey(&fbGCPrivateKeyRec, PRIVATE_GC, sizeof(FbGCPrivRec)))
 	return FALSE;
 #ifdef FB_SCREEN_PRIVATE
-    {
-	FbScreenPrivPtr	pScreenPriv;
-
-	pScreenPriv = (FbScreenPrivPtr) malloc(sizeof (FbScreenPrivRec));
-	if (!pScreenPriv)
-	    return FALSE;
-	dixSetPrivate(&pScreen->devPrivates, fbScreenPrivateKey, pScreenPriv);
-    }
+    if (!dixRegisterPrivateKey(&fbScreenPrivateKeyRec, PRIVATE_SCREEN, sizeof (FbScreenPrivRec)))
+	return FALSE;
 #endif
+    if (!dixRegisterPrivateKey(&fbWinPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
     return TRUE;
 }
 
diff --git a/fb/fbcmap.c b/fb/fbcmap.c
index ce6fcd5..02b7268 100644
--- a/fb/fbcmap.c
+++ b/fb/fbcmap.c
@@ -36,8 +36,8 @@
 #error "You should be compiling fbcmap_mi.c instead of fbcmap.c!"
 #endif
 
-static int cmapScrPrivateKeyIndex;
-static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex;
+static DevPrivateKeyRec cmapScrPrivateKeyRec;
+#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
 
 #define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
 #define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
diff --git a/fb/fboverlay.c b/fb/fboverlay.c
index 392e27f..cda7fc7 100644
--- a/fb/fboverlay.c
+++ b/fb/fboverlay.c
@@ -33,8 +33,8 @@
 #include "fboverlay.h"
 #include "shmint.h"
 
-static int fbOverlayScreenPrivateKeyIndex;
-static DevPrivateKey fbOverlayScreenPrivateKey = &fbOverlayScreenPrivateKeyIndex;
+static DevPrivateKeyRec fbOverlayScreenPrivateKeyRec;
+#define fbOverlayScreenPrivateKey (&fbOverlayScreenPrivateKeyRec)
 
 DevPrivateKey fbOverlayGetScreenPrivateKey(void)
 {
@@ -348,6 +348,9 @@ fbOverlayFinishScreenInit(ScreenPtr	pScreen,
     VisualID	defaultVisual;
     FbOverlayScrPrivPtr	pScrPriv;
 
+    if (!dixRegisterPrivateKey(&fbOverlayScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     pScrPriv = malloc(sizeof (FbOverlayScrPrivRec));
     if (!pScrPriv)
 	return FALSE;
@@ -416,7 +419,6 @@ fbOverlayFinishScreenInit(ScreenPtr	pScreen,
     pScrPriv->layer[1].u.init.pbits = pbits2;
     pScrPriv->layer[1].u.init.width = width2;
     pScrPriv->layer[1].u.init.depth = depth2;
-    
     dixSetPrivate(&pScreen->devPrivates, fbOverlayScreenPrivateKey, pScrPriv);
     
     /* overwrite miCloseScreen with our own */
diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index 625ce71..15eedcd 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -67,6 +67,7 @@ fbCreatePixmapBpp (ScreenPtr pScreen, int width, int height, int depth, int bpp,
     pPixmap->devKind = paddedWidth;
     pPixmap->refcnt = 1;
     pPixmap->devPrivate.ptr = (pointer) ((char *)pPixmap + base + adjust);
+
 #ifdef FB_DEBUG
     pPixmap->devPrivate.ptr = (void *) ((char *) pPixmap->devPrivate.ptr + paddedWidth);
     fbInitializeDrawable (&pPixmap->drawable);
@@ -100,8 +101,7 @@ fbDestroyPixmap (PixmapPtr pPixmap)
 {
     if(--pPixmap->refcnt)
 	return TRUE;
-    dixFreePrivates(pPixmap->devPrivates);
-    free(pPixmap);
+    FreePixmap(pPixmap);
     return TRUE;
 }
 
diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index 9b789b0..f4311ae 100644
--- a/fb/fbscreen.c
+++ b/fb/fbscreen.c
@@ -37,9 +37,6 @@ fbCloseScreen (int index, ScreenPtr pScreen)
     free(depths);
     free(pScreen->visuals);
     free(pScreen->devPrivate);
-#ifdef FB_SCREEN_PRIVATE
-    free(dixLookupPrivate(&pScreen->devPrivates, fbGetScreenPrivateKey()));
-#endif
     return TRUE;
 }
 
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index 73ee510..433f286 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -83,13 +83,14 @@
 #define fbFixCoordModePrevious wfbFixCoordModePrevious
 #define fbGCFuncs wfbGCFuncs
 #define fbGCOps wfbGCOps
-#define fbGCPrivateKey wfbGCPrivateKey
+#define fbGCPrivateKeyRec wfbGCPrivateKeyRec
 #define fbGeneration wfbGeneration
 #define fbGetGCPrivateKey wfbGetGCPrivateKey
 #define fbGetImage wfbGetImage
 #define fbGetScreenPrivateKey wfbGetScreenPrivateKey
 #define fbGetSpans wfbGetSpans
 #define _fbGetWindowPixmap _wfbGetWindowPixmap
+#define fbWinPrivateKeyRec wfbWinPrivateKeyRec
 #define fbGetWinPrivateKey wfbGetWinPrivateKey
 #define fbGlyph16 wfbGlyph16
 #define fbGlyph24 wfbGlyph24
@@ -118,7 +119,6 @@
 #define fbOverlayGeneration wfbOverlayGeneration
 #define fbOverlayGetScreenPrivateKey wfbOverlayGetScreenPrivateKey
 #define fbOverlayPaintKey wfbOverlayPaintKey
-#define fbOverlayScreenPrivateKey wfbOverlayScreenPrivateKey
 #define fbOverlaySetupScreen wfbOverlaySetupScreen
 #define fbOverlayUpdateLayerRegion wfbOverlayUpdateLayerRegion
 #define fbOverlayWindowExposures wfbOverlayWindowExposures
@@ -157,7 +157,7 @@
 #define fbResolveColor wfbResolveColor
 #define fbRestoreAreas wfbRestoreAreas
 #define fbSaveAreas wfbSaveAreas
-#define fbScreenPrivateKey wfbScreenPrivateKey
+#define fbScreenPrivateKeyRec wfbScreenPrivateKeyRec
 #define fbSegment wfbSegment
 #define fbSelectBres wfbSelectBres
 #define fbSetSpans wfbSetSpans
@@ -182,7 +182,7 @@
 #define fbUnrealizeFont wfbUnrealizeFont
 #define fbValidateGC wfbValidateGC
 #define fbWalkCompositeRegion wfbWalkCompositeRegion
-#define fbWinPrivateKey wfbWinPrivateKey
+#define fbWinPrivateKeyRec wfbWinPrivateKeyRec
 #define fbZeroLine wfbZeroLine
 #define fbZeroSegment wfbZeroSegment
 #define free_pixman_pict wfb_free_pixman_pict
diff --git a/glx/glxext.c b/glx/glxext.c
index b234afc..4d02b47 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -65,8 +65,8 @@ RESTYPE __glXSwapBarrierRes;
 */
 xGLXSingleReply __glXReply;
 
-static int glxClientPrivateKeyIndex;
-static DevPrivateKey glxClientPrivateKey = &glxClientPrivateKeyIndex;
+static DevPrivateKeyRec glxClientPrivateKeyRec;
+#define glxClientPrivateKey (&glxClientPrivateKeyRec)
 
 /*
 ** Client that called into GLX dispatch.
@@ -364,7 +364,7 @@ void GlxExtensionInit(void)
     if (!__glXContextRes || !__glXDrawableRes || !__glXSwapBarrierRes)
 	return;
 
-    if (!dixRequestPrivate(glxClientPrivateKey, sizeof (__GLXclientState)))
+    if (!dixRegisterPrivateKey(&glxClientPrivateKeyRec, PRIVATE_CLIENT, sizeof (__GLXclientState)))
 	return;
     if (!AddCallback (&ClientStateCallback, glxClientCallback, 0))
 	return;
diff --git a/glx/glxscreens.c b/glx/glxscreens.c
index ffe70c3..a5b61df 100644
--- a/glx/glxscreens.c
+++ b/glx/glxscreens.c
@@ -44,8 +44,8 @@
 #include "glxext.h"
 #include "protocol-versions.h"
 
-static int glxScreenPrivateKeyIndex;
-static DevPrivateKey glxScreenPrivateKey = &glxScreenPrivateKeyIndex;
+static DevPrivateKeyRec glxScreenPrivateKeyRec;
+#define glxScreenPrivateKey (&glxScreenPrivateKeyRec)
 
 const char GLServerVersion[] = "1.4";
 static const char GLServerExtensions[] = 
@@ -352,6 +352,9 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
     __GLXconfig *config;
     int i;
 
+    if (!dixRegisterPrivateKey(&glxScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     pGlxScreen->pScreen       = pScreen;
     pGlxScreen->GLextensions  = xstrdup(GLServerExtensions);
     pGlxScreen->GLXvendor     = xstrdup(GLXServerVendorName);
diff --git a/hw/dmx/dmx.h b/hw/dmx/dmx.h
index fbb8b96..4532960 100644
--- a/hw/dmx/dmx.h
+++ b/hw/dmx/dmx.h
@@ -364,4 +364,27 @@ do {									\
 #define MAXSCREENSCALLOC_FATAL(o,m)     _MAXSCREENSALLOCF(o,MAXSCREENS*(m),1)
 #endif
 
+extern DevPrivateKeyRec dmxGCPrivateKeyRec;
+#define dmxGCPrivateKey (&dmxGCPrivateKeyRec) /**< Private index for GCs       */
+
+extern DevPrivateKeyRec dmxWinPrivateKeyRec;
+#define dmxWinPrivateKey (&dmxWinPrivateKeyRec) /**< Private index for Windows   */
+
+extern DevPrivateKeyRec dmxPixPrivateKeyRec;
+#define dmxPixPrivateKey (&dmxPixPrivateKeyRec) /**< Private index for Pixmaps   */
+
+extern int dmxFontPrivateIndex;        /**< Private index for Fonts     */
+
+extern DevPrivateKeyRec dmxScreenPrivateKeyRec;
+#define dmxScreenPrivateKey (&dmxScreenPrivateKeyRec) /**< Private index for Screens   */
+
+extern DevPrivateKeyRec dmxColormapPrivateKeyRec;
+#define dmxColormapPrivateKey (&dmxColormapPrivateKeyRec) /**< Private index for Colormaps */
+
+extern DevPrivateKeyRec dmxPictPrivateKeyRec;
+#define dmxPictPrivateKey (&dmxPictPrivateKeyRec) /**< Private index for Picts     */
+
+extern DevPrivateKeyRec dmxGlyphSetPrivateKeyRec;
+#define dmxGlyphSetPrivateKey (&dmxGlyphSetPrivateKeyRec) /**< Private index for GlyphSets */
+
 #endif /* DMX_H */
diff --git a/hw/dmx/dmxcmap.h b/hw/dmx/dmxcmap.h
index f968f86..75e0650 100644
--- a/hw/dmx/dmxcmap.h
+++ b/hw/dmx/dmxcmap.h
@@ -55,9 +55,6 @@ extern Bool dmxCreateDefColormap(ScreenPtr pScreen);
 extern Bool dmxBECreateColormap(ColormapPtr pColormap);
 extern Bool dmxBEFreeColormap(ColormapPtr pColormap);
 
-/** Private index.  \see dmxcmap.c \see dmxscrinit.c \see dmxwindow.c */
-extern DevPrivateKey dmxColormapPrivateKey;
-
 /** Set colormap private structure. */
 #define DMX_SET_COLORMAP_PRIV(_pCMap, _pCMapPriv)			\
     dixSetPrivate(&(_pCMap)->devPrivates, dmxColormapPrivateKey, _pCMapPriv)
diff --git a/hw/dmx/dmxgc.c b/hw/dmx/dmxgc.c
index 3e75de7..829200e 100644
--- a/hw/dmx/dmxgc.c
+++ b/hw/dmx/dmxgc.c
@@ -85,7 +85,7 @@ static GCOps dmxGCOps = {
 /** Initialize the GC on \a pScreen */
 Bool dmxInitGC(ScreenPtr pScreen)
 {
-    if (!dixRequestPrivate(dmxGCPrivateKey, sizeof(dmxGCPrivRec)))
+    if (!dixRegisterPrivateKey(&dmxGCPrivateKeyRec, PRIVATE_GC, sizeof(dmxGCPrivRec)))
             return FALSE;
     return TRUE;
 }
diff --git a/hw/dmx/dmxgc.h b/hw/dmx/dmxgc.h
index 2da3ba8..4ff3cd8 100644
--- a/hw/dmx/dmxgc.h
+++ b/hw/dmx/dmxgc.h
@@ -63,9 +63,6 @@ extern void dmxCopyClip(GCPtr pGCDst, GCPtr pGCSrc);
 extern void dmxBECreateGC(ScreenPtr pScreen, GCPtr pGC);
 extern Bool dmxBEFreeGC(GCPtr pGC);
 
-/** Private index.  \see dmxgc.c \see dmxscrinit.c */
-extern DevPrivateKey dmxGCPrivateKey;
-
 /** Get private. */
 #define DMX_GET_GC_PRIV(_pGC)						\
     (dmxGCPrivPtr)dixLookupPrivate(&(_pGC)->devPrivates, dmxGCPrivateKey)
diff --git a/hw/dmx/dmxpict.c b/hw/dmx/dmxpict.c
index 1642145..915e767 100644
--- a/hw/dmx/dmxpict.c
+++ b/hw/dmx/dmxpict.c
@@ -145,7 +145,7 @@ Bool dmxPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
     if (!miPictureInit(pScreen, formats, nformats))
 	return FALSE;
 
-    if (!dixRequestPrivate(dmxPictPrivateKey, sizeof(dmxPictPrivRec)))
+    if (!dixRegisterPrivateKey(&dmxPictPrivateKeyRec, PRIVATE_PICTURE, sizeof(dmxPictPrivRec)))
 	return FALSE;
 
     ps = GetPictureScreen(pScreen);
diff --git a/hw/dmx/dmxpict.h b/hw/dmx/dmxpict.h
index a81eb7d..3c8a09c 100644
--- a/hw/dmx/dmxpict.h
+++ b/hw/dmx/dmxpict.h
@@ -116,10 +116,6 @@ extern Bool dmxBEFreeGlyphSet(ScreenPtr pScreen, GlyphSetPtr glyphSet);
 extern int dmxBECreatePicture(PicturePtr pPicture);
 extern Bool dmxBEFreePicture(PicturePtr pPicture);
 
-extern DevPrivateKey dmxPictPrivateKey;	/**< Index for picture private data */
-extern DevPrivateKey dmxGlyphSetPrivateKey; /**< Index for glyphset private data */
-
-
 /** Get the picture private data given a picture pointer */
 #define DMX_GET_PICT_PRIV(_pPict)					\
     (dmxPictPrivPtr)dixLookupPrivate(&(_pPict)->devPrivates, dmxPictPrivateKey)
diff --git a/hw/dmx/dmxpixmap.c b/hw/dmx/dmxpixmap.c
index a64cbd0..a058ae2 100644
--- a/hw/dmx/dmxpixmap.c
+++ b/hw/dmx/dmxpixmap.c
@@ -49,7 +49,7 @@
 /** Initialize a private area in \a pScreen for pixmap information. */
 Bool dmxInitPixmap(ScreenPtr pScreen)
 {
-    if (!dixRequestPrivate(dmxPixPrivateKey, sizeof(dmxPixPrivRec)))
+    if (!dixRegisterPrivateKey(&dmxPixPrivateKeyRec, PRIVATE_PIXMAP, sizeof(dmxPixPrivRec)))
 	return FALSE;
 
     return TRUE;
@@ -174,8 +174,7 @@ Bool dmxDestroyPixmap(PixmapPtr pPixmap)
 	    dmxSync(dmxScreen, FALSE);
 	}
     }
-    dixFreePrivates(pPixmap->devPrivates);
-    free(pPixmap);
+    FreePixmap(pPixmap);
 
 #if 0
     if (pScreen->DestroyPixmap)
diff --git a/hw/dmx/dmxpixmap.h b/hw/dmx/dmxpixmap.h
index 6441834..59da788 100644
--- a/hw/dmx/dmxpixmap.h
+++ b/hw/dmx/dmxpixmap.h
@@ -57,9 +57,6 @@ extern RegionPtr dmxBitmapToRegion(PixmapPtr pPixmap);
 extern void      dmxBECreatePixmap(PixmapPtr pPixmap);
 extern Bool      dmxBEFreePixmap(PixmapPtr pPixmap);
 
-/** Private index.  \see dmxpicmap.h \see dmxscrinit.c */
-extern DevPrivateKey dmxPixPrivateKey;
-
 /** Get pixmap private pointer. */
 #define DMX_GET_PIXMAP_PRIV(_pPix)					\
     (dmxPixPrivPtr)dixLookupPrivate(&(_pPix)->devPrivates, dmxPixPrivateKey)
diff --git a/hw/dmx/dmxscrinit.c b/hw/dmx/dmxscrinit.c
index 068e809..6d2f2d3 100644
--- a/hw/dmx/dmxscrinit.c
+++ b/hw/dmx/dmxscrinit.c
@@ -65,21 +65,14 @@ static Bool dmxSaveScreen(ScreenPtr pScreen, int what);
 static unsigned long dmxGeneration;
 static unsigned long *dmxCursorGeneration;
 
-static int dmxGCPrivateKeyIndex;
-DevPrivateKey dmxGCPrivateKey = &dmxGCPrivateKeyIndex; /**< Private index for GCs       */
-static int dmxWinPrivateKeyIndex;
-DevPrivateKey dmxWinPrivateKey = &dmxWinPrivateKeyIndex; /**< Private index for Windows   */
-static int dmxPixPrivateKeyIndex;
-DevPrivateKey dmxPixPrivateKey = &dmxPixPrivateKeyIndex; /**< Private index for Pixmaps   */
+DevPrivateKeyRec dmxGCPrivateKeyRec;
+DevPrivateKeyRec dmxWinPrivateKeyRec;
+DevPrivateKeyRec dmxPixPrivateKeyRec;
 int dmxFontPrivateIndex;        /**< Private index for Fonts     */
-static int dmxScreenPrivateKeyIndex;
-DevPrivateKey dmxScreenPrivateKey = &dmxScreenPrivateKeyIndex; /**< Private index for Screens   */
-static int dmxColormapPrivateKeyIndex;
-DevPrivateKey dmxColormapPrivateKey = &dmxColormapPrivateKeyIndex; /**< Private index for Colormaps */
-static int dmxPictPrivateKeyIndex;
-DevPrivateKey dmxPictPrivateKey = &dmxPictPrivateKeyIndex; /**< Private index for Picts     */
-static int dmxGlyphSetPrivateKeyIndex;
-DevPrivateKey dmxGlyphSetPrivateKey = &dmxGlyphSetPrivateKeyIndex; /**< Private index for GlyphSets */
+DevPrivateKeyRec dmxScreenPrivateKeyRec;
+DevPrivateKeyRec dmxColormapPrivateKeyRec;
+DevPrivateKeyRec dmxPictPrivateKeyRec;
+DevPrivateKeyRec dmxGlyphSetPrivateKeyRec;
 
 /** Initialize the parts of screen \a idx that require access to the
  *  back-end server. */
@@ -210,6 +203,13 @@ Bool dmxScreenInit(int idx, ScreenPtr pScreen, int argc, char *argv[])
     DMXScreenInfo        *dmxScreen = &dmxScreens[idx];
     int                   i, j;
 
+    if (!dixRegisterPrivateKey(&dmxScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&dmxColormapPrivateKeyRec, PRIVATE_COLORMAP, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&dmxGlyphSetPrivateKeyRec, PRIVATE_GLYPHSET, 0))
+	return FALSE;
+
     if (dmxGeneration != serverGeneration) {
 	/* Allocate font private index */
 	dmxFontPrivateIndex = AllocateFontPrivateIndex();
diff --git a/hw/dmx/dmxscrinit.h b/hw/dmx/dmxscrinit.h
index a464235..9c9fbc5 100644
--- a/hw/dmx/dmxscrinit.h
+++ b/hw/dmx/dmxscrinit.h
@@ -40,9 +40,6 @@
 
 #include "scrnintstr.h"
 
-/** Private index.  \see dmxscrrinit.c \see input/dmxconcole.c */
-extern DevPrivateKey dmxScreenPrivateKey;
-
 extern Bool dmxScreenInit(int idx, ScreenPtr pScreen, int argc, char *argv[]);
 
 extern void dmxBEScreenInit(int idx, ScreenPtr pScreen);
diff --git a/hw/dmx/dmxwindow.c b/hw/dmx/dmxwindow.c
index 28212a3..4484828 100644
--- a/hw/dmx/dmxwindow.c
+++ b/hw/dmx/dmxwindow.c
@@ -60,7 +60,7 @@ static void dmxDoSetShape(WindowPtr pWindow);
 /** Initialize the private area for the window functions. */
 Bool dmxInitWindow(ScreenPtr pScreen)
 {
-    if (!dixRequestPrivate(dmxWinPrivateKey, sizeof(dmxWinPrivRec)))
+    if (!dixRegisterPrivateKey(&dmxWinPrivateKeyRec, PRIVATE_WINDOW, sizeof(dmxWinPrivRec)))
 	return FALSE;
 
     return TRUE;
diff --git a/hw/dmx/dmxwindow.h b/hw/dmx/dmxwindow.h
index 8bd1f74..f93121e 100644
--- a/hw/dmx/dmxwindow.h
+++ b/hw/dmx/dmxwindow.h
@@ -96,9 +96,6 @@ extern Bool dmxBEDestroyWindow(WindowPtr pWindow);
 /* Support for shape extension */
 extern void dmxSetShape(WindowPtr pWindow, int kind);
 
-/** Private index.  \see dmxwindow.c \see dmxscrinit.c */
-extern DevPrivateKey dmxWinPrivateKey;
-
 /** Get window private pointer. */
 #define DMX_GET_WINDOW_PRIV(_pWin) ((dmxWinPrivPtr) \
     dixLookupPrivate(&(_pWin)->devPrivates, dmxWinPrivateKey))
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 23c2032..4041bf5 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -109,10 +109,10 @@ static Bool findWindowPairFromLocal (WindowPtr a_local,
 
 static unsigned char DRIReqCode = 0;
 
-static int ephyrDRIWindowKeyIndex;
-static DevPrivateKey ephyrDRIWindowKey = &ephyrDRIWindowKeyIndex;
-static int ephyrDRIScreenKeyIndex;
-static DevPrivateKey ephyrDRIScreenKey = &ephyrDRIScreenKeyIndex;
+static DevPrivateKeyRec ephyrDRIWindowKeyRec;
+#define ephyrDRIWindowKey (&ephyrDRIWindowKeyRec)
+static DevPrivateKeyRec ephyrDRIScreenKeyRec;
+#define ephyrDRIScreenKey (&ephyrDRIScreenKeyRec)
 
 #define GET_EPHYR_DRI_WINDOW_PRIV(win) ((EphyrDRIWindowPrivPtr) \
     dixLookupPrivate(&(win)->devPrivates, ephyrDRIWindowKey))
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 27596e4..06c3661 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -64,8 +64,7 @@ KdDepths    kdDepths[] = {
 
 #define KD_DEFAULT_BUTTONS 5
 
-static int          kdScreenPrivateKeyIndex;
-DevPrivateKey       kdScreenPrivateKey = &kdScreenPrivateKeyIndex;
+DevPrivateKeyRec    kdScreenPrivateKeyRec;
 unsigned long	    kdGeneration;
 
 Bool                kdVideoTest;
@@ -699,6 +698,9 @@ KdAllocatePrivates (ScreenPtr pScreen)
     if (kdGeneration != serverGeneration)
 	kdGeneration = serverGeneration;
 
+    if (!dixRegisterPrivateKey(&kdScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     pScreenPriv = calloc(1, sizeof (*pScreenPriv));
     if (!pScreenPriv)
 	return FALSE;
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 35ce036..3ca9814 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -342,7 +342,9 @@ typedef struct _KdPointerMatrix {
     (PixmapWidthPaddingInfo[d].padRoundUp+1)))
 #endif
 
-extern DevPrivateKey	kdScreenPrivateKey;
+extern DevPrivateKeyRec	kdScreenPrivateKeyRec;
+#define kdScreenPrivateKey (&kdScreenPrivateKeyRec)
+
 extern unsigned long	kdGeneration;
 extern Bool		kdEnabled;
 extern Bool		kdSwitchPending;
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 99ab2d8..24ae89e 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -103,10 +103,10 @@ static void KdXVClipNotify(WindowPtr pWin, int dx, int dy);
 /* misc */
 static Bool KdXVInitAdaptors(ScreenPtr, KdVideoAdaptorPtr*, int);
 
-static int KdXVWindowKeyIndex;
-DevPrivateKey KdXVWindowKey = &KdXVWindowKeyIndex;
-static int KdXvScreenKeyIndex;
-DevPrivateKey KdXvScreenKey = &KdXvScreenKeyIndex;
+static DevPrivateKeyRec KdXVWindowKeyRec;
+#define KdXVWindowKey (&KdXVWindowKeyRec)
+static DevPrivateKeyRec KdXvScreenKeyRec;
+#define KdXvScreenKey (&KdXvScreenKeyRec)
 static unsigned long KdXVGeneration = 0;
 static unsigned long PortResource = 0;
 
@@ -199,6 +199,12 @@ KdXVScreenInit(
   if(!XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc)
 	return FALSE;
 
+  if (!dixRegisterPrivateKey(&KdXVWindowKeyRec, PRIVATE_WINDOW, 0))
+      return FALSE;
+
+  if (!dixRegisterPrivateKey(&KdXVScreenKeyRec, PRIVATE_SCREEN, 0))
+      return FALSE;
+
   if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
 
   KdXvScreenKey = (*XvGetScreenKeyProc)();
diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index 0f0edb2..2f41955 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -389,8 +389,8 @@ ddxProcessArgument(int argc, char *argv[], int i)
     return 0;
 }
 
-static int cmapScrPrivateKeyIndex;
-static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex;
+static DevPrivateKeyRec cmapScrPrivateKeyRec;
+#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
 
 #define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
 #define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
@@ -811,6 +811,9 @@ vfbScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     int ret;
     char *pbits;
     
+    if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     if (dpix == 0)
       dpix = 100;
 
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index d8629a8..886c25b 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -55,9 +55,16 @@
 extern _X_EXPORT int xf86DoConfigure;
 extern _X_EXPORT int xf86DoShowOptions;
 extern _X_EXPORT Bool xf86DoConfigurePass1;
-extern _X_EXPORT DevPrivateKey xf86ScreenKey;
-extern _X_EXPORT DevPrivateKey xf86CreateRootWindowKey;
-extern _X_EXPORT DevPrivateKey xf86PixmapKey;
+
+extern _X_EXPORT DevPrivateKeyRec xf86ScreenKeyRec;
+#define xf86ScreenKey (&xf86ScreenKeyRec)
+
+extern _X_EXPORT DevPrivateKeyRec xf86CreateRootWindowKeyRec;
+#define xf86CreateRootWindowKey (&xf86CreateRootWindowKeyRec)
+
+extern _X_EXPORT DevPrivateKeyRec xf86PixmapKeyRec;
+#define xf86PixmapKey (&xf86PixmapKeyRec)
+
 extern _X_EXPORT ScrnInfoPtr *xf86Screens;	/* List of pointers to ScrnInfoRecs */
 extern _X_EXPORT const unsigned char byte_reversed[256];
 extern _X_EXPORT Bool fbSlotClaimed;
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index a51a754..82fb52a 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -51,8 +51,8 @@
 
 #include "mi.h"
 
-static int DGAScreenKeyIndex;
-static DevPrivateKey DGAScreenKey;
+static DevPrivateKeyRec DGAScreenKeyRec;
+#define DGAScreenKeyRegistered dixPrivateKeyRegistered(&DGAScreenKeyRec)
 static int mieq_installed = 0;
 
 static Bool DGACloseScreen(int i, ScreenPtr pScreen);
@@ -71,7 +71,7 @@ DGACopyModeInfo(
 int *XDGAEventBase = NULL;
 
 #define DGA_GET_SCREEN_PRIV(pScreen) ((DGAScreenPtr) \
-    dixLookupPrivate(&(pScreen)->devPrivates, DGAScreenKey))
+    dixLookupPrivate(&(pScreen)->devPrivates, &DGAScreenKeyRec))
 
 
 typedef struct _FakedVisualList{
@@ -118,7 +118,8 @@ DGAInit(
     if(!modes || num <= 0)
 	return FALSE;
 
-    DGAScreenKey = &DGAScreenKeyIndex;
+    if (!dixRegisterPrivateKey(&DGAScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
 
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
@@ -126,7 +127,7 @@ DGAInit(
     {
 	if(!(pScreenPriv = (DGAScreenPtr)malloc(sizeof(DGAScreenRec))))
 	    return FALSE;
-	dixSetPrivate(&pScreen->devPrivates, DGAScreenKey, pScreenPriv);
+	dixSetPrivate(&pScreen->devPrivates, &DGAScreenKeyRec, pScreenPriv);
 	pScreenPriv->CloseScreen = pScreen->CloseScreen;
 	pScreen->CloseScreen = DGACloseScreen;
 	pScreenPriv->DestroyColormap = pScreen->DestroyColormap;
@@ -177,7 +178,7 @@ DGAReInitModes(
     int i;
 
     /* No DGA? Ignore call (but don't make it look like it failed) */
-    if(DGAScreenKey == NULL)
+    if(!DGAScreenKeyRegistered)
 	return TRUE;
 	
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
@@ -347,7 +348,7 @@ xf86SetDGAMode(
    DGAModePtr pMode = NULL;
 
    /* First check if DGAInit was successful on this screen */
-   if (DGAScreenKey == NULL)
+   if (!DGAScreenKeyRegistered)
 	return BadValue;
    pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
    if (!pScreenPriv)
@@ -478,7 +479,7 @@ DGAChangePixmapMode(int index, int *x, int *y, int mode)
    DGAModePtr   pMode;
    PixmapPtr    pPix;
 
-   if(DGAScreenKey == NULL)
+   if(!DGAScreenKeyRegistered)
 	return FALSE;
 
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -528,7 +529,7 @@ DGAChangePixmapMode(int index, int *x, int *y, int mode)
 Bool
 DGAAvailable(int index) 
 {
-   if(DGAScreenKey == NULL)
+   if(!DGAScreenKeyRegistered)
 	return FALSE;
    
    if(DGA_GET_SCREEN_PRIV(screenInfo.screens[index]))
@@ -542,7 +543,7 @@ DGAActive(int index)
 {
    DGAScreenPtr pScreenPriv;
 
-   if(DGAScreenKey == NULL)
+   if(!DGAScreenKeyRegistered)
 	return FALSE;
 
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -563,7 +564,7 @@ DGAShutdown(void)
     ScrnInfoPtr pScrn;
     int i;
 
-    if(DGAScreenKey == NULL)
+    if(!DGAScreenKeyRegistered)
 	return;
 
     for(i = 0; i < screenInfo.numScreens; i++) {
@@ -893,7 +894,7 @@ DGAVTSwitch(void)
 
        /* Alternatively, this could send events to DGA clients */
 
-       if(DGAScreenKey) {
+       if(DGAScreenKeyRegistered) {
 	   DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
 	   if(pScreenPriv && pScreenPriv->current)
@@ -910,7 +911,7 @@ DGAStealKeyEvent(DeviceIntPtr dev, int index, int key_code, int is_down)
    DGAScreenPtr pScreenPriv;
    DGAEvent     event;
 
-   if(DGAScreenKey == NULL) /* no DGA */
+   if(!DGAScreenKeyRegistered) /* no DGA */
         return FALSE;
 
    if (key_code < 8 || key_code > 255)
@@ -943,7 +944,7 @@ DGAStealMotionEvent(DeviceIntPtr dev, int index, int dx, int dy)
    DGAScreenPtr pScreenPriv;
    DGAEvent event;
 
-   if(DGAScreenKey == NULL) /* no DGA */
+   if(!DGAScreenKeyRegistered) /* no DGA */
         return FALSE;
     
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -981,7 +982,7 @@ DGAStealButtonEvent(DeviceIntPtr dev, int index, int button, int is_down)
     DGAScreenPtr pScreenPriv;
     DGAEvent event;
 
-    if (DGAScreenKey == NULL)
+    if(!DGAScreenKeyRegistered) /* no DGA */
         return FALSE;
     
     pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -1009,7 +1010,7 @@ Bool
 DGAIsDgaEvent (xEvent *e)
 {
     int	    coreEquiv;
-    if (DGAScreenKey == NULL || XDGAEventBase == 0)
+    if (!DGAScreenKeyRegistered || XDGAEventBase == 0)
 	return FALSE;
     coreEquiv = e->u.u.type - *XDGAEventBase;
     if (KeyPress <= coreEquiv && coreEquiv <= MotionNotify)
@@ -1203,7 +1204,7 @@ DGAHandleEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
     DGAScreenPtr    pScreenPriv;
 
     /* no DGA */
-    if (DGAScreenKey == NULL || XDGAEventBase == 0)
+    if (!DGAScreenKeyRegistered || XDGAEventBase == 0)
 	return;
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index cd33e75..cd025dc 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -46,7 +46,7 @@
 
 
 #ifdef DPMSExtension
-static int DPMSKeyIndex;
+static DevPrivateKeyRec DPMSKeyRec;
 static DevPrivateKey DPMSKey;
 static Bool DPMSClose(int i, ScreenPtr pScreen);
 static int DPMSCount = 0;
@@ -62,10 +62,9 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
     pointer DPMSOpt;
     MessageType enabled_from;
 
-    DPMSKey = &DPMSKeyIndex;
+    DPMSKey = &DPMSKeyRec;
 
-    if (!dixSetPrivate(&pScreen->devPrivates, DPMSKey,
-		       calloc(sizeof(DPMSRec), 1)))
+    if (!dixRegisterPrivateKey(&DPMSKeyRec, PRIVATE_SCREEN, sizeof (DPMSRec)))
 	return FALSE;
 
     pDPMS = dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
@@ -127,8 +126,6 @@ DPMSClose(int i, ScreenPtr pScreen)
  	xf86Screens[i]->DPMSSet(xf86Screens[i],DPMSModeOn,0);
     }
     
-    free(pDPMS);
-    dixSetPrivate(&pScreen->devPrivates, DPMSKey, NULL);
     if (--DPMSCount == 0)
 	DPMSKey = NULL;
     return pScreen->CloseScreen(i, pScreen);
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 8b483f3..43665d1 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -47,14 +47,10 @@
 
 /* Globals that video drivers may access */
 
-/* Index into pScreen.devPrivates */
-static int xf86CreateRootWindowKeyIndex;
-DevPrivateKey xf86CreateRootWindowKey = &xf86CreateRootWindowKeyIndex;
-/* Index of ScrnInfo in pScreen.devPrivates */
-static int xf86ScreenKeyIndex;
-DevPrivateKey xf86ScreenKey = &xf86ScreenKeyIndex;
-static int xf86PixmapKeyIndex;
-DevPrivateKey xf86PixmapKey = &xf86PixmapKeyIndex;
+DevPrivateKeyRec xf86CreateRootWindowKeyRec;
+DevPrivateKeyRec xf86ScreenKeyRec;
+DevPrivateKeyRec xf86PixmapKeyRec;
+
 ScrnInfoPtr *xf86Screens = NULL;	/* List of ScrnInfos */
 const unsigned char byte_reversed[256] =
 {
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index db88f70..18df8c9 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -66,6 +66,7 @@
 #include "xf86Priv.h"
 #include "xf86Config.h"
 #include "xf86_OSlib.h"
+#include "xf86cmap.h"
 #include "xorgVersion.h"
 #include "xf86Build.h"
 #include "mipointer.h"
@@ -734,6 +735,15 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
   }
 #endif /* SCO325 */
 
+  for (i = 0; i < xf86NumScreens; i++)
+      if (!xf86ColormapAllocatePrivates(xf86Screens[i]))
+	  FatalError("Cannot register DDX private keys");
+
+  if (!dixRegisterPrivateKey(&xf86ScreenKeyRec, PRIVATE_SCREEN, 0) ||
+      !dixRegisterPrivateKey(&xf86CreateRootWindowKeyRec, PRIVATE_SCREEN, 0) ||
+      !dixRegisterPrivateKey(&xf86PixmapKeyRec, PRIVATE_PIXMAP, 0))
+      FatalError("Cannot register DDX private keys");
+
   for (i = 0; i < xf86NumScreens; i++) {
 	xf86VGAarbiterLock(xf86Screens[i]);
 	/*
diff --git a/hw/xfree86/common/xf86RandR.c b/hw/xfree86/common/xf86RandR.c
index 77053b8..d7ffff4 100644
--- a/hw/xfree86/common/xf86RandR.c
+++ b/hw/xfree86/common/xf86RandR.c
@@ -46,7 +46,7 @@ typedef struct _xf86RandRInfo {
     Rotation			    rotation;
 } XF86RandRInfoRec, *XF86RandRInfoPtr;
 
-static int xf86RandRKeyIndex;
+static DevPrivateKeyRec xf86RandRKeyRec;
 static DevPrivateKey xf86RandRKey;
 
 #define XF86RANDRINFO(p) ((XF86RandRInfoPtr)dixLookupPrivate(&(p)->devPrivates, xf86RandRKey))
@@ -424,7 +424,10 @@ xf86RandRInit (ScreenPtr    pScreen)
 	return TRUE;
 #endif
 
-    xf86RandRKey = &xf86RandRKeyIndex;
+    xf86RandRKey = &xf86RandRKeyRec;
+
+    if (!dixRegisterPrivateKey(&xf86RandRKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
 
     randrp = malloc(sizeof (XF86RandRInfoRec));
     if (!randrp)
diff --git a/hw/xfree86/common/xf86VGAarbiter.c b/hw/xfree86/common/xf86VGAarbiter.c
index 4a736fc..a58d21a 100644
--- a/hw/xfree86/common/xf86VGAarbiter.c
+++ b/hw/xfree86/common/xf86VGAarbiter.c
@@ -62,10 +62,10 @@ static miPointerSpriteFuncRec VGAarbiterSpriteFuncs = {
     VGAarbiterDeviceCursorInitialize, VGAarbiterDeviceCursorCleanup
 };
 
-static int VGAarbiterKeyIndex;
-static DevPrivateKey VGAarbiterScreenKey = &VGAarbiterKeyIndex;
-static int VGAarbiterGCIndex;
-static DevPrivateKey VGAarbiterGCKey = &VGAarbiterGCIndex;
+static DevPrivateKeyRec VGAarbiterScreenKeyRec;
+#define VGAarbiterScreenKey (&VGAarbiterScreenKeyRec)
+static DevPrivateKeyRec VGAarbiterGCKeyRec;
+#define VGAarbiterGCKey (&VGAarbiterGCKeyRec)
 
 static int vga_no_arb = 0;
 void
@@ -175,9 +175,12 @@ xf86VGAarbiterWrapFunctions(void)
         pScrn = xf86Screens[pScreen->myNum];
         PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
 
-        if (!dixRequestPrivate(VGAarbiterGCKey, sizeof(VGAarbiterGCRec)))
+        if (!dixRegisterPrivateKey(&VGAarbiterGCKeyRec, PRIVATE_GC, sizeof(VGAarbiterGCRec)))
             return FALSE;
 
+	if (!dixRegisterPrivateKey(&VGAarbiterScreenKeyRec, PRIVATE_SCREEN, 0))
+	    return FALSE;
+
         if (!(pScreenPriv = malloc(sizeof(VGAarbiterScreenRec))))
             return FALSE;
 
diff --git a/hw/xfree86/common/xf86VidMode.c b/hw/xfree86/common/xf86VidMode.c
index e704f5a..1788fa1 100644
--- a/hw/xfree86/common/xf86VidMode.c
+++ b/hw/xfree86/common/xf86VidMode.c
@@ -47,7 +47,7 @@
 #include "vidmodeproc.h"
 #include "xf86cmap.h"
 
-static int VidModeKeyIndex;
+static DevPrivateKeyRec VidModeKeyRec;
 static DevPrivateKey VidModeKey;
 static int VidModeCount = 0;
 static Bool VidModeClose(int i, ScreenPtr pScreen);
@@ -67,15 +67,17 @@ VidModeExtensionInit(ScreenPtr pScreen)
 	return FALSE;
     }
 
-    VidModeKey = &VidModeKeyIndex;
+    VidModeKey = &VidModeKeyRec;
 
-    if (!dixSetPrivate(&pScreen->devPrivates, VidModeKey,
-		       calloc(sizeof(VidModeRec), 1))) {
-	DebugF("xcalloc failed\n");
+    if (!dixRegisterPrivateKey(&VidModeKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
-    }
 
-    pVidMode = VMPTR(pScreen);
+    pVidMode = calloc(sizeof(VidModeRec), 1);
+    if (!pVidMode)
+	return FALSE;
+
+    dixSetPrivate(&pScreen->devPrivates, VidModeKey, pVidMode);
+
     pVidMode->Flags = 0;
     pVidMode->Next = NULL;
     pVidMode->CloseScreen = pScreen->CloseScreen;
diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index f59ffcb..f26c22c 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -102,10 +102,11 @@ typedef struct {
   int		overscan;
 } CMapColormapRec, *CMapColormapPtr;
 
-static int CMapScreenKeyIndex;
-static DevPrivateKey CMapScreenKey;
-static int CMapColormapKeyIndex;
-static DevPrivateKey CMapColormapKey = &CMapColormapKeyIndex;
+static DevPrivateKeyRec CMapScreenKeyRec;
+#define CMapScreenKeyRegistered dixPrivateKeyRegistered(&CMapScreenKeyRec)
+#define CMapScreenKey (&CMapScreenKeyRec)
+static DevPrivateKeyRec CMapColormapKeyRec;
+#define CMapColormapKey (&CMapColormapKeyRec)
 
 static void CMapInstallColormap(ColormapPtr);
 static void CMapStoreColors(ColormapPtr, int, xColorItem *);
@@ -128,6 +129,18 @@ static void CMapReinstallMap(ColormapPtr);
 static void CMapUnwrapScreen(ScreenPtr pScreen);
 
 
+Bool xf86ColormapAllocatePrivates(ScrnInfoPtr pScrn)
+{
+    /* If we support a better colormap system, then pretend we succeeded. */
+    if (xf86_crtc_supports_gamma(pScrn))
+	return TRUE;
+    if (!dixRegisterPrivateKey(&CMapScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&CMapColormapKeyRec, PRIVATE_COLORMAP, 0))
+	return FALSE;
+    return TRUE;
+}
 
 Bool xf86HandleColormaps(
     ScreenPtr pScreen,
@@ -151,8 +164,6 @@ Bool xf86HandleColormaps(
     if(!maxColors || !sigRGBbits || !loadPalette)
 	return FALSE;
 
-    CMapScreenKey = &CMapScreenKeyIndex;
-
     elements = 1 << sigRGBbits;
 
     if(!(gamma = malloc(elements * sizeof(LOCO))))
@@ -169,7 +180,7 @@ Bool xf86HandleColormaps(
 	return FALSE;     
     }
 
-    dixSetPrivate(&pScreen->devPrivates, CMapScreenKey, pScreenPriv);
+    dixSetPrivate(&pScreen->devPrivates, &CMapScreenKeyRec, pScreenPriv);
      
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreenPriv->CreateColormap = pScreen->CreateColormap;
@@ -900,7 +911,7 @@ CMapChangeGamma(
     CMapLinkPtr pLink;
         
     /* Is this sufficient checking ? */
-    if(CMapScreenKey == NULL)
+    if(!CMapScreenKeyRegistered)
 	return BadImplementation;
 
     pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
@@ -1012,7 +1023,7 @@ xf86ChangeGammaRamp(
 	}
     }
 
-    if(CMapScreenKey == NULL)
+    if(!CMapScreenKeyRegistered)
         return BadImplementation;
 
     pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
@@ -1080,7 +1091,7 @@ xf86GetGammaRampSize(ScreenPtr pScreen)
 	    return crtc->gammaSize;
     }
 
-    if(CMapScreenKey == NULL) return 0;
+    if(!CMapScreenKeyRegistered) return 0;
 
     pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
 						  CMapScreenKey);
@@ -1120,7 +1131,7 @@ xf86GetGammaRamp(
 	}
     }
 
-    if(CMapScreenKey == NULL) 
+    if(!CMapScreenKeyRegistered)
 	return BadImplementation;
 
     pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
diff --git a/hw/xfree86/common/xf86cmap.h b/hw/xfree86/common/xf86cmap.h
index f15844e..649f078 100644
--- a/hw/xfree86/common/xf86cmap.h
+++ b/hw/xfree86/common/xf86cmap.h
@@ -45,6 +45,10 @@ extern _X_EXPORT Bool xf86HandleColormaps(
     unsigned int flags
 );
 
+extern _X_EXPORT Bool xf86ColormapAllocatePrivates(
+    ScrnInfoPtr pScrn
+);
+
 extern _X_EXPORT int
 xf86ChangeGamma(
    ScreenPtr pScreen,
diff --git a/hw/xfree86/common/xf86fbman.c b/hw/xfree86/common/xf86fbman.c
index d883ab3..e60e5c4 100644
--- a/hw/xfree86/common/xf86fbman.c
+++ b/hw/xfree86/common/xf86fbman.c
@@ -42,7 +42,7 @@
 #define DEBUG
 */
 
-static int xf86FBManagerKeyIndex;
+static DevPrivateKeyRec xf86FBManagerKeyRec;
 static DevPrivateKey xf86FBManagerKey;
 
 Bool xf86RegisterOffscreenManager(
@@ -50,7 +50,11 @@ Bool xf86RegisterOffscreenManager(
     FBManagerFuncsPtr funcs
 ){
 
-   xf86FBManagerKey = &xf86FBManagerKeyIndex;
+   xf86FBManagerKey = &xf86FBManagerKeyRec;
+
+   if (!dixRegisterPrivateKey(&xf86FBManagerKeyRec, PRIVATE_SCREEN, 0))
+       return FALSE;
+
    dixSetPrivate(&pScreen->devPrivates, xf86FBManagerKey, funcs);
 
    return TRUE;
@@ -60,8 +64,9 @@ Bool xf86RegisterOffscreenManager(
 Bool
 xf86FBManagerRunning(ScreenPtr pScreen)
 {
-    if(xf86FBManagerKey == NULL) 
+    if (xf86FBManagerKey == NULL)
 	return FALSE;
+
     if(!dixLookupPrivate(&pScreen->devPrivates, xf86FBManagerKey))
 	return FALSE;
 
@@ -270,8 +275,8 @@ xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
 
 \************************************************************/ 
 
-static int xf86FBScreenKeyIndex;
-static DevPrivateKey xf86FBScreenKey = &xf86FBScreenKeyIndex;
+static DevPrivateKeyRec xf86FBScreenKeyRec;
+#define xf86FBScreenKey (&xf86FBScreenKeyRec)
 
 typedef struct _FBLink {
   FBArea area;
@@ -1321,6 +1326,9 @@ xf86InitFBManagerRegion(
    if(RegionNil(FullRegion))
 	return FALSE;
 
+   if (!dixRegisterPrivateKey(&xf86FBScreenKeyRec, PRIVATE_SCREEN, 0))
+       return FALSE;
+
    if(!xf86RegisterOffscreenManager(pScreen, &xf86FBManFuncs))
 	return FALSE;
 
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 36e325f..a979dd3 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -110,10 +110,11 @@ static void xf86XVAdjustFrame(int index, int x, int y, int flags);
 static Bool xf86XVInitAdaptors(ScreenPtr, XF86VideoAdaptorPtr*, int);
 
 
-static int XF86XVWindowKeyIndex;
-static DevPrivateKey XF86XVWindowKey = &XF86XVWindowKeyIndex;
-static int XF86XvScreenKeyIndex;
-DevPrivateKey XF86XvScreenKey = &XF86XvScreenKeyIndex;
+static DevPrivateKeyRec XF86XVWindowKeyRec;
+#define XF86XVWindowKey (&XF86XVWindowKeyRec)
+
+DevPrivateKey XF86XvScreenKey;
+
 static unsigned long PortResource = 0;
 
 DevPrivateKey (*XvGetScreenKeyProc)(void) = NULL;
@@ -186,8 +187,8 @@ typedef struct {
    int num;
 } OffscreenImageRec;
 
-static int OffscreenPrivateKeyIndex;
-static DevPrivateKey OffscreenPrivateKey = &OffscreenPrivateKeyIndex;
+static DevPrivateKeyRec OffscreenPrivateKeyRec;
+#define OffscreenPrivateKey (&OffscreenPrivateKeyRec)
 #define GetOffscreenImage(pScreen) ((OffscreenImageRec *) dixLookupPrivate(&(pScreen)->devPrivates, OffscreenPrivateKey))
 
 Bool
@@ -198,9 +199,9 @@ xf86XVRegisterOffscreenImages(
 ){
     OffscreenImageRec *OffscreenImage;
     /* This function may be called before xf86XVScreenInit, so there's
-     * no better place than this to call dixRequestPrivate to ensure we
+     * no better place than this to call dixRegisterPrivateKey to ensure we
      * have space reserved. After the first call it is a no-op. */
-    if(!dixRequestPrivate(OffscreenPrivateKey, sizeof(OffscreenImageRec)) ||
+    if(!dixRegisterPrivateKey(OffscreenPrivateKey, PRIVATE_SCREEN, sizeof(OffscreenImageRec)) ||
        !(OffscreenImage = GetOffscreenImage(pScreen)))
         /* Every X.org driver assumes this function always succeeds, so
          * just die on allocation failure. */
@@ -251,7 +252,11 @@ xf86XVScreenInit(
 
   if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
 
+  if (!dixRegisterPrivateKey(&XF86XVWindowKeyRec, PRIVATE_WINDOW, 0))
+      return FALSE;
+
   XF86XvScreenKey = (*XvGetScreenKeyProc)();
+
   PortResource = (*XvGetRTPortProc)();
 
   pxvs = GET_XV_SCREEN(pScreen);
diff --git a/hw/xfree86/common/xf86xvmc.c b/hw/xfree86/common/xf86xvmc.c
index 99d6695..e6464a5 100644
--- a/hw/xfree86/common/xf86xvmc.c
+++ b/hw/xfree86/common/xf86xvmc.c
@@ -55,8 +55,8 @@ typedef struct {
   XvMCAdaptorPtr dixinfo;
 } xf86XvMCScreenRec, *xf86XvMCScreenPtr;
 
-static int XF86XvMCScreenKeyIndex;
-static DevPrivateKey XF86XvMCScreenKey = &XF86XvMCScreenKeyIndex;
+static DevPrivateKeyRec XF86XvMCScreenKeyRec;
+#define XF86XvMCScreenKey (&XF86XvMCScreenKeyRec)
 
 #define XF86XVMC_GET_PRIVATE(pScreen) (xf86XvMCScreenPtr) \
     dixLookupPrivate(&(pScreen)->devPrivates, XF86XvMCScreenKey)
@@ -172,6 +172,9 @@ Bool xf86XvMCScreenInit(
    if(!(pAdapt = malloc(sizeof(XvMCAdaptorRec) * num_adaptors)))
 	return FALSE;
 
+   if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0))
+       return FALSE;
+
    if(!(pScreenPriv = malloc(sizeof(xf86XvMCScreenRec)))) {
 	free(pAdapt);
 	return FALSE;
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 906f4d5..203fccf 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -61,10 +61,11 @@ unsigned char DGAReqCode = 0;
 int DGAErrorBase;
 int DGAEventBase;
 
-static int DGAScreenPrivateKeyIndex;
-static DevPrivateKey DGAScreenPrivateKey = &DGAScreenPrivateKeyIndex;
-static int DGAClientPrivateKeyIndex;
-static DevPrivateKey DGAClientPrivateKey = &DGAClientPrivateKeyIndex;
+static DevPrivateKeyRec DGAScreenPrivateKeyRec;
+#define DGAScreenPrivateKey (&DGAScreenPrivateKeyRec)
+#define DGAScreenPrivateKeyRegistered (DGAScreenPrivateKeyRec.initialized)
+static DevPrivateKeyRec DGAClientPrivateKeyRec;
+#define DGAClientPrivateKey (&DGAClientPrivateKeyRec)
 static int DGACallbackRefCount = 0;
 
 /* This holds the client's version information */
@@ -89,6 +90,12 @@ XFree86DGAExtensionInit(INITARGS)
 {
     ExtensionEntry* extEntry;
 
+    if (!dixRegisterPrivateKey(&DGAClientPrivateKeyRec, PRIVATE_CLIENT, 0))
+	return;
+
+    if (!dixRegisterPrivateKey(&DGAScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     if ((extEntry = AddExtension(XF86DGANAME,
 				XF86DGANumberEvents,
 				XF86DGANumberErrors,
@@ -717,13 +724,13 @@ ProcXF86DGADirectVideo(ClientPtr client)
 
     if (stuff->screen > screenInfo.numScreens)
 	return BadValue;
-    owner = DGA_GETCLIENT(stuff->screen);
-
     REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
 
     if (!DGAAvailable(stuff->screen))
 	return DGAErrorBase + XF86DGANoDirectVideoMode;
 
+    owner = DGA_GETCLIENT(stuff->screen);
+
     if (owner && owner != client)
         return DGAErrorBase + XF86DGANoDirectVideoMode;
 
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 4487628..b02fdaf 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -51,8 +51,8 @@ from Kaleb S. KEITHLEY
 #define DEFAULT_XF86VIDMODE_VERBOSITY	3
 
 static int VidModeErrorBase;
-static int VidModeClientPrivateKeyIndex;
-static DevPrivateKey VidModeClientPrivateKey = &VidModeClientPrivateKeyIndex;
+static DevPrivateKeyRec VidModeClientPrivateKeyRec;
+#define VidModeClientPrivateKey (&VidModeClientPrivateKeyRec)
 
 /* This holds the client's version information */
 typedef struct {
@@ -141,8 +141,8 @@ typedef struct _XF86VidModeScreenPrivate {
     Bool		hasWindow;
 } XF86VidModeScreenPrivateRec, *XF86VidModeScreenPrivatePtr;
 
-static int ScreenPrivateKeyIndex;
-static DevPrivateKey ScreenPrivateKey = &ScreenPrivateKeyIndex;
+static DevPrivateKeyRec ScreenPrivateKeyRec;
+#define ScreenPrivateKey (&ScreenPrivateKeyRec)
 
 #define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \
     dixLookupPrivate(&(s)->devPrivates, ScreenPrivateKey))
@@ -169,6 +169,13 @@ XFree86VidModeExtensionInit(void)
 
     DEBUG_P("XFree86VidModeExtensionInit");
 
+    if (!dixRegisterPrivateKey(&VidModeClientPrivateKeyRec, PRIVATE_CLIENT, 0))
+	return;
+#ifdef XF86VIDMODE_EVENTS
+    if (!dixRegisterPrivateKey(&ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+#endif
+
 #ifdef XF86VIDMODE_EVENTS
     EventType = CreateNewResourceType(XF86VidModeFreeEvents, "VidModeEvent");
 #endif
@@ -177,9 +184,6 @@ XFree86VidModeExtensionInit(void)
         pScreen = screenInfo.screens[i];
 	if (VidModeExtensionInit(pScreen))
 	    enabled = TRUE;
-#ifdef XF86VIDMODE_EVENTS
-	SetScreenPrivate (pScreen, NULL);
-#endif
     }
     /* This means that the DDX doesn't want the vidmode extension enabled */
     if (!enabled)
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index 63c77de..db4cd7b 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -74,10 +74,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu)
 
 static int DRIEntPrivIndex = -1;
-static int DRIScreenPrivKeyIndex;
-static DevPrivateKey DRIScreenPrivKey = &DRIScreenPrivKeyIndex;
-static int DRIWindowPrivKeyIndex;
-static DevPrivateKey DRIWindowPrivKey = &DRIWindowPrivKeyIndex;
+static DevPrivateKeyRec DRIScreenPrivKeyRec;
+#define DRIScreenPrivKey (&DRIScreenPrivKeyRec)
+static DevPrivateKeyRec DRIWindowPrivKeyRec;
+#define DRIWindowPrivKey (&DRIWindowPrivKeyRec)
 static unsigned long DRIGeneration = 0;
 static unsigned int DRIDrawableValidationStamp = 0;
 
@@ -357,6 +357,11 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD)
     if (DRIGeneration != serverGeneration)
 	DRIGeneration = serverGeneration;
 
+    if (!dixRegisterPrivateKey(&DRIScreenPrivKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+    if (!dixRegisterPrivateKey(&DRIWindowPrivKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
     pDRIPriv = (DRIScreenPrivPtr) calloc(1, sizeof(DRIScreenPrivRec));
     if (!pDRIPriv) {
 	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
@@ -785,7 +790,7 @@ drmServerInfo DRIDRMServerInfo =  {
 Bool
 DRIExtensionInit(void)
 {
-    if (!DRIScreenPrivKey || DRIGeneration != serverGeneration) {
+    if (DRIGeneration != serverGeneration) {
 	return FALSE;
     }
 
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 3c8d3a8..baa6706 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -51,12 +51,15 @@
 CARD8 dri2_major; /* version of DRI2 supported by DDX */
 CARD8 dri2_minor;
 
-static int           dri2ScreenPrivateKeyIndex;
-static DevPrivateKey dri2ScreenPrivateKey = &dri2ScreenPrivateKeyIndex;
-static int dri2WindowPrivateKeyIndex;
-static DevPrivateKey dri2WindowPrivateKey = &dri2WindowPrivateKeyIndex;
-static int dri2PixmapPrivateKeyIndex;
-static DevPrivateKey dri2PixmapPrivateKey = &dri2PixmapPrivateKeyIndex;
+static DevPrivateKeyRec dri2ScreenPrivateKeyRec;
+#define dri2ScreenPrivateKey (&dri2ScreenPrivateKeyRec)
+
+static DevPrivateKeyRec dri2WindowPrivateKeyRec;
+#define dri2WindowPrivateKey (&dri2WindowPrivateKeyRec)
+
+static DevPrivateKeyRec dri2PixmapPrivateKeyRec;
+#define dri2PixmapPrivateKey (&dri2PixmapPrivateKeyRec)
+
 static RESTYPE       dri2DrawableRes;
 
 typedef struct _DRI2Screen *DRI2ScreenPtr;
@@ -1025,6 +1028,15 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
         return FALSE;
     }
 
+    if (!dixRegisterPrivateKey(&dri2ScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&dri2WindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&dri2PixmapPrivateKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE;
+
     ds = calloc(1, sizeof *ds);
     if (!ds)
 	return FALSE;
diff --git a/hw/xfree86/exa/examodule.c b/hw/xfree86/exa/examodule.c
index 315ba4a..83f72b5 100644
--- a/hw/xfree86/exa/examodule.c
+++ b/hw/xfree86/exa/examodule.c
@@ -42,8 +42,8 @@ typedef struct _ExaXorgScreenPrivRec {
     OptionInfoPtr		 options;
 } ExaXorgScreenPrivRec, *ExaXorgScreenPrivPtr;
 
-static int exaXorgScreenPrivateKeyIndex;
-static DevPrivateKey exaXorgScreenPrivateKey = &exaXorgScreenPrivateKeyIndex;
+static DevPrivateKeyRec exaXorgScreenPrivateKeyRec;
+#define exaXorgScreenPrivateKey (&exaXorgScreenPrivateKeyRec)
 
 typedef enum {
     EXAOPT_MIGRATION_HEURISTIC,
@@ -114,6 +114,9 @@ exaDDXDriverInit(ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     ExaXorgScreenPrivPtr pScreenPriv;
 
+    if (!dixRegisterPrivateKey(&exaXorgScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     pScreenPriv = calloc(1, sizeof(ExaXorgScreenPrivRec));
     if (pScreenPriv == NULL)
 	return;
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 8d598d6..bb4d75e 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -71,7 +71,7 @@ static Bool xf86RandR12CreateScreenResources12 (ScreenPtr pScreen);
 static int xf86RandR12Generation;
 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(7,0,0,0,0)
 
-static int xf86RandR12KeyIndex;
+static DevPrivateKeyRec xf86RandR12KeyRec;
 static DevPrivateKey xf86RandR12Key;
 #define XF86RANDRINFO(p) ((XF86RandRInfoPtr) \
     dixLookupPrivate(&(p)->devPrivates, xf86RandR12Key))
@@ -883,7 +883,9 @@ xf86RandR12Init (ScreenPtr pScreen)
 	xf86RandR12Generation = serverGeneration;
 
 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(7,0,0,0,0)
-    xf86RandR12Key = &xf86RandR12KeyIndex;
+    xf86RandR12Key = &xf86RandR12KeyRec;
+    if (!dixRegisterPrivateKey(&xf86RandR12KeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
 #else
     xf86RandR12Index = AllocateScreenPrivateIndex();
 #endif
diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c
index 2bbcb9c..e16b510 100644
--- a/hw/xfree86/ramdac/xf86Cursor.c
+++ b/hw/xfree86/ramdac/xf86Cursor.c
@@ -18,8 +18,7 @@
 #include "inputstr.h"
 extern InputInfo inputInfo;
 
-static int xf86CursorScreenKeyIndex;
-DevPrivateKey xf86CursorScreenKey = &xf86CursorScreenKeyIndex;
+DevPrivateKeyRec xf86CursorScreenKeyRec;
 
 /* sprite functions */
 
@@ -65,6 +64,9 @@ xf86InitCursor(
     if (!xf86InitHardwareCursor(pScreen, infoPtr))
 	return FALSE;
 
+    if (!dixRegisterPrivateKey(&xf86CursorScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     ScreenPriv = calloc(1, sizeof(xf86CursorScreenRec));
     if (!ScreenPriv)
 	return FALSE;
diff --git a/hw/xfree86/ramdac/xf86CursorPriv.h b/hw/xfree86/ramdac/xf86CursorPriv.h
index 32be9c2..d22d88d 100644
--- a/hw/xfree86/ramdac/xf86CursorPriv.h
+++ b/hw/xfree86/ramdac/xf86CursorPriv.h
@@ -45,6 +45,7 @@ Bool xf86InitHardwareCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr);
 
 CARD32 xf86ReverseBitOrder(CARD32 data);
 
-extern _X_EXPORT DevPrivateKey xf86CursorScreenKey;
+extern _X_EXPORT DevPrivateKeyRec xf86CursorScreenKeyRec;
+#define xf86CursorScreenKey (&xf86CursorScreenKeyRec)
 
 #endif /* _XF86CURSORPRIV_H */
diff --git a/hw/xfree86/shadowfb/shadow.c b/hw/xfree86/shadowfb/shadow.c
index a0e4b9e..2066f76 100644
--- a/hw/xfree86/shadowfb/shadow.c
+++ b/hw/xfree86/shadowfb/shadow.c
@@ -84,11 +84,11 @@ typedef struct {
    GCFuncs *funcs;
 } ShadowGCRec, *ShadowGCPtr;
 
+static DevPrivateKeyRec ShadowScreenKeyRec;
+#define ShadowScreenKey (&ShadowScreenKeyRec)
 
-static int ShadowScreenKeyIndex;
-static DevPrivateKey ShadowScreenKey = &ShadowScreenKeyIndex;
-static int ShadowGCKeyIndex;
-static DevPrivateKey ShadowGCKey = &ShadowGCKeyIndex;
+static DevPrivateKeyRec ShadowGCKeyRec;
+#define ShadowGCKey (&ShadowGCKeyRec)
 
 #define GET_SCREEN_PRIVATE(pScreen) \
     (ShadowScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, ShadowScreenKey)
@@ -162,7 +162,10 @@ ShadowFBInit2 (
 
     if(!preRefreshArea && !postRefreshArea) return FALSE;
     
-    if(!dixRequestPrivate(ShadowGCKey, sizeof(ShadowGCRec)))
+    if (!dixRegisterPrivateKey(&ShadowScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if(!dixRegisterPrivateKey(&ShadowGCKeyRec, PRIVATE_GC, sizeof(ShadowGCRec)))
 	return FALSE;
 
     if(!(pPriv = (ShadowScreenPtr)malloc(sizeof(ShadowScreenRec))))
diff --git a/hw/xfree86/xaa/xaaInit.c b/hw/xfree86/xaa/xaaInit.c
index 0ccdae5..d0a66b8 100644
--- a/hw/xfree86/xaa/xaaInit.c
+++ b/hw/xfree86/xaa/xaaInit.c
@@ -42,12 +42,12 @@ static int  XAASetDGAMode(int index, int num, DGADevicePtr devRet);
 static void XAAEnableDisableFBAccess (int index, Bool enable);
 static Bool XAAChangeWindowAttributes (WindowPtr pWin, unsigned long mask);
 
-static int XAAScreenKeyIndex;
-static DevPrivateKey XAAScreenKey = &XAAScreenKeyIndex;
-static int XAAGCKeyIndex;
-static DevPrivateKey XAAGCKey = &XAAGCKeyIndex;
-static int XAAPixmapKeyIndex;
-static DevPrivateKey XAAPixmapKey = &XAAPixmapKeyIndex;
+static DevPrivateKeyRec XAAScreenKeyRec;
+#define XAAScreenKey (&XAAScreenKeyRec)
+static DevPrivateKeyRec XAAGCKeyRec;
+#define XAAGCKey (&XAAGCKeyRec)
+static DevPrivateKeyRec XAAPixmapKeyRec;
+#define XAAPixmapKey (&XAAPixmapKeyRec)
 
 DevPrivateKey XAAGetScreenKey(void) {
     return XAAScreenKey;
@@ -106,10 +106,13 @@ XAAInit(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
     if (!infoRec)
 	return TRUE;
     
-    if (!dixRequestPrivate(XAAGCKey, sizeof(XAAGCRec)))
+    if (!dixRegisterPrivateKey(&XAAGCKeyRec, PRIVATE_GC, sizeof(XAAGCRec)))
 	return FALSE;
 
-    if (!dixRequestPrivate(XAAPixmapKey, sizeof(XAAPixmapRec)))
+    if (!dixRegisterPrivateKey(&XAAPixmapKeyRec, PRIVATE_PIXMAP, sizeof(XAAPixmapRec)))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&XAAScreenKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
     if (!(pScreenPriv = malloc(sizeof(XAAScreenRec))))
diff --git a/hw/xfree86/xaa/xaaOverlayDF.c b/hw/xfree86/xaa/xaaOverlayDF.c
index 61adec6..ca22368 100644
--- a/hw/xfree86/xaa/xaaOverlayDF.c
+++ b/hw/xfree86/xaa/xaaOverlayDF.c
@@ -151,8 +151,8 @@ typedef struct {
    int (*TiledFillChooser)(GCPtr);
 } XAAOverlayRec, *XAAOverlayPtr;
 
-static int XAAOverlayKeyIndex;
-static DevPrivateKey XAAOverlayKey = &XAAOverlayKeyIndex;
+static DevPrivateKeyRec XAAOverlayKeyRec;
+#define XAAOverlayKey (&XAAOverlayKeyRec)
 
 #define GET_OVERLAY_PRIV(pScreen) \
     (XAAOverlayPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAOverlayKey)
@@ -173,6 +173,9 @@ XAAInitDualFramebufferOverlay(
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
     XAAOverlayPtr pOverPriv;
 
+    if (!dixRegisterPrivateKey(&XAAOverlayKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     if(!(pOverPriv = malloc(sizeof(XAAOverlayRec))))
 	return FALSE;
 
diff --git a/hw/xfree86/xaa/xaaStateChange.c b/hw/xfree86/xaa/xaaStateChange.c
index 0e86e67..189441d 100644
--- a/hw/xfree86/xaa/xaaStateChange.c
+++ b/hw/xfree86/xaa/xaaStateChange.c
@@ -272,8 +272,8 @@ typedef struct _XAAStateWrapRec {
                                       int width, int height, int flags);
 } XAAStateWrapRec, *XAAStateWrapPtr;
 
-static int XAAStateKeyIndex;
-static DevPrivateKey XAAStateKey = &XAAStateKeyIndex;
+static DevPrivateKeyRec XAAStateKeyRec;
+#define XAAStateKey (&XAAStateKeyRec)
 
 /* Wrap functions start here */
 #define GET_STATEPRIV_GC(pGC)   XAAStateWrapPtr pStatePriv =\
@@ -1500,6 +1500,7 @@ XAAInitStateWrap(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
    XAAStateWrapPtr pStatePriv;
    int i = 0;
    
+   if (!dixRegisterPrivateKey(&XAAStateKeyRec, PRIVATE_SCREEN, 0)) return FALSE;
    if(!(pStatePriv = malloc(sizeof(XAAStateWrapRec)))) return FALSE;
    dixSetPrivate(&pScreen->devPrivates, XAAStateKey, pStatePriv);
    pStatePriv->RestoreAccelState = infoRec->RestoreAccelState;
diff --git a/hw/xfree86/xaa/xaaWrapper.c b/hw/xfree86/xaa/xaaWrapper.c
index 2491492..e91bac0 100644
--- a/hw/xfree86/xaa/xaaWrapper.c
+++ b/hw/xfree86/xaa/xaaWrapper.c
@@ -125,10 +125,10 @@ typedef struct _xaaWrapperGCPriv {
 #define xaaWrapperGCPriv(pGC)   xaaWrapperGCPrivPtr  pGCPriv = xaaWrapperGetGCPriv(pGC)
 
 
-static int xaaWrapperScrPrivateKeyIndex;
-static DevPrivateKey xaaWrapperScrPrivateKey = &xaaWrapperScrPrivateKeyIndex;
-static int xaaWrapperGCPrivateKeyIndex;
-static DevPrivateKey xaaWrapperGCPrivateKey = &xaaWrapperGCPrivateKeyIndex;
+static DevPrivateKeyRec xaaWrapperScrPrivateKeyRec;
+#define xaaWrapperScrPrivateKey (&xaaWrapperScrPrivateKeyRec)
+static DevPrivateKeyRec xaaWrapperGCPrivateKeyRec;
+#define xaaWrapperGCPrivateKey (&xaaWrapperGCPrivateKeyRec)
 
 static Bool
 xaaWrapperCreateScreenResources(ScreenPtr pScreen)
@@ -268,7 +268,10 @@ xaaSetupWrapper(ScreenPtr pScreen, XAAInfoRecPtr infoPtr, int depth, SyncFunc *f
     xaaWrapperScrPrivPtr pScrPriv;
     PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
 
-    if (!dixRequestPrivate(xaaWrapperGCPrivateKey, sizeof(xaaWrapperGCPrivRec)))
+    if (!dixRegisterPrivateKey(&xaaWrapperGCPrivateKeyRec, PRIVATE_GC, sizeof(xaaWrapperGCPrivRec)))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&xaaWrapperScrPrivateKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
     pScrPriv = (xaaWrapperScrPrivPtr) malloc(sizeof (xaaWrapperScrPrivRec));
diff --git a/hw/xnest/Color.c b/hw/xnest/Color.c
index b3f0fc4..6399e34 100644
--- a/hw/xnest/Color.c
+++ b/hw/xnest/Color.c
@@ -34,8 +34,8 @@ is" without express or implied warranty.
 #include "XNWindow.h"
 #include "Args.h"
 
-static int cmapScrPrivateKeyIndex;
-static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex;
+static DevPrivateKeyRec cmapScrPrivateKeyRec;
+#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
 
 #define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
 #define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
diff --git a/hw/xnest/GC.c b/hw/xnest/GC.c
index 2cd555c..2761583 100644
--- a/hw/xnest/GC.c
+++ b/hw/xnest/GC.c
@@ -35,8 +35,7 @@ is" without express or implied warranty.
 #include "XNFont.h"
 #include "Color.h"
 
-static int xnestGCPrivateKeyIndex;
-DevPrivateKey xnestGCPrivateKey = &xnestGCPrivateKeyIndex;
+DevPrivateKeyRec xnestGCPrivateKeyRec;
 
 static GCFuncs xnestFuncs = {
   xnestValidateGC,
diff --git a/hw/xnest/Pixmap.c b/hw/xnest/Pixmap.c
index bf06480..a0968b9 100644
--- a/hw/xnest/Pixmap.c
+++ b/hw/xnest/Pixmap.c
@@ -33,8 +33,7 @@ is" without express or implied warranty.
 #include "Screen.h"
 #include "XNPixmap.h"
 
-static int xnestPixmapPrivateKeyIndex;
-DevPrivateKey xnestPixmapPrivateKey = &xnestPixmapPrivateKeyIndex;
+DevPrivateKeyRec xnestPixmapPrivateKeyRec;
 
 PixmapPtr
 xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
@@ -42,7 +41,7 @@ xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
 {
   PixmapPtr pPixmap;
 
-  pPixmap = AllocatePixmap(pScreen, sizeof(xnestPrivPixmap));
+  pPixmap = AllocatePixmap(pScreen, 0);
   if (!pPixmap)
     return NullPixmap;
   pPixmap->drawable.type = DRAWABLE_PIXMAP;
@@ -59,8 +58,6 @@ xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
   pPixmap->refcnt = 1;
   pPixmap->devKind = PixmapBytePad(width, depth);
   pPixmap->usage_hint = usage_hint;
-  dixSetPrivate(&pPixmap->devPrivates, xnestPixmapPrivateKey,
-		(char *)pPixmap + pScreen->totalPixmapSize);
   if (width && height)
       xnestPixmapPriv(pPixmap)->pixmap = 
 	  XCreatePixmap(xnestDisplay, 
@@ -78,8 +75,7 @@ xnestDestroyPixmap(PixmapPtr pPixmap)
   if(--pPixmap->refcnt)
     return TRUE;
   XFreePixmap(xnestDisplay, xnestPixmap(pPixmap));
-  dixFreePrivates(pPixmap->devPrivates);
-  free(pPixmap);
+  FreePixmap(pPixmap);
   return TRUE;
 }
 
diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c
index 0a05ac8..957fe4c 100644
--- a/hw/xnest/Screen.c
+++ b/hw/xnest/Screen.c
@@ -45,8 +45,7 @@ is" without express or implied warranty.
 
 Window xnestDefaultWindows[MAXSCREENS];
 Window xnestScreenSaverWindows[MAXSCREENS];
-static int xnestCursorScreenKeyIndex;
-DevPrivateKey xnestCursorScreenKey = &xnestCursorScreenKeyIndex;
+DevPrivateKeyRec xnestCursorScreenKeyRec;
 
 ScreenPtr
 xnestScreen(Window window)
@@ -146,10 +145,14 @@ xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
   int rootDepth;
   miPointerScreenPtr PointPriv;
 
-  if (!dixRequestPrivate(xnestWindowPrivateKey, sizeof(xnestPrivWin)))
-      return False;
-  if (!dixRequestPrivate(xnestGCPrivateKey, sizeof(xnestPrivGC)))
-    return False;
+  if (!dixRegisterPrivateKey(&xnestWindowPrivateKeyRec, PRIVATE_WINDOW, sizeof(xnestPrivWin)))
+      return FALSE;
+  if (!dixRegisterPrivateKey(&xnestGCPrivateKeyRec, PRIVATE_GC, sizeof(xnestPrivGC)))
+    return FALSE;
+  if (!dixRegisterPrivateKey(&xnestPixmapPrivateKeyRec, PRIVATE_PIXMAP, sizeof (xnestPrivPixmap)))
+      return FALSE;
+  if (!dixRegisterPrivateKey(&xnestCursorScreenKeyRec, PRIVATE_SCREEN, 0))
+      return FALSE;
 
   visuals = (VisualPtr)malloc(xnestNumVisuals * sizeof(VisualRec));
   numVisuals = 0;
diff --git a/hw/xnest/Window.c b/hw/xnest/Window.c
index fab2f39..659b135 100644
--- a/hw/xnest/Window.c
+++ b/hw/xnest/Window.c
@@ -39,8 +39,7 @@ is" without express or implied warranty.
 #include "Events.h"
 #include "Args.h"
 
-static int xnestWindowPrivateKeyIndex;
-DevPrivateKey xnestWindowPrivateKey = &xnestWindowPrivateKeyIndex;
+DevPrivateKeyRec xnestWindowPrivateKeyRec;
 
 static int
 xnestFindWindowMatch(WindowPtr pWin, pointer ptr)
diff --git a/hw/xnest/XNCursor.h b/hw/xnest/XNCursor.h
index ab2c3b1..d3b18bd 100644
--- a/hw/xnest/XNCursor.h
+++ b/hw/xnest/XNCursor.h
@@ -21,7 +21,8 @@ typedef struct {
     miPointerSpriteFuncPtr spriteFuncs;
 } xnestCursorFuncRec, *xnestCursorFuncPtr;
 
-extern DevPrivateKey xnestCursorScreenKey;
+extern DevPrivateKeyRec xnestCursorScreenKeyRec;
+#define xnestCursorScreenKey (&xnestCursorScreenKeyRec)
 extern xnestCursorFuncRec xnestCursorFuncs;
 
 typedef struct {
diff --git a/hw/xnest/XNGC.h b/hw/xnest/XNGC.h
index 19535fe..9f10456 100644
--- a/hw/xnest/XNGC.h
+++ b/hw/xnest/XNGC.h
@@ -22,7 +22,8 @@ typedef struct {
   int nClipRects;
 } xnestPrivGC;
 
-extern DevPrivateKey xnestGCPrivateKey;
+extern DevPrivateKeyRec xnestGCPrivateKeyRec;
+#define xnestGCPrivateKey (&xnestGCPrivateKeyRec)
 
 #define xnestGCPriv(pGC) ((xnestPrivGC *) \
     dixLookupPrivate(&(pGC)->devPrivates, xnestGCPrivateKey))
diff --git a/hw/xnest/XNPixmap.h b/hw/xnest/XNPixmap.h
index 6148275..aa671ed 100644
--- a/hw/xnest/XNPixmap.h
+++ b/hw/xnest/XNPixmap.h
@@ -15,7 +15,8 @@ is" without express or implied warranty.
 #ifndef XNESTPIXMAP_H
 #define XNESTPIXMAP_H
 
-extern DevPrivateKey xnestPixmapPrivateKey;
+extern DevPrivateKeyRec xnestPixmapPrivateKeyRec;
+#define xnestPixmapPrivateKey (&xnestPixmapPrivateKeyRec)
 
 typedef struct {
   Pixmap pixmap;
diff --git a/hw/xnest/XNWindow.h b/hw/xnest/XNWindow.h
index 92a1902..f4d8fc7 100644
--- a/hw/xnest/XNWindow.h
+++ b/hw/xnest/XNWindow.h
@@ -33,7 +33,8 @@ typedef struct {
   Window window;
 } xnestWindowMatch;
 
-extern DevPrivateKey xnestWindowPrivateKey;
+extern DevPrivateKeyRec xnestWindowPrivateKeyRec;
+#define xnestWindowPrivateKey (&xnestWindowPrivateKeyRec)
 
 #define xnestWindowPriv(pWin) ((xnestPrivWin *) \
     dixLookupPrivate(&(pWin)->devPrivates, xnestWindowPrivateKey))
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 1d99d36..a99c0f1 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -84,8 +84,7 @@ FILE *debug_log_fp = NULL;
  * X server shared global variables
  */
 int                     darwinScreensFound = 0;
-static int              darwinScreenKeyIndex;
-DevPrivateKey           darwinScreenKey = &darwinScreenKeyIndex;
+DevPrivateKeyRec        darwinScreenKeyRec;
 io_connect_t            darwinParamConnect = 0;
 int                     darwinEventReadFD = -1;
 int                     darwinEventWriteFD = -1;
@@ -185,6 +184,9 @@ static Bool DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv
     Bool        ret;
     DarwinFramebufferPtr dfb;
 
+    if (!dixRegisterPrivateKey(&darwinScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     // reset index of found screens for each server generation
     if (index == 0) {
         foundIndex = 0;
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index 8fa48bf..350eade 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -50,7 +50,8 @@ void xf86SetRootClip (ScreenPtr pScreen, int enable);
 /*
  * Global variables from darwin.c
  */
-extern DevPrivateKey    darwinScreenKey; // index into pScreen.devPrivates
+extern DevPrivateKeyRec darwinScreenKeyRec;
+#define darwinScreenKey (&darwinScreenKeyRec)
 extern int              darwinScreensFound;
 extern io_connect_t     darwinParamConnect;
 extern int              darwinEventReadFD;
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index bb37e4a..2828c57 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -73,8 +73,7 @@ int                     quartzUseAGL = 1;
 int                     quartzEnableKeyEquivalents = 1;
 int                     quartzServerVisible = FALSE;
 int                     quartzServerQuitting = FALSE;
-static int              quartzScreenKeyIndex;
-DevPrivateKey           quartzScreenKey = &quartzScreenKeyIndex;
+DevPrivateKeyRec        quartzScreenKeyRec;
 int                     aquaMenuBarHeight = 0;
 QuartzModeProcsPtr      quartzProcs = NULL;
 const char             *quartzOpenGLBundle = NULL;
@@ -167,6 +166,9 @@ void QuartzInitOutput(
         FatalError("Could not register block and wakeup handlers.");
     }
 
+    if (!dixRegisterPrivateKey(&quartzScreenKeyRec, PRIVATE_SCREEN, 0))
+	FatalError("Failed to alloc quartz screen private.\n");
+
 #if defined(RANDR) && !defined(FAKE_RANDR)
     if(!QuartzRandRInit(pScreen))
         FatalError("Failed to init RandR extension.\n");
diff --git a/hw/xquartz/quartzCommon.h b/hw/xquartz/quartzCommon.h
index 8ab70f2..c038ed0 100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@ -65,7 +65,8 @@ extern int              quartzOptionSendsAlt;
 // Other shared data
 extern int              quartzServerVisible;
 extern int              quartzServerQuitting;
-extern DevPrivateKey    quartzScreenKey;
+extern DevPrivateKeyRec quartzScreenKeyRec;
+#define quartzScreenKey (&quartzScreenKeyRec)
 extern int              aquaMenuBarHeight;
 
 // Name of GLX bundle for native OpenGL
diff --git a/hw/xquartz/xpr/dri.c b/hw/xquartz/xpr/dri.c
index d9b2e03..72a7ecf 100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@ -74,14 +74,14 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <AvailabilityMacros.h>
 
-static int DRIScreenPrivKeyIndex;
-static DevPrivateKey DRIScreenPrivKey = &DRIScreenPrivKeyIndex;
-static int DRIWindowPrivKeyIndex;
-static DevPrivateKey DRIWindowPrivKey = &DRIWindowPrivKeyIndex;
-static int DRIPixmapPrivKeyIndex;
-static DevPrivateKey DRIPixmapPrivKey = &DRIPixmapPrivKeyIndex;
-static int DRIPixmapBufferPrivKeyIndex;
-static DevPrivateKey DRIPixmapBufferPrivKey = &DRIPixmapBufferPrivKeyIndex;
+static DevPrivateKeyRec DRIScreenPrivKeyRec;
+#define DRIScreenPrivKey (&DRIScreenPrivKeyRec)
+static DevPrivateKeyRec DRIWindowPrivKeyRec;
+#define DRIWindowPrivKey (&DRIWindowPrivKeyRec)
+static DevPrivateKeyRec DRIPixmapPrivKeyRec;
+#define DRIPixmapPrivKey (&DRIPixmapPrivKeyRec)
+static DevPrivateKeyRec DRIPixmapBufferPrivKeyRec;
+#define DRIPixmapBufferPrivKey (&DRIPixmapBufferPrivKeyRec)
 
 static RESTYPE DRIDrawablePrivResType;
 
@@ -205,6 +205,15 @@ DRIScreenInit(ScreenPtr pScreen)
     DRIScreenPrivPtr    pDRIPriv;
     int                 i;
 
+    if (!dixRegisterPrivateKey(&DRIScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE:
+    if (!dixRegisterPrivateKey(&DRIWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE:
+    if (!dixRegisterPrivateKey(&DRIPixmapPrivateKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE:
+    if (!dixRegisterPrivateKey(&DRIPixmapBufferPrivateKeyRec, PRIVATE_PIXMAP, 0))
+	return FALSE:
+
     pDRIPriv = (DRIScreenPrivPtr) calloc(1, sizeof(DRIScreenPrivRec));
     if (!pDRIPriv) {
 	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
diff --git a/hw/xquartz/xpr/driWrap.c b/hw/xquartz/xpr/driWrap.c
index f1a5c83..efbae3c 100644
--- a/hw/xquartz/xpr/driWrap.c
+++ b/hw/xquartz/xpr/driWrap.c
@@ -55,11 +55,11 @@ typedef struct {
     DevUnion devPrivate;
 } DRISavedDrawableState;
 
-static int driGCKeyIndex;
-static DevPrivateKey driGCKey = &driGCKeyIndex;
+static DevPrivateKeyRec driGCKeyRec;
+#define driGCKey (&driGCKeyRec)
 
-static int driWrapScreenKeyIndex;
-static DevPrivateKey driWrapScreenKey = &driWrapScreenKeyIndex;
+static DevPrivateKeyRec driWrapScreenKeyRec;
+#define driWrapScreenKey (&driWrapScreenKeyRec)
 
 static GCOps driGCOps;
 
@@ -527,10 +527,10 @@ Bool
 DRIWrapInit(ScreenPtr pScreen) {
     DRIWrapScreenRec *pScreenPriv;
 
-    if(!dixRequestPrivate(driGCKey, sizeof(DRIGCRec)))
+    if(!dixRegisterPrivateKey(&driGCKeyRec, PRIVATE_GC, sizeof(DRIGCRec)))
 	return FALSE;
 
-    if(!dixRequestPrivate(driWrapScreenKey, sizeof(DRIWrapScreenRec)))
+    if(!dixRegisterPrivateKey(&driWrapScreenKeyRec, PRIVATE_WINDOW, sizeof(DRIWrapScreenRec)))
 	return FALSE;
     
     pScreenPriv = malloc(sizeof(*pScreenPriv));
diff --git a/hw/xquartz/xpr/xprCursor.c b/hw/xquartz/xpr/xprCursor.c
index fdb8563..c268c2c 100644
--- a/hw/xquartz/xpr/xprCursor.c
+++ b/hw/xquartz/xpr/xprCursor.c
@@ -57,13 +57,12 @@ typedef struct {
     miPointerSpriteFuncPtr  spriteFuncs;
 } QuartzCursorScreenRec, *QuartzCursorScreenPtr;
 
-static int darwinCursorScreenKeyIndex;
-static DevPrivateKey darwinCursorScreenKey = &darwinCursorScreenKeyIndex;
+static DevPrivateKeyRec darwinCursorScreenKeyRec;
+#define darwinCursorScreenKey (&darwinCursorScreenKey)
 
 #define CURSOR_PRIV(pScreen) ((QuartzCursorScreenPtr) \
     dixLookupPrivate(&pScreen->devPrivates, darwinCursorScreenKey))
 
-
 static Bool
 load_cursor(CursorPtr src, int screen)
 {
@@ -360,6 +359,9 @@ QuartzInitCursor(ScreenPtr pScreen)
     if (!miDCInitialize(pScreen, &quartzScreenFuncsRec))
         return FALSE;
 
+    if (!dixRegisterPrivate(&darwinCursorScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     ScreenPriv = calloc(1, sizeof(QuartzCursorScreenRec));
     if (ScreenPriv == NULL)
         return FALSE;
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index 49b73d7..05913d7 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -628,11 +628,17 @@ extern DWORD			g_dwEvents;
 #ifdef HAS_DEVWINDOWS
 extern int			g_fdMessageQueue;
 #endif
-extern DevPrivateKey		g_iScreenPrivateKey;
-extern DevPrivateKey		g_iCmapPrivateKey;
-extern DevPrivateKey		g_iGCPrivateKey;
-extern DevPrivateKey		g_iPixmapPrivateKey;
-extern DevPrivateKey		g_iWindowPrivateKey;
+extern DevPrivateKeyRec		g_iScreenPrivateKeyRec;
+#define g_iScreenPrivateKey  	(&g_iScreenPrivateKeyRec)
+extern DevPrivateKeyRec		g_iCmapPrivateKeyRec;
+#define g_iCmapPrivateKeyRec 	(&g_iCmapPrivateKeyRec)
+extern DevPrivateKeyRec		g_iGCPrivateKeyRec;
+#define g_iGCPrivateKey 	(&g_iGCPrivateKeyRec)
+extern DevPrivateKeyRec		g_iPixmapPrivateKeyRec;
+#define g_iPixmapPrivateKey 	(&g_iPixmapPrivateKeyRec)
+extern DevPrivateKeyRec		g_iWindowPrivateKeyRec;
+#define g_iWindowPrivateKey 	(&g_iWindowPrivateKeyRec)
+
 extern unsigned long		g_ulServerGeneration;
 extern DWORD			g_dwEnginesSupported;
 extern HINSTANCE		g_hInstance;
diff --git a/hw/xwin/winallpriv.c b/hw/xwin/winallpriv.c
index 21ccd9b..6ecbff6 100644
--- a/hw/xwin/winallpriv.c
+++ b/hw/xwin/winallpriv.c
@@ -78,21 +78,21 @@ winAllocatePrivates (ScreenPtr pScreen)
   winSetScreenPriv (pScreen, pScreenPriv);
 
   /* Reserve GC memory for our privates */
-  if (!dixRequestPrivate(g_iGCPrivateKey, sizeof (winPrivGCRec)))
+  if (!dixRequestPrivateKey(g_iGCPrivateKey, PRIVATE_GC, sizeof (winPrivGCRec)))
     {
       ErrorF ("winAllocatePrivates - AllocateGCPrivate () failed\n");
       return FALSE;
     }
 
   /* Reserve Pixmap memory for our privates */
-  if (!dixRequestPrivate(g_iPixmapPrivateKey, sizeof (winPrivPixmapRec)))
+  if (!dixRequestPrivateKey(g_iPixmapPrivateKey, PRIVATE_PIXMAP, sizeof (winPrivPixmapRec)))
     {
       ErrorF ("winAllocatePrivates - AllocatePixmapPrivates () failed\n");
       return FALSE;
     }
 
   /* Reserve Window memory for our privates */
-  if (!dixRequestPrivate(g_iWindowPrivateKey, sizeof (winPrivWinRec)))
+  if (!dixRequestPrivateKey(g_iWindowPrivateKey, PRIVATE_WINDOW, sizeof (winPrivWinRec)))
     {
       ErrorF ("winAllocatePrivates () - AllocateWindowPrivates () failed\n");
        return FALSE;
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index 2ef8a36..2cc53f2 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -45,16 +45,11 @@ winScreenInfo * g_ScreenInfo = 0;
 #ifdef HAS_DEVWINDOWS
 int		g_fdMessageQueue = WIN_FD_INVALID;
 #endif
-static int	g_iScreenPrivateKeyIndex;
-DevPrivateKey	g_iScreenPrivateKey = &g_iScreenPrivateKeyIndex;
-static int	g_iCmapPrivateKeyIndex;
-DevPrivateKey	g_iCmapPrivateKey = &g_iCmapPrivateKeyIndex;
-static int	g_iGCPrivateKeyIndex;
-DevPrivateKey	g_iGCPrivateKey = &g_iGCPrivateKeyIndex;
-static int	g_iPixmapPrivateKeyIndex;
-DevPrivateKey	g_iPixmapPrivateKey = &g_iPixmapPrivateKeyIndex;
-static int	g_iWindowPrivateKeyIndex;
-DevPrivateKey	g_iWindowPrivateKey = &g_iWindowPrivateKeyIndex;
+DevPrivateKeyRec g_iScreenPrivateKeyRec;
+DevPrivateKeyRec g_iCmapPrivateKeyRec;
+DevPrivateKeyRec g_iGCPrivateKeyRec;
+DevPrivateKeyRec g_iPixmapPrivateKeyRec;
+DevPrivateKeyRec g_iWindowPrivateKeyRec;
 unsigned long	g_ulServerGeneration = 0;
 DWORD		g_dwEnginesSupported = 0;
 HINSTANCE	g_hInstance = 0;
@@ -131,6 +126,13 @@ Atom			g_atomLastOwnedSelection = None;
 void
 winInitializeGlobals (void)
 {
+  if (!dixRegisterPrivateKey(&g_iScreenPrivateKeyRec, PRIVATE_SCREEN, 0) ||
+      !dixRegisterPrivateKey(&g_iCmapPrivateKeyRec, PRIVATE_COLORMAP, 0) ||
+      !dixRegisterPrivateKey(&g_iGCPrivateKeyRec, PRIVATE_GC, 0) ||
+      !dixRegisterPrivateKey(&g_iPixmapPrivateKeyRec, PRIVATE_PIXMAP, 0) ||
+      !dixRegisterPrivateKey(&g_iWindowPrivateKeyRec, PRIVATE_WINDOW, 0)) {
+      FatalError("cannot register private key");
+  }
   g_dwCurrentThreadID = GetCurrentThreadId ();
   g_hwndKeyboardFocus = NULL;
 #ifdef XWIN_CLIPBOARD
diff --git a/include/cursor.h b/include/cursor.h
index dadedfd..59978d4 100644
--- a/include/cursor.h
+++ b/include/cursor.h
@@ -51,6 +51,7 @@ SOFTWARE.
 #include "misc.h"
 #include "screenint.h"
 #include "window.h"
+#include "privates.h"
 
 #define NullCursor ((CursorPtr)NULL)
 
@@ -62,7 +63,7 @@ struct _DeviceIntRec;
 typedef struct _Cursor *CursorPtr;
 typedef struct _CursorMetric *CursorMetricPtr;
 
-extern _X_EXPORT int cursorScreenDevPriv[MAXSCREENS];
+extern _X_EXPORT DevPrivateKeyRec cursorScreenDevPriv[MAXSCREENS];
 #define CursorScreenKey(pScreen) (cursorScreenDevPriv + (pScreen)->myNum)
 
 extern _X_EXPORT CursorPtr rootCursor;
diff --git a/include/cursorstr.h b/include/cursorstr.h
index 3ff56e2..6a4d0db 100644
--- a/include/cursorstr.h
+++ b/include/cursorstr.h
@@ -70,6 +70,8 @@ typedef struct _CursorBits {
 #endif
 } CursorBits, *CursorBitsPtr;
 
+#define CURSOR_BITS_SIZE (sizeof(CursorBits) + dixPrivatesSize(PRIVATE_CURSOR_BITS))
+
 typedef struct _Cursor {
     CursorBitsPtr bits;
     unsigned short foreRed, foreGreen, foreBlue; /* device-independent color */
@@ -83,6 +85,8 @@ typedef struct _Cursor {
 #endif
 } CursorRec;
 
+#define CURSOR_REC_SIZE (sizeof(CursorRec) + dixPrivatesSize(PRIVATE_CURSOR))
+
 typedef struct _CursorMetric {
     unsigned short width, height, xhot, yhot;
 } CursorMetricRec;
diff --git a/include/pixmap.h b/include/pixmap.h
index 55a9c81..5cf42d1 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -115,4 +115,7 @@ extern _X_EXPORT PixmapPtr AllocatePixmap(
     ScreenPtr /*pScreen*/,
     int /*pixDataSize*/);
 
+extern _X_EXPORT void FreePixmap(
+    PixmapPtr /*pPixmap*/);
+
 #endif /* PIXMAP_H */
diff --git a/include/privates.h b/include/privates.h
index 72f4d40..9412fd6 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -12,66 +12,109 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef PRIVATES_H
 #define PRIVATES_H 1
 
-#include "dix.h"
-#include "resource.h"
+#include <X11/Xdefs.h>
+#include <X11/Xosdefs.h>
+#include <X11/Xfuncproto.h>
+#include "misc.h"
 
 /*****************************************************************
  * STUFF FOR PRIVATES
  *****************************************************************/
 
-typedef int *DevPrivateKey;
-struct _Private;
-typedef struct _Private PrivateRec;
+typedef struct _Private PrivateRec, *PrivatePtr;
+
+typedef enum {
+    /* XSELinux uses the same private keys for numerous objects */
+    PRIVATE_XSELINUX,
+
+    /* Otherwise, you get a private in just the requested structure
+     */
+    /* These can have objects created before all of the keys are registered */
+    PRIVATE_SCREEN,
+    PRIVATE_EXTENSION,
+    PRIVATE_COLORMAP,
+
+    /* These cannot have any objects before all relevant keys are registered */
+    PRIVATE_DEVICE,
+    PRIVATE_CLIENT,
+    PRIVATE_PROPERTY,
+    PRIVATE_SELECTION,
+    PRIVATE_WINDOW,
+    PRIVATE_PIXMAP,
+    PRIVATE_GC,
+    PRIVATE_CURSOR,
+    PRIVATE_CURSOR_BITS,
+
+    /* extension privates */
+    PRIVATE_DBE_WINDOW,
+    PRIVATE_DAMAGE,
+    PRIVATE_GLYPH,
+    PRIVATE_GLYPHSET,
+    PRIVATE_PICTURE,
+
+    /* last private type */
+    PRIVATE_LAST,
+} DevPrivateType;
+
+typedef struct _DevPrivateKeyRec {
+    int			key;
+} DevPrivateKeyRec, *DevPrivateKey;
 
 /*
- * Request pre-allocated private space for your driver/module.  This function
- * increases the amount of space allocated automatically when dixLookupPrivate
- * is called on a PrivateRec that does not yet have a value associated with
- * 'key'.
- *
- * This function will only increase the reserved size: if a size was previously
- * requested, then dixRequestPrivate causes later calls to dixLookupPrivate to
- * allocate the maximum of the old size and 'size'.  Requested sizes are reset
- * to 0 by dixResetPrivates, which is called before each server generation.
- *
- * If dixRequestPrivate is not called with a nonzero size for 'key', then the
- * module responsible for 'key' must manage the associated pointer itself with
- * dixSetPrivate.
- *
- * dixRequestPrivate returns FALSE if it cannot store the requested size.
+ * Let drivers know how to initialize private keys
  */
-extern _X_EXPORT int
-dixRequestPrivate(const DevPrivateKey key, unsigned size);
+
+#define HAS_DEVPRIVATEKEYREC		1
+#define HAS_DIXREGISTERPRIVATEKEY	1
 
 /*
- * Allocates space for an association of 'key' with a value in 'privates'.
+ * Register a new private index for the private type.
  *
- * If a nonzero size was requested with dixRequestPrivate, then
- * dixAllocatePrivate also allocates the requested amount of memory and
- * associates the pointer to that memory with 'key' in 'privates'.  The
- * allocated memory is initialized to zero.  This memory can only be freed by
- * dixFreePrivates.
+ * This initializes the specified key and optionally requests pre-allocated
+ * private space for your driver/module. If you request no extra space, you
+ * may set and get a single pointer value using this private key. Otherwise,
+ * you can get the address of the extra space and store whatever data you like
+ * there.
  *
- * If dixRequestPrivate was never called with a nonzero size, then
- * dixAllocatePrivate associates NULL with 'key' in 'privates'.
+ * You may call dixRegisterPrivate more than once on the same key, but the
+ * size and type must match or the server will abort.
  *
- * dixAllocatePrivate returns a pointer to the value associated with 'key' in
- * 'privates', unless a memory allocation fails, in which case it returns NULL.
+ * dixRegisterPrivateIndex returns FALSE if it fails to allocate memory
+ * during its operation.
  */
-extern _X_EXPORT pointer *
-dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key);
+extern _X_EXPORT Bool
+dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size);
+
+/*
+ * Check whether a private key has been registered
+ */
+static inline Bool
+dixPrivateKeyRegistered(DevPrivateKey key)
+{
+    return key->key != 0;
+}
 
 /*
- * Look up a private pointer.
+ * Associate 'val' with 'key' in 'privates' so that later calls to
+ * dixLookupPrivate(privates, key) will return 'val'.
  *
- * If no value is currently associated with 'key' in 'privates', then
- * dixLookupPrivate calls dixAllocatePrivate and returns the resulting
- * associated value.
+ * dixSetPrivate returns FALSE if a memory allocation fails.
+ */
+extern _X_EXPORT int
+dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val);
+
+#include "dix.h"
+#include "resource.h"
+
+/*
+ * Lookup a pointer to the private record.
  *
- * dixLookupPrivate returns NULL if a memory allocation fails.
+ * For privates with defined storage, return the address of the
+ * storage. For privates without defined storage, return the pointer
+ * contents
  */
 extern _X_EXPORT pointer
-dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key);
+dixLookupPrivate(PrivatePtr *privates, const DevPrivateKey key);
 
 /*
  * Look up the address of a private pointer.  If 'key' is not associated with a
@@ -82,29 +125,72 @@ dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key);
  * 'privates' and a memory allocation fails.
  */
 extern _X_EXPORT pointer *
-dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key);
+dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key);
 
 /*
- * Associate 'val' with 'key' in 'privates' so that later calls to
- * dixLookupPrivate(privates, key) will return 'val'.
- *
- * dixSetPrivate returns FALSE if a memory allocation fails.
+ * Allocates private data separately from main object (clients and colormaps)
  */
-extern _X_EXPORT int
-dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val);
+static inline Bool
+dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type) { *privates = NULL; return TRUE; }
 
 /*
- * Unassociates all keys from 'privates' and frees all private data automatically
- * allocated via dixRequestPrivate.
+ * Frees separately allocated private data (screens and clients)
  */
 extern _X_EXPORT void
-dixFreePrivates(PrivateRec *privates);
+dixFreePrivates(PrivatePtr privates, DevPrivateType type);
+
+/*
+ * Initialize privates by zeroing them
+ */
+static inline void
+_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type) { *privates = NULL; }
+
+#define dixInitPrivates(o, v, type) _dixInitPrivates(&(o)->devPrivates, (v), type);
+
+/*
+ * Clean up privates
+ */
+static inline void
+_dixFiniPrivates(PrivatePtr privates, DevPrivateType type) { dixFreePrivates(privates, type); }
+
+#define dixFiniPrivates(o,t)	_dixFiniPrivates((o)->devPrivates,t)
+
+/*
+ * Allocates private data at object creation time. Required
+ * for all objects other than ScreenRecs.
+ */
+static inline void *
+_dixAllocateObjectWithPrivates(unsigned size, unsigned clear, unsigned offset, DevPrivateType type) {
+    return calloc(size, 1);
+}
+
+#define dixAllocateObjectWithPrivates(t, type) (t *) _dixAllocateObjectWithPrivates(sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
+
+static inline void
+_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type) {
+    dixFreePrivates(privates, type);
+    free(object);
+}
+
+#define dixFreeObjectWithPrivates(o,t) _dixFreeObjectWithPrivates(o, (o)->devPrivates, t)
+
+/*
+ * Return size of privates for the specified type
+ */
+static inline int
+dixPrivatesSize(DevPrivateType type) { return 0; }
+
+/*
+ * Dump out private stats to ErrorF
+ */
+void
+dixPrivateUsage(void);
 
 /*
  * Resets the privates subsystem.  dixResetPrivates is called from the main loop
  * before each server generation.  This function must only be called by main().
  */
-extern _X_EXPORT int
+extern _X_EXPORT void
 dixResetPrivates(void);
 
 /*
@@ -121,6 +207,6 @@ dixLookupPrivateOffset(RESTYPE type);
  * Convenience macro for adding an offset to an object pointer
  * when making a call to one of the devPrivates functions
  */
-#define DEVPRIV_AT(ptr, offset) ((PrivateRec **)((char *)ptr + offset))
+#define DEVPRIV_AT(ptr, offset) ((PrivatePtr *)((char *)(ptr) + offset))
 
 #endif /* PRIVATES_H */
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index b3a8319..7c92f64 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -275,7 +275,9 @@ typedef struct
 	device->public.realInputProc = oldprocs->realInputProc; \
 	device->unwrapProc = oldprocs->unwrapProc;
 
-extern DevPrivateKey xkbDevicePrivateKey;
+extern _X_EXPORT DevPrivateKeyRec xkbDevicePrivateKeyRec;
+#define xkbDevicePrivateKey (&xkbDevicePrivateKeyRec)
+
 #define XKBDEVICEINFO(dev) ((xkbDeviceInfoPtr)dixLookupPrivate(&(dev)->devPrivates, xkbDevicePrivateKey))
 
 extern void xkbUnwrapProc(DeviceIntPtr, DeviceHandleProc, pointer);
diff --git a/mi/micmap.c b/mi/micmap.c
index dac700d..3effe6c 100644
--- a/mi/micmap.c
+++ b/mi/micmap.c
@@ -40,8 +40,7 @@
 #include "globals.h"
 #include "micmap.h"
 
-static int micmapScrPrivateKeyIndex;
-DevPrivateKey micmapScrPrivateKey = &micmapScrPrivateKeyIndex;
+DevPrivateKeyRec micmapScrPrivateKeyRec;
 
 int
 miListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps)
@@ -300,6 +299,9 @@ miCreateDefColormap(ScreenPtr pScreen)
     ColormapPtr	cmap;
     int alloctype;
     
+    if (!dixRegisterPrivateKey(&micmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     for (pVisual = pScreen->visuals;
 	 pVisual->vid != pScreen->rootVisual;
 	 pVisual++)
diff --git a/mi/micmap.h b/mi/micmap.h
index 8ad94b9..c67710c 100644
--- a/mi/micmap.h
+++ b/mi/micmap.h
@@ -9,8 +9,8 @@
 #define SetInstalledmiColormap(s,c) \
     (dixSetPrivate(&(s)->devPrivates, micmapScrPrivateKey, c))
 
-extern _X_EXPORT DevPrivateKey micmapScrPrivateKey;
-
+extern _X_EXPORT DevPrivateKeyRec micmapScrPrivateKeyRec;
+#define micmapScrPrivateKey (&micmapScrPrivateKeyRec)
 
 typedef Bool (* miInitVisualsProcPtr)(VisualPtr *, DepthPtr *, int *, int *,
 					int *, VisualID *, unsigned long, int,
diff --git a/mi/midispcur.c b/mi/midispcur.c
index a8aef92..b412477 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -54,18 +54,18 @@ in this Software without prior written authorization from The Open Group.
 # include "inputstr.h"
 
 /* per-screen private data */
-static int miDCScreenKeyIndex;
-static DevPrivateKey miDCScreenKey = &miDCScreenKeyIndex;
+static DevPrivateKeyRec miDCScreenKeyRec;
+#define miDCScreenKey (&miDCScreenKeyRec)
 
 static Bool	miDCCloseScreen(int index, ScreenPtr pScreen);
 
 /* per bits per-screen private data */
-static int miDCCursorBitsKeyIndex[MAXSCREENS];
-#define miDCCursorBitsKey(screen)	(&miDCCursorBitsKeyIndex[(screen)->myNum])
+static DevPrivateKeyRec miDCCursorBitsKeyRec[MAXSCREENS];
+#define miDCCursorBitsKey(screen)	(&miDCCursorBitsKeyRec[(screen)->myNum])
 
 /* per device per-screen private data */
-static int miDCDeviceKeyIndex[MAXSCREENS];
-#define miDCDeviceKey(screen)		(&miDCDeviceKeyIndex[(screen)->myNum])
+static DevPrivateKeyRec miDCDeviceKeyRec[MAXSCREENS];
+#define miDCDeviceKey(screen)		(&miDCDeviceKeyRec[(screen)->myNum])
 
 typedef struct {
     GCPtr	    pSourceGC, pMaskGC;
@@ -103,11 +103,19 @@ miDCInitialize (ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
 {
     miDCScreenPtr   pScreenPriv;
 
+    if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&miDCDeviceKeyRec[pScreen->myNum], PRIVATE_DEVICE, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&miDCCursorBitsKeyRec[pScreen->myNum], PRIVATE_CURSOR_BITS, 0))
+	return FALSE;
+
     pScreenPriv = malloc(sizeof (miDCScreenRec));
     if (!pScreenPriv)
 	return FALSE;
 
-
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = miDCCloseScreen;
 
diff --git a/mi/miline.h b/mi/miline.h
index b5f706d..ae9d113 100644
--- a/mi/miline.h
+++ b/mi/miline.h
@@ -148,7 +148,8 @@ extern _X_EXPORT void miSetZeroLineBias(
 #define IsXDecreasingOctant(_octant)	((_octant) & XDECREASING)
 #define IsYDecreasingOctant(_octant)	((_octant) & YDECREASING)
 
-extern _X_EXPORT DevPrivateKey miZeroLineScreenKey;
+extern _X_EXPORT DevPrivateKeyRec miZeroLineScreenKeyRec;
+#define miZeroLineScreenKey (&miZeroLineScreenKeyRec)
 
 extern _X_EXPORT int miZeroClipLine(
     int /*xmin*/,
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index d8eb642..aa00e23 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -55,10 +55,10 @@ typedef struct {
    Bool				copyUnderlay;
 } miOverlayScreenRec, *miOverlayScreenPtr;
 
-static int miOverlayWindowKeyKeyIndex;
-static DevPrivateKey miOverlayWindowKey = &miOverlayWindowKeyKeyIndex;
-static int miOverlayScreenKeyIndex;
-static DevPrivateKey miOverlayScreenKey = &miOverlayScreenKeyIndex;
+static DevPrivateKeyRec miOverlayWindowKeyRec;
+#define miOverlayWindowKey (&miOverlayWindowKeyRec)
+static DevPrivateKeyRec miOverlayScreenKeyRec;
+#define miOverlayScreenKey (&miOverlayScreenKeyRec)
 
 static void RebuildTree(WindowPtr);
 static Bool HasUnderlayChildren(WindowPtr);
@@ -113,7 +113,10 @@ miInitOverlay(
 
     if(!inOverlayFunc || !transFunc) return FALSE;
 
-    if(!dixRequestPrivate(miOverlayWindowKey, sizeof(miOverlayWindowRec)))
+    if(!dixRegisterPrivateKey(&miOverlayWindowKeyRec, PRIVATE_WINDOW, sizeof(miOverlayWindowRec)))
+	return FALSE;
+
+    if(!dixRegisterPrivateKey(&miOverlayScreenKeyRec, PRIVATE_SCREEN, 0))
 	return FALSE;
 
     if(!(pScreenPriv = malloc(sizeof(miOverlayScreenRec))))
diff --git a/mi/mipointer.c b/mi/mipointer.c
index 296c57f..33bb40b 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -40,15 +40,13 @@ in this Software without prior written authorization from The Open Group.
 # include   "dixstruct.h"
 # include   "inputstr.h"
 
-static int miPointerScreenKeyIndex;
-DevPrivateKey miPointerScreenKey = &miPointerScreenKeyIndex;
+DevPrivateKeyRec miPointerScreenKeyRec;
 
 #define GetScreenPrivate(s) ((miPointerScreenPtr) \
     dixLookupPrivate(&(s)->devPrivates, miPointerScreenKey))
 #define SetupScreen(s)	miPointerScreenPtr  pScreenPriv = GetScreenPrivate(s)
 
-static int miPointerPrivKeyIndex;
-static DevPrivateKey miPointerPrivKey = &miPointerPrivKeyIndex;
+DevPrivateKeyRec miPointerPrivKeyRec;
 
 #define MIPOINTER(dev) \
     ((!IsMaster(dev) && !dev->u.master) ? \
@@ -86,6 +84,12 @@ miPointerInitialize (ScreenPtr                  pScreen,
 {
     miPointerScreenPtr	pScreenPriv;
 
+    if (!dixRegisterPrivateKey(&miPointerScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&miPointerPrivKeyRec, PRIVATE_DEVICE, 0))
+	return FALSE;
+
     pScreenPriv = malloc(sizeof (miPointerScreenRec));
     if (!pScreenPriv)
 	return FALSE;
diff --git a/mi/mipointer.h b/mi/mipointer.h
index 22575ea..de58c07 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -139,6 +139,10 @@ extern _X_EXPORT void miPointerSetPosition(
 extern _X_EXPORT void miPointerUpdateSprite(
     DeviceIntPtr pDev);
 
-extern _X_EXPORT DevPrivateKey miPointerScreenKey;
+extern _X_EXPORT DevPrivateKeyRec miPointerPrivKeyRec;
+#define miPointerPrivKey (&miPointerPrivKeyRec)
+
+extern _X_EXPORT DevPrivateKeyRec miPointerScreenKeyRec;
+#define miPointerScreenKey (&miPointerScreenKeyRec)
 
 #endif /* MIPOINTER_H */
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index 1b88ecb..ea2a0c1 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -292,21 +292,25 @@ miScreenInit(
     return miScreenDevPrivateInit(pScreen, width, pbits);
 }
 
-static int privateKeyIndex;
-static DevPrivateKey privateKey = &privateKeyIndex;
+static DevPrivateKeyRec privateKeyRec;
+#define privateKey (&privateKeyRec)
 
 DevPrivateKey
 miAllocateGCPrivateIndex(void)
 {
+    if (!dixRegisterPrivateKey(&privateKeyRec, PRIVATE_GC, 0))
+	return NULL;
     return privateKey;
 }
 
-static int miZeroLineScreenKeyIndex;
-DevPrivateKey miZeroLineScreenKey = &miZeroLineScreenKeyIndex;
+DevPrivateKeyRec miZeroLineScreenKeyRec;
 
 void
 miSetZeroLineBias(ScreenPtr pScreen, unsigned int bias)
 {
+    if (!dixRegisterPrivateKey(&miZeroLineScreenKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
     dixSetPrivate(&pScreen->devPrivates, miZeroLineScreenKey, 
 					(unsigned long *)(unsigned long)bias);
 }
diff --git a/mi/misprite.c b/mi/misprite.c
index b2cf5f0..38a6b93 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -182,10 +182,10 @@ miSpriteIsDown(miCursorInfoPtr pDevCursor)
  * screen wrappers
  */
 
-static int miSpriteScreenKeyIndex;
-static DevPrivateKey miSpriteScreenKey = &miSpriteScreenKeyIndex;
-static int miSpriteDevPrivatesKeyIndex;
-static DevPrivateKey miSpriteDevPrivatesKey = &miSpriteDevPrivatesKeyIndex;
+static DevPrivateKeyRec miSpriteScreenKeyRec;
+#define miSpriteScreenKey (&miSpriteScreenKeyRec)
+static DevPrivateKeyRec miSpriteDevPrivatesKeyRec;
+#define miSpriteDevPrivatesKey (&miSpriteDevPrivatesKeyRec)
 
 static Bool	    miSpriteCloseScreen(int i, ScreenPtr pScreen);
 static void	    miSpriteGetImage(DrawablePtr pDrawable, int sx, int sy,
@@ -293,6 +293,12 @@ miSpriteInitialize (ScreenPtr               pScreen,
     if (!DamageSetup (pScreen))
 	return FALSE;
 
+    if (!dixRegisterPrivateKey(&miSpriteScreenKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&miSpriteDevPrivatesKeyRec, PRIVATE_DEVICE, 0))
+	return FALSE;
+
     pScreenPriv = malloc(sizeof (miSpriteScreenRec));
     if (!pScreenPriv)
 	return FALSE;
diff --git a/miext/cw/cw.c b/miext/cw/cw.c
index 563831a..7623de7 100644
--- a/miext/cw/cw.c
+++ b/miext/cw/cw.c
@@ -43,14 +43,11 @@
 #define CW_ASSERT(x) do {} while (0)
 #endif
 
-static int cwGCKeyIndex;
-DevPrivateKey cwGCKey = &cwGCKeyIndex;
-static int cwScreenKeyIndex;
-DevPrivateKey cwScreenKey = &cwScreenKeyIndex;
-static int cwWindowKeyIndex;
-DevPrivateKey cwWindowKey = &cwWindowKeyIndex;
-static int cwPictureKeyIndex;
-DevPrivateKey cwPictureKey = &cwPictureKeyIndex;
+DevPrivateKeyRec cwGCKeyRec;
+DevPrivateKeyRec cwScreenKeyRec;
+DevPrivateKeyRec cwWindowKeyRec;
+DevPrivateKeyRec cwPictureKeyRec;
+
 extern GCOps cwGCOps;
 
 static Bool
@@ -477,7 +474,16 @@ miInitializeCompositeWrapper(ScreenPtr pScreen)
     cwScreenPtr pScreenPriv;
     Bool has_render = GetPictureScreenIfSet(pScreen) != NULL;
 
-    if (!dixRequestPrivate(cwGCKey, sizeof(cwGCRec)))
+    if (!dixRegisterPrivateKey(&cwScreenKeyRec, PRIVATE_SCREEN, 0))
+	return;
+
+    if (!dixRegisterPrivateKey(&cwGCKeyRec, PRIVATE_GC, sizeof(cwGCRec)))
+	return;
+
+    if (!dixRegisterPrivateKey(&cwWindowKeyRec, PRIVATE_WINDOW, 0))
+	return;
+
+    if (!dixRegisterPrivateKey(&cwPictureKeyRec, PRIVATE_PICTURE, 0))
 	return;
 
     pScreenPriv = malloc(sizeof(cwScreenRec));
diff --git a/miext/cw/cw.h b/miext/cw/cw.h
index 79051df..31eb9e5 100644
--- a/miext/cw/cw.h
+++ b/miext/cw/cw.h
@@ -44,7 +44,8 @@ typedef struct {
     GCFuncs	    *wrapFuncs;	    /* wrapped funcs */
 } cwGCRec, *cwGCPtr;
 
-extern _X_EXPORT DevPrivateKey cwGCKey;
+extern _X_EXPORT DevPrivateKeyRec cwGCKeyRec;
+#define cwGCKey (&cwGCKeyRec)
 
 #define getCwGC(pGC) ((cwGCPtr)dixLookupPrivate(&(pGC)->devPrivates, cwGCKey))
 #define setCwGC(pGC,p) dixSetPrivate(&(pGC)->devPrivates, cwGCKey, p)
@@ -60,12 +61,15 @@ typedef struct {
     unsigned long   stateChanges;
 } cwPictureRec, *cwPicturePtr;
 
+extern _X_EXPORT DevPrivateKeyRec cwPictureKeyRec;
+#define cwPictureKey (&cwPictureKeyRec)
+
 #define getCwPicture(pPicture) (pPicture->pDrawable ? \
     (cwPicturePtr)dixLookupPrivate(&(pPicture)->devPrivates, cwPictureKey) : 0)
 #define setCwPicture(pPicture,p) dixSetPrivate(&(pPicture)->devPrivates, cwPictureKey, p)
 
-extern _X_EXPORT DevPrivateKey cwPictureKey;
-extern _X_EXPORT DevPrivateKey cwWindowKey;
+extern _X_EXPORT DevPrivateKeyRec cwWindowKeyRec;
+#define cwWindowKey (&cwWindowKeyRec)
 
 #define cwWindowPrivate(pWin) dixLookupPrivate(&(pWin)->devPrivates, cwWindowKey)
 #define getCwPixmap(pWindow)	    ((PixmapPtr) cwWindowPrivate(pWindow))
@@ -108,7 +112,8 @@ typedef struct {
     RasterizeTrapezoidProcPtr	RasterizeTrapezoid;
 } cwScreenRec, *cwScreenPtr;
 
-extern _X_EXPORT DevPrivateKey cwScreenKey;
+extern _X_EXPORT DevPrivateKeyRec cwScreenKeyRec;
+#define cwScreenKey (&cwScreenKeyRec)
 
 #define getCwScreen(pScreen) ((cwScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, cwScreenKey))
 #define setCwScreen(pScreen,p) dixSetPrivate(&(pScreen)->devPrivates, cwScreenKey, p)
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index 935b1c0..e8a1191 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -70,14 +70,14 @@
 
 #define pixmapDamage(pPixmap)		damagePixPriv(pPixmap)
 
-static int damageScrPrivateKeyIndex;
-static DevPrivateKey damageScrPrivateKey = &damageScrPrivateKeyIndex;
-static int damagePixPrivateKeyIndex;
-static DevPrivateKey damagePixPrivateKey = &damagePixPrivateKeyIndex;
-static int damageGCPrivateKeyIndex;
-static DevPrivateKey damageGCPrivateKey = &damageGCPrivateKeyIndex;
-static int damageWinPrivateKeyIndex;
-static DevPrivateKey damageWinPrivateKey = &damageWinPrivateKeyIndex;
+static DevPrivateKeyRec damageScrPrivateKeyRec;
+#define damageScrPrivateKey (&damageScrPrivateKeyRec)
+static DevPrivateKeyRec damagePixPrivateKeyRec;
+#define damagePixPrivateKey (&damagePixPrivateKeyRec)
+static DevPrivateKeyRec damageGCPrivateKeyRec;
+#define damageGCPrivateKey (&damageGCPrivateKeyRec)
+static DevPrivateKeyRec damageWinPrivateKeyRec;
+#define damageWinPrivateKey (&damageWinPrivateKeyRec)
 
 static DamagePtr *
 getDrawableDamageRef (DrawablePtr pDrawable)
@@ -1884,10 +1884,19 @@ DamageSetup (ScreenPtr pScreen)
 	miDamageCreate, miDamageRegister, miDamageUnregister, miDamageDestroy
     };
 
+    if (!dixRegisterPrivateKey(&damageScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     if (dixLookupPrivate(&pScreen->devPrivates, damageScrPrivateKey))
 	return TRUE;
 
-    if (!dixRequestPrivate(damageGCPrivateKey, sizeof(DamageGCPrivRec)))
+    if (!dixRegisterPrivateKey(&damageGCPrivateKeyRec, PRIVATE_GC, sizeof(DamageGCPrivRec)))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&damagePixPrivateKeyRec, PRIVATE_PICTURE, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&damageWinPrivateKeyRec, PRIVATE_WINDOW, 0))
 	return FALSE;
 
     pScrPriv = malloc(sizeof (DamageScrPrivRec));
@@ -1926,7 +1935,7 @@ DamageCreate (DamageReportFunc  damageReport,
     damageScrPriv(pScreen);
     DamagePtr	pDamage;
 
-    pDamage = malloc(sizeof (DamageRec));
+    pDamage = dixAllocateObjectWithPrivates(DamageRec, PRIVATE_DAMAGE);
     if (!pDamage)
 	return 0;
     pDamage->pNext = 0;
@@ -1946,7 +1955,6 @@ DamageCreate (DamageReportFunc  damageReport,
     pDamage->damageDestroy = damageDestroy;
     pDamage->damageMarker = NULL;
     pDamage->pScreen = pScreen;
-    pDamage->devPrivates = NULL;
 
     (*pScrPriv->funcs.Create) (pDamage);
 
@@ -2050,11 +2058,9 @@ DamageDestroy (DamagePtr    pDamage)
     if (pDamage->damageDestroy)
 	(*pDamage->damageDestroy) (pDamage, pDamage->closure);
     (*pScrPriv->funcs.Destroy) (pDamage);
-    dixFreePrivates(pDamage->devPrivates);
-    pDamage->devPrivates = NULL;
     RegionUninit(&pDamage->damage);
     RegionUninit(&pDamage->pendingDamage);
-    free(pDamage);
+    dixFreeObjectWithPrivates(pDamage, PRIVATE_DAMAGE);
 }
 
 Bool
diff --git a/miext/rootless/rootlessCommon.h b/miext/rootless/rootlessCommon.h
index 8a4b813..6faf1fe 100644
--- a/miext/rootless/rootlessCommon.h
+++ b/miext/rootless/rootlessCommon.h
@@ -54,10 +54,17 @@
 
 
 // Global variables
-extern DevPrivateKey rootlessGCPrivateKey;
-extern DevPrivateKey rootlessScreenPrivateKey;
-extern DevPrivateKey rootlessWindowPrivateKey;
-extern DevPrivateKey rootlessWindowOldPixmapPrivateKey;
+extern DevPrivateKeyRec rootlessGCPrivateKeyRec;
+#define rootlessGCPrivateKey (&rootlessGCPrivateKeyRec)
+
+extern DevPrivateKeyRec rootlessScreenPrivateKeyRec;
+#define rootlessScreenPrivateKey (&rootlessScreenPrivateKeyRec)
+
+extern DevPrivateKeyRec rootlessWindowPrivateKeyRec;
+#define rootlessWindowPrivateKey (&rootlessWindowPrivateKeyRec)
+
+extern DevPrivateKeyRec rootlessWindowOldPixmapPrivateKeyRec;
+#define rootlessWindowOldPixmapPrivateKey (&rootlessWindowOldPixmapPrivateKeyRec)
 
 
 // RootlessGCRec: private per-gc data
diff --git a/miext/rootless/rootlessScreen.c b/miext/rootless/rootlessScreen.c
index 24dcfe8..43b9cbb 100644
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@ -62,15 +62,10 @@ extern int RootlessMiValidateTree(WindowPtr pRoot, WindowPtr pChild,
 extern Bool RootlessCreateGC(GCPtr pGC);
 
 // Initialize globals
-static int rootlessGCPrivateKeyIndex;
-DevPrivateKey rootlessGCPrivateKey = &rootlessGCPrivateKeyIndex;
-static int rootlessScreenPrivateKeyIndex;
-DevPrivateKey rootlessScreenPrivateKey = &rootlessScreenPrivateKeyIndex;
-static int rootlessWindowPrivateKeyIndex;
-DevPrivateKey rootlessWindowPrivateKey = &rootlessWindowPrivateKeyIndex;
-static int rootlessWindowOldPixmapPrivateKeyIndex;
-DevPrivateKey rootlessWindowOldPixmapPrivateKey = &rootlessWindowOldPixmapPrivateKeyIndex;
-
+DevPrivateKeyRec rootlessGCPrivateKeyRec;
+DevPrivateKeyRec rootlessScreenPrivateKeyRec;
+DevPrivateKeyRec rootlessWindowPrivateKeyRec;
+DevPrivateKeyRec rootlessWindowOldPixmapPrivateKeyRec;
 
 /*
  * RootlessUpdateScreenPixmap
@@ -637,8 +632,13 @@ RootlessAllocatePrivates(ScreenPtr pScreen)
 {
     RootlessScreenRec *s;
 
-    // no allocation needed for screen privates
-    if (!dixRequestPrivate(rootlessGCPrivateKey, sizeof(RootlessGCRec)))
+    if (!dixRegisterPrivateKey(&rootlessGCPrivateKeyRec, PRIVATE_GC, sizeof(RootlessGCRec)))
+        return FALSE;
+    if (!dixRegisterPrivateKey(&rootlessScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+        return FALSE;
+    if (!dixRegisterPrivateKey(&rootlessWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+        return FALSE;
+    if (!dixRegisterPrivateKey(&rootlessWindowOldPixmapPrivateKeyRec, PRIVATE_WINDOW, 0))
         return FALSE;
 
     s = malloc(sizeof(RootlessScreenRec));
diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index 893014b..111f46a 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -36,8 +36,8 @@
 #include    "gcstruct.h"
 #include    "shadow.h"
 
-static int shadowScrPrivateKeyIndex;
-DevPrivateKey shadowScrPrivateKey = &shadowScrPrivateKeyIndex;
+static DevPrivateKeyRec shadowScrPrivateKeyRec;
+#define shadowScrPrivateKey (&shadowScrPrivateKeyRec)
 
 #define wrap(priv, real, mem) {\
     priv->mem = real->mem; \
@@ -233,6 +233,9 @@ shadowInit(ScreenPtr pScreen, ShadowUpdateProc update, ShadowWindowProc window)
 {
     PixmapPtr pPixmap;
     
+    if (!dixRegisterPrivateKey(&shadowScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     pPixmap = pScreen->CreatePixmap(pScreen, pScreen->width, pScreen->height,
 				    pScreen->rootDepth, 0);
     if (!pPixmap)
diff --git a/randr/randr.c b/randr/randr.c
index ffb34d6..f52a46a 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -54,11 +54,9 @@ static int SProcRRDispatch (ClientPtr pClient);
 int	RREventBase;
 int	RRErrorBase;
 RESTYPE RRClientType, RREventType; /* resource types for event masks */
-static int RRClientPrivateKeyIndex;
-DevPrivateKey RRClientPrivateKey = &RRClientPrivateKeyIndex;
+DevPrivateKeyRec RRClientPrivateKeyRec;
 
-static int rrPrivKeyIndex;
-DevPrivateKey rrPrivKey = &rrPrivKeyIndex;
+DevPrivateKeyRec rrPrivKeyRec;
 
 static void
 RRClientCallback (CallbackListPtr	*list,
@@ -215,6 +213,9 @@ Bool RRInit (void)
 	    return FALSE;
 	RRGeneration = serverGeneration;
     }
+    if (!dixRegisterPrivateKey(&rrPrivKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     return TRUE;
 }
 
@@ -329,9 +330,9 @@ RRExtensionInit (void)
 
     if (RRNScreens == 0) return;
 
-    if (!dixRequestPrivate(RRClientPrivateKey,
-				sizeof (RRClientRec) +
-				screenInfo.numScreens * sizeof (RRTimesRec)))
+    if (!dixRegisterPrivateKey(&RRClientPrivateKeyRec, PRIVATE_CLIENT,
+			       sizeof (RRClientRec) +
+			       screenInfo.numScreens * sizeof (RRTimesRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, RRClientCallback, 0))
 	return;
diff --git a/randr/randrstr.h b/randr/randrstr.h
index a18c834..aad126f 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -299,7 +299,8 @@ typedef struct _rrScrPriv {
 #endif
 } rrScrPrivRec, *rrScrPrivPtr;
 
-extern _X_EXPORT DevPrivateKey rrPrivKey;
+extern _X_EXPORT DevPrivateKeyRec rrPrivKeyRec;
+#define rrPrivKey (&rrPrivKeyRec)
 
 #define rrGetScrPriv(pScr)  ((rrScrPrivPtr)dixLookupPrivate(&(pScr)->devPrivates, rrPrivKey))
 #define rrScrPriv(pScr)	rrScrPrivPtr    pScrPriv = rrGetScrPriv(pScr)
@@ -335,7 +336,8 @@ typedef struct _RRClient {
 } RRClientRec, *RRClientPtr;
 
 extern _X_EXPORT RESTYPE RRClientType, RREventType; /* resource types for event masks */
-extern _X_EXPORT DevPrivateKey RRClientPrivateKey;
+extern _X_EXPORT DevPrivateKeyRec RRClientPrivateKeyRec;
+#define RRClientPrivateKey (&RRClientPrivateKeyRec)
 extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType;
 
 #define VERIFY_RR_OUTPUT(id, ptr, a)\
diff --git a/record/record.c b/record/record.c
index 46231c9..82d5f9f 100644
--- a/record/record.c
+++ b/record/record.c
@@ -167,8 +167,8 @@ typedef struct {
     ProcFunctionPtr recordVector[256]; 
 } RecordClientPrivateRec, *RecordClientPrivatePtr;
 
-static int RecordClientPrivateKeyIndex;
-static DevPrivateKey RecordClientPrivateKey = &RecordClientPrivateKeyIndex;
+static DevPrivateKeyRec RecordClientPrivateKeyRec;
+#define RecordClientPrivateKey (&RecordClientPrivateKeyRec)
 
 /*  RecordClientPrivatePtr RecordClientPrivate(ClientPtr)
  *  gets the client private of the given client.  Syntactic sugar.
diff --git a/render/animcur.c b/render/animcur.c
index ad126fb..2160f50 100644
--- a/render/animcur.c
+++ b/render/animcur.c
@@ -76,11 +76,11 @@ static CursorBits   animCursorBits = {
     empty, empty, 2, 1, 1, 0, 0, 1
 };
 
-static int AnimCurScreenPrivateKeyIndex;
-static DevPrivateKey AnimCurScreenPrivateKey = &AnimCurScreenPrivateKeyIndex;
+static DevPrivateKeyRec AnimCurScreenPrivateKeyRec;
+#define AnimCurScreenPrivateKey (&AnimCurScreenPrivateKeyRec)
 
 #define IsAnimCur(c)	    ((c) && ((c)->bits == &animCursorBits))
-#define GetAnimCur(c)	    ((AnimCurPtr) ((c) + 1))
+#define GetAnimCur(c)	    ((AnimCurPtr) ((((char *)(c) + CURSOR_REC_SIZE))))
 #define GetAnimCurScreen(s) ((AnimCurScreenPtr)dixLookupPrivate(&(s)->devPrivates, AnimCurScreenPrivateKey))
 #define SetAnimCurScreen(s,p) dixSetPrivate(&(s)->devPrivates, AnimCurScreenPrivateKey, p)
 
@@ -322,6 +322,9 @@ AnimCurInit (ScreenPtr pScreen)
 {
     AnimCurScreenPtr    as;
 
+    if (!dixRegisterPrivateKey(&AnimCurScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     as = (AnimCurScreenPtr) malloc(sizeof (AnimCurScreenRec));
     if (!as)
 	return FALSE;
@@ -354,11 +357,12 @@ AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *pp
 	if (IsAnimCur (cursors[i]))
 	    return BadMatch;
 	
-    pCursor = (CursorPtr) malloc(sizeof (CursorRec) +
-				  sizeof (AnimCurRec) +
-				  ncursor * sizeof (AnimCurElt));
+    pCursor = (CursorPtr) calloc(CURSOR_REC_SIZE +
+				 sizeof (AnimCurRec) +
+				 ncursor * sizeof (AnimCurElt), 1);
     if (!pCursor)
 	return BadAlloc;
+    dixInitPrivates(pCursor, pCursor + 1, PRIVATE_CURSOR);
     pCursor->bits = &animCursorBits;
     pCursor->refcnt = 1;
     
@@ -371,13 +375,12 @@ AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *pp
     pCursor->backBlue = cursors[0]->backBlue;
 
     pCursor->id = cid;
-    pCursor->devPrivates = NULL;
 
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, pCursor,
 		  RT_NONE, NULL, DixCreateAccess);
     if (rc != Success) {
-	dixFreePrivates(pCursor->devPrivates);
+	dixFiniPrivates(pCursor, PRIVATE_CURSOR);
 	free(pCursor);
 	return rc;
     }
diff --git a/render/glyph.c b/render/glyph.c
index e5b8f86..948a20a 100644
--- a/render/glyph.c
+++ b/render/glyph.c
@@ -84,19 +84,13 @@ static const CARD8	glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 };
 
 static GlyphHashRec	globalGlyphs[GlyphFormatNum];
 
-static void
-FreeGlyphPrivates (GlyphPtr glyph)
-{
-    dixFreePrivates(glyph->devPrivates);
-    glyph->devPrivates = NULL;
-}
-
 void
 GlyphUninit (ScreenPtr pScreen)
 {
     PictureScreenPtr ps = GetPictureScreen (pScreen);
     GlyphPtr	     glyph;
     int		     fdepth, i;
+    int		     scrno = pScreen->myNum;
 
     for (fdepth = 0; fdepth < GlyphFormatNum; fdepth++)
     {
@@ -108,8 +102,12 @@ GlyphUninit (ScreenPtr pScreen)
 	    glyph = globalGlyphs[fdepth].table[i].glyph;
 	    if (glyph && glyph != DeletedGlyph)
 	    {
+		if (GlyphPicture(glyph)[scrno])
+		{
+		    FreePicture ((pointer) GlyphPicture (glyph)[scrno], 0);
+		    GlyphPicture(glyph)[scrno] = NULL;
+		}
 		(*ps->UnrealizeGlyph) (pScreen, glyph);
-		FreeGlyphPrivates(glyph);
 	    }
 	}
     }
@@ -301,8 +299,7 @@ FreeGlyph (GlyphPtr glyph, int format)
 	}
 
 	FreeGlyphPicture(glyph);
-	FreeGlyphPrivates(glyph);
-	free(glyph);
+	dixFreeObjectWithPrivates(glyph, PRIVATE_GLYPH);
     }
 }
 
@@ -320,8 +317,7 @@ AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id)
     if (gr->glyph && gr->glyph != DeletedGlyph && gr->glyph != glyph)
     {
 	FreeGlyphPicture(glyph);
-	FreeGlyphPrivates(glyph);
-	free(glyph);
+	dixFreeObjectWithPrivates(glyph, PRIVATE_GLYPH);
 	glyph = gr->glyph;
     }
     else if (gr->glyph != glyph)
@@ -372,6 +368,8 @@ FindGlyph (GlyphSetPtr glyphSet, Glyph id)
     return glyph;
 }
 
+#define GLYPH_SIZE	(sizeof (GlyphRec) + dixPrivatesSize(PRIVATE_GLYPH))
+
 GlyphPtr
 AllocateGlyph (xGlyphInfo *gi, int fdepth)
 {
@@ -381,13 +379,13 @@ AllocateGlyph (xGlyphInfo *gi, int fdepth)
     int		     i;
 
     size = screenInfo.numScreens * sizeof (PicturePtr);
-    glyph = (GlyphPtr) malloc(size + sizeof (GlyphRec));
+    glyph = (GlyphPtr) malloc (size + GLYPH_SIZE);
     if (!glyph)
 	return 0;
     glyph->refcnt = 0;
     glyph->size = size + sizeof (xGlyphInfo);
     glyph->info = *gi;
-    glyph->devPrivates = NULL;
+    dixInitPrivates(glyph, glyph + 1, PRIVATE_GLYPH);
 
     for (i = 0; i < screenInfo.numScreens; i++)
     {
@@ -411,8 +409,7 @@ bail:
 	    (*ps->UnrealizeGlyph) (screenInfo.screens[i], glyph);
     }
 
-    FreeGlyphPrivates(glyph);
-    free(glyph);
+    dixFreeObjectWithPrivates(glyph, PRIVATE_GLYPH);
     return 0;
 }
     
@@ -481,7 +478,6 @@ GlyphSetPtr
 AllocateGlyphSet (int fdepth, PictFormatPtr format)
 {
     GlyphSetPtr	glyphSet;
-    int size;
     
     if (!globalGlyphs[fdepth].hashSet)
     {
@@ -489,8 +485,7 @@ AllocateGlyphSet (int fdepth, PictFormatPtr format)
 	    return FALSE;
     }
 
-    size = sizeof (GlyphSetRec);
-    glyphSet = calloc(1, size);
+    glyphSet = dixAllocateObjectWithPrivates(GlyphSetRec, PRIVATE_GLYPHSET);
     if (!glyphSet)
 	return FALSE;
 
@@ -532,8 +527,7 @@ FreeGlyphSet (pointer	value,
 	else
 	    ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], 0, TRUE);
 	free(table);
-	dixFreePrivates(glyphSet->devPrivates);
-	free(glyphSet);
+	dixFreeObjectWithPrivates(glyphSet, PRIVATE_GLYPHSET);
     }
     return Success;
 }
diff --git a/render/picture.c b/render/picture.c
index ca5e18e..f6e3a9e 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -42,10 +42,8 @@
 #include "picturestr.h"
 #include "xace.h"
 
-static int PictureScreenPrivateKeyIndex;
-DevPrivateKey PictureScreenPrivateKey = &PictureScreenPrivateKeyIndex;
-static int PictureWindowPrivateKeyIndex;
-DevPrivateKey	PictureWindowPrivateKey = &PictureWindowPrivateKeyIndex;
+DevPrivateKeyRec PictureScreenPrivateKeyRec;
+DevPrivateKeyRec PictureWindowPrivateKeyRec;
 static int	PictureGeneration;
 RESTYPE		PictureType;
 RESTYPE		PictFormatType;
@@ -628,6 +626,12 @@ PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats)
 	    return FALSE;
 	PictureGeneration = serverGeneration;
     }
+    if (!dixRegisterPrivateKey(&PictureScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
+    if (!dixRegisterPrivateKey(&PictureWindowPrivateKeyRec, PRIVATE_WINDOW, 0))
+	return FALSE;
+
     if (!formats)
     {
 	formats = PictureCreateDefaultFormats (pScreen, &nformats);
@@ -753,7 +757,7 @@ CreatePicture (Picture		pid,
     PicturePtr		pPicture;
     PictureScreenPtr	ps = GetPictureScreen(pDrawable->pScreen);
 
-    pPicture = (PicturePtr)malloc(sizeof(PictureRec));
+    pPicture = dixAllocateObjectWithPrivates(PictureRec, PRIVATE_PICTURE);
     if (!pPicture)
     {
 	*error = BadAlloc;
@@ -764,7 +768,6 @@ CreatePicture (Picture		pid,
     pPicture->pDrawable = pDrawable;
     pPicture->pFormat = pFormat;
     pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24);
-    pPicture->devPrivates = NULL;
 
     /* security creation/labeling check */
     *error = XaceHook(XACE_RESOURCE_ACCESS, client, pid, PictureType, pPicture,
@@ -896,12 +899,11 @@ static void initGradient(SourcePictPtr pGradient, int stopCount,
 static PicturePtr createSourcePicture(void)
 {
     PicturePtr pPicture;
-    pPicture = (PicturePtr) malloc(sizeof(PictureRec));
+    pPicture = dixAllocateObjectWithPrivates(PictureRec, PRIVATE_PICTURE);
     pPicture->pDrawable = 0;
     pPicture->pFormat = 0;
     pPicture->pNext = 0;
     pPicture->format = PICT_a8r8g8b8;
-    pPicture->devPrivates = 0;
 
     SetPictureToDefaults(pPicture);
     return pPicture;
@@ -1566,8 +1568,7 @@ FreePicture (pointer	value,
                 (*pScreen->DestroyPixmap) ((PixmapPtr)pPicture->pDrawable);
             }
         }
-	dixFreePrivates(pPicture->devPrivates);
-	free(pPicture);
+	dixFreeObjectWithPrivates(pPicture, PRIVATE_PICTURE);
     }
     return Success;
 }
diff --git a/render/picture.h b/render/picture.h
index 8bd38b9..e5f0d78 100644
--- a/render/picture.h
+++ b/render/picture.h
@@ -174,7 +174,6 @@ extern _X_EXPORT int PictureCmapPolicy;
 extern _X_EXPORT int PictureParseCmapPolicy (const char *name);
 
 extern _X_EXPORT int RenderErrBase;
-extern _X_EXPORT DevPrivateKey RenderClientPrivateKey;
 
 /* Fixed point updates from Carl Worth, USC, Information Sciences Institute */
 
diff --git a/render/picturestr.h b/render/picturestr.h
index a401108..da69ff6 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -396,8 +396,12 @@ typedef struct _PictureScreen {
 
 } PictureScreenRec, *PictureScreenPtr;
 
-extern _X_EXPORT DevPrivateKey	PictureScreenPrivateKey;
-extern _X_EXPORT DevPrivateKey	PictureWindowPrivateKey;
+extern _X_EXPORT DevPrivateKeyRec PictureScreenPrivateKeyRec;
+#define PictureScreenPrivateKey (&PictureScreenPrivateKeyRec)
+
+extern _X_EXPORT DevPrivateKeyRec PictureWindowPrivateKeyRec;
+#define	PictureWindowPrivateKey (&PictureWindowPrivateKeyRec)
+
 extern _X_EXPORT RESTYPE	PictureType;
 extern _X_EXPORT RESTYPE	PictFormatType;
 extern _X_EXPORT RESTYPE	GlyphSetType;
diff --git a/render/render.c b/render/render.c
index 78ecf43..40401a4 100644
--- a/render/render.c
+++ b/render/render.c
@@ -210,8 +210,8 @@ int	(*SProcRenderVector[RenderNumberRequests])(ClientPtr) = {
 };
 
 int	RenderErrBase;
-static int RenderClientPrivateKeyIndex;
-DevPrivateKey RenderClientPrivateKey = &RenderClientPrivateKeyIndex;
+static DevPrivateKeyRec RenderClientPrivateKeyRec;
+#define RenderClientPrivateKey (&RenderClientPrivateKeyRec )
 
 typedef struct _RenderClient {
     int	    major_version;
@@ -246,7 +246,7 @@ RenderExtensionInit (void)
 	return;
     if (!PictureFinishInit ())
 	return;
-    if (!dixRequestPrivate(RenderClientPrivateKey, sizeof(RenderClientRec)))
+    if (!dixRegisterPrivateKey(&RenderClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(RenderClientRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0))
 	return;
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 5f08db7..a9f089f 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -59,8 +59,8 @@ static RESTYPE		CursorHideCountType;
 static RESTYPE		CursorWindowType;
 static CursorPtr	CursorCurrent[MAXDEVICES];
 
-static int CursorScreenPrivateKeyIndex;
-static DevPrivateKey CursorScreenPrivateKey = &CursorScreenPrivateKeyIndex;
+static DevPrivateKeyRec CursorScreenPrivateKeyRec;
+#define CursorScreenPrivateKey (&CursorScreenPrivateKeyRec)
 
 static void deleteCursorHideCountsForScreen (ScreenPtr pScreen);
 
@@ -1037,6 +1037,9 @@ XFixesCursorInit (void)
     if (party_like_its_1989)
 	CursorVisible = EnableCursor;
     
+    if (!dixRegisterPrivateKey(&CursorScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+	return FALSE;
+
     for (i = 0; i < screenInfo.numScreens; i++)
     {
 	ScreenPtr	pScreen = screenInfo.screens[i];
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index 2f64a04..215909d 100644
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -56,8 +56,8 @@ static unsigned char	XFixesReqCode;
 int		XFixesEventBase;
 int		XFixesErrorBase;
 
-static int XFixesClientPrivateKeyIndex;
-static DevPrivateKey XFixesClientPrivateKey = &XFixesClientPrivateKeyIndex;
+static DevPrivateKeyRec XFixesClientPrivateKeyRec;
+#define XFixesClientPrivateKey (&XFixesClientPrivateKeyRec)
 
 static int
 ProcXFixesQueryVersion(ClientPtr client)
@@ -241,7 +241,7 @@ XFixesExtensionInit(void)
 {
     ExtensionEntry *extEntry;
 
-    if (!dixRequestPrivate(XFixesClientPrivateKey, sizeof (XFixesClientRec)))
+    if (!dixRegisterPrivateKey(&XFixesClientPrivateKeyRec, PRIVATE_CLIENT, sizeof (XFixesClientRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, XFixesClientCallback, 0))
 	return;
diff --git a/xkb/xkb.c b/xkb/xkb.c
index 5a425bd..0dab694 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -6707,6 +6707,9 @@ XkbExtensionInit(void)
     if (!RT_XKBCLIENT)
 	return;
 
+    if (!dixRegisterPrivateKey(&xkbDevicePrivateKeyRec, PRIVATE_DEVICE, 0))
+	return;
+
     if ((extEntry = AddExtension(XkbName, XkbNumberEvents, XkbNumberErrors,
 				 ProcXkbDispatch, SProcXkbDispatch,
 				 NULL, StandardMinorOpcode))) {
diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c
index 0a1a873..3f0b766 100644
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@ -43,8 +43,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "mi.h"
 #define EXTENSION_EVENT_BASE 64
 
-static int xkbDevicePrivateKeyIndex;
-DevPrivateKey xkbDevicePrivateKey = &xkbDevicePrivateKeyIndex;
+DevPrivateKeyRec xkbDevicePrivateKeyRec;
 
 static void XkbFakeDeviceButton(DeviceIntPtr dev,Bool press,int button);
 static void XkbFakePointerMotion(DeviceIntPtr dev, unsigned flags,int x,int y);
commit c865a24401f06bcf1347d8b41f736a066ab25693
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Apr 30 22:05:27 2010 -0700

    Create separate private key for midispcur cursor bits
    
    The CursorScreenKey array is supposed to be used by the DDX for cursor
    private data, but midispcur was abusing it to hold cursor bits private
    information. Create a separate set of privates for the dispcur cursor
    bits information.
    
    This also renames the device private index and macros to better
    reflect their usage:
    
    	miDCSpriteKey -> miDCDeviceKey
    	MIDCBUFFER -> miGetDCDevice
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/mi/midispcur.c b/mi/midispcur.c
index 87eb27d..a8aef92 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -59,9 +59,13 @@ static DevPrivateKey miDCScreenKey = &miDCScreenKeyIndex;
 
 static Bool	miDCCloseScreen(int index, ScreenPtr pScreen);
 
+/* per bits per-screen private data */
+static int miDCCursorBitsKeyIndex[MAXSCREENS];
+#define miDCCursorBitsKey(screen)	(&miDCCursorBitsKeyIndex[(screen)->myNum])
+
 /* per device per-screen private data */
-static int miDCSpriteKeyIndex[MAXSCREENS];
-static DevPrivateKey miDCSpriteKey = miDCSpriteKeyIndex;
+static int miDCDeviceKeyIndex[MAXSCREENS];
+#define miDCDeviceKey(screen)		(&miDCDeviceKeyIndex[(screen)->myNum])
 
 typedef struct {
     GCPtr	    pSourceGC, pMaskGC;
@@ -72,10 +76,10 @@ typedef struct {
 #endif
 } miDCBufferRec, *miDCBufferPtr;
 
-#define MIDCBUFFER(dev, screen) \
+#define miGetDCDevice(dev, screen) \
  ((DevHasCursor(dev)) ? \
-  (miDCBufferPtr)dixLookupPrivate(&dev->devPrivates, miDCSpriteKey + (screen)->myNum) : \
-  (miDCBufferPtr)dixLookupPrivate(&dev->u.master->devPrivates, miDCSpriteKey + (screen)->myNum))
+  (miDCBufferPtr)dixLookupPrivate(&dev->devPrivates, miDCDeviceKey(screen)) : \
+  (miDCBufferPtr)dixLookupPrivate(&dev->u.master->devPrivates, miDCDeviceKey(screen)))
 
 /* 
  * The core pointer buffer will point to the index of the virtual core pointer
@@ -133,7 +137,7 @@ Bool
 miDCRealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
 {
     if (pCursor->bits->refcnt <= 1)
-	dixSetPrivate(&pCursor->bits->devPrivates, CursorScreenKey(pScreen), NULL);
+	dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), NULL);
     return TRUE;
 }
 
@@ -232,7 +236,7 @@ miDCRealize (ScreenPtr pScreen, CursorPtr pCursor)
 	    free((pointer) pPriv);
 	    return NULL;
 	}
-	dixSetPrivate(&pCursor->bits->devPrivates, CursorScreenKey(pScreen), pPriv);
+	dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), pPriv);
 	return pPriv;
     }
     pPriv->pPicture = 0;
@@ -250,7 +254,7 @@ miDCRealize (ScreenPtr pScreen, CursorPtr pCursor)
 	free((pointer) pPriv);
 	return NULL;
     }
-    dixSetPrivate(&pCursor->bits->devPrivates, CursorScreenKey(pScreen), pPriv);
+    dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), pPriv);
 
     /* create the two sets of bits, clipping as appropriate */
 
@@ -295,7 +299,7 @@ miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
     miDCCursorPtr   pPriv;
 
     pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates,
-					    CursorScreenKey(pScreen));
+					    miDCCursorBitsKey(pScreen));
     if (pPriv && (pCursor->bits->refcnt <= 1))
     {
 	if (pPriv->sourceBits)
@@ -307,7 +311,7 @@ miDCUnrealizeCursor (ScreenPtr pScreen, CursorPtr pCursor)
 	    FreePicture (pPriv->pPicture, 0);
 #endif
 	free((pointer) pPriv);
-	dixSetPrivate(&pCursor->bits->devPrivates, CursorScreenKey(pScreen), NULL);
+	dixSetPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey(pScreen), NULL);
     }
     return TRUE;
 }
@@ -396,7 +400,7 @@ miDCPutUpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
     WindowPtr	    pWin;
 
     pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates,
-					    CursorScreenKey(pScreen));
+					    miDCCursorBitsKey(pScreen));
     if (!pPriv)
     {
 	pPriv = miDCRealize(pScreen, pCursor);
@@ -406,7 +410,7 @@ miDCPutUpCursor (DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
     pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
 						  miDCScreenKey);
     pWin = pScreen->root;
-    pBuffer = MIDCBUFFER(pDev, pScreen);
+    pBuffer = miGetDCDevice(pDev, pScreen);
 
 #ifdef ARGB_CURSOR
     if (pPriv->pPicture)
@@ -445,7 +449,7 @@ miDCSaveUnderCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
 
     pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
 						  miDCScreenKey);
-    pBuffer = MIDCBUFFER(pDev, pScreen);
+    pBuffer = miGetDCDevice(pDev, pScreen);
 
     pSave = pBuffer->pSave;
     pWin = pScreen->root;
@@ -479,7 +483,7 @@ miDCRestoreUnderCursor (DeviceIntPtr pDev, ScreenPtr pScreen,
 
     pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
 						  miDCScreenKey);
-    pBuffer = MIDCBUFFER(pDev, pScreen);
+    pBuffer = miGetDCDevice(pDev, pScreen);
     pSave = pBuffer->pSave;
 
     pWin = pScreen->root;
@@ -512,7 +516,7 @@ miDCDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
         if (!pBuffer)
             goto failure;
 
-        dixSetPrivate(&pDev->devPrivates, miDCSpriteKey + pScreen->myNum, pBuffer);
+        dixSetPrivate(&pDev->devPrivates, miDCDeviceKey(pScreen), pBuffer);
         pWin = pScreen->root;
 
         pBuffer->pSourceGC = miDCMakeGC(pWin);
@@ -560,7 +564,7 @@ miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
         {
             pScreen = screenInfo.screens[i];
 
-            pBuffer = MIDCBUFFER(pDev, pScreen);
+            pBuffer = miGetDCDevice(pDev, pScreen);
 
             if (pBuffer)
             {
@@ -578,7 +582,7 @@ miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
                 if (pBuffer->pSave) (*pScreen->DestroyPixmap)(pBuffer->pSave);
 
                 free(pBuffer);
-                dixSetPrivate(&pDev->devPrivates, miDCSpriteKey + pScreen->myNum, NULL);
+                dixSetPrivate(&pDev->devPrivates, miDCDeviceKey(pScreen), NULL);
             }
         }
     }
commit 431781a921251d54782f0a4f194bbef1fabd1380
Author: Keith Packard <keithp at keithp.com>
Date:   Sat May 15 14:52:39 2010 -0700

    Remove dixRegisterPrivateOffset; hard-code devPrivates offsets instead
    
    For predefined resource types, the offset of the devPrivates field was
    already kept in a constant table. The only non-predefined type needing
    this treatment was dbeDrawableResType, which is just a magic alias for
    RT_PIXMAP.
    
    This patch special-cases looking up RC_DRAWABLE offsets and uses the
    table directly for everything else.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>

diff --git a/dbe/dbe.c b/dbe/dbe.c
index fba10d6..9b5474c 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -1576,10 +1576,6 @@ DbeExtensionInit(void)
     if (!dbeWindowPrivResType)
 	return;
 
-    if (!dixRegisterPrivateOffset(dbeDrawableResType,
-				  offsetof(PixmapRec, devPrivates)))
-	return;
-
     for (i = 0; i < screenInfo.numScreens; i++)
     {
         /* For each screen, set up DBE screen privates and init DIX and DDX
diff --git a/dix/privates.c b/dix/privates.c
index 4a8a186..9ec6c46 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -208,7 +208,7 @@ dixFreePrivates(PrivateRec *privates)
 }
 
 /* Table of devPrivates offsets */
-static const int offsetDefaults[] = {
+static const int offsets[] = {
     -1,					/* RT_NONE */
     offsetof(WindowRec, devPrivates),	/* RT_WINDOW */
     offsetof(PixmapRec, devPrivates),	/* RT_PIXMAP */
@@ -216,45 +216,27 @@ static const int offsetDefaults[] = {
     -1,		    			/* RT_FONT */
     offsetof(CursorRec, devPrivates),	/* RT_CURSOR */
     offsetof(ColormapRec, devPrivates),	/* RT_COLORMAP */
-    -1,			  		/* RT_CMAPENTRY */
-    -1,					/* RT_OTHERCLIENT */
-    -1					/* RT_PASSIVEGRAB */
 };
-    
-static int *offsets = NULL;
-static int offsetsSize = 0;
 
-/*
- * Specify where the devPrivates field is located in a structure type
- */
-int
-dixRegisterPrivateOffset(RESTYPE type, int offset)
-{
-    type = type & TypeMask;
-
-    /* resize offsets table if necessary */
-    while (type >= offsetsSize) {
-	unsigned i = offsetsSize * 2 * sizeof(int);
-	offsets = (int *)realloc(offsets, i);
-	if (!offsets) {
-	    offsetsSize = 0;
-	    return FALSE;
-	}
-	for (i=offsetsSize; i < 2*offsetsSize; i++)
-	    offsets[i] = -1;
-	offsetsSize *= 2;
-    }
-
-    offsets[type] = offset;
-    return TRUE;
-}
+#define NUM_OFFSETS	(sizeof (offsets) / sizeof (offsets[0]))
 
 int
 dixLookupPrivateOffset(RESTYPE type)
 {
+    /*
+     * Special kludge for DBE which registers a new resource type that
+     * points at pixmaps (thanks, DBE)
+     */
+    if (type & RC_DRAWABLE) {
+	if (type == RT_WINDOW)
+	    return offsets[RT_WINDOW & TypeMask];
+	else
+	    return offsets[RT_PIXMAP & TypeMask];
+    }
     type = type & TypeMask;
-    assert(type < offsetsSize);
-    return offsets[type];
+    if (type < NUM_OFFSETS)
+	return offsets[type];
+    return -1;
 }
 
 int
@@ -268,15 +250,5 @@ dixResetPrivates(void)
 	items[i].size = 0;
     }
     nextPriv = 1;
-
-    /* reset offsets */
-    if (offsets)
-	free(offsets);
-    offsetsSize = sizeof(offsetDefaults);
-    offsets = malloc(offsetsSize);
-    offsetsSize /= sizeof(int);
-    if (!offsets)
-	return FALSE;
-    memcpy(offsets, offsetDefaults, sizeof(offsetDefaults));
     return TRUE;
 }
diff --git a/dix/resource.c b/dix/resource.c
index a6d115f..ce025f9 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -254,8 +254,6 @@ CreateNewResourceType(DeleteType deleteFunc, char *name)
     types = realloc(resourceTypes, (next + 1) * sizeof(*resourceTypes));
     if (!types)
 	return 0;
-    if (!dixRegisterPrivateOffset(next, -1))
-	return 0;
 
     lastResourceType = next;
     resourceTypes = types;
diff --git a/include/privates.h b/include/privates.h
index 7850dea..72f4d40 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -108,26 +108,16 @@ extern _X_EXPORT int
 dixResetPrivates(void);
 
 /*
- * These next two functions are necessary because the position of
- * the devPrivates field varies by structure and calling code might
- * only know the resource type, not the structure definition.
- */
-
-/*
  * Looks up the offset where the devPrivates field is located.
- * Returns -1 if no offset has been registered for the resource type.
+ * Returns -1 if the specified resource has no dev privates.
+ * The position of the devPrivates field varies by structure
+ * and calling code might only know the resource type, not the
+ * structure definition.
  */
 extern _X_EXPORT int
 dixLookupPrivateOffset(RESTYPE type);
 
 /*
- * Specifies the offset where the devPrivates field is located.
- * A negative value indicates no devPrivates field is available.
- */
-extern _X_EXPORT int
-dixRegisterPrivateOffset(RESTYPE type, int offset);
-
-/*
  * Convenience macro for adding an offset to an object pointer
  * when making a call to one of the devPrivates functions
  */
commit 7ef612de784daaed09ba13f4615c10714614033f
Author: Keith Packard <keithp at keithp.com>
Date:   Fri May 21 12:35:29 2010 -0700

    Add REGION_ macros for source compatibility with existing drivers.
    
    This makes the region code changes source compatible with existing
    code, although none of them are used within the server source itself.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/regionstr.h b/include/regionstr.h
index 8bc902a..627941b 100644
--- a/include/regionstr.h
+++ b/include/regionstr.h
@@ -328,4 +328,43 @@ extern _X_EXPORT int RegionClipSpans(
     int /*fSorted*/
 );
 
+#define INCLUDE_LEGACY_REGION_DEFINES
+#ifdef INCLUDE_LEGACY_REGION_DEFINES
+
+#define REGION_NIL				RegionNil
+#define REGION_NAR				RegionNar
+#define REGION_NUM_RECTS			RegionNumRects
+#define REGION_SIZE				RegionSize
+#define REGION_RECTS				RegionRects
+#define REGION_BOXPTR				RegionBoxptr
+#define REGION_BOX				RegionBox
+#define REGION_TOP				RegionTop
+#define REGION_END				RegionEnd
+#define REGION_SZOF				RegionSizeof
+#define BITMAP_TO_REGION			BitmapToRegion
+#define REGION_CREATE(pScreen, r, s)		RegionCreate(r,s)
+#define REGION_COPY(pScreen, d, r)		RegionCopy(d, r)
+#define REGION_DESTROY(pScreen, r)		RegionDestroy(r)
+#define REGION_INTERSECT(pScreen, res, r1, r2)	RegionIntersect(res, r1, r2)
+#define REGION_UNION(pScreen, res, r1, r2)	RegionUnion(res, r1, r2)
+#define REGION_SUBTRACT(pScreen, res, r1, r2)	RegionSubtract(res, r1, r2)
+#define REGION_INVERSE(pScreen, n, r, b)	RegionInverse(n, r, b)
+#define REGION_TRANSLATE(pScreen, r, x, y)	RegionTranslate(r, x, y)
+#define RECT_IN_REGION(pScreen, r, b) 		RegionContainsRect(r, b)
+#define POINT_IN_REGION(pScreen, r, x, y, b) 	RegionContainsPoint(r, x, y, b)
+#define REGION_EQUAL(pScreen, r1, r2)		RegionEqual(r1, r2)
+#define REGION_APPEND(pScreen, d, r)		RegionAppend(d, r)
+#define REGION_VALIDATE(pScreen, r, o)		RegionValidate(r, o)
+#define RECTS_TO_REGION(pScreen, n, r, c)	RegionFromRects(n, r, c)
+#define REGION_BREAK(pScreen, r)		RegionBreak(r)
+#define REGION_INIT(pScreen, r, b, s)		RegionInit(r, b, s)
+#define REGION_UNINIT(pScreen, r)		RegionUninit(r)
+#define REGION_RESET(pScreen, r, b)		RegionReset(r, b)
+#define REGION_NOTEMPTY(pScreen, r)		RegionNotEmpty(r)
+#define REGION_BROKEN(pScreen, r)		RegionBroken(r)
+#define REGION_EMPTY(pScreen, r)		RegionEmpty(r)
+#define REGION_EXTENTS(pScreen, r)		RegionExtents(r)
+#define REGION_NULL(pScreen, r)			RegionNull(r)
+
+#endif /* INCLUDE_LEGACY_REGION_DEFINES */
 #endif /* REGIONSTRUCT_H */
commit 965cade6ee7c226f850e806cb2e910793d1536f9
Author: Keith Packard <keithp at keithp.com>
Date:   Fri May 21 12:18:22 2010 -0700

    Change region implementation from macros to inline functions.
    
    This makes all of the previous macros into inline functions and also
    turns all of the direct calls to pixman region code into inline
    functions as well.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 670cf50..c625438 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -386,7 +386,7 @@ static void XineramaInitData(ScreenPtr pScreen)
 {
     int i, w, h;
 
-    RegionNull(&PanoramiXScreenRegion)
+    RegionNull(&PanoramiXScreenRegion);
     for (i = 0; i < PanoramiXNumScreens; i++) {
 	BoxRec TheBox;
 	RegionRec ScreenRegion;
diff --git a/dix/region.c b/dix/region.c
index 2e8dde5..911fe16 100644
--- a/dix/region.c
+++ b/dix/region.c
@@ -275,12 +275,6 @@ RegionPrint(RegionPtr rgn)
     ErrorF("[mi] \n");
 }
 
-Bool
-RegionEqual(RegionPtr reg1, RegionPtr reg2)
-{
-    return pixman_region_equal (reg1, reg2);
-}
-
 #ifdef DEBUG
 Bool
 RegionIsValid(RegionPtr reg)
@@ -376,12 +370,6 @@ RegionRectAlloc(RegionPtr pRgn, int n)
     return TRUE;
 }
 
-Bool
-RegionCopy(RegionPtr dst, RegionPtr src)
-{
-    return pixman_region_copy (dst, src);
-}
-
 /*======================================================================
  *	    Generic Region Operator
  *====================================================================*/
@@ -800,8 +788,8 @@ RegionOp(
  *-----------------------------------------------------------------------
  * RegionSetExtents --
  *	Reset the extents of a region to what they should be. Called by
- *	RegionSubtract and RegionIntersect as they can't figure it out along the
- *	way or do so easily, as RegionUnion can.
+ *	Subtract and Intersect as they can't figure it out along the
+ *	way or do so easily, as Union can.
  *
  * Results:
  *	None.
@@ -869,15 +857,6 @@ RegionSetExtents (RegionPtr pReg)
  *-----------------------------------------------------------------------
  */
 /*ARGSUSED*/
-Bool
-RegionIntersect(
-    RegionPtr	newReg,     /* destination Region */
-    RegionPtr	reg1,
-    RegionPtr	reg2        /* source regions     */
-    )
-{
-    return pixman_region_intersect (newReg, reg1, reg2);
-}
 
 #define MERGERECT(r)						\
 {								\
@@ -973,16 +952,6 @@ RegionUnionO (
     return TRUE;
 }
 
-Bool
-RegionUnion(
-    RegionPtr	newReg,          /* destination Region */
-    RegionPtr	reg1,
-    RegionPtr	reg2             /* source regions     */
-    )
-{
-    return pixman_region_union (newReg, reg1, reg2);
-}
-
 /*======================================================================
  *	    Batch Rectangle Union
  *====================================================================*/
@@ -1182,7 +1151,7 @@ QuickSortRects(
  *		or a coalescing into 1 box (ala Menus).
  *
  *	Step 3. Merge the separate regions down to a single region by calling
- *		RegionUnion.  Maximize the work each RegionUnion call does by using
+ *		Union.  Maximize the work each Union call does by using
  *		a binary merge.
  *
  *-----------------------------------------------------------------------
@@ -1456,102 +1425,6 @@ RegionFromRects(int nrects, xRectangle *prect, int ctype)
     return pRgn;
 }
 
-/*======================================================================
- * 	    	  Region Subtraction
- *====================================================================*/
-
-
-/*-
- *-----------------------------------------------------------------------
- * RegionSubtractO --
- *	Overlapping band subtraction. x1 is the left-most point not yet
- *	checked.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *	pReg may have rectangles added to it.
- *
- *-----------------------------------------------------------------------
- */
-/*ARGSUSED*/
-
-/*-
- *-----------------------------------------------------------------------
- * RegionSubtract --
- *	Subtract regS from regM and leave the result in regD.
- *	S stands for subtrahend, M for minuend and D for difference.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *	regD is overwritten.
- *
- *-----------------------------------------------------------------------
- */
-Bool
-RegionSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
-{
-    return pixman_region_subtract (regD, regM, regS);
-}
-
-/*======================================================================
- *	    Region Inversion
- *====================================================================*/
-
-/*-
- *-----------------------------------------------------------------------
- * RegionInverse --
- *	Take a region and a box and return a region that is everything
- *	in the box but not in the region. The careful reader will note
- *	that this is the same as subtracting the region from the box...
- *
- * Results:
- *	TRUE.
- *
- * Side Effects:
- *	newReg is overwritten.
- *
- *-----------------------------------------------------------------------
- */
-Bool
-RegionInverse(
-    RegionPtr	  newReg,       /* Destination region */
-    RegionPtr	  reg1,         /* Region to invert */
-    BoxPtr	  invRect	/* Bounding box for inversion */
-    )
-{
-    return pixman_region_inverse (newReg, reg1, invRect);
-}
-int
-RegionContainsRect(RegionPtr region, BoxPtr prect)
-{
-    return pixman_region_contains_rectangle (region, prect);
-}
-
-/* TranslateRegion(pReg, x, y)
-   translates in place
-*/
-
-void
-RegionTranslate(RegionPtr pReg, int x, int y)
-{
-    pixman_region_translate (pReg, x, y);
-}
-
-Bool
-RegionContainsPoint(
-    RegionPtr pReg,
-    int x,
-    int y,
-    BoxPtr box      /* "return" value */
-    )
-{
-    return pixman_region_contains_point (pReg, x, y, box);
-}
-
 #define ExchangeSpans(a, b)				    \
 {							    \
     DDXPointRec	tpt;				    	    \
diff --git a/include/regionstr.h b/include/regionstr.h
index c6dd162..8bc902a 100644
--- a/include/regionstr.h
+++ b/include/regionstr.h
@@ -69,131 +69,112 @@ typedef struct pixman_region16_data RegDataRec, *RegDataPtr;
 extern _X_EXPORT BoxRec RegionEmptyBox;
 extern _X_EXPORT RegDataRec RegionEmptyData;
 extern _X_EXPORT RegDataRec RegionBrokenData;
+static inline Bool RegionNil(RegionPtr reg) {
+    return ((reg)->data && !(reg)->data->numRects);
+}
 
-#define RegionNil(reg) ((reg)->data && !(reg)->data->numRects)
 /* not a region */
-#define RegionNar(reg)	((reg)->data == &RegionBrokenData)
-#define RegionNumRects(reg) ((reg)->data ? (reg)->data->numRects : 1)
-#define RegionSize(reg) ((reg)->data ? (reg)->data->size : 0)
-#define RegionRects(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \
-			               : &(reg)->extents)
-#define RegionBoxptr(reg) ((BoxPtr)((reg)->data + 1))
-#define RegionBox(reg,i) (&RegionBoxptr(reg)[i])
-#define RegionTop(reg) RegionBox(reg, (reg)->data->numRects)
-#define RegionEnd(reg) RegionBox(reg, (reg)->data->numRects - 1)
-#define RegionSizeof(n) (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)))
-
-#define RegionCreate(_rect, _size) \
-    RegionCreate(_rect, _size)
-
-#define RegionCopy(dst, src) \
-    RegionCopy(dst, src)
-
-#define RegionDestroy(_pReg) \
-    RegionDestroy(_pReg)
-
-#define RegionIntersect(newReg, reg1, reg2) \
-    RegionIntersect(newReg, reg1, reg2)
-
-#define RegionUnion(newReg, reg1, reg2) \
-    RegionUnion(newReg, reg1, reg2)
-
-#define RegionSubtract(newReg, reg1, reg2) \
-    RegionSubtract(newReg, reg1, reg2)
-
-#define RegionInverse(newReg, reg1, invRect) \
-    RegionInverse(newReg, reg1, invRect)
-
-#define RegionTranslate(_pReg, _x, _y) \
-    RegionTranslate(_pReg, _x, _y)
-
-#define RegionContainsRect(_pReg, prect) \
-    RegionContainsRect(_pReg, prect)
-
-#define RegionContainsPoint(_pReg, _x, _y, prect) \
-    RegionContainsPoint(_pReg, _x, _y, prect)
-
-#define RegionAppend(dstrgn, rgn) \
-    RegionAppend(dstrgn, rgn)
-
-#define RegionValidate(badreg, pOverlap) \
-    RegionValidate(badreg, pOverlap)
-
-#define BitmapToRegion(_pScreen, pPix) \
-    (*(_pScreen)->BitmapToRegion)(pPix) /* no mi version?! */
-
-#define RegionFromRects(nrects, prect, ctype) \
-    RegionFromRects(nrects, prect, ctype)
-
-#define RegionEqual(_pReg1, _pReg2) \
-    RegionEqual(_pReg1, _pReg2)
-
-#define RegionBreak(_pReg) \
-    RegionBreak(_pReg)
-
-#define RegionInit(_pReg, _rect, _size) \
-{ \
-    if ((_rect) != NULL)				\
-    { \
-        (_pReg)->extents = *(_rect); \
-        (_pReg)->data = (RegDataPtr)NULL; \
-    } \
-    else \
-    { \
-        (_pReg)->extents = RegionEmptyBox; \
-        if (((_size) > 1) && ((_pReg)->data = \
-                             (RegDataPtr)malloc(RegionSizeof(_size)))) \
-        { \
-            (_pReg)->data->size = (_size); \
-            (_pReg)->data->numRects = 0; \
-        } \
-        else \
-            (_pReg)->data = &RegionEmptyData; \
-    } \
- }
-
-
-#define RegionUninit(_pReg) \
-{ \
-    if ((_pReg)->data && (_pReg)->data->size) { \
-	free((_pReg)->data); \
-	(_pReg)->data = NULL; \
-    } \
+
+static inline Bool RegionNar(RegionPtr reg) {
+    return ((reg)->data == &RegionBrokenData);
+}
+
+static inline int RegionNumRects(RegionPtr reg) {
+    return ((reg)->data ? (reg)->data->numRects : 1);
+}
+
+static inline int RegionSize(RegionPtr reg) {
+    return ((reg)->data ? (reg)->data->size : 0);
 }
 
-#define RegionReset(_pReg, _pBox) \
-{ \
-    (_pReg)->extents = *(_pBox); \
-    RegionUninit(_pReg); \
-    (_pReg)->data = (RegDataPtr)NULL; \
+static inline BoxPtr RegionRects(RegionPtr reg) {
+    return ((reg)->data ? (BoxPtr)((reg)->data + 1) : &(reg)->extents);
 }
 
-#define RegionNotEmpty(_pReg) \
-    !RegionNil(_pReg)
+static inline BoxPtr RegionBoxptr(RegionPtr reg) {
+    return ((BoxPtr)((reg)->data + 1));
+}
 
-#define RegionBroken(_pReg) \
-    RegionNar(_pReg)
+static inline BoxPtr RegionBox(RegionPtr reg, int i) {
+    return (&RegionBoxptr(reg)[i]);
+}
 
-#define RegionEmpty(_pReg) \
-{ \
-    RegionUninit(_pReg); \
-    (_pReg)->extents.x2 = (_pReg)->extents.x1; \
-    (_pReg)->extents.y2 = (_pReg)->extents.y1; \
-    (_pReg)->data = &RegionEmptyData; \
+static inline BoxPtr RegionTop(RegionPtr reg) {
+    return RegionBox(reg, (reg)->data->numRects);
 }
 
-#define RegionExtents(_pReg) \
-    (&(_pReg)->extents)
+static inline BoxPtr RegionEnd(RegionPtr reg) {
+    return RegionBox(reg, (reg)->data->numRects - 1);
+}
 
-#define RegionNull(_pReg) \
-{ \
-    (_pReg)->extents = RegionEmptyBox; \
-    (_pReg)->data = &RegionEmptyData; \
+static inline size_t RegionSizeof(int n) {
+    return (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)));
 }
 
-/* moved from mi.h */
+static inline void RegionInit(RegionPtr _pReg, BoxPtr _rect, int _size)
+{
+    if ((_rect) != NULL)
+    {
+        (_pReg)->extents = *(_rect);
+        (_pReg)->data = (RegDataPtr)NULL;
+    }
+    else
+    {
+        (_pReg)->extents = RegionEmptyBox;
+        if (((_size) > 1) && ((_pReg)->data =
+			      (RegDataPtr)malloc(RegionSizeof(_size))))
+        {
+            (_pReg)->data->size = (_size);
+            (_pReg)->data->numRects = 0;
+        }
+        else
+            (_pReg)->data = &RegionEmptyData;
+    }
+}
 
-extern _X_EXPORT void InitRegions (void);
+static inline void RegionUninit(RegionPtr _pReg)
+{
+    if ((_pReg)->data && (_pReg)->data->size) {
+	free((_pReg)->data);
+	(_pReg)->data = NULL;
+    }
+}
+
+static inline void RegionReset(RegionPtr _pReg, BoxPtr _pBox)
+{
+    (_pReg)->extents = *(_pBox);
+    RegionUninit(_pReg);
+    (_pReg)->data = (RegDataPtr)NULL;
+}
+
+static inline Bool RegionNotEmpty(RegionPtr _pReg) {
+    return !RegionNil(_pReg);
+}
+
+static inline Bool RegionBroken(RegionPtr _pReg) {
+    return RegionNar(_pReg);
+}
+
+static inline void RegionEmpty(RegionPtr _pReg)
+{
+    RegionUninit(_pReg);
+    (_pReg)->extents.x2 = (_pReg)->extents.x1;
+    (_pReg)->extents.y2 = (_pReg)->extents.y1;
+    (_pReg)->data = &RegionEmptyData;
+}
+
+static inline BoxPtr RegionExtents(RegionPtr _pReg)
+{
+    return (&(_pReg)->extents);
+}
+
+static inline void RegionNull(RegionPtr _pReg)
+{
+    (_pReg)->extents = RegionEmptyBox;
+    (_pReg)->data = &RegionEmptyData;
+}
+
+extern _X_EXPORT void InitRegions(void);
 
 extern _X_EXPORT RegionPtr RegionCreate(
     BoxPtr /*rect*/,
@@ -202,19 +183,31 @@ extern _X_EXPORT RegionPtr RegionCreate(
 extern _X_EXPORT void RegionDestroy(
     RegionPtr /*pReg*/);
 
-extern _X_EXPORT Bool RegionCopy(
-    RegionPtr /*dst*/,
-    RegionPtr /*src*/);
+static inline Bool
+RegionCopy(RegionPtr dst, RegionPtr src)
+{
+    return pixman_region_copy (dst, src);
+}
 
-extern _X_EXPORT Bool RegionIntersect(
-    RegionPtr /*newReg*/,
-    RegionPtr /*reg1*/,
-    RegionPtr /*reg2*/);
+static inline Bool
+RegionIntersect(
+    RegionPtr	newReg,     /* destination Region */
+    RegionPtr	reg1,
+    RegionPtr	reg2        /* source regions     */
+    )
+{
+    return pixman_region_intersect (newReg, reg1, reg2);
+}
 
-extern _X_EXPORT Bool RegionUnion(
-    RegionPtr /*newReg*/,
-    RegionPtr /*reg1*/,
-    RegionPtr /*reg2*/);
+static inline Bool
+RegionUnion(
+    RegionPtr	newReg,          /* destination Region */
+    RegionPtr	reg1,
+    RegionPtr	reg2             /* source regions     */
+    )
+{
+    return pixman_region_union (newReg, reg1, reg2);
+}
 
 extern _X_EXPORT Bool RegionAppend(
     RegionPtr /*dstrgn*/,
@@ -229,37 +222,87 @@ extern _X_EXPORT RegionPtr RegionFromRects(
     xRectanglePtr /*prect*/,
     int /*ctype*/);
 
-extern _X_EXPORT Bool RegionSubtract(
-    RegionPtr /*regD*/,
-    RegionPtr /*regM*/,
-    RegionPtr /*regS*/);
+/*-
+ *-----------------------------------------------------------------------
+ * Subtract --
+ *	Subtract regS from regM and leave the result in regD.
+ *	S stands for subtrahend, M for minuend and D for difference.
+ *
+ * Results:
+ *	TRUE if successful.
+ *
+ * Side Effects:
+ *	regD is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+static inline Bool
+RegionSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
+{
+    return pixman_region_subtract (regD, regM, regS);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * Inverse --
+ *	Take a region and a box and return a region that is everything
+ *	in the box but not in the region. The careful reader will note
+ *	that this is the same as subtracting the region from the box...
+ *
+ * Results:
+ *	TRUE.
+ *
+ * Side Effects:
+ *	newReg is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
 
-extern _X_EXPORT Bool RegionInverse(
-    RegionPtr /*newReg*/,
-    RegionPtr /*reg1*/,
-    BoxPtr /*invRect*/);
+static inline Bool
+RegionInverse(
+    RegionPtr	  newReg,       /* Destination region */
+    RegionPtr	  reg1,         /* Region to invert */
+    BoxPtr	  invRect	/* Bounding box for inversion */
+    )
+{
+    return pixman_region_inverse (newReg, reg1, invRect);
+}
 
-extern _X_EXPORT int RegionContainsRect(
-    RegionPtr /*region*/,
-    BoxPtr /*prect*/);
+static inline int
+RegionContainsRect(RegionPtr region, BoxPtr prect)
+{
+    return pixman_region_contains_rectangle (region, prect);
+}
 
-extern _X_EXPORT void RegionTranslate(
-    RegionPtr /*pReg*/,
-    int /*x*/,
-    int /*y*/);
+/* TranslateRegion(pReg, x, y)
+   translates in place
+*/
+
+static inline void
+RegionTranslate(RegionPtr pReg, int x, int y)
+{
+    pixman_region_translate (pReg, x, y);
+}
 
 extern _X_EXPORT Bool RegionBreak(
     RegionPtr /*pReg*/);
 
-extern _X_EXPORT Bool RegionContainsPoint(
-    RegionPtr /*pReg*/,
-    int /*x*/,
-    int /*y*/,
-    BoxPtr /*box*/);
+static inline Bool
+RegionContainsPoint(
+    RegionPtr pReg,
+    int x,
+    int y,
+    BoxPtr box      /* "return" value */
+    )
+{
+    return pixman_region_contains_point (pReg, x, y, box);
+}
 
-extern _X_EXPORT Bool RegionEqual(
-    RegionPtr /*pReg1*/,
-    RegionPtr /*pReg2*/);
+static inline Bool
+RegionEqual(RegionPtr reg1, RegionPtr reg2)
+{
+    return pixman_region_equal (reg1, reg2);
+}
 
 extern _X_EXPORT Bool RegionRectAlloc(
     RegionPtr /*pRgn*/,
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 361c484..e36b15f 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -603,6 +603,10 @@ typedef struct _Screen {
     DeviceCursorCleanupProcPtr    DeviceCursorCleanup;
 } ScreenRec;
 
+static inline RegionPtr BitmapToRegion(ScreenPtr _pScreen, PixmapPtr pPix) {
+    return (*(_pScreen)->BitmapToRegion)(pPix); /* no mi version?! */
+}
+
 typedef struct _ScreenInfo {
     int		imageByteOrder;
     int		bitmapScanlineUnit;
commit 2dc138922b7588515d5f2447e4b9dcdc0bef15e0
Author: Keith Packard <keithp at keithp.com>
Date:   Fri May 21 15:05:48 2010 -0700

    Rename region macros to eliminate screen argument
    
    This is a combination of a huge mechanical patch and a few small
    fixups required to finish the job. They were reviewed separately, but
    because the server does not build without both pieces, I've merged
    them together at this time.
    
    The mechanical changes were performed by running the included
    'fix-region' script over the whole tree:
    
    $ git ls-files | grep -v '^fix-' | xargs ./fix-region
    
    And then, the white space errors in the resulting patch were fixed
    using the provided fix-patch-whitespace script.
    
    $ sh ./fix-patch-whitespace
    
    Thanks to Jamey Sharp for the mighty fine sed-generating sed script.
    
    The hand-done changes involve removing functions from dix/region.c
    that duplicate inline functions in include/regionstr.h, along with
    their declarations in regionstr.h, mi.h and mispans.h.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 14e06e1..670cf50 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -152,7 +152,7 @@ XineramaCloseScreen (int i, ScreenPtr pScreen)
     pScreen->CreateGC = pScreenPriv->CreateGC;
 
     if (pScreen->myNum == 0)
-	REGION_UNINIT(pScreen, &PanoramiXScreenRegion);
+	RegionUninit(&PanoramiXScreenRegion);
 
     free((pointer) pScreenPriv);
 
@@ -386,7 +386,7 @@ static void XineramaInitData(ScreenPtr pScreen)
 {
     int i, w, h;
 
-    REGION_NULL(pScreen, &PanoramiXScreenRegion)
+    RegionNull(&PanoramiXScreenRegion)
     for (i = 0; i < PanoramiXNumScreens; i++) {
 	BoxRec TheBox;
 	RegionRec ScreenRegion;
@@ -398,10 +398,10 @@ static void XineramaInitData(ScreenPtr pScreen)
 	TheBox.y1 = pScreen->y;
 	TheBox.y2 = TheBox.y1 + pScreen->height;
 
-	REGION_INIT(pScreen, &ScreenRegion, &TheBox, 1);
-	REGION_UNION(pScreen, &PanoramiXScreenRegion, &PanoramiXScreenRegion,
+	RegionInit(&ScreenRegion, &TheBox, 1);
+	RegionUnion(&PanoramiXScreenRegion, &PanoramiXScreenRegion,
 		     &ScreenRegion);
-	REGION_UNINIT(pScreen, &ScreenRegion);
+	RegionUninit(&ScreenRegion);
     }
 
     PanoramiXPixWidth = screenInfo.screens[0]->x + screenInfo.screens[0]->width;
@@ -421,7 +421,7 @@ static void XineramaInitData(ScreenPtr pScreen)
 
 void XineramaReinitData(ScreenPtr pScreen)
 {
-    REGION_UNINIT(pScreen, &PanoramiXScreenRegion);
+    RegionUninit(&PanoramiXScreenRegion);
     XineramaInitData(pScreen);
 }
 
@@ -1153,8 +1153,8 @@ XineramaGetImageData(
     SrcBox.x2 = SrcBox.x1 + width;
     SrcBox.y2 = SrcBox.y1 + height;
     
-    REGION_INIT(pScreen, &SrcRegion, &SrcBox, 1);
-    REGION_NULL(pScreen, &GrabRegion);
+    RegionInit(&SrcRegion, &SrcBox, 1);
+    RegionNull(&GrabRegion);
 
     depth = (format == XYPixmap) ? 1 : pDraw->depth;
 
@@ -1169,11 +1169,11 @@ XineramaGetImageData(
 	TheBox.y1 = pScreen->y;
 	TheBox.y2 = TheBox.y1 + pScreen->height;
 
-	REGION_INIT(pScreen, &ScreenRegion, &TheBox, 1);
-	inOut = RECT_IN_REGION(pScreen, &ScreenRegion, &SrcBox);
+	RegionInit(&ScreenRegion, &TheBox, 1);
+	inOut = RegionContainsRect(&ScreenRegion, &SrcBox);
 	if(inOut == rgnPART)
-	    REGION_INTERSECT(pScreen, &GrabRegion, &SrcRegion, &ScreenRegion);
-	REGION_UNINIT(pScreen, &ScreenRegion);
+	    RegionIntersect(&GrabRegion, &SrcRegion, &ScreenRegion);
+	RegionUninit(&ScreenRegion);
 
 	if(inOut == rgnIN) {	   
 	    (*pScreen->GetImage)(pDraw,
@@ -1184,10 +1184,10 @@ XineramaGetImageData(
 	} else if (inOut == rgnOUT)
 	    continue;
 
-	nbox = REGION_NUM_RECTS(&GrabRegion);
+	nbox = RegionNumRects(&GrabRegion);
 
 	if(nbox) {
-	    pbox = REGION_RECTS(&GrabRegion);
+	    pbox = RegionRects(&GrabRegion);
 
 	    while(nbox--) {
 		w = pbox->x2 - pbox->x1;
@@ -1264,8 +1264,8 @@ XineramaGetImageData(
 		pbox++;
 	    }
 
-	    REGION_SUBTRACT(pScreen, &SrcRegion, &SrcRegion, &GrabRegion);
-	    if(!REGION_NOTEMPTY(pScreen, &SrcRegion))
+	    RegionSubtract(&SrcRegion, &SrcRegion, &GrabRegion);
+	    if(!RegionNotEmpty(&SrcRegion))
 		break;
 	}
 	
@@ -1274,6 +1274,6 @@ XineramaGetImageData(
     if(ScratchMem)
 	free(ScratchMem);
 
-    REGION_UNINIT(pScreen, &SrcRegion);
-    REGION_UNINIT(pScreen, &GrabRegion);
+    RegionUninit(&SrcRegion);
+    RegionUninit(&GrabRegion);
 }
diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 5ccbe27..457e071 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -620,7 +620,7 @@ int PanoramiXTranslateCoords(ClientPtr client)
 		 * borderSize
 		 */
 		&& (!wBoundingShape(pWin) ||
-		    POINT_IN_REGION(pWin->drawable.pScreen, 
+		    RegionContainsPoint(
 					wBoundingShape(pWin), 
 					x - pWin->drawable.x, 
 					y - pWin->drawable.y, &box))
@@ -1087,7 +1087,7 @@ int PanoramiXCopyArea(ClientPtr client)
 	RegionRec totalReg;
 	int rc;
 
-	REGION_NULL(unusedScreen, &totalReg);
+	RegionNull(&totalReg);
 	FOR_NSCREENS_BACKWARD(j) {
 	    RegionPtr pRgn;
 	    stuff->dstDrawable = dst->info[j].id;
@@ -1124,11 +1124,11 @@ int PanoramiXCopyArea(ClientPtr client)
 				stuff->dstX, stuff->dstY);
 	    if(pGC->graphicsExposures && pRgn) {
 	       if(srcIsRoot) {
-		   REGION_TRANSLATE(unusedScreen, pRgn,
+		   RegionTranslate(pRgn,
 			    screenInfo.screens[j]->x, screenInfo.screens[j]->y);
 	       }
-	       REGION_APPEND(unusedScreen, &totalReg, pRgn);
-	       REGION_DESTROY(unusedScreen, pRgn);
+	       RegionAppend(&totalReg, pRgn);
+	       RegionDestroy(pRgn);
 	    }
 
 	    if(dstShared)
@@ -1138,10 +1138,10 @@ int PanoramiXCopyArea(ClientPtr client)
 	if(pGC->graphicsExposures) {
 	    ScreenPtr pScreen = pDst->pScreen;
 	    Bool overlap;
-	    REGION_VALIDATE(unusedScreen, &totalReg, &overlap);
+	    RegionValidate(&totalReg, &overlap);
 	    (*pScreen->SendGraphicsExpose)(
 		client, &totalReg, stuff->dstDrawable, X_CopyArea, 0);
-	    REGION_UNINIT(unusedScreen, &totalReg);
+	    RegionUninit(&totalReg);
 	}
     }
 
@@ -1193,7 +1193,7 @@ int PanoramiXCopyPlane(ClientPtr client)
     srcx = stuff->srcX; srcy = stuff->srcY;
     dstx = stuff->dstX; dsty = stuff->dstY;
  
-    REGION_NULL(unusedScreen, &totalReg);
+    RegionNull(&totalReg);
     FOR_NSCREENS_BACKWARD(j) {
 	RegionPtr pRgn;
 	stuff->dstDrawable = dst->info[j].id;
@@ -1233,8 +1233,8 @@ int PanoramiXCopyPlane(ClientPtr client)
 				stuff->width, stuff->height, 
 				stuff->dstX, stuff->dstY, stuff->bitPlane);
 	if(pGC->graphicsExposures && pRgn) {
-	    REGION_APPEND(unusedScreen, &totalReg, pRgn);
-	    REGION_DESTROY(unusedScreen, pRgn);
+	    RegionAppend(&totalReg, pRgn);
+	    RegionDestroy(pRgn);
 	}
 
 	if(dstShared)
@@ -1244,10 +1244,10 @@ int PanoramiXCopyPlane(ClientPtr client)
     if(pGC->graphicsExposures) {
 	ScreenPtr pScreen = pdstDraw->pScreen;
 	Bool overlap;
-	REGION_VALIDATE(unusedScreen, &totalReg, &overlap);
+	RegionValidate(&totalReg, &overlap);
 	(*pScreen->SendGraphicsExpose)(
 		client, &totalReg, stuff->dstDrawable, X_CopyPlane, 0);
-	REGION_UNINIT(unusedScreen, &totalReg);
+	RegionUninit(&totalReg);
     }
 
     return Success;
diff --git a/Xext/shape.c b/Xext/shape.c
index 86b0bc0..fb5b9a7 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -153,11 +153,11 @@ RegionOperate (
     ScreenPtr	pScreen = pWin->drawable.pScreen;
 
     if (srcRgn && (xoff || yoff))
-	REGION_TRANSLATE(pScreen, srcRgn, xoff, yoff);
+	RegionTranslate(srcRgn, xoff, yoff);
     if (!pWin->parent)
     {
 	if (srcRgn)
-	    REGION_DESTROY(pScreen, srcRgn);
+	    RegionDestroy(srcRgn);
 	return Success;
     }
 
@@ -168,7 +168,7 @@ RegionOperate (
      */
     if (srcRgn == NULL) {
       if (*destRgnp != NULL) {
-	REGION_DESTROY (pScreen, *destRgnp);
+	RegionDestroy(*destRgnp);
 	*destRgnp = 0;
 	/* go on to remove shape and generate ShapeNotify */
       }
@@ -187,17 +187,17 @@ RegionOperate (
     else switch (op) {
     case ShapeSet:
 	if (*destRgnp)
-	    REGION_DESTROY(pScreen, *destRgnp);
+	    RegionDestroy(*destRgnp);
 	*destRgnp = srcRgn;
 	srcRgn = 0;
 	break;
     case ShapeUnion:
 	if (*destRgnp)
-	    REGION_UNION(pScreen, *destRgnp, *destRgnp, srcRgn);
+	    RegionUnion(*destRgnp, *destRgnp, srcRgn);
 	break;
     case ShapeIntersect:
 	if (*destRgnp)
-	    REGION_INTERSECT(pScreen, *destRgnp, *destRgnp, srcRgn);
+	    RegionIntersect(*destRgnp, *destRgnp, srcRgn);
 	else {
 	    *destRgnp = srcRgn;
 	    srcRgn = 0;
@@ -206,20 +206,20 @@ RegionOperate (
     case ShapeSubtract:
 	if (!*destRgnp)
 	    *destRgnp = (*create)(pWin);
-	REGION_SUBTRACT(pScreen, *destRgnp, *destRgnp, srcRgn);
+	RegionSubtract(*destRgnp, *destRgnp, srcRgn);
 	break;
     case ShapeInvert:
 	if (!*destRgnp)
-	    *destRgnp = REGION_CREATE(pScreen, (BoxPtr) 0, 0);
+	    *destRgnp = RegionCreate((BoxPtr) 0, 0);
 	else
-	    REGION_SUBTRACT(pScreen, *destRgnp, srcRgn, *destRgnp);
+	    RegionSubtract(*destRgnp, srcRgn, *destRgnp);
 	break;
     default:
 	client->errorValue = op;
 	return BadValue;
     }
     if (srcRgn)
-	REGION_DESTROY(pScreen, srcRgn);
+	RegionDestroy(srcRgn);
     (*pScreen->SetShape) (pWin, kind);
     SendShapeNotify (pWin, kind);
     return Success;
@@ -234,7 +234,7 @@ CreateBoundingShape (WindowPtr pWin)
     extents.y1 = -wBorderWidth (pWin);
     extents.x2 = pWin->drawable.width + wBorderWidth (pWin);
     extents.y2 = pWin->drawable.height + wBorderWidth (pWin);
-    return REGION_CREATE(pWin->drawable.pScreen, &extents, 1);
+    return RegionCreate(&extents, 1);
 }
 
 RegionPtr
@@ -246,7 +246,7 @@ CreateClipShape (WindowPtr pWin)
     extents.y1 = 0;
     extents.x2 = pWin->drawable.width;
     extents.y2 = pWin->drawable.height;
-    return REGION_CREATE(pWin->drawable.pScreen, &extents, 1);
+    return RegionCreate(&extents, 1);
 }
 
 static int
@@ -323,7 +323,7 @@ ProcShapeRectangles (ClientPtr client)
     ctype = VerifyRectOrder(nrects, prects, (int)stuff->ordering);
     if (ctype < 0)
 	return BadMatch;
-    srcRgn = RECTS_TO_REGION(pScreen, nrects, prects, ctype);
+    srcRgn = RegionFromRects(nrects, prects, ctype);
 
     if (!pWin->optional)
 	MakeWindowOptional (pWin);
@@ -419,7 +419,7 @@ ProcShapeMask (ClientPtr client)
 	if (pPixmap->drawable.pScreen != pScreen ||
 	    pPixmap->drawable.depth != 1)
 	    return BadMatch;
-	srcRgn = BITMAP_TO_REGION(pScreen, pPixmap);
+	srcRgn = BitmapToRegion(pScreen, pPixmap);
 	if (!srcRgn)
 	    return BadAlloc;
     }
@@ -547,8 +547,8 @@ ProcShapeCombine (ClientPtr client)
     }
 
     if (srcRgn) {
-        tmp = REGION_CREATE(pScreen, (BoxPtr) 0, 0);
-        REGION_COPY(pScreen, tmp, srcRgn);
+        tmp = RegionCreate((BoxPtr) 0, 0);
+        RegionCopy(tmp, srcRgn);
         srcRgn = tmp;
     } else
 	srcRgn = (*createSrc) (pSrcWin);
@@ -641,7 +641,7 @@ ProcShapeOffset (ClientPtr client)
     pScreen = pWin->drawable.pScreen;
     if (srcRgn)
     {
-        REGION_TRANSLATE(pScreen, srcRgn, stuff->xOff, stuff->yOff);
+        RegionTranslate(srcRgn, stuff->xOff, stuff->yOff);
         (*pScreen->SetShape) (pWin, stuff->destKind);
     }
     SendShapeNotify (pWin, (int)stuff->destKind);
@@ -697,7 +697,7 @@ ProcShapeQueryExtents (ClientPtr client)
     rep.clipShaped = (wClipShape(pWin) != 0);
     if ((region = wBoundingShape(pWin))) {
      /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */
-	pExtents = REGION_EXTENTS(pWin->drawable.pScreen, region);
+	pExtents = RegionExtents(region);
 	extents = *pExtents;
     } else {
 	extents.x1 = -wBorderWidth (pWin);
@@ -711,7 +711,7 @@ ProcShapeQueryExtents (ClientPtr client)
     rep.heightBoundingShape = extents.y2 - extents.y1;
     if ((region = wClipShape(pWin))) {
      /* this is done in two steps because of a compiler bug on SunOS 4.1.3 */
-	pExtents = REGION_EXTENTS(pWin->drawable.pScreen, region);
+	pExtents = RegionExtents(region);
 	extents = *pExtents;
     } else {
 	extents.x1 = 0;
@@ -899,7 +899,7 @@ SendShapeNotify (WindowPtr pWin, int which)
     case ShapeBounding:
 	region = wBoundingShape(pWin);
 	if (region) {
-	    extents = *REGION_EXTENTS(pWin->drawable.pScreen, region);
+	    extents = *RegionExtents(region);
 	    shaped = xTrue;
 	} else {
 	    extents.x1 = -wBorderWidth (pWin);
@@ -912,7 +912,7 @@ SendShapeNotify (WindowPtr pWin, int which)
     case ShapeClip:
 	region = wClipShape(pWin);
 	if (region) {
-	    extents = *REGION_EXTENTS(pWin->drawable.pScreen, region);
+	    extents = *RegionExtents(region);
 	    shaped = xTrue;
 	} else {
 	    extents.x1 = 0;
@@ -925,7 +925,7 @@ SendShapeNotify (WindowPtr pWin, int which)
     case ShapeInput:
 	region = wInputShape(pWin);
 	if (region) {
-	    extents = *REGION_EXTENTS(pWin->drawable.pScreen, region);
+	    extents = *RegionExtents(region);
 	    shaped = xTrue;
 	} else {
 	    extents.x1 = -wBorderWidth (pWin);
@@ -1050,8 +1050,8 @@ ProcShapeGetRectangles (ClientPtr client)
 	}
     } else {
 	BoxPtr box;
-	nrects = REGION_NUM_RECTS(region);
-	box = REGION_RECTS(region);
+	nrects = RegionNumRects(region);
+	box = RegionRects(region);
 	rects = malloc(nrects * sizeof (xRectangle));
 	if (!rects && nrects)
 	    return BadAlloc;
diff --git a/Xext/xace.c b/Xext/xace.c
index 53f4b4d..07e3da5 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -255,12 +255,12 @@ XaceCensorImage(
     imageBox.y1 = y;
     imageBox.x2 = x + w;
     imageBox.y2 = y + h;
-    REGION_INIT(pScreen, &imageRegion, &imageBox, 1);
-    REGION_NULL(pScreen, &censorRegion);
+    RegionInit(&imageRegion, &imageBox, 1);
+    RegionNull(&censorRegion);
 
     /* censorRegion = imageRegion - visibleRegion */
-    REGION_SUBTRACT(pScreen, &censorRegion, &imageRegion, pVisibleRegion);
-    nRects = REGION_NUM_RECTS(&censorRegion);
+    RegionSubtract(&censorRegion, &imageRegion, pVisibleRegion);
+    nRects = RegionNumRects(&censorRegion);
     if (nRects > 0)
     { /* we have something to censor */
 	GCPtr pScratchGC = NULL;
@@ -280,7 +280,7 @@ XaceCensorImage(
 	    failed = TRUE;
 	    goto failSafe;
 	}
-	for (pBox = REGION_RECTS(&censorRegion), i = 0;
+	for (pBox = RegionRects(&censorRegion), i = 0;
 	     i < nRects;
 	     i++, pBox++)
 	{
@@ -330,8 +330,8 @@ XaceCensorImage(
 	if (pScratchGC) FreeScratchGC(pScratchGC);
 	if (pPix)       FreeScratchPixmapHeader(pPix);
     }
-    REGION_UNINIT(pScreen, &imageRegion);
-    REGION_UNINIT(pScreen, &censorRegion);
+    RegionUninit(&imageRegion);
+    RegionUninit(&censorRegion);
 } /* XaceCensorImage */
 
 /*
diff --git a/composite/compalloc.c b/composite/compalloc.c
index 7930ebe..d8ccc11 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -134,7 +134,7 @@ compRedirectWindow (ClientPtr pClient, WindowPtr pWin, int update)
 	    EnableMapUnmapEvents (pWin);
 	}
 
-	REGION_NULL (pScreen, &cw->borderClip);
+	RegionNull(&cw->borderClip);
 	cw->borderClipX = 0;
 	cw->borderClipY = 0;
 	cw->update = CompositeRedirectAutomatic;
@@ -227,7 +227,7 @@ compFreeClientWindow (WindowPtr pWin, XID id)
 	if (cw->damage)
 	    DamageDestroy (cw->damage);
 	
-	REGION_UNINIT (pScreen, &cw->borderClip);
+	RegionUninit(&cw->borderClip);
     
 	dixSetPrivate(&pWin->devPrivates, CompWindowPrivateKey, NULL);
 	free(cw);
@@ -599,7 +599,7 @@ compFreePixmap (WindowPtr pWin)
      * case correctly.  Unmap adds the window borderClip to the
      * parent exposed area; regions beyond the parent cause crashes
      */
-    REGION_COPY (pScreen, &pWin->borderClip, &cw->borderClip);
+    RegionCopy(&pWin->borderClip, &cw->borderClip);
     pRedirectPixmap = (*pScreen->GetWindowPixmap) (pWin);
     pParentPixmap = (*pScreen->GetWindowPixmap) (pWin->parent);
     pWin->redirectDraw = RedirectDrawNone;
diff --git a/composite/compext.c b/composite/compext.c
index ed43775..d37d52a 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -218,7 +218,7 @@ ProcCompositeCreateRegionFromBorderClip (ClientPtr client)
     pRegion = XFixesRegionCopy (pBorderClip);
     if (!pRegion)
 	return BadAlloc;
-    REGION_TRANSLATE (pScreen, pRegion, -pWin->drawable.x, -pWin->drawable.y);
+    RegionTranslate(pRegion, -pWin->drawable.x, -pWin->drawable.y);
     
     if (!AddResource (stuff->region, RegionResType, (pointer) pRegion))
 	return BadAlloc;
diff --git a/composite/compwindow.c b/composite/compwindow.c
index 0f3898c..7d877b1 100644
--- a/composite/compwindow.c
+++ b/composite/compwindow.c
@@ -98,10 +98,10 @@ compRepaintBorder (ClientPtr pClient, pointer closure)
     if (rc == Success) {
 	RegionRec exposed;
 
-	REGION_NULL(pScreen, &exposed);
-	REGION_SUBTRACT(pScreen, &exposed, &pWindow->borderClip, &pWindow->winSize);
+	RegionNull(&exposed);
+	RegionSubtract(&exposed, &pWindow->borderClip, &pWindow->winSize);
 	miPaintWindow(pWindow, &exposed, PW_BORDER);
-	REGION_UNINIT(pScreen, &exposed);
+	RegionUninit(&exposed);
     }
     return TRUE;
 }
@@ -283,7 +283,7 @@ compClipNotify (WindowPtr pWin, int dx, int dy)
 	if (cw->borderClipX != pWin->drawable.x ||
 	    cw->borderClipY != pWin->drawable.y)
 	{
-	    REGION_TRANSLATE (pScreen, &cw->borderClip,
+	    RegionTranslate(&cw->borderClip,
 			      pWin->drawable.x - cw->borderClipX,
 			      pWin->drawable.y - cw->borderClipY);
 	    cw->borderClipX = pWin->drawable.x;
@@ -404,14 +404,14 @@ compCopyWindow (WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 
 	    dx = ptOldOrg.x - pWin->drawable.x;
 	    dy = ptOldOrg.y - pWin->drawable.y;
-	    REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
+	    RegionTranslate(prgnSrc, -dx, -dy);
 
-	    REGION_NULL (pWin->drawable.pScreen, &rgnDst);
+	    RegionNull(&rgnDst);
 
-	    REGION_INTERSECT(pWin->drawable.pScreen, &rgnDst,
+	    RegionIntersect(&rgnDst,
 			     &pWin->borderClip, prgnSrc);
 
-	    REGION_TRANSLATE (pWin->drawable.pScreen, &rgnDst,
+	    RegionTranslate(&rgnDst,
 			      -pPixmap->screen_x, -pPixmap->screen_y);
 
 	    dx = dx + pPixmap->screen_x - cw->oldx;
@@ -419,8 +419,8 @@ compCopyWindow (WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 	    pGC = GetScratchGC (pPixmap->drawable.depth, pScreen);
 	    if (pGC)
 	    {
-		BoxPtr	pBox = REGION_RECTS (&rgnDst);
-		int	nBox = REGION_NUM_RECTS (&rgnDst);
+		BoxPtr	pBox = RegionRects (&rgnDst);
+		int	nBox = RegionNumRects (&rgnDst);
 
 		ValidateGC(&pPixmap->drawable, pGC);
 		while (nBox--)
@@ -448,16 +448,16 @@ compCopyWindow (WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     if (ptOldOrg.x != pWin->drawable.x || ptOldOrg.y != pWin->drawable.y)
     {
 	if (dx || dy)
-	    REGION_TRANSLATE (pScreen, prgnSrc, dx, dy);
+	    RegionTranslate(prgnSrc, dx, dy);
 	(*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc);
 	if (dx || dy)
-	    REGION_TRANSLATE (pScreen, prgnSrc, -dx, -dy);
+	    RegionTranslate(prgnSrc, -dx, -dy);
     }
     else
     {
 	ptOldOrg.x -= dx;
 	ptOldOrg.y -= dy;
-	REGION_TRANSLATE (prgnSrc, prgnSrc,
+	RegionTranslate(prgnSrc,
 			  pWin->drawable.x - ptOldOrg.x,
 			  pWin->drawable.y - ptOldOrg.y);
 	DamageRegionAppend(&pWin->drawable, prgnSrc);
@@ -525,26 +525,26 @@ compSetRedirectBorderClip (WindowPtr pWin, RegionPtr pRegion)
     CompWindowPtr   cw = GetCompWindow (pWin);
     RegionRec	    damage;
 
-    REGION_NULL (pScreen, &damage);
+    RegionNull(&damage);
     /*
      * Align old border clip with new border clip
      */
-    REGION_TRANSLATE (pScreen, &cw->borderClip,
+    RegionTranslate(&cw->borderClip,
 		      pWin->drawable.x - cw->borderClipX,
 		      pWin->drawable.y - cw->borderClipY);
     /*
      * Compute newly visible portion of window for repaint
      */
-    REGION_SUBTRACT (pScreen, &damage, pRegion, &cw->borderClip);
+    RegionSubtract(&damage, pRegion, &cw->borderClip);
     /*
      * Report that as damaged so it will be redrawn
      */
     DamageRegionAppend(&pWin->drawable, &damage);
-    REGION_UNINIT (pScreen, &damage);
+    RegionUninit(&damage);
     /*
      * Save the new border clip region
      */
-    REGION_COPY (pScreen, &cw->borderClip, pRegion);
+    RegionCopy(&cw->borderClip, pRegion);
     cw->borderClipX = pWin->drawable.x;
     cw->borderClipY = pWin->drawable.y;
 }
@@ -606,18 +606,18 @@ compWindowUpdateAutomatic (WindowPtr pWin)
     /*
      * First move the region from window to screen coordinates
      */
-    REGION_TRANSLATE (pScreen, pRegion,
+    RegionTranslate(pRegion,
 		      pWin->drawable.x, pWin->drawable.y);
 
     /*
      * Clip against the "real" border clip
      */
-    REGION_INTERSECT (pScreen, pRegion, pRegion, &cw->borderClip);
+    RegionIntersect(pRegion, pRegion, &cw->borderClip);
 
     /*
      * Now translate from screen to dest coordinates
      */
-    REGION_TRANSLATE (pScreen, pRegion,
+    RegionTranslate(pRegion,
 		      -pParent->drawable.x, -pParent->drawable.y);
 
     /*
diff --git a/damageext/damageext.c b/damageext/damageext.c
index e4eda5e..7717a40 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -94,10 +94,10 @@ DamageExtReport (DamagePtr pDamage, RegionPtr pRegion, void *closure)
     switch (pDamageExt->level) {
     case DamageReportRawRegion:
     case DamageReportDeltaRegion:
-	DamageExtNotify (pDamageExt, REGION_RECTS(pRegion), REGION_NUM_RECTS(pRegion));
+	DamageExtNotify (pDamageExt, RegionRects(pRegion), RegionNumRects(pRegion));
 	break;
     case DamageReportBoundingBox:
-	DamageExtNotify (pDamageExt, REGION_EXTENTS(prScreen, pRegion), 1);
+	DamageExtNotify (pDamageExt, RegionExtents(pRegion), 1);
 	break;
     case DamageReportNonEmpty:
 	DamageExtNotify (pDamageExt, NullBox, 0);
@@ -261,14 +261,14 @@ ProcDamageSubtract (ClientPtr client)
 	if (pRepair)
 	{
 	    if (pParts)
-		REGION_INTERSECT (prScreen, pParts, DamageRegion (pDamage), pRepair);
+		RegionIntersect(pParts, DamageRegion (pDamage), pRepair);
 	    if (DamageSubtract (pDamage, pRepair))
 		DamageExtReport (pDamage, DamageRegion (pDamage), (void *) pDamageExt);
 	}
 	else
 	{
 	    if (pParts)
-		REGION_COPY (prScreen, pParts, DamageRegion (pDamage));
+		RegionCopy(pParts, DamageRegion (pDamage));
 	    DamageEmpty (pDamage);
 	}
     }
@@ -293,9 +293,9 @@ ProcDamageAdd (ClientPtr client)
     /* The region is relative to the drawable origin, so translate it out to
      * screen coordinates like damage expects.
      */
-    REGION_TRANSLATE(pScreen, pRegion, pDrawable->x, pDrawable->y);
+    RegionTranslate(pRegion, pDrawable->x, pDrawable->y);
     DamageRegionAppend(pDrawable, pRegion);
-    REGION_TRANSLATE(pScreen, pRegion, -pDrawable->x, -pDrawable->y);
+    RegionTranslate(pRegion, -pDrawable->x, -pDrawable->y);
 
     return Success;
 }
diff --git a/dix/dispatch.c b/dix/dispatch.c
index c0efce5..859b93e 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1179,11 +1179,11 @@ ProcTranslateCoords(ClientPtr client)
 		 * borderSize
 		 */
 		&& (!wBoundingShape(pWin) ||
-		    POINT_IN_REGION(pWin->drawable.pScreen, 
+		    RegionContainsPoint(
 					&pWin->borderSize, x, y, &box))
 		
 		&& (!wInputShape(pWin) ||
-		    POINT_IN_REGION(pWin->drawable.pScreen,
+		    RegionContainsPoint(
 				    wInputShape(pWin),
 				    x - pWin->drawable.x,
 				    y - pWin->drawable.y, &box))
@@ -1661,7 +1661,7 @@ ProcCopyArea(ClientPtr client)
 	(*pDst->pScreen->SendGraphicsExpose)
  		(client, pRgn, stuff->dstDrawable, X_CopyArea, 0);
 	if (pRgn)
-	    REGION_DESTROY(pDst->pScreen, pRgn);
+	    RegionDestroy(pRgn);
     }
 
     return Success;
@@ -1711,7 +1711,7 @@ ProcCopyPlane(ClientPtr client)
 	(*pdstDraw->pScreen->SendGraphicsExpose)
  		(client, pRgn, stuff->dstDrawable, X_CopyPlane, 0);
 	if (pRgn)
-	    REGION_DESTROY(pdstDraw->pScreen, pRgn);
+	    RegionDestroy(pRgn);
     }
     return Success;
 }
@@ -2151,7 +2151,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
 	pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw);
 	if (pVisibleRegion)
 	{
-	    REGION_TRANSLATE(pDraw->pScreen, pVisibleRegion,
+	    RegionTranslate(pVisibleRegion,
 			     -pDraw->x, -pDraw->y);
 	}
     }
@@ -2240,7 +2240,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
 	}
     }
     if (pVisibleRegion)
-	REGION_DESTROY(pDraw->pScreen, pVisibleRegion);
+	RegionDestroy(pVisibleRegion);
     if (!im_return)
 	free(pBuf);
     return Success;
diff --git a/dix/events.c b/dix/events.c
index 502eebd..4c53b55 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -598,7 +598,7 @@ XineramaConfineCursorToWindow(DeviceIntPtr pDev,
 
     i = PanoramiXNumScreens - 1;
 
-    REGION_COPY(pSprite->screen, &pSprite->Reg1,
+    RegionCopy(&pSprite->Reg1,
             &pSprite->windows[i]->borderSize);
     off_x = screenInfo.screens[i]->x;
     off_y = screenInfo.screens[i]->y;
@@ -608,18 +608,18 @@ XineramaConfineCursorToWindow(DeviceIntPtr pDev,
         y = off_y - screenInfo.screens[i]->y;
 
         if(x || y)
-            REGION_TRANSLATE(pSprite->screen, &pSprite->Reg1, x, y);
+            RegionTranslate(&pSprite->Reg1, x, y);
 
-        REGION_UNION(pSprite->screen, &pSprite->Reg1, &pSprite->Reg1,
+        RegionUnion(&pSprite->Reg1, &pSprite->Reg1,
                 &pSprite->windows[i]->borderSize);
 
         off_x = screenInfo.screens[i]->x;
         off_y = screenInfo.screens[i]->y;
     }
 
-    pSprite->hotLimits = *REGION_EXTENTS(pSprite->screen, &pSprite->Reg1);
+    pSprite->hotLimits = *RegionExtents(&pSprite->Reg1);
 
-    if(REGION_NUM_RECTS(&pSprite->Reg1) > 1)
+    if(RegionNumRects(&pSprite->Reg1) > 1)
         pSprite->hotShape = &pSprite->Reg1;
     else
         pSprite->hotShape = NullRegion;
@@ -671,9 +671,9 @@ ConfineToShape(DeviceIntPtr pDev, RegionPtr shape, int *px, int *py)
     SpritePtr pSprite;
 
     pSprite = pDev->spriteInfo->sprite;
-    if (POINT_IN_REGION(pSprite->hot.pScreen, shape, x, y, &box))
+    if (RegionContainsPoint(shape, x, y, &box))
 	return;
-    box = *REGION_EXTENTS(pSprite->hot.pScreen, shape);
+    box = *RegionExtents(shape);
     /* this is rather crude */
     do {
 	x += incx;
@@ -695,7 +695,7 @@ ConfineToShape(DeviceIntPtr pDev, RegionPtr shape, int *px, int *py)
 	    else if (y < box.y1)
 		return; /* should never get here! */
 	}
-    } while (!POINT_IN_REGION(pSprite->hot.pScreen, shape, x, y, &box));
+    } while (!RegionContainsPoint(shape, x, y, &box));
     *px = x;
     *py = y;
 }
@@ -817,7 +817,7 @@ CheckVirtualMotion(
 
             i = PanoramiXNumScreens - 1;
 
-            REGION_COPY(pSprite->screen, &pSprite->Reg2,
+            RegionCopy(&pSprite->Reg2,
                     &pSprite->windows[i]->borderSize);
             off_x = screenInfo.screens[i]->x;
             off_y = screenInfo.screens[i]->y;
@@ -827,9 +827,9 @@ CheckVirtualMotion(
                 y = off_y - screenInfo.screens[i]->y;
 
                 if(x || y)
-                    REGION_TRANSLATE(pSprite->screen, &pSprite->Reg2, x, y);
+                    RegionTranslate(&pSprite->Reg2, x, y);
 
-                REGION_UNION(pSprite->screen, &pSprite->Reg2, &pSprite->Reg2,
+                RegionUnion(&pSprite->Reg2, &pSprite->Reg2,
                         &pSprite->windows[i]->borderSize);
 
                 off_x = screenInfo.screens[i]->x;
@@ -845,7 +845,7 @@ CheckVirtualMotion(
             }
         }
 
-	lims = *REGION_EXTENTS(pWin->drawable.pScreen, &pWin->borderSize);
+	lims = *RegionExtents(&pWin->borderSize);
 	if (pSprite->hot.x < lims.x1)
 	    pSprite->hot.x = lims.x1;
 	else if (pSprite->hot.x >= lims.x2)
@@ -858,7 +858,7 @@ CheckVirtualMotion(
 #ifdef PANORAMIX
         if (!noPanoramiXExtension)
         {
-            if (REGION_NUM_RECTS(&pSprite->Reg2) > 1)
+            if (RegionNumRects(&pSprite->Reg2) > 1)
                 reg = &pSprite->Reg2;
 
         } else
@@ -903,7 +903,7 @@ ConfineCursorToWindow(DeviceIntPtr pDev, WindowPtr pWin, Bool generateEvents, Bo
             return;
         }
 #endif
-	pSprite->hotLimits = *REGION_EXTENTS( pScreen, &pWin->borderSize);
+	pSprite->hotLimits = *RegionExtents(&pWin->borderSize);
 	pSprite->hotShape = wBoundingShape(pWin) ? &pWin->borderSize
 					       : NullRegion;
         CheckPhysLimits(pDev, pSprite->current, generateEvents,
@@ -2552,7 +2552,7 @@ PointInBorderSize(WindowPtr pWin, int x, int y)
 {
     BoxRec box;
 
-    if(POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderSize, x, y, &box))
+    if(RegionContainsPoint(&pWin->borderSize, x, y, &box))
 	return TRUE;
 
 #ifdef PANORAMIX
@@ -2562,7 +2562,7 @@ PointInBorderSize(WindowPtr pWin, int x, int y)
 	int i;
 
 	for(i = 1; i < PanoramiXNumScreens; i++) {
-	   if(POINT_IN_REGION(pSprite->screen,
+	   if(RegionContainsPoint(
 			&pSprite->windows[i]->borderSize,
 			x + screenInfo.screens[0]->x - screenInfo.screens[i]->x,
 			y + screenInfo.screens[0]->y - screenInfo.screens[i]->y,
@@ -2610,7 +2610,7 @@ XYToWindow(DeviceIntPtr pDev, int x, int y)
 	     */
 	    && (!wBoundingShape(pWin) || PointInBorderSize(pWin, x, y))
 	    && (!wInputShape(pWin) ||
-		POINT_IN_REGION(pWin->drawable.pScreen,
+		RegionContainsPoint(
 				wInputShape(pWin),
 				x - pWin->drawable.x,
 				y - pWin->drawable.y, &box))
@@ -2880,10 +2880,10 @@ void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff)
             pSprite->hotLimits.x2 -= xoff;
             pSprite->hotLimits.y2 -= yoff;
 
-            if (REGION_NOTEMPTY(pSprite->screen, &pSprite->Reg1))
-                REGION_TRANSLATE(pSprite->screen, &pSprite->Reg1,    xoff, yoff);
-            if (REGION_NOTEMPTY(pSprite->screen, &pSprite->Reg2))
-                REGION_TRANSLATE(pSprite->screen, &pSprite->Reg2,    xoff, yoff);
+            if (RegionNotEmpty(&pSprite->Reg1))
+                RegionTranslate(&pSprite->Reg1,    xoff, yoff);
+            if (RegionNotEmpty(&pSprite->Reg2))
+                RegionTranslate(&pSprite->Reg2,    xoff, yoff);
 
             /* FIXME: if we call ConfineCursorToWindow, must we do anything else? */
             if ((grab = pDev->deviceGrab.grab) && grab->confineTo) {
@@ -3018,8 +3018,8 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin)
         pSprite->hotShape = NullRegion;
         pSprite->screen = pScreen;
         /* gotta UNINIT these someplace */
-        REGION_NULL(pScreen, &pSprite->Reg1);
-        REGION_NULL(pScreen, &pSprite->Reg2);
+        RegionNull(&pSprite->Reg1);
+        RegionNull(&pSprite->Reg2);
     }
 #endif
 }
@@ -3157,7 +3157,7 @@ XineramaPointInWindowIsVisible(
 
     if (!pWin->realized) return FALSE;
 
-    if (POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box))
+    if (RegionContainsPoint(&pWin->borderClip, x, y, &box))
         return TRUE;
 
     if(!XineramaSetWindowPntrs(inputInfo.pointer, pWin)) return FALSE;
@@ -3171,9 +3171,9 @@ XineramaPointInWindowIsVisible(
 	x = xoff - screenInfo.screens[i]->x;
 	y = yoff - screenInfo.screens[i]->y;
 
-	if(POINT_IN_REGION(pScreen, &pWin->borderClip, x, y, &box)
+	if(RegionContainsPoint(&pWin->borderClip, x, y, &box)
 	   && (!wInputShape(pWin) ||
-	       POINT_IN_REGION(pWin->drawable.pScreen,
+	       RegionContainsPoint(
 			       wInputShape(pWin),
 			       x - pWin->drawable.x,
 			       y - pWin->drawable.y, &box)))
@@ -3367,7 +3367,7 @@ ProcWarpPointer(ClientPtr client)
 static Bool
 BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin)
 {
-     if(REGION_NOTEMPTY(pDev->spriteInfo->sprite->hotPhys.pScreen, &pWin->borderSize))
+     if(RegionNotEmpty(&pWin->borderSize))
 	return TRUE;
 
 #ifdef PANORAMIX
@@ -3375,7 +3375,7 @@ BorderSizeNotEmpty(DeviceIntPtr pDev, WindowPtr pWin)
 	int i;
 
 	for(i = 1; i < PanoramiXNumScreens; i++) {
-	    if(REGION_NOTEMPTY(pDev->spriteInfo->sprite->screen,
+	    if(RegionNotEmpty(
                         &pDev->spriteInfo->sprite->windows[i]->borderSize))
 		return TRUE;
 	}
diff --git a/dix/region.c b/dix/region.c
index a561601..2e8dde5 100644
--- a/dix/region.c
+++ b/dix/region.c
@@ -83,8 +83,6 @@ Equipment Corporation.
 #include <X11/Xprotostr.h>
 #include <X11/Xfuncproto.h>
 #include "gc.h"
-#include "mi.h"
-#include "mispans.h"
 #include <pixman.h>
 
 #undef assert
@@ -171,7 +169,7 @@ Equipment Corporation.
         ((r1)->y1 <= (r2)->y1) && \
         ((r1)->y2 >= (r2)->y2) )
 
-#define xallocData(n) malloc(REGION_SZOF(n))
+#define xallocData(n) malloc(RegionSizeof(n))
 #define xfreeData(reg) if ((reg)->data && (reg)->data->size) free((reg)->data)
 
 #define RECTALLOC_BAIL(pReg,n,bail) \
@@ -197,7 +195,7 @@ if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
     {									\
 	if (!RegionRectAlloc(pReg, 1))					\
 	    return FALSE;						\
-	pNextRect = REGION_TOP(pReg);					\
+	pNextRect = RegionTop(pReg);					\
     }									\
     ADDRECT(pNextRect,nx1,ny1,nx2,ny2);					\
     pReg->data->numRects++;						\
@@ -209,7 +207,7 @@ if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
 if (((numRects) < ((reg)->data->size >> 1)) && ((reg)->data->size > 50)) \
 {									 \
     RegDataPtr NewData;							 \
-    NewData = (RegDataPtr)realloc((reg)->data, REGION_SZOF(numRects));	 \
+    NewData = (RegDataPtr)realloc((reg)->data, RegionSizeof(numRects));	 \
     if (NewData)							 \
     {									 \
 	NewData->size = (numRects);					 \
@@ -265,9 +263,9 @@ RegionPrint(RegionPtr rgn)
     int i;
     BoxPtr rects;
 
-    num = REGION_NUM_RECTS(rgn);
-    size = REGION_SIZE(rgn);
-    rects = REGION_RECTS(rgn);
+    num = RegionNumRects(rgn);
+    size = RegionSize(rgn);
+    rects = RegionRects(rgn);
     ErrorF("[mi] num: %d size: %d\n", num, size);
     ErrorF("[mi] extents: %d %d %d %d\n",
 	   rgn->extents.x1, rgn->extents.y1, rgn->extents.x2, rgn->extents.y2);
@@ -292,7 +290,7 @@ RegionIsValid(RegionPtr reg)
     if ((reg->extents.x1 > reg->extents.x2) ||
 	(reg->extents.y1 > reg->extents.y2))
 	return FALSE;
-    numRects = REGION_NUM_RECTS(reg);
+    numRects = RegionNumRects(reg);
     if (!numRects)
 	return ((reg->extents.x1 == reg->extents.x2) &&
 		(reg->extents.y1 == reg->extents.y2) &&
@@ -304,7 +302,7 @@ RegionIsValid(RegionPtr reg)
 	BoxPtr pboxP, pboxN;
 	BoxRec box;
 	
-	pboxP = REGION_RECTS(reg);
+	pboxP = RegionRects(reg);
 	box = *pboxP;
 	box.y2 = pboxP[numRects-1].y2;
 	pboxN = pboxP + 1;
@@ -330,26 +328,6 @@ RegionIsValid(RegionPtr reg)
 }
 #endif /* DEBUG */
 
-/*****************************************************************
- *   RegionInit(pReg, rect, size)
- *     Outer region rect is statically allocated.
- *****************************************************************/
-
-void
-RegionInit(RegionPtr pReg, BoxPtr rect, int size)
-{
-    if (rect)
-	pixman_region_init_with_extents (pReg, rect);
-    else
-	pixman_region_init (pReg);
-}
-
-void
-RegionUninit(RegionPtr pReg)
-{
-    pixman_region_fini (pReg);
-}
-
 Bool
 RegionBreak (RegionPtr pReg)
 {
@@ -371,7 +349,7 @@ RegionRectAlloc(RegionPtr pRgn, int n)
 	if (!pRgn->data)
 	    return RegionBreak (pRgn);
 	pRgn->data->numRects = 1;
-	*REGION_BOXPTR(pRgn) = pRgn->extents;
+	*RegionBoxptr(pRgn) = pRgn->extents;
     }
     else if (!pRgn->data->size)
     {
@@ -389,7 +367,7 @@ RegionRectAlloc(RegionPtr pRgn, int n)
 		n = 250;
 	}
 	n += pRgn->data->numRects;
-	data = (RegDataPtr)realloc(pRgn->data, REGION_SZOF(n));
+	data = (RegDataPtr)realloc(pRgn->data, RegionSizeof(n));
 	if (!data)
 	    return RegionBreak (pRgn);
 	pRgn->data = data;
@@ -448,8 +426,8 @@ RegionCoalesce (
      * The bands may only be coalesced if the bottom of the previous
      * matches the top scanline of the current.
      */
-    pPrevBox = REGION_BOX(pReg, prevStart);
-    pCurBox = REGION_BOX(pReg, curStart);
+    pPrevBox = RegionBox(pReg, prevStart);
+    pCurBox = RegionBox(pReg, curStart);
     if (pPrevBox->y2 != pCurBox->y1) return curStart;
 
     /*
@@ -528,7 +506,7 @@ RegionAppendNonO (
 
     /* Make sure we have enough space for all rectangles to be added */
     RECTALLOC(pReg, newRects);
-    pNextRect = REGION_TOP(pReg);
+    pNextRect = RegionTop(pReg);
     pReg->data->numRects += newRects;
     do {
 	assert(r->x1 < r->x2);
@@ -553,7 +531,7 @@ RegionAppendNonO (
     int newRects;							\
     if ((newRects = rEnd - r)) {					\
 	RECTALLOC(newReg, newRects);					\
-	memmove((char *)REGION_TOP(newReg),(char *)r, 			\
+	memmove((char *)RegionTop(newReg),(char *)r, 			\
               newRects * sizeof(BoxRec));				\
 	newReg->data->numRects += newRects;				\
     }									\
@@ -634,7 +612,7 @@ RegionOp(
     /*
      * Break any region computed from a broken region
      */
-    if (REGION_NAR (reg1) || REGION_NAR(reg2))
+    if (RegionNar (reg1) || RegionNar(reg2))
 	return RegionBreak (newReg);
     
     /*
@@ -645,11 +623,11 @@ RegionOp(
      * another array of rectangles for it to use.
      */
 
-    r1 = REGION_RECTS(reg1);
-    newSize = REGION_NUM_RECTS(reg1);
+    r1 = RegionRects(reg1);
+    newSize = RegionNumRects(reg1);
     r1End = r1 + newSize;
-    numRects = REGION_NUM_RECTS(reg2);
-    r2 = REGION_RECTS(reg2);
+    numRects = RegionNumRects(reg2);
+    r2 = RegionRects(reg2);
     r2End = r2 + numRects;
     assert(r1 != r1End);
     assert(r2 != r2End);
@@ -806,7 +784,7 @@ RegionOp(
     }
     else if (numRects == 1)
     {
-	newReg->extents = *REGION_BOXPTR(newReg);
+	newReg->extents = *RegionBoxptr(newReg);
 	xfreeData(newReg);
 	newReg->data = NULL;
     }
@@ -847,8 +825,8 @@ RegionSetExtents (RegionPtr pReg)
 	return;
     }
 
-    pBox = REGION_BOXPTR(pReg);
-    pBoxEnd = REGION_END(pReg);
+    pBox = RegionBoxptr(pReg);
+    pBoxEnd = RegionEnd(pReg);
 
     /*
      * Since pBox is the first rectangle in the region, it must have the
@@ -953,7 +931,7 @@ RegionUnionO (
     assert (y1 < y2);
     assert(r1 != r1End && r2 != r2End);
 
-    pNextRect = REGION_TOP(pReg);
+    pNextRect = RegionTop(pReg);
 
     /* Start off current rectangle */
     if (r1->x1 < r2->x1)
@@ -1033,7 +1011,7 @@ RegionAppend(RegionPtr dstrgn, RegionPtr rgn)
     BoxPtr new, old;
     Bool prepend;
 
-    if (REGION_NAR(rgn))
+    if (RegionNar(rgn))
 	return RegionBreak (dstrgn);
     
     if (!rgn->data && (dstrgn->data == &RegionEmptyData))
@@ -1043,16 +1021,16 @@ RegionAppend(RegionPtr dstrgn, RegionPtr rgn)
 	return TRUE;
     }
 
-    numRects = REGION_NUM_RECTS(rgn);
+    numRects = RegionNumRects(rgn);
     if (!numRects)
 	return TRUE;
     prepend = FALSE;
     size = numRects;
-    dnumRects = REGION_NUM_RECTS(dstrgn);
+    dnumRects = RegionNumRects(dstrgn);
     if (!dnumRects && (size < 200))
 	size = 200; /* XXX pick numbers out of a hat */
     RECTALLOC(dstrgn, size);
-    old = REGION_RECTS(rgn);
+    old = RegionRects(rgn);
     if (!dnumRects)
 	dstrgn->extents = rgn->extents;
     else if (dstrgn->extents.x2 > dstrgn->extents.x1)
@@ -1060,7 +1038,7 @@ RegionAppend(RegionPtr dstrgn, RegionPtr rgn)
 	BoxPtr first, last;
 
 	first = old;
-	last = REGION_BOXPTR(dstrgn) + (dnumRects - 1);
+	last = RegionBoxptr(dstrgn) + (dnumRects - 1);
 	if ((first->y1 > last->y2) ||
 	    ((first->y1 == last->y1) && (first->y2 == last->y2) &&
 	     (first->x1 > last->x2)))
@@ -1073,7 +1051,7 @@ RegionAppend(RegionPtr dstrgn, RegionPtr rgn)
 	}
 	else
 	{
-	    first = REGION_BOXPTR(dstrgn);
+	    first = RegionBoxptr(dstrgn);
 	    last = old + (numRects - 1);
 	    if ((first->y1 > last->y2) ||
 		((first->y1 == last->y1) && (first->y2 == last->y2) &&
@@ -1092,16 +1070,16 @@ RegionAppend(RegionPtr dstrgn, RegionPtr rgn)
     }
     if (prepend)
     {
-	new = REGION_BOX(dstrgn, numRects);
+	new = RegionBox(dstrgn, numRects);
 	if (dnumRects == 1)
-	    *new = *REGION_BOXPTR(dstrgn);
+	    *new = *RegionBoxptr(dstrgn);
 	else
-	    memmove((char *)new,(char *)REGION_BOXPTR(dstrgn), 
+	    memmove((char *)new,(char *)RegionBoxptr(dstrgn),
 		  dnumRects * sizeof(BoxRec));
-	new = REGION_BOXPTR(dstrgn);
+	new = RegionBoxptr(dstrgn);
     }
     else
-	new = REGION_BOXPTR(dstrgn) + dnumRects;
+	new = RegionBoxptr(dstrgn) + dnumRects;
     if (numRects == 1)
 	*new = *old;
     else
@@ -1242,7 +1220,7 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap)
     numRects = badreg->data->numRects;
     if (!numRects)
     {
-	if (REGION_NAR(badreg))
+	if (RegionNar(badreg))
 	    return FALSE;
 	good(badreg);
 	return TRUE;
@@ -1263,7 +1241,7 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap)
     }
 
     /* Step 1: Sort the rects array into ascending (y1, x1) order */
-    QuickSortRects(REGION_BOXPTR(badreg), numRects);
+    QuickSortRects(RegionBoxptr(badreg), numRects);
 
     /* Step 2: Scatter the sorted array into the minimum number of regions */
 
@@ -1277,7 +1255,7 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap)
     ri[0].prevBand = 0;
     ri[0].curBand = 0;
     ri[0].reg = *badreg;
-    box = REGION_BOXPTR(&ri[0].reg);
+    box = RegionBoxptr(&ri[0].reg);
     ri[0].reg.extents = *box;
     ri[0].reg.data->numRects = 1;
 
@@ -1294,7 +1272,7 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap)
 	for (j = numRI, rit = ri; --j >= 0; rit++)
 	{
 	    reg = &rit->reg;
-	    riBox = REGION_END(reg);
+	    riBox = RegionEnd(reg);
 
 	    if (box->y1 == riBox->y1 && box->y2 == riBox->y2)
 	    {
@@ -1308,7 +1286,7 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap)
 		else
 		{
 		    RECTALLOC_BAIL(reg, 1, bail);
-		    *REGION_TOP(reg) = *box;
+		    *RegionTop(reg) = *box;
 		    reg->data->numRects++;
 		}
 		goto NextRect;   /* So sue me */
@@ -1321,7 +1299,7 @@ RegionValidate(RegionPtr badreg, Bool *pOverlap)
 		Coalesce(reg, rit->prevBand, rit->curBand);
 		rit->curBand = reg->data->numRects;
 		RECTALLOC_BAIL(reg, 1, bail);
-		*REGION_TOP(reg) = *box;
+		*RegionTop(reg) = *box;
 		reg->data->numRects++;
 		goto NextRect;
 	    }
@@ -1355,7 +1333,7 @@ NextRect: ;
     for (j = numRI, rit = ri; --j >= 0; rit++)
     {
 	reg = &rit->reg;
-	riBox = REGION_END(reg);
+	riBox = RegionEnd(reg);
 	reg->extents.y2 = riBox->y2;
 	if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2;
 	Coalesce(reg, rit->prevBand, rit->curBand);
@@ -1410,7 +1388,7 @@ RegionFromRects(int nrects, xRectangle *prect, int ctype)
     int			x1, y1, x2, y2;
 
     pRgn = RegionCreate(NullBox, 0);
-    if (REGION_NAR (pRgn))
+    if (RegionNar (pRgn))
 	return pRgn;
     if (!nrects)
 	return pRgn;
@@ -1563,12 +1541,6 @@ RegionTranslate(RegionPtr pReg, int x, int y)
     pixman_region_translate (pReg, x, y);
 }
 
-void
-RegionReset(RegionPtr pReg, BoxPtr pBox)
-{
-    pixman_region_reset (pReg, pBox);
-}
-
 Bool
 RegionContainsPoint(
     RegionPtr pReg,
@@ -1580,36 +1552,6 @@ RegionContainsPoint(
     return pixman_region_contains_point (pReg, x, y, box);
 }
 
-Bool
-RegionNotEmpty(RegionPtr pReg)
-{
-    return pixman_region_not_empty (pReg);
-}
-
-Bool
-RegionBroken(RegionPtr pReg)
-{
-    good(pReg);
-    return (REGION_NAR(pReg));
-}
-
-void
-RegionEmpty(RegionPtr pReg)
-{
-    good(pReg);
-    xfreeData(pReg);
-    pReg->extents.x2 = pReg->extents.x1;
-    pReg->extents.y2 = pReg->extents.y1;
-    pReg->data = &RegionEmptyData;
-}
-
-BoxPtr
-RegionExtents(RegionPtr pReg)
-{
-    good(pReg);
-    return(&pReg->extents);
-}
-
 #define ExchangeSpans(a, b)				    \
 {							    \
     DDXPointRec	tpt;				    	    \
@@ -1795,7 +1737,7 @@ RegionClipSpans(
 	if ((! fSorted) && (nspans > 1))
 	    QuickSortSpans(ppt, pwidth, nspans);
 
-	pboxBandStart = REGION_BOXPTR(prgnDst);
+	pboxBandStart = RegionBoxptr(prgnDst);
 	pboxLast = pboxBandStart + numRects;
     
 	NextBand();
diff --git a/dix/window.c b/dix/window.c
index afb10fd..a98437b 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -416,10 +416,10 @@ CreateRootWindow(ScreenPtr pScreen)
     box.y1 = 0;
     box.x2 = pScreen->width;
     box.y2 = pScreen->height;
-    REGION_INIT(pScreen, &pWin->clipList, &box, 1);
-    REGION_INIT(pScreen, &pWin->winSize, &box, 1);
-    REGION_INIT(pScreen, &pWin->borderSize, &box, 1);
-    REGION_INIT(pScreen, &pWin->borderClip, &box, 1);
+    RegionInit(&pWin->clipList, &box, 1);
+    RegionInit(&pWin->winSize, &box, 1);
+    RegionInit(&pWin->borderSize, &box, 1);
+    RegionInit(&pWin->borderClip, &box, 1);
 
     pWin->drawable.class = InputOutput;
     pWin->optional->visual = pScreen->rootVisual;
@@ -499,7 +499,7 @@ ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn,
 
     pScreen = pWin->drawable.pScreen;
 
-    box = *(REGION_EXTENTS(pScreen, &pWin->winSize));
+    box = *(RegionExtents(&pWin->winSize));
     /* we do these calculations to avoid overflows */
     if (x > box.x1)
 	box.x1 = x;
@@ -515,8 +515,8 @@ ClippedRegionFromBox(WindowPtr pWin, RegionPtr Rgn,
 	box.x2 = box.x1;
     if (box.y1 > box.y2)
 	box.y2 = box.y1;
-    REGION_RESET(pScreen, Rgn, &box);
-    REGION_INTERSECT(pScreen, Rgn, Rgn, &pWin->winSize);
+    RegionReset(Rgn, &box);
+    RegionIntersect(Rgn, Rgn, &pWin->winSize);
 }
 
 static RealChildHeadProc realChildHeadProc = NULL;
@@ -703,10 +703,10 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
     pWin->drawable.y = pParent->drawable.y + y + (int)bw;
 
 	/* set up clip list correctly for unobscured WindowPtr */
-    REGION_NULL(pScreen, &pWin->clipList);
-    REGION_NULL(pScreen, &pWin->borderClip);
-    REGION_NULL(pScreen, &pWin->winSize);
-    REGION_NULL(pScreen, &pWin->borderSize);
+    RegionNull(&pWin->clipList);
+    RegionNull(&pWin->borderClip);
+    RegionNull(&pWin->winSize);
+    RegionNull(&pWin->borderSize);
 
     pHead = RealChildHead(pParent);
     if (pHead)
@@ -824,16 +824,16 @@ FreeWindowResources(WindowPtr pWin)
     DeleteWindowFromAnySaveSet(pWin);
     DeleteWindowFromAnySelections(pWin);
     DeleteWindowFromAnyEvents(pWin, TRUE);
-    REGION_UNINIT(pScreen, &pWin->clipList);
-    REGION_UNINIT(pScreen, &pWin->winSize);
-    REGION_UNINIT(pScreen, &pWin->borderClip);
-    REGION_UNINIT(pScreen, &pWin->borderSize);
+    RegionUninit(&pWin->clipList);
+    RegionUninit(&pWin->winSize);
+    RegionUninit(&pWin->borderClip);
+    RegionUninit(&pWin->borderSize);
     if (wBoundingShape (pWin))
-	REGION_DESTROY(pScreen, wBoundingShape (pWin));
+	RegionDestroy(wBoundingShape (pWin));
     if (wClipShape (pWin))
-	REGION_DESTROY(pScreen, wClipShape (pWin));
+	RegionDestroy(wClipShape (pWin));
     if (wInputShape (pWin))
-	REGION_DESTROY(pScreen, wInputShape (pWin));
+	RegionDestroy(wInputShape (pWin));
     if (pWin->borderIsPixel == FALSE)
 	(*pScreen->DestroyPixmap)(pWin->border.pixmap);
     if (pWin->backgroundState == BackgroundPixmap)
@@ -1431,10 +1431,10 @@ PatchUp:
     {
 	RegionRec exposed;
 
-	REGION_NULL(pScreen, &exposed);
-	REGION_SUBTRACT(pScreen, &exposed, &pWin->borderClip, &pWin->winSize);
+	RegionNull(&exposed);
+	RegionSubtract(&exposed, &pWin->borderClip, &pWin->winSize);
 	miPaintWindow(pWin, &exposed, PW_BORDER);
-	REGION_UNINIT(pScreen, &exposed);
+	RegionUninit(&exposed);
     }
     return error;
 }
@@ -1581,7 +1581,7 @@ SetWinSize (WindowPtr pWin)
 	box.y1 = pWin->drawable.y;
 	box.x2 = pWin->drawable.x + pWin->drawable.width;
 	box.y2 = pWin->drawable.y + pWin->drawable.height;
-	REGION_RESET (pScreen, &pWin->winSize, &box);
+	RegionReset(&pWin->winSize, &box);
     }
     else
 #endif
@@ -1593,15 +1593,15 @@ SetWinSize (WindowPtr pWin)
 	ScreenPtr pScreen;
         pScreen = pWin->drawable.pScreen;
 
-	REGION_TRANSLATE(pScreen, &pWin->winSize, - pWin->drawable.x,
+	RegionTranslate(&pWin->winSize, - pWin->drawable.x,
 			 - pWin->drawable.y);
 	if (wBoundingShape (pWin))
-	    REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize,
+	    RegionIntersect(&pWin->winSize, &pWin->winSize,
 			     wBoundingShape (pWin));
 	if (wClipShape (pWin))
-	    REGION_INTERSECT(pScreen, &pWin->winSize, &pWin->winSize,
+	    RegionIntersect(&pWin->winSize, &pWin->winSize,
 			     wClipShape (pWin));
-	REGION_TRANSLATE(pScreen, &pWin->winSize, pWin->drawable.x,
+	RegionTranslate(&pWin->winSize, pWin->drawable.x,
 			 pWin->drawable.y);
     }
 }
@@ -1626,7 +1626,7 @@ SetBorderSize (WindowPtr pWin)
 	    box.y1 = pWin->drawable.y - bw;
 	    box.x2 = pWin->drawable.x + pWin->drawable.width + bw;
 	    box.y2 = pWin->drawable.y + pWin->drawable.height + bw;
-	    REGION_RESET (pScreen, &pWin->borderSize, &box);
+	    RegionReset(&pWin->borderSize, &box);
 	}
 	else
 #endif
@@ -1638,17 +1638,17 @@ SetBorderSize (WindowPtr pWin)
 	    ScreenPtr pScreen;
             pScreen = pWin->drawable.pScreen;
 
-	    REGION_TRANSLATE(pScreen, &pWin->borderSize, - pWin->drawable.x,
+	    RegionTranslate(&pWin->borderSize, - pWin->drawable.x,
 			     - pWin->drawable.y);
-	    REGION_INTERSECT(pScreen, &pWin->borderSize, &pWin->borderSize,
+	    RegionIntersect(&pWin->borderSize, &pWin->borderSize,
 			     wBoundingShape (pWin));
-	    REGION_TRANSLATE(pScreen, &pWin->borderSize, pWin->drawable.x,
+	    RegionTranslate(&pWin->borderSize, pWin->drawable.x,
 			     pWin->drawable.y);
-	    REGION_UNION(pScreen, &pWin->borderSize, &pWin->borderSize,
+	    RegionUnion(&pWin->borderSize, &pWin->borderSize,
 			 &pWin->winSize);
 	}
     } else {
-	REGION_COPY(pWin->drawable.pScreen, &pWin->borderSize,
+	RegionCopy(&pWin->borderSize,
 					       &pWin->winSize);
     }
 }
@@ -1848,12 +1848,12 @@ MakeBoundingRegion (
     ScreenPtr   pScreen;
     pScreen = pWin->drawable.pScreen;
 
-    pRgn = REGION_CREATE(pScreen, pBox, 1);
+    pRgn = RegionCreate(pBox, 1);
     if (wBoundingShape (pWin)) {
-	    REGION_TRANSLATE(pScreen, pRgn, -pWin->origin.x,
+	    RegionTranslate(pRgn, -pWin->origin.x,
 						  -pWin->origin.y);
-	    REGION_INTERSECT(pScreen, pRgn, pRgn, wBoundingShape (pWin));
-	    REGION_TRANSLATE(pScreen, pRgn, pWin->origin.x,
+	    RegionIntersect(pRgn, pRgn, wBoundingShape (pWin));
+	    RegionTranslate(pRgn, pWin->origin.x,
 						  pWin->origin.y);
     }
     return pRgn;
@@ -1875,10 +1875,10 @@ ShapeOverlap (
     pScreen = pWin->drawable.pScreen;
     pWinRgn = MakeBoundingRegion (pWin, pWinBox);
     pSibRgn = MakeBoundingRegion (pSib, pSibBox);
-    REGION_INTERSECT(pScreen, pWinRgn, pWinRgn, pSibRgn);
-    ret = REGION_NOTEMPTY(pScreen, pWinRgn);
-    REGION_DESTROY(pScreen, pWinRgn);
-    REGION_DESTROY(pScreen, pSibRgn);
+    RegionIntersect(pWinRgn, pWinRgn, pSibRgn);
+    ret = RegionNotEmpty(pWinRgn);
+    RegionDestroy(pWinRgn);
+    RegionDestroy(pSibRgn);
     return ret;
 }
 
@@ -2004,7 +2004,7 @@ WhereDoIGoInTheStack(
 	else if (pSib)
 	{
 	    if ((IsSiblingAboveMe(pWin, pSib) == Above) &&
-		(RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT))
+		(RegionContainsRect(&pSib->borderSize, &box) != rgnOUT))
 		return(pFirst);
 	    else
 		return(pWin->nextSib);
@@ -2019,7 +2019,7 @@ WhereDoIGoInTheStack(
 	else if (pSib)
 	{
 	    if ((IsSiblingAboveMe(pWin, pSib) == Below) &&
-		(RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT))
+		(RegionContainsRect(&pSib->borderSize, &box) != rgnOUT))
 		return NullWindow;
 	    else
 		return(pWin->nextSib);
@@ -2033,7 +2033,7 @@ WhereDoIGoInTheStack(
 	    return(pWin->nextSib);
 	else if (pSib)
 	{
-	    if (RECT_IN_REGION(pScreen, &pSib->borderSize, &box) != rgnOUT)
+	    if (RegionContainsRect(&pSib->borderSize, &box) != rgnOUT)
 	    {
 		if (IsSiblingAboveMe(pWin, pSib) == Above)
 		    return(pFirst);
@@ -2681,10 +2681,10 @@ MapWindow(WindowPtr pWin, ClientPtr client)
 	    (*pScreen->ClipNotify) (pWin, 0, 0);
 	if (pScreen->PostValidateTree)
 	    (*pScreen->PostValidateTree)(NullWindow, pWin, VTMap);
-	REGION_NULL(pScreen, &temp);
-	REGION_COPY(pScreen, &temp, &pWin->clipList);
+	RegionNull(&temp);
+	RegionCopy(&temp, &pWin->clipList);
 	(*pScreen->WindowExposures) (pWin, &temp, NullRegion);
-	REGION_UNINIT(pScreen, &temp);
+	RegionUninit(&temp);
     }
 
     return(Success);
@@ -3017,10 +3017,10 @@ PointInWindowIsVisible(WindowPtr pWin, int x, int y)
 
     if (!pWin->realized)
 	return (FALSE);
-    if (POINT_IN_REGION(pWin->drawable.pScreen, &pWin->borderClip,
+    if (RegionContainsPoint(&pWin->borderClip,
 						  x, y, &box)
 	&& (!wInputShape(pWin) ||
-	    POINT_IN_REGION(pWin->drawable.pScreen,
+	    RegionContainsPoint(
 			    wInputShape(pWin),
 			    x - pWin->drawable.x, 
 			    y - pWin->drawable.y, &box)))
@@ -3036,12 +3036,12 @@ NotClippedByChildren(WindowPtr pWin)
     RegionPtr pReg;
 
     pScreen = pWin->drawable.pScreen;
-    pReg = REGION_CREATE(pScreen, NullBox, 1);
+    pReg = RegionCreate(NullBox, 1);
     if (pWin->parent ||
 	screenIsSaved != SCREEN_SAVER_ON ||
 	!HasSaverWindow (pWin->drawable.pScreen))
     {
-	REGION_INTERSECT(pScreen, pReg, &pWin->borderClip, &pWin->winSize);
+	RegionIntersect(pReg, &pWin->borderClip, &pWin->winSize);
     }
     return(pReg);
 }
diff --git a/doc/xml/Xserver-spec.xml b/doc/xml/Xserver-spec.xml
index 1bea20f..88885ae 100644
--- a/doc/xml/Xserver-spec.xml
+++ b/doc/xml/Xserver-spec.xml
@@ -2101,7 +2101,7 @@ Making direct calls is faster on many architectures.</para>
 		BoxPtr rect;
 		int size;
 
-	macro: RegionPtr REGION_CREATE(pScreen, rect, size)
+	macro: RegionPtr RegionCreate(rect, size)
 
 </programlisting></blockquote>
 RegionCreate creates a region that describes ONE rectangle.  The
@@ -2122,7 +2122,7 @@ applicable.</para>
 		BoxPtr		rect;
 		int		size;
 
-	macro: REGION_INIT(pScreen, pRegion, rect, size)
+	macro: RegionInit(pRegion, rect, size)
 
 </programlisting></blockquote>
 Given an existing raw region structure (such as an local variable), this
@@ -2136,7 +2136,7 @@ allocation overhead for the region structure itself.
 	Bool pScreen->RegionCopy(dstrgn, srcrgn)
 		RegionPtr dstrgn, srcrgn;
 
-	macro: Bool REGION_COPY(pScreen, dstrgn, srcrgn)
+	macro: Bool RegionCopy(dstrgn, srcrgn)
 
 </programlisting></blockquote>
 RegionCopy copies the description of one region, srcrgn, to another
@@ -2148,7 +2148,7 @@ dstrgn; returning TRUE if the copy succeeded, and FALSE otherwise.</para>
 	void pScreen->RegionDestroy( pRegion)
 		RegionPtr pRegion;
 
-	macro: REGION_DESTROY(pScreen, pRegion)
+	macro: RegionDestroy(pRegion)
 
 </programlisting></blockquote>
 RegionDestroy destroys a region and frees all allocated memory.</para>
@@ -2158,7 +2158,7 @@ RegionDestroy destroys a region and frees all allocated memory.</para>
 	void pScreen->RegionUninit (pRegion)
 		RegionPtr pRegion;
 
-	macro: REGION_UNINIT(pScreen, pRegion)
+	macro: RegionUninit(pRegion)
 
 </programlisting></blockquote>
 Frees everything except the region structure itself, useful when the
@@ -2171,23 +2171,23 @@ it has been RegionInit'ed again.</para>
 	Bool pScreen->Intersect(newReg, reg1, reg2)
 		RegionPtr newReg, reg1, reg2;
 
-	macro: Bool REGION_INTERSECT(pScreen, newReg, reg1, reg2)
+	macro: Bool RegionIntersect(newReg, reg1, reg2)
 
 	Bool  pScreen->Union(newReg, reg1, reg2)
 		RegionPtr newReg, reg1, reg2;
 
-	macro: Bool REGION_UNION(pScreen, newReg, reg1, reg2)
+	macro: Bool RegionUnion(newReg, reg1, reg2)
 
 	Bool  pScreen->Subtract(newReg, regMinuend, regSubtrahend)
 		RegionPtr newReg, regMinuend, regSubtrahend;
 
-	macro: Bool REGION_UNION(pScreen, newReg, regMinuend, regSubtrahend)
+	macro: Bool RegionUnion(newReg, regMinuend, regSubtrahend)
 
 	Bool pScreen->Inverse(newReg, pReg,  pBox)
 		RegionPtr newReg, pReg;
 		BoxPtr pBox;
 
-	macro: Bool REGION_INVERSE(pScreen, newReg, pReg,  pBox)
+	macro: Bool RegionInverse(newReg, pReg,  pBox)
 
 </programlisting></blockquote>
 The above four calls all do basic logical operations on regions.  They
@@ -2213,7 +2213,7 @@ Each routine must return the value TRUE for success.</para>
 		RegionPtr pRegion;
 		BoxPtr pBox;
 
-	macro: REGION_RESET(pScreen, pRegion, pBox)
+	macro: RegionReset(pRegion, pBox)
 
 </programlisting></blockquote>
 RegionReset sets the region to describe
@@ -2225,7 +2225,7 @@ one rectangle and reallocates it to a size of one rectangle, if applicable.</par
 		RegionPtr pRegion;
 		int x, y;
 
-	macro: REGION_TRANSLATE(pScreen, pRegion, x, y)
+	macro: RegionTranslate(pRegion, x, y)
 
 </programlisting></blockquote>
 TranslateRegion simply moves a region +x in the x direction and +y in the y
@@ -2237,7 +2237,7 @@ direction.</para>
 		RegionPtr pRegion;
 		BoxPtr pBox;
 
-	macro: int RECT_IN_REGION(pScreen, pRegion, pBox)
+	macro: int RegionContainsRect(pRegion, pBox)
 
 </programlisting></blockquote>
 RectIn returns one of the defined constants rgnIN, rgnOUT, or rgnPART,
@@ -2252,7 +2252,7 @@ These constants are defined in Xserver/include/region.h.</para>
 		int x, y;
 		BoxPtr pBox;
 
-	macro: Bool POINT_IN_REGION(pScreen, pRegion, x, y, pBox)
+	macro: Bool RegionContainsPoint(pRegion, x, y, pBox)
 
 </programlisting></blockquote>
 PointInRegion returns true if the point x, y is in the region.  In
@@ -2275,7 +2275,7 @@ returned box.</para>
 	Bool pScreen->RegionNotEmpty(pRegion)
 		RegionPtr pRegion;
 
-	macro: Bool REGION_NOTEMPTY(pScreen, pRegion)
+	macro: Bool RegionNotEmpty(pRegion)
 
 </programlisting></blockquote>
 RegionNotEmpty is a boolean function that returns
@@ -2286,7 +2286,7 @@ true or false depending upon whether the region encloses any pixels.</para>
 	void pScreen->RegionEmpty(pRegion)
 		RegionPtr pRegion;
 
-	macro: REGION_EMPTY(pScreen, pRegion)
+	macro: RegionEmpty(pRegion)
 
 </programlisting></blockquote>
 RegionEmpty sets the region to be empty.</para>
@@ -2296,7 +2296,7 @@ RegionEmpty sets the region to be empty.</para>
 	BoxPtr pScreen->RegionExtents(pRegion)
 		RegionPtr pRegion;
 
-	macro: REGION_EXTENTS(pScreen, pRegion)
+	macro: RegionExtents(pRegion)
 
 </programlisting></blockquote>
 RegionExtents returns a rectangle that is the smallest
@@ -2310,13 +2310,13 @@ in your region struct.</para>
 		RegionPtr pDstRgn;
 		RegionPtr pRegion;
 
-	macro: Bool REGION_APPEND(pScreen, pDstRgn, pRegion)
+	macro: Bool RegionAppend(pDstRgn, pRegion)
 
 	Bool pScreen->RegionValidate (pRegion, pOverlap)
 		RegionPtr pRegion;
 		Bool *pOverlap;
 
-	macro: Bool REGION_VALIDATE(pScreen, pRegion, pOverlap)
+	macro: Bool RegionValidate(pRegion, pOverlap)
 
 </programlisting></blockquote>
 These functions provide an optimization for clip list generation and
@@ -2332,7 +2332,7 @@ regions overlap; FALSE otherwise.</para>
 	RegionPtr pScreen->BitmapToRegion (pPixmap)
 		PixmapPtr pPixmap;
 
-	macro: RegionPtr BITMAP_TO_REGION(pScreen, pPixmap)
+	macro: RegionPtr BitmapToRegion(pScreen, pPixmap)
 
 </programlisting></blockquote>
 Given a depth-1 pixmap, this routine must create a valid region which
@@ -2346,7 +2346,7 @@ areas filled with 0's.  This routine returns NULL if out of memory.</para>
 		xRectangle *pRects;
 		int ordering;
 
-	macro: RegionPtr RECTS_TO_REGION(pScreen, nrects, pRects, ordering)
+	macro: RegionPtr RegionFromRects(nrects, pRects, ordering)
 
 </programlisting></blockquote>
 Given a client-supplied list of rectangles, produces a region which includes
diff --git a/exa/exa.c b/exa/exa.c
index 46a850f..4e1ffd6 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -161,10 +161,10 @@ exaPixmapDirty (PixmapPtr pPix, int x1, int y1, int x2, int y2)
     if (box.x1 >= box.x2 || box.y1 >= box.y2)
 	return;
 
-    REGION_INIT(pScreen, &region, &box, 1);
+    RegionInit(&region, &box, 1);
     DamageRegionAppend(&pPix->drawable, &region);
     DamageRegionProcessPending(&pPix->drawable);
-    REGION_UNINIT(pScreen, &region);
+    RegionUninit(&region);
 }
 
 static int
@@ -658,7 +658,7 @@ exaBitmapToRegion(PixmapPtr pPix)
 
     exaPrepareAccess(&pPix->drawable, EXA_PREPARE_SRC);
     swap(pExaScr, pScreen, BitmapToRegion);
-    ret = pScreen->BitmapToRegion(pPix);
+    ret = (*pScreen->BitmapToRegion)(pPix);
     swap(pExaScr, pScreen, BitmapToRegion);
     exaFinishAccess(&pPix->drawable, EXA_PREPARE_SRC);
 
diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index cf48ecd..6c677c7 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -81,7 +81,7 @@ exaFillSpans(DrawablePtr pDrawable, GCPtr pGC, int n,
 	return;
     }
 
-    pextent = REGION_EXTENTS(pGC->pScreen, pClip);
+    pextent = RegionExtents(pClip);
     extentX1 = pextent->x1;
     extentY1 = pextent->y1;
     extentX2 = pextent->x2;
@@ -106,7 +106,7 @@ exaFillSpans(DrawablePtr pDrawable, GCPtr pGC, int n,
 	if (fullX1 >= fullX2)
 	    continue;
 
-	nbox = REGION_NUM_RECTS (pClip);
+	nbox = RegionNumRects (pClip);
 	if (nbox == 1)
 	{
 	    (*pExaScr->info->Solid) (pPixmap,
@@ -115,7 +115,7 @@ exaFillSpans(DrawablePtr pDrawable, GCPtr pGC, int n,
 	}
 	else
 	{
-	    pbox = REGION_RECTS(pClip);
+	    pbox = RegionRects(pClip);
 	    while(nbox--)
 	    {
 		if (pbox->y1 <= fullY1 && fullY1 < pbox->y2)
@@ -192,8 +192,8 @@ exaDoPutImage (DrawablePtr pDrawable, GCPtr pGC, int depth, int x, int y,
     y += pDrawable->y;
 
     pClip = fbGetCompositeClip(pGC);
-    for (nbox = REGION_NUM_RECTS(pClip),
-	 pbox = REGION_RECTS(pClip);
+    for (nbox = RegionNumRects(pClip),
+	 pbox = RegionRects(pClip);
 	 nbox--;
 	 pbox++)
     {
@@ -416,15 +416,15 @@ exaHWCopyNtoN (DrawablePtr    pSrcDrawable,
 	else
 	    ordering = CT_UNSORTED;
 
-	srcregion  = RECTS_TO_REGION(pScreen, nbox, rects, ordering);
+	srcregion  = RegionFromRects(nbox, rects, ordering);
 	free(rects);
 
 	if (!pGC || !exaGCReadsDestination(pDstDrawable, pGC->planemask,
 					   pGC->fillStyle, pGC->alu,
 					   pGC->clientClipType)) {
-	    dstregion = REGION_CREATE(pScreen, NullBox, 0);
-	    REGION_COPY(pScreen, dstregion, srcregion);
-	    REGION_TRANSLATE(pScreen, dstregion, dst_off_x - dx - src_off_x,
+	    dstregion = RegionCreate(NullBox, 0);
+	    RegionCopy(dstregion, srcregion);
+	    RegionTranslate(dstregion, dst_off_x - dx - src_off_x,
 			     dst_off_y - dy - src_off_y);
 	}
     }
@@ -551,12 +551,12 @@ fallback:
 
 out:
     if (dstregion) {
-	REGION_UNINIT(pScreen, dstregion);
-	REGION_DESTROY(pScreen, dstregion);
+	RegionUninit(dstregion);
+	RegionDestroy(dstregion);
     }
     if (srcregion) {
-	REGION_UNINIT(pScreen, srcregion);
-	REGION_DESTROY(pScreen, srcregion);
+	RegionUninit(srcregion);
+	RegionDestroy(srcregion);
     }
 
     return ret;
@@ -788,13 +788,13 @@ exaPolyFillRect(DrawablePtr pDrawable,
     int		    xoff, yoff;
     int		    xorg, yorg;
     int		    n;
-    RegionPtr pReg = RECTS_TO_REGION(pScreen, nrect, prect, CT_UNSORTED);
+    RegionPtr pReg = RegionFromRects(nrect, prect, CT_UNSORTED);
 
     /* Compute intersection of rects and clip region */
-    REGION_TRANSLATE(pScreen, pReg, pDrawable->x, pDrawable->y);
-    REGION_INTERSECT(pScreen, pReg, pClip, pReg);
+    RegionTranslate(pReg, pDrawable->x, pDrawable->y);
+    RegionIntersect(pReg, pClip, pReg);
 
-    if (!REGION_NUM_RECTS(pReg)) {
+    if (!RegionNumRects(pReg)) {
 	goto out;
     }
 
@@ -856,7 +856,7 @@ fallback:
     xorg = pDrawable->x;
     yorg = pDrawable->y;
 
-    pextent = REGION_EXTENTS(pGC->pScreen, pClip);
+    pextent = RegionExtents(pClip);
     extentX1 = pextent->x1;
     extentY1 = pextent->y1;
     extentX2 = pextent->x2;
@@ -883,7 +883,7 @@ fallback:
 
 	if ((fullX1 >= fullX2) || (fullY1 >= fullY2))
 	    continue;
-	n = REGION_NUM_RECTS (pClip);
+	n = RegionNumRects (pClip);
 	if (n == 1)
 	{
 	    (*pExaScr->info->Solid) (pPixmap,
@@ -892,7 +892,7 @@ fallback:
 	}
 	else
 	{
-	    pbox = REGION_RECTS(pClip);
+	    pbox = RegionRects(pClip);
 	    /*
 	     * clip the rectangle to each box in the clip region
 	     * this is logically equivalent to calling Intersect(),
@@ -927,8 +927,8 @@ fallback:
     exaMarkSync(pDrawable->pScreen);
 
 out:
-    REGION_UNINIT(pScreen, pReg);
-    REGION_DESTROY(pScreen, pReg);
+    RegionUninit(pReg);
+    RegionDestroy(pReg);
 }
 
 const GCOps exaOps = {
@@ -964,14 +964,14 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 
     dx = ptOldOrg.x - pWin->drawable.x;
     dy = ptOldOrg.y - pWin->drawable.y;
-    REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
+    RegionTranslate(prgnSrc, -dx, -dy);
 
-    REGION_INIT (pWin->drawable.pScreen, &rgnDst, NullBox, 0);
+    RegionInit(&rgnDst, NullBox, 0);
 
-    REGION_INTERSECT(pWin->drawable.pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
+    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
 #ifdef COMPOSITE
     if (pPixmap->screen_x || pPixmap->screen_y)
-	REGION_TRANSLATE (pWin->drawable.pScreen, &rgnDst,
+	RegionTranslate(&rgnDst,
 			  -pPixmap->screen_x, -pPixmap->screen_y);
 #endif
 
@@ -987,11 +987,11 @@ exaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     pExaScr->fallback_flags &= ~EXA_ACCEL_COPYWINDOW;
 
 fallback:
-    REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
 
     if (pExaScr->fallback_flags & EXA_FALLBACK_COPYWINDOW) {
 	pExaScr->fallback_flags &= ~EXA_FALLBACK_COPYWINDOW;
-	REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, dx, dy);
+	RegionTranslate(prgnSrc, dx, dy);
 	ExaCheckCopyWindow(pWin, ptOldOrg, prgnSrc);
     }
 }
@@ -1007,7 +1007,7 @@ exaFillRegionSolid (DrawablePtr	pDrawable, RegionPtr pRegion, Pixel pixel,
     Bool ret = FALSE;
 
     exaGetDrawableDeltas(pDrawable, pPixmap, &xoff, &yoff);
-    REGION_TRANSLATE(pScreen, pRegion, xoff, yoff);
+    RegionTranslate(pRegion, xoff, yoff);
 
     if (pExaScr->fallback_counter || pExaPixmap->accel_blocked)
 	goto out;
@@ -1030,8 +1030,8 @@ exaFillRegionSolid (DrawablePtr	pDrawable, RegionPtr pRegion, Pixel pixel,
 	int nbox;
 	BoxPtr pBox;
 
-	nbox = REGION_NUM_RECTS (pRegion);
-	pBox = REGION_RECTS (pRegion);
+	nbox = RegionNumRects (pRegion);
+	pBox = RegionRects (pRegion);
 
 	while (nbox--)
 	{
@@ -1060,18 +1060,18 @@ exaFillRegionSolid (DrawablePtr	pDrawable, RegionPtr pRegion, Pixel pixel,
 		*(CARD8*)pExaPixmap->sys_ptr = pixel;
 	    }
 
-	    REGION_UNION(pScreen, &pExaPixmap->validSys, &pExaPixmap->validSys,
+	    RegionUnion(&pExaPixmap->validSys, &pExaPixmap->validSys,
 			 pRegion);
-	    REGION_UNION(pScreen, &pExaPixmap->validFB, &pExaPixmap->validFB,
+	    RegionUnion(&pExaPixmap->validFB, &pExaPixmap->validFB,
 			 pRegion);
-	    REGION_SUBTRACT(pScreen, pending_damage, pending_damage, pRegion);
+	    RegionSubtract(pending_damage, pending_damage, pRegion);
 	}
 
 	ret = TRUE;
     }
 
 out:
-    REGION_TRANSLATE(pScreen, pRegion, -xoff, -yoff);
+    RegionTranslate(pRegion, -xoff, -yoff);
 
     return ret;
 }
@@ -1090,8 +1090,8 @@ exaFillRegionTiled (DrawablePtr pDrawable, RegionPtr pRegion, PixmapPtr pTile,
     ExaPixmapPrivPtr pTileExaPixmap = ExaGetPixmapPriv(pTile);
     int xoff, yoff;
     int tileWidth, tileHeight;
-    int nbox = REGION_NUM_RECTS (pRegion);
-    BoxPtr pBox = REGION_RECTS (pRegion);
+    int nbox = RegionNumRects (pRegion);
+    BoxPtr pBox = RegionRects (pRegion);
     Bool ret = FALSE;
     int i;
 
@@ -1137,7 +1137,7 @@ exaFillRegionTiled (DrawablePtr pDrawable, RegionPtr pRegion, PixmapPtr pTile,
     if ((*pExaScr->info->PrepareCopy) (pTile, pPixmap, 1, 1, alu, planemask))
     {
 	if (xoff || yoff)
-	    REGION_TRANSLATE(pScreen, pRegion, xoff, yoff);
+	    RegionTranslate(pRegion, xoff, yoff);
 
 	for (i = 0; i < nbox; i++)
 	{
@@ -1245,7 +1245,7 @@ exaFillRegionTiled (DrawablePtr pDrawable, RegionPtr pRegion, PixmapPtr pTile,
 	exaMarkSync(pDrawable->pScreen);
 
 	if (xoff || yoff)
-	    REGION_TRANSLATE(pScreen, pRegion, -xoff, -yoff);
+	    RegionTranslate(pRegion, -xoff, -yoff);
     }
 
     return ret;
diff --git a/exa/exa_classic.c b/exa/exa_classic.c
index e1ead6c..0b0ca4e 100644
--- a/exa/exa_classic.c
+++ b/exa/exa_classic.c
@@ -131,8 +131,8 @@ exaCreatePixmap_classic(ScreenPtr pScreen, int w, int h, int depth,
     box.y1 = 0;
     box.x2 = w;
     box.y2 = h;
-    REGION_INIT(pScreen, &pExaPixmap->validSys, &box, 0);
-    REGION_INIT(pScreen, &pExaPixmap->validFB, &box, 0);
+    RegionInit(&pExaPixmap->validSys, &box, 0);
+    RegionInit(&pExaPixmap->validFB, &box, 0);
 
     exaSetAccelBlock(pExaScr, pExaPixmap,
                      w, h, bpp);
@@ -237,8 +237,8 @@ exaDestroyPixmap_classic (PixmapPtr pPixmap)
 	    pPixmap->devPrivate.ptr = pExaPixmap->sys_ptr;
 	    pPixmap->devKind = pExaPixmap->sys_pitch;
 	}
-	REGION_UNINIT(pPixmap->drawable.pScreen, &pExaPixmap->validSys);
-	REGION_UNINIT(pPixmap->drawable.pScreen, &pExaPixmap->validFB);
+	RegionUninit(&pExaPixmap->validSys);
+	RegionUninit(&pExaPixmap->validFB);
     }
 
     swap(pExaScr, pScreen, DestroyPixmap);
diff --git a/exa/exa_migration_classic.c b/exa/exa_migration_classic.c
index 871679f..6c49fb7 100644
--- a/exa/exa_migration_classic.c
+++ b/exa/exa_migration_classic.c
@@ -78,8 +78,8 @@ exaPixmapIsDirty (PixmapPtr pPix)
     if (!pExaPixmap->pDamage)
 	return FALSE;
 
-    return REGION_NOTEMPTY (pScreen, DamageRegion(pExaPixmap->pDamage)) ||
-	!REGION_EQUAL(pScreen, &pExaPixmap->validSys, &pExaPixmap->validFB);
+    return RegionNotEmpty(DamageRegion(pExaPixmap->pDamage)) ||
+	!RegionEqual(&pExaPixmap->validSys, &pExaPixmap->validFB);
 }
 
 /**
@@ -123,22 +123,22 @@ exaCopyDirty(ExaMigrationPtr migrate, RegionPtr pValidDst, RegionPtr pValidSrc,
 
     /* Damaged bits are valid in current copy but invalid in other one */
     if (pExaPixmap->use_gpu_copy) {
-	REGION_UNION(pScreen, &pExaPixmap->validFB, &pExaPixmap->validFB,
+	RegionUnion(&pExaPixmap->validFB, &pExaPixmap->validFB,
 		     damage);
-	REGION_SUBTRACT(pScreen, &pExaPixmap->validSys, &pExaPixmap->validSys,
+	RegionSubtract(&pExaPixmap->validSys, &pExaPixmap->validSys,
 			damage);
     } else {
-	REGION_UNION(pScreen, &pExaPixmap->validSys, &pExaPixmap->validSys,
+	RegionUnion(&pExaPixmap->validSys, &pExaPixmap->validSys,
 		     damage);
-	REGION_SUBTRACT(pScreen, &pExaPixmap->validFB, &pExaPixmap->validFB,
+	RegionSubtract(&pExaPixmap->validFB, &pExaPixmap->validFB,
 			damage);
     }
 
-    REGION_EMPTY(pScreen, damage);
+    RegionEmpty(damage);
 
     /* Copy bits valid in source but not in destination */
-    REGION_NULL(pScreen, &CopyReg);
-    REGION_SUBTRACT(pScreen, &CopyReg, pValidSrc, pValidDst);
+    RegionNull(&CopyReg);
+    RegionSubtract(&CopyReg, pValidSrc, pValidDst);
 
     if (migrate->as_dst) {
 	ExaScreenPriv (pPixmap->drawable.pScreen);
@@ -153,7 +153,7 @@ exaCopyDirty(ExaMigrationPtr migrate, RegionPtr pValidDst, RegionPtr pValidSrc,
 	    RegionPtr pending_damage = DamagePendingRegion(pExaPixmap->pDamage);
 
 #if DEBUG_MIGRATE
-	    if (REGION_NIL(pending_damage)) {
+	    if (RegionNil(pending_damage)) {
 		static Bool firsttime = TRUE;
 
 		if (firsttime) {
@@ -167,23 +167,23 @@ exaCopyDirty(ExaMigrationPtr migrate, RegionPtr pValidDst, RegionPtr pValidSrc,
 	     * rects by filling it up to the extents of the union of the
 	     * destination valid region and the pending damage region.
 	     */
-	    if (REGION_NUM_RECTS(pValidDst) > 10) {
+	    if (RegionNumRects(pValidDst) > 10) {
 		BoxRec box;
 		BoxPtr pValidExt, pDamageExt;
 		RegionRec closure;
 
-		pValidExt = REGION_EXTENTS(pScreen, pValidDst);
-		pDamageExt = REGION_EXTENTS(pScreen, pending_damage);
+		pValidExt = RegionExtents(pValidDst);
+		pDamageExt = RegionExtents(pending_damage);
 
 		box.x1 = min(pValidExt->x1, pDamageExt->x1);
 		box.y1 = min(pValidExt->y1, pDamageExt->y1);
 		box.x2 = max(pValidExt->x2, pDamageExt->x2);
 		box.y2 = max(pValidExt->y2, pDamageExt->y2);
 
-		REGION_INIT(pScreen, &closure, &box, 0);
-		REGION_INTERSECT(pScreen, &CopyReg, &CopyReg, &closure);
+		RegionInit(&closure, &box, 0);
+		RegionIntersect(&CopyReg, &CopyReg, &closure);
 	    } else
-		REGION_INTERSECT(pScreen, &CopyReg, &CopyReg, pending_damage);
+		RegionIntersect(&CopyReg, &CopyReg, pending_damage);
 	}
 
 	/* The caller may provide a region to be subtracted from the calculated
@@ -191,17 +191,17 @@ exaCopyDirty(ExaMigrationPtr migrate, RegionPtr pValidDst, RegionPtr pValidSrc,
 	 * contribute to the result of the operation.
 	 */
 	if (migrate->pReg)
-	    REGION_SUBTRACT(pScreen, &CopyReg, &CopyReg, migrate->pReg);
+	    RegionSubtract(&CopyReg, &CopyReg, migrate->pReg);
     } else {
 	/* The caller may restrict the region to be migrated for source pixmaps
 	 * to what's relevant for the operation.
 	 */
 	if (migrate->pReg)
-	    REGION_INTERSECT(pScreen, &CopyReg, &CopyReg, migrate->pReg);
+	    RegionIntersect(&CopyReg, &CopyReg, migrate->pReg);
     }
 
-    pBox = REGION_RECTS(&CopyReg);
-    nbox = REGION_NUM_RECTS(&CopyReg);
+    pBox = RegionRects(&CopyReg);
+    nbox = RegionNumRects(&CopyReg);
 
     save_use_gpu_copy = pExaPixmap->use_gpu_copy;
     save_pitch = pPixmap->devKind;
@@ -252,13 +252,13 @@ exaCopyDirty(ExaMigrationPtr migrate, RegionPtr pValidDst, RegionPtr pValidSrc,
      * removing parts of it which are also in the destination valid region.
      * Removing anything beyond that would lead to data loss.
      */
-    if (REGION_NUM_RECTS(pValidSrc) > 20)
-	REGION_SUBTRACT(pScreen, pValidSrc, pValidSrc, pValidDst);
+    if (RegionNumRects(pValidSrc) > 20)
+	RegionSubtract(pValidSrc, pValidSrc, pValidDst);
 
     /* The copied bits are now valid in destination */
-    REGION_UNION(pScreen, pValidDst, pValidDst, &CopyReg);
+    RegionUnion(pValidDst, pValidDst, &CopyReg);
 
-    REGION_UNINIT(pScreen, &CopyReg);
+    RegionUninit(&CopyReg);
 
     if (access_prepared)
 	exaFinishAccess(&pPixmap->drawable, fallback_index);
@@ -440,7 +440,7 @@ exaPixmapSave (ScreenPtr pScreen, ExaOffscreenArea *area)
 
     /* Mark all FB bits as invalid, so all valid system bits get copied to FB
      * next time */
-    REGION_EMPTY(pPixmap->drawable.pScreen, &pExaPixmap->validFB);
+    RegionEmpty(&pExaPixmap->validFB);
 }
 
 /**
@@ -531,15 +531,15 @@ exaAssertNotDirty (PixmapPtr pPixmap)
     if (exaPixmapIsPinned(pPixmap) || pExaPixmap->area == NULL)
 	return ret;
 
-    REGION_NULL(pScreen, &ValidReg);
-    REGION_INTERSECT(pScreen, &ValidReg, &pExaPixmap->validFB,
+    RegionNull(&ValidReg);
+    RegionIntersect(&ValidReg, &pExaPixmap->validFB,
 		     &pExaPixmap->validSys);
-    nbox = REGION_NUM_RECTS(&ValidReg);
+    nbox = RegionNumRects(&ValidReg);
 
     if (!nbox)
 	goto out;
 
-    pBox = REGION_RECTS(&ValidReg);
+    pBox = RegionRects(&ValidReg);
 
     dst_pitch = pExaPixmap->sys_pitch;
     src_pitch = pExaPixmap->fb_pitch;
@@ -586,7 +586,7 @@ skip:
     pPixmap->devKind = save_pitch;
 
 out:
-    REGION_UNINIT(pScreen, &ValidReg);
+    RegionUninit(&ValidReg);
     return ret;
 }
 
diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c
index 49e04f2..89cb137 100644
--- a/exa/exa_mixed.c
+++ b/exa/exa_mixed.c
@@ -180,7 +180,7 @@ exaModifyPixmapHeader_mixed(PixmapPtr pPixmap, int width, int height, int depth,
 
             exaSetAccelBlock(pExaScr, pExaPixmap,
                              width, height, bitsPerPixel);
-            REGION_EMPTY(pScreen, &pExaPixmap->validFB);
+            RegionEmpty(&pExaPixmap->validFB);
         }
 
 	/* Need to re-create system copy if there's also a GPU copy */
@@ -192,7 +192,7 @@ exaModifyPixmapHeader_mixed(PixmapPtr pPixmap, int width, int height, int depth,
 	    DamageUnregister(&pPixmap->drawable, pExaPixmap->pDamage);
 	    DamageDestroy(pExaPixmap->pDamage);
 	    pExaPixmap->pDamage = NULL;
-	    REGION_EMPTY(pScreen, &pExaPixmap->validSys);
+	    RegionEmpty(&pExaPixmap->validSys);
 
 	    if (pExaScr->deferred_mixed_pixmap == pPixmap)
 		pExaScr->deferred_mixed_pixmap = NULL;
diff --git a/exa/exa_render.c b/exa/exa_render.c
index b7f383f..6f2af8a 100644
--- a/exa/exa_render.c
+++ b/exa/exa_render.c
@@ -292,7 +292,7 @@ exaTryDriverSolidFill(PicturePtr	pSrc,
 
     exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &dst_off_x, &dst_off_y);
 
-    REGION_TRANSLATE(pScreen, &region, dst_off_x, dst_off_y);
+    RegionTranslate(&region, dst_off_x, dst_off_y);
 
     if (pSrc->pDrawable) {
 	pSrcPix = exaGetDrawablePixmap (pSrc->pDrawable);
@@ -305,7 +305,7 @@ exaTryDriverSolidFill(PicturePtr	pSrc,
 	!exaGetPixelFromRGBA(&pixel, red, green, blue, alpha,
 			     pDst->pFormat))
     {
-	REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+	RegionUninit(&region);
 	return -1;
     }
 
@@ -320,18 +320,18 @@ exaTryDriverSolidFill(PicturePtr	pSrc,
     }
 
     if (!exaPixmapHasGpuCopy(pDstPix)) {
-	REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+	RegionUninit(&region);
 	return 0;
     }
 
     if (!(*pExaScr->info->PrepareSolid) (pDstPix, GXcopy, 0xffffffff, pixel))
     {
-	REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+	RegionUninit(&region);
 	return -1;
     }
 
-    nbox = REGION_NUM_RECTS(&region);
-    pbox = REGION_RECTS(&region);
+    nbox = RegionNumRects(&region);
+    pbox = RegionRects(&region);
 
     while (nbox--)
     {
@@ -342,7 +342,7 @@ exaTryDriverSolidFill(PicturePtr	pSrc,
     (*pExaScr->info->DoneSolid) (pDstPix);
     exaMarkSync(pDst->pDrawable->pScreen);
 
-    REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+    RegionUninit(&region);
     return 1;
 }
 
@@ -469,10 +469,10 @@ exaTryDriverCompositeRects(CARD8	       op,
 				       rects->width, rects->height))
 	    goto next_rect;
 
-	REGION_TRANSLATE(pScreen, &region, dst_off_x, dst_off_y);
+	RegionTranslate(&region, dst_off_x, dst_off_y);
 
-	nbox = REGION_NUM_RECTS(&region);
-	pbox = REGION_RECTS(&region);
+	nbox = RegionNumRects(&region);
+	pbox = RegionRects(&region);
 
 	xMask = xMask + mask_off_x - xDst - dst_off_x;
 	yMask = yMask + mask_off_y - yDst - dst_off_y;
@@ -494,7 +494,7 @@ exaTryDriverCompositeRects(CARD8	       op,
 	}
 
     next_rect:
-	REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+	RegionUninit(&region);
 
 	rects++;
     }
@@ -575,11 +575,11 @@ exaCompositeRects(CARD8	              op,
 	 * (see use of DamagePendingRegion in exaCopyDirty)
 	 */
 
-	REGION_INIT(pScreen, &region, &box, 1);
+	RegionInit(&region, &box, 1);
     
 	DamageRegionAppend(pDst->pDrawable, &region);
 
-	REGION_UNINIT(pScreen, &region);
+	RegionUninit(&region);
     }
     
     /************************************************************/
@@ -703,7 +703,7 @@ exaTryDriverComposite(CARD8		op,
 
     exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &dst_off_x, &dst_off_y);
 
-    REGION_TRANSLATE(pScreen, &region, dst_off_x, dst_off_y);
+    RegionTranslate(&region, dst_off_x, dst_off_y);
 
     if (pExaScr->do_migration) {
 	ExaMigrationRec pixmaps[3];
@@ -737,7 +737,7 @@ exaTryDriverComposite(CARD8		op,
     if (pSrcPix) {
 	pSrcPix = exaGetOffscreenPixmap (pSrc->pDrawable, &src_off_x, &src_off_y);
 	if (!pSrcPix) {
-	    REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+	    RegionUninit(&region);
 	    return 0;
 	}
     }
@@ -746,25 +746,25 @@ exaTryDriverComposite(CARD8		op,
 	pMaskPix = exaGetOffscreenPixmap (pMask->pDrawable, &mask_off_x,
 					  &mask_off_y);
 	if (!pMaskPix) {
-	    REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+	    RegionUninit(&region);
 	    return 0;
 	}
     }
 
     if (!exaPixmapHasGpuCopy(pDstPix)) {
-	REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+	RegionUninit(&region);
 	return 0;
     }
 
     if (!(*pExaScr->info->PrepareComposite) (op, pSrc, pMask, pDst, pSrcPix,
 					     pMaskPix, pDstPix))
     {
-	REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+	RegionUninit(&region);
 	return -1;
     }
 
-    nbox = REGION_NUM_RECTS(&region);
-    pbox = REGION_RECTS(&region);
+    nbox = RegionNumRects(&region);
+    pbox = RegionRects(&region);
 
     xMask = xMask + mask_off_x - xDst - dst_off_x;
     yMask = yMask + mask_off_y - yDst - dst_off_y;
@@ -788,7 +788,7 @@ exaTryDriverComposite(CARD8		op,
     (*pExaScr->info->DoneComposite) (pDstPix);
     exaMarkSync(pDst->pDrawable->pScreen);
 
-    REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+    RegionUninit(&region);
     return 1;
 }
 
@@ -953,9 +953,9 @@ exaComposite(CARD8	op,
 		    goto done;
 
 		ret = exaHWCopyNtoN(pSrc->pDrawable, pDst->pDrawable, NULL,
-			     REGION_RECTS(&region), REGION_NUM_RECTS(&region),
+			     RegionRects(&region), RegionNumRects(&region),
 			     xSrc - xDst, ySrc - yDst, FALSE, FALSE);
-		REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+		RegionUninit(&region);
 
 		/* Reset values to their original values. */
 		xDst -= pDst->pDrawable->x;
@@ -1005,7 +1005,7 @@ exaComposite(CARD8	op,
 					 (PixmapPtr)pSrc->pDrawable,
 					 &patOrg, FB_ALLONES, GXcopy, CT_NONE);
 
-		REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+		RegionUninit(&region);
 
 		if (ret)
 		    goto done;
diff --git a/exa/exa_unaccel.c b/exa/exa_unaccel.c
index 402d76d..a078cc1 100644
--- a/exa/exa_unaccel.c
+++ b/exa/exa_unaccel.c
@@ -131,10 +131,10 @@ ExaCheckCopyNtoN (DrawablePtr pSrc, DrawablePtr pDst,  GCPtr pGC,
 	PixmapPtr pPixmap = exaGetDrawablePixmap(pSrc);
 
 	exaGetDrawableDeltas(pSrc, pPixmap, &xoff, &yoff);
-	REGION_INIT(pScreen, &reg, pbox, nbox);
-	REGION_TRANSLATE(pScreen, &reg, xoff + dx, yoff + dy);
+	RegionInit(&reg, pbox, nbox);
+	RegionTranslate(&reg, xoff + dx, yoff + dy);
 	pExaScr->prepare_access_reg(pPixmap, EXA_PREPARE_SRC, &reg);
-	REGION_UNINIT(pScreen, &reg);
+	RegionUninit(&reg);
     } else
 	exaPrepareAccess (pSrc, EXA_PREPARE_SRC);
 
@@ -144,10 +144,10 @@ ExaCheckCopyNtoN (DrawablePtr pSrc, DrawablePtr pDst,  GCPtr pGC,
 	PixmapPtr pPixmap = exaGetDrawablePixmap(pDst);
 
 	exaGetDrawableDeltas(pSrc, pPixmap, &xoff, &yoff);
-	REGION_INIT(pScreen, &reg, pbox, nbox);
-	REGION_TRANSLATE(pScreen, &reg, xoff, yoff);
+	RegionInit(&reg, pbox, nbox);
+	RegionTranslate(&reg, xoff, yoff);
 	pExaScr->prepare_access_reg(pPixmap, EXA_PREPARE_DEST, &reg);
-	REGION_UNINIT(pScreen, &reg);
+	RegionUninit(&reg);
     } else
 	exaPrepareAccess (pDst, EXA_PREPARE_DEST);
 
@@ -188,9 +188,9 @@ ExaFallbackPrepareReg(DrawablePtr pDrawable,
 	box.x2 = box.x1 + width;
 	box.y2 = box.y1 + height;
 
-	REGION_INIT(pScreen, &reg, &box, 1);
+	RegionInit(&reg, &box, 1);
 	pExaScr->prepare_access_reg(pPixmap, index, &reg);
-	REGION_UNINIT(pScreen, &reg);
+	RegionUninit(&reg);
     } else
 	exaPrepareAccess(pDrawable, index);
 }
@@ -382,9 +382,9 @@ ExaCheckCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 	int xoff, yoff;
 
 	exaGetDrawableDeltas(&pWin->drawable, pPixmap, &xoff, &yoff);
-	REGION_TRANSLATE(pScreen, prgnSrc, xoff, yoff);
+	RegionTranslate(prgnSrc, xoff, yoff);
 	pExaScr->prepare_access_reg(pPixmap, EXA_PREPARE_SRC, prgnSrc);
-	REGION_TRANSLATE(pScreen, prgnSrc, -xoff, -yoff);
+	RegionTranslate(prgnSrc, -xoff, -yoff);
     } else
 	exaPrepareAccess(pDrawable, EXA_PREPARE_SRC);
 
@@ -458,9 +458,9 @@ ExaSrcValidate(DrawablePtr pDrawable,
     dst = (pExaScr->srcPix == pPix) ? &pExaScr->srcReg :
 	&pExaScr->maskReg;
 
-    REGION_INIT(pScreen, &reg, &box, 1);
-    REGION_UNION(pScreen, dst, dst, &reg);
-    REGION_UNINIT(pScreen, &reg);
+    RegionInit(&reg, &box, 1);
+    RegionUnion(dst, dst, &reg);
+    RegionUninit(&reg);
 
     if (pExaScr->SavedSourceValidate) {
         swap(pExaScr, pScreen, SourceValidate);
@@ -495,30 +495,30 @@ ExaPrepareCompositeReg(ScreenPtr  pScreen,
     Bool ret;
 
 
-    REGION_NULL(pScreen, &region);
+    RegionNull(&region);
 
     if (pSrc->pDrawable) {
 	pSrcPix = exaGetDrawablePixmap(pSrc->pDrawable);
-	REGION_NULL(pScreen, &pExaScr->srcReg);
+	RegionNull(&pExaScr->srcReg);
 	srcReg = &pExaScr->srcReg;
 	pExaScr->srcPix = pSrcPix;
 	if (pSrc != pDst)
-	    REGION_TRANSLATE(pScreen, pSrc->pCompositeClip,
+	    RegionTranslate(pSrc->pCompositeClip,
 			     -pSrc->pDrawable->x,
 			     -pSrc->pDrawable->y);
     }
 
     if (pMask && pMask->pDrawable) {
 	pMaskPix = exaGetDrawablePixmap(pMask->pDrawable);
-	REGION_NULL(pScreen, &pExaScr->maskReg);
+	RegionNull(&pExaScr->maskReg);
 	maskReg = &pExaScr->maskReg;
 	if (pMask != pDst && pMask != pSrc)
-	    REGION_TRANSLATE(pScreen, pMask->pCompositeClip,
+	    RegionTranslate(pMask->pCompositeClip,
 			     -pMask->pDrawable->x,
 			     -pMask->pDrawable->y);
     }
 
-    REGION_TRANSLATE(pScreen, pDst->pCompositeClip,
+    RegionTranslate(pDst->pCompositeClip,
 		     -pDst->pDrawable->x,
 		     -pDst->pDrawable->y);
 
@@ -531,23 +531,23 @@ ExaPrepareCompositeReg(ScreenPtr  pScreen,
 				    width, height);
     swap(pExaScr, pScreen, SourceValidate);
 
-    REGION_TRANSLATE(pScreen, pDst->pCompositeClip,
+    RegionTranslate(pDst->pCompositeClip,
 		     pDst->pDrawable->x,
 		     pDst->pDrawable->y);
     if (pSrc->pDrawable && pSrc != pDst)
-	REGION_TRANSLATE(pScreen, pSrc->pCompositeClip,
+	RegionTranslate(pSrc->pCompositeClip,
 			 pSrc->pDrawable->x,
 			 pSrc->pDrawable->y);
     if (pMask && pMask->pDrawable && pMask != pDst && pMask != pSrc)
-	REGION_TRANSLATE(pScreen, pMask->pCompositeClip,
+	RegionTranslate(pMask->pCompositeClip,
 			 pMask->pDrawable->x,
 			 pMask->pDrawable->y);
 
     if (!ret) {
 	if (srcReg)
-	    REGION_UNINIT(pScreen, srcReg);
+	    RegionUninit(srcReg);
 	if (maskReg)
-	    REGION_UNINIT(pScreen, maskReg);
+	    RegionUninit(maskReg);
 
 	return FALSE;
     }
@@ -577,9 +577,9 @@ ExaPrepareCompositeReg(ScreenPtr  pScreen,
 				    maskReg);
 
     if (srcReg)
-	REGION_UNINIT(pScreen, srcReg);
+	RegionUninit(srcReg);
     if (maskReg)
-	REGION_UNINIT(pScreen, maskReg);
+	RegionUninit(maskReg);
 
     pDstPix = exaGetDrawablePixmap(pDst->pDrawable);
     if (!exaOpReadsDestination(op)) {
@@ -587,7 +587,7 @@ ExaPrepareCompositeReg(ScreenPtr  pScreen,
 	int yoff;
 
 	exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &xoff, &yoff);
-	REGION_TRANSLATE(pScreen, &region, pDst->pDrawable->x + xoff,
+	RegionTranslate(&region, pDst->pDrawable->x + xoff,
 			 pDst->pDrawable->y + yoff);
 	dstReg = &region;
     }
@@ -598,7 +598,7 @@ ExaPrepareCompositeReg(ScreenPtr  pScreen,
 				    dstReg);
     pExaScr->prepare_access_reg(pDstPix, EXA_PREPARE_DEST, dstReg);
 
-    REGION_UNINIT(pScreen, &region);
+    RegionUninit(&region);
     return TRUE;
 }
 
diff --git a/fb/fb.h b/fb/fb.h
index e2222a5..7ab4adf 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -739,7 +739,7 @@ typedef struct {
  */
 
 #define fbWindowEnabled(pWin) \
-    REGION_NOTEMPTY((pWin)->drawable.pScreen, \
+    RegionNotEmpty(\
 		    &(pWin)->drawable.pScreen->root->borderClip)
 
 #define fbDrawableEnabled(pDrawable) \
diff --git a/fb/fb24_32.c b/fb/fb24_32.c
index 1ebd598..2e600ed 100644
--- a/fb/fb24_32.c
+++ b/fb/fb24_32.c
@@ -335,8 +335,8 @@ fb24_32SetSpans (DrawablePtr	    pDrawable,
     {
 	d = dst + (ppt->y + dstYoff) * dstStride;
 	s = (CARD8 *) src;
-	n = REGION_NUM_RECTS(pClip);
-	pbox = REGION_RECTS (pClip);
+	n = RegionNumRects(pClip);
+	pbox = RegionRects (pClip);
 	while (n--)
 	{
 	    if (pbox->y1 > ppt->y)
@@ -399,8 +399,8 @@ fb24_32PutZImage (DrawablePtr	pDrawable,
     dstStride *= sizeof(FbBits);
     dst = (CARD8 *) dstBits;
 
-    for (nbox = REGION_NUM_RECTS (pClip),
-	 pbox = REGION_RECTS(pClip);
+    for (nbox = RegionNumRects (pClip),
+	 pbox = RegionRects(pClip);
 	 nbox--;
 	 pbox++)
     {
diff --git a/fb/fbarc.c b/fb/fbarc.c
index 3a8a2c5..33e44b0 100644
--- a/fb/fbarc.c
+++ b/fb/fbarc.c
@@ -102,7 +102,7 @@ fbPolyArc (DrawablePtr	pDrawable,
 		    y2 = box.y1 + (int)parcs->height + 1;
 		    box.y2 = y2;
 		    if ( (x2 <= SHRT_MAX) && (y2 <= SHRT_MAX) &&
-			(RECT_IN_REGION(pDrawable->pScreen, cclip, &box) == rgnIN) ) {
+			(RegionContainsRect(cclip, &box) == rgnIN) ) {
 #ifdef FB_ACCESS_WRAPPER
 			if (!wrapped) {
 			    fbPrepareAccess (pDrawable);
diff --git a/fb/fbbits.h b/fb/fbbits.h
index 44991f1..8bf1a02 100644
--- a/fb/fbbits.h
+++ b/fb/fbbits.h
@@ -670,7 +670,7 @@ POLYLINE (DrawablePtr	pDrawable,
     int		    xoff = pDrawable->x;
     int		    yoff = pDrawable->y;
     unsigned int    bias = miGetZeroLineBias(pDrawable->pScreen);
-    BoxPtr	    pBox = REGION_EXTENTS (pDrawable->pScreen, fbGetCompositeClip (pGC));
+    BoxPtr	    pBox = RegionExtents(fbGetCompositeClip (pGC));
     
     FbBits	    *dst;
     int		    dstStride;
@@ -807,7 +807,7 @@ POLYSEGMENT (DrawablePtr    pDrawable,
     int		    xoff = pDrawable->x;
     int		    yoff = pDrawable->y;
     unsigned int    bias = miGetZeroLineBias(pDrawable->pScreen);
-    BoxPtr	    pBox = REGION_EXTENTS (pDrawable->pScreen, fbGetCompositeClip (pGC));
+    BoxPtr	    pBox = RegionExtents(fbGetCompositeClip (pGC));
     
     FbBits	    *dst;
     int		    dstStride;
diff --git a/fb/fbfill.c b/fb/fbfill.c
index 831b1ce..801a0d0 100644
--- a/fb/fbfill.c
+++ b/fb/fbfill.c
@@ -185,7 +185,7 @@ fbSolidBoxClipped (DrawablePtr	pDrawable,
 
     fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
     
-    for (nbox = REGION_NUM_RECTS(pClip), pbox = REGION_RECTS(pClip); 
+    for (nbox = RegionNumRects(pClip), pbox = RegionRects(pClip);
 	 nbox--; 
 	 pbox++)
     {
diff --git a/fb/fbfillrect.c b/fb/fbfillrect.c
index 4e4edb3..7fc03f9 100644
--- a/fb/fbfillrect.c
+++ b/fb/fbfillrect.c
@@ -44,7 +44,7 @@ fbPolyFillRect(DrawablePtr  pDrawable,
     xorg = pDrawable->x;
     yorg = pDrawable->y;
     
-    pextent = REGION_EXTENTS(pGC->pScreen, pClip);
+    pextent = RegionExtents(pClip);
     extentX1 = pextent->x1;
     extentY1 = pextent->y1;
     extentX2 = pextent->x2;
@@ -71,7 +71,7 @@ fbPolyFillRect(DrawablePtr  pDrawable,
 
 	if ((fullX1 >= fullX2) || (fullY1 >= fullY2))
 	    continue;
-	n = REGION_NUM_RECTS (pClip);
+	n = RegionNumRects (pClip);
 	if (n == 1)
 	{
 	    fbFill (pDrawable,
@@ -80,7 +80,7 @@ fbPolyFillRect(DrawablePtr  pDrawable,
 	}
 	else
 	{
-	    pbox = REGION_RECTS(pClip);
+	    pbox = RegionRects(pClip);
 	    /* 
 	     * clip the rectangle to each box in the clip region
 	     * this is logically equivalent to calling Intersect()
diff --git a/fb/fbfillsp.c b/fb/fbfillsp.c
index 5d21472..194bfc8 100644
--- a/fb/fbfillsp.c
+++ b/fb/fbfillsp.c
@@ -41,7 +41,7 @@ fbFillSpans (DrawablePtr    pDrawable,
     int		    fullX1, fullX2, fullY1;
     int		    partX1, partX2;
     
-    pextent = REGION_EXTENTS(pGC->pScreen, pClip);
+    pextent = RegionExtents(pClip);
     extentX1 = pextent->x1;
     extentY1 = pextent->y1;
     extentX2 = pextent->x2;
@@ -66,7 +66,7 @@ fbFillSpans (DrawablePtr    pDrawable,
 	if (fullX1 >= fullX2)
 	    continue;
 	
-	nbox = REGION_NUM_RECTS (pClip);
+	nbox = RegionNumRects (pClip);
 	if (nbox == 1)
 	{
 	    fbFill (pDrawable,
@@ -75,7 +75,7 @@ fbFillSpans (DrawablePtr    pDrawable,
 	}
 	else
 	{
-	    pbox = REGION_RECTS(pClip);
+	    pbox = RegionRects(pClip);
 	    while(nbox--)
 	    {
 		if (pbox->y1 <= fullY1 && fullY1 < pbox->y2)
diff --git a/fb/fbgc.c b/fb/fbgc.c
index fda391b..e3e9236 100644
--- a/fb/fbgc.c
+++ b/fb/fbgc.c
@@ -213,7 +213,7 @@ fbValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
 	)
     {
 	miComputeCompositeClip (pGC, pDrawable);
-	pPriv->oneRect = REGION_NUM_RECTS(fbGetCompositeClip(pGC)) == 1;
+	pPriv->oneRect = RegionNumRects(fbGetCompositeClip(pGC)) == 1;
     }
     
 #ifdef FB_24_32BIT    
diff --git a/fb/fbglyph.c b/fb/fbglyph.c
index 2c19b74..44fe80f 100644
--- a/fb/fbglyph.c
+++ b/fb/fbglyph.c
@@ -39,7 +39,7 @@ fbGlyphIn (RegionPtr	pRegion,
 	   int		height)
 {
     BoxRec  box;
-    BoxPtr  pExtents = REGION_EXTENTS (dummyScreen, pRegion);
+    BoxPtr  pExtents = RegionExtents(pRegion);
 
     /*
      * Check extents by hand to avoid 16 bit overflows
@@ -56,7 +56,7 @@ fbGlyphIn (RegionPtr	pRegion,
     box.x2 = x + width;
     box.y1 = y;
     box.y2 = y + height;
-    return RECT_IN_REGION (dummyScreen, pRegion, &box) == rgnIN;
+    return RegionContainsRect(pRegion, &box) == rgnIN;
 }
 
 #ifdef FB_24BIT
diff --git a/fb/fbimage.c b/fb/fbimage.c
index 2b9ac27..da1e8bc 100644
--- a/fb/fbimage.c
+++ b/fb/fbimage.c
@@ -134,8 +134,8 @@ fbPutZImage (DrawablePtr	pDrawable,
 
     fbGetStipDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
 
-    for (nbox = REGION_NUM_RECTS (pClip),
-	 pbox = REGION_RECTS(pClip);
+    for (nbox = RegionNumRects (pClip),
+	 pbox = RegionRects(pClip);
 	 nbox--;
 	 pbox++)
     {
@@ -224,8 +224,8 @@ fbPutXYImage (DrawablePtr	pDrawable,
 	}
     }
 
-    for (nbox = REGION_NUM_RECTS (pClip),
-	 pbox = REGION_RECTS(pClip);
+    for (nbox = RegionNumRects (pClip),
+	 pbox = RegionRects(pClip);
 	 nbox--;
 	 pbox++)
     {
diff --git a/fb/fbline.c b/fb/fbline.c
index 2cee123..fa80573 100644
--- a/fb/fbline.c
+++ b/fb/fbline.c
@@ -117,7 +117,7 @@ fbPolyLine (DrawablePtr	pDrawable,
 #ifndef FBNOPIXADDR
 	if (pGC->fillStyle == FillSolid &&
 	    pGC->lineStyle == LineSolid &&
-	    REGION_NUM_RECTS (fbGetCompositeClip(pGC)) == 1)
+	    RegionNumRects (fbGetCompositeClip(pGC)) == 1)
 	{
 	    switch (pDrawable->bitsPerPixel) {
 	    case 8:  line = fbPolyline8; break;
@@ -154,7 +154,7 @@ fbPolySegment (DrawablePtr  pDrawable,
 #ifndef FBNOPIXADDR
 	if (pGC->fillStyle == FillSolid &&
 	    pGC->lineStyle == LineSolid &&
-	    REGION_NUM_RECTS (fbGetCompositeClip(pGC)) == 1)
+	    RegionNumRects (fbGetCompositeClip(pGC)) == 1)
 	{
 	    switch (pDrawable->bitsPerPixel) {
 	    case 8:  seg = fbPolySegment8; break;
diff --git a/fb/fboverlay.c b/fb/fboverlay.c
index 3eb1b03..392e27f 100644
--- a/fb/fboverlay.c
+++ b/fb/fboverlay.c
@@ -75,7 +75,7 @@ fbOverlayCreateWindow(WindowPtr pWin)
 	     */
 	    if (!pWin->parent)
 	    {
-		REGION_EMPTY (pWin->drawable.pScreen,
+		RegionEmpty(
 			      &pScrPriv->layer[i].u.run.region);
 	    }
 	    return TRUE;
@@ -93,7 +93,7 @@ fbOverlayCloseScreen (int iScreen, ScreenPtr pScreen)
     for (i = 0; i < pScrPriv->nlayers; i++)
     {
 	(*pScreen->DestroyPixmap)(pScrPriv->layer[i].u.run.pixmap);
-	REGION_UNINIT (pScreen, &pScrPriv->layer[i].u.run.region);
+	RegionUninit(&pScrPriv->layer[i].u.run.region);
     }
     return TRUE;
 }
@@ -147,7 +147,7 @@ fbOverlayCreateScreenResources(ScreenPtr pScreen)
 					    pbits))
 	    return FALSE;
 	pScrPriv->layer[i].u.run.pixmap = pPixmap;
-	REGION_INIT(pScreen, &pScrPriv->layer[i].u.run.region, &box, 0);
+	RegionInit(&pScrPriv->layer[i].u.run.region, &box, 0);
     }
     pScreen->devPrivate = pScrPriv->layer[0].u.run.pixmap;
     return TRUE;
@@ -175,24 +175,24 @@ fbOverlayUpdateLayerRegion (ScreenPtr	pScreen,
     int			i;
     RegionRec		rgnNew;
     
-    if (!prgn || !REGION_NOTEMPTY(pScreen, prgn))
+    if (!prgn || !RegionNotEmpty(prgn))
 	return;
     for (i = 0; i < pScrPriv->nlayers; i++)
     {
 	if (i == layer)
 	{
 	    /* add new piece to this fb */
-	    REGION_UNION (pScreen,
+	    RegionUnion(
 			  &pScrPriv->layer[i].u.run.region,
 			  &pScrPriv->layer[i].u.run.region,
 			  prgn);
 	}
-	else if (REGION_NOTEMPTY (pScreen, 
+	else if (RegionNotEmpty(
 				  &pScrPriv->layer[i].u.run.region))
 	{
 	    /* paint new piece with chroma key */
-	    REGION_NULL (pScreen, &rgnNew);
-	    REGION_INTERSECT (pScreen,
+	    RegionNull(&rgnNew);
+	    RegionIntersect(
 			      &rgnNew, 
 			      prgn, 
 			      &pScrPriv->layer[i].u.run.region);
@@ -200,9 +200,9 @@ fbOverlayUpdateLayerRegion (ScreenPtr	pScreen,
 				   &rgnNew,
 				   pScrPriv->layer[i].key,
 				   i);
-	    REGION_UNINIT(pScreen, &rgnNew);
+	    RegionUninit(&rgnNew);
 	    /* remove piece from other fbs */
-	    REGION_SUBTRACT (pScreen,
+	    RegionSubtract(
 			     &pScrPriv->layer[i].u.run.region,
 			     &pScrPriv->layer[i].u.run.region,
 			     prgn);
@@ -232,21 +232,21 @@ fbOverlayCopyWindow(WindowPtr	pWin,
     /*
      * Clip to existing bits
      */
-    REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy);
-    REGION_NULL (pScreen, &rgnDst);
-    REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
-    REGION_TRANSLATE(pScreen, &rgnDst, dx, dy);
+    RegionTranslate(prgnSrc, -dx, -dy);
+    RegionNull(&rgnDst);
+    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
+    RegionTranslate(&rgnDst, dx, dy);
     /*
      * Compute the portion of each fb affected by this copy
      */
     for (i = 0; i < pScrPriv->nlayers; i++)
     {
-	REGION_NULL (pScreen, &layerRgn[i]);
-	REGION_INTERSECT(pScreen, &layerRgn[i], &rgnDst,
+	RegionNull(&layerRgn[i]);
+	RegionIntersect(&layerRgn[i], &rgnDst,
 			 &pScrPriv->layer[i].u.run.region);
-	if (REGION_NOTEMPTY (pScreen, &layerRgn[i]))
+	if (RegionNotEmpty(&layerRgn[i]))
 	{
-	    REGION_TRANSLATE(pScreen, &layerRgn[i], -dx, -dy);
+	    RegionTranslate(&layerRgn[i], -dx, -dy);
 	    pPixmap = pScrPriv->layer[i].u.run.pixmap;
 	    miCopyRegion (&pPixmap->drawable, &pPixmap->drawable,
 			  0,
@@ -259,12 +259,12 @@ fbOverlayCopyWindow(WindowPtr	pWin,
      */
     for (i = 0; i < pScrPriv->nlayers; i++)
     {
-	if (REGION_NOTEMPTY (pScreen, &layerRgn[i]))
+	if (RegionNotEmpty(&layerRgn[i]))
 	    fbOverlayUpdateLayerRegion (pScreen, i, &layerRgn[i]);
 
-	REGION_UNINIT(pScreen, &layerRgn[i]);
+	RegionUninit(&layerRgn[i]);
     }
-    REGION_UNINIT(pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
 }   
 
 void
diff --git a/fb/fbpict.c b/fb/fbpict.c
index 896d33e..26cdc0d 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -77,8 +77,8 @@ fbWalkCompositeRegion (CARD8 op,
 				   xMask, yMask, xDst, yDst, width, height))
         return;
     
-    n = REGION_NUM_RECTS (&region);
-    pbox = REGION_RECTS (&region);
+    n = RegionNumRects (&region);
+    pbox = RegionRects (&region);
     while (n--)
     {
 	h = pbox->y2 - pbox->y1;
@@ -138,7 +138,7 @@ fbWalkCompositeRegion (CARD8 op,
 	}
 	pbox++;
     }
-    REGION_UNINIT (pDst->pDrawable->pScreen, &region);
+    RegionUninit(&region);
 }
 
 void
diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index cbaab33..625ce71 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -116,7 +116,7 @@ if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&			\
     if ((reg)->data->numRects == (reg)->data->size)		\
     {								\
 	RegionRectAlloc(reg, 1);					\
-	fr = REGION_BOXPTR(reg);				\
+	fr = RegionBoxptr(reg);				\
 	r = fr + (reg)->data->numRects;				\
     }								\
     r->x1 = (rx1);						\
@@ -153,10 +153,10 @@ fbPixmapToRegion(PixmapPtr pPix)
     FbBits		*pwLine;
     int			nWidth;
     
-    pReg = REGION_CREATE(pPix->drawable.pScreen, NULL, 1);
+    pReg = RegionCreate(NULL, 1);
     if(!pReg)
 	return NullRegion;
-    FirstRect = REGION_BOXPTR(pReg);
+    FirstRect = RegionBoxptr(pReg);
     rects = FirstRect;
 
     fbPrepareAccess(&pPix->drawable);
@@ -304,8 +304,8 @@ fbPixmapToRegion(PixmapPtr pPix)
 	pReg->extents.x1 = pReg->extents.x2 = 0;
     else
     {
-	pReg->extents.y1 = REGION_BOXPTR(pReg)->y1;
-	pReg->extents.y2 = REGION_END(pReg)->y2;
+	pReg->extents.y1 = RegionBoxptr(pReg)->y1;
+	pReg->extents.y2 = RegionEnd(pReg)->y2;
 	if (pReg->data->numRects == 1)
 	{
 	    free(pReg->data);
diff --git a/fb/fbpoint.c b/fb/fbpoint.c
index c0ea8ba..f260a69 100644
--- a/fb/fbpoint.c
+++ b/fb/fbpoint.c
@@ -154,7 +154,7 @@ fbPolyPoint (DrawablePtr    pDrawable,
     case 32:    dots = fbDots32; break;
     }
 #endif
-    for (nBox = REGION_NUM_RECTS (pClip), pBox = REGION_RECTS (pClip);
+    for (nBox = RegionNumRects (pClip), pBox = RegionRects (pClip);
 	 nBox--; pBox++)
 	(*dots) (dst, dstStride, dstBpp, pBox, pptInit, nptInit, 
 		 pDrawable->x, pDrawable->y, dstXoff, dstYoff, and, xor);
diff --git a/fb/fbpush.c b/fb/fbpush.c
index 891572f..9d82718 100644
--- a/fb/fbpush.c
+++ b/fb/fbpush.c
@@ -190,8 +190,8 @@ fbPushImage (DrawablePtr    pDrawable,
     BoxPtr	pbox;
     int		x1, y1, x2, y2;
     
-    for (nbox = REGION_NUM_RECTS (pClip),
-	 pbox = REGION_RECTS(pClip);
+    for (nbox = RegionNumRects (pClip),
+	 pbox = RegionRects(pClip);
 	 nbox--;
 	 pbox++)
     {
diff --git a/fb/fbseg.c b/fb/fbseg.c
index 999be1c..7cc38a2 100644
--- a/fb/fbseg.c
+++ b/fb/fbseg.c
@@ -624,8 +624,8 @@ fbSegment (DrawablePtr	pDrawable,
     unsigned int oc1;	/* outcode of point 1 */
     unsigned int oc2;	/* outcode of point 2 */
 
-    nBox = REGION_NUM_RECTS (pClip);
-    pBox = REGION_RECTS (pClip);
+    nBox = RegionNumRects (pClip);
+    pBox = RegionRects (pClip);
     
     bres = fbSelectBres (pDrawable, pGC);
     
diff --git a/fb/fbsetsp.c b/fb/fbsetsp.c
index 227ba4c..61dc4dc 100644
--- a/fb/fbsetsp.c
+++ b/fb/fbsetsp.c
@@ -60,8 +60,8 @@ fbSetSpans (DrawablePtr	    pDrawable,
 	xoff = (int) (((long) src) & (FB_MASK >> 3));
 	s = (FbBits *) (src - xoff);
 	xoff <<= 3;
-	n = REGION_NUM_RECTS(pClip);
-	pbox = REGION_RECTS (pClip);
+	n = RegionNumRects(pClip);
+	pbox = RegionRects (pClip);
 	while (n--)
 	{
 	    if (pbox->y1 > ppt->y)
diff --git a/fb/fbwindow.c b/fb/fbwindow.c
index 46c0334..bb0384d 100644
--- a/fb/fbwindow.c
+++ b/fb/fbwindow.c
@@ -128,15 +128,15 @@ fbCopyWindow(WindowPtr	    pWin,
 
     dx = ptOldOrg.x - pWin->drawable.x;
     dy = ptOldOrg.y - pWin->drawable.y;
-    REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
+    RegionTranslate(prgnSrc, -dx, -dy);
 
-    REGION_NULL (pWin->drawable.pScreen, &rgnDst);
+    RegionNull(&rgnDst);
     
-    REGION_INTERSECT(pWin->drawable.pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
+    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
 
 #ifdef COMPOSITE
     if (pPixmap->screen_x || pPixmap->screen_y)
-	REGION_TRANSLATE (pWin->drawable.pScreen, &rgnDst, 
+	RegionTranslate(&rgnDst,
 			  -pPixmap->screen_x, -pPixmap->screen_y);
 #endif
 
@@ -144,7 +144,7 @@ fbCopyWindow(WindowPtr	    pWin,
 		  0,
 		  &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
     
-    REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
     fbValidateDrawable (&pWin->drawable);
 }
 
@@ -211,8 +211,8 @@ fbFillRegionSolid (DrawablePtr	pDrawable,
     FbStride	dstStride;
     int		dstBpp;
     int		dstXoff, dstYoff;
-    int		n = REGION_NUM_RECTS(pRegion);
-    BoxPtr	pbox = REGION_RECTS(pRegion);
+    int		n = RegionNumRects(pRegion);
+    BoxPtr	pbox = RegionRects(pRegion);
 
 #ifndef FB_ACCESS_WRAPPER
     int try_mmx = 0;
diff --git a/fix-patch-whitespace b/fix-patch-whitespace
new file mode 100755
index 0000000..2d06d8e
--- /dev/null
+++ b/fix-patch-whitespace
@@ -0,0 +1,4 @@
+#!/bin/sh
+git diff --check |
+sed -n 's!^\([^:]*\):\([^:]*\):.*!sed -i "\2 s/[ \t]*$//; \2 s/ *\t/\t/g" \1!p' |
+sh
diff --git a/fix-region b/fix-region
new file mode 100755
index 0000000..ef8eb42
--- /dev/null
+++ b/fix-region
@@ -0,0 +1,38 @@
+#!/bin/sh
+sed -i \
+    -e 's/REGION_NIL\b/RegionNil/g' \
+    -e 's/REGION_NAR\b/RegionNar/g' \
+    -e 's/REGION_NUM_RECTS\b/RegionNumRects/g' \
+    -e 's/REGION_SIZE\b/RegionSize/g' \
+    -e 's/REGION_RECTS\b/RegionRects/g' \
+    -e 's/REGION_BOXPTR\b/RegionBoxptr/g' \
+    -e 's/REGION_BOX\b/RegionBox/g' \
+    -e 's/REGION_TOP\b/RegionTop/g' \
+    -e 's/REGION_END\b/RegionEnd/g' \
+    -e 's/REGION_SZOF\b/RegionSizeof/g' \
+    -e 's/REGION_CREATE *([^,]*, */RegionCreate(/g' \
+    -e 's/REGION_COPY *([^,]*, */RegionCopy(/g' \
+    -e 's/REGION_DESTROY *([^,]*, */RegionDestroy(/g' \
+    -e 's/REGION_INTERSECT *([^,]*, */RegionIntersect(/g' \
+    -e 's/REGION_UNION *([^,]*, */RegionUnion(/g' \
+    -e 's/REGION_SUBTRACT *([^,]*, */RegionSubtract(/g' \
+    -e 's/REGION_INVERSE *([^,]*, */RegionInverse(/g' \
+    -e 's/REGION_TRANSLATE *([^,]*, */RegionTranslate(/g' \
+    -e 's/RECT_IN_REGION *([^,]*, */RegionContainsRect(/g' \
+    -e 's/POINT_IN_REGION *([^,]*, */RegionContainsPoint(/g' \
+    -e 's/REGION_EQUAL *([^,]*, */RegionEqual(/g' \
+    -e 's/REGION_APPEND *([^,]*, */RegionAppend(/g' \
+    -e 's/REGION_VALIDATE *([^,]*, */RegionValidate(/g' \
+    -e 's/BITMAP_TO_REGION\b/BitmapToRegion/g' \
+    -e 's/RECTS_TO_REGION *([^,]*, */RegionFromRects(/g' \
+    -e 's/REGION_BREAK *([^,]*, */RegionBreak(/g' \
+    -e 's/REGION_INIT *([^,]*, */RegionInit(/g' \
+    -e 's/REGION_UNINIT *([^,]*, */RegionUninit(/g' \
+    -e 's/REGION_RESET *([^,]*, */RegionReset(/g' \
+    -e 's/REGION_NOTEMPTY *([^,]*, */RegionNotEmpty(/g' \
+    -e 's/REGION_BROKEN *([^,]*, */RegionBroken(/g' \
+    -e 's/REGION_EMPTY *([^,]*, */RegionEmpty(/g' \
+    -e 's/REGION_EXTENTS *([^,]*, */RegionExtents(/g' \
+    -e 's/REGION_NULL *([^,]*, */RegionNull(/g' \
+    -e 's/REGION_NULL$/RegionNull/g' \
+    "$@"
diff --git a/glx/glxdri.c b/glx/glxdri.c
index 131efcf..32b35db 100644
--- a/glx/glxdri.c
+++ b/glx/glxdri.c
@@ -468,7 +468,7 @@ nooverride:
 	pRegion = NULL;
     } else {
 	pRegion = DamageRegion(driDraw->pDamage);
-	if (REGION_NIL(pRegion))
+	if (RegionNil(pRegion))
 	    return Success;
     }
 
@@ -531,8 +531,8 @@ nooverride:
         int i, numRects;
 	BoxPtr p;
 
-	numRects = REGION_NUM_RECTS (pRegion);
-	p = REGION_RECTS (pRegion);
+	numRects = RegionNumRects (pRegion);
+	p = RegionRects (pRegion);
 
 	CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_PIXELS, 0) );
 	CALL_PixelStorei( GET_DISPATCH(), (GL_UNPACK_SKIP_ROWS, 0) );
@@ -832,12 +832,12 @@ static void __glXReportDamage(__DRIdrawable *driDraw,
 
     __glXenterServer(GL_FALSE);
 
-    REGION_INIT(pDraw->pScreen, &region, (BoxPtr) rects, num_rects);
-    REGION_TRANSLATE(pScreen, &region, pDraw->x, pDraw->y);
+    RegionInit(&region, (BoxPtr) rects, num_rects);
+    RegionTranslate(&region, pDraw->x, pDraw->y);
     DamageRegionAppend(pDraw, &region);
     /* This is wrong, this needs a seperate function. */
     DamageRegionProcessPending(pDraw);
-    REGION_UNINIT(pDraw->pScreen, &region);
+    RegionUninit(&region);
 
     __glXleaveServer(GL_FALSE);
 }
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index b971102..177c73c 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -122,7 +122,7 @@ __glXDRIdrawableCopySubBuffer(__GLXdrawable *drawable,
     box.y1 = private->height - y - h;
     box.x2 = x + w;
     box.y2 = private->height - y;
-    REGION_INIT(drawable->pDraw->pScreen, &region, &box, 0);
+    RegionInit(&region, &box, 0);
 
     DRI2CopyRegion(drawable->pDraw, &region,
 		   DRI2BufferFrontLeft, DRI2BufferBackLeft);
@@ -139,7 +139,7 @@ __glXDRIdrawableWaitX(__GLXdrawable *drawable)
     box.y1 = 0;
     box.x2 = private->width;
     box.y2 = private->height;
-    REGION_INIT(drawable->pDraw->pScreen, &region, &box, 0);
+    RegionInit(&region, &box, 0);
 
     DRI2CopyRegion(drawable->pDraw, &region,
 		   DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft);
@@ -156,7 +156,7 @@ __glXDRIdrawableWaitGL(__GLXdrawable *drawable)
     box.y1 = 0;
     box.x2 = private->width;
     box.y2 = private->height;
-    REGION_INIT(drawable->pDraw->pScreen, &region, &box, 0);
+    RegionInit(&region, &box, 0);
 
     DRI2CopyRegion(drawable->pDraw, &region,
 		   DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft);
diff --git a/hw/dmx/dmxextension.c b/hw/dmx/dmxextension.c
index 5945a5e..0092835 100644
--- a/hw/dmx/dmxextension.c
+++ b/hw/dmx/dmxextension.c
@@ -350,7 +350,7 @@ void dmxUpdateScreenResources(ScreenPtr pScreen, int x, int y, int w, int h)
 	 * clipList to be broken since it will be recalculated in
 	 * ValidateTree()
 	 */
-	REGION_BREAK(pScreen, &pRoot->clipList);
+	RegionBreak(&pRoot->clipList);
     } else {
 	/* Otherwise, we just set it directly since there are no
 	 * windows visible on this screen
@@ -994,7 +994,7 @@ static void dmxForceExposures(int idx)
 	 * clipList to be broken since it will be recalculated in
 	 * ValidateTree()
 	 */
-	REGION_BREAK(pScreen, &pRoot->clipList);
+	RegionBreak(&pRoot->clipList);
 	pScreen->ValidateTree(pRoot, NULL, VTBroken);
 	pScreen->HandleExposures(pRoot);
 	if (pScreen->PostValidateTree)
diff --git a/hw/dmx/dmxgc.c b/hw/dmx/dmxgc.c
index a761ea8..3e75de7 100644
--- a/hw/dmx/dmxgc.c
+++ b/hw/dmx/dmxgc.c
@@ -363,9 +363,9 @@ void dmxChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects)
 
     case CT_REGION:
 	if (dmxScreen->beDisplay) {
-	    nRects = REGION_NUM_RECTS((RegionPtr)pGC->clientClip);
+	    nRects = RegionNumRects((RegionPtr)pGC->clientClip);
 	    pRects = malloc(nRects * sizeof(*pRects));
-	    pBox   = REGION_RECTS((RegionPtr)pGC->clientClip);
+	    pBox   = RegionRects((RegionPtr)pGC->clientClip);
 
 	    for (i = 0; i < nRects; i++) {
 		pRects[i].x      = pBox[i].x1;
diff --git a/hw/dmx/dmxgcops.c b/hw/dmx/dmxgcops.c
index 267a306..589c637 100644
--- a/hw/dmx/dmxgcops.c
+++ b/hw/dmx/dmxgcops.c
@@ -127,16 +127,16 @@ void dmxPutImage(DrawablePtr pDrawable, GCPtr pGC,
 	    box.y1 = y;
 	    box.x2 = x + w;
 	    box.y2 = y + h;
-	    pSubImages = REGION_CREATE(pGC->pScreen, &box, 1);
+	    pSubImages = RegionCreate(&box, 1);
 
-	    pClip = REGION_CREATE(pGC->pScreen, NullBox, 1);
-	    REGION_COPY(pGC->pScreen, pClip, pGC->pCompositeClip);
-	    REGION_TRANSLATE(pGC->pScreen, pClip,
+	    pClip = RegionCreate(NullBox, 1);
+	    RegionCopy(pClip, pGC->pCompositeClip);
+	    RegionTranslate(pClip,
 			     -pDrawable->x, -pDrawable->y);
-	    REGION_INTERSECT(pGC->pScreen, pSubImages, pSubImages, pClip);
+	    RegionIntersect(pSubImages, pSubImages, pClip);
 
-	    nBox = REGION_NUM_RECTS(pSubImages);
-	    pBox = REGION_RECTS(pSubImages);
+	    nBox = RegionNumRects(pSubImages);
+	    pBox = RegionRects(pSubImages);
 
 	    while (nBox--) {
 		XPutImage(dmxScreen->beDisplay, draw, pGCPriv->gc, img,
@@ -148,8 +148,8 @@ void dmxPutImage(DrawablePtr pDrawable, GCPtr pGC,
 			  pBox->y2 - pBox->y1);
 		pBox++;
 	    }
-            REGION_DESTROY(pGC->pScreen, pClip);
-            REGION_DESTROY(pGC->pScreen, pSubImages);
+            RegionDestroy(pClip);
+            RegionDestroy(pSubImages);
 	} else {
 	    XPutImage(dmxScreen->beDisplay, draw, pGCPriv->gc,
 		      img, 0, 0, x, y, w, h);
diff --git a/hw/dmx/dmxpict.c b/hw/dmx/dmxpict.c
index 0544c88..1642145 100644
--- a/hw/dmx/dmxpict.c
+++ b/hw/dmx/dmxpict.c
@@ -871,8 +871,8 @@ int dmxChangePictureClip(PicturePtr pPicture, int clipType,
 				       pPictPriv->pict, 0, 0, None);
 	} else if (pPicture->clientClip) {
 	    RegionPtr   pClip = pPicture->clientClip;
-	    BoxPtr      pBox  = REGION_RECTS(pClip);
-	    int         nBox  = REGION_NUM_RECTS(pClip);
+	    BoxPtr      pBox  = RegionRects(pClip);
+	    int         nBox  = RegionNumRects(pClip);
 	    XRectangle *pRects;
 	    XRectangle *pRect;
 	    int         nRects;
diff --git a/hw/dmx/dmxpixmap.c b/hw/dmx/dmxpixmap.c
index c8b064b..a64cbd0 100644
--- a/hw/dmx/dmxpixmap.c
+++ b/hw/dmx/dmxpixmap.c
@@ -201,7 +201,7 @@ RegionPtr dmxBitmapToRegion(PixmapPtr pPixmap)
     Bool           overlap;
   
     if (!dmxScreen->beDisplay) {
-	pReg = REGION_CREATE(pScreen, NullBox, 1);
+	pReg = RegionCreate(NullBox, 1);
 	return pReg;
     }
 
@@ -209,8 +209,8 @@ RegionPtr dmxBitmapToRegion(PixmapPtr pPixmap)
 		       pPixmap->drawable.width, pPixmap->drawable.height,
 		       1, XYPixmap);
 
-    pReg = REGION_CREATE(pScreen, NullBox, 1);
-    pTmpReg = REGION_CREATE(pScreen, NullBox, 1);
+    pReg = RegionCreate(NullBox, 1);
+    pTmpReg = RegionCreate(NullBox, 1);
     if(!pReg || !pTmpReg) {
 	XDestroyImage(ximage);
 	return NullRegion;
@@ -229,8 +229,8 @@ RegionPtr dmxBitmapToRegion(PixmapPtr pPixmap)
 		} else if (currentPixel == 0L) {
 		    /* right edge */
 		    Box.x2 = x;
-		    REGION_RESET(pScreen, pTmpReg, &Box);
-		    REGION_APPEND(pScreen, pReg, pTmpReg);
+		    RegionReset(pTmpReg, &Box);
+		    RegionAppend(pReg, pTmpReg);
 		}
 		previousPixel = currentPixel;
 	    }
@@ -238,15 +238,15 @@ RegionPtr dmxBitmapToRegion(PixmapPtr pPixmap)
 	if (previousPixel != 0L) {
 	    /* right edge because of the end of pixmap */
 	    Box.x2 = pPixmap->drawable.width;
-	    REGION_RESET(pScreen, pTmpReg, &Box);
-	    REGION_APPEND(pScreen, pReg, pTmpReg);
+	    RegionReset(pTmpReg, &Box);
+	    RegionAppend(pReg, pTmpReg);
 	}
     }
   
-    REGION_DESTROY(pScreen, pTmpReg);
+    RegionDestroy(pTmpReg);
     XDestroyImage(ximage);
 
-    REGION_VALIDATE(pScreen, pReg, &overlap);
+    RegionValidate(pReg, &overlap);
 
     dmxSync(dmxScreen, FALSE);
     return(pReg);
diff --git a/hw/dmx/dmxshadow.c b/hw/dmx/dmxshadow.c
index 461fd08..a62eb5c 100644
--- a/hw/dmx/dmxshadow.c
+++ b/hw/dmx/dmxshadow.c
@@ -47,8 +47,8 @@
 void dmxShadowUpdateProc(ScreenPtr pScreen, shadowBufPtr pBuf)
 {
     RegionPtr      damage = &pBuf->damage;
-    int            nbox = REGION_NUM_RECTS(damage);
-    BoxPtr         pbox = REGION_RECTS(damage);
+    int            nbox = RegionNumRects(damage);
+    BoxPtr         pbox = RegionRects(damage);
     DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
 
     if (!dmxScreen->beDisplay)
diff --git a/hw/dmx/dmxwindow.c b/hw/dmx/dmxwindow.c
index 5b0baff..28212a3 100644
--- a/hw/dmx/dmxwindow.c
+++ b/hw/dmx/dmxwindow.c
@@ -940,8 +940,8 @@ static void dmxDoSetShape(WindowPtr pWindow)
 
     /* First, set the bounding shape */
     if (wBoundingShape(pWindow)) {
-	pBox = REGION_RECTS(wBoundingShape(pWindow));
-	nRect = nBox = REGION_NUM_RECTS(wBoundingShape(pWindow));
+	pBox = RegionRects(wBoundingShape(pWindow));
+	nRect = nBox = RegionNumRects(wBoundingShape(pWindow));
 	pRectFirst = pRect = malloc(nRect * sizeof(*pRect));
 	while (nBox--) {
 	    pRect->x      = pBox->x1;
@@ -963,8 +963,8 @@ static void dmxDoSetShape(WindowPtr pWindow)
 
     /* Next, set the clip shape */
     if (wClipShape(pWindow)) {
-	pBox = REGION_RECTS(wClipShape(pWindow));
-	nRect = nBox = REGION_NUM_RECTS(wClipShape(pWindow));
+	pBox = RegionRects(wClipShape(pWindow));
+	nRect = nBox = RegionNumRects(wClipShape(pWindow));
 	pRectFirst = pRect = malloc(nRect * sizeof(*pRect));
 	while (nBox--) {
 	    pRect->x      = pBox->x1;
diff --git a/hw/dmx/input/dmxconsole.c b/hw/dmx/input/dmxconsole.c
index 297166e..80df064 100644
--- a/hw/dmx/input/dmxconsole.c
+++ b/hw/dmx/input/dmxconsole.c
@@ -226,7 +226,7 @@ static void dmxConsoleDrawWindows(pointer private)
                        pChild->drawable.height,
                        pChild->visibility,
                        pChild->overrideRedirect,
-                       REGION_NUM_RECTS(&pChild->clipList));
+                       RegionNumRects(&pChild->clipList));
 #endif
                 rect.x      = scalex(priv, pChild->drawable.x + pScreen->x);
                 rect.y      = scaley(priv, pChild->drawable.y + pScreen->y);
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index b968516..e0cb956 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -343,13 +343,13 @@ ephyrInternalDamageRedisplay (ScreenPtr pScreen)
 
   pRegion = DamageRegion (scrpriv->pDamage);
 
-  if (REGION_NOTEMPTY (pScreen, pRegion))
+  if (RegionNotEmpty(pRegion))
     {
       int           nbox;
       BoxPtr        pbox;
 
-      nbox = REGION_NUM_RECTS (pRegion);
-      pbox = REGION_RECTS (pRegion);
+      nbox = RegionNumRects (pRegion);
+      pbox = RegionRects (pRegion);
 
       while (nbox--)
         {
@@ -897,10 +897,10 @@ ephyrExposePairedWindow (int a_remote)
 	return;
     }
     screen = pair->local->drawable.pScreen;
-    REGION_NULL (screen, &reg);
-    REGION_COPY (screen, &reg, &pair->local->clipList);
+    RegionNull(&reg);
+    RegionCopy(&reg, &pair->local->clipList);
     screen->WindowExposures (pair->local, &reg, NullRegion);
-    REGION_UNINIT (screen, &reg);
+    RegionUninit(&reg);
 }
 #endif /* XF86DRI */
 
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 55cc0f1..23c2032 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -418,11 +418,11 @@ ephyrDRIClipNotify (WindowPtr a_win,
         EPHYR_LOG_ERROR ("failed to get window pair\n") ;
         goto out ;
     }
-    rects = calloc(REGION_NUM_RECTS (&a_win->clipList),
+    rects = calloc(RegionNumRects (&a_win->clipList),
                      sizeof (EphyrRect)) ;
-    for (i=0; i < REGION_NUM_RECTS (&a_win->clipList); i++) {
+    for (i=0; i < RegionNumRects (&a_win->clipList); i++) {
         memmove (&rects[i],
-                 &REGION_RECTS (&a_win->clipList)[i],
+                 &RegionRects (&a_win->clipList)[i],
                  sizeof (EphyrRect)) ;
         rects[i].x1 -= a_win->drawable.x;
         rects[i].x2 -= a_win->drawable.x;
@@ -436,7 +436,7 @@ ephyrDRIClipNotify (WindowPtr a_win,
     is_ok = hostx_set_window_bounding_rectangles
                                 (pair->remote,
                                  rects,
-                                 REGION_NUM_RECTS (&a_win->clipList)) ;
+                                 RegionNumRects (&a_win->clipList)) ;
     is_ok = TRUE ;
 
 out:
@@ -1168,12 +1168,12 @@ ProcXF86DRIGetDrawableInfo (register ClientPtr client)
         return BadMatch ;
     }
     EPHYR_LOG ("clip list of xephyr gl drawable:\n") ;
-    for (i=0; i < REGION_NUM_RECTS (&window->clipList); i++) {
+    for (i=0; i < RegionNumRects (&window->clipList); i++) {
         EPHYR_LOG ("x1:%d, y1:%d, x2:%d, y2:%d\n",
-                   REGION_RECTS (&window->clipList)[i].x1,
-                   REGION_RECTS (&window->clipList)[i].y1,
-                   REGION_RECTS (&window->clipList)[i].x2,
-                   REGION_RECTS (&window->clipList)[i].y2) ;
+                   RegionRects (&window->clipList)[i].x1,
+                   RegionRects (&window->clipList)[i].y1,
+                   RegionRects (&window->clipList)[i].x2,
+                   RegionRects (&window->clipList)[i].y2) ;
     }
 
     if (!ephyrDRIGetDrawableInfo (stuff->screen,
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index 65127ce..69a89ae 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -946,8 +946,8 @@ ephyrPutImage (KdScreenInfo *a_info,
                               a_drw_x, a_drw_y, a_drw_w, a_drw_h,
                               a_src_x, a_src_y, a_src_w, a_src_h,
                               a_width, a_height, a_buf,
-                              (EphyrHostBox*)REGION_RECTS (a_clipping_region),
-                              REGION_NUM_RECTS (a_clipping_region))) {
+                              (EphyrHostBox*)RegionRects (a_clipping_region),
+                              RegionNumRects (a_clipping_region))) {
         EPHYR_LOG_ERROR ("EphyrHostXVPutImage() failed\n") ;
         goto out ;
     }
@@ -1025,8 +1025,8 @@ ephyrReputImage (KdScreenInfo *a_info,
                               port_priv->src_w, port_priv->src_h,
                               port_priv->image_width, port_priv->image_height,
                               port_priv->image_buf,
-                              (EphyrHostBox*)REGION_RECTS (a_clipping_region),
-                              REGION_NUM_RECTS (a_clipping_region))) {
+                              (EphyrHostBox*)RegionRects (a_clipping_region),
+                              RegionNumRects (a_clipping_region))) {
         EPHYR_LOG_ERROR ("ephyrHostXVPutImage() failed\n") ;
         goto out ;
     }
@@ -1064,7 +1064,7 @@ ephyrPutVideo (KdScreenInfo *a_info,
     dst_box.y2 = a_drw_y + a_drw_h;
 
     if (!DoSimpleClip (&dst_box,
-                       REGION_EXTENTS (pScreen->pScreen, a_clipping_region),
+                       RegionExtents(a_clipping_region),
                        &clipped_area)) {
         EPHYR_LOG_ERROR ("failed to simple clip\n") ;
         goto out ;
@@ -1115,7 +1115,7 @@ ephyrGetVideo (KdScreenInfo *a_info,
     dst_box.y2 = a_drw_y + a_drw_h;
 
     if (!DoSimpleClip (&dst_box,
-                       REGION_EXTENTS (pScreen->pScreen, a_clipping_region),
+                       RegionExtents(a_clipping_region),
                        &clipped_area)) {
         EPHYR_LOG_ERROR ("failed to simple clip\n") ;
         goto out ;
@@ -1166,7 +1166,7 @@ ephyrPutStill (KdScreenInfo *a_info,
     dst_box.y2 = a_drw_y + a_drw_h;
 
     if (!DoSimpleClip (&dst_box,
-                       REGION_EXTENTS (pScreen->pScreen, a_clipping_region),
+                       RegionExtents(a_clipping_region),
                        &clipped_area)) {
         EPHYR_LOG_ERROR ("failed to simple clip\n") ;
         goto out ;
@@ -1217,7 +1217,7 @@ ephyrGetStill (KdScreenInfo *a_info,
     dst_box.y2 = a_drw_y + a_drw_h;
 
     if (!DoSimpleClip (&dst_box,
-                       REGION_EXTENTS (pScreen->pScreen, a_clipping_region),
+                       RegionExtents(a_clipping_region),
                        &clipped_area)) {
         EPHYR_LOG_ERROR ("failed to simple clip\n") ;
         goto out ;
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 7993f9b..27596e4 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -121,8 +121,8 @@ KdSetRootClip (ScreenPtr pScreen, BOOL enable)
 	    {
 		RegionPtr	borderVisible;
 
-		borderVisible = REGION_CREATE(pScreen, NullBox, 1);
-		REGION_SUBTRACT(pScreen, borderVisible,
+		borderVisible = RegionCreate(NullBox, 1);
+		RegionSubtract(borderVisible,
 				&pWin->borderClip, &pWin->winSize);
 		pWin->valdata->before.borderVisible = borderVisible;
 	    }
@@ -138,15 +138,15 @@ KdSetRootClip (ScreenPtr pScreen, BOOL enable)
 	box.y2 = pScreen->height;
 	pWin->drawable.width = pScreen->width;
 	pWin->drawable.height = pScreen->height;
-	REGION_INIT (pScreen, &pWin->winSize, &box, 1);
-	REGION_INIT (pScreen, &pWin->borderSize, &box, 1);
-	REGION_RESET(pScreen, &pWin->borderClip, &box);
-	REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+	RegionInit(&pWin->winSize, &box, 1);
+	RegionInit(&pWin->borderSize, &box, 1);
+	RegionReset(&pWin->borderClip, &box);
+	RegionBreak(&pWin->clipList);
     }
     else
     {
-	REGION_EMPTY(pScreen, &pWin->borderClip);
-	REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+	RegionEmpty(&pWin->borderClip);
+	RegionBreak(&pWin->clipList);
     }
 
     ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
@@ -836,8 +836,8 @@ KdCreateWindow (WindowPtr pWin)
 
 	if (!pScreenPriv->enabled)
 	{
-	    REGION_EMPTY (pWin->drawable.pScreen, &pWin->borderClip);
-	    REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+	    RegionEmpty(&pWin->borderClip);
+	    RegionBreak(&pWin->clipList);
 	}
     }
 #endif
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index c81d7da..99ab2d8 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -268,9 +268,9 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
           pPriv = (XvPortRecPrivatePtr)pPort->devPriv.ptr;
 	  if(pPriv) {
 	     if(pPriv->clientClip)
-		REGION_DESTROY(pAdaptor->pScreen, pPriv->clientClip);
+		RegionDestroy(pPriv->clientClip);
              if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
-		REGION_DESTROY(pAdaptor->pScreen, pPriv->pCompositeClip);
+		RegionDestroy(pPriv->pCompositeClip);
 	     free(pPriv);
 	  }
       }
@@ -607,18 +607,18 @@ KdXVUpdateCompositeClip(XvPortRecPrivatePtr portPriv)
 	return;
    }
 
-   pCompositeClip = REGION_CREATE(pWin->pScreen, NullBox, 1);
-   REGION_COPY(pWin->pScreen, pCompositeClip, portPriv->clientClip);
-   REGION_TRANSLATE(pWin->pScreen, pCompositeClip,
+   pCompositeClip = RegionCreate(NullBox, 1);
+   RegionCopy(pCompositeClip, portPriv->clientClip);
+   RegionTranslate(pCompositeClip,
 			portPriv->pDraw->x + portPriv->clipOrg.x,
 			portPriv->pDraw->y + portPriv->clipOrg.y);
-   REGION_INTERSECT(pWin->pScreen, pCompositeClip, pregWin, pCompositeClip);
+   RegionIntersect(pCompositeClip, pregWin, pCompositeClip);
 
    portPriv->pCompositeClip = pCompositeClip;
    portPriv->FreeCompositeClip = TRUE;
 
    if(freeCompClip) {
-   	REGION_DESTROY(pWin->pScreen, pregWin);
+	RegionDestroy(pregWin);
    }
 }
 
@@ -633,17 +633,17 @@ KdXVCopyClip(
     /* copy the new clip if it exists */
     if((pGC->clientClipType == CT_REGION) && pGC->clientClip) {
 	if(!portPriv->clientClip)
-	    portPriv->clientClip = REGION_CREATE(pGC->pScreen, NullBox, 1);
+	    portPriv->clientClip = RegionCreate(NullBox, 1);
 	/* Note: this is in window coordinates */
-	REGION_COPY(pGC->pScreen, portPriv->clientClip, pGC->clientClip);
+	RegionCopy(portPriv->clientClip, pGC->clientClip);
     } else if(portPriv->clientClip) { /* free the old clientClip */
-	REGION_DESTROY(pGC->pScreen, portPriv->clientClip);
+	RegionDestroy(portPriv->clientClip);
 	portPriv->clientClip = NULL;
     }
 
     /* get rid of the old clip list */
     if(portPriv->pCompositeClip && portPriv->FreeCompositeClip) {
-	REGION_DESTROY(pWin->pScreen, portPriv->pCompositeClip);
+	RegionDestroy(portPriv->pCompositeClip);
     }
 
     portPriv->clipOrg = pGC->clipOrg;
@@ -670,18 +670,18 @@ KdXVRegetVideo(XvPortRecPrivatePtr portPriv)
   WinBox.y2 = WinBox.y1 + portPriv->drw_h;
 
   /* clip to the window composite clip */
-  REGION_INIT(portPriv->pDraw->pScreen, &WinRegion, &WinBox, 1);
-  REGION_INIT(portPriv->pDraw->pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(portPriv->pDraw->pScreen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionInit(&ClipRegion, NullBox, 1);
+  RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip);
 
   /* that's all if it's totally obscured */
-  if(!REGION_NOTEMPTY(portPriv->pDraw->pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
 	clippedAway = TRUE;
 	goto CLIP_VIDEO_BAILOUT;
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(portPriv->pDraw->pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->GetVideo)(portPriv->screen, portPriv->pDraw,
@@ -706,8 +706,8 @@ CLIP_VIDEO_BAILOUT:
   if(!portPriv->FreeCompositeClip)
      portPriv->pCompositeClip = NULL;
 
-  REGION_UNINIT(portPriv->pDraw->pScreen, &WinRegion);
-  REGION_UNINIT(portPriv->pDraw->pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -734,9 +734,9 @@ KdXVReputVideo(XvPortRecPrivatePtr portPriv)
   WinBox.y2 = WinBox.y1 + portPriv->drw_h;
 
   /* clip to the window composite clip */
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(Screen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionInit(&ClipRegion, NullBox, 1);
+  RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip);
 
   /* clip and translate to the viewport */
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
@@ -748,21 +748,21 @@ KdXVReputVideo(XvPortRecPrivatePtr portPriv)
      VPBox.x2 = screen->width;
      VPBox.y2 = screen->height;
 
-     REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg);
-     REGION_UNINIT(pScreen, &VPReg);
+     RegionInit(&VPReg, &VPBox, 1);
+     RegionIntersect(&ClipRegion, &ClipRegion, &VPReg);
+     RegionUninit(&VPReg);
   }
 
   /* that's all if it's totally obscured */
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
 	clippedAway = TRUE;
 	goto CLIP_VIDEO_BAILOUT;
   }
 
   /* bailout if we have to clip but the hardware doesn't support it */
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-     BoxPtr clipBox = REGION_RECTS(&ClipRegion);
-     if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+     BoxPtr clipBox = RegionRects(&ClipRegion);
+     if(  (RegionNumRects(&ClipRegion) != 1) ||
 	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
@@ -772,7 +772,7 @@ KdXVReputVideo(XvPortRecPrivatePtr portPriv)
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->PutVideo)(portPriv->screen, portPriv->pDraw,
@@ -796,8 +796,8 @@ CLIP_VIDEO_BAILOUT:
   if(!portPriv->FreeCompositeClip)
      portPriv->pCompositeClip = NULL;
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -823,9 +823,9 @@ KdXVReputImage(XvPortRecPrivatePtr portPriv)
   WinBox.y2 = WinBox.y1 + portPriv->drw_h;
 
   /* clip to the window composite clip */
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(Screen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionInit(&ClipRegion, NullBox, 1);
+  RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip);
 
   /* clip and translate to the viewport */
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
@@ -837,21 +837,21 @@ KdXVReputImage(XvPortRecPrivatePtr portPriv)
      VPBox.x2 = screen->width;
      VPBox.y2 = screen->height;
 
-     REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg);
-     REGION_UNINIT(pScreen, &VPReg);
+     RegionInit(&VPReg, &VPBox, 1);
+     RegionIntersect(&ClipRegion, &ClipRegion, &VPReg);
+     RegionUninit(&VPReg);
   }
 
   /* that's all if it's totally obscured */
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
 	clippedAway = TRUE;
 	goto CLIP_VIDEO_BAILOUT;
   }
 
   /* bailout if we have to clip but the hardware doesn't support it */
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-     BoxPtr clipBox = REGION_RECTS(&ClipRegion);
-     if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+     BoxPtr clipBox = RegionRects(&ClipRegion);
+     if(  (RegionNumRects(&ClipRegion) != 1) ||
 	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
@@ -861,7 +861,7 @@ KdXVReputImage(XvPortRecPrivatePtr portPriv)
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->ReputImage)(portPriv->screen, portPriv->pDraw,
@@ -882,8 +882,8 @@ CLIP_VIDEO_BAILOUT:
   if(!portPriv->FreeCompositeClip)
      portPriv->pCompositeClip = NULL;
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -1021,7 +1021,7 @@ KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
   XvPortRecPrivatePtr pPriv;
   Bool AreasExposed;
 
-  AreasExposed = (WinPriv && reg1 && REGION_NOTEMPTY(pScreen, reg1));
+  AreasExposed = (WinPriv && reg1 && RegionNotEmpty(reg1));
 
   pScreen->WindowExposures = ScreenPriv->WindowExposures;
   (*pScreen->WindowExposures)(pWin, reg1, reg2);
@@ -1089,7 +1089,7 @@ KdXVClipNotify(WindowPtr pWin, int dx, int dy)
      pPriv = WinPriv->PortRec;
 
      if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
-	REGION_DESTROY(pScreen, pPriv->pCompositeClip);
+	RegionDestroy(pPriv->pCompositeClip);
 
      pPriv->pCompositeClip = NULL;
 
@@ -1220,7 +1220,7 @@ KdXVDisable(ScreenPtr pScreen)
 		pPriv->isOn = XV_OFF;
 
 		if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
-		    REGION_DESTROY(pScreen, pPriv->pCompositeClip);
+		    RegionDestroy(pPriv->pCompositeClip);
 
 		pPriv->pCompositeClip = NULL;
 
@@ -1330,9 +1330,9 @@ KdXVPutStill(
   WinBox.x2 = WinBox.x1 + drw_w;
   WinBox.y2 = WinBox.y1 + drw_h;
 
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionInit(&ClipRegion, NullBox, 1);
+  RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip);
 
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
      RegionRec VPReg;
@@ -1343,23 +1343,23 @@ KdXVPutStill(
      VPBox.x2 = screen->width;
      VPBox.y2 = screen->height;
 
-     REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg);
-     REGION_UNINIT(pScreen, &VPReg);
+     RegionInit(&VPReg, &VPBox, 1);
+     RegionIntersect(&ClipRegion, &ClipRegion, &VPReg);
+     RegionUninit(&VPReg);
   }
 
   if(portPriv->pDraw) {
      KdXVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
   }
 
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
      clippedAway = TRUE;
      goto PUT_STILL_BAILOUT;
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-     BoxPtr clipBox = REGION_RECTS(&ClipRegion);
-     if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+     BoxPtr clipBox = RegionRects(&ClipRegion);
+     if(  (RegionNumRects(&ClipRegion) != 1) ||
 	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
@@ -1369,7 +1369,7 @@ KdXVPutStill(
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->PutStill)(portPriv->screen, pDraw,
@@ -1398,8 +1398,8 @@ PUT_STILL_BAILOUT:
         portPriv->isOn = XV_PENDING;
   }
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -1483,21 +1483,21 @@ KdXVGetStill(
   WinBox.x2 = WinBox.x1 + drw_w;
   WinBox.y2 = WinBox.y1 + drw_h;
 
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionInit(&ClipRegion, NullBox, 1);
+  RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip);
 
   if(portPriv->pDraw) {
      KdXVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
   }
 
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
      clippedAway = TRUE;
      goto GET_STILL_BAILOUT;
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->GetStill)(portPriv->screen, pDraw,
@@ -1513,8 +1513,8 @@ GET_STILL_BAILOUT:
         portPriv->isOn = XV_PENDING;
   }
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -1630,9 +1630,9 @@ KdXVPutImage(
   WinBox.x2 = WinBox.x1 + drw_w;
   WinBox.y2 = WinBox.y1 + drw_h;
 
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_INIT(pScreen, &ClipRegion, NullBox, 1);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionInit(&ClipRegion, NullBox, 1);
+  RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip);
 
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
      RegionRec VPReg;
@@ -1643,23 +1643,23 @@ KdXVPutImage(
      VPBox.x2 = pScreen->width;
      VPBox.y2 = pScreen->height;
 
-     REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(Screen, &ClipRegion, &ClipRegion, &VPReg);
-     REGION_UNINIT(pScreen, &VPReg);
+     RegionInit(&VPReg, &VPBox, 1);
+     RegionIntersect(&ClipRegion, &ClipRegion, &VPReg);
+     RegionUninit(&VPReg);
   }
 
   if(portPriv->pDraw) {
      KdXVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
   }
 
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
      clippedAway = TRUE;
      goto PUT_IMAGE_BAILOUT;
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-     BoxPtr clipBox = REGION_RECTS(&ClipRegion);
-     if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+     BoxPtr clipBox = RegionRects(&ClipRegion);
+     if(  (RegionNumRects(&ClipRegion) != 1) ||
 	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
@@ -1669,7 +1669,7 @@ KdXVPutImage(
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->PutImage)(portPriv->screen, pDraw,
@@ -1698,8 +1698,8 @@ PUT_IMAGE_BAILOUT:
         portPriv->isOn = XV_PENDING;
   }
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -1869,8 +1869,8 @@ KXVPaintRegion (DrawablePtr pDraw, RegionPtr pRgn, Pixel fg)
     GCPtr	pGC;
     ChangeGCVal	val[2];
     xRectangle	*rects, *r;
-    BoxPtr	pBox = REGION_RECTS (pRgn);
-    int		nBox = REGION_NUM_RECTS (pRgn);
+    BoxPtr	pBox = RegionRects (pRgn);
+    int		nBox = RegionNumRects (pRgn);
 
     rects = malloc(nBox * sizeof (xRectangle));
     if (!rects)
@@ -1897,7 +1897,7 @@ KXVPaintRegion (DrawablePtr pDraw, RegionPtr pRgn, Pixel fg)
     ValidateGC (pDraw, pGC);
 
     (*pGC->ops->PolyFillRect) (pDraw, pGC,
-			       REGION_NUM_RECTS (pRgn), rects);
+			       RegionNumRects (pRgn), rects);
 
     FreeScratchGC (pGC);
 bail1:
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 1aad2d1..7867a42 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1085,8 +1085,8 @@ xf86SetRootClip (ScreenPtr pScreen, Bool enable)
 	    {
 		RegionPtr	borderVisible;
 
-		borderVisible = REGION_CREATE(pScreen, NullBox, 1);
-		REGION_SUBTRACT(pScreen, borderVisible,
+		borderVisible = RegionCreate(NullBox, 1);
+		RegionSubtract(borderVisible,
 				&pWin->borderClip, &pWin->winSize);
 		pWin->valdata->before.borderVisible = borderVisible;
 	    }
@@ -1105,18 +1105,18 @@ xf86SetRootClip (ScreenPtr pScreen, Bool enable)
 	box.y1 = 0;
 	box.x2 = pScreen->width;
 	box.y2 = pScreen->height;
-	REGION_INIT (pScreen, &pWin->winSize, &box, 1);
-	REGION_INIT (pScreen, &pWin->borderSize, &box, 1);
+	RegionInit(&pWin->winSize, &box, 1);
+	RegionInit(&pWin->borderSize, &box, 1);
 	if (WasViewable)
-	    REGION_RESET(pScreen, &pWin->borderClip, &box);
+	    RegionReset(&pWin->borderClip, &box);
 	pWin->drawable.width = pScreen->width;
 	pWin->drawable.height = pScreen->height;
-        REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+        RegionBreak(&pWin->clipList);
     }
     else
     {
-	REGION_EMPTY(pScreen, &pWin->borderClip);
-	REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+	RegionEmpty(&pWin->borderClip);
+	RegionBreak(&pWin->clipList);
     }
 
     ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
diff --git a/hw/xfree86/common/xf86fbman.c b/hw/xfree86/common/xf86fbman.c
index a142abe..d883ab3 100644
--- a/hw/xfree86/common/xf86fbman.c
+++ b/hw/xfree86/common/xf86fbman.c
@@ -363,8 +363,8 @@ AllocateArea(
 
    if(granularity <= 1) granularity = 0;
 
-   boxp = REGION_RECTS(offman->FreeBoxes);
-   num = REGION_NUM_RECTS(offman->FreeBoxes);
+   boxp = RegionRects(offman->FreeBoxes);
+   num = RegionNumRects(offman->FreeBoxes);
 
    /* look through the free boxes */
    for(i = 0; i < num; i++, boxp++) {
@@ -407,9 +407,9 @@ AllocateArea(
 
 	   /* bye, bye */
 	   (*link->area.RemoveAreaCallback)(&link->area);
-	   REGION_INIT(pScreen, &NewReg, &(link->area.box), 1); 
-	   REGION_UNION(pScreen, offman->FreeBoxes, offman->FreeBoxes, &NewReg);
-	   REGION_UNINIT(pScreen, &NewReg); 
+	   RegionInit(&NewReg, &(link->area.box), 1);
+	   RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &NewReg);
+	   RegionUninit(&NewReg);
 
            area = &(link->area);
 	   break;
@@ -427,9 +427,9 @@ AllocateArea(
 	area->RemoveAreaCallback = removeCB;
 	area->devPrivate.ptr = privData;
 
-        REGION_INIT(pScreen, &NewReg, &(area->box), 1);
-	REGION_SUBTRACT(pScreen, offman->FreeBoxes, offman->FreeBoxes, &NewReg);
-	REGION_UNINIT(pScreen, &NewReg);
+        RegionInit(&NewReg, &(area->box), 1);
+	RegionSubtract(offman->FreeBoxes, offman->FreeBoxes, &NewReg);
+	RegionUninit(&NewReg);
    }
 
    return area;
@@ -477,9 +477,9 @@ localFreeOffscreenArea(FBAreaPtr area)
    }
 
    /* put the area back into the pool */
-   REGION_INIT(pScreen, &FreedRegion, &(pLink->area.box), 1); 
-   REGION_UNION(pScreen, offman->FreeBoxes, offman->FreeBoxes, &FreedRegion);
-   REGION_UNINIT(pScreen, &FreedRegion); 
+   RegionInit(&FreedRegion, &(pLink->area.box), 1);
+   RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedRegion);
+   RegionUninit(&FreedRegion);
 
    if(pLinkPrev)
 	pLinkPrev->next = pLink->next;
@@ -536,12 +536,12 @@ localResizeOffscreenArea(
 	   (resize->box.x2 == OrigArea.x2))
 		return TRUE;
 
-	REGION_INIT(pScreen, &FreedReg, &OrigArea, 1); 
-	REGION_INIT(pScreen, &NewReg, &(resize->box), 1); 
-	REGION_SUBTRACT(pScreen, &FreedReg, &FreedReg, &NewReg);
-	REGION_UNION(pScreen, offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
-	REGION_UNINIT(pScreen, &FreedReg); 
-	REGION_UNINIT(pScreen, &NewReg); 
+	RegionInit(&FreedReg, &OrigArea, 1);
+	RegionInit(&NewReg, &(resize->box), 1);
+	RegionSubtract(&FreedReg, &FreedReg, &NewReg);
+	RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
+	RegionUninit(&FreedReg);
+	RegionUninit(&NewReg);
 
 	SendCallFreeBoxCallbacks(offman);
 
@@ -551,8 +551,8 @@ localResizeOffscreenArea(
 
    /* otherwise we remove the old region */
 
-   REGION_INIT(pScreen, &FreedReg, &OrigArea, 1); 
-   REGION_UNION(pScreen, offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
+   RegionInit(&FreedReg, &OrigArea, 1);
+   RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
   
    /* remove the old link */
    if(pLinkPrev)
@@ -589,8 +589,8 @@ localResizeOffscreenArea(
 	offman->NumUsedAreas--;  
    } else {
       /* reinstate the old region */
-      REGION_SUBTRACT(pScreen, offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
-      REGION_UNINIT(pScreen, &FreedReg); 
+      RegionSubtract(offman->FreeBoxes, offman->FreeBoxes, &FreedReg);
+      RegionUninit(&FreedReg);
 
       pLink->next = offman->UsedAreas;
       offman->UsedAreas = pLink;
@@ -598,7 +598,7 @@ localResizeOffscreenArea(
    }
 
 
-   REGION_UNINIT(pScreen, &FreedReg); 
+   RegionUninit(&FreedReg);
 
    SendCallFreeBoxCallbacks(offman);
 
@@ -636,47 +636,47 @@ localQueryLargestOffscreenArea(
 	if(offman->NumUsedAreas) {
 	    FBLinkPtr pLink;
 	    RegionRec tmpRegion;
-	    newRegion = REGION_CREATE(pScreen, NULL, 1);
-	    REGION_COPY(pScreen, newRegion, offman->InitialBoxes);
+	    newRegion = RegionCreate(NULL, 1);
+	    RegionCopy(newRegion, offman->InitialBoxes);
 	    pLink = offman->UsedAreas;
 
 	    while(pLink) {
 		if(!pLink->area.RemoveAreaCallback) {
-		    REGION_INIT(pScreen, &tmpRegion, &(pLink->area.box), 1);
-		    REGION_SUBTRACT(pScreen, newRegion, newRegion, &tmpRegion);
-		    REGION_UNINIT(pScreen, &tmpRegion);
+		    RegionInit(&tmpRegion, &(pLink->area.box), 1);
+		    RegionSubtract(newRegion, newRegion, &tmpRegion);
+		    RegionUninit(&tmpRegion);
 		}
 		pLink = pLink->next;
 	    }
 
-	    nbox = REGION_NUM_RECTS(newRegion);
-	    pbox = REGION_RECTS(newRegion);
+	    nbox = RegionNumRects(newRegion);
+	    pbox = RegionRects(newRegion);
 	    break;
 	}
     case 1:
 	if(offman->NumUsedAreas) {
 	    FBLinkPtr pLink;
 	    RegionRec tmpRegion;
-	    newRegion = REGION_CREATE(pScreen, NULL, 1);
-	    REGION_COPY(pScreen, newRegion, offman->FreeBoxes);
+	    newRegion = RegionCreate(NULL, 1);
+	    RegionCopy(newRegion, offman->FreeBoxes);
 	    pLink = offman->UsedAreas;
 
 	    while(pLink) {
 		if(pLink->area.RemoveAreaCallback) {
-		    REGION_INIT(pScreen, &tmpRegion, &(pLink->area.box), 1);
-		    REGION_APPEND(pScreen, newRegion, &tmpRegion);
-		    REGION_UNINIT(pScreen, &tmpRegion);
+		    RegionInit(&tmpRegion, &(pLink->area.box), 1);
+		    RegionAppend(newRegion, &tmpRegion);
+		    RegionUninit(&tmpRegion);
 		}
 		pLink = pLink->next;
 	    }
 
-	    nbox = REGION_NUM_RECTS(newRegion);
-	    pbox = REGION_RECTS(newRegion);
+	    nbox = RegionNumRects(newRegion);
+	    pbox = RegionRects(newRegion);
 	    break;
 	}
     default:
-	nbox = REGION_NUM_RECTS(offman->FreeBoxes);
-	pbox = REGION_RECTS(offman->FreeBoxes);
+	nbox = RegionNumRects(offman->FreeBoxes);
+	pbox = RegionRects(offman->FreeBoxes);
 	break;
     }
 
@@ -719,7 +719,7 @@ localQueryLargestOffscreenArea(
     }
 
     if(newRegion)
-	REGION_DESTROY(pScreen, newRegion);
+	RegionDestroy(newRegion);
 
     return TRUE;
 }
@@ -741,9 +741,9 @@ localPurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
 	if(pLink->area.RemoveAreaCallback) {
 	    (*pLink->area.RemoveAreaCallback)(&pLink->area);
 
-	    REGION_INIT(pScreen, &FreedRegion, &(pLink->area.box), 1); 
-	    REGION_APPEND(pScreen, offman->FreeBoxes, &FreedRegion);
-	    REGION_UNINIT(pScreen, &FreedRegion); 
+	    RegionInit(&FreedRegion, &(pLink->area.box), 1);
+	    RegionAppend(offman->FreeBoxes, &FreedRegion);
+	    RegionUninit(&FreedRegion);
 
 	    if(pPrev)
 	      pPrev->next = pLink->next;
@@ -761,7 +761,7 @@ localPurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
    }
 
    if(anyUsed) {
-	REGION_VALIDATE(pScreen, offman->FreeBoxes, &anyUsed);
+	RegionValidate(offman->FreeBoxes, &anyUsed);
 	SendCallFreeBoxCallbacks(offman);
    }
 
@@ -924,7 +924,7 @@ localAllocateOffscreenLinear(
      return NULL;
 
    /* No linear available, so try and pinch some from the XY areas */
-   extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
+   extents = RegionExtents(offman->InitialBoxes);
    pitch = extents->x2 - extents->x1;
 
    if (gran > 1) {
@@ -1055,7 +1055,7 @@ localResizeOffscreenLinear(FBLinearPtr resize, int length)
 	BoxPtr extents;
 	int pitch, w, h;
 
-	extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
+	extents = RegionExtents(offman->InitialBoxes);
 	pitch = extents->x2 - extents->x1;
 
 	if(length < pitch) { /* special case */
@@ -1121,7 +1121,7 @@ localQueryLargestOffscreenLinear(
 
 	    offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
 						    xf86FBScreenKey);
-	    extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
+	    extents = RegionExtents(offman->InitialBoxes);
 	    if((extents->x2 - extents->x1) == w)
 	    	*size = w * h;
 	    return TRUE;
@@ -1171,8 +1171,8 @@ xf86FBCloseScreen (int i, ScreenPtr pScreen)
 	free(tmp2);
    }
 
-   REGION_DESTROY(pScreen, offman->InitialBoxes);
-   REGION_DESTROY(pScreen, offman->FreeBoxes);
+   RegionDestroy(offman->InitialBoxes);
+   RegionDestroy(offman->FreeBoxes);
 
    free(offman->FreeBoxesUpdateCallback);
    free(offman->devPrivates);
@@ -1206,15 +1206,15 @@ xf86InitFBManager(
    if (FullBox->y2 < FullBox->y1) return FALSE;
    if (FullBox->x2 < FullBox->x1) return FALSE;
 
-   REGION_INIT(pScreen, &ScreenRegion, &ScreenBox, 1); 
-   REGION_INIT(pScreen, &FullRegion, FullBox, 1); 
+   RegionInit(&ScreenRegion, &ScreenBox, 1);
+   RegionInit(&FullRegion, FullBox, 1);
 
-   REGION_SUBTRACT(pScreen, &FullRegion, &FullRegion, &ScreenRegion);
+   RegionSubtract(&FullRegion, &FullRegion, &ScreenRegion);
 
    ret = xf86InitFBManagerRegion(pScreen, &FullRegion);
 
-   REGION_UNINIT(pScreen, &ScreenRegion);
-   REGION_UNINIT(pScreen, &FullRegion);
+   RegionUninit(&ScreenRegion);
+   RegionUninit(&FullRegion);
     
    return ret;
 }
@@ -1249,17 +1249,17 @@ xf86InitFBManagerArea(
     }
 
     /* Factor out virtual resolution */
-    pRegion = RECTS_TO_REGION(pScreen, nRect, Rect, 0);
+    pRegion = RegionFromRects(nRect, Rect, 0);
     if (pRegion) {
-	if (!REGION_NAR(pRegion)) {
+	if (!RegionNar(pRegion)) {
 	    Rect[2].x = Rect[2].y = 0;
 	    Rect[2].width = pScrn->virtualX;
 	    Rect[2].height = pScrn->virtualY;
 
-	    pScreenRegion = RECTS_TO_REGION(pScreen, 1, &Rect[2], 0);
+	    pScreenRegion = RegionFromRects(1, &Rect[2], 0);
 	    if (pScreenRegion) {
-		if (!REGION_NAR(pScreenRegion)) {
-		    REGION_SUBTRACT(pScreen, pRegion, pRegion, pScreenRegion);
+		if (!RegionNar(pScreenRegion)) {
+		    RegionSubtract(pRegion, pRegion, pScreenRegion);
 
 		    ret = xf86InitFBManagerRegion(pScreen, pRegion);
 
@@ -1301,11 +1301,11 @@ xf86InitFBManagerArea(
 		    }
 		}
 
-		REGION_DESTROY(pScreen, pScreenRegion);
+		RegionDestroy(pScreenRegion);
 	    }
 	}
 
-	REGION_DESTROY(pScreen, pRegion);
+	RegionDestroy(pRegion);
     }
 
     return ret;
@@ -1318,7 +1318,7 @@ xf86InitFBManagerRegion(
 ){
    FBManagerPtr offman;
 
-   if(REGION_NIL(FullRegion))
+   if(RegionNil(FullRegion))
 	return FALSE;
 
    if(!xf86RegisterOffscreenManager(pScreen, &xf86FBManFuncs))
@@ -1332,11 +1332,11 @@ xf86InitFBManagerRegion(
    offman->CloseScreen = pScreen->CloseScreen;
    pScreen->CloseScreen = xf86FBCloseScreen;
 
-   offman->InitialBoxes = REGION_CREATE(pScreen, NULL, 1);
-   offman->FreeBoxes = REGION_CREATE(pScreen, NULL, 1);
+   offman->InitialBoxes = RegionCreate(NULL, 1);
+   offman->FreeBoxes = RegionCreate(NULL, 1);
 
-   REGION_COPY(pScreen, offman->InitialBoxes, FullRegion);
-   REGION_COPY(pScreen, offman->FreeBoxes, FullRegion);
+   RegionCopy(offman->InitialBoxes, FullRegion);
+   RegionCopy(offman->FreeBoxes, FullRegion);
 
    offman->pScreen = pScreen;
    offman->UsedAreas = NULL;
@@ -1415,7 +1415,7 @@ xf86AllocateLinearOffscreenArea (
 
    offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
 					   xf86FBScreenKey);
-   extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
+   extents = RegionExtents(offman->InitialBoxes);
    w = extents->x2 - extents->x1;
 
    if (gran > 1) {
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index efed677..36e325f 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -322,9 +322,9 @@ xf86XVFreeAdaptor(XvAdaptorPtr pAdaptor)
 	  pPriv = (XvPortRecPrivatePtr)pPort->devPriv.ptr;
 	  if(pPriv) {
 	     if(pPriv->clientClip)
-		REGION_DESTROY(pAdaptor->pScreen, pPriv->clientClip);
+		RegionDestroy(pPriv->clientClip);
 	     if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
-		REGION_DESTROY(pAdaptor->pScreen, pPriv->pCompositeClip);
+		RegionDestroy(pPriv->pCompositeClip);
 	     free(pPriv);
 	  }
       }
@@ -658,18 +658,18 @@ xf86XVUpdateCompositeClip(XvPortRecPrivatePtr portPriv)
 	return;
    }
 
-   pCompositeClip = REGION_CREATE(pScreen, NullBox, 1);
-   REGION_COPY(pScreen, pCompositeClip, portPriv->clientClip);
-   REGION_TRANSLATE(pScreen, pCompositeClip,
+   pCompositeClip = RegionCreate(NullBox, 1);
+   RegionCopy(pCompositeClip, portPriv->clientClip);
+   RegionTranslate(pCompositeClip,
 			portPriv->pDraw->x + portPriv->clipOrg.x,
 			portPriv->pDraw->y + portPriv->clipOrg.y);
-   REGION_INTERSECT(pScreen, pCompositeClip, pregWin, pCompositeClip);
+   RegionIntersect(pCompositeClip, pregWin, pCompositeClip);
 
    portPriv->pCompositeClip = pCompositeClip;
    portPriv->FreeCompositeClip = TRUE;
 
    if(freeCompClip) {
-	REGION_DESTROY(pScreen, pregWin);
+	RegionDestroy(pregWin);
    }
 }
 
@@ -684,17 +684,17 @@ xf86XVCopyClip(
     /* copy the new clip if it exists */
     if((pGC->clientClipType == CT_REGION) && pGC->clientClip) {
 	if(!portPriv->clientClip)
-	    portPriv->clientClip = REGION_CREATE(pScreen, NullBox, 1);
+	    portPriv->clientClip = RegionCreate(NullBox, 1);
 	/* Note: this is in window coordinates */
-	REGION_COPY(pScreen, portPriv->clientClip, pGC->clientClip);
+	RegionCopy(portPriv->clientClip, pGC->clientClip);
     } else if(portPriv->clientClip) { /* free the old clientClip */
-	REGION_DESTROY(pScreen, portPriv->clientClip);
+	RegionDestroy(portPriv->clientClip);
 	portPriv->clientClip = NULL;
     }
 
     /* get rid of the old clip list */
     if(portPriv->pCompositeClip && portPriv->FreeCompositeClip) {
-	REGION_DESTROY(pScreen, portPriv->pCompositeClip);
+	RegionDestroy(portPriv->pCompositeClip);
     }
 
     portPriv->clipOrg = pGC->clipOrg;
@@ -723,18 +723,18 @@ xf86XVRegetVideo(XvPortRecPrivatePtr portPriv)
   WinBox.y2 = WinBox.y1 + portPriv->drw_h;
 
   /* clip to the window composite clip */
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_NULL(pScreen, &ClipRegion);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionNull(&ClipRegion);
+  RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip);
 
   /* that's all if it's totally obscured */
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
 	clippedAway = TRUE;
 	goto CLIP_VIDEO_BAILOUT;
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->GetVideo)(portPriv->pScrn,
@@ -760,8 +760,8 @@ CLIP_VIDEO_BAILOUT:
   if(!portPriv->FreeCompositeClip)
      portPriv->pCompositeClip = NULL;
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -788,9 +788,9 @@ xf86XVReputVideo(XvPortRecPrivatePtr portPriv)
   WinBox.y2 = WinBox.y1 + portPriv->drw_h;
 
   /* clip to the window composite clip */
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_NULL(pScreen, &ClipRegion);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionNull(&ClipRegion);
+  RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip);
 
   /* clip and translate to the viewport */
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
@@ -802,21 +802,21 @@ xf86XVReputVideo(XvPortRecPrivatePtr portPriv)
      VPBox.x2 = portPriv->pScrn->frameX1 + 1;
      VPBox.y2 = portPriv->pScrn->frameY1 + 1;
 
-     REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(pScreen, &ClipRegion, &ClipRegion, &VPReg);
-     REGION_UNINIT(pScreen, &VPReg);
+     RegionInit(&VPReg, &VPBox, 1);
+     RegionIntersect(&ClipRegion, &ClipRegion, &VPReg);
+     RegionUninit(&VPReg);
   }
 
   /* that's all if it's totally obscured */
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
 	clippedAway = TRUE;
 	goto CLIP_VIDEO_BAILOUT;
   }
 
   /* bailout if we have to clip but the hardware doesn't support it */
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-     BoxPtr clipBox = REGION_RECTS(&ClipRegion);
-     if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+     BoxPtr clipBox = RegionRects(&ClipRegion);
+     if(  (RegionNumRects(&ClipRegion) != 1) ||
 	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
@@ -826,7 +826,7 @@ xf86XVReputVideo(XvPortRecPrivatePtr portPriv)
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->PutVideo)(portPriv->pScrn,
@@ -851,8 +851,8 @@ CLIP_VIDEO_BAILOUT:
   if(!portPriv->FreeCompositeClip)
      portPriv->pCompositeClip = NULL;
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -878,9 +878,9 @@ xf86XVReputImage(XvPortRecPrivatePtr portPriv)
   WinBox.y2 = WinBox.y1 + portPriv->drw_h;
 
   /* clip to the window composite clip */
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_NULL(pScreen, &ClipRegion);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, portPriv->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionNull(&ClipRegion);
+  RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip);
 
   /* clip and translate to the viewport */
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
@@ -892,21 +892,21 @@ xf86XVReputImage(XvPortRecPrivatePtr portPriv)
      VPBox.x2 = portPriv->pScrn->frameX1 + 1;
      VPBox.y2 = portPriv->pScrn->frameY1 + 1;
 
-     REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(pScreen, &ClipRegion, &ClipRegion, &VPReg);
-     REGION_UNINIT(pScreen, &VPReg);
+     RegionInit(&VPReg, &VPBox, 1);
+     RegionIntersect(&ClipRegion, &ClipRegion, &VPReg);
+     RegionUninit(&VPReg);
   }
 
   /* that's all if it's totally obscured */
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
 	clippedAway = TRUE;
 	goto CLIP_VIDEO_BAILOUT;
   }
 
   /* bailout if we have to clip but the hardware doesn't support it */
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-     BoxPtr clipBox = REGION_RECTS(&ClipRegion);
-     if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+     BoxPtr clipBox = RegionRects(&ClipRegion);
+     if(  (RegionNumRects(&ClipRegion) != 1) ||
 	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
@@ -916,7 +916,7 @@ xf86XVReputImage(XvPortRecPrivatePtr portPriv)
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->ReputImage)(portPriv->pScrn,
@@ -938,8 +938,8 @@ CLIP_VIDEO_BAILOUT:
   if(!portPriv->FreeCompositeClip)
      portPriv->pCompositeClip = NULL;
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -1060,7 +1060,7 @@ xf86XVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
   XvPortRecPrivatePtr pPriv;
   Bool AreasExposed;
 
-  AreasExposed = (WinPriv && reg1 && REGION_NOTEMPTY(pScreen, reg1));
+  AreasExposed = (WinPriv && reg1 && RegionNotEmpty(reg1));
 
   pScreen->WindowExposures = ScreenPriv->WindowExposures;
   (*pScreen->WindowExposures)(pWin, reg1, reg2);
@@ -1131,7 +1131,7 @@ xf86XVClipNotify(WindowPtr pWin, int dx, int dy)
      if(!pPriv) goto next;
  
      if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
-	REGION_DESTROY(pScreen, pPriv->pCompositeClip);
+	RegionDestroy(pPriv->pCompositeClip);
 
      pPriv->pCompositeClip = NULL;
 
@@ -1268,7 +1268,7 @@ xf86XVLeaveVT(int index, int flags)
 		pPriv->isOn = XV_OFF;
 
 		if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
-		    REGION_DESTROY(pScreen, pPriv->pCompositeClip);
+		    RegionDestroy(pPriv->pCompositeClip);
 
 		pPriv->pCompositeClip = NULL;
 
@@ -1309,7 +1309,7 @@ xf86XVAdjustFrame(int index, int x, int y, int flags)
 	if(!pPriv->type && (pPriv->isOn != XV_OFF)) { /* overlaid still/image */
 
 	  if(pPriv->pCompositeClip && pPriv->FreeCompositeClip)
-	     REGION_DESTROY(pScreen, pPriv->pCompositeClip);
+	     RegionDestroy(pPriv->pCompositeClip);
 
 	  pPriv->pCompositeClip = NULL;
 
@@ -1432,9 +1432,9 @@ xf86XVPutStill(
   WinBox.x2 = WinBox.x1 + drw_w;
   WinBox.y2 = WinBox.y1 + drw_h;
 
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_NULL(pScreen, &ClipRegion);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionNull(&ClipRegion);
+  RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip);
 
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
      RegionRec VPReg;
@@ -1445,23 +1445,23 @@ xf86XVPutStill(
      VPBox.x2 = portPriv->pScrn->frameX1 + 1;
      VPBox.y2 = portPriv->pScrn->frameY1 + 1;
 
-     REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(pScreen, &ClipRegion, &ClipRegion, &VPReg);
-     REGION_UNINIT(pScreen, &VPReg);
+     RegionInit(&VPReg, &VPBox, 1);
+     RegionIntersect(&ClipRegion, &ClipRegion, &VPReg);
+     RegionUninit(&VPReg);
   }
 
   if(portPriv->pDraw) {
      xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
   }
 
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
      clippedAway = TRUE;
      goto PUT_STILL_BAILOUT;
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-     BoxPtr clipBox = REGION_RECTS(&ClipRegion);
-     if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+     BoxPtr clipBox = RegionRects(&ClipRegion);
+     if(  (RegionNumRects(&ClipRegion) != 1) ||
 	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
@@ -1471,7 +1471,7 @@ xf86XVPutStill(
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->PutStill)(portPriv->pScrn,
@@ -1500,8 +1500,8 @@ PUT_STILL_BAILOUT:
 	portPriv->isOn = XV_PENDING;
   }
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -1584,21 +1584,21 @@ xf86XVGetStill(
   WinBox.x2 = WinBox.x1 + drw_w;
   WinBox.y2 = WinBox.y1 + drw_h;
 
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_NULL(pScreen, &ClipRegion);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionNull(&ClipRegion);
+  RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip);
 
   if(portPriv->pDraw) {
      xf86XVRemovePortFromWindow((WindowPtr)(portPriv->pDraw), portPriv);
   }
 
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
      clippedAway = TRUE;
      goto GET_STILL_BAILOUT;
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->GetStill)(portPriv->pScrn,
@@ -1615,8 +1615,8 @@ GET_STILL_BAILOUT:
 	portPriv->isOn = XV_PENDING;
   }
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -1732,9 +1732,9 @@ xf86XVPutImage(
   WinBox.x2 = WinBox.x1 + drw_w;
   WinBox.y2 = WinBox.y1 + drw_h;
 
-  REGION_INIT(pScreen, &WinRegion, &WinBox, 1);
-  REGION_NULL(pScreen, &ClipRegion);
-  REGION_INTERSECT(pScreen, &ClipRegion, &WinRegion, pGC->pCompositeClip);
+  RegionInit(&WinRegion, &WinBox, 1);
+  RegionNull(&ClipRegion);
+  RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip);
 
   if(portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) {
      RegionRec VPReg;
@@ -1745,9 +1745,9 @@ xf86XVPutImage(
      VPBox.x2 = portPriv->pScrn->frameX1 + 1;
      VPBox.y2 = portPriv->pScrn->frameY1 + 1;
 
-     REGION_INIT(pScreen, &VPReg, &VPBox, 1);
-     REGION_INTERSECT(pScreen, &ClipRegion, &ClipRegion, &VPReg);
-     REGION_UNINIT(pScreen, &VPReg);
+     RegionInit(&VPReg, &VPBox, 1);
+     RegionIntersect(&ClipRegion, &ClipRegion, &VPReg);
+     RegionUninit(&VPReg);
   }
 
   /* If we are changing windows, unregister our port in the old window */
@@ -1758,14 +1758,14 @@ xf86XVPutImage(
   ret =  xf86XVEnlistPortInWindow((WindowPtr)pDraw, portPriv);
   if(ret != Success) goto PUT_IMAGE_BAILOUT;
 
-  if(!REGION_NOTEMPTY(pScreen, &ClipRegion)) {
+  if(!RegionNotEmpty(&ClipRegion)) {
      clippedAway = TRUE;
      goto PUT_IMAGE_BAILOUT;
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-     BoxPtr clipBox = REGION_RECTS(&ClipRegion);
-     if(  (REGION_NUM_RECTS(&ClipRegion) != 1) ||
+     BoxPtr clipBox = RegionRects(&ClipRegion);
+     if(  (RegionNumRects(&ClipRegion) != 1) ||
 	  (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
 	  (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2))
      {
@@ -1775,7 +1775,7 @@ xf86XVPutImage(
   }
 
   if(portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-     REGION_SUBTRACT(pScreen, &ClipRegion, &WinRegion, &ClipRegion);
+     RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
   }
 
   ret = (*portPriv->AdaptorRec->PutImage)(portPriv->pScrn,
@@ -1803,8 +1803,8 @@ PUT_IMAGE_BAILOUT:
 	portPriv->isOn = XV_PENDING;
   }
 
-  REGION_UNINIT(pScreen, &WinRegion);
-  REGION_UNINIT(pScreen, &ClipRegion);
+  RegionUninit(&WinRegion);
+  RegionUninit(&ClipRegion);
 
   return ret;
 }
@@ -1834,8 +1834,8 @@ xf86XVFillKeyHelperDrawable (DrawablePtr pDraw, CARD32 key, RegionPtr clipboxes)
    WindowPtr pWin = (WindowPtr)pDraw;
    XF86XVWindowPtr pPriv = GET_XF86XV_WINDOW(pWin);
    GCPtr pGC = NULL;
-   BoxPtr pbox = REGION_RECTS(clipboxes);
-   int i, nbox = REGION_NUM_RECTS(clipboxes);
+   BoxPtr pbox = RegionRects(clipboxes);
+   int i, nbox = RegionNumRects(clipboxes);
    xRectangle *rects;
 
    if(!xf86Screens[pScreen->myNum]->vtSema) return;
@@ -1860,7 +1860,7 @@ xf86XVFillKeyHelperDrawable (DrawablePtr pDraw, CARD32 key, RegionPtr clipboxes)
        ValidateGC(pDraw, pGC);
    }
 
-   REGION_TRANSLATE(pDraw->pScreen, clipboxes, -pDraw->x, -pDraw->y);
+   RegionTranslate(clipboxes, -pDraw->x, -pDraw->y);
 
    rects = malloc(nbox * sizeof(xRectangle));
 
@@ -1883,8 +1883,8 @@ xf86XVFillKeyHelper (ScreenPtr pScreen, CARD32 key, RegionPtr clipboxes)
 {
    DrawablePtr root = &pScreen->root->drawable;
    ChangeGCVal pval[2];
-   BoxPtr pbox = REGION_RECTS(clipboxes);
-   int i, nbox = REGION_NUM_RECTS(clipboxes);
+   BoxPtr pbox = RegionRects(clipboxes);
+   int i, nbox = RegionNumRects(clipboxes);
    xRectangle *rects;
    GCPtr gc;
 
@@ -1936,7 +1936,7 @@ xf86XVClipVideoHelper(
 ){
     double xsw, xdw, ysw, ydw;
     INT32 delta;
-    BoxPtr extents = REGION_EXTENTS(DummyScreen, reg);
+    BoxPtr extents = RegionExtents(reg);
     int diff;
 
     xsw = (*xb - *xa) << 16;
@@ -1998,9 +1998,9 @@ xf86XVClipVideoHelper(
 	(dst->y1 > extents->y1) || (dst->y2 < extents->y2))
     {
 	RegionRec clipReg;
-	REGION_INIT(DummyScreen, &clipReg, dst, 1);
-	REGION_INTERSECT(DummyScreen, reg, reg, &clipReg);
-	REGION_UNINIT(DummyScreen, &clipReg);
+	RegionInit(&clipReg, dst, 1);
+	RegionIntersect(reg, reg, &clipReg);
+	RegionUninit(&clipReg);
     }
     return TRUE;
 }
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index f7cea5e..63c77de 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1157,7 +1157,7 @@ DRIDCNTreeTraversal(WindowPtr pWin, pointer data)
 	ScreenPtr pScreen = pWin->drawable.pScreen;
 	DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
-	if (REGION_NUM_RECTS(&pWin->clipList) > 0) {
+	if (RegionNumRects(&pWin->clipList) > 0) {
 	    WindowPtr *pDRIWindows = (WindowPtr*)data;
 	    int i = 0;
 
@@ -1269,7 +1269,7 @@ DRICreateDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable,
 	    pDRIDrawablePriv->pScreen = pScreen;
 	    pDRIDrawablePriv->refCount = 1;
 	    pDRIDrawablePriv->drawableIndex = -1;
-	    pDRIDrawablePriv->nrects = REGION_NUM_RECTS(&pWin->clipList);
+	    pDRIDrawablePriv->nrects = RegionNumRects(&pWin->clipList);
 
 	    /* save private off of preallocated index */
 	    dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey,
@@ -1288,8 +1288,8 @@ DRICreateDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable,
 	    drmUpdateDrawableInfo(pDRIPriv->drmFD,
 				  pDRIDrawablePriv->hwDrawable,
 				  DRM_DRAWABLE_CLIPRECTS,
-				  REGION_NUM_RECTS(&pWin->clipList),
-				  REGION_RECTS(&pWin->clipList));
+				  RegionNumRects(&pWin->clipList),
+				  RegionRects(&pWin->clipList));
 	    *hHWDrawable = pDRIDrawablePriv->hwDrawable;
 	}
     }
@@ -1502,8 +1502,8 @@ DRIGetDrawableInfo(ScreenPtr pScreen,
 #endif
 	    *W = (int)(pWin->drawable.width);
 	    *H = (int)(pWin->drawable.height);
-	    *numClipRects = REGION_NUM_RECTS(&pWin->clipList);
-	    *pClipRects = (drm_clip_rect_t *)REGION_RECTS(&pWin->clipList);
+	    *numClipRects = RegionNumRects(&pWin->clipList);
+	    *pClipRects = (drm_clip_rect_t *)RegionRects(&pWin->clipList);
 
 	    if (!*numClipRects && pDRIPriv->fullscreen) {
 				/* use fake full-screen clip rect */
@@ -1883,10 +1883,10 @@ DRITreeTraversal(WindowPtr pWin, pointer data)
         ScreenPtr pScreen = pWin->drawable.pScreen;
         DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
-	if(REGION_NUM_RECTS(&(pWin->clipList)) > 0) {
+	if(RegionNumRects(&(pWin->clipList)) > 0) {
 	   RegionPtr reg = (RegionPtr)data;
 
-	   REGION_UNION(pScreen, reg, reg, &(pWin->clipList));
+	   RegionUnion(reg, reg, &(pWin->clipList));
 	   pDRIPriv->nrWalked++;
 	}
 
@@ -1932,21 +1932,21 @@ DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     if(pDRIPriv->nrWindowsVisible > 0) {
        RegionRec reg;
 
-       REGION_NULL(pScreen, &reg);
+       RegionNull(&reg);
        pDRIPriv->nrWalked = 0;
        TraverseTree(pWin, DRITreeTraversal, (pointer)(&reg));
 
-       if(REGION_NOTEMPTY(pScreen, &reg)) {
-           REGION_TRANSLATE(pScreen, &reg, ptOldOrg.x - pWin->drawable.x,  
+       if(RegionNotEmpty(&reg)) {
+           RegionTranslate(&reg, ptOldOrg.x - pWin->drawable.x,
                                         ptOldOrg.y - pWin->drawable.y);
-           REGION_INTERSECT(pScreen, &reg, &reg, prgnSrc);
+           RegionIntersect(&reg, &reg, prgnSrc);
 
            /* The MoveBuffers interface is not ideal */
            (*pDRIPriv->pDriverInfo->MoveBuffers)(pWin, ptOldOrg, &reg,
 				pDRIPriv->pDriverInfo->ddxDrawableTableEntry);
        }
 
-       REGION_UNINIT(pScreen, &reg);
+       RegionUninit(&reg);
     }
 
     /* call lower wrapped functions */
@@ -2122,7 +2122,7 @@ DRIClipNotify(WindowPtr pWin, int dx, int dy)
     if(!pDRIPriv) return;
 
     if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) {
-        int nrects = REGION_NUM_RECTS(&pWin->clipList);
+        int nrects = RegionNumRects(&pWin->clipList);
 
         if(!pDRIPriv->windowsTouched) {
             DRILockTree(pScreen);
@@ -2143,7 +2143,7 @@ DRIClipNotify(WindowPtr pWin, int dx, int dy)
 
 	drmUpdateDrawableInfo(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable,
 			      DRM_DRAWABLE_CLIPRECTS,
-			      nrects, REGION_RECTS(&pWin->clipList));
+			      nrects, RegionRects(&pWin->clipList));
     }
 
     /* call lower wrapped functions */
@@ -2368,9 +2368,9 @@ DRIMoveBuffersHelper(
    BoxRec tmpBox;
    int y, nbox;
 
-   extents = REGION_EXTENTS(pScreen, reg);
-   nbox = REGION_NUM_RECTS(reg);
-   pbox = REGION_RECTS(reg);
+   extents = RegionExtents(reg);
+   nbox = RegionNumRects(reg);
+   pbox = RegionRects(reg);
 
    if((dy > 0) && (dy < (extents->y2 - extents->y1))) {
      *ydir = -1;
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 45a8271..3c8d3a8 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -461,7 +461,7 @@ do_get_buffers(DrawablePtr pDraw, int *width, int *height,
 	box.y1 = 0;
 	box.x2 = pPriv->width;
 	box.y2 = pPriv->height;
-	REGION_INIT(pDraw->pScreen, &region, &box, 0);
+	RegionInit(&region, &box, 0);
 
 	DRI2CopyRegion(pDraw, &region, DRI2BufferFakeFrontLeft,
 		       DRI2BufferFrontLeft);
@@ -614,7 +614,7 @@ DRI2CanFlip(DrawablePtr pDraw)
     pWinPixmap = pScreen->GetWindowPixmap(pWin);
     if (pRootPixmap != pWinPixmap)
 	return FALSE;
-    if (!REGION_EQUAL(pScreen, &pWin->clipList, &pRoot->winSize))
+    if (!RegionEqual(&pWin->clipList, &pRoot->winSize))
 	return FALSE;
 
     return TRUE;
@@ -710,7 +710,7 @@ DRI2SwapComplete(ClientPtr client, DrawablePtr pDraw, int frame,
     box.y1 = 0;
     box.x2 = pDraw->width;
     box.y2 = pDraw->height;
-    REGION_INIT(pScreen, &region, &box, 0);
+    RegionInit(&region, &box, 0);
     DRI2CopyRegion(pDraw, &region, DRI2BufferFakeFrontLeft,
 		   DRI2BufferFrontLeft);
 
@@ -782,7 +782,7 @@ DRI2SwapBuffers(ClientPtr client, DrawablePtr pDraw, CARD64 target_msc,
 	box.y1 = 0;
 	box.x2 = pDraw->width;
 	box.y2 = pDraw->height;
-	REGION_INIT(pScreen, &region, &box, 0);
+	RegionInit(&region, &box, 0);
 
 	pPriv->swapsPending++;
 
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 065ba48..60003d5 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -3155,9 +3155,9 @@ xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn,
 						  &crtc_box);
 
 	if (crtc) {
-	    REGION_INIT (pScreen, &crtc_region_local, &crtc_box, 1);
+	    RegionInit(&crtc_region_local, &crtc_box, 1);
 	    crtc_region = &crtc_region_local;
-	    REGION_INTERSECT (pScreen, crtc_region, crtc_region, reg);
+	    RegionIntersect(crtc_region, crtc_region, reg);
 	}
 	*crtc_ret = crtc;
     }
@@ -3166,7 +3166,7 @@ xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn,
 				crtc_region, width, height);
 
     if (crtc_region != reg)
-	REGION_UNINIT (pScreen, &crtc_region_local);
+	RegionUninit(&crtc_region_local);
 
     return ret;
 }
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index e3683a8..4cc99ad 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -81,8 +81,8 @@ xf86RotateCrtcRedisplay (xf86CrtcPtr crtc, RegionPtr region)
     PictFormatPtr	format = compWindowFormat (screen->root);
     int			error;
     PicturePtr		src, dst;
-    int			n = REGION_NUM_RECTS(region);
-    BoxPtr		b = REGION_RECTS(region);
+    int			n = RegionNumRects(region);
+    BoxPtr		b = RegionRects(region);
     XID			include_inferiors = IncludeInferiors;
     
     src = CreatePicture (None,
@@ -167,10 +167,10 @@ xf86CrtcDamageShadow (xf86CrtcPtr crtc)
     if (damage_box.y1 < 0) damage_box.y1 = 0;
     if (damage_box.x2 > pScreen->width) damage_box.x2 = pScreen->width;
     if (damage_box.y2 > pScreen->height) damage_box.y2 = pScreen->height;
-    REGION_INIT (pScreen, &damage_region, &damage_box, 1);
+    RegionInit(&damage_region, &damage_box, 1);
     DamageRegionAppend (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
 			&damage_region);
-    REGION_UNINIT (pScreen, &damage_region);
+    RegionUninit(&damage_region);
     crtc->shadowClear = TRUE;
 }
 
@@ -217,7 +217,7 @@ xf86RotateRedisplay(ScreenPtr pScreen)
 	return FALSE;
     xf86RotatePrepare (pScreen);
     region = DamageRegion(damage);
-    if (REGION_NOTEMPTY(pScreen, region)) 
+    if (RegionNotEmpty(region))
     {
 	int			c;
 	SourceValidateProcPtr	SourceValidate;
@@ -240,14 +240,14 @@ xf86RotateRedisplay(ScreenPtr pScreen)
 		RegionRec   crtc_damage;
 
 		/* compute portion of damage that overlaps crtc */
-		REGION_INIT(pScreen, &crtc_damage, &crtc->bounds, 1);
-		REGION_INTERSECT (pScreen, &crtc_damage, &crtc_damage, region);
+		RegionInit(&crtc_damage, &crtc->bounds, 1);
+		RegionIntersect(&crtc_damage, &crtc_damage, region);
 		
 		/* update damaged region */
-		if (REGION_NOTEMPTY(pScreen, &crtc_damage))
+		if (RegionNotEmpty(&crtc_damage))
     		    xf86RotateCrtcRedisplay (crtc, &crtc_damage);
 		
-		REGION_UNINIT (pScreen, &crtc_damage);
+		RegionUninit(&crtc_damage);
 	    }
 	}
 	pScreen->SourceValidate = SourceValidate;
diff --git a/hw/xfree86/shadowfb/shadow.c b/hw/xfree86/shadowfb/shadow.c
index fd5f26c..a0e4b9e 100644
--- a/hw/xfree86/shadowfb/shadow.c
+++ b/hw/xfree86/shadowfb/shadow.c
@@ -272,18 +272,18 @@ ShadowCopyWindow(
     RegionRec rgnDst;
 
     if (pPriv->vtSema) {
-        REGION_NULL(pWin->drawable.pScreen, &rgnDst);
-	REGION_COPY(pWin->drawable.pScreen, &rgnDst, prgn);
+        RegionNull(&rgnDst);
+	RegionCopy(&rgnDst, prgn);
         
-        REGION_TRANSLATE(pWin->drawable.pScreen, &rgnDst,
+        RegionTranslate(&rgnDst,
                          pWin->drawable.x - ptOldOrg.x,
                          pWin->drawable.y - ptOldOrg.y);
-        REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, &rgnDst);
-        if ((num = REGION_NUM_RECTS(&rgnDst))) {
+        RegionIntersect(&rgnDst, &pWin->borderClip, &rgnDst);
+        if ((num = RegionNumRects(&rgnDst))) {
             if(pPriv->preRefresh)
-                (*pPriv->preRefresh)(pPriv->pScrn, num, REGION_RECTS(&rgnDst));
+                (*pPriv->preRefresh)(pPriv->pScrn, num, RegionRects(&rgnDst));
         } else {
-            REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
+            RegionUninit(&rgnDst);
         }
     }
     
@@ -293,8 +293,8 @@ ShadowCopyWindow(
     
     if (num) {
         if (pPriv->postRefresh)
-            (*pPriv->postRefresh)(pPriv->pScrn, num, REGION_RECTS(&rgnDst));
-        REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
+            (*pPriv->postRefresh)(pPriv->pScrn, num, RegionRects(&rgnDst));
+        RegionUninit(&rgnDst);
     }
 }
 
@@ -1353,37 +1353,37 @@ ShadowFontToBox(BoxPtr BB, DrawablePtr pDrawable, GCPtr pGC, int x, int y,
 	}
 	right += pFont->info.maxbounds.rightSideBearing;
 	BB->x1 =
-	    max(pDrawable->x + x - left, (REGION_EXTENTS(pGC->pScreen,
+	    max(pDrawable->x + x - left, (RegionExtents(
 		&((WindowPtr) pDrawable)->winSize))->x1);
 	BB->y1 =
 	    max(pDrawable->y + y - ascent,
-	    (REGION_EXTENTS(pGC->pScreen,
+	    (RegionExtents(
              &((WindowPtr) pDrawable)->winSize))->y1);
 	BB->x2 =
 	    min(pDrawable->x + x + right,
-	    (REGION_EXTENTS(pGC->pScreen,
+	    (RegionExtents(
              &((WindowPtr) pDrawable)->winSize))->x2);
 	BB->y2 =
 	    min(pDrawable->y + y + descent,
-	    (REGION_EXTENTS(pGC->pScreen,
+	    (RegionExtents(
              &((WindowPtr) pDrawable)->winSize))->y2);
     } else {
     	ShadowTextExtent(pFont, count, chars, wide ? (FONTLASTROW(pFont) == 0)
                          ? Linear16Bit : TwoD16Bit : Linear8Bit, BB);
 	BB->x1 =
-	    max(pDrawable->x + x + BB->x1, (REGION_EXTENTS(pGC->pScreen,
+	    max(pDrawable->x + x + BB->x1, (RegionExtents(
 		&((WindowPtr) pDrawable)->winSize))->x1);
 	BB->y1 =
 	    max(pDrawable->y + y + BB->y1,
-	    (REGION_EXTENTS(pGC->pScreen,
+	    (RegionExtents(
              &((WindowPtr) pDrawable)->winSize))->y1);
 	BB->x2 =
 	    min(pDrawable->x + x + BB->x2,
-	    (REGION_EXTENTS(pGC->pScreen,
+	    (RegionExtents(
 	     &((WindowPtr) pDrawable)->winSize))->x2);
 	BB->y2 =
 	    min(pDrawable->y + y + BB->y2,
-	    (REGION_EXTENTS(pGC->pScreen, 
+	    (RegionExtents(
 	     &((WindowPtr) pDrawable)->winSize))->y2);
     }
 }
diff --git a/hw/xfree86/xaa/xaaBitBlt.c b/hw/xfree86/xaa/xaaBitBlt.c
index 75033bc..5148ed4 100644
--- a/hw/xfree86/xaa/xaaBitBlt.c
+++ b/hw/xfree86/xaa/xaaBitBlt.c
@@ -118,8 +118,8 @@ XAABitBlt(
 	    fastExpose = 0;
 	}
     } else {
-	REGION_INIT(pGC->pScreen, &rgnDst, &fastBox, 1);
-	REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst, prgnSrcClip);
+	RegionInit(&rgnDst, &fastBox, 1);
+	RegionIntersect(&rgnDst, &rgnDst, prgnSrcClip);
     }
 
     dstx += pDstDrawable->x;
@@ -128,9 +128,9 @@ XAABitBlt(
     if (pDstDrawable->type == DRAWABLE_WINDOW) {
 	if (!((WindowPtr)pDstDrawable)->realized) {
 	    if (!fastClip)
-		REGION_UNINIT(pGC->pScreen, &rgnDst);
+		RegionUninit(&rgnDst);
 	    if (freeSrcClip)
-		REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+		RegionDestroy(prgnSrcClip);
 	    return NULL;
 	}
     }
@@ -153,8 +153,8 @@ XAABitBlt(
 	   blown region and call intersect */
 
 	cclip = pGC->pCompositeClip;
-        if (REGION_NUM_RECTS(cclip) == 1) {
-	    BoxPtr pBox = REGION_RECTS(cclip);
+        if (RegionNumRects(cclip) == 1) {
+	    BoxPtr pBox = RegionRects(cclip);
 
 	    if (fastBox.x1 < pBox->x1) fastBox.x1 = pBox->x1;
 	    if (fastBox.x2 > pBox->x2) fastBox.x2 = pBox->x2;
@@ -163,37 +163,37 @@ XAABitBlt(
 
 	    /* Check to see if the region is empty */
 	    if (fastBox.x1 >= fastBox.x2 || fastBox.y1 >= fastBox.y2) {
-		REGION_NULL(pGC->pScreen, &rgnDst);
+		RegionNull(&rgnDst);
 	    } else {
-		REGION_INIT(pGC->pScreen, &rgnDst, &fastBox, 1);
+		RegionInit(&rgnDst, &fastBox, 1);
 	    }
 	} else {
 	    /* We must turn off fastClip now, since we must create
 	       a full blown region.  It is intersected with the
 	       composite clip below. */
 	    fastClip = 0;
-	    REGION_INIT(pGC->pScreen, &rgnDst, &fastBox,1);
+	    RegionInit(&rgnDst, &fastBox,1);
 	}
     } else {
-        REGION_TRANSLATE(pGC->pScreen, &rgnDst, -dx, -dy);
+        RegionTranslate(&rgnDst, -dx, -dy);
     }
 
     if (!fastClip) {
-	REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst,
+	RegionIntersect(&rgnDst, &rgnDst,
 				 pGC->pCompositeClip);
     }
 
     /* Do bit blitting */
-    numRects = REGION_NUM_RECTS(&rgnDst);
+    numRects = RegionNumRects(&rgnDst);
     if (numRects && width && height) {
 	if(!(pptSrc = (DDXPointPtr)malloc(numRects *
 						  sizeof(DDXPointRec)))) {
-	    REGION_UNINIT(pGC->pScreen, &rgnDst);
+	    RegionUninit(&rgnDst);
 	    if (freeSrcClip)
-		REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+		RegionDestroy(prgnSrcClip);
 	    return NULL;
 	}
-	pbox = REGION_RECTS(&rgnDst);
+	pbox = RegionRects(&rgnDst);
 	ppt = pptSrc;
 	for (i = numRects; --i >= 0; pbox++, ppt++) {
 	    ppt->x = pbox->x1 + dx;
@@ -214,8 +214,8 @@ XAABitBlt(
 				  (int)origSource.height,
 				  origDest.x, origDest.y, bitPlane);
     }
-    REGION_UNINIT(pGC->pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
     if (freeSrcClip)
-	REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+	RegionDestroy(prgnSrcClip);
     return prgnExposed;
 }
diff --git a/hw/xfree86/xaa/xaaCpyArea.c b/hw/xfree86/xaa/xaaCpyArea.c
index 1a03bfd..443a0e1 100644
--- a/hw/xfree86/xaa/xaaCpyArea.c
+++ b/hw/xfree86/xaa/xaaCpyArea.c
@@ -95,8 +95,8 @@ XAADoBitBlt(
                ((pSrc->type == DRAWABLE_WINDOW) &&
                 (pDst->type == DRAWABLE_WINDOW)));
 
-    pbox = REGION_RECTS(prgnDst);
-    nbox = REGION_NUM_RECTS(prgnDst);
+    pbox = RegionRects(prgnDst);
+    nbox = RegionNumRects(prgnDst);
 
     pboxNew1 = NULL;
     pptNew1 = NULL;
@@ -204,8 +204,8 @@ XAADoImageWrite(
     int srcwidth;
     unsigned char* psrcBase;			/* start of image */
     unsigned char* srcPntr;			/* index into the image */
-    BoxPtr pbox = REGION_RECTS(prgnDst);
-    int nbox = REGION_NUM_RECTS(prgnDst);
+    BoxPtr pbox = RegionRects(prgnDst);
+    int nbox = RegionNumRects(prgnDst);
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
     int Bpp = pSrc->bitsPerPixel >> 3; 
 
@@ -233,8 +233,8 @@ XAADoImageRead(
     int dstwidth;
     unsigned char* pdstBase;			/* start of image */
     unsigned char* dstPntr;			/* index into the image */
-    BoxPtr pbox = REGION_RECTS(prgnDst);
-    int nbox = REGION_NUM_RECTS(prgnDst);
+    BoxPtr pbox = RegionRects(prgnDst);
+    int nbox = RegionNumRects(prgnDst);
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
     int Bpp = pSrc->bitsPerPixel >> 3;  /* wouldn't get here unless both
                                            src and dst have same bpp */
diff --git a/hw/xfree86/xaa/xaaCpyPlane.c b/hw/xfree86/xaa/xaaCpyPlane.c
index e3010ea..6d2b3a0 100644
--- a/hw/xfree86/xaa/xaaCpyPlane.c
+++ b/hw/xfree86/xaa/xaaCpyPlane.c
@@ -76,8 +76,8 @@ XAACopyPlane1toNColorExpand(
     DDXPointPtr   pptSrc )
 {
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    BoxPtr pbox = REGION_RECTS(rgnDst);
-    int numrects = REGION_NUM_RECTS(rgnDst);
+    BoxPtr pbox = RegionRects(rgnDst);
+    int numrects = RegionNumRects(rgnDst);
     unsigned char *src = ((PixmapPtr)pSrc)->devPrivate.ptr;
     int srcwidth = ((PixmapPtr)pSrc)->devKind; 
     
@@ -101,8 +101,8 @@ XAACopyPlaneNtoNColorExpand(
     DDXPointPtr   pptSrc 
 ){
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    BoxPtr pbox = REGION_RECTS(rgnDst);
-    int numrects = REGION_NUM_RECTS(rgnDst);
+    BoxPtr pbox = RegionRects(rgnDst);
+    int numrects = RegionNumRects(rgnDst);
     unsigned char *src = ((PixmapPtr)pSrc)->devPrivate.ptr;
     unsigned char *data, *srcPtr, *dataPtr;
     int srcwidth = ((PixmapPtr)pSrc)->devKind; 
@@ -168,14 +168,14 @@ XAAPushPixelsSolidColorExpansion(
     int xOrg, int yOrg )
 {
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-   int MaxBoxes = REGION_NUM_RECTS(pGC->pCompositeClip);
+   int MaxBoxes = RegionNumRects(pGC->pCompositeClip);
    BoxPtr	pbox, pClipBoxes;
    int		nboxes, srcx, srcy;
    xRectangle TheRect;
    unsigned char *src = pBitMap->devPrivate.ptr;
    int srcwidth = pBitMap->devKind;
 
-   if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+   if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
    TheRect.x = xOrg;
diff --git a/hw/xfree86/xaa/xaaCpyWin.c b/hw/xfree86/xaa/xaaCpyWin.c
index d58db8e..c3c2690 100644
--- a/hw/xfree86/xaa/xaaCpyWin.c
+++ b/hw/xfree86/xaa/xaaCpyWin.c
@@ -49,18 +49,18 @@ XAACopyWindow(
 
     pwinRoot = pScreen->root;
 
-    REGION_NULL(pScreen, &rgnDst);
+    RegionNull(&rgnDst);
 
     dx = ptOldOrg.x - pWin->drawable.x;
     dy = ptOldOrg.y - pWin->drawable.y;
-    REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy);
-    REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
+    RegionTranslate(prgnSrc, -dx, -dy);
+    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
 
-    pbox = REGION_RECTS(&rgnDst);
-    nbox = REGION_NUM_RECTS(&rgnDst);
+    pbox = RegionRects(&rgnDst);
+    nbox = RegionNumRects(&rgnDst);
     if(!nbox || 
       !(pptSrc = (DDXPointPtr )malloc(nbox * sizeof(DDXPointRec)))) {
-	REGION_UNINIT(pScreen, &rgnDst);
+	RegionUninit(&rgnDst);
 	return;
     }
     ppt = pptSrc;
@@ -78,5 +78,5 @@ XAACopyWindow(
         		&(infoRec->ScratchGC), &rgnDst, pptSrc);
 
     free(pptSrc);
-    REGION_UNINIT(pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
 }
diff --git a/hw/xfree86/xaa/xaaDashLine.c b/hw/xfree86/xaa/xaaDashLine.c
index 63233e0..e847084 100644
--- a/hw/xfree86/xaa/xaaDashLine.c
+++ b/hw/xfree86/xaa/xaaDashLine.c
@@ -37,8 +37,8 @@ XAAPolyLinesDashed(
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
     XAAGCPtr   pGCPriv = (XAAGCPtr)dixLookupPrivate(&pGC->devPrivates,
 						    XAAGetGCKey());
-    BoxPtr pboxInit = REGION_RECTS(pGC->pCompositeClip);
-    int nboxInit = REGION_NUM_RECTS(pGC->pCompositeClip);
+    BoxPtr pboxInit = RegionRects(pGC->pCompositeClip);
+    int nboxInit = RegionNumRects(pGC->pCompositeClip);
     unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
     int xorg = pDrawable->x;
     int yorg = pDrawable->y;
diff --git a/hw/xfree86/xaa/xaaFillArc.c b/hw/xfree86/xaa/xaaFillArc.c
index d83922c..47d8041 100644
--- a/hw/xfree86/xaa/xaaFillArc.c
+++ b/hw/xfree86/xaa/xaaFillArc.c
@@ -171,7 +171,7 @@ XAAPolyFillArcSolid(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc *parcs)
 
     cclip = pGC->pCompositeClip;
 
-    if(!REGION_NUM_RECTS(cclip))
+    if(!RegionNumRects(cclip))
 	return;
 
     for (arc = parcs, i = narcs; --i >= 0; arc++)
@@ -198,7 +198,7 @@ XAAPolyFillArcSolid(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc *parcs)
  	    y2 = box.y1 + (int)arc->height + 1;
  	    box.y2 = y2;
  	    if ( (x2 <= SHRT_MAX) && (y2 <= SHRT_MAX) &&
- 		    (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN) )
+		    (RegionContainsRect(cclip, &box) == rgnIN) )
 	    {
 		if ((arc->angle2 >= FULLCIRCLE) ||
 		    (arc->angle2 <= -FULLCIRCLE))
diff --git a/hw/xfree86/xaa/xaaFillPoly.c b/hw/xfree86/xaa/xaaFillPoly.c
index 6f11e35..289a3ca 100644
--- a/hw/xfree86/xaa/xaaFillPoly.c
+++ b/hw/xfree86/xaa/xaaFillPoly.c
@@ -213,7 +213,7 @@ XAAFillPolygonSolid(
     int		    c, y, maxy, h, yoffset;
     DDXPointPtr	    topPoint;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     if (mode == CoordModePrevious) {
@@ -226,7 +226,7 @@ XAAFillPolygonSolid(
         mode = CoordModeOrigin;
     }
     
-    if (REGION_NUM_RECTS(pGC->pCompositeClip) != 1) {
+    if (RegionNumRects(pGC->pCompositeClip) != 1) {
 	miFillPolygon (pDraw, pGC, shape, mode, count, ptsIn);
 	return;
     }
@@ -676,7 +676,7 @@ XAAFillPolygonStippled(
     RectFuncPtr	    RectFunc = NULL;
     TrapFuncPtr	    TrapFunc = NULL;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     if (mode == CoordModePrevious) {
@@ -689,7 +689,7 @@ XAAFillPolygonStippled(
         mode = CoordModeOrigin;
     }
     
-    if (REGION_NUM_RECTS(pGC->pCompositeClip) != 1) {
+    if (RegionNumRects(pGC->pCompositeClip) != 1) {
 	miFillPolygon (pDraw, pGC, shape, mode, count, ptsIn);
 	return;
     }
@@ -836,7 +836,7 @@ XAAFillPolygonTiled(
     RectFuncPtr	    RectFunc = NULL;
     TrapFuncPtr	    TrapFunc = NULL;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     if (mode == CoordModePrevious) {
@@ -849,7 +849,7 @@ XAAFillPolygonTiled(
         mode = CoordModeOrigin;
     }
     
-    if (REGION_NUM_RECTS(pGC->pCompositeClip) != 1) {
+    if (RegionNumRects(pGC->pCompositeClip) != 1) {
 	miFillPolygon (pDraw, pGC, shape, mode, count, ptsIn);
 	return;
     }
diff --git a/hw/xfree86/xaa/xaaFillRect.c b/hw/xfree86/xaa/xaaFillRect.c
index 0b83ef3..dde31c1 100644
--- a/hw/xfree86/xaa/xaaFillRect.c
+++ b/hw/xfree86/xaa/xaaFillRect.c
@@ -40,7 +40,7 @@ XAAPolyFillRect(
     if((nrectFill <= 0) || !pGC->planemask)
         return;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     switch(pGC->fillStyle) {
@@ -944,8 +944,8 @@ XAAClipAndRenderRects(
     pboxClippedBase = (BoxPtr)infoRec->PreAllocMem;
     pboxClipped = pboxClippedBase;
 
-    if (REGION_NUM_RECTS(pGC->pCompositeClip) == 1) {
-	pextent = REGION_RECTS(pGC->pCompositeClip);
+    if (RegionNumRects(pGC->pCompositeClip) == 1) {
+	pextent = RegionRects(pGC->pCompositeClip);
     	while (nrectFill--) {
 	    pboxClipped->x1 = max(pextent->x1, prect->x);
 	    pboxClipped->y1 = max(pextent->y1, prect->y);
@@ -967,7 +967,7 @@ XAAClipAndRenderRects(
 	    }
     	}
     } else {
-	pextent = REGION_EXTENTS(pGC->pScreen, pGC->pCompositeClip);
+	pextent = RegionExtents(pGC->pCompositeClip);
     	while (nrectFill--) {
 	    int n;
 	    BoxRec box, *pbox;
@@ -986,8 +986,8 @@ XAAClipAndRenderRects(
 	    if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
 	    	continue;
     
-	    n = REGION_NUM_RECTS (pGC->pCompositeClip);
-	    pbox = REGION_RECTS(pGC->pCompositeClip);
+	    n = RegionNumRects (pGC->pCompositeClip);
+	    pbox = RegionRects(pGC->pCompositeClip);
     
 	    /* clip the rectangle to each box in the clip region
 	       this is logically equivalent to calling Intersect()
@@ -1030,8 +1030,8 @@ XAAGetRectClipBoxes(
     xRectangle	*prect = prectInit;
     RegionPtr   prgnClip = pGC->pCompositeClip;
 
-    if (REGION_NUM_RECTS(prgnClip) == 1) {
-	pextent = REGION_RECTS(prgnClip);
+    if (RegionNumRects(prgnClip) == 1) {
+	pextent = RegionRects(prgnClip);
     	while (nrectFill--) {
 	    pboxClipped->x1 = max(pextent->x1, prect->x);
 	    pboxClipped->y1 = max(pextent->y1, prect->y);
@@ -1049,7 +1049,7 @@ XAAGetRectClipBoxes(
 	    }
     	}
     } else {
-	pextent = REGION_EXTENTS(pGC->pScreen, prgnClip);
+	pextent = RegionExtents(prgnClip);
     	while (nrectFill--) {
 	    int n;
 	    BoxRec box, *pbox;
@@ -1068,8 +1068,8 @@ XAAGetRectClipBoxes(
 	    if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
 	    	continue;
     
-	    n = REGION_NUM_RECTS (prgnClip);
-	    pbox = REGION_RECTS(prgnClip);
+	    n = RegionNumRects (prgnClip);
+	    pbox = RegionRects(prgnClip);
     
 	    /* clip the rectangle to each box in the clip region
 	       this is logically equivalent to calling Intersect()
diff --git a/hw/xfree86/xaa/xaaImage.c b/hw/xfree86/xaa/xaaImage.c
index 30caa2a..e88f45c 100644
--- a/hw/xfree86/xaa/xaaImage.c
+++ b/hw/xfree86/xaa/xaaImage.c
@@ -406,7 +406,7 @@ XAAPutImage(
     Bool depthBug = FALSE;
     if(!w || !h) return;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     depthBug = XAA_DEPTH_BUG(pGC);
@@ -431,7 +431,7 @@ XAAPutImage(
 	     !(infoRec->WriteBitmapFlags & NO_PLANEMASK) &&
 	     !(infoRec->WriteBitmapFlags & TRANSPARENCY_ONLY))){
 
-	int MaxBoxes = REGION_NUM_RECTS(pGC->pCompositeClip);
+	int MaxBoxes = RegionNumRects(pGC->pCompositeClip);
 	BoxPtr pbox, pClipBoxes;
 	int nboxes, srcx, srcy, srcwidth;
 	xRectangle TheRect;
diff --git a/hw/xfree86/xaa/xaaLine.c b/hw/xfree86/xaa/xaaLine.c
index 7469de1..d6c06eb 100644
--- a/hw/xfree86/xaa/xaaLine.c
+++ b/hw/xfree86/xaa/xaaLine.c
@@ -35,8 +35,8 @@ XAAPolyLines(
 #endif
 ){
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    BoxPtr pboxInit = REGION_RECTS(pGC->pCompositeClip);
-    int nboxInit = REGION_NUM_RECTS(pGC->pCompositeClip);
+    BoxPtr pboxInit = RegionRects(pGC->pCompositeClip);
+    int nboxInit = RegionNumRects(pGC->pCompositeClip);
     unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
     int xorg = pDrawable->x;
     int yorg = pDrawable->y;
diff --git a/hw/xfree86/xaa/xaaNonTEText.c b/hw/xfree86/xaa/xaaNonTEText.c
index 072fe19..a7fcf7a 100644
--- a/hw/xfree86/xaa/xaaNonTEText.c
+++ b/hw/xfree86/xaa/xaaNonTEText.c
@@ -128,7 +128,7 @@ XAAImageText8NonTEColorExpansion(
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
     unsigned long n;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     (*pGC->font->get_glyphs)(pGC->font, (unsigned long)count, 
@@ -153,7 +153,7 @@ XAAImageText16NonTEColorExpansion(
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
     unsigned long n;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     (*pGC->font->get_glyphs)(
@@ -188,7 +188,7 @@ XAAImageGlyphBltNonTEColorExpansion(
 ){
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     ImageGlyphBltNonTEColorExpansion(
@@ -208,7 +208,7 @@ XAAPolyGlyphBltNonTEColorExpansion(
 ){
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     PolyGlyphBltNonTEColorExpansion(
@@ -368,8 +368,8 @@ ImageGlyphBltNonTEColorExpansion(
     int skippix, skipglyph, width, n, i;
     int Left, Right, Top, Bottom;
     int LeftEdge, RightEdge, ytop, ybot;
-    int nbox = REGION_NUM_RECTS(cclip);
-    BoxPtr pbox = REGION_RECTS(cclip);
+    int nbox = RegionNumRects(cclip);
+    BoxPtr pbox = RegionRects(cclip);
     Bool AlreadySetup = FALSE;
 
     width = CollectCharacterInfo(infoRec->GlyphInfo, nglyph, ppci, font);
@@ -405,8 +405,8 @@ ImageGlyphBltNonTEColorExpansion(
 	nbox--; pbox++;
     }
  
-    nbox = REGION_NUM_RECTS(cclip);
-    pbox = REGION_RECTS(cclip);
+    nbox = RegionNumRects(cclip);
+    pbox = RegionRects(cclip);
 
     if(infoRec->WriteBitmap && (nglyph > 1) && 
 			((FONTMAXBOUNDS(font, rightSideBearing) - 
@@ -477,8 +477,8 @@ PolyGlyphBltNonTEColorExpansion(
     int skippix, skipglyph, width, n, i;
     int Left, Right, Top, Bottom;
     int LeftEdge, RightEdge;
-    int nbox = REGION_NUM_RECTS(cclip);
-    BoxPtr pbox = REGION_RECTS(cclip);
+    int nbox = RegionNumRects(cclip);
+    BoxPtr pbox = RegionRects(cclip);
 
     width = CollectCharacterInfo(infoRec->GlyphInfo, nglyph, ppci, font);
 
diff --git a/hw/xfree86/xaa/xaaOverlay.c b/hw/xfree86/xaa/xaaOverlay.c
index 14de9bd..4b52bf6 100644
--- a/hw/xfree86/xaa/xaaOverlay.c
+++ b/hw/xfree86/xaa/xaaOverlay.c
@@ -59,18 +59,18 @@ XAACopyWindow8_32(
     if(doUnderlay)
 	freeReg = miOverlayCollectUnderlayRegions(pWin, &borderClip);
 
-    REGION_NULL(pScreen, &rgnDst);
+    RegionNull(&rgnDst);
 
     dx = ptOldOrg.x - pWin->drawable.x;
     dy = ptOldOrg.y - pWin->drawable.y;
-    REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy);
-    REGION_INTERSECT(pScreen, &rgnDst, borderClip, prgnSrc);
+    RegionTranslate(prgnSrc, -dx, -dy);
+    RegionIntersect(&rgnDst, borderClip, prgnSrc);
 
-    pbox = REGION_RECTS(&rgnDst);
-    nbox = REGION_NUM_RECTS(&rgnDst);
+    pbox = RegionRects(&rgnDst);
+    nbox = RegionNumRects(&rgnDst);
     if(!nbox || 
       !(pptSrc = (DDXPointPtr )malloc(nbox * sizeof(DDXPointRec)))) {
-	REGION_UNINIT(pScreen, &rgnDst);
+	RegionUninit(&rgnDst);
 	return;
     }
     ppt = pptSrc;
@@ -88,9 +88,9 @@ XAACopyWindow8_32(
         		&(infoRec->ScratchGC), &rgnDst, pptSrc);
 
     free(pptSrc);
-    REGION_UNINIT(pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
     if(freeReg) 
-	REGION_DESTROY(pScreen, borderClip);
+	RegionDestroy(borderClip);
 }
 
 static void
diff --git a/hw/xfree86/xaa/xaaOverlayDF.c b/hw/xfree86/xaa/xaaOverlayDF.c
index b186cb5..61adec6 100644
--- a/hw/xfree86/xaa/xaaOverlayDF.c
+++ b/hw/xfree86/xaa/xaaOverlayDF.c
@@ -341,18 +341,18 @@ XAAOverCopyWindow(
     infoRec->ScratchGC.alu = GXcopy;
     infoRec->ScratchGC.planemask = ~0;
 
-    REGION_NULL(pScreen, &rgnDst);
+    RegionNull(&rgnDst);
 
     dx = ptOldOrg.x - pWin->drawable.x;
     dy = ptOldOrg.y - pWin->drawable.y;
-    REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy);
-    REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
+    RegionTranslate(prgnSrc, -dx, -dy);
+    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
 
-    nbox = REGION_NUM_RECTS(&rgnDst);
+    nbox = RegionNumRects(&rgnDst);
     if(nbox &&
 	(pptSrc = (DDXPointPtr )malloc(nbox * sizeof(DDXPointRec)))) {
 
-	pbox = REGION_RECTS(&rgnDst);
+	pbox = RegionRects(&rgnDst);
 	for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) {
 	    ppt->x = pbox->x1 + dx;
 	    ppt->y = pbox->y1 + dy;
@@ -371,18 +371,18 @@ XAAOverCopyWindow(
 	free(pptSrc);
     }
 
-    REGION_UNINIT(pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
 
     if(pWin->drawable.depth == 8) {
-      REGION_NULL(pScreen, &rgnDst);
+      RegionNull(&rgnDst);
       miSegregateChildren(pWin, &rgnDst, pScrn->depth);
-      if(REGION_NOTEMPTY(pScreen, &rgnDst)) {
-	REGION_INTERSECT(pScreen, &rgnDst, &rgnDst, prgnSrc);
-	nbox = REGION_NUM_RECTS(&rgnDst);
+      if(RegionNotEmpty(&rgnDst)) {
+	RegionIntersect(&rgnDst, &rgnDst, prgnSrc);
+	nbox = RegionNumRects(&rgnDst);
 	if(nbox &&
 	  (pptSrc = (DDXPointPtr )malloc(nbox * sizeof(DDXPointRec)))){
 
-	    pbox = REGION_RECTS(&rgnDst);
+	    pbox = RegionRects(&rgnDst);
 	    for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) {
 		ppt->x = pbox->x1 + dx;
 		ppt->y = pbox->y1 + dy;
@@ -394,7 +394,7 @@ XAAOverCopyWindow(
 	    free(pptSrc);
 	}
       }
-      REGION_UNINIT(pScreen, &rgnDst);
+      RegionUninit(&rgnDst);
     }
 }
 
@@ -409,13 +409,13 @@ XAAOverWindowExposures(
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
 
     if((pWin->drawable.bitsPerPixel != 8) && infoRec->pScrn->vtSema) {
-	if(REGION_NUM_RECTS(pReg) && infoRec->FillSolidRects) {
+	if(RegionNumRects(pReg) && infoRec->FillSolidRects) {
 	    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pScreen);
 
 	    SWITCH_DEPTH(8);
 	    (*infoRec->FillSolidRects)(infoRec->pScrn, 
 		infoRec->pScrn->colorKey, GXcopy, ~0,
-			REGION_NUM_RECTS(pReg), REGION_RECTS(pReg));
+			RegionNumRects(pReg), RegionRects(pReg));
 	    miWindowExposures(pWin, pReg, pOtherReg);
 	    return;
 	} else if(infoRec->NeedToSync) {
diff --git a/hw/xfree86/xaa/xaaPCache.c b/hw/xfree86/xaa/xaaPCache.c
index 598a1be..f7f6a29 100644
--- a/hw/xfree86/xaa/xaaPCache.c
+++ b/hw/xfree86/xaa/xaaPCache.c
@@ -639,8 +639,8 @@ XAAInitPixmapCache(
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    XAAInfoRecPtr infoRec = (XAAInfoRecPtr)data;
    XAAPixmapCachePrivatePtr pCachePriv;
-   BoxPtr pBox = REGION_RECTS(areas);
-   int nBox = REGION_NUM_RECTS(areas);
+   BoxPtr pBox = RegionRects(areas);
+   int nBox = RegionNumRects(areas);
    int Num512, Num256, Num128, NumPartial, NumColor, NumMono;
    int Target512, Target256;
    CacheLinkPtr List512, List256, List128, ListPartial, ListColor, ListMono;
diff --git a/hw/xfree86/xaa/xaaPict.c b/hw/xfree86/xaa/xaaPict.c
index 38ef21e..aaafacb 100644
--- a/hw/xfree86/xaa/xaaPict.c
+++ b/hw/xfree86/xaa/xaaPict.c
@@ -215,7 +215,7 @@ XAADoComposite (
     BoxPtr pbox;
     int nbox, w, h;
 
-    if(!REGION_NUM_RECTS(pDst->pCompositeClip))
+    if(!RegionNumRects(pDst->pCompositeClip))
         return TRUE;
 
     if(!infoRec->pScrn->vtSema || !DRAWABLE_IS_ON_CARD(pDst->pDrawable))
@@ -273,8 +273,8 @@ XAADoComposite (
                                    width, height))
 		      return TRUE;
 		      
-	  	nbox = REGION_NUM_RECTS(&region);
-	  	pbox = REGION_RECTS(&region);   
+		nbox = RegionNumRects(&region);
+		pbox = RegionRects(&region);
 		
 	        if(!nbox)
 		    return TRUE;	
@@ -298,7 +298,7 @@ XAADoComposite (
 	   	}
 				  
 		/* WriteBitmap sets the Sync flag */		  
-	        REGION_UNINIT(pScreen, &region);
+	        RegionUninit(&region);
 		return TRUE;
 	  }
 
@@ -340,11 +340,11 @@ XAADoComposite (
                                    width, height))
 		return TRUE;
 
-	  nbox = REGION_NUM_RECTS(&region);
-	  pbox = REGION_RECTS(&region);   
+	  nbox = RegionNumRects(&region);
+	  pbox = RegionRects(&region);
 	     
 	  if(!nbox) {
-                REGION_UNINIT(pScreen, &region);
+                RegionUninit(&region);
 		return TRUE;
 	  }
 
@@ -355,7 +355,7 @@ XAADoComposite (
 			((PixmapPtr)(pMask->pDrawable))->devKind, 
 			w, h, flags))
 	  {
-                REGION_UNINIT(pScreen, &region);
+                RegionUninit(&region);
 		return FALSE;
 	  }
 
@@ -371,7 +371,7 @@ XAADoComposite (
 	   }
 
 	   SET_SYNC_FLAG(infoRec);
-	   REGION_UNINIT(pScreen, &region);
+	   RegionUninit(&region);
 	   return TRUE;
 	}
     } else {
@@ -409,11 +409,11 @@ XAADoComposite (
                                    width, height))
 		return TRUE;
 
-	nbox = REGION_NUM_RECTS(&region);
-	pbox = REGION_RECTS(&region);   
+	nbox = RegionNumRects(&region);
+	pbox = RegionRects(&region);
 	     
         if(!nbox) {
-             REGION_UNINIT(pScreen, &region);
+             RegionUninit(&region);
              return TRUE;
         }
 
@@ -423,7 +423,7 @@ XAADoComposite (
 			((PixmapPtr)(pSrc->pDrawable))->devKind, 
 			w, h, flags))
         {
-              REGION_UNINIT(pScreen, &region);
+              RegionUninit(&region);
               return FALSE;
         }
 
@@ -440,7 +440,7 @@ XAADoComposite (
 	 }
 
 	SET_SYNC_FLAG(infoRec);
-	REGION_UNINIT(pScreen, &region);
+	RegionUninit(&region);
 	return TRUE;
     }
 
@@ -476,16 +476,16 @@ XAACompositeSrcCopy (PicturePtr pSrc,
 				   width, height))
 	return;
 
-    nbox = REGION_NUM_RECTS(&region);
-    pbox = REGION_RECTS(&region);   
+    nbox = RegionNumRects(&region);
+    pbox = RegionRects(&region);
 
     if(!nbox) {
-	REGION_UNINIT(pScreen, &region);
+	RegionUninit(&region);
 	return;
     }
     pptSrc = malloc(sizeof(DDXPointRec) * nbox);
     if (!pptSrc) {
-	REGION_UNINIT(pScreen, &region);
+	RegionUninit(&region);
 	return;
     }
     xoff = xSrc - xDst;
@@ -502,7 +502,7 @@ XAACompositeSrcCopy (PicturePtr pSrc,
 		pptSrc);
 
     free(pptSrc);
-    REGION_UNINIT(pScreen, &region);
+    RegionUninit(&region);
     return;
 }
 
@@ -588,7 +588,7 @@ XAADoGlyphs (CARD8         op,
     ScreenPtr	pScreen = pDst->pDrawable->pScreen;
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
 
-    if(!REGION_NUM_RECTS(pDst->pCompositeClip))
+    if(!RegionNumRects(pDst->pCompositeClip))
 	return TRUE;
 
     if(!infoRec->pScrn->vtSema || 
diff --git a/hw/xfree86/xaa/xaaRect.c b/hw/xfree86/xaa/xaaRect.c
index 0a7e174..4a39129 100644
--- a/hw/xfree86/xaa/xaaRect.c
+++ b/hw/xfree86/xaa/xaaRect.c
@@ -46,8 +46,8 @@ XAAPolyRectangleThinSolid(
     int         clipYMax;       /* lower right corner of clip rect */
     int         width, height;  /* width and height of rect */
 
-    nClipRects = REGION_NUM_RECTS(pGC->pCompositeClip);
-    pClipRects = REGION_RECTS(pGC->pCompositeClip);
+    nClipRects = RegionNumRects(pGC->pCompositeClip);
+    pClipRects = RegionRects(pGC->pCompositeClip);
 
     if(!nClipRects) return;
 
diff --git a/hw/xfree86/xaa/xaaSpans.c b/hw/xfree86/xaa/xaaSpans.c
index 46d6d07..a742cba 100644
--- a/hw/xfree86/xaa/xaaSpans.c
+++ b/hw/xfree86/xaa/xaaSpans.c
@@ -49,7 +49,7 @@ XAAFillSpans(
     if((nInit <= 0) || !pGC->planemask)
         return;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     switch(pGC->fillStyle) {
@@ -117,7 +117,7 @@ XAAFillSpans(
     }
 
 
-    if((nInit < 10) || (REGION_NUM_RECTS(pGC->pCompositeClip) != 1))
+    if((nInit < 10) || (RegionNumRects(pGC->pCompositeClip) != 1))
 	fastClip = FALSE;
 
     if(fastClip) {
@@ -797,10 +797,10 @@ XAAClipAndRenderSpans(
     pptNew = pptBase;
     pwidthNew = pwidthBase;
 
-    numRects = REGION_NUM_RECTS(pGC->pCompositeClip);
+    numRects = RegionNumRects(pGC->pCompositeClip);
 
     if(numRects == 1) {
-        BoxPtr pextent = REGION_RECTS(pGC->pCompositeClip);
+        BoxPtr pextent = RegionRects(pGC->pCompositeClip);
 	    
 	while(nspans--) {
 	    if ((pextent->y1 <= ppt->y) && (ppt->y < pextent->y2)) {
@@ -830,7 +830,7 @@ XAAClipAndRenderSpans(
 
 	while(nspans--) {
 	    nbox = numRects;
-	    pbox = REGION_RECTS(pGC->pCompositeClip);
+	    pbox = RegionRects(pGC->pCompositeClip);
 
 	    /* find the first band */
 	    while(nbox && (pbox->y2 <= ppt->y)) {
diff --git a/hw/xfree86/xaa/xaaTEText.c b/hw/xfree86/xaa/xaaTEText.c
index b182283..729e8a8 100644
--- a/hw/xfree86/xaa/xaaTEText.c
+++ b/hw/xfree86/xaa/xaaTEText.c
@@ -110,7 +110,7 @@ XAAImageText8TEColorExpansion(
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
     unsigned long n;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     (*pGC->font->get_glyphs)(pGC->font, (unsigned long)count, 
@@ -134,7 +134,7 @@ XAAImageText16TEColorExpansion(
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
     unsigned long n;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     (*pGC->font->get_glyphs)(
@@ -169,7 +169,7 @@ XAAImageGlyphBltTEColorExpansion(
 {
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     XAAGlyphBltTEColorExpansion(
@@ -189,7 +189,7 @@ XAAPolyGlyphBltTEColorExpansion(
 {
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
     XAAGlyphBltTEColorExpansion(
@@ -229,8 +229,8 @@ XAAGlyphBltTEColorExpansion(
     int skippix, skipglyphs;
     int Left, Right, Top, Bottom;
     int LeftEdge, RightEdge, ytop, ybot;
-    int nbox = REGION_NUM_RECTS(cclip);
-    BoxPtr pbox = REGION_RECTS(cclip);
+    int nbox = RegionNumRects(cclip);
+    BoxPtr pbox = RegionRects(cclip);
     unsigned int **glyphs = NULL; 
     int glyphWidth = FONTMAXBOUNDS(font, characterWidth);
 
diff --git a/hw/xfree86/xaa/xaaWideLine.c b/hw/xfree86/xaa/xaaWideLine.c
index a684d66..79a6159 100644
--- a/hw/xfree86/xaa/xaaWideLine.c
+++ b/hw/xfree86/xaa/xaaWideLine.c
@@ -804,10 +804,10 @@ XAAPolylinesWideSolid (
     int		    yorg = pDrawable->y;
     Bool	    hardClip = FALSE;
 
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip))
+    if(!RegionNumRects(pGC->pCompositeClip))
 	return;
 
-    if(REGION_NUM_RECTS(pGC->pCompositeClip) != 1) {
+    if(RegionNumRects(pGC->pCompositeClip) != 1) {
 	miWideLine(pDrawable, pGC, mode, npt, pPts);
 	return;
     }
diff --git a/hw/xfree86/xaa/xaawrap.h b/hw/xfree86/xaa/xaawrap.h
index 86ba003..3f3c261 100644
--- a/hw/xfree86/xaa/xaawrap.h
+++ b/hw/xfree86/xaa/xaawrap.h
@@ -32,7 +32,7 @@
 #define XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC)\
     XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&(pGC)->devPrivates, XAAGetGCKey()); \
     GCFuncs *oldFuncs = pGC->funcs;\
-    if(!REGION_NUM_RECTS(pGC->pCompositeClip)) return; \
+    if(!RegionNumRects(pGC->pCompositeClip)) return; \
     pGC->funcs = pGCPriv->wrapFuncs;\
     pGC->ops = pGCPriv->wrapOps
 
diff --git a/hw/xnest/Events.c b/hw/xnest/Events.c
index 277718b..194ec63 100644
--- a/hw/xnest/Events.c
+++ b/hw/xnest/Events.c
@@ -93,7 +93,7 @@ xnestCollectExposures(void)
       Box.x2 = Box.x1 + X.xexpose.width;
       Box.y2 = Box.y1 + X.xexpose.height;
       
-      REGION_INIT(pWin->drawable.pScreen, &Rgn, &Box, 1);
+      RegionInit(&Rgn, &Box, 1);
       
       miSendExposures(pWin, &Rgn, Box.x2, Box.y2);
     }
diff --git a/hw/xnest/GC.c b/hw/xnest/GC.c
index 4082bfc..2cd555c 100644
--- a/hw/xnest/GC.c
+++ b/hw/xnest/GC.c
@@ -210,10 +210,10 @@ xnestChangeClip(GCPtr pGC, int type, pointer pValue, int nRects)
       break;
       
     case CT_REGION:
-      nRects = REGION_NUM_RECTS((RegionPtr)pValue);
+      nRects = RegionNumRects((RegionPtr)pValue);
       size = nRects * sizeof(*pRects);
       pRects = (XRectangle *) malloc(size);
-      pBox = REGION_RECTS((RegionPtr)pValue);
+      pBox = RegionRects((RegionPtr)pValue);
       for (i = nRects; i-- > 0; ) {
 	pRects[i].x = pBox[i].x1;
 	pRects[i].y = pBox[i].y1;
@@ -277,7 +277,7 @@ xnestChangeClip(GCPtr pGC, int type, pointer pValue, int nRects)
        * other parts of server can only deal with CT_NONE,
        * CT_PIXMAP and CT_REGION client clips.
        */
-      pGC->clientClip = (pointer) RECTS_TO_REGION(pGC->pScreen, nRects,
+      pGC->clientClip = (pointer) RegionFromRects(nRects,
 						  (xRectangle *)pValue, type);
       free(pValue);
       pValue = pGC->clientClip;
@@ -313,7 +313,7 @@ xnestDestroyClipHelper(GCPtr pGC)
       break;
       
     case CT_REGION:
-      REGION_DESTROY(pGC->pScreen, pGC->clientClip); 
+      RegionDestroy(pGC->clientClip);
       break;
     }
 }
@@ -331,8 +331,8 @@ xnestCopyClip(GCPtr pGCDst, GCPtr pGCSrc)
       break;
 
     case CT_REGION:
-      pRgn = REGION_CREATE(pGCDst->pScreen, NULL, 1);
-      REGION_COPY(pGCDst->pScreen, pRgn, pGCSrc->clientClip);
+      pRgn = RegionCreate(NULL, 1);
+      RegionCopy(pRgn, pGCSrc->clientClip);
       xnestChangeClip(pGCDst, CT_REGION, pRgn, 0);
       break;
     }
diff --git a/hw/xnest/GCOps.c b/hw/xnest/GCOps.c
index ad9668e..6b76fc2 100644
--- a/hw/xnest/GCOps.c
+++ b/hw/xnest/GCOps.c
@@ -131,8 +131,8 @@ xnestBitBlitHelper(GCPtr pGC)
     BoxRec Box;
     Bool pending, overlap;
 
-    pReg = REGION_CREATE(pGC->pScreen, NULL, 1);
-    pTmpReg = REGION_CREATE(pGC->pScreen, NULL, 1);
+    pReg = RegionCreate(NULL, 1);
+    pTmpReg = RegionCreate(NULL, 1);
     if(!pReg || !pTmpReg) return NullRegion;
     
     pending = True;
@@ -149,15 +149,15 @@ xnestBitBlitHelper(GCPtr pGC)
 	Box.y1 = event.xgraphicsexpose.y;
 	Box.x2 = event.xgraphicsexpose.x + event.xgraphicsexpose.width;
 	Box.y2 = event.xgraphicsexpose.y + event.xgraphicsexpose.height;
-	REGION_RESET(pGC->pScreen, pTmpReg, &Box);
-	REGION_APPEND(pGC->pScreen, pReg, pTmpReg);
+	RegionReset(pTmpReg, &Box);
+	RegionAppend(pReg, pTmpReg);
 	pending = event.xgraphicsexpose.count;
 	break;
       }
     }
 
-    REGION_DESTROY(pGC->pScreen, pTmpReg);
-    REGION_VALIDATE(pGC->pScreen, pReg, &overlap);
+    RegionDestroy(pTmpReg);
+    RegionValidate(pReg, &overlap);
     return(pReg);
   }
 }
diff --git a/hw/xnest/Pixmap.c b/hw/xnest/Pixmap.c
index 583f877..bf06480 100644
--- a/hw/xnest/Pixmap.c
+++ b/hw/xnest/Pixmap.c
@@ -97,8 +97,8 @@ xnestPixmapToRegion(PixmapPtr pPixmap)
 		     pPixmap->drawable.width, pPixmap->drawable.height,
 		     1, XYPixmap);
   
-  pReg = REGION_CREATE(pPixmap->drawable.pScreen, NULL, 1);
-  pTmpReg = REGION_CREATE(pPixmap->drawable.pScreen, NULL, 1);
+  pReg = RegionCreate(NULL, 1);
+  pTmpReg = RegionCreate(NULL, 1);
   if(!pReg || !pTmpReg) {
       XDestroyImage(ximage);
       return NullRegion;
@@ -118,8 +118,8 @@ xnestPixmapToRegion(PixmapPtr pPixmap)
 	else if (currentPixel == 0L) {
 	  /* right edge */
 	  Box.x2 = x;
-	  REGION_RESET(pPixmap->drawable.pScreen, pTmpReg, &Box);
-	  REGION_APPEND(pPixmap->drawable.pScreen, pReg, pTmpReg);
+	  RegionReset(pTmpReg, &Box);
+	  RegionAppend(pReg, pTmpReg);
 	}
 	previousPixel = currentPixel;
       }
@@ -127,15 +127,15 @@ xnestPixmapToRegion(PixmapPtr pPixmap)
     if (previousPixel != 0L) {
       /* right edge because of the end of pixmap */
       Box.x2 = pPixmap->drawable.width;
-      REGION_RESET(pPixmap->drawable.pScreen, pTmpReg, &Box);
-      REGION_APPEND(pPixmap->drawable.pScreen, pReg, pTmpReg);
+      RegionReset(pTmpReg, &Box);
+      RegionAppend(pReg, pTmpReg);
     }
   }
   
-  REGION_DESTROY(pPixmap->drawable.pScreen, pTmpReg);
+  RegionDestroy(pTmpReg);
   XDestroyImage(ximage);
 
-  REGION_VALIDATE(pPixmap->drawable.pScreen, pReg, &overlap);
+  RegionValidate(pReg, &overlap);
 
   return(pReg);
 }
diff --git a/hw/xnest/Window.c b/hw/xnest/Window.c
index 11d5369..fab2f39 100644
--- a/hw/xnest/Window.c
+++ b/hw/xnest/Window.c
@@ -135,9 +135,9 @@ xnestCreateWindow(WindowPtr pWin)
   if (pWin->nextSib)
     xnestWindowPriv(pWin->nextSib)->sibling_above = xnestWindow(pWin);
   xnestWindowPriv(pWin)->bounding_shape = 
-    REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
+    RegionCreate(NULL, 1);
   xnestWindowPriv(pWin)->clip_shape = 
-    REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
+    RegionCreate(NULL, 1);
 
   if (!pWin->parent) /* only the root window will have the right colormap */
     xnestSetInstalledColormapWindows(pWin->drawable.pScreen);
@@ -151,9 +151,9 @@ xnestDestroyWindow(WindowPtr pWin)
   if (pWin->nextSib)
     xnestWindowPriv(pWin->nextSib)->sibling_above = 
       xnestWindowPriv(pWin)->sibling_above;
-  REGION_DESTROY(pWin->drawable.pScreen, 
+  RegionDestroy(
 				xnestWindowPriv(pWin)->bounding_shape);
-  REGION_DESTROY(pWin->drawable.pScreen, 
+  RegionDestroy(
 				xnestWindowPriv(pWin)->clip_shape);
   XDestroyWindow(xnestDisplay, xnestWindow(pWin));
   xnestWindowPriv(pWin)->window = None;
@@ -415,7 +415,7 @@ xnestWindowExposures(WindowPtr pWin, RegionPtr pRgn, RegionPtr other_exposed)
 	
     event.xexpose.type = ProcessedExpose;
 	
-    if (RECT_IN_REGION(pWin->drawable.pScreen, pRgn, &Box) != rgnIN)
+    if (RegionContainsRect(pRgn, &Box) != rgnIN)
       XPutBackEvent(xnestDisplay, &event);
   }
   
@@ -439,11 +439,11 @@ xnestRegionEqual(RegionPtr pReg1, RegionPtr pReg2)
 
   if (pReg1 == NullRegion || pReg2 == NullRegion) return False;
 
-  pBox1 = REGION_RECTS(pReg1);
-  n1 = REGION_NUM_RECTS(pReg1);
+  pBox1 = RegionRects(pReg1);
+  n1 = RegionNumRects(pReg1);
 
-  pBox2 = REGION_RECTS(pReg2);
-  n2 = REGION_NUM_RECTS(pReg2);
+  pBox2 = RegionRects(pReg2);
+  n2 = RegionNumRects(pReg2);
 
   if (n1 != n2) return False;
 
@@ -466,13 +466,13 @@ xnestShapeWindow(WindowPtr pWin)
 			wBoundingShape(pWin))) {
     
     if (wBoundingShape(pWin)) {
-      REGION_COPY(pWin->drawable.pScreen, 
+      RegionCopy(
 		xnestWindowPriv(pWin)->bounding_shape, wBoundingShape(pWin));
       
       reg = XCreateRegion();
-      pBox = REGION_RECTS(xnestWindowPriv(pWin)->bounding_shape);
+      pBox = RegionRects(xnestWindowPriv(pWin)->bounding_shape);
       for (i = 0; 
-	   i < REGION_NUM_RECTS(xnestWindowPriv(pWin)->bounding_shape);
+	   i < RegionNumRects(xnestWindowPriv(pWin)->bounding_shape);
 	   i++) {
         rect.x = pBox[i].x1;
         rect.y = pBox[i].y1;
@@ -485,7 +485,7 @@ xnestShapeWindow(WindowPtr pWin)
       XDestroyRegion(reg);
     }
     else {
-      REGION_EMPTY(pWin->drawable.pScreen, 
+      RegionEmpty(
 				xnestWindowPriv(pWin)->bounding_shape);
       
       XShapeCombineMask(xnestDisplay, xnestWindow(pWin),
@@ -497,13 +497,13 @@ xnestShapeWindow(WindowPtr pWin)
 			wClipShape(pWin))) {
     
     if (wClipShape(pWin)) {
-      REGION_COPY(pWin->drawable.pScreen, 
+      RegionCopy(
 			xnestWindowPriv(pWin)->clip_shape, wClipShape(pWin));
       
       reg = XCreateRegion();
-      pBox = REGION_RECTS(xnestWindowPriv(pWin)->clip_shape);
+      pBox = RegionRects(xnestWindowPriv(pWin)->clip_shape);
       for (i = 0; 
-	   i < REGION_NUM_RECTS(xnestWindowPriv(pWin)->clip_shape);
+	   i < RegionNumRects(xnestWindowPriv(pWin)->clip_shape);
 	   i++) {
         rect.x = pBox[i].x1;
         rect.y = pBox[i].y1;
@@ -516,7 +516,7 @@ xnestShapeWindow(WindowPtr pWin)
       XDestroyRegion(reg);
     }
     else {
-      REGION_EMPTY(pWin->drawable.pScreen, 
+      RegionEmpty(
 				     xnestWindowPriv(pWin)->clip_shape);
       
       XShapeCombineMask(xnestDisplay, xnestWindow(pWin),
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 7453ecc..1d99d36 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -817,8 +817,8 @@ xf86SetRootClip (ScreenPtr pScreen, int enable)
 	    {
 		RegionPtr	borderVisible;
 
-		borderVisible = REGION_CREATE(pScreen, NullBox, 1);
-		REGION_SUBTRACT(pScreen, borderVisible,
+		borderVisible = RegionCreate(NullBox, 1);
+		RegionSubtract(borderVisible,
 				&pWin->borderClip, &pWin->winSize);
 		pWin->valdata->before.borderVisible = borderVisible;
 	    }
@@ -837,13 +837,13 @@ xf86SetRootClip (ScreenPtr pScreen, int enable)
 	box.y1 = 0;
 	box.x2 = pScreen->width;
 	box.y2 = pScreen->height;
-	REGION_RESET(pScreen, &pWin->borderClip, &box);
-	REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+	RegionReset(&pWin->borderClip, &box);
+	RegionBreak(&pWin->clipList);
     }
     else
     {
-	REGION_EMPTY(pScreen, &pWin->borderClip);
-	REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+	RegionEmpty(&pWin->borderClip);
+	RegionBreak(&pWin->clipList);
     }
 
     ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
@@ -852,8 +852,8 @@ xf86SetRootClip (ScreenPtr pScreen, int enable)
     {
 	if (pWin->backStorage)
 	{
-	    pOldClip = REGION_CREATE(pScreen, NullBox, 1);
-	    REGION_COPY(pScreen, pOldClip, &pWin->clipList);
+	    pOldClip = RegionCreate(NullBox, 1);
+	    RegionCopy(pOldClip, &pWin->clipList);
 	}
 
 	if (pWin->firstChild)
@@ -882,7 +882,7 @@ xf86SetRootClip (ScreenPtr pScreen, int enable)
 			     (pWin, 0, 0, pOldClip,
 			      pWin->drawable.x, pWin->drawable.y);
 	if (WasViewable)
-	    REGION_DESTROY(pScreen, pOldClip);
+	    RegionDestroy(pOldClip);
 	if (bsExposed)
 	{
 	    RegionPtr	valExposed = NullRegion;
@@ -891,8 +891,8 @@ xf86SetRootClip (ScreenPtr pScreen, int enable)
 		valExposed = &pWin->valdata->after.exposed;
 	    (*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
 	    if (valExposed)
-		REGION_EMPTY(pScreen, valExposed);
-	    REGION_DESTROY(pScreen, bsExposed);
+		RegionEmpty(valExposed);
+	    RegionDestroy(bsExposed);
 	}
     }
     if (WasViewable)
diff --git a/hw/xquartz/xpr/dri.c b/hw/xquartz/xpr/dri.c
index 3b14581..d9b2e03 100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@ -347,8 +347,8 @@ DRIUpdateSurface(DRIDrawablePrivPtr pDRIDrawablePriv, DrawablePtr pDraw)
         wc.height = pWin->drawable.height + 2 * pWin->borderWidth;
         wc.bit_gravity = XP_GRAVITY_NONE;
 
-        wc.shape_nrects = REGION_NUM_RECTS(&pWin->clipList);
-        wc.shape_rects = REGION_RECTS(&pWin->clipList);
+        wc.shape_nrects = RegionNumRects(&pWin->clipList);
+        wc.shape_rects = RegionRects(&pWin->clipList);
         wc.shape_tx = - (pTopWin->drawable.x - pTopWin->borderWidth);
         wc.shape_ty = - (pTopWin->drawable.y - pTopWin->borderWidth);
 
diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index 6dc2c87..9f5d8a6 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -163,8 +163,8 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
 
     if (pShape != NULL)
     {
-        wc.shape_nrects = REGION_NUM_RECTS(pShape);
-        wc.shape_rects = REGION_RECTS(pShape);
+        wc.shape_nrects = RegionNumRects(pShape);
+        wc.shape_rects = RegionRects(pShape);
         wc.shape_tx = wc.shape_ty = 0;
         mask |= XP_SHAPE;
     }
@@ -306,8 +306,8 @@ xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
     
     if (pShape != NULL)
     {
-        wc.shape_nrects = REGION_NUM_RECTS(pShape);
-        wc.shape_rects = REGION_RECTS(pShape);
+        wc.shape_nrects = RegionNumRects(pShape);
+        wc.shape_rects = RegionRects(pShape);
     }
     else
     {
diff --git a/hw/xwin/winfillsp.c b/hw/xwin/winfillsp.c
index 702f34f..1e8e3e6 100644
--- a/hw/xwin/winfillsp.c
+++ b/hw/xwin/winfillsp.c
@@ -80,8 +80,8 @@ winFillSpansNativeGDI (DrawablePtr	pDrawable,
   int		    	fullX1, fullX2, fullY1;
   HRGN			hrgn = NULL, combined = NULL;
 
-  nbox = REGION_NUM_RECTS (pClip);
-  pbox = REGION_RECTS (pClip);
+  nbox = RegionNumRects (pClip);
+  pbox = RegionRects (pClip);
 
   if (!nbox) return;
 
@@ -97,7 +97,7 @@ winFillSpansNativeGDI (DrawablePtr	pDrawable,
       pbox++;
     }
 
-  pextent = REGION_EXTENTS (pGC->pScreen, pClip);
+  pextent = RegionExtents(pClip);
   extentX1 = pextent->x1;
   extentY1 = pextent->y1;
   extentX2 = pextent->x2;
diff --git a/hw/xwin/wingc.c b/hw/xwin/wingc.c
index 1f37752..196b5b5 100644
--- a/hw/xwin/wingc.c
+++ b/hw/xwin/wingc.c
@@ -210,7 +210,7 @@ winDestroyGCNativeGDI (GCPtr pGC)
   winScreenPriv(pGC->pScreen);
 
   if (pGC->freeCompClip)
-	REGION_DESTROY (pGC->pScreen, pGC->pCompositeClip);
+	RegionDestroy(pGC->pCompositeClip);
 
   /* Free the memory DC */
   if (pGCPriv->hdcMem != NULL)
diff --git a/hw/xwin/winmultiwindowshape.c b/hw/xwin/winmultiwindowshape.c
index 597eab6..9b4910b 100644
--- a/hw/xwin/winmultiwindowshape.c
+++ b/hw/xwin/winmultiwindowshape.c
@@ -117,15 +117,15 @@ winReshapeMultiWindow (WindowPtr pWin)
   if (!wBoundingShape (pWin))
     return;
 
-  REGION_NULL(pWin->drawable.pScreen, &rrNewShape);
-  REGION_COPY(pWin->drawable.pScreen, &rrNewShape, wBoundingShape(pWin));
-  REGION_TRANSLATE(pWin->drawable.pScreen,
+  RegionNull(&rrNewShape);
+  RegionCopy(&rrNewShape, wBoundingShape(pWin));
+  RegionTranslate(
 		   &rrNewShape,
 		   pWin->borderWidth,
                    pWin->borderWidth);
   
-  nRects = REGION_NUM_RECTS(&rrNewShape);
-  pShape = REGION_RECTS(&rrNewShape);
+  nRects = RegionNumRects(&rrNewShape);
+  pShape = RegionRects(&rrNewShape);
   
   /* Don't do anything if there are no rectangles in the region */
   if (nRects > 0)
@@ -205,7 +205,7 @@ winReshapeMultiWindow (WindowPtr pWin)
       pWinPriv->hRgn = hRgn;
     }
 
-  REGION_UNINIT(pWin->drawable.pScreen, &rrNewShape);
+  RegionUninit(&rrNewShape);
   
   return;
 }
diff --git a/hw/xwin/winsetsp.c b/hw/xwin/winsetsp.c
index f894d6c..d1bf90b 100644
--- a/hw/xwin/winsetsp.c
+++ b/hw/xwin/winsetsp.c
@@ -54,8 +54,8 @@ winSetSpansNativeGDI (DrawablePtr	pDrawable,
   int			nbox;
   BoxPtr	 	pbox;
 
-  nbox = REGION_NUM_RECTS (pGC->pCompositeClip);
-  pbox = REGION_RECTS (pGC->pCompositeClip);
+  nbox = RegionNumRects (pGC->pCompositeClip);
+  pbox = RegionRects (pGC->pCompositeClip);
 
   if (!nbox) return;
 
diff --git a/hw/xwin/winshaddd.c b/hw/xwin/winshaddd.c
index 85dc10f..8dd1084 100644
--- a/hw/xwin/winshaddd.c
+++ b/hw/xwin/winshaddd.c
@@ -525,8 +525,8 @@ winShadowUpdateDD (ScreenPtr pScreen,
   HRESULT		ddrval = DD_OK;
   RECT			rcDest, rcSrc;
   POINT			ptOrigin;
-  DWORD			dwBox = REGION_NUM_RECTS (damage);
-  BoxPtr		pBox = REGION_RECTS (damage);
+  DWORD			dwBox = RegionNumRects (damage);
+  BoxPtr		pBox = RegionRects (damage);
   HRGN			hrgnTemp = NULL, hrgnCombined = NULL;
 
   /*
@@ -588,7 +588,7 @@ winShadowUpdateDD (ScreenPtr pScreen,
     }
   else
     {
-      BoxPtr		pBoxExtents = REGION_EXTENTS (pScreen, damage);
+      BoxPtr		pBoxExtents = RegionExtents(damage);
 
       /* Compute a GDI region from the damaged region */
       hrgnCombined = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
diff --git a/hw/xwin/winshadddnl.c b/hw/xwin/winshadddnl.c
index e78fbd9..5ca3e4f 100644
--- a/hw/xwin/winshadddnl.c
+++ b/hw/xwin/winshadddnl.c
@@ -601,8 +601,8 @@ winShadowUpdateDDNL (ScreenPtr pScreen,
   HRESULT		ddrval = DD_OK;
   RECT			rcDest, rcSrc;
   POINT			ptOrigin;
-  DWORD			dwBox = REGION_NUM_RECTS (damage);
-  BoxPtr		pBox = REGION_RECTS (damage);
+  DWORD			dwBox = RegionNumRects (damage);
+  BoxPtr		pBox = RegionRects (damage);
   HRGN			hrgnTemp = NULL, hrgnCombined = NULL;
 
   /*
@@ -677,7 +677,7 @@ winShadowUpdateDDNL (ScreenPtr pScreen,
     }
   else
     {
-      BoxPtr		pBoxExtents = REGION_EXTENTS (pScreen, damage);
+      BoxPtr		pBoxExtents = RegionExtents(damage);
 
       /* Compute a GDI region from the damaged region */
       hrgnCombined = CreateRectRgn (pBox->x1, pBox->y1, pBox->x2, pBox->y2);
diff --git a/hw/xwin/winshadgdi.c b/hw/xwin/winshadgdi.c
index d38e4f7..96d149c 100644
--- a/hw/xwin/winshadgdi.c
+++ b/hw/xwin/winshadgdi.c
@@ -499,8 +499,8 @@ winShadowUpdateGDI (ScreenPtr pScreen,
   winScreenPriv(pScreen);
   winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
   RegionPtr		damage = shadowDamage(pBuf);
-  DWORD			dwBox = REGION_NUM_RECTS (damage);
-  BoxPtr		pBox = REGION_RECTS (damage);
+  DWORD			dwBox = RegionNumRects (damage);
+  BoxPtr		pBox = RegionRects (damage);
   int			x, y, w, h;
   HRGN			hrgnTemp = NULL, hrgnCombined = NULL;
 #ifdef XWIN_UPDATESTATS
@@ -508,7 +508,7 @@ winShadowUpdateGDI (ScreenPtr pScreen,
   static DWORD		s_dwTotalUpdates = 0;
   static DWORD		s_dwTotalBoxes = 0;
 #endif
-  BoxPtr		pBoxExtents = REGION_EXTENTS (pScreen, damage);
+  BoxPtr		pBoxExtents = RegionExtents(damage);
 
   /*
    * Return immediately if the app is not active
diff --git a/hw/xwin/winvideo.c b/hw/xwin/winvideo.c
index 4cdb3c4..0438e5f 100755
--- a/hw/xwin/winvideo.c
+++ b/hw/xwin/winvideo.c
@@ -185,7 +185,7 @@ winSetupImageVideo (ScreenPtr pScreen)
 
 #if 0
     /* gotta uninit this someplace */
-    REGION_NULL(pScreen, &pPriv->clip);
+    RegionNull(&pPriv->clip);
 #endif
 
 #if 0
diff --git a/hw/xwin/winwin32rootless.c b/hw/xwin/winwin32rootless.c
index c225a44..9749861 100755
--- a/hw/xwin/winwin32rootless.c
+++ b/hw/xwin/winwin32rootless.c
@@ -150,8 +150,8 @@ winMWExtWMCreateRgnFromRegion (RegionPtr pShape)
 
   if (pShape == NULL) return NULL;
 
-  nRects = REGION_NUM_RECTS(pShape);
-  pRects = REGION_RECTS(pShape);
+  nRects = RegionNumRects(pShape);
+  pRects = RegionRects(pShape);
   
   hRgn = CreateRectRgn (0, 0, 0, 0);
   if (hRgn == NULL)
diff --git a/hw/xwin/winwindow.c b/hw/xwin/winwindow.c
index 9348d5c..bc0614d 100644
--- a/hw/xwin/winwindow.c
+++ b/hw/xwin/winwindow.c
@@ -147,22 +147,22 @@ winCopyWindowNativeGDI (WindowPtr pWin,
   pwinRoot = pWin->drawable.pScreen->root;
 
   /* Create a region for the destination */
-  prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
+  prgnDst = RegionCreate(NULL, 1);
 
   /* Calculate the shift from the source to the destination */
   dx = ptOldOrg.x - pWin->drawable.x;
   dy = ptOldOrg.y - pWin->drawable.y;
 
   /* Translate the region from the destination to the source? */
-  REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
-  REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip,
+  RegionTranslate(prgnSrc, -dx, -dy);
+  RegionIntersect(prgnDst, &pWin->borderClip,
 		   prgnSrc);
 
   /* Get a pointer to the first box in the region to be copied */
-  pBox = REGION_RECTS(prgnDst);
+  pBox = RegionRects(prgnDst);
   
   /* Get the number of boxes in the region */
-  nbox = REGION_NUM_RECTS(prgnDst);
+  nbox = RegionNumRects(prgnDst);
 
   /* Allocate source points for each box */
   if(!(pptSrc = (DDXPointPtr )malloc(nbox * sizeof(DDXPointRec))))
@@ -179,7 +179,7 @@ winCopyWindowNativeGDI (WindowPtr pWin,
     }
 
   /* Setup loop pointers again */
-  pBoxDst = REGION_RECTS(prgnDst);
+  pBoxDst = RegionRects(prgnDst);
   ppt = pptSrc;
 
 #if 0
@@ -205,7 +205,7 @@ winCopyWindowNativeGDI (WindowPtr pWin,
 
   /* Cleanup the regions, etc. */
   free(pptSrc);
-  REGION_DESTROY(pWin->drawable.pScreen, prgnDst);
+  RegionDestroy(prgnDst);
 }
 
 
@@ -593,13 +593,13 @@ winReshapeRootless (WindowPtr pWin)
   if (!wBoundingShape (pWin))
     return;
 
-  REGION_NULL(pScreen, &rrNewShape);
-  REGION_COPY(pScreen, &rrNewShape, wBoundingShape(pWin));
-  REGION_TRANSLATE(pScreen, &rrNewShape, pWin->borderWidth,
+  RegionNull(&rrNewShape);
+  RegionCopy(&rrNewShape, wBoundingShape(pWin));
+  RegionTranslate(&rrNewShape, pWin->borderWidth,
                    pWin->borderWidth);
   
-  nRects = REGION_NUM_RECTS(&rrNewShape);
-  pShape = REGION_RECTS(&rrNewShape);
+  nRects = RegionNumRects(&rrNewShape);
+  pShape = RegionRects(&rrNewShape);
   
   if (nRects > 0)
     {
@@ -631,7 +631,7 @@ winReshapeRootless (WindowPtr pWin)
       pWinPriv->hRgn = hRgn;
     }
 
-  REGION_UNINIT(pScreen, &rrNewShape);
+  RegionUninit(&rrNewShape);
   
   return;
 }
diff --git a/hw/xwin/winwindowswm.c b/hw/xwin/winwindowswm.c
index 99329c3..5935ac4 100755
--- a/hw/xwin/winwindowswm.c
+++ b/hw/xwin/winwindowswm.c
@@ -495,11 +495,11 @@ ProcWindowsWMFrameDraw (register ClientPtr client)
       /* wBoundingShape is relative to *inner* origin of window.
 	 Translate by borderWidth to get the outside-relative position. */
       
-      REGION_NULL(pScreen, &newShape);
-      REGION_COPY(pScreen, &newShape, wBoundingShape(pWin));
-      REGION_TRANSLATE(pScreen, &newShape, pWin->borderWidth, pWin->borderWidth);
+      RegionNull(&newShape);
+      RegionCopy(&newShape, wBoundingShape(pWin));
+      RegionTranslate(&newShape, pWin->borderWidth, pWin->borderWidth);
       winMWExtWMReshapeFrame (pRLWinPriv, &newShape);
-      REGION_UNINIT(pScreen, &newShape);
+      RegionUninit(&newShape);
     }
 #if CYGMULTIWINDOW_DEBUG
   ErrorF ("ProcWindowsWMFrameDraw - done\n");
diff --git a/include/regionstr.h b/include/regionstr.h
index 89cf024..c6dd162 100644
--- a/include/regionstr.h
+++ b/include/regionstr.h
@@ -70,68 +70,68 @@ extern _X_EXPORT BoxRec RegionEmptyBox;
 extern _X_EXPORT RegDataRec RegionEmptyData;
 extern _X_EXPORT RegDataRec RegionBrokenData;
 
-#define REGION_NIL(reg) ((reg)->data && !(reg)->data->numRects)
+#define RegionNil(reg) ((reg)->data && !(reg)->data->numRects)
 /* not a region */
-#define REGION_NAR(reg)	((reg)->data == &RegionBrokenData)
-#define REGION_NUM_RECTS(reg) ((reg)->data ? (reg)->data->numRects : 1)
-#define REGION_SIZE(reg) ((reg)->data ? (reg)->data->size : 0)
-#define REGION_RECTS(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \
+#define RegionNar(reg)	((reg)->data == &RegionBrokenData)
+#define RegionNumRects(reg) ((reg)->data ? (reg)->data->numRects : 1)
+#define RegionSize(reg) ((reg)->data ? (reg)->data->size : 0)
+#define RegionRects(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \
 			               : &(reg)->extents)
-#define REGION_BOXPTR(reg) ((BoxPtr)((reg)->data + 1))
-#define REGION_BOX(reg,i) (&REGION_BOXPTR(reg)[i])
-#define REGION_TOP(reg) REGION_BOX(reg, (reg)->data->numRects)
-#define REGION_END(reg) REGION_BOX(reg, (reg)->data->numRects - 1)
-#define REGION_SZOF(n) (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)))
+#define RegionBoxptr(reg) ((BoxPtr)((reg)->data + 1))
+#define RegionBox(reg,i) (&RegionBoxptr(reg)[i])
+#define RegionTop(reg) RegionBox(reg, (reg)->data->numRects)
+#define RegionEnd(reg) RegionBox(reg, (reg)->data->numRects - 1)
+#define RegionSizeof(n) (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)))
 
-#define REGION_CREATE(_pScreen, _rect, _size) \
+#define RegionCreate(_rect, _size) \
     RegionCreate(_rect, _size)
 
-#define REGION_COPY(_pScreen, dst, src) \
+#define RegionCopy(dst, src) \
     RegionCopy(dst, src)
 
-#define REGION_DESTROY(_pScreen, _pReg) \
+#define RegionDestroy(_pReg) \
     RegionDestroy(_pReg)
 
-#define REGION_INTERSECT(_pScreen, newReg, reg1, reg2) \
+#define RegionIntersect(newReg, reg1, reg2) \
     RegionIntersect(newReg, reg1, reg2)
 
-#define REGION_UNION(_pScreen, newReg, reg1, reg2) \
+#define RegionUnion(newReg, reg1, reg2) \
     RegionUnion(newReg, reg1, reg2)
 
-#define REGION_SUBTRACT(_pScreen, newReg, reg1, reg2) \
+#define RegionSubtract(newReg, reg1, reg2) \
     RegionSubtract(newReg, reg1, reg2)
 
-#define REGION_INVERSE(_pScreen, newReg, reg1, invRect) \
+#define RegionInverse(newReg, reg1, invRect) \
     RegionInverse(newReg, reg1, invRect)
 
-#define REGION_TRANSLATE(_pScreen, _pReg, _x, _y) \
+#define RegionTranslate(_pReg, _x, _y) \
     RegionTranslate(_pReg, _x, _y)
 
-#define RECT_IN_REGION(_pScreen, _pReg, prect) \
+#define RegionContainsRect(_pReg, prect) \
     RegionContainsRect(_pReg, prect)
 
-#define POINT_IN_REGION(_pScreen, _pReg, _x, _y, prect) \
+#define RegionContainsPoint(_pReg, _x, _y, prect) \
     RegionContainsPoint(_pReg, _x, _y, prect)
 
-#define REGION_APPEND(_pScreen, dstrgn, rgn) \
+#define RegionAppend(dstrgn, rgn) \
     RegionAppend(dstrgn, rgn)
 
-#define REGION_VALIDATE(_pScreen, badreg, pOverlap) \
+#define RegionValidate(badreg, pOverlap) \
     RegionValidate(badreg, pOverlap)
 
-#define BITMAP_TO_REGION(_pScreen, pPix) \
+#define BitmapToRegion(_pScreen, pPix) \
     (*(_pScreen)->BitmapToRegion)(pPix) /* no mi version?! */
 
-#define RECTS_TO_REGION(_pScreen, nrects, prect, ctype) \
+#define RegionFromRects(nrects, prect, ctype) \
     RegionFromRects(nrects, prect, ctype)
 
-#define REGION_EQUAL(_pScreen, _pReg1, _pReg2) \
+#define RegionEqual(_pReg1, _pReg2) \
     RegionEqual(_pReg1, _pReg2)
 
-#define REGION_BREAK(_pScreen, _pReg) \
+#define RegionBreak(_pReg) \
     RegionBreak(_pReg)
 
-#define REGION_INIT(_pScreen, _pReg, _rect, _size) \
+#define RegionInit(_pReg, _rect, _size) \
 { \
     if ((_rect) != NULL)				\
     { \
@@ -142,7 +142,7 @@ extern _X_EXPORT RegDataRec RegionBrokenData;
     { \
         (_pReg)->extents = RegionEmptyBox; \
         if (((_size) > 1) && ((_pReg)->data = \
-                             (RegDataPtr)malloc(REGION_SZOF(_size)))) \
+                             (RegDataPtr)malloc(RegionSizeof(_size)))) \
         { \
             (_pReg)->data->size = (_size); \
             (_pReg)->data->numRects = 0; \
@@ -153,7 +153,7 @@ extern _X_EXPORT RegDataRec RegionBrokenData;
  }
 
 
-#define REGION_UNINIT(_pScreen, _pReg) \
+#define RegionUninit(_pReg) \
 { \
     if ((_pReg)->data && (_pReg)->data->size) { \
 	free((_pReg)->data); \
@@ -161,41 +161,36 @@ extern _X_EXPORT RegDataRec RegionBrokenData;
     } \
 }
 
-#define REGION_RESET(_pScreen, _pReg, _pBox) \
+#define RegionReset(_pReg, _pBox) \
 { \
     (_pReg)->extents = *(_pBox); \
-    REGION_UNINIT(_pScreen, _pReg); \
+    RegionUninit(_pReg); \
     (_pReg)->data = (RegDataPtr)NULL; \
 }
 
-#define REGION_NOTEMPTY(_pScreen, _pReg) \
-    !REGION_NIL(_pReg)
+#define RegionNotEmpty(_pReg) \
+    !RegionNil(_pReg)
 
-#define REGION_BROKEN(_pScreen, _pReg) \
-    REGION_NAR(_pReg)
+#define RegionBroken(_pReg) \
+    RegionNar(_pReg)
 
-#define REGION_EMPTY(_pScreen, _pReg) \
+#define RegionEmpty(_pReg) \
 { \
-    REGION_UNINIT(_pScreen, _pReg); \
+    RegionUninit(_pReg); \
     (_pReg)->extents.x2 = (_pReg)->extents.x1; \
     (_pReg)->extents.y2 = (_pReg)->extents.y1; \
     (_pReg)->data = &RegionEmptyData; \
 }
 
-#define REGION_EXTENTS(_pScreen, _pReg) \
+#define RegionExtents(_pReg) \
     (&(_pReg)->extents)
 
-#define REGION_NULL(_pScreen, _pReg) \
+#define RegionNull(_pReg) \
 { \
     (_pReg)->extents = RegionEmptyBox; \
     (_pReg)->data = &RegionEmptyData; \
 }
 
-#ifndef REGION_NULL
-#define REGION_NULL(_pScreen, _pReg) \
-    REGION_INIT(_pScreen, _pReg, NullBox, 1)
-#endif
-
 /* moved from mi.h */
 
 extern _X_EXPORT void InitRegions (void);
@@ -204,17 +199,9 @@ extern _X_EXPORT RegionPtr RegionCreate(
     BoxPtr /*rect*/,
     int /*size*/);
 
-extern _X_EXPORT void RegionInit(
-    RegionPtr /*pReg*/,
-    BoxPtr /*rect*/,
-    int /*size*/);
-
 extern _X_EXPORT void RegionDestroy(
     RegionPtr /*pReg*/);
 
-extern _X_EXPORT void RegionUninit(
-    RegionPtr /*pReg*/);
-
 extern _X_EXPORT Bool RegionCopy(
     RegionPtr /*dst*/,
     RegionPtr /*src*/);
@@ -261,10 +248,6 @@ extern _X_EXPORT void RegionTranslate(
     int /*x*/,
     int /*y*/);
 
-extern _X_EXPORT void RegionReset(
-    RegionPtr /*pReg*/,
-    BoxPtr /*pBox*/);
-
 extern _X_EXPORT Bool RegionBreak(
     RegionPtr /*pReg*/);
 
@@ -278,16 +261,28 @@ extern _X_EXPORT Bool RegionEqual(
     RegionPtr /*pReg1*/,
     RegionPtr /*pReg2*/);
 
-extern _X_EXPORT Bool RegionNotEmpty(
-    RegionPtr /*pReg*/);
-
-extern _X_EXPORT void RegionEmpty(
-    RegionPtr /*pReg*/);
+extern _X_EXPORT Bool RegionRectAlloc(
+    RegionPtr /*pRgn*/,
+    int /*n*/
+);
 
-extern _X_EXPORT BoxPtr RegionExtents(
-    RegionPtr /*pReg*/);
+#ifdef DEBUG
+extern _X_EXPORT Bool RegionIsValid(
+    RegionPtr /*prgn*/
+);
+#endif
 
 extern _X_EXPORT void RegionPrint(
     RegionPtr /*pReg*/);
 
+extern _X_EXPORT int RegionClipSpans(
+    RegionPtr /*prgnDst*/,
+    DDXPointPtr /*ppt*/,
+    int * /*pwidth*/,
+    int /*nspans*/,
+    DDXPointPtr /*pptNew*/,
+    int * /*pwidthNew*/,
+    int /*fSorted*/
+);
+
 #endif /* REGIONSTRUCT_H */
diff --git a/mi/mi.h b/mi/mi.h
index 9f67d2e..fa32b6b 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -418,23 +418,6 @@ extern _X_EXPORT void miPushPixels(
     int /*yOrg*/
 );
 
-/* miregion.c */
-
-/* see also region.h */
-
-extern _X_EXPORT Bool RegionRectAlloc(
-    RegionPtr /*pRgn*/,
-    int /*n*/
-);
-
-#ifdef DEBUG
-extern _X_EXPORT Bool RegionIsValid(
-    RegionPtr /*prgn*/
-);
-#endif
-
-extern _X_EXPORT Bool RegionBroken(RegionPtr pReg);
-
 /* miscrinit.c */
 
 extern _X_EXPORT Bool miModifyPixmapHeader(
diff --git a/mi/mibitblt.c b/mi/mibitblt.c
index 9c6e03d..8448483 100644
--- a/mi/mibitblt.c
+++ b/mi/mibitblt.c
@@ -116,7 +116,7 @@ miCopyArea(DrawablePtr  pSrcDrawable,
 	box.x2 = pSrcDrawable->x + (int) pSrcDrawable->width;
 	box.y2 = pSrcDrawable->y + (int) pSrcDrawable->height;
 
-	prgnSrcClip = REGION_CREATE(pGC->pScreen, &box, 1);
+	prgnSrcClip = RegionCreate(&box, 1);
 	realSrcClip = 1;
     }
     else
@@ -145,8 +145,8 @@ miCopyArea(DrawablePtr  pSrcDrawable,
 
     pptFirst = ppt = malloc(heightSrc * sizeof(DDXPointRec));
     pwidthFirst = pwidth = malloc(heightSrc * sizeof(unsigned int));
-    numRects = REGION_NUM_RECTS(prgnSrcClip);
-    boxes = REGION_RECTS(prgnSrcClip);
+    numRects = RegionNumRects(prgnSrcClip);
+    boxes = RegionRects(prgnSrcClip);
     ordering = malloc(numRects * sizeof(unsigned int));
     if(!pptFirst || !pwidthFirst || !ordering)
     {
@@ -259,7 +259,7 @@ miCopyArea(DrawablePtr  pSrcDrawable,
     prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, xIn, yIn,
 		      widthSrc, heightSrc, xOut, yOut, (unsigned long)0);
     if(realSrcClip)
-	REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+	RegionDestroy(prgnSrcClip);
 		
     free(ordering);
     free(pwidthFirst);
@@ -443,9 +443,9 @@ miOpqStipDrawable(DrawablePtr pDraw, GCPtr pGC, RegionPtr prgnSrc,
        to destroy what it's sent.  note that this means we don't
        have to free prgnSrcClip ourselves.
     */
-    prgnSrcClip = REGION_CREATE(pGCT->pScreen, NULL, 0);
-    REGION_COPY(pGCT->pScreen, prgnSrcClip, prgnSrc);
-    REGION_TRANSLATE(pGCT->pScreen, prgnSrcClip, srcx, 0);
+    prgnSrcClip = RegionCreate(NULL, 0);
+    RegionCopy(prgnSrcClip, prgnSrc);
+    RegionTranslate(prgnSrcClip, srcx, 0);
     (*pGCT->funcs->ChangeClip)(pGCT, CT_REGION, prgnSrcClip, 0);
     ValidateGC((DrawablePtr)pPixmap, pGCT);
 
@@ -578,7 +578,7 @@ miCopyPlane( DrawablePtr pSrcDrawable,
 	box.x2 = box.x1;
     if (box.y1 > box.y2)
 	box.y2 = box.y1;
-    prgnSrc = REGION_CREATE(pGC->pScreen, &box, 1);
+    prgnSrc = RegionCreate(&box, 1);
 
     if (pSrcDrawable->type != DRAWABLE_PIXMAP) {
 	/* clip to visible drawable */
@@ -586,15 +586,15 @@ miCopyPlane( DrawablePtr pSrcDrawable,
 	if (pGC->subWindowMode == IncludeInferiors)
 	{
 	    RegionPtr	clipList = NotClippedByChildren ((WindowPtr) pSrcDrawable);
-	    REGION_INTERSECT(pGC->pScreen, prgnSrc, prgnSrc, clipList);
-	    REGION_DESTROY(pGC->pScreen, clipList);
+	    RegionIntersect(prgnSrc, prgnSrc, clipList);
+	    RegionDestroy(clipList);
 	} else
-	    REGION_INTERSECT(pGC->pScreen, prgnSrc, prgnSrc,
+	    RegionIntersect(prgnSrc, prgnSrc,
 				       &((WindowPtr)pSrcDrawable)->clipList);
     }
 
-    box = *REGION_EXTENTS(pGC->pScreen, prgnSrc);
-    REGION_TRANSLATE(pGC->pScreen, prgnSrc, -box.x1, -box.y1);
+    box = *RegionExtents(prgnSrc);
+    RegionTranslate(prgnSrc, -box.x1, -box.y1);
 
     if ((box.x2 > box.x1) && (box.y2 > box.y1))
     {
@@ -618,7 +618,7 @@ miCopyPlane( DrawablePtr pSrcDrawable,
     }
     prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, srcx, srcy,
 		      width, height, dstx, dsty, bitPlane);
-    REGION_DESTROY(pGC->pScreen, prgnSrc);
+    RegionDestroy(prgnSrc);
     return prgnExposed;
 }
 
@@ -761,11 +761,11 @@ miPutImage( DrawablePtr pDraw, GCPtr pGC, int depth,
 	box.y1 = 0;
 	box.x2 = w;
 	box.y2 = h;
-	prgnSrc = REGION_CREATE(pGC->pScreen, &box, 1);
+	prgnSrc = RegionCreate(&box, 1);
 
         miOpqStipDrawable(pDraw, pGC, prgnSrc, (MiBits *) pImage,
 			  leftPad, w, h, x, y);
-	REGION_DESTROY(pGC->pScreen, prgnSrc);
+	RegionDestroy(prgnSrc);
 	break;
 
       case XYPixmap:
diff --git a/mi/micopy.c b/mi/micopy.c
index 6df9d88..157e324 100644
--- a/mi/micopy.c
+++ b/mi/micopy.c
@@ -49,8 +49,8 @@ miCopyRegion (DrawablePtr   pSrcDrawable,
     int		nbox;
     BoxPtr	pboxNew1, pboxNew2, pboxBase, pboxNext, pboxTmp;
     
-    pbox = REGION_RECTS(pDstRegion);
-    nbox = REGION_NUM_RECTS(pDstRegion);
+    pbox = RegionRects(pDstRegion);
+    nbox = RegionNumRects(pDstRegion);
     
     /* XXX we have to err on the side of safety when both are windows,
      * because we don't know if IncludeInferiors is being used.
@@ -209,7 +209,7 @@ miDoCopy (DrawablePtr	pSrcDrawable,
 	     * VT is inactive, make sure the region isn't empty
 	     */
 	    if (!((WindowPtr) pSrcDrawable)->parent &&
-		REGION_NOTEMPTY (pSrcDrawable->pScreen,
+		RegionNotEmpty(
 				 &((WindowPtr) pSrcDrawable)->borderClip))
 	    {
 		/*
@@ -291,9 +291,9 @@ miDoCopy (DrawablePtr	pSrcDrawable,
 	   blown region and call intersect */
 
 	cclip = miGetCompositeClip(pGC);
-        if (REGION_NUM_RECTS(cclip) == 1)
+        if (RegionNumRects(cclip) == 1)
         {
-	    BoxPtr pBox = REGION_RECTS(cclip);
+	    BoxPtr pBox = RegionRects(cclip);
 
 	    if (box_x1 < pBox->x1) box_x1 = pBox->x1;
 	    if (box_x2 > pBox->x2) box_x2 = pBox->x2;
@@ -306,7 +306,7 @@ miDoCopy (DrawablePtr	pSrcDrawable,
     /* Check to see if the region is empty */
     if (box_x1 >= box_x2 || box_y1 >= box_y2)
     {
-	REGION_NULL(pGC->pScreen, &rgnDst);
+	RegionNull(&rgnDst);
     }
     else
     {
@@ -315,25 +315,25 @@ miDoCopy (DrawablePtr	pSrcDrawable,
 	box.y1 = box_y1;
 	box.x2 = box_x2;
 	box.y2 = box_y2;
-	REGION_INIT(pGC->pScreen, &rgnDst, &box, 1);
+	RegionInit(&rgnDst, &box, 1);
     }
     
     /* Clip against complex source if needed */
     if (!fastSrc)
     {
-	REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst, prgnSrcClip);
-	REGION_TRANSLATE(pGC->pScreen, &rgnDst, -dx, -dy);
+	RegionIntersect(&rgnDst, &rgnDst, prgnSrcClip);
+	RegionTranslate(&rgnDst, -dx, -dy);
     }
 
     /* Clip against complex dest if needed */
     if (!fastDst)
     {
-	REGION_INTERSECT(pGC->pScreen, &rgnDst, &rgnDst,
+	RegionIntersect(&rgnDst, &rgnDst,
 			 miGetCompositeClip(pGC));
     }
 
     /* Do bit blitting */
-    numRects = REGION_NUM_RECTS(&rgnDst);
+    numRects = RegionNumRects(&rgnDst);
     if (numRects && widthSrc && heightSrc)
 	miCopyRegion (pSrcDrawable, pDstDrawable, pGC,
 		      &rgnDst, dx, dy, copyProc, bitPlane, closure);
@@ -347,8 +347,8 @@ miDoCopy (DrawablePtr	pSrcDrawable,
 					xOut - pDstDrawable->x,
 					yOut - pDstDrawable->y,
 					(unsigned long) bitPlane);
-    REGION_UNINIT(pGC->pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
     if (freeSrcClip)
-	REGION_DESTROY(pGC->pScreen, prgnSrcClip);
+	RegionDestroy(prgnSrcClip);
     return prgnExposed;
 }
diff --git a/mi/miexpose.c b/mi/miexpose.c
index 088149b..2fd070d 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -175,21 +175,21 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
 	if (pGC->subWindowMode == IncludeInferiors)
  	{
 	    prgnSrcClip = NotClippedByChildren (pSrcWin);
-	    if ((RECT_IN_REGION(pscr, prgnSrcClip, &TsrcBox)) == rgnIN)
+	    if ((RegionContainsRect(prgnSrcClip, &TsrcBox)) == rgnIN)
 	    {
-		REGION_DESTROY(pscr, prgnSrcClip);
+		RegionDestroy(prgnSrcClip);
 		return NULL;
 	    }
 	}
  	else
  	{
-	    if ((RECT_IN_REGION(pscr, &pSrcWin->clipList, &TsrcBox)) == rgnIN)
+	    if ((RegionContainsRect(&pSrcWin->clipList, &TsrcBox)) == rgnIN)
 		return NULL;
 	    prgnSrcClip = &rgnSrcRec;
-	    REGION_NULL(pscr, prgnSrcClip);
-	    REGION_COPY(pscr, prgnSrcClip, &pSrcWin->clipList);
+	    RegionNull(prgnSrcClip);
+	    RegionCopy(prgnSrcClip, &pSrcWin->clipList);
 	}
-	REGION_TRANSLATE(pscr, prgnSrcClip,
+	RegionTranslate(prgnSrcClip,
 				-pSrcDrawable->x, -pSrcDrawable->y);
     }
     else
@@ -206,7 +206,7 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
 	box.x2 = pSrcDrawable->width;
 	box.y2 = pSrcDrawable->height;
 	prgnSrcClip = &rgnSrcRec;
-	REGION_INIT(pscr, prgnSrcClip, &box, 1);
+	RegionInit(prgnSrcClip, &box, 1);
 	pSrcWin = NULL;
     }
 
@@ -223,11 +223,11 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
 	else
 	{
 	    prgnDstClip = &rgnDstRec;
-	    REGION_NULL(pscr, prgnDstClip);
-	    REGION_COPY(pscr, prgnDstClip,
+	    RegionNull(prgnDstClip);
+	    RegionCopy(prgnDstClip,
 				&((WindowPtr)pDstDrawable)->clipList);
 	}
-	REGION_TRANSLATE(pscr, prgnDstClip,
+	RegionTranslate(prgnDstClip,
 				 -pDstDrawable->x, -pDstDrawable->y);
     }
     else
@@ -239,24 +239,24 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
 	box.x2 = pDstDrawable->width;
 	box.y2 = pDstDrawable->height;
 	prgnDstClip = &rgnDstRec;
-	REGION_INIT(pscr, prgnDstClip, &box, 1);
+	RegionInit(prgnDstClip, &box, 1);
     }
 
     /* drawable-relative source region */
-    REGION_INIT(pscr, &rgnExposed, &srcBox, 1);
+    RegionInit(&rgnExposed, &srcBox, 1);
 
     /* now get the hidden parts of the source box*/
-    REGION_SUBTRACT(pscr, &rgnExposed, &rgnExposed, prgnSrcClip);
+    RegionSubtract(&rgnExposed, &rgnExposed, prgnSrcClip);
 
     /* move them over the destination */
-    REGION_TRANSLATE(pscr, &rgnExposed, dstx-srcx, dsty-srcy);
+    RegionTranslate(&rgnExposed, dstx-srcx, dsty-srcy);
 
     /* intersect with visible areas of dest */
-    REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, prgnDstClip);
+    RegionIntersect(&rgnExposed, &rgnExposed, prgnDstClip);
 
     /* intersect with client clip region. */
     if (pGC->clientClipType == CT_REGION)
-	REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, pGC->clientClip);
+	RegionIntersect(&rgnExposed, &rgnExposed, pGC->clientClip);
 
     /*
      * If we have LOTS of rectangles, we decide to take the extents
@@ -266,7 +266,7 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
      * for windows.
      */
     extents = pGC->graphicsExposures &&
-	      (REGION_NUM_RECTS(&rgnExposed) > RECTLIMIT) &&
+	      (RegionNumRects(&rgnExposed) > RECTLIMIT) &&
 	      (pDstDrawable->type != DRAWABLE_PIXMAP);
     if (pSrcWin)
     {
@@ -278,13 +278,13 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
      	 * exposed region will undo all our work!
      	 */
     	if (extents && pSrcWin && region &&
-    	    (RECT_IN_REGION(pscr, region, &srcBox) != rgnIN))
+	    (RegionContainsRect(region, &srcBox) != rgnIN))
 	    	extents = FALSE;
     }
     if (extents)
     {
-	expBox = *REGION_EXTENTS(pscr, &rgnExposed);
-	REGION_RESET(pscr, &rgnExposed, &expBox);
+	expBox = *RegionExtents(&rgnExposed);
+	RegionReset(&rgnExposed, &expBox);
     }
     if ((pDstDrawable->type != DRAWABLE_PIXMAP) &&
 	(((WindowPtr)pDstDrawable)->backgroundState != None))
@@ -292,52 +292,52 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
 	WindowPtr pWin = (WindowPtr)pDstDrawable;
 
 	/* make the exposed area screen-relative */
-	REGION_TRANSLATE(pscr, &rgnExposed, 
+	RegionTranslate(&rgnExposed,
 				 pDstDrawable->x, pDstDrawable->y);
 
 	if (extents)
 	{
 	    /* miPaintWindow doesn't clip, so we have to */
-	    REGION_INTERSECT(pscr, &rgnExposed, &rgnExposed, &pWin->clipList);
+	    RegionIntersect(&rgnExposed, &rgnExposed, &pWin->clipList);
 	}
 	miPaintWindow((WindowPtr)pDstDrawable, &rgnExposed, PW_BACKGROUND);
 
 	if (extents)
 	{
-	    REGION_RESET(pscr, &rgnExposed, &expBox);
+	    RegionReset(&rgnExposed, &expBox);
 	}
 	else
-	    REGION_TRANSLATE(pscr, &rgnExposed,
+	    RegionTranslate(&rgnExposed,
 				     -pDstDrawable->x, -pDstDrawable->y);
     }
     if (prgnDstClip == &rgnDstRec)
     {
-	REGION_UNINIT(pscr, prgnDstClip);
+	RegionUninit(prgnDstClip);
     }
     else if (prgnDstClip != prgnSrcClip)
     {
-	REGION_DESTROY(pscr, prgnDstClip);
+	RegionDestroy(prgnDstClip);
     }
 
     if (prgnSrcClip == &rgnSrcRec)
     {
-	REGION_UNINIT(pscr, prgnSrcClip);
+	RegionUninit(prgnSrcClip);
     }
     else
     {
-	REGION_DESTROY(pscr, prgnSrcClip);
+	RegionDestroy(prgnSrcClip);
     }
 
     if (pGC->graphicsExposures)
     {
 	/* don't look */
-	RegionPtr exposed = REGION_CREATE(pscr, NullBox, 0);
+	RegionPtr exposed = RegionCreate(NullBox, 0);
 	*exposed = rgnExposed;
 	return exposed;
     }
     else
     {
-	REGION_UNINIT(pscr, &rgnExposed);
+	RegionUninit(&rgnExposed);
 	return NULL;
     }
 }
@@ -348,7 +348,7 @@ void
 miSendGraphicsExpose (ClientPtr client, RegionPtr pRgn, XID drawable,
                       int major, int minor)
 {
-    if (pRgn && !REGION_NIL(pRgn))
+    if (pRgn && !RegionNil(pRgn))
     {
         xEvent *pEvent;
 	xEvent *pe;
@@ -356,8 +356,8 @@ miSendGraphicsExpose (ClientPtr client, RegionPtr pRgn, XID drawable,
 	int i;
 	int numRects;
 
-	numRects = REGION_NUM_RECTS(pRgn);
-	pBox = REGION_RECTS(pRgn);
+	numRects = RegionNumRects(pRgn);
+	pBox = RegionRects(pRgn);
 	if(!(pEvent = malloc(numRects * sizeof(xEvent))))
 		return;
 	pe = pEvent;
@@ -401,8 +401,8 @@ miSendExposures( WindowPtr pWin, RegionPtr pRgn, int dx, int dy)
     xEvent *pEvent, *pe;
     int i;
 
-    pBox = REGION_RECTS(pRgn);
-    numRects = REGION_NUM_RECTS(pRgn);
+    pBox = RegionRects(pRgn);
+    numRects = RegionNumRects(pRgn);
     if(!(pEvent = calloc(1, numRects * sizeof(xEvent))))
 	return;
 
@@ -457,8 +457,8 @@ void
 miWindowExposures( WindowPtr pWin, RegionPtr prgn, RegionPtr other_exposed)
 {
     RegionPtr   exposures = prgn;
-    if ((prgn && !REGION_NIL(prgn)) || 
-	(exposures && !REGION_NIL(exposures)) || other_exposed)
+    if ((prgn && !RegionNil(prgn)) ||
+	(exposures && !RegionNil(exposures)) || other_exposed)
     {
 	RegionRec   expRec;
 	int	    clientInterested;
@@ -471,15 +471,15 @@ miWindowExposures( WindowPtr pWin, RegionPtr prgn, RegionPtr other_exposed)
 	{
 	    if (exposures)
 	    {
-		REGION_UNION(pWin->drawable.pScreen, other_exposed,
+		RegionUnion(other_exposed,
 						  exposures,
 					          other_exposed);
 		if (exposures != prgn)
-		    REGION_DESTROY(pWin->drawable.pScreen, exposures);
+		    RegionDestroy(exposures);
 	    }
 	    exposures = other_exposed;
 	}
-	if (clientInterested && exposures && (REGION_NUM_RECTS(exposures) > RECTLIMIT))
+	if (clientInterested && exposures && (RegionNumRects(exposures) > RECTLIMIT))
 	{
 	    /*
 	     * If we have LOTS of rectangles, we decide to take the extents
@@ -489,34 +489,34 @@ miWindowExposures( WindowPtr pWin, RegionPtr prgn, RegionPtr other_exposed)
 	     */
 	    BoxRec box;
 
-	    box = *REGION_EXTENTS( pWin->drawable.pScreen, exposures);
+	    box = *RegionExtents(exposures);
 	    if (exposures == prgn) {
 		exposures = &expRec;
-		REGION_INIT( pWin->drawable.pScreen, exposures, &box, 1);
-		REGION_RESET( pWin->drawable.pScreen, prgn, &box);
+		RegionInit(exposures, &box, 1);
+		RegionReset(prgn, &box);
 	    } else {
-		REGION_RESET( pWin->drawable.pScreen, exposures, &box);
-		REGION_UNION( pWin->drawable.pScreen, prgn, prgn, exposures);
+		RegionReset(exposures, &box);
+		RegionUnion(prgn, prgn, exposures);
 	    }
 	    /* miPaintWindow doesn't clip, so we have to */
-	    REGION_INTERSECT( pWin->drawable.pScreen, prgn, prgn, &pWin->clipList);
+	    RegionIntersect(prgn, prgn, &pWin->clipList);
 	}
-	if (prgn && !REGION_NIL(prgn))
+	if (prgn && !RegionNil(prgn))
 	    miPaintWindow(pWin, prgn, PW_BACKGROUND);
-	if (clientInterested && exposures && !REGION_NIL(exposures))
+	if (clientInterested && exposures && !RegionNil(exposures))
 	    miSendExposures(pWin, exposures,
 			    pWin->drawable.x, pWin->drawable.y);
 	if (exposures == &expRec)
 	{
-	    REGION_UNINIT( pWin->drawable.pScreen, exposures);
+	    RegionUninit(exposures);
 	}
 	else if (exposures && exposures != prgn && exposures != other_exposed)
-	    REGION_DESTROY( pWin->drawable.pScreen, exposures);
+	    RegionDestroy(exposures);
 	if (prgn)
-	    REGION_EMPTY( pWin->drawable.pScreen, prgn);
+	    RegionEmpty(prgn);
     }
     else if (exposures && exposures != prgn)
-	REGION_DESTROY( pWin->drawable.pScreen, exposures);
+	RegionDestroy(exposures);
 }
 
 #ifdef ROOTLESS
@@ -647,7 +647,7 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
 	gcmask |= GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin;
     }
 
-    prect = malloc(REGION_NUM_RECTS(prgn) * sizeof(xRectangle));
+    prect = malloc(RegionNumRects(prgn) * sizeof(xRectangle));
     if (!prect)
 	return;
 
@@ -661,8 +661,8 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     ChangeGC (NullClient, pGC, gcmask, gcval);
     ValidateGC (drawable, pGC);
 
-    numRects = REGION_NUM_RECTS(prgn);
-    pbox = REGION_RECTS(prgn);
+    numRects = RegionNumRects(prgn);
+    pbox = RegionRects(prgn);
     for (i= numRects; --i >= 0; pbox++, prect++)
     {
 	prect->x = pbox->x1 - draw_x_off;
diff --git a/mi/migc.c b/mi/migc.c
index 7b2b1c3..778c4b4 100644
--- a/mi/migc.c
+++ b/mi/migc.c
@@ -50,7 +50,7 @@ miDestroyGC(GCPtr pGC)
     if (pGC->pRotatedPixmap)
 	(*pGC->pScreen->DestroyPixmap) (pGC->pRotatedPixmap);
     if (pGC->freeCompClip)
-	REGION_DESTROY(pGC->pScreen, pGC->pCompositeClip);
+	RegionDestroy(pGC->pCompositeClip);
 }
 
 void
@@ -68,7 +68,7 @@ miDestroyClip(GCPtr pGC)
 	 * we know we'll never have a list of rectangles, since ChangeClip
 	 * immediately turns them into a region
 	 */
-	REGION_DESTROY(pGC->pScreen, pGC->clientClip);
+	RegionDestroy(pGC->clientClip);
     }
     pGC->clientClip = NULL;
     pGC->clientClipType = CT_NONE;
@@ -81,7 +81,7 @@ miChangeClip( GCPtr pGC, int type, pointer pvalue, int nrects)
     if (type == CT_PIXMAP)
     {
 	/* convert the pixmap to a region */
-	pGC->clientClip = (pointer) BITMAP_TO_REGION(pGC->pScreen,
+	pGC->clientClip = (pointer) BitmapToRegion(pGC->pScreen,
 							(PixmapPtr) pvalue);
 	(*pGC->pScreen->DestroyPixmap) (pvalue);
     }
@@ -92,7 +92,7 @@ miChangeClip( GCPtr pGC, int type, pointer pvalue, int nrects)
     }
     else if (type != CT_NONE)
     {
-	pGC->clientClip = (pointer) RECTS_TO_REGION(pGC->pScreen, nrects,
+	pGC->clientClip = (pointer) RegionFromRects(nrects,
 						      (xRectangle *) pvalue,
 								    type);
 	free(pvalue);
@@ -116,8 +116,8 @@ miCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
 				   pgcSrc->clientClip, 0);
 	break;
       case CT_REGION:
-	prgnNew = REGION_CREATE(pgcSrc->pScreen, NULL, 1);
-	REGION_COPY(pgcDst->pScreen, prgnNew,
+	prgnNew = RegionCreate(NULL, 1);
+	RegionCopy(prgnNew,
 					(RegionPtr) (pgcSrc->clientClip));
 	(*pgcDst->funcs->ChangeClip) (pgcDst, CT_REGION, (pointer) prgnNew, 0);
 	break;
@@ -167,7 +167,7 @@ miComputeCompositeClip( GCPtr pGC, DrawablePtr pDrawable)
 	if (pGC->clientClipType == CT_NONE)
 	{
 	    if (freeCompClip)
-		REGION_DESTROY(pScreen, pGC->pCompositeClip);
+		RegionDestroy(pGC->pCompositeClip);
 	    pGC->pCompositeClip = pregWin;
 	    pGC->freeCompClip = freeTmpClip;
 	}
@@ -182,30 +182,30 @@ miComputeCompositeClip( GCPtr pGC, DrawablePtr pDrawable)
 	     * clip. if neither is real, create a new region.
 	     */
 
-	    REGION_TRANSLATE(pScreen, pGC->clientClip,
+	    RegionTranslate(pGC->clientClip,
 					 pDrawable->x + pGC->clipOrg.x,
 					 pDrawable->y + pGC->clipOrg.y);
 
 	    if (freeCompClip)
 	    {
-		REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
+		RegionIntersect(pGC->pCompositeClip,
 					    pregWin, pGC->clientClip);
 		if (freeTmpClip)
-		    REGION_DESTROY(pScreen, pregWin);
+		    RegionDestroy(pregWin);
 	    }
 	    else if (freeTmpClip)
 	    {
-		REGION_INTERSECT(pScreen, pregWin, pregWin, pGC->clientClip);
+		RegionIntersect(pregWin, pregWin, pGC->clientClip);
 		pGC->pCompositeClip = pregWin;
 	    }
 	    else
 	    {
-		pGC->pCompositeClip = REGION_CREATE(pScreen, NullBox, 0);
-		REGION_INTERSECT(pScreen, pGC->pCompositeClip,
+		pGC->pCompositeClip = RegionCreate(NullBox, 0);
+		RegionIntersect(pGC->pCompositeClip,
 				       pregWin, pGC->clientClip);
 	    }
 	    pGC->freeCompClip = TRUE;
-	    REGION_TRANSLATE(pScreen, pGC->clientClip,
+	    RegionTranslate(pGC->clientClip,
 					 -(pDrawable->x + pGC->clipOrg.x),
 					 -(pDrawable->y + pGC->clipOrg.y));
 	}
@@ -223,31 +223,31 @@ miComputeCompositeClip( GCPtr pGC, DrawablePtr pDrawable)
 
 	if (pGC->freeCompClip)
 	{
-	    REGION_RESET(pScreen, pGC->pCompositeClip, &pixbounds);
+	    RegionReset(pGC->pCompositeClip, &pixbounds);
 	}
 	else
 	{
 	    pGC->freeCompClip = TRUE;
-	    pGC->pCompositeClip = REGION_CREATE(pScreen, &pixbounds, 1);
+	    pGC->pCompositeClip = RegionCreate(&pixbounds, 1);
 	}
 
 	if (pGC->clientClipType == CT_REGION)
 	{
 	    if(pDrawable->x || pDrawable->y) {
-	        REGION_TRANSLATE(pScreen, pGC->clientClip,
+	        RegionTranslate(pGC->clientClip,
 					  pDrawable->x + pGC->clipOrg.x, 
 					  pDrawable->y + pGC->clipOrg.y);
-	        REGION_INTERSECT(pScreen, pGC->pCompositeClip,
+	        RegionIntersect(pGC->pCompositeClip,
 				pGC->pCompositeClip, pGC->clientClip);
-	        REGION_TRANSLATE(pScreen, pGC->clientClip,
+	        RegionTranslate(pGC->clientClip,
 					  -(pDrawable->x + pGC->clipOrg.x), 
 					  -(pDrawable->y + pGC->clipOrg.y));
 	    } else {
-	        REGION_TRANSLATE(pScreen, pGC->pCompositeClip,
+	        RegionTranslate(pGC->pCompositeClip,
 					 -pGC->clipOrg.x, -pGC->clipOrg.y);
-	        REGION_INTERSECT(pScreen, pGC->pCompositeClip,
+	        RegionIntersect(pGC->pCompositeClip,
 				pGC->pCompositeClip, pGC->clientClip);
-	        REGION_TRANSLATE(pScreen, pGC->pCompositeClip,
+	        RegionTranslate(pGC->pCompositeClip,
 					 pGC->clipOrg.x, pGC->clipOrg.y);
 	    }
 	}
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index da3ff4a..d8eb642 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -201,8 +201,8 @@ miOverlayCreateWindow(WindowPtr pWin)
 	    pTree->visibility = VisibilityNotViewable;
 	    pWinPriv->tree = pTree;
 	    if(pWin->parent) {
-		REGION_NULL(pScreen, &(pTree->borderClip));
-		REGION_NULL(pScreen, &(pTree->clipList));
+		RegionNull(&(pTree->borderClip));
+		RegionNull(&(pTree->clipList));
 		RebuildTree(pWin);
 	    } else {
 		BoxRec fullBox;
@@ -210,8 +210,8 @@ miOverlayCreateWindow(WindowPtr pWin)
 		fullBox.y1 = 0;
 		fullBox.x2 = pScreen->width;
 		fullBox.y2 = pScreen->height;
-		REGION_INIT(pScreen, &(pTree->borderClip), &fullBox, 1);
-		REGION_INIT(pScreen, &(pTree->clipList), &fullBox, 1);
+		RegionInit(&(pTree->borderClip), &fullBox, 1);
+		RegionInit(&(pTree->clipList), &fullBox, 1);
 	    }
 	} else free(pTree);
     }
@@ -239,8 +239,8 @@ miOverlayDestroyWindow(WindowPtr pWin)
 	else if(pTree->parent)
 	   pTree->parent->lastChild = pTree->prevSib;
 
-	REGION_UNINIT(pScreen, &(pTree->borderClip));
-	REGION_UNINIT(pScreen, &(pTree->clipList));
+	RegionUninit(&(pTree->borderClip));
+	RegionUninit(&(pTree->clipList));
 	free(pTree);
     }
 
@@ -338,7 +338,7 @@ miOverlayMarkOverlappedWindows(
 
     doUnderlay = (IN_UNDERLAY(pWin) || HasUnderlayChildren(pWin));
 
-    box = REGION_EXTENTS(pScreen, &pWin->borderSize);
+    box = RegionExtents(&pWin->borderSize);
 
     if((pChild = pFirst)) {
 	pLast = pChild->parent->lastChild;
@@ -349,13 +349,13 @@ miOverlayMarkOverlappedWindows(
 		pTree = MIOVERLAY_GET_WINDOW_TREE(pChild);
 
 	    if(pChild->viewable) {
-                if (REGION_BROKEN (pScreen, &pChild->winSize))
+                if (RegionBroken(&pChild->winSize))
                     SetWinSize (pChild);
-                if (REGION_BROKEN (pScreen, &pChild->borderSize))
+                if (RegionBroken(&pChild->borderSize))
 		    SetBorderSize (pChild);
 
 	    	if (markAll || 
-		    RECT_IN_REGION(pScreen, &pChild->borderSize, box))
+		    RegionContainsRect(&pChild->borderSize, box))
 		{
 		    MARK_OVERLAY(pChild);
 		    overMarked = TRUE;
@@ -410,12 +410,12 @@ miOverlayMarkOverlappedWindows(
 
 	while(1) {
 	    if(tChild->pWin->viewable) { 
-                if (REGION_BROKEN (pScreen, &tChild->pWin->winSize))
+                if (RegionBroken(&tChild->pWin->winSize))
                     SetWinSize (tChild->pWin);
-                if (REGION_BROKEN (pScreen, &tChild->pWin->borderSize))
+                if (RegionBroken(&tChild->pWin->borderSize))
 		    SetBorderSize (tChild->pWin);
 
-		if(RECT_IN_REGION(pScreen, &(tChild->pWin->borderSize), box)) 
+		if(RegionContainsRect(&(tChild->pWin->borderSize), box))
 	        {
 		    MARK_UNDERLAY(tChild->pWin);
 		    underMarked = TRUE;
@@ -473,7 +473,7 @@ miOverlayComputeClips(
     borderSize.y2 = dy;
   
     oldVis = tParent->visibility;
-    switch (RECT_IN_REGION( pScreen, universe, &borderSize)) {
+    switch (RegionContainsRect(universe, &borderSize)) {
 	case rgnIN:
 	    newVis = VisibilityUnobscured;
 	    break;
@@ -521,8 +521,8 @@ miOverlayComputeClips(
 	    while (1) {
 		if (tChild->pWin->viewable) {
 		    if (tChild->visibility != VisibilityFullyObscured) {
-			REGION_TRANSLATE( pScreen, &tChild->borderClip, dx, dy);
-			REGION_TRANSLATE( pScreen, &tChild->clipList, dx, dy);
+			RegionTranslate(&tChild->borderClip, dx, dy);
+			RegionTranslate(&tChild->clipList, dx, dy);
 		
 			tChild->pWin->drawable.serialNumber = 
 							 NEXT_SERIAL_NUMBER;
@@ -530,14 +530,14 @@ miOverlayComputeClips(
                             (* pScreen->ClipNotify) (tChild->pWin, dx, dy);
 		    }
 		    if (tChild->valdata) {
-			REGION_NULL(pScreen, &tChild->valdata->borderExposed);
+			RegionNull(&tChild->valdata->borderExposed);
 			if (HasParentRelativeBorder(tChild->pWin)){
-			    REGION_SUBTRACT(pScreen,
+			    RegionSubtract(
 					 &tChild->valdata->borderExposed,
 					 &tChild->borderClip,
 					 &tChild->pWin->winSize);
 			}
-			REGION_NULL(pScreen, &tChild->valdata->exposed);
+			RegionNull(&tChild->valdata->exposed);
 		    }
 		    if (tChild->firstChild) {
 			tChild = tChild->firstChild;
@@ -555,50 +555,50 @@ miOverlayComputeClips(
 	/* fall through */
     default:
     	if (dx || dy)  {
-	    REGION_TRANSLATE( pScreen, &tParent->borderClip, dx, dy);
-	    REGION_TRANSLATE( pScreen, &tParent->clipList, dx, dy);
+	    RegionTranslate(&tParent->borderClip, dx, dy);
+	    RegionTranslate(&tParent->clipList, dx, dy);
     	} 
 	break;
     case VTBroken:
-	REGION_EMPTY (pScreen, &tParent->borderClip);
-	REGION_EMPTY (pScreen, &tParent->clipList);
+	RegionEmpty(&tParent->borderClip);
+	RegionEmpty(&tParent->clipList);
 	break;
     }
 
     borderVisible = tParent->valdata->borderVisible;
-    REGION_NULL(pScreen, &tParent->valdata->borderExposed);
-    REGION_NULL(pScreen, &tParent->valdata->exposed);
+    RegionNull(&tParent->valdata->borderExposed);
+    RegionNull(&tParent->valdata->exposed);
 
     if (HasBorder (pParent)) {
     	if (borderVisible) {
-	    REGION_SUBTRACT( pScreen, exposed, universe, borderVisible);
-	    REGION_DESTROY( pScreen, borderVisible);
+	    RegionSubtract(exposed, universe, borderVisible);
+	    RegionDestroy(borderVisible);
     	} else
-	    REGION_SUBTRACT( pScreen, exposed, universe, &tParent->borderClip);
+	    RegionSubtract(exposed, universe, &tParent->borderClip);
 
 	if (HasParentRelativeBorder(pParent) && (dx || dy))
-	    REGION_SUBTRACT( pScreen, &tParent->valdata->borderExposed,
+	    RegionSubtract(&tParent->valdata->borderExposed,
 				  universe, &pParent->winSize);
 	else
-	    REGION_SUBTRACT( pScreen, &tParent->valdata->borderExposed,
+	    RegionSubtract(&tParent->valdata->borderExposed,
 			       exposed, &pParent->winSize);
 
-    	REGION_COPY( pScreen, &tParent->borderClip, universe);    
-    	REGION_INTERSECT( pScreen, universe, universe, &pParent->winSize);
+	RegionCopy(&tParent->borderClip, universe);
+	RegionIntersect(universe, universe, &pParent->winSize);
     }
     else
-    	REGION_COPY( pScreen, &tParent->borderClip, universe);
+	RegionCopy(&tParent->borderClip, universe);
 
     if ((tChild = tParent->firstChild) && pParent->mapped) {
-	REGION_NULL(pScreen, &childUniverse);
-	REGION_NULL(pScreen, &childUnion);
+	RegionNull(&childUniverse);
+	RegionNull(&childUnion);
 
 	for (; tChild; tChild = tChild->nextSib) {
 	    if (tChild->pWin->viewable)
-		REGION_APPEND( pScreen, &childUnion, &tChild->pWin->borderSize);
+		RegionAppend(&childUnion, &tChild->pWin->borderSize);
 	}
 
-	REGION_VALIDATE( pScreen, &childUnion, &overlap);
+	RegionValidate(&childUnion, &overlap);
 
 	for (tChild = tParent->firstChild;
 	     tChild;
@@ -606,31 +606,31 @@ miOverlayComputeClips(
  	{
 	    if (tChild->pWin->viewable) {
 		if (tChild->valdata) {
-		    REGION_INTERSECT( pScreen, &childUniverse, universe,
+		    RegionIntersect(&childUniverse, universe,
 					    &tChild->pWin->borderSize);
 		    miOverlayComputeClips (tChild->pWin, &childUniverse, 
 						kind, exposed);
 		}
 		if (overlap)
-		    REGION_SUBTRACT( pScreen, universe, universe,
+		    RegionSubtract(universe, universe,
 					  &tChild->pWin->borderSize);
 	    }
 	}
 	if (!overlap)
-	    REGION_SUBTRACT( pScreen, universe, universe, &childUnion);
-	REGION_UNINIT( pScreen, &childUnion);
-	REGION_UNINIT( pScreen, &childUniverse);
+	    RegionSubtract(universe, universe, &childUnion);
+	RegionUninit(&childUnion);
+	RegionUninit(&childUniverse);
     } 
 
     if (oldVis == VisibilityFullyObscured ||
 	oldVis == VisibilityNotViewable)
     {
-	REGION_COPY( pScreen, &tParent->valdata->exposed, universe);
+	RegionCopy(&tParent->valdata->exposed, universe);
     }
     else if (newVis != VisibilityFullyObscured &&
 	     newVis != VisibilityNotViewable)
     {
-    	REGION_SUBTRACT( pScreen, &tParent->valdata->exposed,
+	RegionSubtract(&tParent->valdata->exposed,
 			       universe, &tParent->clipList);
     }
     
@@ -708,14 +708,14 @@ miOverlayMarkUnrealizedWindow(
     if ((pChild != pWin) || fromConfigure) {
 	miOverlayTreePtr pTree;
 
-        REGION_EMPTY(pChild->drawable.pScreen, &pChild->clipList);
+        RegionEmpty(&pChild->clipList);
         if (pChild->drawable.pScreen->ClipNotify)
             (* pChild->drawable.pScreen->ClipNotify)(pChild, 0, 0);
-        REGION_EMPTY(pChild->drawable.pScreen, &pChild->borderClip);
+        RegionEmpty(&pChild->borderClip);
 	if((pTree = MIOVERLAY_GET_WINDOW_TREE(pChild))) {
 	    if(pTree->valdata != (miOverlayValDataPtr)UnmapValData) {
-		REGION_EMPTY(pChild->drawable.pScreen, &pTree->clipList);
-		REGION_EMPTY(pChild->drawable.pScreen, &pTree->borderClip);
+		RegionEmpty(&pTree->clipList);
+		RegionEmpty(&pTree->borderClip);
 	    }
 	}
     }
@@ -740,9 +740,9 @@ miOverlayValidateTree(
 
     if (!pChild) pChild = pParent->firstChild;
 
-    REGION_NULL(pScreen, &totalClip);
-    REGION_NULL(pScreen, &childClip);
-    REGION_NULL(pScreen, &exposed);
+    RegionNull(&totalClip);
+    RegionNull(&childClip);
+    RegionNull(&exposed);
 
     newParent = pParent;
 
@@ -756,52 +756,52 @@ miOverlayValidateTree(
     else
 	tChild = tParent->firstChild;
 
-    if (REGION_BROKEN (pScreen, &tParent->clipList) &&
-        !REGION_BROKEN (pScreen, &tParent->borderClip))
+    if (RegionBroken(&tParent->clipList) &&
+        !RegionBroken(&tParent->borderClip))
     {
 	kind = VTBroken;
-	REGION_COPY (pScreen, &totalClip, &tParent->borderClip);
-	REGION_INTERSECT (pScreen, &totalClip, &totalClip,
+	RegionCopy(&totalClip, &tParent->borderClip);
+	RegionIntersect(&totalClip, &totalClip,
 						 &tParent->pWin->winSize);
         
         for (tWin = tParent->firstChild; tWin != tChild; tWin = tWin->nextSib) {
             if (tWin->pWin->viewable)
-                REGION_SUBTRACT (pScreen, &totalClip, &totalClip, 
+                RegionSubtract(&totalClip, &totalClip,
 					&tWin->pWin->borderSize);
         }        
-        REGION_EMPTY (pScreen, &tParent->clipList);
+        RegionEmpty(&tParent->clipList);
     } else {
 	for(tWin = tChild; tWin; tWin = tWin->nextSib) {
 	    if(tWin->valdata)
-		REGION_APPEND(pScreen, &totalClip, &tWin->borderClip);
+		RegionAppend(&totalClip, &tWin->borderClip);
 	}
-	REGION_VALIDATE(pScreen, &totalClip, &overlap);
+	RegionValidate(&totalClip, &overlap);
     }
 
     if(kind != VTStack)
-	REGION_UNION(pScreen, &totalClip, &totalClip, &tParent->clipList);
+	RegionUnion(&totalClip, &totalClip, &tParent->clipList);
 	
     for(tWin = tChild; tWin; tWin = tWin->nextSib) {
 	if(tWin->valdata) {
 	    if(tWin->pWin->viewable) {
-		REGION_INTERSECT(pScreen, &childClip, &totalClip,
+		RegionIntersect(&childClip, &totalClip,
 					&tWin->pWin->borderSize);
 		miOverlayComputeClips(tWin->pWin, &childClip, kind, &exposed);
-		REGION_SUBTRACT(pScreen, &totalClip, &totalClip,
+		RegionSubtract(&totalClip, &totalClip,
 					&tWin->pWin->borderSize);
 	    } else {  /* Means we are unmapping */
-                REGION_EMPTY(pScreen, &tWin->clipList);
-                REGION_EMPTY( pScreen, &tWin->borderClip);
+                RegionEmpty(&tWin->clipList);
+                RegionEmpty(&tWin->borderClip);
 		tWin->valdata = NULL;
 	    }
 	}
     }
 
-    REGION_UNINIT(pScreen, &childClip);
+    RegionUninit(&childClip);
 
     if(!((*pPriv->InOverlay)(newParent))) {
-	REGION_NULL(pScreen, &tParent->valdata->exposed);
-	REGION_NULL(pScreen, &tParent->valdata->borderExposed);
+	RegionNull(&tParent->valdata->exposed);
+	RegionNull(&tParent->valdata->borderExposed);
     }
 
     switch (kind) {
@@ -809,18 +809,18 @@ miOverlayValidateTree(
 	break;
     default:
     	if(!((*pPriv->InOverlay)(newParent))) 
-	    REGION_SUBTRACT(pScreen, &tParent->valdata->exposed, &totalClip, 
+	    RegionSubtract(&tParent->valdata->exposed, &totalClip,
 						&tParent->clipList);
 	/* fall through */
     case VTMap:
-	REGION_COPY( pScreen, &tParent->clipList, &totalClip);
+	RegionCopy(&tParent->clipList, &totalClip);
     	if(!((*pPriv->InOverlay)(newParent))) 
 	    newParent->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	break;
     }
 
-    REGION_UNINIT( pScreen, &totalClip);
-    REGION_UNINIT( pScreen, &exposed);
+    RegionUninit(&totalClip);
+    RegionUninit(&exposed);
 
 SKIP_UNDERLAY:
 
@@ -853,14 +853,14 @@ miOverlayHandleExposures(WindowPtr pWin)
 	while (1) {
 	    if((mival = pTree->valdata)) {
 		if(!((*pPriv->InOverlay)(pTree->pWin))) {
-		    if (REGION_NOTEMPTY(pScreen, &mival->borderExposed)) {
+		    if (RegionNotEmpty(&mival->borderExposed)) {
 			miPaintWindow(pTree->pWin, &mival->borderExposed,
 				      PW_BORDER);
 		    }
-		    REGION_UNINIT(pScreen, &mival->borderExposed);
+		    RegionUninit(&mival->borderExposed);
 
 		    (*WindowExposures)(pTree->pWin,&mival->exposed,NullRegion);
-		    REGION_UNINIT(pScreen, &mival->exposed);
+		    RegionUninit(&mival->exposed);
 		}
 		free(mival);
 		pTree->valdata = NULL;
@@ -882,24 +882,24 @@ miOverlayHandleExposures(WindowPtr pWin)
     while (1) {
 	if ( (val = pChild->valdata) ) {
 	    if(!((*pPriv->InOverlay)(pChild))) {
-		REGION_UNION(pScreen, &val->after.exposed, &val->after.exposed,
+		RegionUnion(&val->after.exposed, &val->after.exposed,
 			&val->after.borderExposed);
 
-		if (REGION_NOTEMPTY(pScreen, &val->after.exposed)) {
+		if (RegionNotEmpty(&val->after.exposed)) {
 		   (*(MIOVERLAY_GET_SCREEN_PRIVATE(pScreen)->MakeTransparent))(
 				pScreen, 
-				REGION_NUM_RECTS(&val->after.exposed),
-				REGION_RECTS(&val->after.exposed));
+				RegionNumRects(&val->after.exposed),
+				RegionRects(&val->after.exposed));
 		}
 	    } else {
-		if (REGION_NOTEMPTY(pScreen, &val->after.borderExposed)) {
+		if (RegionNotEmpty(&val->after.borderExposed)) {
 			miPaintWindow(pChild, &val->after.borderExposed,
 				      PW_BORDER);
 		}
 		(*WindowExposures)(pChild, &val->after.exposed, NullRegion);
 	    }
-	    REGION_UNINIT(pScreen, &val->after.borderExposed);
-	    REGION_UNINIT(pScreen, &val->after.exposed);
+	    RegionUninit(&val->after.borderExposed);
+	    RegionUninit(&val->after.exposed);
 	    free(val);
 	    pChild->valdata = NULL;
 	    if (pChild->firstChild)
@@ -940,13 +940,13 @@ miOverlayMoveWindow(
     oldpt.x = pWin->drawable.x;
     oldpt.y = pWin->drawable.y;
     if (WasViewable) {
-	REGION_NULL(pScreen, &overReg);
-	REGION_NULL(pScreen, &underReg);
+	RegionNull(&overReg);
+	RegionNull(&underReg);
 	if(pTree) {
-	    REGION_COPY(pScreen, &overReg, &pWin->borderClip);
-	    REGION_COPY(pScreen, &underReg, &pTree->borderClip);
+	    RegionCopy(&overReg, &pWin->borderClip);
+	    RegionCopy(&underReg, &pTree->borderClip);
         } else {
-	    REGION_COPY(pScreen, &overReg, &pWin->borderClip);
+	    RegionCopy(&overReg, &pWin->borderClip);
 	    CollectUnderlayChildrenRegions(pWin, &underReg);
 	}
 	(*pScreen->MarkOverlappedWindows)(pWin, pWin, NULL);
@@ -971,16 +971,16 @@ miOverlayMoveWindow(
 
 
 	(*pScreen->ValidateTree)(pWin->parent, NullWindow, kind);
-	if(REGION_NOTEMPTY(pScreen, &underReg)) {
+	if(RegionNotEmpty(&underReg)) {
 	    pPriv->copyUnderlay = TRUE;
 	    (* pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, &underReg);
 	}
-	REGION_UNINIT(pScreen, &underReg);
-	if(REGION_NOTEMPTY(pScreen, &overReg)) {
+	RegionUninit(&underReg);
+	if(RegionNotEmpty(&overReg)) {
 	    pPriv->copyUnderlay = FALSE;
 	    (* pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, &overReg);
 	}
-	REGION_UNINIT(pScreen, &overReg);
+	RegionUninit(&overReg);
 	(*pScreen->HandleExposures)(pWin->parent);
 
 	if (pScreen->PostValidateTree)
@@ -1003,8 +1003,8 @@ miOverlayWindowExposures(
     RegionPtr   exposures = prgn;
     ScreenPtr pScreen = pWin->drawable.pScreen;
 
-    if ((prgn && !REGION_NIL(prgn)) || 
-	(exposures && !REGION_NIL(exposures)) || other_exposed)
+    if ((prgn && !RegionNil(prgn)) ||
+	(exposures && !RegionNil(exposures)) || other_exposed)
     {
 	RegionRec   expRec;
 	int	    clientInterested;
@@ -1013,51 +1013,51 @@ miOverlayWindowExposures(
 		 	    ExposureMask;
 	if (other_exposed) {
 	    if (exposures) {
-		REGION_UNION(pScreen, other_exposed, exposures, other_exposed);
+		RegionUnion(other_exposed, exposures, other_exposed);
 		if (exposures != prgn)
-		    REGION_DESTROY(pScreen, exposures);
+		    RegionDestroy(exposures);
 	    }
 	    exposures = other_exposed;
 	}
 	if (clientInterested && exposures && 
-	   (REGION_NUM_RECTS(exposures) > RECTLIMIT))
+	   (RegionNumRects(exposures) > RECTLIMIT))
 	{
             miOverlayScreenPtr pPriv = MIOVERLAY_GET_SCREEN_PRIVATE(pScreen);
 	    BoxRec box;
 
-	    box = *REGION_EXTENTS(pScreen, exposures);
+	    box = *RegionExtents(exposures);
 	    if (exposures == prgn) {
 		exposures = &expRec;
-		REGION_INIT(pScreen, exposures, &box, 1);
-		REGION_RESET(pScreen, prgn, &box);
+		RegionInit(exposures, &box, 1);
+		RegionReset(prgn, &box);
 	    } else {
-		REGION_RESET(pScreen, exposures, &box);
-		REGION_UNION(pScreen, prgn, prgn, exposures);
+		RegionReset(exposures, &box);
+		RegionUnion(prgn, prgn, exposures);
 	    }
 	    /* This is the only reason why we are replacing mi's version
                of this file */
 	    
 	    if(!((*pPriv->InOverlay)(pWin))) {
 		miOverlayTreePtr pTree = MIOVERLAY_GET_WINDOW_TREE(pWin);
-		REGION_INTERSECT(pScreen, prgn, prgn, &pTree->clipList);
+		RegionIntersect(prgn, prgn, &pTree->clipList);
 	    } else
-		REGION_INTERSECT(pScreen, prgn, prgn, &pWin->clipList);
+		RegionIntersect(prgn, prgn, &pWin->clipList);
 	}
-	if (prgn && !REGION_NIL(prgn))
+	if (prgn && !RegionNil(prgn))
 	    miPaintWindow(pWin, prgn, PW_BACKGROUND);
-	if (clientInterested && exposures && !REGION_NIL(exposures))
+	if (clientInterested && exposures && !RegionNil(exposures))
 	    miSendExposures(pWin, exposures,
 			    pWin->drawable.x, pWin->drawable.y);
 	if (exposures == &expRec) {
-	    REGION_UNINIT(pScreen, exposures);
+	    RegionUninit(exposures);
 	} 
 	else if (exposures && exposures != prgn && exposures != other_exposed)
-	    REGION_DESTROY(pScreen, exposures);
+	    RegionDestroy(exposures);
 	if (prgn)
-	    REGION_EMPTY(pScreen, prgn);
+	    RegionEmpty(prgn);
     }
     else if (exposures && exposures != prgn)
-	REGION_DESTROY(pScreen, exposures);
+	RegionDestroy(exposures);
 }
 
 
@@ -1082,23 +1082,23 @@ miOverlayRecomputeExposures (
 	/*
 	 * compute exposed regions of this window
 	 */
-	REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed,
+	RegionSubtract(&pWin->valdata->after.exposed,
 			&pWin->clipList, pValid->over);
 	/*
 	 * compute exposed regions of the border
 	 */
-	REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed,
+	RegionSubtract(&pWin->valdata->after.borderExposed,
 			     &pWin->borderClip, &pWin->winSize);
-	REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed,
+	RegionSubtract(&pWin->valdata->after.borderExposed,
 			     &pWin->valdata->after.borderExposed, pValid->over);
     } 
 
     if(pTree && pTree->valdata) {
-	REGION_SUBTRACT(pScreen, &pTree->valdata->exposed,
+	RegionSubtract(&pTree->valdata->exposed,
 			&pTree->clipList, pValid->under);
-	REGION_SUBTRACT(pScreen, &pTree->valdata->borderExposed,
+	RegionSubtract(&pTree->valdata->borderExposed,
 			     &pTree->borderClip, &pWin->winSize);
-	REGION_SUBTRACT(pScreen, &pTree->valdata->borderExposed,
+	RegionSubtract(&pTree->valdata->borderExposed,
 			     &pTree->valdata->borderExposed, pValid->under);    
     } else if (!pWin->valdata)
 	return WT_NOMATCH;
@@ -1154,11 +1154,11 @@ miOverlayResizeWindow(
 	/*
 	 * save the visible region of the window
 	 */
-	oldRegion = REGION_CREATE(pScreen, NullBox, 1);
-	REGION_COPY(pScreen, oldRegion, &pWin->winSize);
+	oldRegion = RegionCreate(NullBox, 1);
+	RegionCopy(oldRegion, &pWin->winSize);
 	if(doUnderlay) {
-	    oldRegion2 = REGION_CREATE(pScreen, NullBox, 1);
-	    REGION_COPY(pScreen, oldRegion2, &pWin->winSize);
+	    oldRegion2 = RegionCreate(NullBox, 1);
+	    RegionCopy(oldRegion2, &pWin->winSize);
 	}
 
 	/*
@@ -1170,16 +1170,16 @@ miOverlayResizeWindow(
 	    g = pChild->winGravity;
 	    if (g != UnmapGravity) {
 		if (!gravitate[g])
-		    gravitate[g] = REGION_CREATE(pScreen, NullBox, 1);
-		REGION_UNION(pScreen, gravitate[g],
+		    gravitate[g] = RegionCreate(NullBox, 1);
+		RegionUnion(gravitate[g],
 				   gravitate[g], &pChild->borderClip);
 		
 		if(doUnderlay) {
 		    if (!gravitate2[g])
-			gravitate2[g] = REGION_CREATE(pScreen, NullBox, 0);
+			gravitate2[g] = RegionCreate(NullBox, 0);
 		
 		    if((tChild = MIOVERLAY_GET_WINDOW_TREE(pChild))) {
-		        REGION_UNION(pScreen, gravitate2[g],
+		        RegionUnion(gravitate2[g],
 				   gravitate2[g], &tChild->borderClip);
 		    } else 
 			CollectUnderlayChildrenRegions(pChild, gravitate2[g]);
@@ -1193,11 +1193,11 @@ miOverlayResizeWindow(
 
 	oldWinClip = oldWinClip2 = NULL;
 	if (pWin->bitGravity != ForgetGravity) {
-	    oldWinClip = REGION_CREATE(pScreen, NullBox, 1);
-	    REGION_COPY(pScreen, oldWinClip, &pWin->clipList);
+	    oldWinClip = RegionCreate(NullBox, 1);
+	    RegionCopy(oldWinClip, &pWin->clipList);
 	    if(pTree) {
-		oldWinClip2 = REGION_CREATE(pScreen, NullBox, 1);
-		REGION_COPY(pScreen, oldWinClip2, &pTree->clipList);
+		oldWinClip2 = RegionCreate(NullBox, 1);
+		RegionCopy(oldWinClip2, &pTree->clipList);
 	    }
 	}
 	/*
@@ -1213,26 +1213,26 @@ miOverlayResizeWindow(
 	if ((pWin->drawable.height != h || pWin->drawable.width != w) &&
 	    HasBorder (pWin))
 	{
-	    borderVisible = REGION_CREATE(pScreen, NullBox, 1);
+	    borderVisible = RegionCreate(NullBox, 1);
 	    if(pTree)
-		borderVisible2 = REGION_CREATE(pScreen, NullBox, 1);
+		borderVisible2 = RegionCreate(NullBox, 1);
 	    /* for tiled borders, we punt and draw the whole thing */
 	    if (pWin->borderIsPixel || !moved)
 	    {
 		if (shrunk || moved)
-		    REGION_SUBTRACT(pScreen, borderVisible,
+		    RegionSubtract(borderVisible,
 					  &pWin->borderClip,
 					  &pWin->winSize);
 		else
-		    REGION_COPY(pScreen, borderVisible,
+		    RegionCopy(borderVisible,
 					    &pWin->borderClip);
 		if(pTree) {
 		    if (shrunk || moved)
-			REGION_SUBTRACT(pScreen, borderVisible,
+			RegionSubtract(borderVisible,
 					  &pTree->borderClip,
 					  &pWin->winSize);
 		    else
-			REGION_COPY(pScreen, borderVisible,
+			RegionCopy(borderVisible,
 					    &pTree->borderClip);
 		}
 	    }
@@ -1259,7 +1259,7 @@ miOverlayResizeWindow(
     pFirstChange = MoveWindowInStack(pWin, pSib);
 
     if (WasViewable) {
-	pRegion = REGION_CREATE(pScreen, NullBox, 1);
+	pRegion = RegionCreate(NullBox, 1);
 
 	(*pScreen->MarkOverlappedWindows)(pWin, pFirstChange, NULL);
 
@@ -1274,9 +1274,9 @@ miOverlayResizeWindow(
 	 * the entire window is trashed unless bitGravity
 	 * recovers portions of it
 	 */
-	REGION_COPY(pScreen, &pWin->valdata->after.exposed, &pWin->clipList);
+	RegionCopy(&pWin->valdata->after.exposed, &pWin->clipList);
 	if(pTree)
-	    REGION_COPY(pScreen, &pTree->valdata->exposed, &pTree->clipList);
+	    RegionCopy(&pTree->valdata->exposed, &pTree->clipList);
     }
 
     GravityTranslate (x, y, oldx, oldy, dw, dh, pWin->bitGravity, &nx, &ny);
@@ -1304,20 +1304,20 @@ miOverlayResizeWindow(
 		dx = (oldx - nx) - offx;
 		dy = (oldy - ny) - offy;
 		if (dx || dy) {
-		    REGION_TRANSLATE(pScreen, &pWin->winSize, dx, dy);
+		    RegionTranslate(&pWin->winSize, dx, dy);
 		    offx += dx;
 		    offy += dy;
 		}
 		if(gravitate[g])
-		    REGION_INTERSECT(pScreen, gravitate[g], gravitate[g],
+		    RegionIntersect(gravitate[g], gravitate[g],
 				 &pWin->winSize);
 		if(gravitate2[g])
-		    REGION_INTERSECT(pScreen, gravitate2[g], gravitate2[g],
+		    RegionIntersect(gravitate2[g], gravitate2[g],
 				 &pWin->winSize);
 	    }
 	    /* get winSize back where it belongs */
 	    if (offx || offy)
-		REGION_TRANSLATE(pScreen, &pWin->winSize, -offx, -offy);
+		RegionTranslate(&pWin->winSize, -offx, -offy);
 	}
 	/*
 	 * add screen bits to the appropriate bucket
@@ -1325,22 +1325,22 @@ miOverlayResizeWindow(
 
 	if (oldWinClip2)
 	{
-	    REGION_COPY(pScreen, pRegion, oldWinClip2);
-	    REGION_TRANSLATE(pScreen, pRegion, nx - oldx, ny - oldy);
-	    REGION_INTERSECT(pScreen, oldWinClip2, pRegion, &pTree->clipList);
+	    RegionCopy(pRegion, oldWinClip2);
+	    RegionTranslate(pRegion, nx - oldx, ny - oldy);
+	    RegionIntersect(oldWinClip2, pRegion, &pTree->clipList);
 
 	    for (g = pWin->bitGravity + 1; g <= StaticGravity; g++) {
 		if (gravitate2[g])
-		    REGION_SUBTRACT(pScreen, oldWinClip2, oldWinClip2,
+		    RegionSubtract(oldWinClip2, oldWinClip2,
 					gravitate2[g]);
 	    }
-	    REGION_TRANSLATE(pScreen, oldWinClip2, oldx - nx, oldy - ny);
+	    RegionTranslate(oldWinClip2, oldx - nx, oldy - ny);
 	    g = pWin->bitGravity;
 	    if (!gravitate2[g])
 		gravitate2[g] = oldWinClip2;
 	    else {
-		REGION_UNION(pScreen,gravitate2[g],gravitate2[g],oldWinClip2);
-		REGION_DESTROY(pScreen, oldWinClip2);
+		RegionUnion(gravitate2[g],gravitate2[g],oldWinClip2);
+		RegionDestroy(oldWinClip2);
 	    }
 	}
 
@@ -1349,9 +1349,9 @@ miOverlayResizeWindow(
 	    /*
 	     * clip to new clipList
 	     */
-	    REGION_COPY(pScreen, pRegion, oldWinClip);
-	    REGION_TRANSLATE(pScreen, pRegion, nx - oldx, ny - oldy);
-	    REGION_INTERSECT(pScreen, oldWinClip, pRegion, &pWin->clipList);
+	    RegionCopy(pRegion, oldWinClip);
+	    RegionTranslate(pRegion, nx - oldx, ny - oldy);
+	    RegionIntersect(oldWinClip, pRegion, &pWin->clipList);
 	    /*
 	     * don't step on any gravity bits which will be copied after this
 	     * region.	Note -- this assumes that the regions will be copied
@@ -1359,16 +1359,16 @@ miOverlayResizeWindow(
 	     */
 	    for (g = pWin->bitGravity + 1; g <= StaticGravity; g++) {
 		if (gravitate[g])
-		    REGION_SUBTRACT(pScreen, oldWinClip, oldWinClip,
+		    RegionSubtract(oldWinClip, oldWinClip,
 					gravitate[g]);
 	    }
-	    REGION_TRANSLATE(pScreen, oldWinClip, oldx - nx, oldy - ny);
+	    RegionTranslate(oldWinClip, oldx - nx, oldy - ny);
 	    g = pWin->bitGravity;
 	    if (!gravitate[g])
 		gravitate[g] = oldWinClip;
 	    else {
-		REGION_UNION(pScreen, gravitate[g], gravitate[g], oldWinClip);
-		REGION_DESTROY(pScreen, oldWinClip);
+		RegionUnion(gravitate[g], gravitate[g], oldWinClip);
+		RegionDestroy(oldWinClip);
 	    }
 	}
 
@@ -1392,23 +1392,23 @@ miOverlayResizeWindow(
 	    /* only copy the remaining useful bits */
 
 	    if(gravitate[g])
-		REGION_INTERSECT(pScreen, gravitate[g], 
+		RegionIntersect(gravitate[g],
 				 gravitate[g], oldRegion);
 	    if(gravitate2[g])
-		REGION_INTERSECT(pScreen, gravitate2[g], 
+		RegionIntersect(gravitate2[g],
 				 gravitate2[g], oldRegion2);
 
 	    /* clip to not overwrite already copied areas */
 
 	    if (destClip && gravitate[g]) {
-		REGION_TRANSLATE(pScreen, destClip, oldpt.x - x, oldpt.y - y);
-		REGION_SUBTRACT(pScreen, gravitate[g], gravitate[g], destClip);
-		REGION_TRANSLATE(pScreen, destClip, x - oldpt.x, y - oldpt.y);
+		RegionTranslate(destClip, oldpt.x - x, oldpt.y - y);
+		RegionSubtract(gravitate[g], gravitate[g], destClip);
+		RegionTranslate(destClip, x - oldpt.x, y - oldpt.y);
 	    }
 	    if (destClip2 && gravitate2[g]) {
-		REGION_TRANSLATE(pScreen, destClip2, oldpt.x - x, oldpt.y - y);
-		REGION_SUBTRACT(pScreen,gravitate2[g],gravitate2[g],destClip2);
-		REGION_TRANSLATE(pScreen, destClip2, x - oldpt.x, y - oldpt.y);
+		RegionTranslate(destClip2, oldpt.x - x, oldpt.y - y);
+		RegionSubtract(gravitate2[g],gravitate2[g],destClip2);
+		RegionTranslate(destClip2, x - oldpt.x, y - oldpt.y);
 	    }
 
 	    /* and move those bits */
@@ -1429,9 +1429,9 @@ miOverlayResizeWindow(
 	    /* remove any overwritten bits from the remaining useful bits */
 
 	    if(gravitate[g])
-		REGION_SUBTRACT(pScreen, oldRegion, oldRegion, gravitate[g]);
+		RegionSubtract(oldRegion, oldRegion, gravitate[g]);
 	    if(gravitate2[g])
-		REGION_SUBTRACT(pScreen, oldRegion2, oldRegion2, gravitate2[g]);
+		RegionSubtract(oldRegion2, oldRegion2, gravitate2[g]);
 
 	    /*
 	     * recompute exposed regions of child windows
@@ -1456,38 +1456,38 @@ miOverlayResizeWindow(
 
 	    if (g == pWin->bitGravity) {
 		if(gravitate[g])
-		    REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed,
+		    RegionSubtract(&pWin->valdata->after.exposed,
 				&pWin->valdata->after.exposed, gravitate[g]);
 		if(gravitate2[g] && pTree) 
-		    REGION_SUBTRACT(pScreen, &pTree->valdata->exposed,
+		    RegionSubtract(&pTree->valdata->exposed,
 				&pTree->valdata->exposed, gravitate2[g]);
 	    }
 	    if(gravitate[g]) {
 		if (!destClip)
 		    destClip = gravitate[g];
 		else {
-		    REGION_UNION(pScreen, destClip, destClip, gravitate[g]);
-		    REGION_DESTROY(pScreen, gravitate[g]);
+		    RegionUnion(destClip, destClip, gravitate[g]);
+		    RegionDestroy(gravitate[g]);
 		}
 	    }
 	    if(gravitate2[g]) {
 		if (!destClip2)
 		    destClip2 = gravitate2[g];
 		else {
-		    REGION_UNION(pScreen, destClip2, destClip2, gravitate2[g]);
-		    REGION_DESTROY(pScreen, gravitate2[g]);
+		    RegionUnion(destClip2, destClip2, gravitate2[g]);
+		    RegionDestroy(gravitate2[g]);
 		}
 	    }
 	}
 
-	REGION_DESTROY(pScreen, pRegion);
-	REGION_DESTROY(pScreen, oldRegion);
+	RegionDestroy(pRegion);
+	RegionDestroy(oldRegion);
 	if(doUnderlay)
-	    REGION_DESTROY(pScreen, oldRegion2);
+	    RegionDestroy(oldRegion2);
 	if (destClip)
-	    REGION_DESTROY(pScreen, destClip);
+	    RegionDestroy(destClip);
 	if (destClip2)
-	    REGION_DESTROY(pScreen, destClip2);
+	    RegionDestroy(destClip2);
 	(*pScreen->HandleExposures)(pWin->parent);
 	if (pScreen->PostValidateTree)
 	    (*pScreen->PostValidateTree)(pWin->parent, pFirstChange, VTOther);
@@ -1510,8 +1510,8 @@ miOverlaySetShape(WindowPtr pWin, int kind)
             if (HasBorder (pWin)) {
                 RegionPtr borderVisible;
 
-                borderVisible = REGION_CREATE(pScreen, NullBox, 1);
-                REGION_SUBTRACT(pScreen, borderVisible,
+                borderVisible = RegionCreate(NullBox, 1);
+                RegionSubtract(borderVisible,
                                         &pWin->borderClip, &pWin->winSize);
                 pWin->valdata->before.borderVisible = borderVisible;
                 pWin->valdata->before.resized = TRUE;
@@ -1519,8 +1519,8 @@ miOverlaySetShape(WindowPtr pWin, int kind)
                     miOverlayTreePtr pTree = MIOVERLAY_GET_WINDOW_TREE(pWin);
                     RegionPtr borderVisible2;
 
-                    borderVisible2 = REGION_CREATE(pScreen, NULL, 1);
-                    REGION_SUBTRACT(pScreen, borderVisible2,
+                    borderVisible2 = RegionCreate(NULL, 1);
+                    RegionSubtract(borderVisible2,
                                         &pTree->borderClip, &pWin->winSize);
                     pTree->valdata->borderVisible = borderVisible2;
                 }
@@ -1579,16 +1579,16 @@ miOverlayChangeBorderWidth(
 
 	    if (HadBorder) {
 		RegionPtr   borderVisible;
-		borderVisible = REGION_CREATE(pScreen, NULL, 1);
-		REGION_SUBTRACT(pScreen, borderVisible,
+		borderVisible = RegionCreate(NULL, 1);
+		RegionSubtract(borderVisible,
 				      &pWin->borderClip, &pWin->winSize);
 		pWin->valdata->before.borderVisible = borderVisible;
 		if(IN_UNDERLAY(pWin)) {
 		    miOverlayTreePtr pTree = MIOVERLAY_GET_WINDOW_TREE(pWin);
 		    RegionPtr borderVisible2;
 
-		    borderVisible2 = REGION_CREATE(pScreen, NULL, 1);
-		    REGION_SUBTRACT(pScreen, borderVisible2,
+		    borderVisible2 = RegionCreate(NULL, 1);
+		    RegionSubtract(borderVisible2,
 				      &pTree->borderClip, &pWin->winSize);
 		    pTree->valdata->borderVisible = borderVisible2;
 		}
@@ -1623,11 +1623,11 @@ miOverlaySetRootClip(ScreenPtr pScreen, Bool enable)
 	box.x2 = pScreen->width;
 	box.y2 = pScreen->height;
 
-	REGION_RESET(pScreen, &pTree->borderClip, &box);
+	RegionReset(&pTree->borderClip, &box);
     } else 
-	REGION_EMPTY(pScreen, &pTree->borderClip);
+	RegionEmpty(&pTree->borderClip);
 
-    REGION_BREAK(pScreen, &pTree->clipList);
+    RegionBreak(&pTree->clipList);
 }
 
 static void 
@@ -1662,7 +1662,7 @@ miOverlayClearToBackground(
     clipList = ((*pScreenPriv->InOverlay)(pWin)) ? &pWin->clipList :
                                                  &pTree->clipList;
 
-    extents = REGION_EXTENTS(pScreen, clipList);
+    extents = RegionExtents(clipList);
     
     if (x1 < extents->x1) x1 = extents->x1;
     if (x2 > extents->x2) x2 = extents->x2;
@@ -1675,16 +1675,16 @@ miOverlayClearToBackground(
     box.x1 = x1; box.x2 = x2;
     box.y1 = y1; box.y2 = y2;
 
-    REGION_INIT(pScreen, &reg, &box, 1);
+    RegionInit(&reg, &box, 1);
 
-    REGION_INTERSECT(pScreen, &reg, &reg, clipList);
+    RegionIntersect(&reg, &reg, clipList);
     if (generateExposures)
         (*pScreen->WindowExposures)(pWin, &reg, pBSReg);
     else if (pWin->backgroundState != None)
 	miPaintWindow(pWin, &reg, PW_BACKGROUND);
-    REGION_UNINIT(pScreen, &reg);
+    RegionUninit(&reg);
     if (pBSReg)
-        REGION_DESTROY(pScreen, pBSReg);
+        RegionDestroy(pBSReg);
 }
 
 
@@ -1738,12 +1738,12 @@ miOverlayComputeCompositeClip(GCPtr pGC, WindowPtr pWin)
     }
 
     if (pGC->subWindowMode == IncludeInferiors) {
-	pregWin = REGION_CREATE(pScreen, NullBox, 1);
+	pregWin = RegionCreate(NullBox, 1);
 	freeTmpClip = TRUE;
 	if (pWin->parent || (screenIsSaved != SCREEN_SAVER_ON) ||
 		!HasSaverWindow (pScreen))
 	{
-            REGION_INTERSECT(pScreen,pregWin,&pTree->borderClip,&pWin->winSize);
+            RegionIntersect(pregWin,&pTree->borderClip,&pWin->winSize);
 	}
     } else {
 	pregWin = &pTree->clipList;
@@ -1752,29 +1752,29 @@ miOverlayComputeCompositeClip(GCPtr pGC, WindowPtr pWin)
     freeCompClip = pGC->freeCompClip;
     if (pGC->clientClipType == CT_NONE) {
 	if (freeCompClip) 
-	    REGION_DESTROY(pScreen, pGC->pCompositeClip);
+	    RegionDestroy(pGC->pCompositeClip);
 	pGC->pCompositeClip = pregWin;
 	pGC->freeCompClip = freeTmpClip;
     } else {
-	REGION_TRANSLATE(pScreen, pGC->clientClip,
+	RegionTranslate(pGC->clientClip,
 				pWin->drawable.x + pGC->clipOrg.x,
 				pWin->drawable.y + pGC->clipOrg.y);
 
 	if (freeCompClip) {
-	    REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
+	    RegionIntersect(pGC->pCompositeClip,
 					    pregWin, pGC->clientClip);
 	    if (freeTmpClip)
-		REGION_DESTROY(pScreen, pregWin);
+		RegionDestroy(pregWin);
 	} else if (freeTmpClip) {
-	    REGION_INTERSECT(pScreen, pregWin, pregWin, pGC->clientClip);
+	    RegionIntersect(pregWin, pregWin, pGC->clientClip);
 	    pGC->pCompositeClip = pregWin;
 	} else {
-	    pGC->pCompositeClip = REGION_CREATE(pScreen, NullBox, 0);
-	    REGION_INTERSECT(pScreen, pGC->pCompositeClip,
+	    pGC->pCompositeClip = RegionCreate(NullBox, 0);
+	    RegionIntersect(pGC->pCompositeClip,
 				       pregWin, pGC->clientClip);
 	}
 	pGC->freeCompClip = TRUE;
-	REGION_TRANSLATE(pScreen, pGC->clientClip,
+	RegionTranslate(pGC->clientClip,
 				-(pWin->drawable.x + pGC->clipOrg.x),
 				-(pWin->drawable.y + pGC->clipOrg.y));
     }
@@ -1792,7 +1792,7 @@ miOverlayCollectUnderlayRegions(
 	return FALSE;
     }
 
-    *region = REGION_CREATE(pWin->drawable.pScreen, NullBox, 0);
+    *region = RegionCreate(NullBox, 0);
     
     CollectUnderlayChildrenRegions(pWin, *region);
 
@@ -1913,7 +1913,7 @@ CollectUnderlayChildrenRegions(WindowPtr pWin, RegionPtr pReg)
 
     while(1) {
 	if((pTree = MIOVERLAY_GET_WINDOW_TREE(pChild))) {
-	    REGION_APPEND(pScreen, pReg, &pTree->borderClip);
+	    RegionAppend(pReg, &pTree->borderClip);
 	    hasUnderlay = TRUE;
 	} else
 	if(pChild->firstChild) {
@@ -1931,7 +1931,7 @@ CollectUnderlayChildrenRegions(WindowPtr pWin, RegionPtr pReg)
 
     if(hasUnderlay) {
 	Bool overlap;
-	REGION_VALIDATE(pScreen, pReg, &overlap);
+	RegionValidate(pReg, &overlap);
     } 
 
     return hasUnderlay;
diff --git a/mi/mispans.h b/mi/mispans.h
index ef090bb..c3a3e67 100644
--- a/mi/mispans.h
+++ b/mi/mispans.h
@@ -85,16 +85,6 @@ extern _X_EXPORT void miFreeSpanGroup(
     SpanGroup * /*spanGroup*/
 );
 
-extern _X_EXPORT int RegionClipSpans(
-    RegionPtr /*prgnDst*/,
-    DDXPointPtr /*ppt*/,
-    int * /*pwidth*/,
-    int /*nspans*/,
-    DDXPointPtr /*pptNew*/,
-    int * /*pwidthNew*/,
-    int /*fSorted*/
-);
-
 /* Rops which must use span groups */
 #define miSpansCarefulRop(rop)	(((rop) & 0xc) == 0x8 || ((rop) & 0x3) == 0x2)
 #define miSpansEasyRop(rop)	(!miSpansCarefulRop(rop))
diff --git a/mi/mivaltree.c b/mi/mivaltree.c
index cfcdab7..dc88c4d 100644
--- a/mi/mivaltree.c
+++ b/mi/mivaltree.c
@@ -116,8 +116,8 @@ miShapedWindowIn (ScreenPtr pScreen, RegionPtr universe, RegionPtr bounding,
     Bool	someIn, someOut;
     int 	t, x1, y1, x2, y2;
 
-    nbox = REGION_NUM_RECTS (bounding);
-    boundBox = REGION_RECTS (bounding);
+    nbox = RegionNumRects (bounding);
+    boundBox = RegionRects (bounding);
     someIn = someOut = FALSE;
     x1 = rect->x1;
     y1 = rect->y1;
@@ -141,7 +141,7 @@ miShapedWindowIn (ScreenPtr pScreen, RegionPtr universe, RegionPtr bounding,
 	    box.x2 = box.x1;
 	if (box.y1 > box.y2)
 	    box.y2 = box.y1;
-	switch (RECT_IN_REGION(pScreen, universe, &box))
+	switch (RegionContainsRect(universe, &box))
 	{
 	case rgnIN:
 	    if (someOut)
@@ -252,15 +252,15 @@ miComputeClips (
 	if (miSetRedirectBorderClipProc)
 	{
 	    if (TreatAsTransparent (pParent))
-		REGION_EMPTY (pScreen, universe);
+		RegionEmpty(universe);
 	    (*miSetRedirectBorderClipProc) (pParent, universe);
 	}
-	REGION_COPY(pScreen, universe, &pParent->borderSize);
+	RegionCopy(universe, &pParent->borderSize);
     }
 #endif
 
     oldVis = pParent->visibility;
-    switch (RECT_IN_REGION( pScreen, universe, &borderSize)) 
+    switch (RegionContainsRect(universe, &borderSize))
     {
 	case rgnIN:
 	    newVis = VisibilityUnobscured;
@@ -320,9 +320,9 @@ miComputeClips (
 		{
 		    if (pChild->visibility != VisibilityFullyObscured)
 		    {
-			REGION_TRANSLATE( pScreen, &pChild->borderClip,
+			RegionTranslate(&pChild->borderClip,
 						      dx, dy);
-			REGION_TRANSLATE( pScreen, &pChild->clipList,
+			RegionTranslate(&pChild->clipList,
 						      dx, dy);
 			pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 			if (pScreen->ClipNotify)
@@ -331,16 +331,16 @@ miComputeClips (
 		    }
 		    if (pChild->valdata)
 		    {
-			REGION_NULL(pScreen,
+			RegionNull(
 				    &pChild->valdata->after.borderExposed);
 			if (HasParentRelativeBorder(pChild))
 			{
-			    REGION_SUBTRACT(pScreen,
+			    RegionSubtract(
 					 &pChild->valdata->after.borderExposed,
 					 &pChild->borderClip,
 					 &pChild->winSize);
 			}
-			REGION_NULL(pScreen, &pChild->valdata->after.exposed);
+			RegionNull(&pChild->valdata->after.exposed);
 		    }
 		    if (pChild->firstChild)
 		    {
@@ -369,20 +369,20 @@ miComputeClips (
 	     * We translate the old clipList because that will be exposed or copied
 	     * if gravity is right.
 	     */
-	    REGION_TRANSLATE( pScreen, &pParent->borderClip, dx, dy);
-	    REGION_TRANSLATE( pScreen, &pParent->clipList, dx, dy);
+	    RegionTranslate(&pParent->borderClip, dx, dy);
+	    RegionTranslate(&pParent->clipList, dx, dy);
     	} 
 	break;
     case VTBroken:
-	REGION_EMPTY (pScreen, &pParent->borderClip);
-	REGION_EMPTY (pScreen, &pParent->clipList);
+	RegionEmpty(&pParent->borderClip);
+	RegionEmpty(&pParent->clipList);
 	break;
     }
 
     borderVisible = pParent->valdata->before.borderVisible;
     resized = pParent->valdata->before.resized;
-    REGION_NULL(pScreen, &pParent->valdata->after.borderExposed);
-    REGION_NULL(pScreen, &pParent->valdata->after.exposed);
+    RegionNull(&pParent->valdata->after.borderExposed);
+    RegionNull(&pParent->valdata->after.exposed);
 
     /*
      * Since the borderClip must not be clipped by the children, we do
@@ -402,22 +402,22 @@ miComputeClips (
 	     * of the border will be saved by DIX in borderVisible --
 	     * use that region and destroy it
 	     */
-	    REGION_SUBTRACT( pScreen, exposed, universe, borderVisible);
-	    REGION_DESTROY( pScreen, borderVisible);
+	    RegionSubtract(exposed, universe, borderVisible);
+	    RegionDestroy(borderVisible);
     	}
     	else
     	{
-	    REGION_SUBTRACT( pScreen, exposed, universe, &pParent->borderClip);
+	    RegionSubtract(exposed, universe, &pParent->borderClip);
     	}
 	if (HasParentRelativeBorder(pParent) && (dx || dy))
-	    REGION_SUBTRACT( pScreen, &pParent->valdata->after.borderExposed,
+	    RegionSubtract(&pParent->valdata->after.borderExposed,
 				  universe,
 				  &pParent->winSize);
 	else
-	    REGION_SUBTRACT( pScreen, &pParent->valdata->after.borderExposed,
+	    RegionSubtract(&pParent->valdata->after.borderExposed,
 			       exposed, &pParent->winSize);
 
-    	REGION_COPY( pScreen, &pParent->borderClip, universe);
+	RegionCopy(&pParent->borderClip, universe);
     
     	/*
      	 * To get the right clipList for the parent, and to make doubly sure
@@ -425,15 +425,15 @@ miComputeClips (
      	 * border from the universe before proceeding.
      	 */
     
-    	REGION_INTERSECT( pScreen, universe, universe, &pParent->winSize);
+	RegionIntersect(universe, universe, &pParent->winSize);
     }
     else
-    	REGION_COPY( pScreen, &pParent->borderClip, universe);
+	RegionCopy(&pParent->borderClip, universe);
     
     if ((pChild = pParent->firstChild) && pParent->mapped)
     {
-	REGION_NULL(pScreen, &childUniverse);
-	REGION_NULL(pScreen, &childUnion);
+	RegionNull(&childUniverse);
+	RegionNull(&childUnion);
 	if ((pChild->drawable.y < pParent->lastChild->drawable.y) ||
 	    ((pChild->drawable.y == pParent->lastChild->drawable.y) &&
 	     (pChild->drawable.x < pParent->lastChild->drawable.x)))
@@ -441,7 +441,7 @@ miComputeClips (
 	    for (; pChild; pChild = pChild->nextSib)
 	    {
 		if (pChild->viewable && !TreatAsTransparent(pChild))
-		    REGION_APPEND( pScreen, &childUnion, &pChild->borderSize);
+		    RegionAppend(&childUnion, &pChild->borderSize);
 	    }
 	}
 	else
@@ -449,10 +449,10 @@ miComputeClips (
 	    for (pChild = pParent->lastChild; pChild; pChild = pChild->prevSib)
 	    {
 		if (pChild->viewable && !TreatAsTransparent(pChild))
-		    REGION_APPEND( pScreen, &childUnion, &pChild->borderSize);
+		    RegionAppend(&childUnion, &pChild->borderSize);
 	    }
 	}
-	REGION_VALIDATE( pScreen, &childUnion, &overlap);
+	RegionValidate(&childUnion, &overlap);
 
 	for (pChild = pParent->firstChild;
 	     pChild;
@@ -469,7 +469,7 @@ miComputeClips (
 		     * Figure out the new universe from the child's
 		     * perspective and recurse.
 		     */
-		    REGION_INTERSECT( pScreen, &childUniverse,
+		    RegionIntersect(&childUniverse,
 					    universe,
 					    &pChild->borderSize);
 		    miComputeClips (pChild, pScreen, &childUniverse, kind,
@@ -481,14 +481,14 @@ miComputeClips (
 		 * other sibling.
 		 */
 		if (overlap && !TreatAsTransparent (pChild))
-		    REGION_SUBTRACT( pScreen, universe, universe,
+		    RegionSubtract(universe, universe,
 					  &pChild->borderSize);
 	    }
 	}
 	if (!overlap)
-	    REGION_SUBTRACT( pScreen, universe, universe, &childUnion);
-	REGION_UNINIT( pScreen, &childUnion);
-	REGION_UNINIT( pScreen, &childUniverse);
+	    RegionSubtract(universe, universe, &childUnion);
+	RegionUninit(&childUnion);
+	RegionUninit(&childUniverse);
     } /* if any children */
 
     /*
@@ -501,12 +501,12 @@ miComputeClips (
     if (oldVis == VisibilityFullyObscured ||
 	oldVis == VisibilityNotViewable)
     {
-	REGION_COPY( pScreen, &pParent->valdata->after.exposed, universe);
+	RegionCopy(&pParent->valdata->after.exposed, universe);
     }
     else if (newVis != VisibilityFullyObscured &&
 	     newVis != VisibilityNotViewable)
     {
-    	REGION_SUBTRACT( pScreen, &pParent->valdata->after.exposed,
+	RegionSubtract(&pParent->valdata->after.exposed,
 			       universe, &pParent->clipList);
     }
 
@@ -520,7 +520,7 @@ miComputeClips (
     }
 
 #ifdef NOTDEF
-    REGION_COPY( pScreen, &pParent->clipList, universe);
+    RegionCopy(&pParent->clipList, universe);
 #endif
 
     pParent->drawable.serialNumber = NEXT_SERIAL_NUMBER;
@@ -616,8 +616,8 @@ miValidateTree (
     if (pChild == NullWindow)
 	pChild = pParent->firstChild;
 
-    REGION_NULL(pScreen, &childClip);
-    REGION_NULL(pScreen, &exposed);
+    RegionNull(&childClip);
+    RegionNull(&exposed);
 
     /*
      * compute the area of the parent window occupied
@@ -625,10 +625,10 @@ miValidateTree (
      * is the area which can be divied up among the marked
      * children in their new configuration.
      */
-    REGION_NULL(pScreen, &totalClip);
+    RegionNull(&totalClip);
     viewvals = 0;
-    if (REGION_BROKEN (pScreen, &pParent->clipList) &&
-	!REGION_BROKEN (pScreen, &pParent->borderClip))
+    if (RegionBroken(&pParent->clipList) &&
+	!RegionBroken(&pParent->borderClip))
     {
 	kind = VTBroken;
 	/*
@@ -636,19 +636,19 @@ miValidateTree (
 	 * assume everything is busted.
 	 */
 	forward = TRUE;
-	REGION_COPY (pScreen, &totalClip, &pParent->borderClip);
-	REGION_INTERSECT (pScreen, &totalClip, &totalClip, &pParent->winSize);
+	RegionCopy(&totalClip, &pParent->borderClip);
+	RegionIntersect(&totalClip, &totalClip, &pParent->winSize);
 	
 	for (pWin = pParent->firstChild; pWin != pChild; pWin = pWin->nextSib)
 	{
 	    if (pWin->viewable && !TreatAsTransparent (pWin))
-		REGION_SUBTRACT (pScreen, &totalClip, &totalClip, &pWin->borderSize);
+		RegionSubtract(&totalClip, &totalClip, &pWin->borderSize);
 	}
 	for (pWin = pChild; pWin; pWin = pWin->nextSib)
 	    if (pWin->valdata && pWin->viewable)
 		viewvals++;
 	
-	REGION_EMPTY (pScreen, &pParent->clipList);
+	RegionEmpty(&pParent->clipList);
     }
     else 
     {
@@ -666,7 +666,7 @@ miValidateTree (
 		    if (pWin->redirectDraw != RedirectDrawNone && miGetRedirectBorderClipProc)
 			pBorderClip = (*miGetRedirectBorderClipProc)(pWin);
 #endif
-		    REGION_APPEND( pScreen, &totalClip, pBorderClip );
+		    RegionAppend(&totalClip, pBorderClip );
 		    if (pWin->viewable)
 			viewvals++;
 		}
@@ -685,7 +685,7 @@ miValidateTree (
 		    if (pWin->redirectDraw != RedirectDrawNone && miGetRedirectBorderClipProc)
 			pBorderClip = (*miGetRedirectBorderClipProc)(pWin);
 #endif
-		    REGION_APPEND( pScreen, &totalClip, pBorderClip );
+		    RegionAppend(&totalClip, pBorderClip );
 		    if (pWin->viewable)
 			viewvals++;
 		}
@@ -694,7 +694,7 @@ miValidateTree (
 		pWin = pWin->prevSib;
 	    }
 	}
-	REGION_VALIDATE( pScreen, &totalClip, &overlap);
+	RegionValidate(&totalClip, &overlap);
     }
 
     /*
@@ -707,7 +707,7 @@ miValidateTree (
     overlap = TRUE;
     if (kind != VTStack)
     {
-	REGION_UNION( pScreen, &totalClip, &totalClip, &pParent->clipList);
+	RegionUnion(&totalClip, &totalClip, &pParent->clipList);
 	if (viewvals > 1)
 	{
 	    /*
@@ -717,12 +717,12 @@ miValidateTree (
 	     * lower than the cost of multiple Subtracts in the
 	     * loop below.
 	     */
-	    REGION_NULL(pScreen, &childUnion);
+	    RegionNull(&childUnion);
 	    if (forward)
 	    {
 		for (pWin = pChild; pWin; pWin = pWin->nextSib)
 		    if (pWin->valdata && pWin->viewable && !TreatAsTransparent (pWin))
-			REGION_APPEND( pScreen, &childUnion,
+			RegionAppend(&childUnion,
 						   &pWin->borderSize);
 	    }
 	    else
@@ -731,16 +731,16 @@ miValidateTree (
 		while (1)
 		{
 		    if (pWin->valdata && pWin->viewable && !TreatAsTransparent (pWin))
-			REGION_APPEND( pScreen, &childUnion,
+			RegionAppend(&childUnion,
 						   &pWin->borderSize);
 		    if (pWin == pChild)
 			break;
 		    pWin = pWin->prevSib;
 		}
 	    }
-	    REGION_VALIDATE(pScreen, &childUnion, &overlap);
+	    RegionValidate(&childUnion, &overlap);
 	    if (overlap)
-		REGION_UNINIT(pScreen, &childUnion);
+		RegionUninit(&childUnion);
 	}
     }
 
@@ -750,13 +750,13 @@ miValidateTree (
     {
 	if (pWin->viewable) {
 	    if (pWin->valdata) {
-		REGION_INTERSECT( pScreen, &childClip,
+		RegionIntersect(&childClip,
 					&totalClip,
  					&pWin->borderSize);
 		miComputeClips (pWin, pScreen, &childClip, kind, &exposed);
 		if (overlap && !TreatAsTransparent (pWin))
 		{
-		    REGION_SUBTRACT( pScreen, &totalClip,
+		    RegionSubtract(&totalClip,
 				       	   &totalClip,
 				       	   &pWin->borderSize);
 		}
@@ -765,24 +765,24 @@ miValidateTree (
 	    }
 	} else {
 	    if (pWin->valdata) {
-		REGION_EMPTY( pScreen, &pWin->clipList);
+		RegionEmpty(&pWin->clipList);
 		if (pScreen->ClipNotify)
 		    (* pScreen->ClipNotify) (pWin, 0, 0);
-		REGION_EMPTY( pScreen, &pWin->borderClip);
+		RegionEmpty(&pWin->borderClip);
 		pWin->valdata = NULL;
 	    }
 	}
     }
 
-    REGION_UNINIT( pScreen, &childClip);
+    RegionUninit(&childClip);
     if (!overlap)
     {
-	REGION_SUBTRACT(pScreen, &totalClip, &totalClip, &childUnion);
-	REGION_UNINIT(pScreen, &childUnion);
+	RegionSubtract(&totalClip, &totalClip, &childUnion);
+	RegionUninit(&childUnion);
     }
 
-    REGION_NULL(pScreen, &pParent->valdata->after.exposed);
-    REGION_NULL(pScreen, &pParent->valdata->after.borderExposed);
+    RegionNull(&pParent->valdata->after.exposed);
+    RegionNull(&pParent->valdata->after.borderExposed);
 
     /*
      * each case below is responsible for updating the
@@ -798,17 +798,17 @@ miValidateTree (
 	 * exposures and obscures as per miComputeClips and reset the parent's
 	 * clipList.
 	 */
-	REGION_SUBTRACT( pScreen, &pParent->valdata->after.exposed,
+	RegionSubtract(&pParent->valdata->after.exposed,
 			       &totalClip, &pParent->clipList);
 	/* fall through */
     case VTMap:
-	REGION_COPY( pScreen, &pParent->clipList, &totalClip);
+	RegionCopy(&pParent->clipList, &totalClip);
 	pParent->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	break;
     }
 
-    REGION_UNINIT( pScreen, &totalClip);
-    REGION_UNINIT( pScreen, &exposed);
+    RegionUninit(&totalClip);
+    RegionUninit(&exposed);
     if (pScreen->ClipNotify)
 	(*pScreen->ClipNotify) (pParent, 0, 0);
     return (1);
diff --git a/mi/miwindow.c b/mi/miwindow.c
index ce35974..02b4074 100644
--- a/mi/miwindow.c
+++ b/mi/miwindow.c
@@ -112,16 +112,16 @@ miClearToBackground(WindowPtr pWin,
     box.y2 = y2;
 
     pScreen = pWin->drawable.pScreen;
-    REGION_INIT(pScreen, &reg, &box, 1);
+    RegionInit(&reg, &box, 1);
 
-    REGION_INTERSECT(pScreen, &reg, &reg, &pWin->clipList);
+    RegionIntersect(&reg, &reg, &pWin->clipList);
     if (generateExposures)
 	(*pScreen->WindowExposures)(pWin, &reg, pBSReg);
     else if (pWin->backgroundState != None)
 	miPaintWindow(pWin, &reg, PW_BACKGROUND);
-    REGION_UNINIT(pScreen, &reg);
+    RegionUninit(&reg);
     if (pBSReg)
-	REGION_DESTROY(pScreen, pBSReg);
+	RegionDestroy(pBSReg);
 }
 
 void
@@ -164,9 +164,9 @@ miMarkOverlappedWindows(WindowPtr pWin, WindowPtr pFirst, WindowPtr *ppLayerWin)
 	{
 	    if (pChild->viewable)
 	    {
-		if (REGION_BROKEN (pScreen, &pChild->winSize))
+		if (RegionBroken(&pChild->winSize))
 		    SetWinSize (pChild);
-		if (REGION_BROKEN (pScreen, &pChild->borderSize))
+		if (RegionBroken(&pChild->borderSize))
 		    SetBorderSize (pChild);
 		(* MarkWindow)(pChild);
 		if (pChild->firstChild)
@@ -186,17 +186,17 @@ miMarkOverlappedWindows(WindowPtr pWin, WindowPtr pFirst, WindowPtr *ppLayerWin)
     }
     if ( (pChild = pFirst) )
     {
-	box = REGION_EXTENTS(pChild->drawable.pScreen, &pWin->borderSize);
+	box = RegionExtents(&pWin->borderSize);
 	pLast = pChild->parent->lastChild;
 	while (1)
 	{
 	    if (pChild->viewable)
 	    {
-		if (REGION_BROKEN (pScreen, &pChild->winSize))
+		if (RegionBroken(&pChild->winSize))
 		    SetWinSize (pChild);
-		if (REGION_BROKEN (pScreen, &pChild->borderSize))
+		if (RegionBroken(&pChild->borderSize))
 		    SetBorderSize (pChild);
-		if (RECT_IN_REGION(pScreen, &pChild->borderSize, box))
+		if (RegionContainsRect(&pChild->borderSize, box))
 		{
 		    (* MarkWindow)(pChild);
 		    anyMarked = TRUE;
@@ -241,11 +241,11 @@ miHandleValidateExposures(WindowPtr pWin)
     {
 	if ( (val = pChild->valdata) )
 	{
-	    if (REGION_NOTEMPTY(pScreen, &val->after.borderExposed))
+	    if (RegionNotEmpty(&val->after.borderExposed))
 		miPaintWindow(pChild, &val->after.borderExposed, PW_BORDER);
-	    REGION_UNINIT(pScreen, &val->after.borderExposed);
+	    RegionUninit(&val->after.borderExposed);
 	    (*WindowExposures)(pChild, &val->after.exposed, NullRegion);
-	    REGION_UNINIT(pScreen, &val->after.exposed);
+	    RegionUninit(&val->after.exposed);
 	    free(val);
 	    pChild->valdata = NULL;
 	    if (pChild->firstChild)
@@ -285,8 +285,8 @@ miMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pNextSib, VTKind kind)
     oldpt.y = pWin->drawable.y;
     if (WasViewable)
     {
-	oldRegion = REGION_CREATE(pScreen, NullBox, 1);
-	REGION_COPY(pScreen, oldRegion, &pWin->borderClip);
+	oldRegion = RegionCreate(NullBox, 1);
+	RegionCopy(oldRegion, &pWin->borderClip);
 	anyMarked = (*pScreen->MarkOverlappedWindows)(pWin, pWin, &pLayerWin);
     }
     pWin->origin.x = x + (int)bw;
@@ -317,7 +317,7 @@ miMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pNextSib, VTKind kind)
 	{
 	    (*pScreen->ValidateTree)(pLayerWin->parent, NullWindow, kind);
 	    (* pWin->drawable.pScreen->CopyWindow)(pWin, oldpt, oldRegion);
-	    REGION_DESTROY(pScreen, oldRegion);
+	    RegionDestroy(oldRegion);
 	    /* XXX need to retile border if ParentRelative origin */
 	    (*pScreen->HandleExposures)(pLayerWin->parent);
 	}
@@ -357,14 +357,14 @@ miRecomputeExposures (
 	/*
 	 * compute exposed regions of this window
 	 */
-	REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed,
+	RegionSubtract(&pWin->valdata->after.exposed,
 			&pWin->clipList, pValid);
 	/*
 	 * compute exposed regions of the border
 	 */
-	REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed,
+	RegionSubtract(&pWin->valdata->after.borderExposed,
 			     &pWin->borderClip, &pWin->winSize);
-	REGION_SUBTRACT(pScreen, &pWin->valdata->after.borderExposed,
+	RegionSubtract(&pWin->valdata->after.borderExposed,
 			     &pWin->valdata->after.borderExposed, pValid);
 	return WT_WALKCHILDREN;
     }
@@ -416,8 +416,8 @@ miSlideAndSizeWindow(WindowPtr pWin,
 	/*
 	 * save the visible region of the window
 	 */
-	oldRegion = REGION_CREATE(pScreen, NullBox, 1);
-	REGION_COPY(pScreen, oldRegion, &pWin->winSize);
+	oldRegion = RegionCreate(NullBox, 1);
+	RegionCopy(oldRegion, &pWin->winSize);
 
 	/*
 	 * categorize child windows into regions to be moved
@@ -430,8 +430,8 @@ miSlideAndSizeWindow(WindowPtr pWin,
 	    if (g != UnmapGravity)
 	    {
 		if (!gravitate[g])
-		    gravitate[g] = REGION_CREATE(pScreen, NullBox, 1);
-		REGION_UNION(pScreen, gravitate[g],
+		    gravitate[g] = RegionCreate(NullBox, 1);
+		RegionUnion(gravitate[g],
 				   gravitate[g], &pChild->borderClip);
 	    }
 	    else
@@ -446,8 +446,8 @@ miSlideAndSizeWindow(WindowPtr pWin,
 	oldWinClip = NULL;
 	if (pWin->bitGravity != ForgetGravity)
 	{
-	    oldWinClip = REGION_CREATE(pScreen, NullBox, 1);
-	    REGION_COPY(pScreen, oldWinClip, &pWin->clipList);
+	    oldWinClip = RegionCreate(NullBox, 1);
+	    RegionCopy(oldWinClip, &pWin->clipList);
 	}
 	/*
 	 * if the window is changing size, borderExposed
@@ -462,16 +462,16 @@ miSlideAndSizeWindow(WindowPtr pWin,
 	if ((pWin->drawable.height != h || pWin->drawable.width != w) &&
 	    HasBorder (pWin))
 	{
-	    borderVisible = REGION_CREATE(pScreen, NullBox, 1);
+	    borderVisible = RegionCreate(NullBox, 1);
 	    /* for tiled borders, we punt and draw the whole thing */
 	    if (pWin->borderIsPixel || !moved)
 	    {
 		if (shrunk || moved)
-		    REGION_SUBTRACT(pScreen, borderVisible,
+		    RegionSubtract(borderVisible,
 					  &pWin->borderClip,
 					  &pWin->winSize);
 		else
-		    REGION_COPY(pScreen, borderVisible,
+		    RegionCopy(borderVisible,
 					    &pWin->borderClip);
 	    }
 	}
@@ -498,7 +498,7 @@ miSlideAndSizeWindow(WindowPtr pWin,
 
     if (WasViewable)
     {
-	pRegion = REGION_CREATE(pScreen, NullBox, 1);
+	pRegion = RegionCreate(NullBox, 1);
 
 	if (pLayerWin == pWin)
 	    anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin, pFirstChange,
@@ -520,7 +520,7 @@ miSlideAndSizeWindow(WindowPtr pWin,
 	 * the entire window is trashed unless bitGravity
 	 * recovers portions of it
 	 */
-	REGION_COPY(pScreen, &pWin->valdata->after.exposed, &pWin->clipList);
+	RegionCopy(&pWin->valdata->after.exposed, &pWin->clipList);
     }
 
     GravityTranslate (x, y, oldx, oldy, dw, dh, pWin->bitGravity, &nx, &ny);
@@ -549,16 +549,16 @@ miSlideAndSizeWindow(WindowPtr pWin,
 		dy = (oldy - ny) - offy;
 		if (dx || dy)
 		{
-		    REGION_TRANSLATE(pScreen, &pWin->winSize, dx, dy);
+		    RegionTranslate(&pWin->winSize, dx, dy);
 		    offx += dx;
 		    offy += dy;
 		}
-		REGION_INTERSECT(pScreen, gravitate[g], gravitate[g],
+		RegionIntersect(gravitate[g], gravitate[g],
 				 &pWin->winSize);
 	    }
 	    /* get winSize back where it belongs */
 	    if (offx || offy)
-		REGION_TRANSLATE(pScreen, &pWin->winSize, -offx, -offy);
+		RegionTranslate(&pWin->winSize, -offx, -offy);
 	}
 	/*
 	 * add screen bits to the appropriate bucket
@@ -569,9 +569,9 @@ miSlideAndSizeWindow(WindowPtr pWin,
 	    /*
 	     * clip to new clipList
 	     */
-	    REGION_COPY(pScreen, pRegion, oldWinClip);
-	    REGION_TRANSLATE(pScreen, pRegion, nx - oldx, ny - oldy);
-	    REGION_INTERSECT(pScreen, oldWinClip, pRegion, &pWin->clipList);
+	    RegionCopy(pRegion, oldWinClip);
+	    RegionTranslate(pRegion, nx - oldx, ny - oldy);
+	    RegionIntersect(oldWinClip, pRegion, &pWin->clipList);
 	    /*
 	     * don't step on any gravity bits which will be copied after this
 	     * region.	Note -- this assumes that the regions will be copied
@@ -580,17 +580,17 @@ miSlideAndSizeWindow(WindowPtr pWin,
 	    for (g = pWin->bitGravity + 1; g <= StaticGravity; g++)
 	    {
 		if (gravitate[g])
-		    REGION_SUBTRACT(pScreen, oldWinClip, oldWinClip,
+		    RegionSubtract(oldWinClip, oldWinClip,
 					gravitate[g]);
 	    }
-	    REGION_TRANSLATE(pScreen, oldWinClip, oldx - nx, oldy - ny);
+	    RegionTranslate(oldWinClip, oldx - nx, oldy - ny);
 	    g = pWin->bitGravity;
 	    if (!gravitate[g])
 		gravitate[g] = oldWinClip;
 	    else
 	    {
-		REGION_UNION(pScreen, gravitate[g], gravitate[g], oldWinClip);
-		REGION_DESTROY(pScreen, oldWinClip);
+		RegionUnion(gravitate[g], gravitate[g], oldWinClip);
+		RegionDestroy(oldWinClip);
 	    }
 	}
 
@@ -614,14 +614,14 @@ miSlideAndSizeWindow(WindowPtr pWin,
 
 	    /* only copy the remaining useful bits */
 
-	    REGION_INTERSECT(pScreen, gravitate[g], gravitate[g], oldRegion);
+	    RegionIntersect(gravitate[g], gravitate[g], oldRegion);
 
 	    /* clip to not overwrite already copied areas */
 
 	    if (destClip) {
-		REGION_TRANSLATE(pScreen, destClip, oldpt.x - x, oldpt.y - y);
-		REGION_SUBTRACT(pScreen, gravitate[g], gravitate[g], destClip);
-		REGION_TRANSLATE(pScreen, destClip, x - oldpt.x, y - oldpt.y);
+		RegionTranslate(destClip, oldpt.x - x, oldpt.y - y);
+		RegionSubtract(gravitate[g], gravitate[g], destClip);
+		RegionTranslate(destClip, x - oldpt.x, y - oldpt.y);
 	    }
 
 	    /* and move those bits */
@@ -637,7 +637,7 @@ miSlideAndSizeWindow(WindowPtr pWin,
 
 	    /* remove any overwritten bits from the remaining useful bits */
 
-	    REGION_SUBTRACT(pScreen, oldRegion, oldRegion, gravitate[g]);
+	    RegionSubtract(oldRegion, oldRegion, gravitate[g]);
 
 	    /*
 	     * recompute exposed regions of child windows
@@ -647,7 +647,7 @@ miSlideAndSizeWindow(WindowPtr pWin,
 	    {
 		if (pChild->winGravity != g)
 		    continue;
-		REGION_INTERSECT(pScreen, pRegion,
+		RegionIntersect(pRegion,
 				       &pChild->borderClip, gravitate[g]);
 		TraverseTree (pChild, miRecomputeExposures, (pointer)pRegion);
 	    }
@@ -658,21 +658,21 @@ miSlideAndSizeWindow(WindowPtr pWin,
 	     */
 
 	    if (g == pWin->bitGravity)
-		REGION_SUBTRACT(pScreen, &pWin->valdata->after.exposed,
+		RegionSubtract(&pWin->valdata->after.exposed,
 				     &pWin->valdata->after.exposed, gravitate[g]);
 	    if (!destClip)
 		destClip = gravitate[g];
 	    else
 	    {
-		REGION_UNION(pScreen, destClip, destClip, gravitate[g]);
-		REGION_DESTROY(pScreen, gravitate[g]);
+		RegionUnion(destClip, destClip, gravitate[g]);
+		RegionDestroy(gravitate[g]);
 	    }
 	}
 
-	REGION_DESTROY(pScreen, oldRegion);
-	REGION_DESTROY(pScreen, pRegion);
+	RegionDestroy(oldRegion);
+	RegionDestroy(pRegion);
 	if (destClip)
-	    REGION_DESTROY(pScreen, destClip);
+	    RegionDestroy(destClip);
 	if (anyMarked)
 	    (*pScreen->HandleExposures)(pLayerWin->parent);
 	if (anyMarked && pScreen->PostValidateTree)
@@ -715,8 +715,8 @@ miSetShape(WindowPtr pWin, int kind)
                 {
                     RegionPtr borderVisible;
 
-                    borderVisible = REGION_CREATE(pScreen, NullBox, 1);
-                    REGION_SUBTRACT(pScreen, borderVisible,
+                    borderVisible = RegionCreate(NullBox, 1);
+                    RegionSubtract(borderVisible,
                                     &pWin->borderClip, &pWin->winSize);
                     pWin->valdata->before.borderVisible = borderVisible;
                 }
@@ -789,8 +789,8 @@ miChangeBorderWidth(WindowPtr pWin, unsigned int width)
 	    if (pWin->valdata && HadBorder)
 	    {
 		RegionPtr   borderVisible;
-		borderVisible = REGION_CREATE(pScreen, NULL, 1);
-		REGION_SUBTRACT(pScreen, borderVisible,
+		borderVisible = RegionCreate(NULL, 1);
+		RegionSubtract(borderVisible,
 				      &pWin->borderClip, &pWin->winSize);
 		pWin->valdata->before.borderVisible = borderVisible;
 	    }
@@ -814,10 +814,10 @@ miMarkUnrealizedWindow(WindowPtr pChild, WindowPtr pWin, Bool fromConfigure)
 {
     if ((pChild != pWin) || fromConfigure)
     {
-	REGION_EMPTY(pChild->drawable.pScreen, &pChild->clipList);
+	RegionEmpty(&pChild->clipList);
 	if (pChild->drawable.pScreen->ClipNotify)
 	    (* pChild->drawable.pScreen->ClipNotify)(pChild, 0, 0);
-	REGION_EMPTY(pChild->drawable.pScreen, &pChild->borderClip);
+	RegionEmpty(&pChild->borderClip);
     }
 }
 
@@ -832,7 +832,7 @@ miSegregateChildren(WindowPtr pWin, RegionPtr pReg, int depth)
     for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
     {
 	if (pChild->drawable.depth == depth)
-	    REGION_UNION(pScreen, pReg, pReg, &pChild->borderClip);
+	    RegionUnion(pReg, pReg, &pChild->borderClip);
 
 	if (pChild->firstChild)
 	    miSegregateChildren(pChild, pReg, depth);
diff --git a/miext/cw/cw.c b/miext/cw/cw.c
index 2d8fd12..563831a 100644
--- a/miext/cw/cw.c
+++ b/miext/cw/cw.c
@@ -191,8 +191,8 @@ cwValidateGC(GCPtr pGC, unsigned long stateChanges, DrawablePtr pDrawable)
 	ChangeGCVal vals[2];
 	RegionPtr   pCompositeClip;
 
-	pCompositeClip = REGION_CREATE (pScreen, NULL, 0);
-	REGION_COPY (pScreen, pCompositeClip, pGC->pCompositeClip);
+	pCompositeClip = RegionCreate(NULL, 0);
+	RegionCopy(pCompositeClip, pGC->pCompositeClip);
 
 	/* Either the drawable has changed, or the clip list in the drawable has
 	 * changed.  Copy the new clip list over and set the new translated
@@ -403,7 +403,7 @@ cwCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 	dx = ptOldOrg.x - pWin->drawable.x;
 	dy = ptOldOrg.y - pWin->drawable.y;
 
-	pExtents = REGION_EXTENTS(pScreen, prgnSrc);
+	pExtents = RegionExtents(prgnSrc);
 
 	pBackingPixmap = (PixmapPtr) cwGetBackingDrawable((DrawablePtr)pWin,
 							  &x_off, &y_off);
@@ -416,15 +416,15 @@ cwCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 	dst_y = src_y - dy;
 			       
 	/* Translate region (as required by API) */
-	REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy);
+	RegionTranslate(prgnSrc, -dx, -dy);
 	
 	pGC = GetScratchGC(pBackingPixmap->drawable.depth, pScreen);
 	/*
 	 * Copy region to GC as clip, aligning as dest clip
 	 */
-	pClip = REGION_CREATE (pScreen, NULL, 0);
-	REGION_INTERSECT(pScreen, pClip, &pWin->borderClip, prgnSrc);
-	REGION_TRANSLATE(pScreen, pClip, 
+	pClip = RegionCreate(NULL, 0);
+	RegionIntersect(pClip, &pWin->borderClip, prgnSrc);
+	RegionTranslate(pClip,
 			 -pBackingPixmap->screen_x,
 			 -pBackingPixmap->screen_y);
 	
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index 551cb72..935b1c0 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -129,40 +129,40 @@ damageReportDamage (DamagePtr pDamage, RegionPtr pDamageRegion)
 
     switch (pDamage->damageLevel) {
     case DamageReportRawRegion:
-	REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage,
+	RegionUnion(&pDamage->damage, &pDamage->damage,
 			 pDamageRegion);
 	(*pDamage->damageReport) (pDamage, pDamageRegion, pDamage->closure);
 	break;
     case DamageReportDeltaRegion:
-	REGION_NULL (pScreen, &tmpRegion);
-	REGION_SUBTRACT (pScreen, &tmpRegion, pDamageRegion, &pDamage->damage);
-	if (REGION_NOTEMPTY (pScreen, &tmpRegion)) {
-	    REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage,
+	RegionNull(&tmpRegion);
+	RegionSubtract(&tmpRegion, pDamageRegion, &pDamage->damage);
+	if (RegionNotEmpty(&tmpRegion)) {
+	    RegionUnion(&pDamage->damage, &pDamage->damage,
 			 pDamageRegion);
 	    (*pDamage->damageReport) (pDamage, &tmpRegion, pDamage->closure);
 	}
-	REGION_UNINIT(pScreen, &tmpRegion);
+	RegionUninit(&tmpRegion);
 	break;
     case DamageReportBoundingBox:
-	tmpBox = *REGION_EXTENTS (pScreen, &pDamage->damage);
-	REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage,
+	tmpBox = *RegionExtents(&pDamage->damage);
+	RegionUnion(&pDamage->damage, &pDamage->damage,
 		     pDamageRegion);
-	if (!BOX_SAME (&tmpBox, REGION_EXTENTS (pScreen, &pDamage->damage))) {
+	if (!BOX_SAME (&tmpBox, RegionExtents(&pDamage->damage))) {
 	    (*pDamage->damageReport) (pDamage, &pDamage->damage,
 				      pDamage->closure);
 	}
 	break;
     case DamageReportNonEmpty:
-	was_empty = !REGION_NOTEMPTY(pScreen, &pDamage->damage);
-	REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage,
+	was_empty = !RegionNotEmpty(&pDamage->damage);
+	RegionUnion(&pDamage->damage, &pDamage->damage,
 		     pDamageRegion);
-	if (was_empty && REGION_NOTEMPTY(pScreen, &pDamage->damage)) {
+	if (was_empty && RegionNotEmpty(&pDamage->damage)) {
 	    (*pDamage->damageReport) (pDamage, &pDamage->damage,
 				      pDamage->closure);
 	}
 	break;
     case DamageReportNone:
-	REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage,
+	RegionUnion(&pDamage->damage, &pDamage->damage,
 		     pDamageRegion);
 	break;
     }
@@ -175,30 +175,30 @@ damageReportDamagePostRendering (DamagePtr pDamage, RegionPtr pOldDamage, Region
     RegionRec tmpRegion, newDamage;
     Bool was_empty;
 
-    REGION_UNION(pScreem, &newDamage, pOldDamage, pDamageRegion);
+    RegionUnion(&newDamage, pOldDamage, pDamageRegion);
 
     switch (pDamage->damageLevel) {
     case DamageReportRawRegion:
 	(*pDamage->damageReportPostRendering) (pDamage, pDamageRegion, pDamage->closure);
 	break;
     case DamageReportDeltaRegion:
-	REGION_NULL (pScreen, &tmpRegion);
-	REGION_SUBTRACT (pScreen, &tmpRegion, pDamageRegion, pOldDamage);
-	if (REGION_NOTEMPTY (pScreen, &tmpRegion)) {
+	RegionNull(&tmpRegion);
+	RegionSubtract(&tmpRegion, pDamageRegion, pOldDamage);
+	if (RegionNotEmpty(&tmpRegion)) {
 	    (*pDamage->damageReportPostRendering) (pDamage, &tmpRegion, pDamage->closure);
 	}
-	REGION_UNINIT(pScreen, &tmpRegion);
+	RegionUninit(&tmpRegion);
 	break;
     case DamageReportBoundingBox:
-	tmpBox = *REGION_EXTENTS (pScreen, pOldDamage);
-	if (!BOX_SAME (&tmpBox, REGION_EXTENTS (pScreen, &newDamage))) {
+	tmpBox = *RegionExtents(pOldDamage);
+	if (!BOX_SAME (&tmpBox, RegionExtents(&newDamage))) {
 	    (*pDamage->damageReportPostRendering) (pDamage, &newDamage,
 				      pDamage->closure);
 	}
 	break;
     case DamageReportNonEmpty:
-	was_empty = !REGION_NOTEMPTY(pScreen, pOldDamage);
-	if (was_empty && REGION_NOTEMPTY(pScreen, &newDamage)) {
+	was_empty = !RegionNotEmpty(pOldDamage);
+	if (was_empty && RegionNotEmpty(&newDamage)) {
 	    (*pDamage->damageReportPostRendering) (pDamage, &newDamage,
 				      pDamage->closure);
 	}
@@ -207,7 +207,7 @@ damageReportDamagePostRendering (DamagePtr pDamage, RegionPtr pOldDamage, Region
 	break;
     }
 
-    REGION_UNINIT(pScreen, &newDamage);
+    RegionUninit(&newDamage);
 }
 
 #if DAMAGE_DEBUG_ENABLE
@@ -233,7 +233,7 @@ damageRegionAppend (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
 #endif
 
     /* short circuit for empty regions */
-    if (!REGION_NOTEMPTY(pScreen, pRegion))
+    if (!RegionNotEmpty(pRegion))
 	return;
     
 #ifdef COMPOSITE
@@ -248,7 +248,7 @@ damageRegionAppend (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
 	screen_y = ((PixmapPtr) pDrawable)->screen_y - pDrawable->y;
     }
     if (screen_x || screen_y)
-        REGION_TRANSLATE (pScreen, pRegion, screen_x, screen_y);
+        RegionTranslate(pRegion, screen_x, screen_y);
 #endif
 	
     if (pDrawable->type == DRAWABLE_WINDOW &&
@@ -256,22 +256,22 @@ damageRegionAppend (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
     {
 	if (subWindowMode == ClipByChildren)
 	{
-	    REGION_INTERSECT(pScreen, pRegion, pRegion,
+	    RegionIntersect(pRegion, pRegion,
 			     &((WindowPtr)(pDrawable))->clipList);
 	}
 	else if (subWindowMode == IncludeInferiors)
 	{
 	    RegionPtr pTempRegion =
 		NotClippedByChildren((WindowPtr)(pDrawable));
-	    REGION_INTERSECT(pScreen, pRegion, pRegion, pTempRegion);
-	    REGION_DESTROY(pScreen, pTempRegion);
+	    RegionIntersect(pRegion, pRegion, pTempRegion);
+	    RegionDestroy(pTempRegion);
 	}
 	/* If subWindowMode is set to an invalid value, don't perform
 	 * any drawable-based clipping. */
     }
         
 
-    REGION_NULL (pScreen, &clippedRec);
+    RegionNull(&clippedRec);
     for (; pDamage; pDamage = pNext)
     {
 	pNext = pDamage->pNext;
@@ -316,7 +316,7 @@ damageRegionAppend (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
 	{
 	    pDamageRegion = &clippedRec;
 	    if (pDamage->pDrawable->type == DRAWABLE_WINDOW) {
-		REGION_INTERSECT (pScreen, pDamageRegion, pRegion,
+		RegionIntersect(pDamageRegion, pRegion,
 		    &((WindowPtr)(pDamage->pDrawable))->borderClip);
 	    } else {
 		BoxRec	box;
@@ -324,14 +324,14 @@ damageRegionAppend (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
 		box.y1 = draw_y;
 		box.x2 = draw_x + pDamage->pDrawable->width;
 		box.y2 = draw_y + pDamage->pDrawable->height;
-		REGION_INIT(pScreen, &pixClip, &box, 1);
-		REGION_INTERSECT (pScreen, pDamageRegion, pRegion, &pixClip);
-		REGION_UNINIT(pScreen, &pixClip);
+		RegionInit(&pixClip, &box, 1);
+		RegionIntersect(pDamageRegion, pRegion, &pixClip);
+		RegionUninit(&pixClip);
 	    }
 	    /*
 	     * Short circuit empty results
 	     */
-	    if (!REGION_NOTEMPTY(pScreen, pDamageRegion))
+	    if (!RegionNotEmpty(pDamageRegion))
 		continue;
 	}
 	
@@ -346,23 +346,23 @@ damageRegionAppend (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
 	 * Move region to target coordinate space
 	 */
 	if (draw_x || draw_y)
-	    REGION_TRANSLATE (pScreen, pDamageRegion, -draw_x, -draw_y);
+	    RegionTranslate(pDamageRegion, -draw_x, -draw_y);
 
 	/* Store damage region if needed after submission. */
 	if (pDamage->reportAfter || pDamage->damageMarker)
-	    REGION_UNION(pScreen, &pDamage->pendingDamage,
+	    RegionUnion(&pDamage->pendingDamage,
 			 &pDamage->pendingDamage, pDamageRegion);
 
 	/* Duplicate current damage if needed. */
 	if (pDamage->damageMarker)
-	    REGION_COPY(pScreen, &pDamage->backupDamage, &pDamage->damage);
+	    RegionCopy(&pDamage->backupDamage, &pDamage->damage);
 
 	/* Report damage now, if desired. */
 	if (!pDamage->reportAfter) {
 	    if (pDamage->damageReport)
 		damageReportDamage (pDamage, pDamageRegion);
 	    else
-		REGION_UNION(pScreen, &pDamage->damage,
+		RegionUnion(&pDamage->damage,
 			 &pDamage->damage, pDamageRegion);
 	}
 
@@ -370,14 +370,14 @@ damageRegionAppend (DrawablePtr pDrawable, RegionPtr pRegion, Bool clip,
 	 * translate original region back
 	 */
 	if (pDamageRegion == pRegion && (draw_x || draw_y))
-	    REGION_TRANSLATE (pScreen, pDamageRegion, draw_x, draw_y);
+	    RegionTranslate(pDamageRegion, draw_x, draw_y);
     }
 #ifdef COMPOSITE
     if (screen_x || screen_y)
-	REGION_TRANSLATE (pScreen, pRegion, -screen_x, -screen_y);
+	RegionTranslate(pRegion, -screen_x, -screen_y);
 #endif
     
-    REGION_UNINIT (pScreen, &clippedRec);
+    RegionUninit(&clippedRec);
 }
 
 static void
@@ -395,14 +395,14 @@ damageRegionProcessPending (DrawablePtr pDrawable)
 	    if (pDamage->damageReport)
 		damageReportDamage (pDamage, &pDamage->pendingDamage);
 	    else
-		REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage,
+		RegionUnion(&pDamage->damage, &pDamage->damage,
 			&pDamage->pendingDamage);
 	}
 
 	if (pDamage->reportAfter || pDamage->damageMarker)
-	    REGION_EMPTY (pScreen, &pDamage->pendingDamage);
+	    RegionEmpty(&pDamage->pendingDamage);
 	if (pDamage->damageMarker)
-	    REGION_EMPTY (pScreen, &pDamage->backupDamage);
+	    RegionEmpty(&pDamage->backupDamage);
     }
     
 }
@@ -418,13 +418,13 @@ damageDamageBox (DrawablePtr pDrawable, BoxPtr pBox, int subWindowMode)
 {
     RegionRec	region;
 
-    REGION_INIT (pDrawable->pScreen, &region, pBox, 1);
+    RegionInit(&region, pBox, 1);
 #if DAMAGE_DEBUG_ENABLE
     _damageRegionAppend (pDrawable, &region, TRUE, subWindowMode, where);
 #else
     damageRegionAppend (pDrawable, &region, TRUE, subWindowMode);
 #endif
-    REGION_UNINIT (pDrawable->pScreen, &region);
+    RegionUninit(&region);
 }
 
 static void damageValidateGC(GCPtr, unsigned long, DrawablePtr);
@@ -593,7 +593,7 @@ damageDestroyClip(GCPtr pGC)
 
 #define checkGCDamage(d,g)	(getDrawableDamage(d) && \
 				 (!g->pCompositeClip ||\
-				  REGION_NOTEMPTY(d->pScreen, \
+				  RegionNotEmpty(\
 						  g->pCompositeClip)))
 
 #define TRIM_PICTURE_BOX(box, pDst) { \
@@ -605,7 +605,7 @@ damageDestroyClip(GCPtr pGC)
     }
     
 #define checkPictureDamage(p)	(getDrawableDamage(p->pDrawable) && \
-				 REGION_NOTEMPTY(pScreen, p->pCompositeClip))
+				 RegionNotEmpty(p->pCompositeClip))
 
 static void
 damageComposite (CARD8      op,
@@ -1763,9 +1763,9 @@ damageCopyWindow(WindowPtr	pWindow,
 	 * The region comes in source relative, but the damage occurs
 	 * at the destination location.  Translate back and forth.
 	 */
-	REGION_TRANSLATE (pScreen, prgnSrc, dx, dy);
+	RegionTranslate(prgnSrc, dx, dy);
 	damageRegionAppend (&pWindow->drawable, prgnSrc, FALSE, -1);
-	REGION_TRANSLATE (pScreen, prgnSrc, -dx, -dy);
+	RegionTranslate(prgnSrc, -dx, -dy);
     }
     unwrap (pScrPriv, pScreen, CopyWindow);
     (*pScreen->CopyWindow) (pWindow, ptOldOrg, prgnSrc);
@@ -1931,8 +1931,8 @@ DamageCreate (DamageReportFunc  damageReport,
 	return 0;
     pDamage->pNext = 0;
     pDamage->pNextWin = 0;
-    REGION_NULL(pScreen, &pDamage->damage);
-    REGION_NULL(pScreen, &pDamage->pendingDamage);
+    RegionNull(&pDamage->damage);
+    RegionNull(&pDamage->pendingDamage);
     
     pDamage->damageLevel = damageLevel;
     pDamage->isInternal = isInternal;
@@ -2052,8 +2052,8 @@ DamageDestroy (DamagePtr    pDamage)
     (*pScrPriv->funcs.Destroy) (pDamage);
     dixFreePrivates(pDamage->devPrivates);
     pDamage->devPrivates = NULL;
-    REGION_UNINIT (pScreen, &pDamage->damage);
-    REGION_UNINIT (pScreen, &pDamage->pendingDamage);
+    RegionUninit(&pDamage->damage);
+    RegionUninit(&pDamage->pendingDamage);
     free(pDamage);
 }
 
@@ -2065,7 +2065,7 @@ DamageSubtract (DamagePtr	    pDamage,
     RegionRec	pixmapClip;
     DrawablePtr	pDrawable = pDamage->pDrawable;
     
-    REGION_SUBTRACT (pDrawable->pScreen, &pDamage->damage, &pDamage->damage, pRegion);
+    RegionSubtract(&pDamage->damage, &pDamage->damage, pRegion);
     if (pDrawable)
     {
 	if (pDrawable->type == DRAWABLE_WINDOW)
@@ -2078,22 +2078,22 @@ DamageSubtract (DamagePtr	    pDamage,
 	    box.y1 = pDrawable->y;
 	    box.x2 = pDrawable->x + pDrawable->width;
 	    box.y2 = pDrawable->y + pDrawable->height;
-	    REGION_INIT (pDrawable->pScreen, &pixmapClip, &box, 1);
+	    RegionInit(&pixmapClip, &box, 1);
 	    pClip = &pixmapClip;
 	}
-	REGION_TRANSLATE (pDrawable->pScreen, &pDamage->damage, pDrawable->x, pDrawable->y);
-	REGION_INTERSECT (pDrawable->pScreen, &pDamage->damage, &pDamage->damage, pClip);
-	REGION_TRANSLATE (pDrawable->pScreen, &pDamage->damage, -pDrawable->x, -pDrawable->y);
+	RegionTranslate(&pDamage->damage, pDrawable->x, pDrawable->y);
+	RegionIntersect(&pDamage->damage, &pDamage->damage, pClip);
+	RegionTranslate(&pDamage->damage, -pDrawable->x, -pDrawable->y);
 	if (pDrawable->type != DRAWABLE_WINDOW)
-	    REGION_UNINIT(pDrawable->pScreen, &pixmapClip);
+	    RegionUninit(&pixmapClip);
     }
-    return REGION_NOTEMPTY (pDrawable->pScreen, &pDamage->damage);
+    return RegionNotEmpty(&pDamage->damage);
 }
 
 void
 DamageEmpty (DamagePtr	    pDamage)
 {
-    REGION_EMPTY (pDamage->pDrawable->pScreen, &pDamage->damage);
+    RegionEmpty(&pDamage->damage);
 }
 
 RegionPtr
diff --git a/miext/rootless/rootlessCommon.c b/miext/rootless/rootlessCommon.c
index dd3f953..4fb0e49 100644
--- a/miext/rootless/rootlessCommon.c
+++ b/miext/rootless/rootlessCommon.c
@@ -286,30 +286,30 @@ RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion)
        drawing inside the clip, go to some lengths to avoid the general
        case intersection. */
 
-    b1 = REGION_EXTENTS(pScreen, &pWindow->borderClip);
-    b2 = REGION_EXTENTS(pScreen, pRegion);
+    b1 = RegionExtents(&pWindow->borderClip);
+    b2 = RegionExtents(pRegion);
 
     if (EXTENTCHECK(b1, b2)) {
         /* Regions may overlap. */
 
-        if (REGION_NUM_RECTS(pRegion) == 1) {
+        if (RegionNumRects(pRegion) == 1) {
             int in;
 
             /* Damaged region only has a single rect, so we can
                just compare that against the region */
 
-            in = RECT_IN_REGION(pScreen, &pWindow->borderClip,
-                                REGION_RECTS (pRegion));
+            in = RegionContainsRect(&pWindow->borderClip,
+                                RegionRects (pRegion));
             if (in == rgnIN) {
             /* clip totally contains pRegion */
 
 #ifdef ROOTLESS_TRACK_DAMAGE
-                REGION_UNION(pScreen, &winRec->damage,
+                RegionUnion(&winRec->damage,
                                  &winRec->damage, (pRegion));
 #else
                 SCREENREC(pScreen)->imp->DamageRects(winRec->wid,
-                                REGION_NUM_RECTS(pRegion),
-                                REGION_RECTS(pRegion),
+                                RegionNumRects(pRegion),
+                                RegionRects(pRegion),
                                 -winRec->x, -winRec->y);
 #endif
 
@@ -325,20 +325,20 @@ RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion)
 
         /* clip overlaps pRegion, need to intersect */
 
-        REGION_NULL(pScreen, &clipped);
-        REGION_INTERSECT(pScreen, &clipped, &pWindow->borderClip, pRegion);
+        RegionNull(&clipped);
+        RegionIntersect(&clipped, &pWindow->borderClip, pRegion);
 
 #ifdef ROOTLESS_TRACK_DAMAGE
-        REGION_UNION(pScreen, &winRec->damage,
+        RegionUnion(&winRec->damage,
                      &winRec->damage, (pRegion));
 #else
         SCREENREC(pScreen)->imp->DamageRects(winRec->wid,
-                        REGION_NUM_RECTS(&clipped),
-                        REGION_RECTS(&clipped),
+                        RegionNumRects(&clipped),
+                        RegionRects(&clipped),
                         -winRec->x, -winRec->y);
 #endif
 
-        REGION_UNINIT(pScreen, &clipped);
+        RegionUninit(&clipped);
 
         RootlessQueueRedisplay(pTop->drawable.pScreen);
     }
@@ -346,8 +346,8 @@ RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion)
 out:
 #ifdef ROOTLESSDEBUG
     {
-        BoxRec *box = REGION_RECTS(pRegion), *end;
-        int numBox = REGION_NUM_RECTS(pRegion);
+        BoxRec *box = RegionRects(pRegion), *end;
+        int numBox = RegionNumRects(pRegion);
 
         for (end = box+numBox; box < end; box++) {
             RL_DEBUG_MSG("Damage rect: %i, %i, %i, %i\n",
@@ -369,11 +369,11 @@ RootlessDamageBox(WindowPtr pWindow, BoxPtr pBox)
 {
     RegionRec region;
 
-    REGION_INIT(pWindow->drawable.pScreen, &region, pBox, 1);
+    RegionInit(&region, pBox, 1);
 
     RootlessDamageRegion(pWindow, &region);
 
-    REGION_UNINIT(pWindow->drawable.pScreen, &region);  /* no-op */
+    RegionUninit(&region);  /* no-op */
 }
 
 
@@ -396,11 +396,11 @@ RootlessDamageRect(WindowPtr pWindow, int x, int y, int w, int h)
     box.y1 = y;
     box.y2 = y + h;
 
-    REGION_INIT(pWindow->drawable.pScreen, &region, &box, 1);
+    RegionInit(&region, &box, 1);
 
     RootlessDamageRegion(pWindow, &region);
 
-    REGION_UNINIT(pWindow->drawable.pScreen, &region);  /* no-op */
+    RegionUninit(&region);  /* no-op */
 }
 
 
@@ -418,18 +418,18 @@ RootlessRedisplay(WindowPtr pWindow)
 
     RootlessStopDrawing(pWindow, FALSE);
 
-    if (REGION_NOTEMPTY(pScreen, &winRec->damage)) {
+    if (RegionNotEmpty(&winRec->damage)) {
         RL_DEBUG_MSG("Redisplay Win 0x%x, %i x %i @ (%i, %i)\n",
                      pWindow, winRec->width, winRec->height,
                      winRec->x, winRec->y);
 
         // move region to window local coords
-        REGION_TRANSLATE(pScreen, &winRec->damage,
+        RegionTranslate(&winRec->damage,
                          -winRec->x, -winRec->y);
 
         SCREENREC(pScreen)->imp->UpdateRegion(winRec->wid, &winRec->damage);
 
-        REGION_EMPTY(pScreen, &winRec->damage);
+        RegionEmpty(&winRec->damage);
     }
 
 #else   /* !ROOTLESS_TRACK_DAMAGE */
diff --git a/miext/rootless/rootlessScreen.c b/miext/rootless/rootlessScreen.c
index d24ca04..24dcfe8 100644
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@ -441,9 +441,9 @@ RootlessMarkOverlappedWindows(WindowPtr pWin, WindowPtr pFirst,
             pChild = pWin;
             while (1) {
                 if (pChild->viewable) {
-                    if (REGION_BROKEN (pScreen, &pChild->winSize))
+                    if (RegionBroken(&pChild->winSize))
                         SetWinSize (pChild);
-                    if (REGION_BROKEN (pScreen, &pChild->borderSize))
+                    if (RegionBroken(&pChild->borderSize))
                         SetBorderSize (pChild);
                     (* MarkWindow)(pChild);
                     if (pChild->firstChild) {
diff --git a/miext/rootless/rootlessValTree.c b/miext/rootless/rootlessValTree.c
index 0ee4919..0f62c28 100644
--- a/miext/rootless/rootlessValTree.c
+++ b/miext/rootless/rootlessValTree.c
@@ -122,8 +122,8 @@ RootlessShapedWindowIn (ScreenPtr pScreen, RegionPtr universe,
     Bool    someIn, someOut;
     register int t, x1, y1, x2, y2;
 
-    nbox = REGION_NUM_RECTS (bounding);
-    boundBox = REGION_RECTS (bounding);
+    nbox = RegionNumRects (bounding);
+    boundBox = RegionRects (bounding);
     someIn = someOut = FALSE;
     x1 = rect->x1;
     y1 = rect->y1;
@@ -147,7 +147,7 @@ RootlessShapedWindowIn (ScreenPtr pScreen, RegionPtr universe,
 	    box.x2 = box.x1;
 	if (box.y1 > box.y2)
 	    box.y2 = box.y1;
-	switch (RECT_IN_REGION(pScreen, universe, &box))
+	switch (RegionContainsRect(universe, &box))
 	{
 	case rgnIN:
 	    if (someOut)
@@ -224,7 +224,7 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
     borderSize.y2 = dy;
 
     oldVis = pParent->visibility;
-    switch (RECT_IN_REGION( pScreen, universe, &borderSize)) 
+    switch (RegionContainsRect(universe, &borderSize))
     {
     case rgnIN:
 	    newVis = VisibilityUnobscured;
@@ -285,9 +285,9 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 		{
 		    if (pChild->visibility != VisibilityFullyObscured)
 		    {
-			REGION_TRANSLATE( pScreen, &pChild->borderClip,
+			RegionTranslate(&pChild->borderClip,
 						      dx, dy);
-			REGION_TRANSLATE( pScreen, &pChild->clipList,
+			RegionTranslate(&pChild->clipList,
 						      dx, dy);
 			pChild->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 			if (pScreen->ClipNotify)
@@ -296,16 +296,16 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 		    }
 		    if (pChild->valdata)
 		    {
-			REGION_NULL(pScreen,
+			RegionNull(
 				    &pChild->valdata->after.borderExposed);
 			if (HasParentRelativeBorder(pChild))
 			  {
-			    REGION_SUBTRACT(pScreen,
+			    RegionSubtract(
 					 &pChild->valdata->after.borderExposed,
 					 &pChild->borderClip,
 					 &pChild->winSize);
 			}
-			REGION_NULL(pScreen, &pChild->valdata->after.exposed);
+			RegionNull(&pChild->valdata->after.exposed);
 		    }
 		    if (pChild->firstChild)
 		    {
@@ -334,20 +334,20 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 	     * We translate the old clipList because that will be exposed or copied
 	     * if gravity is right.
 	     */
-	    REGION_TRANSLATE( pScreen, &pParent->borderClip, dx, dy);
-	    REGION_TRANSLATE( pScreen, &pParent->clipList, dx, dy);
+	    RegionTranslate(&pParent->borderClip, dx, dy);
+	    RegionTranslate(&pParent->clipList, dx, dy);
     	} 
 	break;
     case VTBroken:
-	REGION_EMPTY (pScreen, &pParent->borderClip);
-	REGION_EMPTY (pScreen, &pParent->clipList);
+	RegionEmpty(&pParent->borderClip);
+	RegionEmpty(&pParent->clipList);
 	break;
     }
 
     borderVisible = pParent->valdata->before.borderVisible;
     resized = pParent->valdata->before.resized;
-    REGION_NULL(pScreen, &pParent->valdata->after.borderExposed);
-    REGION_NULL(pScreen, &pParent->valdata->after.exposed);
+    RegionNull(&pParent->valdata->after.borderExposed);
+    RegionNull(&pParent->valdata->after.exposed);
 
     /*
      * Since the borderClip must not be clipped by the children, we do
@@ -367,23 +367,23 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 	     * of the border will be saved by DIX in borderVisible --
 	     * use that region and destroy it
 	     */
-	    REGION_SUBTRACT( pScreen, exposed, universe, borderVisible);
-	    REGION_DESTROY( pScreen, borderVisible);
+	    RegionSubtract(exposed, universe, borderVisible);
+	    RegionDestroy(borderVisible);
     	}
     	else
     	{
-	    REGION_SUBTRACT( pScreen, exposed, universe, &pParent->borderClip);
+	    RegionSubtract(exposed, universe, &pParent->borderClip);
     	}
 	if (HasParentRelativeBorder(pParent) && (dx || dy)) {
-	    REGION_SUBTRACT( pScreen, &pParent->valdata->after.borderExposed,
+	    RegionSubtract(&pParent->valdata->after.borderExposed,
 				  universe,
 				  &pParent->winSize);
 	} else {
-	    REGION_SUBTRACT( pScreen, &pParent->valdata->after.borderExposed,
+	    RegionSubtract(&pParent->valdata->after.borderExposed,
 			       exposed, &pParent->winSize);
 	}
 
-    	REGION_COPY( pScreen, &pParent->borderClip, universe);
+	RegionCopy(&pParent->borderClip, universe);
     
     	/*
      	 * To get the right clipList for the parent, and to make doubly sure
@@ -391,15 +391,15 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
      	 * border from the universe before proceeding.
      	 */
     
-    	REGION_INTERSECT( pScreen, universe, universe, &pParent->winSize);
+	RegionIntersect(universe, universe, &pParent->winSize);
     }
     else
-    	REGION_COPY( pScreen, &pParent->borderClip, universe);
+	RegionCopy(&pParent->borderClip, universe);
     
     if ((pChild = pParent->firstChild) && pParent->mapped)
     {
-	REGION_NULL(pScreen, &childUniverse);
-	REGION_NULL(pScreen, &childUnion);
+	RegionNull(&childUniverse);
+	RegionNull(&childUnion);
 	if ((pChild->drawable.y < pParent->lastChild->drawable.y) ||
 	    ((pChild->drawable.y == pParent->lastChild->drawable.y) &&
 	     (pChild->drawable.x < pParent->lastChild->drawable.x)))
@@ -407,7 +407,7 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 	    for (; pChild; pChild = pChild->nextSib)
 	    {
 		if (pChild->viewable)
-		    REGION_APPEND( pScreen, &childUnion, &pChild->borderSize);
+		    RegionAppend(&childUnion, &pChild->borderSize);
 	    }
 	}
 	else
@@ -415,10 +415,10 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 	    for (pChild = pParent->lastChild; pChild; pChild = pChild->prevSib)
 	    {
 		if (pChild->viewable)
-		    REGION_APPEND( pScreen, &childUnion, &pChild->borderSize);
+		    RegionAppend(&childUnion, &pChild->borderSize);
 	    }
 	}
-	REGION_VALIDATE( pScreen, &childUnion, &overlap);
+	RegionValidate(&childUnion, &overlap);
 
 	for (pChild = pParent->firstChild;
 	     pChild;
@@ -435,7 +435,7 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 		     * Figure out the new universe from the child's
 		     * perspective and recurse.
 		     */
-		    REGION_INTERSECT( pScreen, &childUniverse,
+		    RegionIntersect(&childUniverse,
 					    universe,
 					    &pChild->borderSize);
 		    RootlessComputeClips (pChild, pScreen, &childUniverse, 
@@ -447,14 +447,14 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
 		 * other sibling.
 		 */
 		if (overlap)
-		    REGION_SUBTRACT( pScreen, universe, universe,
+		    RegionSubtract(universe, universe,
 					  &pChild->borderSize);
 	    }
 	}
 	if (!overlap)
-	    REGION_SUBTRACT( pScreen, universe, universe, &childUnion);
-	REGION_UNINIT( pScreen, &childUnion);
-	REGION_UNINIT( pScreen, &childUniverse);
+	    RegionSubtract(universe, universe, &childUnion);
+	RegionUninit(&childUnion);
+	RegionUninit(&childUniverse);
     } /* if any children */
 
     /*
@@ -467,12 +467,12 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
     if (oldVis == VisibilityFullyObscured ||
 	oldVis == VisibilityNotViewable)
     {
-	REGION_COPY( pScreen, &pParent->valdata->after.exposed, universe);
+	RegionCopy(&pParent->valdata->after.exposed, universe);
     }
     else if (newVis != VisibilityFullyObscured &&
 	     newVis != VisibilityNotViewable)
     {
-    	REGION_SUBTRACT( pScreen, &pParent->valdata->after.exposed,
+	RegionSubtract(&pParent->valdata->after.exposed,
 			       universe, &pParent->clipList);
     }
 
@@ -484,7 +484,7 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
      */
     if (pParent->backStorage && !resized)
     {
-	REGION_SUBTRACT( pScreen, exposed, &pParent->clipList, universe);
+	RegionSubtract(exposed, &pParent->clipList, universe);
 	(* pScreen->SaveDoomedAreas)(pParent, exposed, dx, dy);
     }
     
@@ -498,7 +498,7 @@ RootlessComputeClips (WindowPtr pParent, ScreenPtr pScreen,
     }
 
 #ifdef NOTDEF
-    REGION_COPY( pScreen, &pParent->clipList, universe);
+    RegionCopy(&pParent->clipList, universe);
 #endif
 
     pParent->drawable.serialNumber = NEXT_SERIAL_NUMBER;
@@ -589,15 +589,15 @@ RootlessMiValidateTree (WindowPtr pRoot, /* Parent to validate */
     if (pChild == NullWindow)
 	pChild = pRoot->firstChild;
 
-    REGION_NULL(pScreen, &childClip);
-    REGION_NULL(pScreen, &exposed);
+    RegionNull(&childClip);
+    RegionNull(&exposed);
 
-    if (REGION_BROKEN (pScreen, &pRoot->clipList) &&
-	!REGION_BROKEN (pScreen, &pRoot->borderClip))
+    if (RegionBroken(&pRoot->clipList) &&
+	!RegionBroken(&pRoot->borderClip))
     {
         // fixme this might not work, but hopefully doesn't happen anyway.
         kind = VTBroken;
-        REGION_EMPTY (pScreen, &pRoot->clipList);
+        RegionEmpty(&pRoot->clipList);
         ErrorF("ValidateTree: BUSTED!\n");
     }
 
@@ -613,28 +613,28 @@ RootlessMiValidateTree (WindowPtr pRoot, /* Parent to validate */
     {
         if (pWin->viewable) {
             if (pWin->valdata) {
-                REGION_COPY( pScreen, &childClip, &pWin->borderSize);
+                RegionCopy(&childClip, &pWin->borderSize);
                 RootlessComputeClips (pWin, pScreen, &childClip, kind, &exposed);
             } else if (pWin->visibility == VisibilityNotViewable) {
                 RootlessTreeObscured(pWin);
             }
         } else {
             if (pWin->valdata) {
-                REGION_EMPTY( pScreen, &pWin->clipList);
+                RegionEmpty(&pWin->clipList);
                 if (pScreen->ClipNotify)
                     (* pScreen->ClipNotify) (pWin, 0, 0);
-                REGION_EMPTY( pScreen, &pWin->borderClip);
+                RegionEmpty(&pWin->borderClip);
                 pWin->valdata = NULL;
             }
         }
     }
 
-    REGION_UNINIT(pScreen, &childClip);
+    RegionUninit(&childClip);
 
     /* The root is never clipped by its children, so nothing on the root 
        is ever exposed by moving or mapping its children. */
-    REGION_NULL(pScreen, &pRoot->valdata->after.exposed);
-    REGION_NULL(pScreen, &pRoot->valdata->after.borderExposed);
+    RegionNull(&pRoot->valdata->after.exposed);
+    RegionNull(&pRoot->valdata->after.borderExposed);
 
     return 1;
 }
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 4d541f4..7f03214 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -184,7 +184,7 @@ RootlessDestroyFrame(WindowPtr pWin, RootlessWindowPtr winRec)
     SCREENREC(pScreen)->imp->DestroyFrame(winRec->wid);
 
 #ifdef ROOTLESS_TRACK_DAMAGE
-    REGION_UNINIT(pScreen, &winRec->damage);
+    RegionUninit(&winRec->damage);
 #endif
 
     free(winRec);
@@ -232,9 +232,9 @@ RootlessGetShape(WindowPtr pWin, RegionPtr pShape)
     /* wBoundingShape is relative to *inner* origin of window.
        Translate by borderWidth to get the outside-relative position. */
 
-    REGION_NULL(pScreen, pShape);
-    REGION_COPY(pScreen, pShape, wBoundingShape(pWin));
-    REGION_TRANSLATE(pScreen, pShape, pWin->borderWidth, pWin->borderWidth);
+    RegionNull(pShape);
+    RegionCopy(pShape, wBoundingShape(pWin));
+    RegionTranslate(pShape, pWin->borderWidth, pWin->borderWidth);
 
     return TRUE;
 }
@@ -266,7 +266,7 @@ static void RootlessReshapeFrame(WindowPtr pWin)
     RL_DEBUG_MSG("reshaping...");
     if (pShape != NULL) {
         RL_DEBUG_MSG("numrects %d, extents %d %d %d %d ",
-                     REGION_NUM_RECTS(&newShape),
+                     RegionNumRects(&newShape),
                      newShape.extents.x1, newShape.extents.y1,
                      newShape.extents.x2, newShape.extents.y2);
     } else {
@@ -277,7 +277,7 @@ static void RootlessReshapeFrame(WindowPtr pWin)
     SCREENREC(pScreen)->imp->ReshapeFrame(winRec->wid, pShape);
 
     if (pShape != NULL)
-        REGION_UNINIT(pScreen, &newShape);
+        RegionUninit(&newShape);
 }
 
 
@@ -355,8 +355,8 @@ RootlessPositionWindow(WindowPtr pWin, int x, int y)
 
 #ifdef ROOTLESS_TRACK_DAMAGE
             // Move damaged region to correspond to new window position
-            if (REGION_NOTEMPTY(pScreen, &winRec->damage)) {
-                REGION_TRANSLATE(pScreen, &winRec->damage,
+            if (RegionNotEmpty(&winRec->damage)) {
+                RegionTranslate(&winRec->damage,
                                  x - bw - winRec->x,
                                  y - bw - winRec->y);
             }
@@ -394,7 +394,7 @@ RootlessInitializeFrame(WindowPtr pWin, RootlessWindowRec *winRec)
     winRec->borderWidth = bw;
 
 #ifdef ROOTLESS_TRACK_DAMAGE
-    REGION_NULL(pScreen, &winRec->damage);
+    RegionNull(&winRec->damage);
 #endif
 }
 
@@ -457,7 +457,7 @@ RootlessEnsureFrame(WindowPtr pWin)
       RootlessFlushWindowColormap(pWin);
 
     if (pShape != NULL)
-        REGION_UNINIT(pScreen, &shape);
+        RegionUninit(&shape);
 
     return winRec;
 }
@@ -673,7 +673,7 @@ RootlessNoCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
 
     RL_DEBUG_MSG("ROOTLESSNOCOPYWINDOW ");
 
-    REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
+    RegionTranslate(prgnSrc, -dx, -dy);
 }
 
 
@@ -705,9 +705,9 @@ RootlessResizeCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
 
     dx = ptOldOrg.x - pWin->drawable.x;
     dy = ptOldOrg.y - pWin->drawable.y;
-    REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy);
-    REGION_NULL(pScreen, &rgnDst);
-    REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
+    RegionTranslate(prgnSrc, -dx, -dy);
+    RegionNull(&rgnDst);
+    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
 
     if (gResizeDeathCount == 1) {
         /* Simple case, we only have a single source pixmap. */
@@ -724,21 +724,21 @@ RootlessResizeCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
            intersect the destination with each source and copy those bits. */
 
         for (i = 0; i < gResizeDeathCount; i++) {
-            REGION_INIT(pScreen, &clip, gResizeDeathBounds + 0, 1);
-            REGION_NULL(pScreen, &clipped);
-            REGION_INTERSECT(pScreen, &rgnDst, &clip, &clipped);
+            RegionInit(&clip, gResizeDeathBounds + 0, 1);
+            RegionNull(&clipped);
+            RegionIntersect(&rgnDst, &clip, &clipped);
 
             fbCopyRegion(&gResizeDeathPix[i]->drawable,
                          &pScreen->GetWindowPixmap(pWin)->drawable, 0,
                          &clipped, dx, dy, fbCopyWindowProc, 0, 0);
 
-            REGION_UNINIT(pScreen, &clipped);
-            REGION_UNINIT(pScreen, &clip);
+            RegionUninit(&clipped);
+            RegionUninit(&clip);
         }
     }
 
     /* Don't update - resize will update everything */
-    REGION_UNINIT(pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
 
     fbValidateDrawable(&pWin->drawable);
 
@@ -768,12 +768,12 @@ RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 
     dx = ptOldOrg.x - pWin->drawable.x;
     dy = ptOldOrg.y - pWin->drawable.y;
-    REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy);
+    RegionTranslate(prgnSrc, -dx, -dy);
 
-    REGION_NULL(pScreen, &rgnDst);
-    REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
+    RegionNull(&rgnDst);
+    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
 
-    extents = REGION_EXTENTS(pScreen, &rgnDst);
+    extents = RegionExtents(&rgnDst);
     area = (extents->x2 - extents->x1) * (extents->y2 - extents->y1);
 
     /* If the area exceeds threshold, use the implementation's
@@ -797,13 +797,13 @@ RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
         }
 
         /* Move region to window local coords */
-        REGION_TRANSLATE(pScreen, &rgnDst, -winRec->x, -winRec->y);
+        RegionTranslate(&rgnDst, -winRec->x, -winRec->y);
 
         RootlessStopDrawing(pWin, FALSE);
 
         SCREENREC(pScreen)->imp->CopyWindow(winRec->wid,
-                                            REGION_NUM_RECTS(&rgnDst),
-                                            REGION_RECTS(&rgnDst),
+                                            RegionNumRects(&rgnDst),
+                                            RegionRects(&rgnDst),
                                             dx, dy);
     }
     else {
@@ -817,7 +817,7 @@ RootlessCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     }
 
 out:
-    REGION_UNINIT(pScreen, &rgnDst);
+    RegionUninit(&rgnDst);
     fbValidateDrawable(&pWin->drawable);
 
     SCREEN_WRAP(pScreen, CopyWindow);
@@ -1320,11 +1320,11 @@ RootlessResizeWindow(WindowPtr pWin, int x, int y,
 
         box.x1 = x; box.y1 = y;
         box.x2 = x + w; box.y2 = y + h;
-        REGION_UNINIT(pScreen, &pWin->winSize);
-        REGION_INIT(pScreen, &pWin->winSize, &box, 1);
-        REGION_COPY(pScreen, &pWin->borderSize, &pWin->winSize);
-        REGION_COPY(pScreen, &pWin->clipList, &pWin->winSize);
-        REGION_COPY(pScreen, &pWin->borderClip, &pWin->winSize);
+        RegionUninit(&pWin->winSize);
+        RegionInit(&pWin->winSize, &box, 1);
+        RegionCopy(&pWin->borderSize, &pWin->winSize);
+        RegionCopy(&pWin->clipList, &pWin->winSize);
+        RegionCopy(&pWin->borderClip, &pWin->winSize);
 
         miSendExposures(pWin, &pWin->borderClip,
                         pWin->drawable.x, pWin->drawable.y);        
diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index e027e76..893014b 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -57,7 +57,7 @@ shadowRedisplay(ScreenPtr pScreen)
     if (!pBuf || !pBuf->pDamage || !pBuf->update)
 	return;
     pRegion = DamageRegion(pBuf->pDamage);
-    if (REGION_NOTEMPTY(pScreen, pRegion)) {
+    if (RegionNotEmpty(pRegion)) {
 	(*pBuf->update)(pScreen, pBuf);
 	DamageEmpty(pBuf->pDamage);
     }
@@ -103,7 +103,7 @@ shadowCloseScreen(int i, ScreenPtr pScreen)
     shadowRemove(pScreen, pBuf->pPixmap);
     DamageDestroy(pBuf->pDamage);
 #ifdef BACKWARDS_COMPATIBILITY
-    REGION_UNINIT(pScreen, &pBuf->damage); /* bc */
+    RegionUninit(&pBuf->damage); /* bc */
 #endif
     if (pBuf->pPixmap)
 	pScreen->DestroyPixmap(pBuf->pPixmap);
@@ -121,13 +121,13 @@ shadowReportFunc(DamagePtr pDamage, RegionPtr pRegion, void *closure)
 
     /* Register the damaged region, use DamageReportNone below when we
      * want to break BC below... */
-    REGION_UNION(pScreen, &pDamage->damage, &pDamage->damage, pRegion);
+    RegionUnion(&pDamage->damage, &pDamage->damage, pRegion);
 
     /*
      * BC hack.  In 7.0 and earlier several drivers would inspect the
      * 'damage' member directly, so we have to keep it existing.
      */
-    REGION_COPY(pScreen, &pBuf->damage, pRegion);
+    RegionCopy(&pBuf->damage, pRegion);
 }
 #endif
 
@@ -166,7 +166,7 @@ shadowSetup(ScreenPtr pScreen)
     pBuf->closure = 0;
     pBuf->randr = 0;
 #ifdef BACKWARDS_COMPATIBILITY
-    REGION_NULL(pScreen, &pBuf->damage); /* bc */
+    RegionNull(&pBuf->damage); /* bc */
 #endif
 
     dixSetPrivate(&pScreen->devPrivates, shadowScrPrivateKey, pBuf);
diff --git a/miext/shadow/shpacked.c b/miext/shadow/shpacked.c
index 6736162..20d2ea1 100644
--- a/miext/shadow/shpacked.c
+++ b/miext/shadow/shpacked.c
@@ -46,8 +46,8 @@ shadowUpdatePacked (ScreenPtr	    pScreen,
 {
     RegionPtr	damage = shadowDamage (pBuf);
     PixmapPtr	pShadow = pBuf->pPixmap;
-    int		nbox = REGION_NUM_RECTS (damage);
-    BoxPtr	pbox = REGION_RECTS (damage);
+    int		nbox = RegionNumRects (damage);
+    BoxPtr	pbox = RegionRects (damage);
     FbBits	*shaBase, *shaLine, *sha;
     FbStride	shaStride;
     int		scrBase, scrLine, scr;
diff --git a/miext/shadow/shplanar.c b/miext/shadow/shplanar.c
index b5983dc..9ca3f3f 100644
--- a/miext/shadow/shplanar.c
+++ b/miext/shadow/shplanar.c
@@ -92,8 +92,8 @@ shadowUpdatePlanar4 (ScreenPtr	    pScreen,
 {
     RegionPtr	damage = shadowDamage (pBuf);
     PixmapPtr	pShadow = pBuf->pPixmap;
-    int		nbox = REGION_NUM_RECTS (damage);
-    BoxPtr	pbox = REGION_RECTS (damage);
+    int		nbox = RegionNumRects (damage);
+    BoxPtr	pbox = RegionRects (damage);
     CARD32	*shaBase, *shaLine, *sha;
     FbStride	shaStride;
     int		scrBase, scrLine, scr;
diff --git a/miext/shadow/shplanar8.c b/miext/shadow/shplanar8.c
index 6d8defa..f8b255d 100644
--- a/miext/shadow/shplanar8.c
+++ b/miext/shadow/shplanar8.c
@@ -95,8 +95,8 @@ shadowUpdatePlanar4x8 (ScreenPtr	pScreen,
 {
     RegionPtr	damage = shadowDamage (pBuf);
     PixmapPtr	pShadow = pBuf->pPixmap;
-    int		nbox = REGION_NUM_RECTS (damage);
-    BoxPtr	pbox = REGION_RECTS (damage);
+    int		nbox = RegionNumRects (damage);
+    BoxPtr	pbox = RegionRects (damage);
     CARD32	*shaBase, *shaLine, *sha;
     CARD8	s1, s2, s3, s4;
     FbStride	shaStride;
diff --git a/miext/shadow/shrotate.c b/miext/shadow/shrotate.c
index 673cd76..c389826 100644
--- a/miext/shadow/shrotate.c
+++ b/miext/shadow/shrotate.c
@@ -54,8 +54,8 @@ shadowUpdateRotatePacked (ScreenPtr	pScreen,
 {
     RegionPtr	damage = shadowDamage (pBuf);
     PixmapPtr	pShadow = pBuf->pPixmap;
-    int		nbox = REGION_NUM_RECTS (damage);
-    BoxPtr	pbox = REGION_RECTS (damage);
+    int		nbox = RegionNumRects (damage);
+    BoxPtr	pbox = RegionRects (damage);
     FbBits	*shaBits;
     FbStride	shaStride;
     int		shaBpp;
diff --git a/miext/shadow/shrotpack.h b/miext/shadow/shrotpack.h
index 015a985..2d1a87c 100644
--- a/miext/shadow/shrotpack.h
+++ b/miext/shadow/shrotpack.h
@@ -99,8 +99,8 @@ FUNC (ScreenPtr	    pScreen,
 {
     RegionPtr	damage = shadowDamage (pBuf);
     PixmapPtr	pShadow = pBuf->pPixmap;
-    int		nbox = REGION_NUM_RECTS (damage);
-    BoxPtr	pbox = REGION_RECTS (damage);
+    int		nbox = RegionNumRects (damage);
+    BoxPtr	pbox = RegionRects (damage);
     FbBits	*shaBits;
     Data	*shaBase, *shaLine, *sha;
     FbStride	shaStride;
diff --git a/miext/shadow/shrotpackYX.h b/miext/shadow/shrotpackYX.h
index 8ef70f1..7d36bd1 100644
--- a/miext/shadow/shrotpackYX.h
+++ b/miext/shadow/shrotpackYX.h
@@ -63,8 +63,8 @@ FUNC (ScreenPtr	    pScreen,
 {
     RegionPtr	damage = shadowDamage(pBuf);
     PixmapPtr	pShadow = pBuf->pPixmap;
-    int		nbox = REGION_NUM_RECTS (damage);
-    BoxPtr	pbox = REGION_RECTS (damage);
+    int		nbox = RegionNumRects (damage);
+    BoxPtr	pbox = RegionRects (damage);
     FbBits	*shaBits;
     Data	*shaBase, *shaLine, *sha;
     FbStride	shaStride, winStride;
diff --git a/render/mipict.c b/render/mipict.c
index 1dad88e..b5b8970 100644
--- a/render/mipict.c
+++ b/render/mipict.c
@@ -47,7 +47,7 @@ void
 miDestroyPicture (PicturePtr pPicture)
 {
     if (pPicture->freeCompClip)
-	REGION_DESTROY(pPicture->pDrawable->pScreen, pPicture->pCompositeClip);
+	RegionDestroy(pPicture->pCompositeClip);
 }
 
 void
@@ -64,7 +64,7 @@ miDestroyPictureClip (PicturePtr pPicture)
 	 * we know we'll never have a list of rectangles, since ChangeClip
 	 * immediately turns them into a region
 	 */
-	REGION_DESTROY(pPicture->pDrawable->pScreen, pPicture->clientClip);
+	RegionDestroy(pPicture->clientClip);
 	break;
     }
     pPicture->clientClip = NULL;
@@ -85,7 +85,7 @@ miChangePictureClip (PicturePtr    pPicture,
     switch (type) {
     case CT_PIXMAP:
 	/* convert the pixmap to a region */
-	clientClip = (pointer) BITMAP_TO_REGION(pScreen, (PixmapPtr) value);
+	clientClip = (pointer) BitmapToRegion(pScreen, (PixmapPtr) value);
 	if (!clientClip)
 	    return BadAlloc;
 	clientClipType = CT_REGION;
@@ -100,7 +100,7 @@ miChangePictureClip (PicturePtr    pPicture,
 	clientClipType = CT_NONE;
 	break;
     default:
-	clientClip = (pointer) RECTS_TO_REGION(pScreen, n,
+	clientClip = (pointer) RegionFromRects(n,
 					       (xRectangle *) value,
 					       type);
 	if (!clientClip)
@@ -160,7 +160,7 @@ miValidatePicture (PicturePtr pPicture,
 	    if (pPicture->clientClipType == CT_NONE)
 	    {
 		if (freeCompClip)
-		    REGION_DESTROY(pScreen, pPicture->pCompositeClip);
+		    RegionDestroy(pPicture->pCompositeClip);
 		pPicture->pCompositeClip = pregWin;
 		pPicture->freeCompClip = freeTmpClip;
 	    }
@@ -175,30 +175,30 @@ miValidatePicture (PicturePtr pPicture,
 		 * clip. if neither is real, create a new region.
 		 */
 
-		REGION_TRANSLATE(pScreen, pPicture->clientClip,
+		RegionTranslate(pPicture->clientClip,
 				 pDrawable->x + pPicture->clipOrigin.x,
 				 pDrawable->y + pPicture->clipOrigin.y);
 
 		if (freeCompClip)
 		{
-		    REGION_INTERSECT(pScreen, pPicture->pCompositeClip,
+		    RegionIntersect(pPicture->pCompositeClip,
 				     pregWin, pPicture->clientClip);
 		    if (freeTmpClip)
-			REGION_DESTROY(pScreen, pregWin);
+			RegionDestroy(pregWin);
 		}
 		else if (freeTmpClip)
 		{
-		    REGION_INTERSECT(pScreen, pregWin, pregWin, pPicture->clientClip);
+		    RegionIntersect(pregWin, pregWin, pPicture->clientClip);
 		    pPicture->pCompositeClip = pregWin;
 		}
 		else
 		{
-		    pPicture->pCompositeClip = REGION_CREATE(pScreen, NullBox, 0);
-		    REGION_INTERSECT(pScreen, pPicture->pCompositeClip,
+		    pPicture->pCompositeClip = RegionCreate(NullBox, 0);
+		    RegionIntersect(pPicture->pCompositeClip,
 				     pregWin, pPicture->clientClip);
 		}
 		pPicture->freeCompClip = TRUE;
-		REGION_TRANSLATE(pScreen, pPicture->clientClip,
+		RegionTranslate(pPicture->clientClip,
 				 -(pDrawable->x + pPicture->clipOrigin.x),
 				 -(pDrawable->y + pPicture->clipOrigin.y));
 	    }
@@ -216,31 +216,31 @@ miValidatePicture (PicturePtr pPicture,
 
 	    if (pPicture->freeCompClip)
 	    {
-		REGION_RESET(pScreen, pPicture->pCompositeClip, &pixbounds);
+		RegionReset(pPicture->pCompositeClip, &pixbounds);
 	    }
 	    else
 	    {
 		pPicture->freeCompClip = TRUE;
-		pPicture->pCompositeClip = REGION_CREATE(pScreen, &pixbounds, 1);
+		pPicture->pCompositeClip = RegionCreate(&pixbounds, 1);
 	    }
 
 	    if (pPicture->clientClipType == CT_REGION)
 	    {
 		if(pDrawable->x || pDrawable->y) {
-		    REGION_TRANSLATE(pScreen, pPicture->clientClip,
+		    RegionTranslate(pPicture->clientClip,
 				     pDrawable->x + pPicture->clipOrigin.x, 
 				     pDrawable->y + pPicture->clipOrigin.y);
-		    REGION_INTERSECT(pScreen, pPicture->pCompositeClip,
+		    RegionIntersect(pPicture->pCompositeClip,
 				     pPicture->pCompositeClip, pPicture->clientClip);
-		    REGION_TRANSLATE(pScreen, pPicture->clientClip,
+		    RegionTranslate(pPicture->clientClip,
 				     -(pDrawable->x + pPicture->clipOrigin.x), 
 				     -(pDrawable->y + pPicture->clipOrigin.y));
 		} else {
-		    REGION_TRANSLATE(pScreen, pPicture->pCompositeClip,
+		    RegionTranslate(pPicture->pCompositeClip,
 				     -pPicture->clipOrigin.x, -pPicture->clipOrigin.y);
-		    REGION_INTERSECT(pScreen, pPicture->pCompositeClip,
+		    RegionIntersect(pPicture->pCompositeClip,
 				     pPicture->pCompositeClip, pPicture->clientClip);
-		    REGION_TRANSLATE(pScreen, pPicture->pCompositeClip,
+		    RegionTranslate(pPicture->pCompositeClip,
 				     pPicture->clipOrigin.x, pPicture->clipOrigin.y);
 		}
 	    }
@@ -321,7 +321,7 @@ miClipPictureSrc (RegionPtr	pRegion,
 				  pPicture->clipOrigin.x + dx,
 				  pPicture->clipOrigin.y + dy);
 
-	result = REGION_INTERSECT (pScreen, pRegion, pRegion, pPicture->clientClip);
+	result = RegionIntersect(pRegion, pRegion, pPicture->clientClip);
 	
 	pixman_region_translate ( pPicture->clientClip,
 				  - (pPicture->clipOrigin.x + dx),
diff --git a/render/mirect.c b/render/mirect.c
index 13d7fa6..6a3112a 100644
--- a/render/mirect.c
+++ b/render/mirect.c
@@ -64,8 +64,8 @@ miColorRects (PicturePtr    pDst,
 	tmpval[4].val = pDst->clipOrigin.y - yoff;
 	mask |= GCClipXOrigin|GCClipYOrigin;
 	
-	pClip = REGION_CREATE (pScreen, NULL, 1);
-	REGION_COPY (pScreen, pClip,
+	pClip = RegionCreate(NULL, 1);
+	RegionCopy(pClip,
 		     (RegionPtr) pClipPict->clientClip);
 	(*pGC->funcs->ChangeClip) (pGC, CT_REGION, pClip, 0);
     }
diff --git a/render/picture.c b/render/picture.c
index 211fa38..ca5e18e 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -1298,7 +1298,7 @@ SetPictureClipRects (PicturePtr	pPicture,
     RegionPtr		clientClip;
     int			result;
 
-    clientClip = RECTS_TO_REGION(pScreen,
+    clientClip = RegionFromRects(
 				 nRect, rects, CT_UNSORTED);
     if (!clientClip)
 	return BadAlloc;
@@ -1329,14 +1329,14 @@ SetPictureClipRegion (PicturePtr    pPicture,
     if (pRegion)
     {
         type = CT_REGION;
-        clientClip = REGION_CREATE (pScreen,
-                                    REGION_EXTENTS(pScreen, pRegion),
-                                    REGION_NUM_RECTS(pRegion));
+        clientClip = RegionCreate(
+                                    RegionExtents(pRegion),
+                                    RegionNumRects(pRegion));
         if (!clientClip)
             return BadAlloc;
-        if (!REGION_COPY (pSCreen, clientClip, pRegion))
+        if (!RegionCopy(clientClip, pRegion))
         {
-            REGION_DESTROY (pScreen, clientClip);
+            RegionDestroy(clientClip);
             return BadAlloc;
         }
     }
@@ -1462,9 +1462,9 @@ CopyPicture (PicturePtr	pSrc,
 		    RegionPtr clientClip;
 		    RegionPtr srcClientClip = (RegionPtr)pSrc->clientClip;
 
-		    clientClip = REGION_CREATE(pSrc->pDrawable->pScreen,
-			REGION_EXTENTS(pSrc->pDrawable->pScreen, srcClientClip),
-			REGION_NUM_RECTS(srcClientClip));
+		    clientClip = RegionCreate(
+			RegionExtents(srcClientClip),
+			RegionNumRects(srcClientClip));
 		    (*ps->ChangePictureClip)(pDst, CT_REGION, clientClip, 0);
 		}
 		break;
diff --git a/xfixes/region.c b/xfixes/region.c
index b034ad0..4fdfa20 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -39,20 +39,20 @@ RegionResFree (pointer data, XID id)
 {
     RegionPtr    pRegion = (RegionPtr) data;
 
-    REGION_DESTROY (0, pRegion);
+    RegionDestroy(pRegion);
     return Success;
 }
 
 RegionPtr
 XFixesRegionCopy (RegionPtr pRegion)
 {
-    RegionPtr   pNew = REGION_CREATE (0, REGION_EXTENTS(0, pRegion),
-				      REGION_NUM_RECTS(pRegion));
+    RegionPtr   pNew = RegionCreate(RegionExtents(pRegion),
+				      RegionNumRects(pRegion));
     if (!pNew)
 	return 0;
-    if (!REGION_COPY (0, pNew, pRegion))
+    if (!RegionCopy(pNew, pRegion))
     {
-	REGION_DESTROY (0, pNew);
+	RegionDestroy(pNew);
 	return 0;
     }
     return pNew;
@@ -81,7 +81,7 @@ ProcXFixesCreateRegion (ClientPtr client)
 	return BadLength;
     things >>= 3;
 
-    pRegion = RECTS_TO_REGION(0, things, (xRectangle *) (stuff + 1), CT_UNSORTED);
+    pRegion = RegionFromRects(things, (xRectangle *) (stuff + 1), CT_UNSORTED);
     if (!pRegion)
 	return BadAlloc;
     if (!AddResource (stuff->region, RegionResType, (pointer) pRegion))
@@ -124,7 +124,7 @@ ProcXFixesCreateRegionFromBitmap (ClientPtr client)
     if (pPixmap->drawable.depth != 1)
 	return BadMatch;
 
-    pRegion = BITMAP_TO_REGION(pPixmap->drawable.pScreen, pPixmap);
+    pRegion = BitmapToRegion(pPixmap->drawable.pScreen, pPixmap);
 
     if (!pRegion)
 	return BadAlloc;
@@ -227,7 +227,7 @@ ProcXFixesCreateRegionFromGC (ClientPtr client)
     
     switch (pGC->clientClipType) {
     case CT_PIXMAP:
-	pRegion = BITMAP_TO_REGION(pGC->pScreen, (PixmapPtr) pGC->clientClip);
+	pRegion = BitmapToRegion(pGC->pScreen, (PixmapPtr) pGC->clientClip);
 	if (!pRegion)
 	    return BadAlloc;
 	break;
@@ -274,7 +274,7 @@ ProcXFixesCreateRegionFromPicture (ClientPtr client)
     
     switch (pPicture->clientClipType) {
     case CT_PIXMAP:
-	pRegion = BITMAP_TO_REGION(pPicture->pDrawable->pScreen,
+	pRegion = BitmapToRegion(pPicture->pDrawable->pScreen,
 				   (PixmapPtr) pPicture->clientClip);
 	if (!pRegion)
 	    return BadAlloc;
@@ -346,15 +346,15 @@ ProcXFixesSetRegion (ClientPtr client)
 	return BadLength;
     things >>= 3;
 
-    pNew = RECTS_TO_REGION(0, things, (xRectangle *) (stuff + 1), CT_UNSORTED);
+    pNew = RegionFromRects(things, (xRectangle *) (stuff + 1), CT_UNSORTED);
     if (!pNew)
 	return BadAlloc;
-    if (!REGION_COPY (0, pRegion, pNew))
+    if (!RegionCopy(pRegion, pNew))
     {
-	REGION_DESTROY (0, pNew);
+	RegionDestroy(pNew);
 	return BadAlloc;
     }
-    REGION_DESTROY (0, pNew);
+    RegionDestroy(pNew);
     return Success;
 }
 
@@ -380,7 +380,7 @@ ProcXFixesCopyRegion (ClientPtr client)
     VERIFY_REGION(pSource, stuff->source, client, DixReadAccess);
     VERIFY_REGION(pDestination, stuff->destination, client, DixWriteAccess);
     
-    if (!REGION_COPY(pScreen, pDestination, pSource))
+    if (!RegionCopy(pDestination, pSource))
 	return BadAlloc;
 
     return Success;
@@ -412,15 +412,15 @@ ProcXFixesCombineRegion (ClientPtr client)
     
     switch (stuff->xfixesReqType) {
     case X_XFixesUnionRegion:
-	if (!REGION_UNION (0, pDestination, pSource1, pSource2))
+	if (!RegionUnion(pDestination, pSource1, pSource2))
 	    return BadAlloc;
 	break;
     case X_XFixesIntersectRegion:
-	if (!REGION_INTERSECT (0, pDestination, pSource1, pSource2))
+	if (!RegionIntersect(pDestination, pSource1, pSource2))
 	    return BadAlloc;
 	break;
     case X_XFixesSubtractRegion:
-	if (!REGION_SUBTRACT (0, pDestination, pSource1, pSource2))
+	if (!RegionSubtract(pDestination, pSource1, pSource2))
 	    return BadAlloc;
 	break;
     }
@@ -466,7 +466,7 @@ ProcXFixesInvertRegion (ClientPtr client)
     else
 	bounds.y2 = stuff->y + stuff->height;
 
-    if (!REGION_INVERSE(0, pDestination, pSource, &bounds))
+    if (!RegionInverse(pDestination, pSource, &bounds))
 	return BadAlloc;
 
     return Success;
@@ -498,7 +498,7 @@ ProcXFixesTranslateRegion (ClientPtr client)
     REQUEST_SIZE_MATCH(xXFixesTranslateRegionReq);
     VERIFY_REGION(pRegion, stuff->region, client, DixWriteAccess);
 
-    REGION_TRANSLATE(pScreen, pRegion, stuff->dx, stuff->dy);
+    RegionTranslate(pRegion, stuff->dx, stuff->dy);
     return Success;
 }
 
@@ -526,7 +526,7 @@ ProcXFixesRegionExtents (ClientPtr client)
     VERIFY_REGION(pSource, stuff->source, client, DixReadAccess);
     VERIFY_REGION(pDestination, stuff->destination, client, DixWriteAccess);
 
-    REGION_RESET (0, pDestination, REGION_EXTENTS (0, pSource));
+    RegionReset(pDestination, RegionExtents(pSource));
 
     return Success;
 }
@@ -558,9 +558,9 @@ ProcXFixesFetchRegion (ClientPtr client)
     REQUEST_SIZE_MATCH(xXFixesFetchRegionReq);
     VERIFY_REGION(pRegion, stuff->region, client, DixReadAccess);
 
-    pExtent = REGION_EXTENTS (0, pRegion);
-    pBox = REGION_RECTS (pRegion);
-    nBox = REGION_NUM_RECTS (pRegion);
+    pExtent = RegionExtents(pRegion);
+    pBox = RegionRects (pRegion);
+    nBox = RegionNumRects (pRegion);
     
     reply = malloc(sizeof (xXFixesFetchRegionReply) +
 		    nBox * sizeof (xRectangle));
@@ -708,7 +708,7 @@ ProcXFixesSetWindowShapeRegion (ClientPtr client)
 	    break;
 	}
 	if (stuff->xOff || stuff->yOff)
-	    REGION_TRANSLATE (0, pRegion, stuff->xOff, stuff->yOff);
+	    RegionTranslate(pRegion, stuff->xOff, stuff->yOff);
     }
     else
     {
@@ -731,7 +731,7 @@ ProcXFixesSetWindowShapeRegion (ClientPtr client)
 	    pDestRegion = &pRegion; /* a NULL region pointer */
     }
     if (*pDestRegion)
-	REGION_DESTROY(pScreen, *pDestRegion);
+	RegionDestroy(*pDestRegion);
     *pDestRegion = pRegion;
     (*pScreen->SetShape) (pWin, stuff->destKind);
     SendShapeNotify (pWin, stuff->destKind);
@@ -801,8 +801,8 @@ ProcXFixesExpandRegion (ClientPtr client)
     VERIFY_REGION(pSource, stuff->source, client, DixReadAccess);
     VERIFY_REGION(pDestination, stuff->destination, client, DixWriteAccess);
     
-    nBoxes = REGION_NUM_RECTS(pSource);
-    pSrc = REGION_RECTS(pSource);
+    nBoxes = RegionNumRects(pSource);
+    pSrc = RegionRects(pSource);
     if (nBoxes)
     {
 	pTmp = malloc(nBoxes * sizeof (BoxRec));
@@ -815,12 +815,12 @@ ProcXFixesExpandRegion (ClientPtr client)
 	    pTmp[i].y1 = pSrc[i].y1 - stuff->top;
 	    pTmp[i].y2 = pSrc[i].y2 + stuff->bottom;
 	}
-	REGION_EMPTY (pScreen, pDestination);
+	RegionEmpty(pDestination);
 	for (i = 0; i < nBoxes; i++)
 	{
 	    RegionRec	r;
-	    REGION_INIT (pScreen, &r, &pTmp[i], 0);
-	    REGION_UNION (pScreen, pDestination, pDestination, &r);
+	    RegionInit(&r, &pTmp[i], 0);
+	    RegionUnion(pDestination, pDestination, &r);
 	}
 	free(pTmp);
     }
commit d17e726e89ef644310de77b960b715c2d11088da
Author: Keith Packard <keithp at keithp.com>
Date:   Sat May 22 00:09:47 2010 -0700

    Move mi/miregion.c to dix/region.c
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/Makefile.am b/dix/Makefile.am
index 42b5121..5e2dad7 100644
--- a/dix/Makefile.am
+++ b/dix/Makefile.am
@@ -32,6 +32,7 @@ libdix_la_SOURCES = 	\
 	privates.c	\
 	property.c	\
 	ptrveloc.c	\
+	region.c	\
 	registry.c	\
 	resource.c	\
 	selection.c	\
diff --git a/dix/region.c b/dix/region.c
new file mode 100644
index 0000000..a561601
--- /dev/null
+++ b/dix/region.c
@@ -0,0 +1,1845 @@
+/***********************************************************
+
+Copyright 1987, 1988, 1989, 1998  The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ 
+
+Copyright 1987, 1988, 1989 by 
+Digital Equipment Corporation, Maynard, Massachusetts. 
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* The panoramix components contained the following notice */
+/*****************************************************************
+
+Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
+BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Digital Equipment Corporation
+shall not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from Digital
+Equipment Corporation.
+
+******************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "regionstr.h"
+#include <X11/Xprotostr.h>
+#include <X11/Xfuncproto.h>
+#include "gc.h"
+#include "mi.h"
+#include "mispans.h"
+#include <pixman.h>
+
+#undef assert
+#ifdef REGION_DEBUG
+#define assert(expr) { \
+            CARD32 *foo = NULL; \
+            if (!(expr)) { \
+                ErrorF("Assertion failed file %s, line %d: %s\n", \
+                       __FILE__, __LINE__, #expr); \
+                *foo = 0xdeadbeef; /* to get a backtrace */ \
+            } \
+        }
+#else
+#define assert(expr)
+#endif
+
+#define good(reg) assert(RegionIsValid(reg))
+
+/*
+ * The functions in this file implement the Region abstraction used extensively
+ * throughout the X11 sample server. A Region is simply a set of disjoint
+ * (non-overlapping) rectangles, plus an "extent" rectangle which is the
+ * smallest single rectangle that contains all the non-overlapping rectangles.
+ *
+ * A Region is implemented as a "y-x-banded" array of rectangles.  This array
+ * imposes two degrees of order.  First, all rectangles are sorted by top side
+ * y coordinate first (y1), and then by left side x coordinate (x1).
+ *
+ * Furthermore, the rectangles are grouped into "bands".  Each rectangle in a
+ * band has the same top y coordinate (y1), and each has the same bottom y
+ * coordinate (y2).  Thus all rectangles in a band differ only in their left
+ * and right side (x1 and x2).  Bands are implicit in the array of rectangles:
+ * there is no separate list of band start pointers.
+ *
+ * The y-x band representation does not minimize rectangles.  In particular,
+ * if a rectangle vertically crosses a band (the rectangle has scanlines in 
+ * the y1 to y2 area spanned by the band), then the rectangle may be broken
+ * down into two or more smaller rectangles stacked one atop the other. 
+ *
+ *  -----------				    -----------
+ *  |         |				    |         |		    band 0
+ *  |         |  --------		    -----------  --------
+ *  |         |  |      |  in y-x banded    |         |  |      |   band 1
+ *  |         |  |      |  form is	    |         |  |      |
+ *  -----------  |      |		    -----------  --------
+ *               |      |				 |      |   band 2
+ *               --------				 --------
+ *
+ * An added constraint on the rectangles is that they must cover as much
+ * horizontal area as possible: no two rectangles within a band are allowed
+ * to touch.
+ *
+ * Whenever possible, bands will be merged together to cover a greater vertical
+ * distance (and thus reduce the number of rectangles). Two bands can be merged
+ * only if the bottom of one touches the top of the other and they have
+ * rectangles in the same places (of the same width, of course).
+ *
+ * Adam de Boor wrote most of the original region code.  Joel McCormack
+ * substantially modified or rewrote most of the core arithmetic routines,
+ * and added RegionValidate in order to support several speed improvements
+ * to miValidateTree.  Bob Scheifler changed the representation to be more
+ * compact when empty or a single rectangle, and did a bunch of gratuitous
+ * reformatting.
+ */
+
+/*  true iff two Boxes overlap */
+#define EXTENTCHECK(r1,r2) \
+      (!( ((r1)->x2 <= (r2)->x1)  || \
+          ((r1)->x1 >= (r2)->x2)  || \
+          ((r1)->y2 <= (r2)->y1)  || \
+          ((r1)->y1 >= (r2)->y2) ) )
+
+/* true iff (x,y) is in Box */
+#define INBOX(r,x,y) \
+      ( ((r)->x2 >  x) && \
+        ((r)->x1 <= x) && \
+        ((r)->y2 >  y) && \
+        ((r)->y1 <= y) )
+
+/* true iff Box r1 contains Box r2 */
+#define SUBSUMES(r1,r2) \
+      ( ((r1)->x1 <= (r2)->x1) && \
+        ((r1)->x2 >= (r2)->x2) && \
+        ((r1)->y1 <= (r2)->y1) && \
+        ((r1)->y2 >= (r2)->y2) )
+
+#define xallocData(n) malloc(REGION_SZOF(n))
+#define xfreeData(reg) if ((reg)->data && (reg)->data->size) free((reg)->data)
+
+#define RECTALLOC_BAIL(pReg,n,bail) \
+if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
+    if (!RegionRectAlloc(pReg, n)) { goto bail; }
+
+#define RECTALLOC(pReg,n) \
+if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
+    if (!RegionRectAlloc(pReg, n)) { return FALSE; }
+
+#define ADDRECT(pNextRect,nx1,ny1,nx2,ny2)	\
+{						\
+    pNextRect->x1 = nx1;			\
+    pNextRect->y1 = ny1;			\
+    pNextRect->x2 = nx2;			\
+    pNextRect->y2 = ny2;			\
+    pNextRect++;				\
+}
+
+#define NEWRECT(pReg,pNextRect,nx1,ny1,nx2,ny2)			\
+{									\
+    if (!(pReg)->data || ((pReg)->data->numRects == (pReg)->data->size))\
+    {									\
+	if (!RegionRectAlloc(pReg, 1))					\
+	    return FALSE;						\
+	pNextRect = REGION_TOP(pReg);					\
+    }									\
+    ADDRECT(pNextRect,nx1,ny1,nx2,ny2);					\
+    pReg->data->numRects++;						\
+    assert(pReg->data->numRects<=pReg->data->size);			\
+}
+
+
+#define DOWNSIZE(reg,numRects)						 \
+if (((numRects) < ((reg)->data->size >> 1)) && ((reg)->data->size > 50)) \
+{									 \
+    RegDataPtr NewData;							 \
+    NewData = (RegDataPtr)realloc((reg)->data, REGION_SZOF(numRects));	 \
+    if (NewData)							 \
+    {									 \
+	NewData->size = (numRects);					 \
+	(reg)->data = NewData;						 \
+    }									 \
+}
+
+
+BoxRec RegionEmptyBox = {0, 0, 0, 0};
+RegDataRec RegionEmptyData = {0, 0};
+
+RegDataRec  RegionBrokenData = {0, 0};
+static RegionRec   RegionBrokenRegion = { { 0, 0, 0, 0 }, &RegionBrokenData };
+
+void
+InitRegions (void)
+{
+    pixman_region_set_static_pointers (&RegionEmptyBox, &RegionEmptyData, &RegionBrokenData);
+}
+
+/*****************************************************************
+ *   RegionCreate(rect, size)
+ *     This routine does a simple malloc to make a structure of
+ *     REGION of "size" number of rectangles.
+ *****************************************************************/
+
+RegionPtr
+RegionCreate(BoxPtr rect, int size)
+{
+    RegionPtr pReg;
+   
+    pReg = (RegionPtr)malloc(sizeof(RegionRec));
+    if (!pReg)
+	return &RegionBrokenRegion;
+
+    RegionInit (pReg, rect, size);
+    
+    return(pReg);
+}
+
+void
+RegionDestroy(RegionPtr pReg)
+{
+    pixman_region_fini (pReg);
+    if (pReg != &RegionBrokenRegion)
+	free(pReg);
+}
+
+void
+RegionPrint(RegionPtr rgn)
+{
+    int num, size;
+    int i;
+    BoxPtr rects;
+
+    num = REGION_NUM_RECTS(rgn);
+    size = REGION_SIZE(rgn);
+    rects = REGION_RECTS(rgn);
+    ErrorF("[mi] num: %d size: %d\n", num, size);
+    ErrorF("[mi] extents: %d %d %d %d\n",
+	   rgn->extents.x1, rgn->extents.y1, rgn->extents.x2, rgn->extents.y2);
+    for (i = 0; i < num; i++)
+      ErrorF("[mi] %d %d %d %d \n",
+	     rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2);
+    ErrorF("[mi] \n");
+}
+
+Bool
+RegionEqual(RegionPtr reg1, RegionPtr reg2)
+{
+    return pixman_region_equal (reg1, reg2);
+}
+
+#ifdef DEBUG
+Bool
+RegionIsValid(RegionPtr reg)
+{
+    int i, numRects;
+    
+    if ((reg->extents.x1 > reg->extents.x2) ||
+	(reg->extents.y1 > reg->extents.y2))
+	return FALSE;
+    numRects = REGION_NUM_RECTS(reg);
+    if (!numRects)
+	return ((reg->extents.x1 == reg->extents.x2) &&
+		(reg->extents.y1 == reg->extents.y2) &&
+		(reg->data->size || (reg->data == &RegionEmptyData)));
+    else if (numRects == 1)
+	return (!reg->data);
+    else
+    {
+	BoxPtr pboxP, pboxN;
+	BoxRec box;
+	
+	pboxP = REGION_RECTS(reg);
+	box = *pboxP;
+	box.y2 = pboxP[numRects-1].y2;
+	pboxN = pboxP + 1;
+	for (i = numRects; --i > 0; pboxP++, pboxN++)
+	{
+	    if ((pboxN->x1 >= pboxN->x2) ||
+		(pboxN->y1 >= pboxN->y2))
+		return FALSE;
+	    if (pboxN->x1 < box.x1)
+		box.x1 = pboxN->x1;
+	    if (pboxN->x2 > box.x2)
+		box.x2 = pboxN->x2;
+	    if ((pboxN->y1 < pboxP->y1) ||
+		((pboxN->y1 == pboxP->y1) &&
+		 ((pboxN->x1 < pboxP->x2) || (pboxN->y2 != pboxP->y2))))
+		return FALSE;
+	}
+	return ((box.x1 == reg->extents.x1) &&
+		(box.x2 == reg->extents.x2) &&
+		(box.y1 == reg->extents.y1) &&
+		(box.y2 == reg->extents.y2));
+    }
+}
+#endif /* DEBUG */
+
+/*****************************************************************
+ *   RegionInit(pReg, rect, size)
+ *     Outer region rect is statically allocated.
+ *****************************************************************/
+
+void
+RegionInit(RegionPtr pReg, BoxPtr rect, int size)
+{
+    if (rect)
+	pixman_region_init_with_extents (pReg, rect);
+    else
+	pixman_region_init (pReg);
+}
+
+void
+RegionUninit(RegionPtr pReg)
+{
+    pixman_region_fini (pReg);
+}
+
+Bool
+RegionBreak (RegionPtr pReg)
+{
+    xfreeData (pReg);
+    pReg->extents = RegionEmptyBox;
+    pReg->data = &RegionBrokenData;
+    return FALSE;
+}
+
+Bool
+RegionRectAlloc(RegionPtr pRgn, int n)
+{
+    RegDataPtr	data;
+    
+    if (!pRgn->data)
+    {
+	n++;
+	pRgn->data = xallocData(n);
+	if (!pRgn->data)
+	    return RegionBreak (pRgn);
+	pRgn->data->numRects = 1;
+	*REGION_BOXPTR(pRgn) = pRgn->extents;
+    }
+    else if (!pRgn->data->size)
+    {
+	pRgn->data = xallocData(n);
+	if (!pRgn->data)
+	    return RegionBreak (pRgn);
+	pRgn->data->numRects = 0;
+    }
+    else
+    {
+	if (n == 1)
+	{
+	    n = pRgn->data->numRects;
+	    if (n > 500) /* XXX pick numbers out of a hat */
+		n = 250;
+	}
+	n += pRgn->data->numRects;
+	data = (RegDataPtr)realloc(pRgn->data, REGION_SZOF(n));
+	if (!data)
+	    return RegionBreak (pRgn);
+	pRgn->data = data;
+    }
+    pRgn->data->size = n;
+    return TRUE;
+}
+
+Bool
+RegionCopy(RegionPtr dst, RegionPtr src)
+{
+    return pixman_region_copy (dst, src);
+}
+
+/*======================================================================
+ *	    Generic Region Operator
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionCoalesce --
+ *	Attempt to merge the boxes in the current band with those in the
+ *	previous one.  We are guaranteed that the current band extends to
+ *      the end of the rects array.  Used only by RegionOp.
+ *
+ * Results:
+ *	The new index for the previous band.
+ *
+ * Side Effects:
+ *	If coalescing takes place:
+ *	    - rectangles in the previous band will have their y2 fields
+ *	      altered.
+ *	    - pReg->data->numRects will be decreased.
+ *
+ *-----------------------------------------------------------------------
+ */
+_X_INLINE static int
+RegionCoalesce (
+    RegionPtr	pReg,	    	/* Region to coalesce		     */
+    int	    	  	prevStart,  	/* Index of start of previous band   */
+    int	    	  	curStart)   	/* Index of start of current band    */
+{
+    BoxPtr	pPrevBox;   	/* Current box in previous band	     */
+    BoxPtr	pCurBox;    	/* Current box in current band       */
+    int  	numRects;	/* Number rectangles in both bands   */
+    int		y2;		/* Bottom of current band	     */
+    /*
+     * Figure out how many rectangles are in the band.
+     */
+    numRects = curStart - prevStart;
+    assert(numRects == pReg->data->numRects - curStart);
+
+    if (!numRects) return curStart;
+
+    /*
+     * The bands may only be coalesced if the bottom of the previous
+     * matches the top scanline of the current.
+     */
+    pPrevBox = REGION_BOX(pReg, prevStart);
+    pCurBox = REGION_BOX(pReg, curStart);
+    if (pPrevBox->y2 != pCurBox->y1) return curStart;
+
+    /*
+     * Make sure the bands have boxes in the same places. This
+     * assumes that boxes have been added in such a way that they
+     * cover the most area possible. I.e. two boxes in a band must
+     * have some horizontal space between them.
+     */
+    y2 = pCurBox->y2;
+
+    do {
+	if ((pPrevBox->x1 != pCurBox->x1) || (pPrevBox->x2 != pCurBox->x2)) {
+	    return (curStart);
+	}
+	pPrevBox++;
+	pCurBox++;
+	numRects--;
+    } while (numRects);
+
+    /*
+     * The bands may be merged, so set the bottom y of each box
+     * in the previous band to the bottom y of the current band.
+     */
+    numRects = curStart - prevStart;
+    pReg->data->numRects -= numRects;
+    do {
+	pPrevBox--;
+	pPrevBox->y2 = y2;
+	numRects--;
+    } while (numRects);
+    return prevStart;
+}
+
+
+/* Quicky macro to avoid trivial reject procedure calls to RegionCoalesce */
+
+#define Coalesce(newReg, prevBand, curBand)				\
+    if (curBand - prevBand == newReg->data->numRects - curBand) {	\
+	prevBand = RegionCoalesce(newReg, prevBand, curBand);		\
+    } else {								\
+	prevBand = curBand;						\
+    }
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionAppendNonO --
+ *	Handle a non-overlapping band for the union and subtract operations.
+ *      Just adds the (top/bottom-clipped) rectangles into the region.
+ *      Doesn't have to check for subsumption or anything.
+ *
+ * Results:
+ *	None.
+ *
+ * Side Effects:
+ *	pReg->data->numRects is incremented and the rectangles overwritten
+ *	with the rectangles we're passed.
+ *
+ *-----------------------------------------------------------------------
+ */
+
+_X_INLINE static Bool
+RegionAppendNonO (
+    RegionPtr	pReg,
+    BoxPtr	r,
+    BoxPtr  	rEnd,
+    int  	y1,
+    int  	y2)
+{
+    BoxPtr	pNextRect;
+    int		newRects;
+
+    newRects = rEnd - r;
+
+    assert(y1 < y2);
+    assert(newRects != 0);
+
+    /* Make sure we have enough space for all rectangles to be added */
+    RECTALLOC(pReg, newRects);
+    pNextRect = REGION_TOP(pReg);
+    pReg->data->numRects += newRects;
+    do {
+	assert(r->x1 < r->x2);
+	ADDRECT(pNextRect, r->x1, y1, r->x2, y2);
+	r++;
+    } while (r != rEnd);
+
+    return TRUE;
+}
+
+#define FindBand(r, rBandEnd, rEnd, ry1)		    \
+{							    \
+    ry1 = r->y1;					    \
+    rBandEnd = r+1;					    \
+    while ((rBandEnd != rEnd) && (rBandEnd->y1 == ry1)) {   \
+	rBandEnd++;					    \
+    }							    \
+}
+
+#define	AppendRegions(newReg, r, rEnd)					\
+{									\
+    int newRects;							\
+    if ((newRects = rEnd - r)) {					\
+	RECTALLOC(newReg, newRects);					\
+	memmove((char *)REGION_TOP(newReg),(char *)r, 			\
+              newRects * sizeof(BoxRec));				\
+	newReg->data->numRects += newRects;				\
+    }									\
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionOp --
+ *	Apply an operation to two regions. Called by RegionUnion, RegionInverse,
+ *	RegionSubtract, RegionIntersect....  Both regions MUST have at least one
+ *      rectangle, and cannot be the same object.
+ *
+ * Results:
+ *	TRUE if successful.
+ *
+ * Side Effects:
+ *	The new region is overwritten.
+ *	pOverlap set to TRUE if overlapFunc ever returns TRUE.
+ *
+ * Notes:
+ *	The idea behind this function is to view the two regions as sets.
+ *	Together they cover a rectangle of area that this function divides
+ *	into horizontal bands where points are covered only by one region
+ *	or by both. For the first case, the nonOverlapFunc is called with
+ *	each the band and the band's upper and lower extents. For the
+ *	second, the overlapFunc is called to process the entire band. It
+ *	is responsible for clipping the rectangles in the band, though
+ *	this function provides the boundaries.
+ *	At the end of each band, the new region is coalesced, if possible,
+ *	to reduce the number of rectangles in the region.
+ *
+ *-----------------------------------------------------------------------
+ */
+
+typedef Bool (*OverlapProcPtr)(
+    RegionPtr	pReg,
+    BoxPtr	r1,
+    BoxPtr   	r1End,
+    BoxPtr	r2,
+    BoxPtr   	r2End,
+    short    	y1,
+    short    	y2,
+    Bool	*pOverlap);
+
+static Bool
+RegionOp(
+    RegionPtr       newReg,		    /* Place to store result	     */
+    RegionPtr       reg1,		    /* First region in operation     */
+    RegionPtr       reg2,		    /* 2d region in operation        */
+    OverlapProcPtr  overlapFunc,            /* Function to call for over-
+					     * lapping bands		     */
+    Bool	    appendNon1,		    /* Append non-overlapping bands  */
+					    /* in region 1 ? */
+    Bool	    appendNon2,		    /* Append non-overlapping bands  */
+					    /* in region 2 ? */
+    Bool	    *pOverlap)
+{
+    BoxPtr 	r1;		    /* Pointer into first region     */
+    BoxPtr 	r2;		    /* Pointer into 2d region	     */
+    BoxPtr	r1End;		    /* End of 1st region	     */
+    BoxPtr	r2End;		    /* End of 2d region		     */
+    short	ybot;		    /* Bottom of intersection	     */
+    short	ytop;		    /* Top of intersection	     */
+    RegDataPtr	oldData;	    /* Old data for newReg	     */
+    int		prevBand;	    /* Index of start of
+				     * previous band in newReg       */
+    int		curBand;	    /* Index of start of current
+				     * band in newReg		     */
+    BoxPtr  	r1BandEnd;	    /* End of current band in r1     */
+    BoxPtr  	r2BandEnd;	    /* End of current band in r2     */
+    short   	top;		    /* Top of non-overlapping band   */
+    short   	bot;	    	    /* Bottom of non-overlapping band*/
+    int     	r1y1;	    	    /* Temps for r1->y1 and r2->y1   */
+    int     	r2y1;
+    int	    	newSize;
+    int	    	numRects;
+
+    /*
+     * Break any region computed from a broken region
+     */
+    if (REGION_NAR (reg1) || REGION_NAR(reg2))
+	return RegionBreak (newReg);
+    
+    /*
+     * Initialization:
+     *	set r1, r2, r1End and r2End appropriately, save the rectangles
+     * of the destination region until the end in case it's one of
+     * the two source regions, then mark the "new" region empty, allocating
+     * another array of rectangles for it to use.
+     */
+
+    r1 = REGION_RECTS(reg1);
+    newSize = REGION_NUM_RECTS(reg1);
+    r1End = r1 + newSize;
+    numRects = REGION_NUM_RECTS(reg2);
+    r2 = REGION_RECTS(reg2);
+    r2End = r2 + numRects;
+    assert(r1 != r1End);
+    assert(r2 != r2End);
+
+    oldData = NULL;
+    if (((newReg == reg1) && (newSize > 1)) ||
+	((newReg == reg2) && (numRects > 1)))
+    {
+	oldData = newReg->data;
+	newReg->data = &RegionEmptyData;
+    }
+    /* guess at new size */
+    if (numRects > newSize)
+	newSize = numRects;
+    newSize <<= 1;
+    if (!newReg->data)
+	newReg->data = &RegionEmptyData;
+    else if (newReg->data->size)
+	newReg->data->numRects = 0;
+    if (newSize > newReg->data->size)
+	if (!RegionRectAlloc(newReg, newSize))
+	    return FALSE;
+
+    /*
+     * Initialize ybot.
+     * In the upcoming loop, ybot and ytop serve different functions depending
+     * on whether the band being handled is an overlapping or non-overlapping
+     * band.
+     * 	In the case of a non-overlapping band (only one of the regions
+     * has points in the band), ybot is the bottom of the most recent
+     * intersection and thus clips the top of the rectangles in that band.
+     * ytop is the top of the next intersection between the two regions and
+     * serves to clip the bottom of the rectangles in the current band.
+     *	For an overlapping band (where the two regions intersect), ytop clips
+     * the top of the rectangles of both regions and ybot clips the bottoms.
+     */
+
+    ybot = min(r1->y1, r2->y1);
+    
+    /*
+     * prevBand serves to mark the start of the previous band so rectangles
+     * can be coalesced into larger rectangles. qv. RegionCoalesce, above.
+     * In the beginning, there is no previous band, so prevBand == curBand
+     * (curBand is set later on, of course, but the first band will always
+     * start at index 0). prevBand and curBand must be indices because of
+     * the possible expansion, and resultant moving, of the new region's
+     * array of rectangles.
+     */
+    prevBand = 0;
+    
+    do {
+	/*
+	 * This algorithm proceeds one source-band (as opposed to a
+	 * destination band, which is determined by where the two regions
+	 * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the
+	 * rectangle after the last one in the current band for their
+	 * respective regions.
+	 */
+	assert(r1 != r1End);
+	assert(r2 != r2End);
+    
+	FindBand(r1, r1BandEnd, r1End, r1y1);
+	FindBand(r2, r2BandEnd, r2End, r2y1);
+
+	/*
+	 * First handle the band that doesn't intersect, if any.
+	 *
+	 * Note that attention is restricted to one band in the
+	 * non-intersecting region at once, so if a region has n
+	 * bands between the current position and the next place it overlaps
+	 * the other, this entire loop will be passed through n times.
+	 */
+	if (r1y1 < r2y1) {
+	    if (appendNon1) {
+		top = max(r1y1, ybot);
+		bot = min(r1->y2, r2y1);
+		if (top != bot)	{
+		    curBand = newReg->data->numRects;
+		    RegionAppendNonO(newReg, r1, r1BandEnd, top, bot);
+		    Coalesce(newReg, prevBand, curBand);
+		}
+	    }
+	    ytop = r2y1;
+	} else if (r2y1 < r1y1) {
+	    if (appendNon2) {
+		top = max(r2y1, ybot);
+		bot = min(r2->y2, r1y1);
+		if (top != bot) {
+		    curBand = newReg->data->numRects;
+		    RegionAppendNonO(newReg, r2, r2BandEnd, top, bot);
+		    Coalesce(newReg, prevBand, curBand);
+		}
+	    }
+	    ytop = r1y1;
+	} else {
+	    ytop = r1y1;
+	}
+
+	/*
+	 * Now see if we've hit an intersecting band. The two bands only
+	 * intersect if ybot > ytop
+	 */
+	ybot = min(r1->y2, r2->y2);
+	if (ybot > ytop) {
+	    curBand = newReg->data->numRects;
+	    (* overlapFunc)(newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot,
+			    pOverlap);
+	    Coalesce(newReg, prevBand, curBand);
+	}
+
+	/*
+	 * If we've finished with a band (y2 == ybot) we skip forward
+	 * in the region to the next band.
+	 */
+	if (r1->y2 == ybot) r1 = r1BandEnd;
+	if (r2->y2 == ybot) r2 = r2BandEnd;
+
+    } while (r1 != r1End && r2 != r2End);
+
+    /*
+     * Deal with whichever region (if any) still has rectangles left.
+     *
+     * We only need to worry about banding and coalescing for the very first
+     * band left.  After that, we can just group all remaining boxes,
+     * regardless of how many bands, into one final append to the list.
+     */
+
+    if ((r1 != r1End) && appendNon1) {
+	/* Do first nonOverlap1Func call, which may be able to coalesce */
+	FindBand(r1, r1BandEnd, r1End, r1y1);
+	curBand = newReg->data->numRects;
+	RegionAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2);
+	Coalesce(newReg, prevBand, curBand);
+	/* Just append the rest of the boxes  */
+	AppendRegions(newReg, r1BandEnd, r1End);
+
+    } else if ((r2 != r2End) && appendNon2) {
+	/* Do first nonOverlap2Func call, which may be able to coalesce */
+	FindBand(r2, r2BandEnd, r2End, r2y1);
+	curBand = newReg->data->numRects;
+	RegionAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2);
+	Coalesce(newReg, prevBand, curBand);
+	/* Append rest of boxes */
+	AppendRegions(newReg, r2BandEnd, r2End);
+    }
+
+    if (oldData)
+	free(oldData);
+
+    if (!(numRects = newReg->data->numRects))
+    {
+	xfreeData(newReg);
+	newReg->data = &RegionEmptyData;
+    }
+    else if (numRects == 1)
+    {
+	newReg->extents = *REGION_BOXPTR(newReg);
+	xfreeData(newReg);
+	newReg->data = NULL;
+    }
+    else
+    {
+	DOWNSIZE(newReg, numRects);
+    }
+
+    return TRUE;
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionSetExtents --
+ *	Reset the extents of a region to what they should be. Called by
+ *	RegionSubtract and RegionIntersect as they can't figure it out along the
+ *	way or do so easily, as RegionUnion can.
+ *
+ * Results:
+ *	None.
+ *
+ * Side Effects:
+ *	The region's 'extents' structure is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+static void
+RegionSetExtents (RegionPtr pReg)
+{
+    BoxPtr pBox, pBoxEnd;
+
+    if (!pReg->data)
+	return;
+    if (!pReg->data->size)
+    {
+	pReg->extents.x2 = pReg->extents.x1;
+	pReg->extents.y2 = pReg->extents.y1;
+	return;
+    }
+
+    pBox = REGION_BOXPTR(pReg);
+    pBoxEnd = REGION_END(pReg);
+
+    /*
+     * Since pBox is the first rectangle in the region, it must have the
+     * smallest y1 and since pBoxEnd is the last rectangle in the region,
+     * it must have the largest y2, because of banding. Initialize x1 and
+     * x2 from  pBox and pBoxEnd, resp., as good things to initialize them
+     * to...
+     */
+    pReg->extents.x1 = pBox->x1;
+    pReg->extents.y1 = pBox->y1;
+    pReg->extents.x2 = pBoxEnd->x2;
+    pReg->extents.y2 = pBoxEnd->y2;
+
+    assert(pReg->extents.y1 < pReg->extents.y2);
+    while (pBox <= pBoxEnd) {
+	if (pBox->x1 < pReg->extents.x1)
+	    pReg->extents.x1 = pBox->x1;
+	if (pBox->x2 > pReg->extents.x2)
+	    pReg->extents.x2 = pBox->x2;
+	pBox++;
+    };
+
+    assert(pReg->extents.x1 < pReg->extents.x2);
+}
+
+/*======================================================================
+ *	    Region Intersection
+ *====================================================================*/
+/*-
+ *-----------------------------------------------------------------------
+ * RegionIntersectO --
+ *	Handle an overlapping band for RegionIntersect.
+ *
+ * Results:
+ *	TRUE if successful.
+ *
+ * Side Effects:
+ *	Rectangles may be added to the region.
+ *
+ *-----------------------------------------------------------------------
+ */
+/*ARGSUSED*/
+Bool
+RegionIntersect(
+    RegionPtr	newReg,     /* destination Region */
+    RegionPtr	reg1,
+    RegionPtr	reg2        /* source regions     */
+    )
+{
+    return pixman_region_intersect (newReg, reg1, reg2);
+}
+
+#define MERGERECT(r)						\
+{								\
+    if (r->x1 <= x2) {						\
+	/* Merge with current rectangle */			\
+	if (r->x1 < x2) *pOverlap = TRUE;				\
+	if (x2 < r->x2) x2 = r->x2;				\
+    } else {							\
+	/* Add current rectangle, start new one */		\
+	NEWRECT(pReg, pNextRect, x1, y1, x2, y2);		\
+	x1 = r->x1;						\
+	x2 = r->x2;						\
+    }								\
+    r++;							\
+}
+
+/*======================================================================
+ *	    Region Union
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionUnionO --
+ *	Handle an overlapping band for the union operation. Picks the
+ *	left-most rectangle each time and merges it into the region.
+ *
+ * Results:
+ *	TRUE if successful.
+ *
+ * Side Effects:
+ *	pReg is overwritten.
+ *	pOverlap is set to TRUE if any boxes overlap.
+ *
+ *-----------------------------------------------------------------------
+ */
+static Bool
+RegionUnionO (
+    RegionPtr	pReg,
+    BoxPtr	r1,
+    BoxPtr  	r1End,
+    BoxPtr	r2,
+    BoxPtr  	r2End,
+    short	y1,
+    short	y2,
+    Bool	*pOverlap)
+{
+    BoxPtr     pNextRect;
+    int        x1;     /* left and right side of current union */
+    int        x2;
+
+    assert (y1 < y2);
+    assert(r1 != r1End && r2 != r2End);
+
+    pNextRect = REGION_TOP(pReg);
+
+    /* Start off current rectangle */
+    if (r1->x1 < r2->x1)
+    {
+	x1 = r1->x1;
+	x2 = r1->x2;
+	r1++;
+    }
+    else
+    {
+	x1 = r2->x1;
+	x2 = r2->x2;
+	r2++;
+    }
+    while (r1 != r1End && r2 != r2End)
+    {
+	if (r1->x1 < r2->x1) MERGERECT(r1) else MERGERECT(r2);
+    }
+
+    /* Finish off whoever (if any) is left */
+    if (r1 != r1End)
+    {
+	do
+	{
+	    MERGERECT(r1);
+	} while (r1 != r1End);
+    }
+    else if (r2 != r2End)
+    {
+	do
+	{
+	    MERGERECT(r2);
+	} while (r2 != r2End);
+    }
+    
+    /* Add current rectangle */
+    NEWRECT(pReg, pNextRect, x1, y1, x2, y2);
+
+    return TRUE;
+}
+
+Bool
+RegionUnion(
+    RegionPtr	newReg,          /* destination Region */
+    RegionPtr	reg1,
+    RegionPtr	reg2             /* source regions     */
+    )
+{
+    return pixman_region_union (newReg, reg1, reg2);
+}
+
+/*======================================================================
+ *	    Batch Rectangle Union
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionAppend --
+ * 
+ *      "Append" the rgn rectangles onto the end of dstrgn, maintaining
+ *      knowledge of YX-banding when it's easy.  Otherwise, dstrgn just
+ *      becomes a non-y-x-banded random collection of rectangles, and not
+ *      yet a true region.  After a sequence of appends, the caller must
+ *      call RegionValidate to ensure that a valid region is constructed.
+ *
+ * Results:
+ *	TRUE if successful.
+ *
+ * Side Effects:
+ *      dstrgn is modified if rgn has rectangles.
+ *
+ */
+Bool
+RegionAppend(RegionPtr dstrgn, RegionPtr rgn)
+{
+    int numRects, dnumRects, size;
+    BoxPtr new, old;
+    Bool prepend;
+
+    if (REGION_NAR(rgn))
+	return RegionBreak (dstrgn);
+    
+    if (!rgn->data && (dstrgn->data == &RegionEmptyData))
+    {
+	dstrgn->extents = rgn->extents;
+	dstrgn->data = NULL;
+	return TRUE;
+    }
+
+    numRects = REGION_NUM_RECTS(rgn);
+    if (!numRects)
+	return TRUE;
+    prepend = FALSE;
+    size = numRects;
+    dnumRects = REGION_NUM_RECTS(dstrgn);
+    if (!dnumRects && (size < 200))
+	size = 200; /* XXX pick numbers out of a hat */
+    RECTALLOC(dstrgn, size);
+    old = REGION_RECTS(rgn);
+    if (!dnumRects)
+	dstrgn->extents = rgn->extents;
+    else if (dstrgn->extents.x2 > dstrgn->extents.x1)
+    {
+	BoxPtr first, last;
+
+	first = old;
+	last = REGION_BOXPTR(dstrgn) + (dnumRects - 1);
+	if ((first->y1 > last->y2) ||
+	    ((first->y1 == last->y1) && (first->y2 == last->y2) &&
+	     (first->x1 > last->x2)))
+	{
+	    if (rgn->extents.x1 < dstrgn->extents.x1)
+		dstrgn->extents.x1 = rgn->extents.x1;
+	    if (rgn->extents.x2 > dstrgn->extents.x2)
+		dstrgn->extents.x2 = rgn->extents.x2;
+	    dstrgn->extents.y2 = rgn->extents.y2;
+	}
+	else
+	{
+	    first = REGION_BOXPTR(dstrgn);
+	    last = old + (numRects - 1);
+	    if ((first->y1 > last->y2) ||
+		((first->y1 == last->y1) && (first->y2 == last->y2) &&
+		 (first->x1 > last->x2)))
+	    {
+		prepend = TRUE;
+		if (rgn->extents.x1 < dstrgn->extents.x1)
+		    dstrgn->extents.x1 = rgn->extents.x1;
+		if (rgn->extents.x2 > dstrgn->extents.x2)
+		    dstrgn->extents.x2 = rgn->extents.x2;
+		dstrgn->extents.y1 = rgn->extents.y1;
+	    }
+	    else
+		dstrgn->extents.x2 = dstrgn->extents.x1;
+	}
+    }
+    if (prepend)
+    {
+	new = REGION_BOX(dstrgn, numRects);
+	if (dnumRects == 1)
+	    *new = *REGION_BOXPTR(dstrgn);
+	else
+	    memmove((char *)new,(char *)REGION_BOXPTR(dstrgn), 
+		  dnumRects * sizeof(BoxRec));
+	new = REGION_BOXPTR(dstrgn);
+    }
+    else
+	new = REGION_BOXPTR(dstrgn) + dnumRects;
+    if (numRects == 1)
+	*new = *old;
+    else
+	memmove((char *)new, (char *)old, numRects * sizeof(BoxRec));
+    dstrgn->data->numRects += numRects;
+    return TRUE;
+}
+
+   
+#define ExchangeRects(a, b) \
+{			    \
+    BoxRec     t;	    \
+    t = rects[a];	    \
+    rects[a] = rects[b];    \
+    rects[b] = t;	    \
+}
+
+static void
+QuickSortRects(
+    BoxRec     rects[],
+    int        numRects)
+{
+    int	y1;
+    int	x1;
+    int        i, j;
+    BoxPtr     r;
+
+    /* Always called with numRects > 1 */
+
+    do
+    {
+	if (numRects == 2)
+	{
+	    if (rects[0].y1 > rects[1].y1 ||
+		    (rects[0].y1 == rects[1].y1 && rects[0].x1 > rects[1].x1))
+		ExchangeRects(0, 1);
+	    return;
+	}
+
+	/* Choose partition element, stick in location 0 */
+        ExchangeRects(0, numRects >> 1);
+	y1 = rects[0].y1;
+	x1 = rects[0].x1;
+
+        /* Partition array */
+        i = 0;
+        j = numRects;
+        do
+	{
+	    r = &(rects[i]);
+	    do
+	    {
+		r++;
+		i++;
+            } while (i != numRects &&
+		     (r->y1 < y1 || (r->y1 == y1 && r->x1 < x1)));
+	    r = &(rects[j]);
+	    do
+	    {
+		r--;
+		j--;
+            } while (y1 < r->y1 || (y1 == r->y1 && x1 < r->x1));
+            if (i < j)
+		ExchangeRects(i, j);
+        } while (i < j);
+
+        /* Move partition element back to middle */
+        ExchangeRects(0, j);
+
+	/* Recurse */
+        if (numRects-j-1 > 1)
+	    QuickSortRects(&rects[j+1], numRects-j-1);
+        numRects = j;
+    } while (numRects > 1);
+}
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionValidate --
+ * 
+ *      Take a ``region'' which is a non-y-x-banded random collection of
+ *      rectangles, and compute a nice region which is the union of all the
+ *      rectangles.
+ *
+ * Results:
+ *	TRUE if successful.
+ *
+ * Side Effects:
+ *      The passed-in ``region'' may be modified.
+ *	pOverlap set to TRUE if any retangles overlapped, else FALSE;
+ *
+ * Strategy:
+ *      Step 1. Sort the rectangles into ascending order with primary key y1
+ *		and secondary key x1.
+ *
+ *      Step 2. Split the rectangles into the minimum number of proper y-x
+ *		banded regions.  This may require horizontally merging
+ *		rectangles, and vertically coalescing bands.  With any luck,
+ *		this step in an identity tranformation (ala the Box widget),
+ *		or a coalescing into 1 box (ala Menus).
+ *
+ *	Step 3. Merge the separate regions down to a single region by calling
+ *		RegionUnion.  Maximize the work each RegionUnion call does by using
+ *		a binary merge.
+ *
+ *-----------------------------------------------------------------------
+ */
+
+Bool
+RegionValidate(RegionPtr badreg, Bool *pOverlap)
+{
+    /* Descriptor for regions under construction  in Step 2. */
+    typedef struct {
+	RegionRec   reg;
+	int	    prevBand;
+	int	    curBand;
+    } RegionInfo;
+
+    int	numRects;   /* Original numRects for badreg	    */
+    RegionInfo *ri;	    /* Array of current regions		    */
+    int	numRI;      /* Number of entries used in ri	    */
+    int	sizeRI;	    /* Number of entries available in ri    */
+    int	i;	    /* Index into rects			    */
+    int	j;	    /* Index into ri			    */
+    RegionInfo *rit;       /* &ri[j]				    */
+    RegionPtr  reg;        /* ri[j].reg			    */
+    BoxPtr	box;	    /* Current box in rects		    */
+    BoxPtr	riBox;      /* Last box in ri[j].reg		    */
+    RegionPtr  hreg;       /* ri[j_half].reg			    */
+    Bool		ret = TRUE;
+
+    *pOverlap = FALSE;
+    if (!badreg->data)
+    {
+	good(badreg);
+	return TRUE;
+    }
+    numRects = badreg->data->numRects;
+    if (!numRects)
+    {
+	if (REGION_NAR(badreg))
+	    return FALSE;
+	good(badreg);
+	return TRUE;
+    }
+    if (badreg->extents.x1 < badreg->extents.x2)
+    {
+	if ((numRects) == 1)
+	{
+	    xfreeData(badreg);
+	    badreg->data = (RegDataPtr) NULL;
+	}
+	else
+	{
+	    DOWNSIZE(badreg, numRects);
+	}
+	good(badreg);
+	return TRUE;
+    }
+
+    /* Step 1: Sort the rects array into ascending (y1, x1) order */
+    QuickSortRects(REGION_BOXPTR(badreg), numRects);
+
+    /* Step 2: Scatter the sorted array into the minimum number of regions */
+
+    /* Set up the first region to be the first rectangle in badreg */
+    /* Note that step 2 code will never overflow the ri[0].reg rects array */
+    ri = (RegionInfo *) malloc(4 * sizeof(RegionInfo));
+    if (!ri)
+	return RegionBreak (badreg);
+    sizeRI = 4;
+    numRI = 1;
+    ri[0].prevBand = 0;
+    ri[0].curBand = 0;
+    ri[0].reg = *badreg;
+    box = REGION_BOXPTR(&ri[0].reg);
+    ri[0].reg.extents = *box;
+    ri[0].reg.data->numRects = 1;
+
+    /* Now scatter rectangles into the minimum set of valid regions.  If the
+       next rectangle to be added to a region would force an existing rectangle
+       in the region to be split up in order to maintain y-x banding, just
+       forget it.  Try the next region.  If it doesn't fit cleanly into any
+       region, make a new one. */
+
+    for (i = numRects; --i > 0;)
+    {
+	box++;
+	/* Look for a region to append box to */
+	for (j = numRI, rit = ri; --j >= 0; rit++)
+	{
+	    reg = &rit->reg;
+	    riBox = REGION_END(reg);
+
+	    if (box->y1 == riBox->y1 && box->y2 == riBox->y2)
+	    {
+		/* box is in same band as riBox.  Merge or append it */
+		if (box->x1 <= riBox->x2)
+		{
+		    /* Merge it with riBox */
+		    if (box->x1 < riBox->x2) *pOverlap = TRUE;
+		    if (box->x2 > riBox->x2) riBox->x2 = box->x2;
+		}
+		else
+		{
+		    RECTALLOC_BAIL(reg, 1, bail);
+		    *REGION_TOP(reg) = *box;
+		    reg->data->numRects++;
+		}
+		goto NextRect;   /* So sue me */
+	    }
+	    else if (box->y1 >= riBox->y2)
+	    {
+		/* Put box into new band */
+		if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2;
+		if (reg->extents.x1 > box->x1)   reg->extents.x1 = box->x1;
+		Coalesce(reg, rit->prevBand, rit->curBand);
+		rit->curBand = reg->data->numRects;
+		RECTALLOC_BAIL(reg, 1, bail);
+		*REGION_TOP(reg) = *box;
+		reg->data->numRects++;
+		goto NextRect;
+	    }
+	    /* Well, this region was inappropriate.  Try the next one. */
+	} /* for j */
+
+	/* Uh-oh.  No regions were appropriate.  Create a new one. */
+	if (sizeRI == numRI)
+	{
+	    /* Oops, allocate space for new region information */
+	    sizeRI <<= 1;
+	    rit = (RegionInfo *) realloc(ri, sizeRI * sizeof(RegionInfo));
+	    if (!rit)
+		goto bail;
+	    ri = rit;
+	    rit = &ri[numRI];
+	}
+	numRI++;
+	rit->prevBand = 0;
+	rit->curBand = 0;
+	rit->reg.extents = *box;
+	rit->reg.data = NULL;
+	if (!RegionRectAlloc(&rit->reg, (i+numRI) / numRI)) /* MUST force allocation */
+	    goto bail;
+NextRect: ;
+    } /* for i */
+
+    /* Make a final pass over each region in order to Coalesce and set
+       extents.x2 and extents.y2 */
+
+    for (j = numRI, rit = ri; --j >= 0; rit++)
+    {
+	reg = &rit->reg;
+	riBox = REGION_END(reg);
+	reg->extents.y2 = riBox->y2;
+	if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2;
+	Coalesce(reg, rit->prevBand, rit->curBand);
+	if (reg->data->numRects == 1) /* keep unions happy below */
+	{
+	    xfreeData(reg);
+	    reg->data = NULL;
+	}
+    }
+
+    /* Step 3: Union all regions into a single region */
+    while (numRI > 1)
+    {
+	int half = numRI/2;
+	for (j = numRI & 1; j < (half + (numRI & 1)); j++)
+	{
+	    reg = &ri[j].reg;
+	    hreg = &ri[j+half].reg;
+	    if (!RegionOp(reg, reg, hreg, RegionUnionO, TRUE, TRUE, pOverlap))
+		ret = FALSE;
+	    if (hreg->extents.x1 < reg->extents.x1)
+		reg->extents.x1 = hreg->extents.x1;
+	    if (hreg->extents.y1 < reg->extents.y1)
+		reg->extents.y1 = hreg->extents.y1;
+	    if (hreg->extents.x2 > reg->extents.x2)
+		reg->extents.x2 = hreg->extents.x2;
+	    if (hreg->extents.y2 > reg->extents.y2)
+		reg->extents.y2 = hreg->extents.y2;
+	    xfreeData(hreg);
+	}
+	numRI -= half;
+    }
+    *badreg = ri[0].reg;
+    free(ri);
+    good(badreg);
+    return ret;
+bail:
+    for (i = 0; i < numRI; i++)
+	xfreeData(&ri[i].reg);
+    free(ri);
+    return RegionBreak (badreg);
+}
+
+RegionPtr
+RegionFromRects(int nrects, xRectangle *prect, int ctype)
+{
+    
+    RegionPtr		pRgn;
+    RegDataPtr		pData;
+    BoxPtr		pBox;
+    int        		i;
+    int			x1, y1, x2, y2;
+
+    pRgn = RegionCreate(NullBox, 0);
+    if (REGION_NAR (pRgn))
+	return pRgn;
+    if (!nrects)
+	return pRgn;
+    if (nrects == 1)
+    {
+	x1 = prect->x;
+	y1 = prect->y;
+	if ((x2 = x1 + (int) prect->width) > MAXSHORT)
+	    x2 = MAXSHORT;
+	if ((y2 = y1 + (int) prect->height) > MAXSHORT)
+	    y2 = MAXSHORT;
+	if (x1 != x2 && y1 != y2)
+	{
+	    pRgn->extents.x1 = x1;
+	    pRgn->extents.y1 = y1;
+	    pRgn->extents.x2 = x2;
+	    pRgn->extents.y2 = y2;
+	    pRgn->data = NULL;
+	}
+	return pRgn;
+    }
+    pData = xallocData(nrects);
+    if (!pData)
+    {
+	RegionBreak (pRgn);
+	return pRgn;
+    }
+    pBox = (BoxPtr) (pData + 1);
+    for (i = nrects; --i >= 0; prect++)
+    {
+	x1 = prect->x;
+	y1 = prect->y;
+	if ((x2 = x1 + (int) prect->width) > MAXSHORT)
+	    x2 = MAXSHORT;
+	if ((y2 = y1 + (int) prect->height) > MAXSHORT)
+	    y2 = MAXSHORT;
+	if (x1 != x2 && y1 != y2)
+	{
+	    pBox->x1 = x1;
+	    pBox->y1 = y1;
+	    pBox->x2 = x2;
+	    pBox->y2 = y2;
+	    pBox++;
+	}
+    }
+    if (pBox != (BoxPtr) (pData + 1))
+    {
+	pData->size = nrects;
+	pData->numRects = pBox - (BoxPtr) (pData + 1);
+    	pRgn->data = pData;
+    	if (ctype != CT_YXBANDED)
+    	{
+	    Bool overlap; /* result ignored */
+	    pRgn->extents.x1 = pRgn->extents.x2 = 0;
+	    RegionValidate(pRgn, &overlap);
+    	}
+    	else
+	    RegionSetExtents(pRgn);
+    	good(pRgn);
+    }
+    else
+    {
+	free(pData);
+    }
+    return pRgn;
+}
+
+/*======================================================================
+ * 	    	  Region Subtraction
+ *====================================================================*/
+
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionSubtractO --
+ *	Overlapping band subtraction. x1 is the left-most point not yet
+ *	checked.
+ *
+ * Results:
+ *	TRUE if successful.
+ *
+ * Side Effects:
+ *	pReg may have rectangles added to it.
+ *
+ *-----------------------------------------------------------------------
+ */
+/*ARGSUSED*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionSubtract --
+ *	Subtract regS from regM and leave the result in regD.
+ *	S stands for subtrahend, M for minuend and D for difference.
+ *
+ * Results:
+ *	TRUE if successful.
+ *
+ * Side Effects:
+ *	regD is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+Bool
+RegionSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
+{
+    return pixman_region_subtract (regD, regM, regS);
+}
+
+/*======================================================================
+ *	    Region Inversion
+ *====================================================================*/
+
+/*-
+ *-----------------------------------------------------------------------
+ * RegionInverse --
+ *	Take a region and a box and return a region that is everything
+ *	in the box but not in the region. The careful reader will note
+ *	that this is the same as subtracting the region from the box...
+ *
+ * Results:
+ *	TRUE.
+ *
+ * Side Effects:
+ *	newReg is overwritten.
+ *
+ *-----------------------------------------------------------------------
+ */
+Bool
+RegionInverse(
+    RegionPtr	  newReg,       /* Destination region */
+    RegionPtr	  reg1,         /* Region to invert */
+    BoxPtr	  invRect	/* Bounding box for inversion */
+    )
+{
+    return pixman_region_inverse (newReg, reg1, invRect);
+}
+int
+RegionContainsRect(RegionPtr region, BoxPtr prect)
+{
+    return pixman_region_contains_rectangle (region, prect);
+}
+
+/* TranslateRegion(pReg, x, y)
+   translates in place
+*/
+
+void
+RegionTranslate(RegionPtr pReg, int x, int y)
+{
+    pixman_region_translate (pReg, x, y);
+}
+
+void
+RegionReset(RegionPtr pReg, BoxPtr pBox)
+{
+    pixman_region_reset (pReg, pBox);
+}
+
+Bool
+RegionContainsPoint(
+    RegionPtr pReg,
+    int x,
+    int y,
+    BoxPtr box      /* "return" value */
+    )
+{
+    return pixman_region_contains_point (pReg, x, y, box);
+}
+
+Bool
+RegionNotEmpty(RegionPtr pReg)
+{
+    return pixman_region_not_empty (pReg);
+}
+
+Bool
+RegionBroken(RegionPtr pReg)
+{
+    good(pReg);
+    return (REGION_NAR(pReg));
+}
+
+void
+RegionEmpty(RegionPtr pReg)
+{
+    good(pReg);
+    xfreeData(pReg);
+    pReg->extents.x2 = pReg->extents.x1;
+    pReg->extents.y2 = pReg->extents.y1;
+    pReg->data = &RegionEmptyData;
+}
+
+BoxPtr
+RegionExtents(RegionPtr pReg)
+{
+    good(pReg);
+    return(&pReg->extents);
+}
+
+#define ExchangeSpans(a, b)				    \
+{							    \
+    DDXPointRec	tpt;				    	    \
+    int    	tw;					    \
+							    \
+    tpt = spans[a]; spans[a] = spans[b]; spans[b] = tpt;    \
+    tw = widths[a]; widths[a] = widths[b]; widths[b] = tw;  \
+}
+
+/* ||| I should apply the merge sort code to rectangle sorting above, and see
+   if mapping time can be improved.  But right now I've been at work 12 hours,
+   so forget it.
+*/
+
+static void QuickSortSpans(
+    DDXPointRec spans[],
+    int	    	widths[],
+    int	    	numSpans)
+{
+    int	    y;
+    int	    i, j, m;
+    DDXPointPtr    r;
+
+    /* Always called with numSpans > 1 */
+    /* Sorts only by y, doesn't bother to sort by x */
+
+    do
+    {
+	if (numSpans < 9)
+	{
+	    /* Do insertion sort */
+	    int yprev;
+
+	    yprev = spans[0].y;
+	    i = 1;
+	    do
+	    { /* while i != numSpans */
+		y = spans[i].y;
+		if (yprev > y)
+		{
+		    /* spans[i] is out of order.  Move into proper location. */
+		    DDXPointRec tpt;
+		    int	    tw, k;
+
+		    for (j = 0; y >= spans[j].y; j++) {}
+		    tpt = spans[i];
+		    tw  = widths[i];
+		    for (k = i; k != j; k--)
+		    {
+			spans[k] = spans[k-1];
+			widths[k] = widths[k-1];
+		    }
+		    spans[j] = tpt;
+		    widths[j] = tw;
+		    y = spans[i].y;
+		} /* if out of order */
+		yprev = y;
+		i++;
+	    } while (i != numSpans);
+	    return;
+	}
+
+	/* Choose partition element, stick in location 0 */
+	m = numSpans / 2;
+	if (spans[m].y > spans[0].y)		ExchangeSpans(m, 0);
+	if (spans[m].y > spans[numSpans-1].y)   ExchangeSpans(m, numSpans-1);
+	if (spans[m].y > spans[0].y)		ExchangeSpans(m, 0);
+	y = spans[0].y;
+
+        /* Partition array */
+        i = 0;
+        j = numSpans;
+        do
+	{
+	    r = &(spans[i]);
+	    do
+	    {
+		r++;
+		i++;
+            } while (i != numSpans && r->y < y);
+	    r = &(spans[j]);
+	    do
+	    {
+		r--;
+		j--;
+            } while (y < r->y);
+            if (i < j)
+		ExchangeSpans(i, j);
+        } while (i < j);
+
+        /* Move partition element back to middle */
+        ExchangeSpans(0, j);
+
+	/* Recurse */
+        if (numSpans-j-1 > 1)
+	    QuickSortSpans(&spans[j+1], &widths[j+1], numSpans-j-1);
+        numSpans = j;
+    } while (numSpans > 1);
+}
+
+#define NextBand()						    \
+{								    \
+    clipy1 = pboxBandStart->y1;					    \
+    clipy2 = pboxBandStart->y2;					    \
+    pboxBandEnd = pboxBandStart + 1;				    \
+    while (pboxBandEnd != pboxLast && pboxBandEnd->y1 == clipy1) {  \
+	pboxBandEnd++;						    \
+    }								    \
+    for (; ppt != pptLast && ppt->y < clipy1; ppt++, pwidth++) {} \
+}
+
+/*
+    Clip a list of scanlines to a region.  The caller has allocated the
+    space.  FSorted is non-zero if the scanline origins are in ascending
+    order.
+    returns the number of new, clipped scanlines.
+*/
+
+int
+RegionClipSpans(
+    RegionPtr	prgnDst,
+    DDXPointPtr ppt,
+    int	    	*pwidth,
+    int		nspans,
+    DDXPointPtr	pptNew,
+    int		*pwidthNew,
+    int		fSorted)
+{
+    DDXPointPtr pptLast;
+    int	*pwidthNewStart;	/* the vengeance of Xerox! */
+    int	y, x1, x2;
+    int	numRects;
+
+    good(prgnDst);
+    pptLast = ppt + nspans;
+    pwidthNewStart = pwidthNew;
+
+    if (!prgnDst->data)
+    {
+	/* Do special fast code with clip boundaries in registers(?) */
+	/* It doesn't pay much to make use of fSorted in this case, 
+	   so we lump everything together. */
+
+	int clipx1, clipx2, clipy1, clipy2;
+
+	clipx1 = prgnDst->extents.x1;
+	clipy1 = prgnDst->extents.y1;
+	clipx2 = prgnDst->extents.x2;
+	clipy2 = prgnDst->extents.y2;
+	    
+	for (; ppt != pptLast; ppt++, pwidth++)
+	{
+	    y = ppt->y;
+	    x1 = ppt->x;
+	    if (clipy1 <= y && y < clipy2)
+	    {
+		x2 = x1 + *pwidth;
+		if (x1 < clipx1)    x1 = clipx1;
+		if (x2 > clipx2)    x2 = clipx2;
+		if (x1 < x2)
+		{
+		    /* part of span in clip rectangle */
+		    pptNew->x = x1;
+		    pptNew->y = y;
+		    *pwidthNew = x2 - x1;
+		    pptNew++;
+		    pwidthNew++;
+		}
+	    }
+	} /* end for */
+
+    }
+    else if ((numRects = prgnDst->data->numRects))
+    {
+	/* Have to clip against many boxes */
+	BoxPtr pboxBandStart, pboxBandEnd;
+	BoxPtr pbox;
+	BoxPtr pboxLast;
+	int clipy1, clipy2;
+
+	/* In this case, taking advantage of sorted spans gains more than
+	   the sorting costs. */
+	if ((! fSorted) && (nspans > 1))
+	    QuickSortSpans(ppt, pwidth, nspans);
+
+	pboxBandStart = REGION_BOXPTR(prgnDst);
+	pboxLast = pboxBandStart + numRects;
+    
+	NextBand();
+
+	for (; ppt != pptLast; )
+	{
+	    y = ppt->y;
+	    if (y < clipy2)
+	    {
+		/* span is in the current band */
+		pbox = pboxBandStart;
+		x1 = ppt->x;
+		x2 = x1 + *pwidth;
+		do
+		{ /* For each box in band */
+		    int newx1, newx2;
+
+		    newx1 = x1;
+		    newx2 = x2;
+		    if (newx1 < pbox->x1)   newx1 = pbox->x1;
+		    if (newx2 > pbox->x2)   newx2 = pbox->x2;
+		    if (newx1 < newx2)
+		    {
+			/* Part of span in clip rectangle */
+			pptNew->x = newx1;
+			pptNew->y = y;
+			*pwidthNew = newx2 - newx1;
+			pptNew++;
+			pwidthNew++;
+		    }
+		    pbox++;
+		} while (pbox != pboxBandEnd);
+		ppt++;
+		pwidth++;
+	    }
+	    else
+	    {
+		/* Move to next band, adjust ppt as needed */
+		pboxBandStart = pboxBandEnd;
+		if (pboxBandStart == pboxLast)
+		    break; /* We're completely done */
+		NextBand();
+	    }
+	}
+    }
+    return (pwidthNew - pwidthNewStart);
+}
diff --git a/mi/Makefile.am b/mi/Makefile.am
index f22dde9..f6dabda 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -48,7 +48,6 @@ libmi_la_SOURCES = 	\
 	mipolytext.c	\
 	mipolyutil.c	\
 	mipushpxl.c	\
-	miregion.c	\
 	miscanfill.h	\
 	miscrinit.c	\
 	mispans.c	\
diff --git a/mi/miregion.c b/mi/miregion.c
deleted file mode 100644
index a561601..0000000
--- a/mi/miregion.c
+++ /dev/null
@@ -1,1845 +0,0 @@
-/***********************************************************
-
-Copyright 1987, 1988, 1989, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
- 
-
-Copyright 1987, 1988, 1989 by 
-Digital Equipment Corporation, Maynard, Massachusetts. 
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-
-/* The panoramix components contained the following notice */
-/*****************************************************************
-
-Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
-BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
-IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of Digital Equipment Corporation
-shall not be used in advertising or otherwise to promote the sale, use or other
-dealings in this Software without prior written authorization from Digital
-Equipment Corporation.
-
-******************************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "regionstr.h"
-#include <X11/Xprotostr.h>
-#include <X11/Xfuncproto.h>
-#include "gc.h"
-#include "mi.h"
-#include "mispans.h"
-#include <pixman.h>
-
-#undef assert
-#ifdef REGION_DEBUG
-#define assert(expr) { \
-            CARD32 *foo = NULL; \
-            if (!(expr)) { \
-                ErrorF("Assertion failed file %s, line %d: %s\n", \
-                       __FILE__, __LINE__, #expr); \
-                *foo = 0xdeadbeef; /* to get a backtrace */ \
-            } \
-        }
-#else
-#define assert(expr)
-#endif
-
-#define good(reg) assert(RegionIsValid(reg))
-
-/*
- * The functions in this file implement the Region abstraction used extensively
- * throughout the X11 sample server. A Region is simply a set of disjoint
- * (non-overlapping) rectangles, plus an "extent" rectangle which is the
- * smallest single rectangle that contains all the non-overlapping rectangles.
- *
- * A Region is implemented as a "y-x-banded" array of rectangles.  This array
- * imposes two degrees of order.  First, all rectangles are sorted by top side
- * y coordinate first (y1), and then by left side x coordinate (x1).
- *
- * Furthermore, the rectangles are grouped into "bands".  Each rectangle in a
- * band has the same top y coordinate (y1), and each has the same bottom y
- * coordinate (y2).  Thus all rectangles in a band differ only in their left
- * and right side (x1 and x2).  Bands are implicit in the array of rectangles:
- * there is no separate list of band start pointers.
- *
- * The y-x band representation does not minimize rectangles.  In particular,
- * if a rectangle vertically crosses a band (the rectangle has scanlines in 
- * the y1 to y2 area spanned by the band), then the rectangle may be broken
- * down into two or more smaller rectangles stacked one atop the other. 
- *
- *  -----------				    -----------
- *  |         |				    |         |		    band 0
- *  |         |  --------		    -----------  --------
- *  |         |  |      |  in y-x banded    |         |  |      |   band 1
- *  |         |  |      |  form is	    |         |  |      |
- *  -----------  |      |		    -----------  --------
- *               |      |				 |      |   band 2
- *               --------				 --------
- *
- * An added constraint on the rectangles is that they must cover as much
- * horizontal area as possible: no two rectangles within a band are allowed
- * to touch.
- *
- * Whenever possible, bands will be merged together to cover a greater vertical
- * distance (and thus reduce the number of rectangles). Two bands can be merged
- * only if the bottom of one touches the top of the other and they have
- * rectangles in the same places (of the same width, of course).
- *
- * Adam de Boor wrote most of the original region code.  Joel McCormack
- * substantially modified or rewrote most of the core arithmetic routines,
- * and added RegionValidate in order to support several speed improvements
- * to miValidateTree.  Bob Scheifler changed the representation to be more
- * compact when empty or a single rectangle, and did a bunch of gratuitous
- * reformatting.
- */
-
-/*  true iff two Boxes overlap */
-#define EXTENTCHECK(r1,r2) \
-      (!( ((r1)->x2 <= (r2)->x1)  || \
-          ((r1)->x1 >= (r2)->x2)  || \
-          ((r1)->y2 <= (r2)->y1)  || \
-          ((r1)->y1 >= (r2)->y2) ) )
-
-/* true iff (x,y) is in Box */
-#define INBOX(r,x,y) \
-      ( ((r)->x2 >  x) && \
-        ((r)->x1 <= x) && \
-        ((r)->y2 >  y) && \
-        ((r)->y1 <= y) )
-
-/* true iff Box r1 contains Box r2 */
-#define SUBSUMES(r1,r2) \
-      ( ((r1)->x1 <= (r2)->x1) && \
-        ((r1)->x2 >= (r2)->x2) && \
-        ((r1)->y1 <= (r2)->y1) && \
-        ((r1)->y2 >= (r2)->y2) )
-
-#define xallocData(n) malloc(REGION_SZOF(n))
-#define xfreeData(reg) if ((reg)->data && (reg)->data->size) free((reg)->data)
-
-#define RECTALLOC_BAIL(pReg,n,bail) \
-if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
-    if (!RegionRectAlloc(pReg, n)) { goto bail; }
-
-#define RECTALLOC(pReg,n) \
-if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
-    if (!RegionRectAlloc(pReg, n)) { return FALSE; }
-
-#define ADDRECT(pNextRect,nx1,ny1,nx2,ny2)	\
-{						\
-    pNextRect->x1 = nx1;			\
-    pNextRect->y1 = ny1;			\
-    pNextRect->x2 = nx2;			\
-    pNextRect->y2 = ny2;			\
-    pNextRect++;				\
-}
-
-#define NEWRECT(pReg,pNextRect,nx1,ny1,nx2,ny2)			\
-{									\
-    if (!(pReg)->data || ((pReg)->data->numRects == (pReg)->data->size))\
-    {									\
-	if (!RegionRectAlloc(pReg, 1))					\
-	    return FALSE;						\
-	pNextRect = REGION_TOP(pReg);					\
-    }									\
-    ADDRECT(pNextRect,nx1,ny1,nx2,ny2);					\
-    pReg->data->numRects++;						\
-    assert(pReg->data->numRects<=pReg->data->size);			\
-}
-
-
-#define DOWNSIZE(reg,numRects)						 \
-if (((numRects) < ((reg)->data->size >> 1)) && ((reg)->data->size > 50)) \
-{									 \
-    RegDataPtr NewData;							 \
-    NewData = (RegDataPtr)realloc((reg)->data, REGION_SZOF(numRects));	 \
-    if (NewData)							 \
-    {									 \
-	NewData->size = (numRects);					 \
-	(reg)->data = NewData;						 \
-    }									 \
-}
-
-
-BoxRec RegionEmptyBox = {0, 0, 0, 0};
-RegDataRec RegionEmptyData = {0, 0};
-
-RegDataRec  RegionBrokenData = {0, 0};
-static RegionRec   RegionBrokenRegion = { { 0, 0, 0, 0 }, &RegionBrokenData };
-
-void
-InitRegions (void)
-{
-    pixman_region_set_static_pointers (&RegionEmptyBox, &RegionEmptyData, &RegionBrokenData);
-}
-
-/*****************************************************************
- *   RegionCreate(rect, size)
- *     This routine does a simple malloc to make a structure of
- *     REGION of "size" number of rectangles.
- *****************************************************************/
-
-RegionPtr
-RegionCreate(BoxPtr rect, int size)
-{
-    RegionPtr pReg;
-   
-    pReg = (RegionPtr)malloc(sizeof(RegionRec));
-    if (!pReg)
-	return &RegionBrokenRegion;
-
-    RegionInit (pReg, rect, size);
-    
-    return(pReg);
-}
-
-void
-RegionDestroy(RegionPtr pReg)
-{
-    pixman_region_fini (pReg);
-    if (pReg != &RegionBrokenRegion)
-	free(pReg);
-}
-
-void
-RegionPrint(RegionPtr rgn)
-{
-    int num, size;
-    int i;
-    BoxPtr rects;
-
-    num = REGION_NUM_RECTS(rgn);
-    size = REGION_SIZE(rgn);
-    rects = REGION_RECTS(rgn);
-    ErrorF("[mi] num: %d size: %d\n", num, size);
-    ErrorF("[mi] extents: %d %d %d %d\n",
-	   rgn->extents.x1, rgn->extents.y1, rgn->extents.x2, rgn->extents.y2);
-    for (i = 0; i < num; i++)
-      ErrorF("[mi] %d %d %d %d \n",
-	     rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2);
-    ErrorF("[mi] \n");
-}
-
-Bool
-RegionEqual(RegionPtr reg1, RegionPtr reg2)
-{
-    return pixman_region_equal (reg1, reg2);
-}
-
-#ifdef DEBUG
-Bool
-RegionIsValid(RegionPtr reg)
-{
-    int i, numRects;
-    
-    if ((reg->extents.x1 > reg->extents.x2) ||
-	(reg->extents.y1 > reg->extents.y2))
-	return FALSE;
-    numRects = REGION_NUM_RECTS(reg);
-    if (!numRects)
-	return ((reg->extents.x1 == reg->extents.x2) &&
-		(reg->extents.y1 == reg->extents.y2) &&
-		(reg->data->size || (reg->data == &RegionEmptyData)));
-    else if (numRects == 1)
-	return (!reg->data);
-    else
-    {
-	BoxPtr pboxP, pboxN;
-	BoxRec box;
-	
-	pboxP = REGION_RECTS(reg);
-	box = *pboxP;
-	box.y2 = pboxP[numRects-1].y2;
-	pboxN = pboxP + 1;
-	for (i = numRects; --i > 0; pboxP++, pboxN++)
-	{
-	    if ((pboxN->x1 >= pboxN->x2) ||
-		(pboxN->y1 >= pboxN->y2))
-		return FALSE;
-	    if (pboxN->x1 < box.x1)
-		box.x1 = pboxN->x1;
-	    if (pboxN->x2 > box.x2)
-		box.x2 = pboxN->x2;
-	    if ((pboxN->y1 < pboxP->y1) ||
-		((pboxN->y1 == pboxP->y1) &&
-		 ((pboxN->x1 < pboxP->x2) || (pboxN->y2 != pboxP->y2))))
-		return FALSE;
-	}
-	return ((box.x1 == reg->extents.x1) &&
-		(box.x2 == reg->extents.x2) &&
-		(box.y1 == reg->extents.y1) &&
-		(box.y2 == reg->extents.y2));
-    }
-}
-#endif /* DEBUG */
-
-/*****************************************************************
- *   RegionInit(pReg, rect, size)
- *     Outer region rect is statically allocated.
- *****************************************************************/
-
-void
-RegionInit(RegionPtr pReg, BoxPtr rect, int size)
-{
-    if (rect)
-	pixman_region_init_with_extents (pReg, rect);
-    else
-	pixman_region_init (pReg);
-}
-
-void
-RegionUninit(RegionPtr pReg)
-{
-    pixman_region_fini (pReg);
-}
-
-Bool
-RegionBreak (RegionPtr pReg)
-{
-    xfreeData (pReg);
-    pReg->extents = RegionEmptyBox;
-    pReg->data = &RegionBrokenData;
-    return FALSE;
-}
-
-Bool
-RegionRectAlloc(RegionPtr pRgn, int n)
-{
-    RegDataPtr	data;
-    
-    if (!pRgn->data)
-    {
-	n++;
-	pRgn->data = xallocData(n);
-	if (!pRgn->data)
-	    return RegionBreak (pRgn);
-	pRgn->data->numRects = 1;
-	*REGION_BOXPTR(pRgn) = pRgn->extents;
-    }
-    else if (!pRgn->data->size)
-    {
-	pRgn->data = xallocData(n);
-	if (!pRgn->data)
-	    return RegionBreak (pRgn);
-	pRgn->data->numRects = 0;
-    }
-    else
-    {
-	if (n == 1)
-	{
-	    n = pRgn->data->numRects;
-	    if (n > 500) /* XXX pick numbers out of a hat */
-		n = 250;
-	}
-	n += pRgn->data->numRects;
-	data = (RegDataPtr)realloc(pRgn->data, REGION_SZOF(n));
-	if (!data)
-	    return RegionBreak (pRgn);
-	pRgn->data = data;
-    }
-    pRgn->data->size = n;
-    return TRUE;
-}
-
-Bool
-RegionCopy(RegionPtr dst, RegionPtr src)
-{
-    return pixman_region_copy (dst, src);
-}
-
-/*======================================================================
- *	    Generic Region Operator
- *====================================================================*/
-
-/*-
- *-----------------------------------------------------------------------
- * RegionCoalesce --
- *	Attempt to merge the boxes in the current band with those in the
- *	previous one.  We are guaranteed that the current band extends to
- *      the end of the rects array.  Used only by RegionOp.
- *
- * Results:
- *	The new index for the previous band.
- *
- * Side Effects:
- *	If coalescing takes place:
- *	    - rectangles in the previous band will have their y2 fields
- *	      altered.
- *	    - pReg->data->numRects will be decreased.
- *
- *-----------------------------------------------------------------------
- */
-_X_INLINE static int
-RegionCoalesce (
-    RegionPtr	pReg,	    	/* Region to coalesce		     */
-    int	    	  	prevStart,  	/* Index of start of previous band   */
-    int	    	  	curStart)   	/* Index of start of current band    */
-{
-    BoxPtr	pPrevBox;   	/* Current box in previous band	     */
-    BoxPtr	pCurBox;    	/* Current box in current band       */
-    int  	numRects;	/* Number rectangles in both bands   */
-    int		y2;		/* Bottom of current band	     */
-    /*
-     * Figure out how many rectangles are in the band.
-     */
-    numRects = curStart - prevStart;
-    assert(numRects == pReg->data->numRects - curStart);
-
-    if (!numRects) return curStart;
-
-    /*
-     * The bands may only be coalesced if the bottom of the previous
-     * matches the top scanline of the current.
-     */
-    pPrevBox = REGION_BOX(pReg, prevStart);
-    pCurBox = REGION_BOX(pReg, curStart);
-    if (pPrevBox->y2 != pCurBox->y1) return curStart;
-
-    /*
-     * Make sure the bands have boxes in the same places. This
-     * assumes that boxes have been added in such a way that they
-     * cover the most area possible. I.e. two boxes in a band must
-     * have some horizontal space between them.
-     */
-    y2 = pCurBox->y2;
-
-    do {
-	if ((pPrevBox->x1 != pCurBox->x1) || (pPrevBox->x2 != pCurBox->x2)) {
-	    return (curStart);
-	}
-	pPrevBox++;
-	pCurBox++;
-	numRects--;
-    } while (numRects);
-
-    /*
-     * The bands may be merged, so set the bottom y of each box
-     * in the previous band to the bottom y of the current band.
-     */
-    numRects = curStart - prevStart;
-    pReg->data->numRects -= numRects;
-    do {
-	pPrevBox--;
-	pPrevBox->y2 = y2;
-	numRects--;
-    } while (numRects);
-    return prevStart;
-}
-
-
-/* Quicky macro to avoid trivial reject procedure calls to RegionCoalesce */
-
-#define Coalesce(newReg, prevBand, curBand)				\
-    if (curBand - prevBand == newReg->data->numRects - curBand) {	\
-	prevBand = RegionCoalesce(newReg, prevBand, curBand);		\
-    } else {								\
-	prevBand = curBand;						\
-    }
-
-/*-
- *-----------------------------------------------------------------------
- * RegionAppendNonO --
- *	Handle a non-overlapping band for the union and subtract operations.
- *      Just adds the (top/bottom-clipped) rectangles into the region.
- *      Doesn't have to check for subsumption or anything.
- *
- * Results:
- *	None.
- *
- * Side Effects:
- *	pReg->data->numRects is incremented and the rectangles overwritten
- *	with the rectangles we're passed.
- *
- *-----------------------------------------------------------------------
- */
-
-_X_INLINE static Bool
-RegionAppendNonO (
-    RegionPtr	pReg,
-    BoxPtr	r,
-    BoxPtr  	rEnd,
-    int  	y1,
-    int  	y2)
-{
-    BoxPtr	pNextRect;
-    int		newRects;
-
-    newRects = rEnd - r;
-
-    assert(y1 < y2);
-    assert(newRects != 0);
-
-    /* Make sure we have enough space for all rectangles to be added */
-    RECTALLOC(pReg, newRects);
-    pNextRect = REGION_TOP(pReg);
-    pReg->data->numRects += newRects;
-    do {
-	assert(r->x1 < r->x2);
-	ADDRECT(pNextRect, r->x1, y1, r->x2, y2);
-	r++;
-    } while (r != rEnd);
-
-    return TRUE;
-}
-
-#define FindBand(r, rBandEnd, rEnd, ry1)		    \
-{							    \
-    ry1 = r->y1;					    \
-    rBandEnd = r+1;					    \
-    while ((rBandEnd != rEnd) && (rBandEnd->y1 == ry1)) {   \
-	rBandEnd++;					    \
-    }							    \
-}
-
-#define	AppendRegions(newReg, r, rEnd)					\
-{									\
-    int newRects;							\
-    if ((newRects = rEnd - r)) {					\
-	RECTALLOC(newReg, newRects);					\
-	memmove((char *)REGION_TOP(newReg),(char *)r, 			\
-              newRects * sizeof(BoxRec));				\
-	newReg->data->numRects += newRects;				\
-    }									\
-}
-
-/*-
- *-----------------------------------------------------------------------
- * RegionOp --
- *	Apply an operation to two regions. Called by RegionUnion, RegionInverse,
- *	RegionSubtract, RegionIntersect....  Both regions MUST have at least one
- *      rectangle, and cannot be the same object.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *	The new region is overwritten.
- *	pOverlap set to TRUE if overlapFunc ever returns TRUE.
- *
- * Notes:
- *	The idea behind this function is to view the two regions as sets.
- *	Together they cover a rectangle of area that this function divides
- *	into horizontal bands where points are covered only by one region
- *	or by both. For the first case, the nonOverlapFunc is called with
- *	each the band and the band's upper and lower extents. For the
- *	second, the overlapFunc is called to process the entire band. It
- *	is responsible for clipping the rectangles in the band, though
- *	this function provides the boundaries.
- *	At the end of each band, the new region is coalesced, if possible,
- *	to reduce the number of rectangles in the region.
- *
- *-----------------------------------------------------------------------
- */
-
-typedef Bool (*OverlapProcPtr)(
-    RegionPtr	pReg,
-    BoxPtr	r1,
-    BoxPtr   	r1End,
-    BoxPtr	r2,
-    BoxPtr   	r2End,
-    short    	y1,
-    short    	y2,
-    Bool	*pOverlap);
-
-static Bool
-RegionOp(
-    RegionPtr       newReg,		    /* Place to store result	     */
-    RegionPtr       reg1,		    /* First region in operation     */
-    RegionPtr       reg2,		    /* 2d region in operation        */
-    OverlapProcPtr  overlapFunc,            /* Function to call for over-
-					     * lapping bands		     */
-    Bool	    appendNon1,		    /* Append non-overlapping bands  */
-					    /* in region 1 ? */
-    Bool	    appendNon2,		    /* Append non-overlapping bands  */
-					    /* in region 2 ? */
-    Bool	    *pOverlap)
-{
-    BoxPtr 	r1;		    /* Pointer into first region     */
-    BoxPtr 	r2;		    /* Pointer into 2d region	     */
-    BoxPtr	r1End;		    /* End of 1st region	     */
-    BoxPtr	r2End;		    /* End of 2d region		     */
-    short	ybot;		    /* Bottom of intersection	     */
-    short	ytop;		    /* Top of intersection	     */
-    RegDataPtr	oldData;	    /* Old data for newReg	     */
-    int		prevBand;	    /* Index of start of
-				     * previous band in newReg       */
-    int		curBand;	    /* Index of start of current
-				     * band in newReg		     */
-    BoxPtr  	r1BandEnd;	    /* End of current band in r1     */
-    BoxPtr  	r2BandEnd;	    /* End of current band in r2     */
-    short   	top;		    /* Top of non-overlapping band   */
-    short   	bot;	    	    /* Bottom of non-overlapping band*/
-    int     	r1y1;	    	    /* Temps for r1->y1 and r2->y1   */
-    int     	r2y1;
-    int	    	newSize;
-    int	    	numRects;
-
-    /*
-     * Break any region computed from a broken region
-     */
-    if (REGION_NAR (reg1) || REGION_NAR(reg2))
-	return RegionBreak (newReg);
-    
-    /*
-     * Initialization:
-     *	set r1, r2, r1End and r2End appropriately, save the rectangles
-     * of the destination region until the end in case it's one of
-     * the two source regions, then mark the "new" region empty, allocating
-     * another array of rectangles for it to use.
-     */
-
-    r1 = REGION_RECTS(reg1);
-    newSize = REGION_NUM_RECTS(reg1);
-    r1End = r1 + newSize;
-    numRects = REGION_NUM_RECTS(reg2);
-    r2 = REGION_RECTS(reg2);
-    r2End = r2 + numRects;
-    assert(r1 != r1End);
-    assert(r2 != r2End);
-
-    oldData = NULL;
-    if (((newReg == reg1) && (newSize > 1)) ||
-	((newReg == reg2) && (numRects > 1)))
-    {
-	oldData = newReg->data;
-	newReg->data = &RegionEmptyData;
-    }
-    /* guess at new size */
-    if (numRects > newSize)
-	newSize = numRects;
-    newSize <<= 1;
-    if (!newReg->data)
-	newReg->data = &RegionEmptyData;
-    else if (newReg->data->size)
-	newReg->data->numRects = 0;
-    if (newSize > newReg->data->size)
-	if (!RegionRectAlloc(newReg, newSize))
-	    return FALSE;
-
-    /*
-     * Initialize ybot.
-     * In the upcoming loop, ybot and ytop serve different functions depending
-     * on whether the band being handled is an overlapping or non-overlapping
-     * band.
-     * 	In the case of a non-overlapping band (only one of the regions
-     * has points in the band), ybot is the bottom of the most recent
-     * intersection and thus clips the top of the rectangles in that band.
-     * ytop is the top of the next intersection between the two regions and
-     * serves to clip the bottom of the rectangles in the current band.
-     *	For an overlapping band (where the two regions intersect), ytop clips
-     * the top of the rectangles of both regions and ybot clips the bottoms.
-     */
-
-    ybot = min(r1->y1, r2->y1);
-    
-    /*
-     * prevBand serves to mark the start of the previous band so rectangles
-     * can be coalesced into larger rectangles. qv. RegionCoalesce, above.
-     * In the beginning, there is no previous band, so prevBand == curBand
-     * (curBand is set later on, of course, but the first band will always
-     * start at index 0). prevBand and curBand must be indices because of
-     * the possible expansion, and resultant moving, of the new region's
-     * array of rectangles.
-     */
-    prevBand = 0;
-    
-    do {
-	/*
-	 * This algorithm proceeds one source-band (as opposed to a
-	 * destination band, which is determined by where the two regions
-	 * intersect) at a time. r1BandEnd and r2BandEnd serve to mark the
-	 * rectangle after the last one in the current band for their
-	 * respective regions.
-	 */
-	assert(r1 != r1End);
-	assert(r2 != r2End);
-    
-	FindBand(r1, r1BandEnd, r1End, r1y1);
-	FindBand(r2, r2BandEnd, r2End, r2y1);
-
-	/*
-	 * First handle the band that doesn't intersect, if any.
-	 *
-	 * Note that attention is restricted to one band in the
-	 * non-intersecting region at once, so if a region has n
-	 * bands between the current position and the next place it overlaps
-	 * the other, this entire loop will be passed through n times.
-	 */
-	if (r1y1 < r2y1) {
-	    if (appendNon1) {
-		top = max(r1y1, ybot);
-		bot = min(r1->y2, r2y1);
-		if (top != bot)	{
-		    curBand = newReg->data->numRects;
-		    RegionAppendNonO(newReg, r1, r1BandEnd, top, bot);
-		    Coalesce(newReg, prevBand, curBand);
-		}
-	    }
-	    ytop = r2y1;
-	} else if (r2y1 < r1y1) {
-	    if (appendNon2) {
-		top = max(r2y1, ybot);
-		bot = min(r2->y2, r1y1);
-		if (top != bot) {
-		    curBand = newReg->data->numRects;
-		    RegionAppendNonO(newReg, r2, r2BandEnd, top, bot);
-		    Coalesce(newReg, prevBand, curBand);
-		}
-	    }
-	    ytop = r1y1;
-	} else {
-	    ytop = r1y1;
-	}
-
-	/*
-	 * Now see if we've hit an intersecting band. The two bands only
-	 * intersect if ybot > ytop
-	 */
-	ybot = min(r1->y2, r2->y2);
-	if (ybot > ytop) {
-	    curBand = newReg->data->numRects;
-	    (* overlapFunc)(newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot,
-			    pOverlap);
-	    Coalesce(newReg, prevBand, curBand);
-	}
-
-	/*
-	 * If we've finished with a band (y2 == ybot) we skip forward
-	 * in the region to the next band.
-	 */
-	if (r1->y2 == ybot) r1 = r1BandEnd;
-	if (r2->y2 == ybot) r2 = r2BandEnd;
-
-    } while (r1 != r1End && r2 != r2End);
-
-    /*
-     * Deal with whichever region (if any) still has rectangles left.
-     *
-     * We only need to worry about banding and coalescing for the very first
-     * band left.  After that, we can just group all remaining boxes,
-     * regardless of how many bands, into one final append to the list.
-     */
-
-    if ((r1 != r1End) && appendNon1) {
-	/* Do first nonOverlap1Func call, which may be able to coalesce */
-	FindBand(r1, r1BandEnd, r1End, r1y1);
-	curBand = newReg->data->numRects;
-	RegionAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2);
-	Coalesce(newReg, prevBand, curBand);
-	/* Just append the rest of the boxes  */
-	AppendRegions(newReg, r1BandEnd, r1End);
-
-    } else if ((r2 != r2End) && appendNon2) {
-	/* Do first nonOverlap2Func call, which may be able to coalesce */
-	FindBand(r2, r2BandEnd, r2End, r2y1);
-	curBand = newReg->data->numRects;
-	RegionAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2);
-	Coalesce(newReg, prevBand, curBand);
-	/* Append rest of boxes */
-	AppendRegions(newReg, r2BandEnd, r2End);
-    }
-
-    if (oldData)
-	free(oldData);
-
-    if (!(numRects = newReg->data->numRects))
-    {
-	xfreeData(newReg);
-	newReg->data = &RegionEmptyData;
-    }
-    else if (numRects == 1)
-    {
-	newReg->extents = *REGION_BOXPTR(newReg);
-	xfreeData(newReg);
-	newReg->data = NULL;
-    }
-    else
-    {
-	DOWNSIZE(newReg, numRects);
-    }
-
-    return TRUE;
-}
-
-/*-
- *-----------------------------------------------------------------------
- * RegionSetExtents --
- *	Reset the extents of a region to what they should be. Called by
- *	RegionSubtract and RegionIntersect as they can't figure it out along the
- *	way or do so easily, as RegionUnion can.
- *
- * Results:
- *	None.
- *
- * Side Effects:
- *	The region's 'extents' structure is overwritten.
- *
- *-----------------------------------------------------------------------
- */
-static void
-RegionSetExtents (RegionPtr pReg)
-{
-    BoxPtr pBox, pBoxEnd;
-
-    if (!pReg->data)
-	return;
-    if (!pReg->data->size)
-    {
-	pReg->extents.x2 = pReg->extents.x1;
-	pReg->extents.y2 = pReg->extents.y1;
-	return;
-    }
-
-    pBox = REGION_BOXPTR(pReg);
-    pBoxEnd = REGION_END(pReg);
-
-    /*
-     * Since pBox is the first rectangle in the region, it must have the
-     * smallest y1 and since pBoxEnd is the last rectangle in the region,
-     * it must have the largest y2, because of banding. Initialize x1 and
-     * x2 from  pBox and pBoxEnd, resp., as good things to initialize them
-     * to...
-     */
-    pReg->extents.x1 = pBox->x1;
-    pReg->extents.y1 = pBox->y1;
-    pReg->extents.x2 = pBoxEnd->x2;
-    pReg->extents.y2 = pBoxEnd->y2;
-
-    assert(pReg->extents.y1 < pReg->extents.y2);
-    while (pBox <= pBoxEnd) {
-	if (pBox->x1 < pReg->extents.x1)
-	    pReg->extents.x1 = pBox->x1;
-	if (pBox->x2 > pReg->extents.x2)
-	    pReg->extents.x2 = pBox->x2;
-	pBox++;
-    };
-
-    assert(pReg->extents.x1 < pReg->extents.x2);
-}
-
-/*======================================================================
- *	    Region Intersection
- *====================================================================*/
-/*-
- *-----------------------------------------------------------------------
- * RegionIntersectO --
- *	Handle an overlapping band for RegionIntersect.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *	Rectangles may be added to the region.
- *
- *-----------------------------------------------------------------------
- */
-/*ARGSUSED*/
-Bool
-RegionIntersect(
-    RegionPtr	newReg,     /* destination Region */
-    RegionPtr	reg1,
-    RegionPtr	reg2        /* source regions     */
-    )
-{
-    return pixman_region_intersect (newReg, reg1, reg2);
-}
-
-#define MERGERECT(r)						\
-{								\
-    if (r->x1 <= x2) {						\
-	/* Merge with current rectangle */			\
-	if (r->x1 < x2) *pOverlap = TRUE;				\
-	if (x2 < r->x2) x2 = r->x2;				\
-    } else {							\
-	/* Add current rectangle, start new one */		\
-	NEWRECT(pReg, pNextRect, x1, y1, x2, y2);		\
-	x1 = r->x1;						\
-	x2 = r->x2;						\
-    }								\
-    r++;							\
-}
-
-/*======================================================================
- *	    Region Union
- *====================================================================*/
-
-/*-
- *-----------------------------------------------------------------------
- * RegionUnionO --
- *	Handle an overlapping band for the union operation. Picks the
- *	left-most rectangle each time and merges it into the region.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *	pReg is overwritten.
- *	pOverlap is set to TRUE if any boxes overlap.
- *
- *-----------------------------------------------------------------------
- */
-static Bool
-RegionUnionO (
-    RegionPtr	pReg,
-    BoxPtr	r1,
-    BoxPtr  	r1End,
-    BoxPtr	r2,
-    BoxPtr  	r2End,
-    short	y1,
-    short	y2,
-    Bool	*pOverlap)
-{
-    BoxPtr     pNextRect;
-    int        x1;     /* left and right side of current union */
-    int        x2;
-
-    assert (y1 < y2);
-    assert(r1 != r1End && r2 != r2End);
-
-    pNextRect = REGION_TOP(pReg);
-
-    /* Start off current rectangle */
-    if (r1->x1 < r2->x1)
-    {
-	x1 = r1->x1;
-	x2 = r1->x2;
-	r1++;
-    }
-    else
-    {
-	x1 = r2->x1;
-	x2 = r2->x2;
-	r2++;
-    }
-    while (r1 != r1End && r2 != r2End)
-    {
-	if (r1->x1 < r2->x1) MERGERECT(r1) else MERGERECT(r2);
-    }
-
-    /* Finish off whoever (if any) is left */
-    if (r1 != r1End)
-    {
-	do
-	{
-	    MERGERECT(r1);
-	} while (r1 != r1End);
-    }
-    else if (r2 != r2End)
-    {
-	do
-	{
-	    MERGERECT(r2);
-	} while (r2 != r2End);
-    }
-    
-    /* Add current rectangle */
-    NEWRECT(pReg, pNextRect, x1, y1, x2, y2);
-
-    return TRUE;
-}
-
-Bool
-RegionUnion(
-    RegionPtr	newReg,          /* destination Region */
-    RegionPtr	reg1,
-    RegionPtr	reg2             /* source regions     */
-    )
-{
-    return pixman_region_union (newReg, reg1, reg2);
-}
-
-/*======================================================================
- *	    Batch Rectangle Union
- *====================================================================*/
-
-/*-
- *-----------------------------------------------------------------------
- * RegionAppend --
- * 
- *      "Append" the rgn rectangles onto the end of dstrgn, maintaining
- *      knowledge of YX-banding when it's easy.  Otherwise, dstrgn just
- *      becomes a non-y-x-banded random collection of rectangles, and not
- *      yet a true region.  After a sequence of appends, the caller must
- *      call RegionValidate to ensure that a valid region is constructed.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *      dstrgn is modified if rgn has rectangles.
- *
- */
-Bool
-RegionAppend(RegionPtr dstrgn, RegionPtr rgn)
-{
-    int numRects, dnumRects, size;
-    BoxPtr new, old;
-    Bool prepend;
-
-    if (REGION_NAR(rgn))
-	return RegionBreak (dstrgn);
-    
-    if (!rgn->data && (dstrgn->data == &RegionEmptyData))
-    {
-	dstrgn->extents = rgn->extents;
-	dstrgn->data = NULL;
-	return TRUE;
-    }
-
-    numRects = REGION_NUM_RECTS(rgn);
-    if (!numRects)
-	return TRUE;
-    prepend = FALSE;
-    size = numRects;
-    dnumRects = REGION_NUM_RECTS(dstrgn);
-    if (!dnumRects && (size < 200))
-	size = 200; /* XXX pick numbers out of a hat */
-    RECTALLOC(dstrgn, size);
-    old = REGION_RECTS(rgn);
-    if (!dnumRects)
-	dstrgn->extents = rgn->extents;
-    else if (dstrgn->extents.x2 > dstrgn->extents.x1)
-    {
-	BoxPtr first, last;
-
-	first = old;
-	last = REGION_BOXPTR(dstrgn) + (dnumRects - 1);
-	if ((first->y1 > last->y2) ||
-	    ((first->y1 == last->y1) && (first->y2 == last->y2) &&
-	     (first->x1 > last->x2)))
-	{
-	    if (rgn->extents.x1 < dstrgn->extents.x1)
-		dstrgn->extents.x1 = rgn->extents.x1;
-	    if (rgn->extents.x2 > dstrgn->extents.x2)
-		dstrgn->extents.x2 = rgn->extents.x2;
-	    dstrgn->extents.y2 = rgn->extents.y2;
-	}
-	else
-	{
-	    first = REGION_BOXPTR(dstrgn);
-	    last = old + (numRects - 1);
-	    if ((first->y1 > last->y2) ||
-		((first->y1 == last->y1) && (first->y2 == last->y2) &&
-		 (first->x1 > last->x2)))
-	    {
-		prepend = TRUE;
-		if (rgn->extents.x1 < dstrgn->extents.x1)
-		    dstrgn->extents.x1 = rgn->extents.x1;
-		if (rgn->extents.x2 > dstrgn->extents.x2)
-		    dstrgn->extents.x2 = rgn->extents.x2;
-		dstrgn->extents.y1 = rgn->extents.y1;
-	    }
-	    else
-		dstrgn->extents.x2 = dstrgn->extents.x1;
-	}
-    }
-    if (prepend)
-    {
-	new = REGION_BOX(dstrgn, numRects);
-	if (dnumRects == 1)
-	    *new = *REGION_BOXPTR(dstrgn);
-	else
-	    memmove((char *)new,(char *)REGION_BOXPTR(dstrgn), 
-		  dnumRects * sizeof(BoxRec));
-	new = REGION_BOXPTR(dstrgn);
-    }
-    else
-	new = REGION_BOXPTR(dstrgn) + dnumRects;
-    if (numRects == 1)
-	*new = *old;
-    else
-	memmove((char *)new, (char *)old, numRects * sizeof(BoxRec));
-    dstrgn->data->numRects += numRects;
-    return TRUE;
-}
-
-   
-#define ExchangeRects(a, b) \
-{			    \
-    BoxRec     t;	    \
-    t = rects[a];	    \
-    rects[a] = rects[b];    \
-    rects[b] = t;	    \
-}
-
-static void
-QuickSortRects(
-    BoxRec     rects[],
-    int        numRects)
-{
-    int	y1;
-    int	x1;
-    int        i, j;
-    BoxPtr     r;
-
-    /* Always called with numRects > 1 */
-
-    do
-    {
-	if (numRects == 2)
-	{
-	    if (rects[0].y1 > rects[1].y1 ||
-		    (rects[0].y1 == rects[1].y1 && rects[0].x1 > rects[1].x1))
-		ExchangeRects(0, 1);
-	    return;
-	}
-
-	/* Choose partition element, stick in location 0 */
-        ExchangeRects(0, numRects >> 1);
-	y1 = rects[0].y1;
-	x1 = rects[0].x1;
-
-        /* Partition array */
-        i = 0;
-        j = numRects;
-        do
-	{
-	    r = &(rects[i]);
-	    do
-	    {
-		r++;
-		i++;
-            } while (i != numRects &&
-		     (r->y1 < y1 || (r->y1 == y1 && r->x1 < x1)));
-	    r = &(rects[j]);
-	    do
-	    {
-		r--;
-		j--;
-            } while (y1 < r->y1 || (y1 == r->y1 && x1 < r->x1));
-            if (i < j)
-		ExchangeRects(i, j);
-        } while (i < j);
-
-        /* Move partition element back to middle */
-        ExchangeRects(0, j);
-
-	/* Recurse */
-        if (numRects-j-1 > 1)
-	    QuickSortRects(&rects[j+1], numRects-j-1);
-        numRects = j;
-    } while (numRects > 1);
-}
-
-/*-
- *-----------------------------------------------------------------------
- * RegionValidate --
- * 
- *      Take a ``region'' which is a non-y-x-banded random collection of
- *      rectangles, and compute a nice region which is the union of all the
- *      rectangles.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *      The passed-in ``region'' may be modified.
- *	pOverlap set to TRUE if any retangles overlapped, else FALSE;
- *
- * Strategy:
- *      Step 1. Sort the rectangles into ascending order with primary key y1
- *		and secondary key x1.
- *
- *      Step 2. Split the rectangles into the minimum number of proper y-x
- *		banded regions.  This may require horizontally merging
- *		rectangles, and vertically coalescing bands.  With any luck,
- *		this step in an identity tranformation (ala the Box widget),
- *		or a coalescing into 1 box (ala Menus).
- *
- *	Step 3. Merge the separate regions down to a single region by calling
- *		RegionUnion.  Maximize the work each RegionUnion call does by using
- *		a binary merge.
- *
- *-----------------------------------------------------------------------
- */
-
-Bool
-RegionValidate(RegionPtr badreg, Bool *pOverlap)
-{
-    /* Descriptor for regions under construction  in Step 2. */
-    typedef struct {
-	RegionRec   reg;
-	int	    prevBand;
-	int	    curBand;
-    } RegionInfo;
-
-    int	numRects;   /* Original numRects for badreg	    */
-    RegionInfo *ri;	    /* Array of current regions		    */
-    int	numRI;      /* Number of entries used in ri	    */
-    int	sizeRI;	    /* Number of entries available in ri    */
-    int	i;	    /* Index into rects			    */
-    int	j;	    /* Index into ri			    */
-    RegionInfo *rit;       /* &ri[j]				    */
-    RegionPtr  reg;        /* ri[j].reg			    */
-    BoxPtr	box;	    /* Current box in rects		    */
-    BoxPtr	riBox;      /* Last box in ri[j].reg		    */
-    RegionPtr  hreg;       /* ri[j_half].reg			    */
-    Bool		ret = TRUE;
-
-    *pOverlap = FALSE;
-    if (!badreg->data)
-    {
-	good(badreg);
-	return TRUE;
-    }
-    numRects = badreg->data->numRects;
-    if (!numRects)
-    {
-	if (REGION_NAR(badreg))
-	    return FALSE;
-	good(badreg);
-	return TRUE;
-    }
-    if (badreg->extents.x1 < badreg->extents.x2)
-    {
-	if ((numRects) == 1)
-	{
-	    xfreeData(badreg);
-	    badreg->data = (RegDataPtr) NULL;
-	}
-	else
-	{
-	    DOWNSIZE(badreg, numRects);
-	}
-	good(badreg);
-	return TRUE;
-    }
-
-    /* Step 1: Sort the rects array into ascending (y1, x1) order */
-    QuickSortRects(REGION_BOXPTR(badreg), numRects);
-
-    /* Step 2: Scatter the sorted array into the minimum number of regions */
-
-    /* Set up the first region to be the first rectangle in badreg */
-    /* Note that step 2 code will never overflow the ri[0].reg rects array */
-    ri = (RegionInfo *) malloc(4 * sizeof(RegionInfo));
-    if (!ri)
-	return RegionBreak (badreg);
-    sizeRI = 4;
-    numRI = 1;
-    ri[0].prevBand = 0;
-    ri[0].curBand = 0;
-    ri[0].reg = *badreg;
-    box = REGION_BOXPTR(&ri[0].reg);
-    ri[0].reg.extents = *box;
-    ri[0].reg.data->numRects = 1;
-
-    /* Now scatter rectangles into the minimum set of valid regions.  If the
-       next rectangle to be added to a region would force an existing rectangle
-       in the region to be split up in order to maintain y-x banding, just
-       forget it.  Try the next region.  If it doesn't fit cleanly into any
-       region, make a new one. */
-
-    for (i = numRects; --i > 0;)
-    {
-	box++;
-	/* Look for a region to append box to */
-	for (j = numRI, rit = ri; --j >= 0; rit++)
-	{
-	    reg = &rit->reg;
-	    riBox = REGION_END(reg);
-
-	    if (box->y1 == riBox->y1 && box->y2 == riBox->y2)
-	    {
-		/* box is in same band as riBox.  Merge or append it */
-		if (box->x1 <= riBox->x2)
-		{
-		    /* Merge it with riBox */
-		    if (box->x1 < riBox->x2) *pOverlap = TRUE;
-		    if (box->x2 > riBox->x2) riBox->x2 = box->x2;
-		}
-		else
-		{
-		    RECTALLOC_BAIL(reg, 1, bail);
-		    *REGION_TOP(reg) = *box;
-		    reg->data->numRects++;
-		}
-		goto NextRect;   /* So sue me */
-	    }
-	    else if (box->y1 >= riBox->y2)
-	    {
-		/* Put box into new band */
-		if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2;
-		if (reg->extents.x1 > box->x1)   reg->extents.x1 = box->x1;
-		Coalesce(reg, rit->prevBand, rit->curBand);
-		rit->curBand = reg->data->numRects;
-		RECTALLOC_BAIL(reg, 1, bail);
-		*REGION_TOP(reg) = *box;
-		reg->data->numRects++;
-		goto NextRect;
-	    }
-	    /* Well, this region was inappropriate.  Try the next one. */
-	} /* for j */
-
-	/* Uh-oh.  No regions were appropriate.  Create a new one. */
-	if (sizeRI == numRI)
-	{
-	    /* Oops, allocate space for new region information */
-	    sizeRI <<= 1;
-	    rit = (RegionInfo *) realloc(ri, sizeRI * sizeof(RegionInfo));
-	    if (!rit)
-		goto bail;
-	    ri = rit;
-	    rit = &ri[numRI];
-	}
-	numRI++;
-	rit->prevBand = 0;
-	rit->curBand = 0;
-	rit->reg.extents = *box;
-	rit->reg.data = NULL;
-	if (!RegionRectAlloc(&rit->reg, (i+numRI) / numRI)) /* MUST force allocation */
-	    goto bail;
-NextRect: ;
-    } /* for i */
-
-    /* Make a final pass over each region in order to Coalesce and set
-       extents.x2 and extents.y2 */
-
-    for (j = numRI, rit = ri; --j >= 0; rit++)
-    {
-	reg = &rit->reg;
-	riBox = REGION_END(reg);
-	reg->extents.y2 = riBox->y2;
-	if (reg->extents.x2 < riBox->x2) reg->extents.x2 = riBox->x2;
-	Coalesce(reg, rit->prevBand, rit->curBand);
-	if (reg->data->numRects == 1) /* keep unions happy below */
-	{
-	    xfreeData(reg);
-	    reg->data = NULL;
-	}
-    }
-
-    /* Step 3: Union all regions into a single region */
-    while (numRI > 1)
-    {
-	int half = numRI/2;
-	for (j = numRI & 1; j < (half + (numRI & 1)); j++)
-	{
-	    reg = &ri[j].reg;
-	    hreg = &ri[j+half].reg;
-	    if (!RegionOp(reg, reg, hreg, RegionUnionO, TRUE, TRUE, pOverlap))
-		ret = FALSE;
-	    if (hreg->extents.x1 < reg->extents.x1)
-		reg->extents.x1 = hreg->extents.x1;
-	    if (hreg->extents.y1 < reg->extents.y1)
-		reg->extents.y1 = hreg->extents.y1;
-	    if (hreg->extents.x2 > reg->extents.x2)
-		reg->extents.x2 = hreg->extents.x2;
-	    if (hreg->extents.y2 > reg->extents.y2)
-		reg->extents.y2 = hreg->extents.y2;
-	    xfreeData(hreg);
-	}
-	numRI -= half;
-    }
-    *badreg = ri[0].reg;
-    free(ri);
-    good(badreg);
-    return ret;
-bail:
-    for (i = 0; i < numRI; i++)
-	xfreeData(&ri[i].reg);
-    free(ri);
-    return RegionBreak (badreg);
-}
-
-RegionPtr
-RegionFromRects(int nrects, xRectangle *prect, int ctype)
-{
-    
-    RegionPtr		pRgn;
-    RegDataPtr		pData;
-    BoxPtr		pBox;
-    int        		i;
-    int			x1, y1, x2, y2;
-
-    pRgn = RegionCreate(NullBox, 0);
-    if (REGION_NAR (pRgn))
-	return pRgn;
-    if (!nrects)
-	return pRgn;
-    if (nrects == 1)
-    {
-	x1 = prect->x;
-	y1 = prect->y;
-	if ((x2 = x1 + (int) prect->width) > MAXSHORT)
-	    x2 = MAXSHORT;
-	if ((y2 = y1 + (int) prect->height) > MAXSHORT)
-	    y2 = MAXSHORT;
-	if (x1 != x2 && y1 != y2)
-	{
-	    pRgn->extents.x1 = x1;
-	    pRgn->extents.y1 = y1;
-	    pRgn->extents.x2 = x2;
-	    pRgn->extents.y2 = y2;
-	    pRgn->data = NULL;
-	}
-	return pRgn;
-    }
-    pData = xallocData(nrects);
-    if (!pData)
-    {
-	RegionBreak (pRgn);
-	return pRgn;
-    }
-    pBox = (BoxPtr) (pData + 1);
-    for (i = nrects; --i >= 0; prect++)
-    {
-	x1 = prect->x;
-	y1 = prect->y;
-	if ((x2 = x1 + (int) prect->width) > MAXSHORT)
-	    x2 = MAXSHORT;
-	if ((y2 = y1 + (int) prect->height) > MAXSHORT)
-	    y2 = MAXSHORT;
-	if (x1 != x2 && y1 != y2)
-	{
-	    pBox->x1 = x1;
-	    pBox->y1 = y1;
-	    pBox->x2 = x2;
-	    pBox->y2 = y2;
-	    pBox++;
-	}
-    }
-    if (pBox != (BoxPtr) (pData + 1))
-    {
-	pData->size = nrects;
-	pData->numRects = pBox - (BoxPtr) (pData + 1);
-    	pRgn->data = pData;
-    	if (ctype != CT_YXBANDED)
-    	{
-	    Bool overlap; /* result ignored */
-	    pRgn->extents.x1 = pRgn->extents.x2 = 0;
-	    RegionValidate(pRgn, &overlap);
-    	}
-    	else
-	    RegionSetExtents(pRgn);
-    	good(pRgn);
-    }
-    else
-    {
-	free(pData);
-    }
-    return pRgn;
-}
-
-/*======================================================================
- * 	    	  Region Subtraction
- *====================================================================*/
-
-
-/*-
- *-----------------------------------------------------------------------
- * RegionSubtractO --
- *	Overlapping band subtraction. x1 is the left-most point not yet
- *	checked.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *	pReg may have rectangles added to it.
- *
- *-----------------------------------------------------------------------
- */
-/*ARGSUSED*/
-
-/*-
- *-----------------------------------------------------------------------
- * RegionSubtract --
- *	Subtract regS from regM and leave the result in regD.
- *	S stands for subtrahend, M for minuend and D for difference.
- *
- * Results:
- *	TRUE if successful.
- *
- * Side Effects:
- *	regD is overwritten.
- *
- *-----------------------------------------------------------------------
- */
-Bool
-RegionSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
-{
-    return pixman_region_subtract (regD, regM, regS);
-}
-
-/*======================================================================
- *	    Region Inversion
- *====================================================================*/
-
-/*-
- *-----------------------------------------------------------------------
- * RegionInverse --
- *	Take a region and a box and return a region that is everything
- *	in the box but not in the region. The careful reader will note
- *	that this is the same as subtracting the region from the box...
- *
- * Results:
- *	TRUE.
- *
- * Side Effects:
- *	newReg is overwritten.
- *
- *-----------------------------------------------------------------------
- */
-Bool
-RegionInverse(
-    RegionPtr	  newReg,       /* Destination region */
-    RegionPtr	  reg1,         /* Region to invert */
-    BoxPtr	  invRect	/* Bounding box for inversion */
-    )
-{
-    return pixman_region_inverse (newReg, reg1, invRect);
-}
-int
-RegionContainsRect(RegionPtr region, BoxPtr prect)
-{
-    return pixman_region_contains_rectangle (region, prect);
-}
-
-/* TranslateRegion(pReg, x, y)
-   translates in place
-*/
-
-void
-RegionTranslate(RegionPtr pReg, int x, int y)
-{
-    pixman_region_translate (pReg, x, y);
-}
-
-void
-RegionReset(RegionPtr pReg, BoxPtr pBox)
-{
-    pixman_region_reset (pReg, pBox);
-}
-
-Bool
-RegionContainsPoint(
-    RegionPtr pReg,
-    int x,
-    int y,
-    BoxPtr box      /* "return" value */
-    )
-{
-    return pixman_region_contains_point (pReg, x, y, box);
-}
-
-Bool
-RegionNotEmpty(RegionPtr pReg)
-{
-    return pixman_region_not_empty (pReg);
-}
-
-Bool
-RegionBroken(RegionPtr pReg)
-{
-    good(pReg);
-    return (REGION_NAR(pReg));
-}
-
-void
-RegionEmpty(RegionPtr pReg)
-{
-    good(pReg);
-    xfreeData(pReg);
-    pReg->extents.x2 = pReg->extents.x1;
-    pReg->extents.y2 = pReg->extents.y1;
-    pReg->data = &RegionEmptyData;
-}
-
-BoxPtr
-RegionExtents(RegionPtr pReg)
-{
-    good(pReg);
-    return(&pReg->extents);
-}
-
-#define ExchangeSpans(a, b)				    \
-{							    \
-    DDXPointRec	tpt;				    	    \
-    int    	tw;					    \
-							    \
-    tpt = spans[a]; spans[a] = spans[b]; spans[b] = tpt;    \
-    tw = widths[a]; widths[a] = widths[b]; widths[b] = tw;  \
-}
-
-/* ||| I should apply the merge sort code to rectangle sorting above, and see
-   if mapping time can be improved.  But right now I've been at work 12 hours,
-   so forget it.
-*/
-
-static void QuickSortSpans(
-    DDXPointRec spans[],
-    int	    	widths[],
-    int	    	numSpans)
-{
-    int	    y;
-    int	    i, j, m;
-    DDXPointPtr    r;
-
-    /* Always called with numSpans > 1 */
-    /* Sorts only by y, doesn't bother to sort by x */
-
-    do
-    {
-	if (numSpans < 9)
-	{
-	    /* Do insertion sort */
-	    int yprev;
-
-	    yprev = spans[0].y;
-	    i = 1;
-	    do
-	    { /* while i != numSpans */
-		y = spans[i].y;
-		if (yprev > y)
-		{
-		    /* spans[i] is out of order.  Move into proper location. */
-		    DDXPointRec tpt;
-		    int	    tw, k;
-
-		    for (j = 0; y >= spans[j].y; j++) {}
-		    tpt = spans[i];
-		    tw  = widths[i];
-		    for (k = i; k != j; k--)
-		    {
-			spans[k] = spans[k-1];
-			widths[k] = widths[k-1];
-		    }
-		    spans[j] = tpt;
-		    widths[j] = tw;
-		    y = spans[i].y;
-		} /* if out of order */
-		yprev = y;
-		i++;
-	    } while (i != numSpans);
-	    return;
-	}
-
-	/* Choose partition element, stick in location 0 */
-	m = numSpans / 2;
-	if (spans[m].y > spans[0].y)		ExchangeSpans(m, 0);
-	if (spans[m].y > spans[numSpans-1].y)   ExchangeSpans(m, numSpans-1);
-	if (spans[m].y > spans[0].y)		ExchangeSpans(m, 0);
-	y = spans[0].y;
-
-        /* Partition array */
-        i = 0;
-        j = numSpans;
-        do
-	{
-	    r = &(spans[i]);
-	    do
-	    {
-		r++;
-		i++;
-            } while (i != numSpans && r->y < y);
-	    r = &(spans[j]);
-	    do
-	    {
-		r--;
-		j--;
-            } while (y < r->y);
-            if (i < j)
-		ExchangeSpans(i, j);
-        } while (i < j);
-
-        /* Move partition element back to middle */
-        ExchangeSpans(0, j);
-
-	/* Recurse */
-        if (numSpans-j-1 > 1)
-	    QuickSortSpans(&spans[j+1], &widths[j+1], numSpans-j-1);
-        numSpans = j;
-    } while (numSpans > 1);
-}
-
-#define NextBand()						    \
-{								    \
-    clipy1 = pboxBandStart->y1;					    \
-    clipy2 = pboxBandStart->y2;					    \
-    pboxBandEnd = pboxBandStart + 1;				    \
-    while (pboxBandEnd != pboxLast && pboxBandEnd->y1 == clipy1) {  \
-	pboxBandEnd++;						    \
-    }								    \
-    for (; ppt != pptLast && ppt->y < clipy1; ppt++, pwidth++) {} \
-}
-
-/*
-    Clip a list of scanlines to a region.  The caller has allocated the
-    space.  FSorted is non-zero if the scanline origins are in ascending
-    order.
-    returns the number of new, clipped scanlines.
-*/
-
-int
-RegionClipSpans(
-    RegionPtr	prgnDst,
-    DDXPointPtr ppt,
-    int	    	*pwidth,
-    int		nspans,
-    DDXPointPtr	pptNew,
-    int		*pwidthNew,
-    int		fSorted)
-{
-    DDXPointPtr pptLast;
-    int	*pwidthNewStart;	/* the vengeance of Xerox! */
-    int	y, x1, x2;
-    int	numRects;
-
-    good(prgnDst);
-    pptLast = ppt + nspans;
-    pwidthNewStart = pwidthNew;
-
-    if (!prgnDst->data)
-    {
-	/* Do special fast code with clip boundaries in registers(?) */
-	/* It doesn't pay much to make use of fSorted in this case, 
-	   so we lump everything together. */
-
-	int clipx1, clipx2, clipy1, clipy2;
-
-	clipx1 = prgnDst->extents.x1;
-	clipy1 = prgnDst->extents.y1;
-	clipx2 = prgnDst->extents.x2;
-	clipy2 = prgnDst->extents.y2;
-	    
-	for (; ppt != pptLast; ppt++, pwidth++)
-	{
-	    y = ppt->y;
-	    x1 = ppt->x;
-	    if (clipy1 <= y && y < clipy2)
-	    {
-		x2 = x1 + *pwidth;
-		if (x1 < clipx1)    x1 = clipx1;
-		if (x2 > clipx2)    x2 = clipx2;
-		if (x1 < x2)
-		{
-		    /* part of span in clip rectangle */
-		    pptNew->x = x1;
-		    pptNew->y = y;
-		    *pwidthNew = x2 - x1;
-		    pptNew++;
-		    pwidthNew++;
-		}
-	    }
-	} /* end for */
-
-    }
-    else if ((numRects = prgnDst->data->numRects))
-    {
-	/* Have to clip against many boxes */
-	BoxPtr pboxBandStart, pboxBandEnd;
-	BoxPtr pbox;
-	BoxPtr pboxLast;
-	int clipy1, clipy2;
-
-	/* In this case, taking advantage of sorted spans gains more than
-	   the sorting costs. */
-	if ((! fSorted) && (nspans > 1))
-	    QuickSortSpans(ppt, pwidth, nspans);
-
-	pboxBandStart = REGION_BOXPTR(prgnDst);
-	pboxLast = pboxBandStart + numRects;
-    
-	NextBand();
-
-	for (; ppt != pptLast; )
-	{
-	    y = ppt->y;
-	    if (y < clipy2)
-	    {
-		/* span is in the current band */
-		pbox = pboxBandStart;
-		x1 = ppt->x;
-		x2 = x1 + *pwidth;
-		do
-		{ /* For each box in band */
-		    int newx1, newx2;
-
-		    newx1 = x1;
-		    newx2 = x2;
-		    if (newx1 < pbox->x1)   newx1 = pbox->x1;
-		    if (newx2 > pbox->x2)   newx2 = pbox->x2;
-		    if (newx1 < newx2)
-		    {
-			/* Part of span in clip rectangle */
-			pptNew->x = newx1;
-			pptNew->y = y;
-			*pwidthNew = newx2 - newx1;
-			pptNew++;
-			pwidthNew++;
-		    }
-		    pbox++;
-		} while (pbox != pboxBandEnd);
-		ppt++;
-		pwidth++;
-	    }
-	    else
-	    {
-		/* Move to next band, adjust ppt as needed */
-		pboxBandStart = pboxBandEnd;
-		if (pboxBandStart == pboxLast)
-		    break; /* We're completely done */
-		NextBand();
-	    }
-	}
-    }
-    return (pwidthNew - pwidthNewStart);
-}
commit 9b6f5f549dfe4c20e3cb3c2ef7095ab47abaca3b
Author: Keith Packard <keithp at keithp.com>
Date:   Fri May 21 11:14:59 2010 -0700

    Change region implementation names to eliminate the 'mi' prefix
    
    This prepares the file to be moved from mi to dix. This patch
    was done mechanically with the included scripts 'fix-miregion' run over
    the entire X server and 'fix-miregion-private' run over
    include/regionstr.h and mi/miregion.c.
    
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/window.c b/dix/window.c
index ea729db..afb10fd 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -195,7 +195,7 @@ PrintChildren(WindowPtr p1, int indent)
         ErrorF("[dix] ");
 	for (i=0; i<indent; i++) ErrorF(" ");
 	ErrorF("%lx\n", p1->drawable.id);
-	miPrintRegion(&p1->clipList);
+	RegionPrint(&p1->clipList);
 	PrintChildren(p2, indent+4);
 	p1 = p1->nextSib;
     }
@@ -211,7 +211,7 @@ PrintWindowTree(void)
     {
 	ErrorF("[dix] WINDOW %d\n", i);
 	pWin = screenInfo.screens[i]->root;
-	miPrintRegion(&pWin->clipList);
+	RegionPrint(&pWin->clipList);
 	p1 = pWin->firstChild;
 	PrintChildren(p1, 4);
     }
diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index 4164ff7..cf48ecd 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -407,7 +407,7 @@ exaHWCopyNtoN (DrawablePtr    pSrcDrawable,
 	    rects[i].height = pbox[i].y2 - pbox[i].y1;
 	}
 
-	/* This must match the miRegionCopy() logic for reversing rect order */
+	/* This must match the RegionCopy() logic for reversing rect order */
 	if (nbox == 1 || (dx > 0 && dy > 0) ||
 	    (pDstDrawable != pSrcDrawable &&
 	     (pDstDrawable->type != DRAWABLE_WINDOW ||
diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index c73f9f4..cbaab33 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -115,7 +115,7 @@ if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&			\
 {								\
     if ((reg)->data->numRects == (reg)->data->size)		\
     {								\
-	miRectAlloc(reg, 1);					\
+	RegionRectAlloc(reg, 1);					\
 	fr = REGION_BOXPTR(reg);				\
 	r = fr + (reg)->data->numRects;				\
     }								\
@@ -315,7 +315,7 @@ fbPixmapToRegion(PixmapPtr pPix)
 
     fbFinishAccess(&pPix->drawable);
 #ifdef DEBUG
-    if (!miValidRegion(pReg))
+    if (!RegionIsValid(pReg))
 	FatalError("Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__);
 #endif
     return(pReg);
diff --git a/fix-miregion b/fix-miregion
new file mode 100755
index 0000000..fc502bb
--- /dev/null
+++ b/fix-miregion
@@ -0,0 +1,29 @@
+#!/bin/sh
+sed -i \
+-e 's/miRegionCreate\b/RegionCreate/g' \
+-e 's/miRegionInit\b/RegionInit/g' \
+-e 's/miRegionDestroy\b/RegionDestroy/g' \
+-e 's/miRegionUninit\b/RegionUninit/g' \
+-e 's/miRegionCopy\b/RegionCopy/g' \
+-e 's/miIntersect\b/RegionIntersect/g' \
+-e 's/miUnion\b/RegionUnion/g' \
+-e 's/miRegionAppend\b/RegionAppend/g' \
+-e 's/miRegionValidate\b/RegionValidate/g' \
+-e 's/miRectsToRegion\b/RegionFromRects/g' \
+-e 's/miSubtract\b/RegionSubtract/g' \
+-e 's/miInverse\b/RegionInverse/g' \
+-e 's/miRectIn\b/RegionContainsRect/g' \
+-e 's/miTranslateRegion\b/RegionTranslate/g' \
+-e 's/miRegionReset\b/RegionReset/g' \
+-e 's/miRegionBreak\b/RegionBreak/g' \
+-e 's/miPointInRegion\b/RegionContainsPoint/g' \
+-e 's/miRegionEqual\b/RegionEqual/g' \
+-e 's/miRegionNotEmpty\b/RegionNotEmpty/g' \
+-e 's/miRegionEmpty\b/RegionEmpty/g' \
+-e 's/miRegionExtents\b/RegionExtents/g' \
+-e 's/miPrintRegion\b/RegionPrint/g' \
+-e 's/miRectAlloc\b/RegionRectAlloc/g' \
+-e 's/miValidRegion\b/RegionIsValid/g' \
+-e 's/miRegionBroken\b/RegionBroken/g' \
+-e 's/miClipSpans\b/RegionClipSpans/g' \
+"$@"
diff --git a/fix-miregion-private b/fix-miregion-private
new file mode 100755
index 0000000..ebc24fa
--- /dev/null
+++ b/fix-miregion-private
@@ -0,0 +1,14 @@
+#!/bin/sh
+sed -i \
+-e 's/miEmptyBox\b/RegionEmptyBox/g' \
+-e 's/miEmptyData\b/RegionEmptyData/g' \
+-e 's/miBrokenData\b/RegionBrokenData/g' \
+-e 's/miBrokenRegion\b/RegionBrokenRegion/g' \
+-e 's/miCoalesce\b/RegionCoalesce/g' \
+-e 's/miAppendNonO\b/RegionAppendNonO/g' \
+-e 's/miRegionOp\b/RegionOp/g' \
+-e 's/miSetExtents\b/RegionSetExtents/g' \
+-e 's/miIntersectO\b/RegionIntersectO/g' \
+-e 's/miUnionO\b/RegionUnionO/g' \
+-e 's/miSubtractO\b/RegionSubtractO/g' \
+"$@"
diff --git a/include/regionstr.h b/include/regionstr.h
index 6a5c98c..89cf024 100644
--- a/include/regionstr.h
+++ b/include/regionstr.h
@@ -66,13 +66,13 @@ typedef struct pixman_region16 RegionRec, *RegionPtr;
 
 typedef struct pixman_region16_data RegDataRec, *RegDataPtr;
 
-extern _X_EXPORT BoxRec miEmptyBox;
-extern _X_EXPORT RegDataRec miEmptyData;
-extern _X_EXPORT RegDataRec miBrokenData;
+extern _X_EXPORT BoxRec RegionEmptyBox;
+extern _X_EXPORT RegDataRec RegionEmptyData;
+extern _X_EXPORT RegDataRec RegionBrokenData;
 
 #define REGION_NIL(reg) ((reg)->data && !(reg)->data->numRects)
 /* not a region */
-#define REGION_NAR(reg)	((reg)->data == &miBrokenData)
+#define REGION_NAR(reg)	((reg)->data == &RegionBrokenData)
 #define REGION_NUM_RECTS(reg) ((reg)->data ? (reg)->data->numRects : 1)
 #define REGION_SIZE(reg) ((reg)->data ? (reg)->data->size : 0)
 #define REGION_RECTS(reg) ((reg)->data ? (BoxPtr)((reg)->data + 1) \
@@ -84,52 +84,52 @@ extern _X_EXPORT RegDataRec miBrokenData;
 #define REGION_SZOF(n) (sizeof(RegDataRec) + ((n) * sizeof(BoxRec)))
 
 #define REGION_CREATE(_pScreen, _rect, _size) \
-    miRegionCreate(_rect, _size)
+    RegionCreate(_rect, _size)
 
 #define REGION_COPY(_pScreen, dst, src) \
-    miRegionCopy(dst, src)
+    RegionCopy(dst, src)
 
 #define REGION_DESTROY(_pScreen, _pReg) \
-    miRegionDestroy(_pReg)
+    RegionDestroy(_pReg)
 
 #define REGION_INTERSECT(_pScreen, newReg, reg1, reg2) \
-    miIntersect(newReg, reg1, reg2)
+    RegionIntersect(newReg, reg1, reg2)
 
 #define REGION_UNION(_pScreen, newReg, reg1, reg2) \
-    miUnion(newReg, reg1, reg2)
+    RegionUnion(newReg, reg1, reg2)
 
 #define REGION_SUBTRACT(_pScreen, newReg, reg1, reg2) \
-    miSubtract(newReg, reg1, reg2)
+    RegionSubtract(newReg, reg1, reg2)
 
 #define REGION_INVERSE(_pScreen, newReg, reg1, invRect) \
-    miInverse(newReg, reg1, invRect)
+    RegionInverse(newReg, reg1, invRect)
 
 #define REGION_TRANSLATE(_pScreen, _pReg, _x, _y) \
-    miTranslateRegion(_pReg, _x, _y)
+    RegionTranslate(_pReg, _x, _y)
 
 #define RECT_IN_REGION(_pScreen, _pReg, prect) \
-    miRectIn(_pReg, prect)
+    RegionContainsRect(_pReg, prect)
 
 #define POINT_IN_REGION(_pScreen, _pReg, _x, _y, prect) \
-    miPointInRegion(_pReg, _x, _y, prect)
+    RegionContainsPoint(_pReg, _x, _y, prect)
 
 #define REGION_APPEND(_pScreen, dstrgn, rgn) \
-    miRegionAppend(dstrgn, rgn)
+    RegionAppend(dstrgn, rgn)
 
 #define REGION_VALIDATE(_pScreen, badreg, pOverlap) \
-    miRegionValidate(badreg, pOverlap)
+    RegionValidate(badreg, pOverlap)
 
 #define BITMAP_TO_REGION(_pScreen, pPix) \
     (*(_pScreen)->BitmapToRegion)(pPix) /* no mi version?! */
 
 #define RECTS_TO_REGION(_pScreen, nrects, prect, ctype) \
-    miRectsToRegion(nrects, prect, ctype)
+    RegionFromRects(nrects, prect, ctype)
 
 #define REGION_EQUAL(_pScreen, _pReg1, _pReg2) \
-    miRegionEqual(_pReg1, _pReg2)
+    RegionEqual(_pReg1, _pReg2)
 
 #define REGION_BREAK(_pScreen, _pReg) \
-    miRegionBreak(_pReg)
+    RegionBreak(_pReg)
 
 #define REGION_INIT(_pScreen, _pReg, _rect, _size) \
 { \
@@ -140,7 +140,7 @@ extern _X_EXPORT RegDataRec miBrokenData;
     } \
     else \
     { \
-        (_pReg)->extents = miEmptyBox; \
+        (_pReg)->extents = RegionEmptyBox; \
         if (((_size) > 1) && ((_pReg)->data = \
                              (RegDataPtr)malloc(REGION_SZOF(_size)))) \
         { \
@@ -148,7 +148,7 @@ extern _X_EXPORT RegDataRec miBrokenData;
             (_pReg)->data->numRects = 0; \
         } \
         else \
-            (_pReg)->data = &miEmptyData; \
+            (_pReg)->data = &RegionEmptyData; \
     } \
  }
 
@@ -179,7 +179,7 @@ extern _X_EXPORT RegDataRec miBrokenData;
     REGION_UNINIT(_pScreen, _pReg); \
     (_pReg)->extents.x2 = (_pReg)->extents.x1; \
     (_pReg)->extents.y2 = (_pReg)->extents.y1; \
-    (_pReg)->data = &miEmptyData; \
+    (_pReg)->data = &RegionEmptyData; \
 }
 
 #define REGION_EXTENTS(_pScreen, _pReg) \
@@ -187,8 +187,8 @@ extern _X_EXPORT RegDataRec miBrokenData;
 
 #define REGION_NULL(_pScreen, _pReg) \
 { \
-    (_pReg)->extents = miEmptyBox; \
-    (_pReg)->data = &miEmptyData; \
+    (_pReg)->extents = RegionEmptyBox; \
+    (_pReg)->data = &RegionEmptyData; \
 }
 
 #ifndef REGION_NULL
@@ -200,94 +200,94 @@ extern _X_EXPORT RegDataRec miBrokenData;
 
 extern _X_EXPORT void InitRegions (void);
 
-extern _X_EXPORT RegionPtr miRegionCreate(
+extern _X_EXPORT RegionPtr RegionCreate(
     BoxPtr /*rect*/,
     int /*size*/);
 
-extern _X_EXPORT void miRegionInit(
+extern _X_EXPORT void RegionInit(
     RegionPtr /*pReg*/,
     BoxPtr /*rect*/,
     int /*size*/);
 
-extern _X_EXPORT void miRegionDestroy(
+extern _X_EXPORT void RegionDestroy(
     RegionPtr /*pReg*/);
 
-extern _X_EXPORT void miRegionUninit(
+extern _X_EXPORT void RegionUninit(
     RegionPtr /*pReg*/);
 
-extern _X_EXPORT Bool miRegionCopy(
+extern _X_EXPORT Bool RegionCopy(
     RegionPtr /*dst*/,
     RegionPtr /*src*/);
 
-extern _X_EXPORT Bool miIntersect(
+extern _X_EXPORT Bool RegionIntersect(
     RegionPtr /*newReg*/,
     RegionPtr /*reg1*/,
     RegionPtr /*reg2*/);
 
-extern _X_EXPORT Bool miUnion(
+extern _X_EXPORT Bool RegionUnion(
     RegionPtr /*newReg*/,
     RegionPtr /*reg1*/,
     RegionPtr /*reg2*/);
 
-extern _X_EXPORT Bool miRegionAppend(
+extern _X_EXPORT Bool RegionAppend(
     RegionPtr /*dstrgn*/,
     RegionPtr /*rgn*/);
 
-extern _X_EXPORT Bool miRegionValidate(
+extern _X_EXPORT Bool RegionValidate(
     RegionPtr /*badreg*/,
     Bool * /*pOverlap*/);
 
-extern _X_EXPORT RegionPtr miRectsToRegion(
+extern _X_EXPORT RegionPtr RegionFromRects(
     int /*nrects*/,
     xRectanglePtr /*prect*/,
     int /*ctype*/);
 
-extern _X_EXPORT Bool miSubtract(
+extern _X_EXPORT Bool RegionSubtract(
     RegionPtr /*regD*/,
     RegionPtr /*regM*/,
     RegionPtr /*regS*/);
 
-extern _X_EXPORT Bool miInverse(
+extern _X_EXPORT Bool RegionInverse(
     RegionPtr /*newReg*/,
     RegionPtr /*reg1*/,
     BoxPtr /*invRect*/);
 
-extern _X_EXPORT int miRectIn(
+extern _X_EXPORT int RegionContainsRect(
     RegionPtr /*region*/,
     BoxPtr /*prect*/);
 
-extern _X_EXPORT void miTranslateRegion(
+extern _X_EXPORT void RegionTranslate(
     RegionPtr /*pReg*/,
     int /*x*/,
     int /*y*/);
 
-extern _X_EXPORT void miRegionReset(
+extern _X_EXPORT void RegionReset(
     RegionPtr /*pReg*/,
     BoxPtr /*pBox*/);
 
-extern _X_EXPORT Bool miRegionBreak(
+extern _X_EXPORT Bool RegionBreak(
     RegionPtr /*pReg*/);
 
-extern _X_EXPORT Bool miPointInRegion(
+extern _X_EXPORT Bool RegionContainsPoint(
     RegionPtr /*pReg*/,
     int /*x*/,
     int /*y*/,
     BoxPtr /*box*/);
 
-extern _X_EXPORT Bool miRegionEqual(
+extern _X_EXPORT Bool RegionEqual(
     RegionPtr /*pReg1*/,
     RegionPtr /*pReg2*/);
 
-extern _X_EXPORT Bool miRegionNotEmpty(
+extern _X_EXPORT Bool RegionNotEmpty(
     RegionPtr /*pReg*/);
 
-extern _X_EXPORT void miRegionEmpty(
+extern _X_EXPORT void RegionEmpty(
     RegionPtr /*pReg*/);
 
-extern _X_EXPORT BoxPtr miRegionExtents(
+extern _X_EXPORT BoxPtr RegionExtents(
     RegionPtr /*pReg*/);
 
-extern _X_EXPORT void miPrintRegion(
+extern _X_EXPORT void RegionPrint(
     RegionPtr /*pReg*/);
 
 #endif /* REGIONSTRUCT_H */
diff --git a/mi/mi.h b/mi/mi.h
index 321523b..9f67d2e 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -422,18 +422,18 @@ extern _X_EXPORT void miPushPixels(
 
 /* see also region.h */
 
-extern _X_EXPORT Bool miRectAlloc(
+extern _X_EXPORT Bool RegionRectAlloc(
     RegionPtr /*pRgn*/,
     int /*n*/
 );
 
 #ifdef DEBUG
-extern _X_EXPORT Bool miValidRegion(
+extern _X_EXPORT Bool RegionIsValid(
     RegionPtr /*prgn*/
 );
 #endif
 
-extern _X_EXPORT Bool miRegionBroken(RegionPtr pReg);
+extern _X_EXPORT Bool RegionBroken(RegionPtr pReg);
 
 /* miscrinit.c */
 
diff --git a/mi/miregion.c b/mi/miregion.c
index 59aaa85..a561601 100644
--- a/mi/miregion.c
+++ b/mi/miregion.c
@@ -101,7 +101,7 @@ Equipment Corporation.
 #define assert(expr)
 #endif
 
-#define good(reg) assert(miValidRegion(reg))
+#define good(reg) assert(RegionIsValid(reg))
 
 /*
  * The functions in this file implement the Region abstraction used extensively
@@ -144,7 +144,7 @@ Equipment Corporation.
  *
  * Adam de Boor wrote most of the original region code.  Joel McCormack
  * substantially modified or rewrote most of the core arithmetic routines,
- * and added miRegionValidate in order to support several speed improvements
+ * and added RegionValidate in order to support several speed improvements
  * to miValidateTree.  Bob Scheifler changed the representation to be more
  * compact when empty or a single rectangle, and did a bunch of gratuitous
  * reformatting.
@@ -176,11 +176,11 @@ Equipment Corporation.
 
 #define RECTALLOC_BAIL(pReg,n,bail) \
 if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
-    if (!miRectAlloc(pReg, n)) { goto bail; }
+    if (!RegionRectAlloc(pReg, n)) { goto bail; }
 
 #define RECTALLOC(pReg,n) \
 if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
-    if (!miRectAlloc(pReg, n)) { return FALSE; }
+    if (!RegionRectAlloc(pReg, n)) { return FALSE; }
 
 #define ADDRECT(pNextRect,nx1,ny1,nx2,ny2)	\
 {						\
@@ -195,7 +195,7 @@ if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \
 {									\
     if (!(pReg)->data || ((pReg)->data->numRects == (pReg)->data->size))\
     {									\
-	if (!miRectAlloc(pReg, 1))					\
+	if (!RegionRectAlloc(pReg, 1))					\
 	    return FALSE;						\
 	pNextRect = REGION_TOP(pReg);					\
     }									\
@@ -218,16 +218,16 @@ if (((numRects) < ((reg)->data->size >> 1)) && ((reg)->data->size > 50)) \
 }
 
 
-BoxRec miEmptyBox = {0, 0, 0, 0};
-RegDataRec miEmptyData = {0, 0};
+BoxRec RegionEmptyBox = {0, 0, 0, 0};
+RegDataRec RegionEmptyData = {0, 0};
 
-RegDataRec  miBrokenData = {0, 0};
-static RegionRec   miBrokenRegion = { { 0, 0, 0, 0 }, &miBrokenData };
+RegDataRec  RegionBrokenData = {0, 0};
+static RegionRec   RegionBrokenRegion = { { 0, 0, 0, 0 }, &RegionBrokenData };
 
 void
 InitRegions (void)
 {
-    pixman_region_set_static_pointers (&miEmptyBox, &miEmptyData, &miBrokenData);
+    pixman_region_set_static_pointers (&RegionEmptyBox, &RegionEmptyData, &RegionBrokenData);
 }
 
 /*****************************************************************
@@ -237,29 +237,29 @@ InitRegions (void)
  *****************************************************************/
 
 RegionPtr
-miRegionCreate(BoxPtr rect, int size)
+RegionCreate(BoxPtr rect, int size)
 {
     RegionPtr pReg;
    
     pReg = (RegionPtr)malloc(sizeof(RegionRec));
     if (!pReg)
-	return &miBrokenRegion;
+	return &RegionBrokenRegion;
 
-    miRegionInit (pReg, rect, size);
+    RegionInit (pReg, rect, size);
     
     return(pReg);
 }
 
 void
-miRegionDestroy(RegionPtr pReg)
+RegionDestroy(RegionPtr pReg)
 {
     pixman_region_fini (pReg);
-    if (pReg != &miBrokenRegion)
+    if (pReg != &RegionBrokenRegion)
 	free(pReg);
 }
 
 void
-miPrintRegion(RegionPtr rgn)
+RegionPrint(RegionPtr rgn)
 {
     int num, size;
     int i;
@@ -278,14 +278,14 @@ miPrintRegion(RegionPtr rgn)
 }
 
 Bool
-miRegionEqual(RegionPtr reg1, RegionPtr reg2)
+RegionEqual(RegionPtr reg1, RegionPtr reg2)
 {
     return pixman_region_equal (reg1, reg2);
 }
 
 #ifdef DEBUG
 Bool
-miValidRegion(RegionPtr reg)
+RegionIsValid(RegionPtr reg)
 {
     int i, numRects;
     
@@ -296,7 +296,7 @@ miValidRegion(RegionPtr reg)
     if (!numRects)
 	return ((reg->extents.x1 == reg->extents.x2) &&
 		(reg->extents.y1 == reg->extents.y2) &&
-		(reg->data->size || (reg->data == &miEmptyData)));
+		(reg->data->size || (reg->data == &RegionEmptyData)));
     else if (numRects == 1)
 	return (!reg->data);
     else
@@ -336,7 +336,7 @@ miValidRegion(RegionPtr reg)
  *****************************************************************/
 
 void
-miRegionInit(RegionPtr pReg, BoxPtr rect, int size)
+RegionInit(RegionPtr pReg, BoxPtr rect, int size)
 {
     if (rect)
 	pixman_region_init_with_extents (pReg, rect);
@@ -345,22 +345,22 @@ miRegionInit(RegionPtr pReg, BoxPtr rect, int size)
 }
 
 void
-miRegionUninit(RegionPtr pReg)
+RegionUninit(RegionPtr pReg)
 {
     pixman_region_fini (pReg);
 }
 
 Bool
-miRegionBreak (RegionPtr pReg)
+RegionBreak (RegionPtr pReg)
 {
     xfreeData (pReg);
-    pReg->extents = miEmptyBox;
-    pReg->data = &miBrokenData;
+    pReg->extents = RegionEmptyBox;
+    pReg->data = &RegionBrokenData;
     return FALSE;
 }
 
 Bool
-miRectAlloc(RegionPtr pRgn, int n)
+RegionRectAlloc(RegionPtr pRgn, int n)
 {
     RegDataPtr	data;
     
@@ -369,7 +369,7 @@ miRectAlloc(RegionPtr pRgn, int n)
 	n++;
 	pRgn->data = xallocData(n);
 	if (!pRgn->data)
-	    return miRegionBreak (pRgn);
+	    return RegionBreak (pRgn);
 	pRgn->data->numRects = 1;
 	*REGION_BOXPTR(pRgn) = pRgn->extents;
     }
@@ -377,7 +377,7 @@ miRectAlloc(RegionPtr pRgn, int n)
     {
 	pRgn->data = xallocData(n);
 	if (!pRgn->data)
-	    return miRegionBreak (pRgn);
+	    return RegionBreak (pRgn);
 	pRgn->data->numRects = 0;
     }
     else
@@ -391,7 +391,7 @@ miRectAlloc(RegionPtr pRgn, int n)
 	n += pRgn->data->numRects;
 	data = (RegDataPtr)realloc(pRgn->data, REGION_SZOF(n));
 	if (!data)
-	    return miRegionBreak (pRgn);
+	    return RegionBreak (pRgn);
 	pRgn->data = data;
     }
     pRgn->data->size = n;
@@ -399,7 +399,7 @@ miRectAlloc(RegionPtr pRgn, int n)
 }
 
 Bool
-miRegionCopy(RegionPtr dst, RegionPtr src)
+RegionCopy(RegionPtr dst, RegionPtr src)
 {
     return pixman_region_copy (dst, src);
 }
@@ -410,10 +410,10 @@ miRegionCopy(RegionPtr dst, RegionPtr src)
 
 /*-
  *-----------------------------------------------------------------------
- * miCoalesce --
+ * RegionCoalesce --
  *	Attempt to merge the boxes in the current band with those in the
  *	previous one.  We are guaranteed that the current band extends to
- *      the end of the rects array.  Used only by miRegionOp.
+ *      the end of the rects array.  Used only by RegionOp.
  *
  * Results:
  *	The new index for the previous band.
@@ -427,7 +427,7 @@ miRegionCopy(RegionPtr dst, RegionPtr src)
  *-----------------------------------------------------------------------
  */
 _X_INLINE static int
-miCoalesce (
+RegionCoalesce (
     RegionPtr	pReg,	    	/* Region to coalesce		     */
     int	    	  	prevStart,  	/* Index of start of previous band   */
     int	    	  	curStart)   	/* Index of start of current band    */
@@ -484,18 +484,18 @@ miCoalesce (
 }
 
 
-/* Quicky macro to avoid trivial reject procedure calls to miCoalesce */
+/* Quicky macro to avoid trivial reject procedure calls to RegionCoalesce */
 
 #define Coalesce(newReg, prevBand, curBand)				\
     if (curBand - prevBand == newReg->data->numRects - curBand) {	\
-	prevBand = miCoalesce(newReg, prevBand, curBand);		\
+	prevBand = RegionCoalesce(newReg, prevBand, curBand);		\
     } else {								\
 	prevBand = curBand;						\
     }
 
 /*-
  *-----------------------------------------------------------------------
- * miAppendNonO --
+ * RegionAppendNonO --
  *	Handle a non-overlapping band for the union and subtract operations.
  *      Just adds the (top/bottom-clipped) rectangles into the region.
  *      Doesn't have to check for subsumption or anything.
@@ -511,7 +511,7 @@ miCoalesce (
  */
 
 _X_INLINE static Bool
-miAppendNonO (
+RegionAppendNonO (
     RegionPtr	pReg,
     BoxPtr	r,
     BoxPtr  	rEnd,
@@ -561,9 +561,9 @@ miAppendNonO (
 
 /*-
  *-----------------------------------------------------------------------
- * miRegionOp --
- *	Apply an operation to two regions. Called by miUnion, miInverse,
- *	miSubtract, miIntersect....  Both regions MUST have at least one
+ * RegionOp --
+ *	Apply an operation to two regions. Called by RegionUnion, RegionInverse,
+ *	RegionSubtract, RegionIntersect....  Both regions MUST have at least one
  *      rectangle, and cannot be the same object.
  *
  * Results:
@@ -599,7 +599,7 @@ typedef Bool (*OverlapProcPtr)(
     Bool	*pOverlap);
 
 static Bool
-miRegionOp(
+RegionOp(
     RegionPtr       newReg,		    /* Place to store result	     */
     RegionPtr       reg1,		    /* First region in operation     */
     RegionPtr       reg2,		    /* 2d region in operation        */
@@ -635,7 +635,7 @@ miRegionOp(
      * Break any region computed from a broken region
      */
     if (REGION_NAR (reg1) || REGION_NAR(reg2))
-	return miRegionBreak (newReg);
+	return RegionBreak (newReg);
     
     /*
      * Initialization:
@@ -659,18 +659,18 @@ miRegionOp(
 	((newReg == reg2) && (numRects > 1)))
     {
 	oldData = newReg->data;
-	newReg->data = &miEmptyData;
+	newReg->data = &RegionEmptyData;
     }
     /* guess at new size */
     if (numRects > newSize)
 	newSize = numRects;
     newSize <<= 1;
     if (!newReg->data)
-	newReg->data = &miEmptyData;
+	newReg->data = &RegionEmptyData;
     else if (newReg->data->size)
 	newReg->data->numRects = 0;
     if (newSize > newReg->data->size)
-	if (!miRectAlloc(newReg, newSize))
+	if (!RegionRectAlloc(newReg, newSize))
 	    return FALSE;
 
     /*
@@ -691,7 +691,7 @@ miRegionOp(
     
     /*
      * prevBand serves to mark the start of the previous band so rectangles
-     * can be coalesced into larger rectangles. qv. miCoalesce, above.
+     * can be coalesced into larger rectangles. qv. RegionCoalesce, above.
      * In the beginning, there is no previous band, so prevBand == curBand
      * (curBand is set later on, of course, but the first band will always
      * start at index 0). prevBand and curBand must be indices because of
@@ -728,7 +728,7 @@ miRegionOp(
 		bot = min(r1->y2, r2y1);
 		if (top != bot)	{
 		    curBand = newReg->data->numRects;
-		    miAppendNonO(newReg, r1, r1BandEnd, top, bot);
+		    RegionAppendNonO(newReg, r1, r1BandEnd, top, bot);
 		    Coalesce(newReg, prevBand, curBand);
 		}
 	    }
@@ -739,7 +739,7 @@ miRegionOp(
 		bot = min(r2->y2, r1y1);
 		if (top != bot) {
 		    curBand = newReg->data->numRects;
-		    miAppendNonO(newReg, r2, r2BandEnd, top, bot);
+		    RegionAppendNonO(newReg, r2, r2BandEnd, top, bot);
 		    Coalesce(newReg, prevBand, curBand);
 		}
 	    }
@@ -781,7 +781,7 @@ miRegionOp(
 	/* Do first nonOverlap1Func call, which may be able to coalesce */
 	FindBand(r1, r1BandEnd, r1End, r1y1);
 	curBand = newReg->data->numRects;
-	miAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2);
+	RegionAppendNonO(newReg, r1, r1BandEnd, max(r1y1, ybot), r1->y2);
 	Coalesce(newReg, prevBand, curBand);
 	/* Just append the rest of the boxes  */
 	AppendRegions(newReg, r1BandEnd, r1End);
@@ -790,7 +790,7 @@ miRegionOp(
 	/* Do first nonOverlap2Func call, which may be able to coalesce */
 	FindBand(r2, r2BandEnd, r2End, r2y1);
 	curBand = newReg->data->numRects;
-	miAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2);
+	RegionAppendNonO(newReg, r2, r2BandEnd, max(r2y1, ybot), r2->y2);
 	Coalesce(newReg, prevBand, curBand);
 	/* Append rest of boxes */
 	AppendRegions(newReg, r2BandEnd, r2End);
@@ -802,7 +802,7 @@ miRegionOp(
     if (!(numRects = newReg->data->numRects))
     {
 	xfreeData(newReg);
-	newReg->data = &miEmptyData;
+	newReg->data = &RegionEmptyData;
     }
     else if (numRects == 1)
     {
@@ -820,10 +820,10 @@ miRegionOp(
 
 /*-
  *-----------------------------------------------------------------------
- * miSetExtents --
+ * RegionSetExtents --
  *	Reset the extents of a region to what they should be. Called by
- *	miSubtract and miIntersect as they can't figure it out along the
- *	way or do so easily, as miUnion can.
+ *	RegionSubtract and RegionIntersect as they can't figure it out along the
+ *	way or do so easily, as RegionUnion can.
  *
  * Results:
  *	None.
@@ -834,7 +834,7 @@ miRegionOp(
  *-----------------------------------------------------------------------
  */
 static void
-miSetExtents (RegionPtr pReg)
+RegionSetExtents (RegionPtr pReg)
 {
     BoxPtr pBox, pBoxEnd;
 
@@ -879,8 +879,8 @@ miSetExtents (RegionPtr pReg)
  *====================================================================*/
 /*-
  *-----------------------------------------------------------------------
- * miIntersectO --
- *	Handle an overlapping band for miIntersect.
+ * RegionIntersectO --
+ *	Handle an overlapping band for RegionIntersect.
  *
  * Results:
  *	TRUE if successful.
@@ -892,7 +892,7 @@ miSetExtents (RegionPtr pReg)
  */
 /*ARGSUSED*/
 Bool
-miIntersect(
+RegionIntersect(
     RegionPtr	newReg,     /* destination Region */
     RegionPtr	reg1,
     RegionPtr	reg2        /* source regions     */
@@ -922,7 +922,7 @@ miIntersect(
 
 /*-
  *-----------------------------------------------------------------------
- * miUnionO --
+ * RegionUnionO --
  *	Handle an overlapping band for the union operation. Picks the
  *	left-most rectangle each time and merges it into the region.
  *
@@ -936,7 +936,7 @@ miIntersect(
  *-----------------------------------------------------------------------
  */
 static Bool
-miUnionO (
+RegionUnionO (
     RegionPtr	pReg,
     BoxPtr	r1,
     BoxPtr  	r1End,
@@ -996,7 +996,7 @@ miUnionO (
 }
 
 Bool
-miUnion(
+RegionUnion(
     RegionPtr	newReg,          /* destination Region */
     RegionPtr	reg1,
     RegionPtr	reg2             /* source regions     */
@@ -1011,13 +1011,13 @@ miUnion(
 
 /*-
  *-----------------------------------------------------------------------
- * miRegionAppend --
+ * RegionAppend --
  * 
  *      "Append" the rgn rectangles onto the end of dstrgn, maintaining
  *      knowledge of YX-banding when it's easy.  Otherwise, dstrgn just
  *      becomes a non-y-x-banded random collection of rectangles, and not
  *      yet a true region.  After a sequence of appends, the caller must
- *      call miRegionValidate to ensure that a valid region is constructed.
+ *      call RegionValidate to ensure that a valid region is constructed.
  *
  * Results:
  *	TRUE if successful.
@@ -1027,16 +1027,16 @@ miUnion(
  *
  */
 Bool
-miRegionAppend(RegionPtr dstrgn, RegionPtr rgn)
+RegionAppend(RegionPtr dstrgn, RegionPtr rgn)
 {
     int numRects, dnumRects, size;
     BoxPtr new, old;
     Bool prepend;
 
     if (REGION_NAR(rgn))
-	return miRegionBreak (dstrgn);
+	return RegionBreak (dstrgn);
     
-    if (!rgn->data && (dstrgn->data == &miEmptyData))
+    if (!rgn->data && (dstrgn->data == &RegionEmptyData))
     {
 	dstrgn->extents = rgn->extents;
 	dstrgn->data = NULL;
@@ -1180,7 +1180,7 @@ QuickSortRects(
 
 /*-
  *-----------------------------------------------------------------------
- * miRegionValidate --
+ * RegionValidate --
  * 
  *      Take a ``region'' which is a non-y-x-banded random collection of
  *      rectangles, and compute a nice region which is the union of all the
@@ -1204,14 +1204,14 @@ QuickSortRects(
  *		or a coalescing into 1 box (ala Menus).
  *
  *	Step 3. Merge the separate regions down to a single region by calling
- *		miUnion.  Maximize the work each miUnion call does by using
+ *		RegionUnion.  Maximize the work each RegionUnion call does by using
  *		a binary merge.
  *
  *-----------------------------------------------------------------------
  */
 
 Bool
-miRegionValidate(RegionPtr badreg, Bool *pOverlap)
+RegionValidate(RegionPtr badreg, Bool *pOverlap)
 {
     /* Descriptor for regions under construction  in Step 2. */
     typedef struct {
@@ -1271,7 +1271,7 @@ miRegionValidate(RegionPtr badreg, Bool *pOverlap)
     /* Note that step 2 code will never overflow the ri[0].reg rects array */
     ri = (RegionInfo *) malloc(4 * sizeof(RegionInfo));
     if (!ri)
-	return miRegionBreak (badreg);
+	return RegionBreak (badreg);
     sizeRI = 4;
     numRI = 1;
     ri[0].prevBand = 0;
@@ -1344,7 +1344,7 @@ miRegionValidate(RegionPtr badreg, Bool *pOverlap)
 	rit->curBand = 0;
 	rit->reg.extents = *box;
 	rit->reg.data = NULL;
-	if (!miRectAlloc(&rit->reg, (i+numRI) / numRI)) /* MUST force allocation */
+	if (!RegionRectAlloc(&rit->reg, (i+numRI) / numRI)) /* MUST force allocation */
 	    goto bail;
 NextRect: ;
     } /* for i */
@@ -1374,7 +1374,7 @@ NextRect: ;
 	{
 	    reg = &ri[j].reg;
 	    hreg = &ri[j+half].reg;
-	    if (!miRegionOp(reg, reg, hreg, miUnionO, TRUE, TRUE, pOverlap))
+	    if (!RegionOp(reg, reg, hreg, RegionUnionO, TRUE, TRUE, pOverlap))
 		ret = FALSE;
 	    if (hreg->extents.x1 < reg->extents.x1)
 		reg->extents.x1 = hreg->extents.x1;
@@ -1396,11 +1396,11 @@ bail:
     for (i = 0; i < numRI; i++)
 	xfreeData(&ri[i].reg);
     free(ri);
-    return miRegionBreak (badreg);
+    return RegionBreak (badreg);
 }
 
 RegionPtr
-miRectsToRegion(int nrects, xRectangle *prect, int ctype)
+RegionFromRects(int nrects, xRectangle *prect, int ctype)
 {
     
     RegionPtr		pRgn;
@@ -1409,7 +1409,7 @@ miRectsToRegion(int nrects, xRectangle *prect, int ctype)
     int        		i;
     int			x1, y1, x2, y2;
 
-    pRgn = miRegionCreate(NullBox, 0);
+    pRgn = RegionCreate(NullBox, 0);
     if (REGION_NAR (pRgn))
 	return pRgn;
     if (!nrects)
@@ -1435,7 +1435,7 @@ miRectsToRegion(int nrects, xRectangle *prect, int ctype)
     pData = xallocData(nrects);
     if (!pData)
     {
-	miRegionBreak (pRgn);
+	RegionBreak (pRgn);
 	return pRgn;
     }
     pBox = (BoxPtr) (pData + 1);
@@ -1465,10 +1465,10 @@ miRectsToRegion(int nrects, xRectangle *prect, int ctype)
     	{
 	    Bool overlap; /* result ignored */
 	    pRgn->extents.x1 = pRgn->extents.x2 = 0;
-	    miRegionValidate(pRgn, &overlap);
+	    RegionValidate(pRgn, &overlap);
     	}
     	else
-	    miSetExtents(pRgn);
+	    RegionSetExtents(pRgn);
     	good(pRgn);
     }
     else
@@ -1485,7 +1485,7 @@ miRectsToRegion(int nrects, xRectangle *prect, int ctype)
 
 /*-
  *-----------------------------------------------------------------------
- * miSubtractO --
+ * RegionSubtractO --
  *	Overlapping band subtraction. x1 is the left-most point not yet
  *	checked.
  *
@@ -1501,7 +1501,7 @@ miRectsToRegion(int nrects, xRectangle *prect, int ctype)
 
 /*-
  *-----------------------------------------------------------------------
- * miSubtract --
+ * RegionSubtract --
  *	Subtract regS from regM and leave the result in regD.
  *	S stands for subtrahend, M for minuend and D for difference.
  *
@@ -1514,7 +1514,7 @@ miRectsToRegion(int nrects, xRectangle *prect, int ctype)
  *-----------------------------------------------------------------------
  */
 Bool
-miSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
+RegionSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
 {
     return pixman_region_subtract (regD, regM, regS);
 }
@@ -1525,7 +1525,7 @@ miSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
 
 /*-
  *-----------------------------------------------------------------------
- * miInverse --
+ * RegionInverse --
  *	Take a region and a box and return a region that is everything
  *	in the box but not in the region. The careful reader will note
  *	that this is the same as subtracting the region from the box...
@@ -1539,7 +1539,7 @@ miSubtract(RegionPtr regD, RegionPtr regM, RegionPtr regS)
  *-----------------------------------------------------------------------
  */
 Bool
-miInverse(
+RegionInverse(
     RegionPtr	  newReg,       /* Destination region */
     RegionPtr	  reg1,         /* Region to invert */
     BoxPtr	  invRect	/* Bounding box for inversion */
@@ -1548,7 +1548,7 @@ miInverse(
     return pixman_region_inverse (newReg, reg1, invRect);
 }
 int
-miRectIn(RegionPtr region, BoxPtr prect)
+RegionContainsRect(RegionPtr region, BoxPtr prect)
 {
     return pixman_region_contains_rectangle (region, prect);
 }
@@ -1558,19 +1558,19 @@ miRectIn(RegionPtr region, BoxPtr prect)
 */
 
 void
-miTranslateRegion(RegionPtr pReg, int x, int y)
+RegionTranslate(RegionPtr pReg, int x, int y)
 {
     pixman_region_translate (pReg, x, y);
 }
 
 void
-miRegionReset(RegionPtr pReg, BoxPtr pBox)
+RegionReset(RegionPtr pReg, BoxPtr pBox)
 {
     pixman_region_reset (pReg, pBox);
 }
 
 Bool
-miPointInRegion(
+RegionContainsPoint(
     RegionPtr pReg,
     int x,
     int y,
@@ -1581,30 +1581,30 @@ miPointInRegion(
 }
 
 Bool
-miRegionNotEmpty(RegionPtr pReg)
+RegionNotEmpty(RegionPtr pReg)
 {
     return pixman_region_not_empty (pReg);
 }
 
 Bool
-miRegionBroken(RegionPtr pReg)
+RegionBroken(RegionPtr pReg)
 {
     good(pReg);
     return (REGION_NAR(pReg));
 }
 
 void
-miRegionEmpty(RegionPtr pReg)
+RegionEmpty(RegionPtr pReg)
 {
     good(pReg);
     xfreeData(pReg);
     pReg->extents.x2 = pReg->extents.x1;
     pReg->extents.y2 = pReg->extents.y1;
-    pReg->data = &miEmptyData;
+    pReg->data = &RegionEmptyData;
 }
 
 BoxPtr
-miRegionExtents(RegionPtr pReg)
+RegionExtents(RegionPtr pReg)
 {
     good(pReg);
     return(&pReg->extents);
@@ -1729,7 +1729,7 @@ static void QuickSortSpans(
 */
 
 int
-miClipSpans(
+RegionClipSpans(
     RegionPtr	prgnDst,
     DDXPointPtr ppt,
     int	    	*pwidth,
diff --git a/mi/mispans.h b/mi/mispans.h
index 8151415..ef090bb 100644
--- a/mi/mispans.h
+++ b/mi/mispans.h
@@ -85,7 +85,7 @@ extern _X_EXPORT void miFreeSpanGroup(
     SpanGroup * /*spanGroup*/
 );
 
-extern _X_EXPORT int miClipSpans(
+extern _X_EXPORT int RegionClipSpans(
     RegionPtr /*prgnDst*/,
     DDXPointPtr /*ppt*/,
     int * /*pwidth*/,
diff --git a/mi/misprite.c b/mi/misprite.c
index 2962abf..b2cf5f0 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -268,7 +268,7 @@ miSpriteReportDamage (DamagePtr pDamage, RegionPtr pRegion, void *closure)
 
             if (pCursorInfo->isUp &&
                 pCursorInfo->pScreen == pScreen &&
-                miRectIn(pRegion, &pCursorInfo->saved) != rgnOUT)
+                RegionContainsRect(pRegion, &pCursorInfo->saved) != rgnOUT)
             {
                 SPRITE_DEBUG(("Damage remove\n"));
                 miSpriteRemoveCursor (pDev, pScreen);
@@ -523,7 +523,7 @@ miSpriteCopyWindow (WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
              * Damage will take care of destination check
              */
             if (pCursorInfo->isUp && pCursorInfo->pScreen == pScreen &&
-                    miRectIn(prgnSrc, &pCursorInfo->saved) != rgnOUT)
+                    RegionContainsRect(prgnSrc, &pCursorInfo->saved) != rgnOUT)
             {
                 SPRITE_DEBUG (("CopyWindow remove\n"));
                 miSpriteRemoveCursor (pDev, pScreen);
commit 1768e51976ae8949d999309bd2384ccad72deecd
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Jun 5 15:58:21 2010 -0700

    rootless: Fix SetShape regression
    
    This fixes a regression in miext/rootless from 643cb6e87c10ab554c03ada81930001a8ebcc909
    
    Found-by: tinderbox
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Pierre-Loup A. Griffais <pgriffais at nvidia.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index ce088c7..4d541f4 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -288,12 +288,12 @@ static void RootlessReshapeFrame(WindowPtr pWin)
  *  shaped when the window is framed.
  */
 void
-RootlessSetShape(WindowPtr pWin)
+RootlessSetShape(WindowPtr pWin, int kind)
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
 
     SCREEN_UNWRAP(pScreen, SetShape);
-    pScreen->SetShape(pWin);
+    pScreen->SetShape(pWin, kind);
     SCREEN_WRAP(pScreen, SetShape);
 
     RootlessReshapeFrame(pWin);
diff --git a/miext/rootless/rootlessWindow.h b/miext/rootless/rootlessWindow.h
index ca104a4..2b018e0 100644
--- a/miext/rootless/rootlessWindow.h
+++ b/miext/rootless/rootlessWindow.h
@@ -39,7 +39,7 @@
 Bool RootlessCreateWindow(WindowPtr pWin);
 Bool RootlessDestroyWindow(WindowPtr pWin);
 
-void RootlessSetShape(WindowPtr pWin);
+void RootlessSetShape(WindowPtr pWin, int kind);
 
 Bool RootlessChangeWindowAttributes(WindowPtr pWin, unsigned long vmask);
 Bool RootlessPositionWindow(WindowPtr pWin, int x, int y);


More information about the Xquartz-changes mailing list