[Xquartz-changes] xserver: Branch 'server-1.13-apple' - 253 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Wed Jul 11 23:51:41 PDT 2012


Rebased ref, commits from common ancestor:
commit 99c0112a2c0f28c1790ce6db8dbd71127715f047
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 40a7e38..52d0b0a 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1684,8 +1684,7 @@ fbFillRegionSolid(DrawablePtr pDrawable,
                   RegionPtr pRegion, FbBits and, FbBits xor);
 
 extern _X_EXPORT pixman_image_t *image_from_pict(PicturePtr pict,
-                                                 Bool has_clip,
-                                                 int *xoff, int *yoff);
+                                                 Bool has_clip);
 
 extern _X_EXPORT void free_pixman_pict(PicturePtr, pixman_image_t *);
 
diff --git a/fb/fbpict.c b/fb/fbpict.c
index 097a1a6..dc0ca3c 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -46,23 +46,18 @@ fbComposite(CARD8 op,
             INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, 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);
     if (pMask)
         miCompositeSourceValidate(pMask);
 
-    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, width, height);
+                               xSrc, ySrc, xMask, yMask, xDst, yDst,
+                               width, height);
     }
 
     free_pixman_pict(pSrc, src);
@@ -143,20 +138,22 @@ create_conical_gradient_image(PictGradient * gradient)
 }
 
 static pixman_image_t *
-create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+create_bits_picture(PicturePtr pict, 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((pixman_format_code_t) pict->format,
-                                     pixmap->drawable.width,
-                                     pixmap->drawable.height, (uint32_t *) bits,
+                                     pict->pDrawable->width,
+                                     pict->pDrawable->height, (uint32_t *) bits,
                                      stride * sizeof(FbStride));
 
     if (!image)
@@ -183,57 +180,31 @@ create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
         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 pixman_image_t *image_from_pict_internal(PicturePtr pict, Bool has_clip,
-                                                int *xoff, int *yoff,
                                                 Bool is_alpha_map);
 
 static void
-set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
-                     int *xoff, int *yoff, Bool is_alpha_map)
+set_image_properties(pixman_image_t * image, PicturePtr pict, Bool is_alpha_map)
 {
     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, pict->transform);
     }
 
     switch (pict->repeatType) {
@@ -261,10 +232,8 @@ set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
      * as the alpha map for this operation
      */
     if (pict->alphaMap && !is_alpha_map) {
-        int alpha_xoff, alpha_yoff;
         pixman_image_t *alpha_map =
-            image_from_pict_internal(pict->alphaMap, FALSE, &alpha_xoff,
-                                     &alpha_yoff, TRUE);
+            image_from_pict_internal(pict->alphaMap, TRUE, TRUE);
 
         pixman_image_set_alpha_map(image, alpha_map, pict->alphaOrigin.x,
                                    pict->alphaOrigin.y);
@@ -298,8 +267,7 @@ set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
 }
 
 static pixman_image_t *
-image_from_pict_internal(PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
-                         Bool is_alpha_map)
+image_from_pict_internal(PicturePtr pict, Bool has_clip, Bool is_alpha_map)
 {
     pixman_image_t *image = NULL;
 
@@ -307,7 +275,7 @@ image_from_pict_internal(PicturePtr pict, Bool has_clip, int *xoff, int *yoff,
         return NULL;
 
     if (pict->pDrawable) {
-        image = create_bits_picture(pict, has_clip, xoff, yoff);
+        image = create_bits_picture(pict, has_clip);
     }
     else if (pict->pSourcePict) {
         SourcePict *sp = pict->pSourcePict;
@@ -325,19 +293,17 @@ image_from_pict_internal(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, is_alpha_map);
-
+        set_image_properties (image, pict, is_alpha_map);
     return image;
 }
 
 pixman_image_t *
-image_from_pict(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
+image_from_pict (PicturePtr pict, Bool has_clip)
 {
-    return image_from_pict_internal(pict, has_clip, xoff, yoff, FALSE);
+    return image_from_pict_internal (pict, has_clip, FALSE);
 }
 
 void
diff --git a/fb/fbtrap.c b/fb/fbtrap.c
index bf82f8f..0145ce9 100644
--- a/fb/fbtrap.c
+++ b/fb/fbtrap.c
@@ -36,13 +36,12 @@ fbAddTraps(PicturePtr pPicture,
            INT16 x_off, INT16 y_off, int ntrap, xTrap * traps)
 {
     pixman_image_t *image;
-    int dst_xoff, dst_yoff;
 
-    if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
-        return;
-
-    pixman_add_traps(image, x_off + dst_xoff, y_off + dst_yoff,
-                     ntrap, (pixman_trap_t *) traps);
+    if (!(image = image_from_pict (pPicture, FALSE)))
+	return;
+    
+    pixman_add_traps(image, x_off, y_off,
+                     ntrap, (pixman_trap_t *)traps);
 
     free_pixman_pict(pPicture, image);
 }
@@ -52,13 +51,12 @@ fbRasterizeTrapezoid(PicturePtr pPicture,
                      xTrapezoid * trap, int x_off, int y_off)
 {
     pixman_image_t *image;
-    int dst_xoff, dst_yoff;
 
-    if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
+    if (!(image = image_from_pict (pPicture, FALSE)))
         return;
 
-    pixman_rasterize_trapezoid(image, (pixman_trapezoid_t *) trap,
-                               x_off + dst_xoff, y_off + dst_yoff);
+    pixman_rasterize_trapezoid(image, (pixman_trapezoid_t *)trap,
+                               x_off, y_off);
 
     free_pixman_pict(pPicture, image);
 }
@@ -68,14 +66,12 @@ fbAddTriangles(PicturePtr pPicture,
                INT16 x_off, INT16 y_off, int ntri, xTriangle * tris)
 {
     pixman_image_t *image;
-    int dst_xoff, dst_yoff;
 
-    if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
+    if (!(image = image_from_pict (pPicture, FALSE)))
         return;
-
-    pixman_add_triangles(image,
-                         dst_xoff + x_off, dst_yoff + y_off,
-                         ntri, (pixman_triangle_t *) tris);
+    
+    pixman_add_triangles(image, x_off, y_off, ntri,
+                         (pixman_triangle_t *)tris);
 
     free_pixman_pict(pPicture, image);
 }
@@ -98,13 +94,11 @@ fbShapes(CompositeShapesFunc composite,
          int16_t ySrc, int nshapes, int shape_size, const uint8_t * shapes)
 {
     pixman_image_t *src, *dst;
-    int src_xoff, src_yoff;
-    int dst_xoff, dst_yoff;
 
     miCompositeSourceValidate(pSrc);
 
-    src = image_from_pict(pSrc, FALSE, &src_xoff, &src_yoff);
-    dst = image_from_pict(pDst, TRUE, &dst_xoff, &dst_yoff);
+    src = image_from_pict(pSrc, FALSE);
+    dst = image_from_pict(pDst, TRUE);
 
     if (src && dst) {
         pixman_format_code_t format;
@@ -121,9 +115,8 @@ fbShapes(CompositeShapesFunc composite,
 
             for (i = 0; i < nshapes; ++i) {
                 composite(op, src, dst, format,
-                          xSrc + src_xoff,
-                          ySrc + src_yoff,
-                          dst_xoff, dst_yoff, 1, shapes + i * shape_size);
+                          xSrc, ySrc, 0, 0, 
+                          1, shapes + i * shape_size);
             }
         }
         else {
@@ -143,8 +136,8 @@ fbShapes(CompositeShapesFunc composite,
             }
 
             composite(op, src, dst, format,
-                      xSrc + src_xoff,
-                      ySrc + src_yoff, dst_xoff, dst_yoff, nshapes, shapes);
+                      xSrc, ySrc, 0, 0,
+                      nshapes, shapes);
         }
 
         DamageRegionProcessPending(pDst->pDrawable);
commit 13665ba13c110a0bab11824fffe7240b0f774876
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 8b7c93f..3e972f7 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -489,7 +489,8 @@ void RootlessSetPixmapOfAncestors(WindowPtr pWin);
 void RootlessStartDrawing(WindowPtr pWin);
 void RootlessDamageRegion(WindowPtr pWin, RegionPtr prgn);
 Bool IsFramedWindow(WindowPtr pWin);
-#endif
+#include "../fb/fb.h"
+#endif 
 
 void
 miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
@@ -518,23 +519,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;
+#endif
+    
+    if (what == PW_BACKGROUND)
+    {
+#ifdef ROOTLESS
+        if(IsFramedWindow(pWin)) {
+            RootlessStartDrawing(pWin);
+            RootlessDamageRegion(pWin, prgn);
 
-    if (IsFramedWindow(pWin)) {
-        RootlessStartDrawing(pWin);
-        RootlessDamageRegion(pWin, prgn);
-
-        if (pWin->backgroundState == ParentRelative) {
-            if ((what == PW_BACKGROUND) ||
-                (what == PW_BORDER && !pWin->borderIsPixel))
+            if(pWin->backgroundState == ParentRelative) {
                 RootlessSetPixmapOfAncestors(pWin);
+            }
         }
-    }
 #endif
 
-    if (what == PW_BACKGROUND) {
         while (pWin->backgroundState == ParentRelative)
             pWin = pWin->parent;
 
@@ -559,6 +574,18 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     else {
         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;
 
@@ -567,6 +594,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;
@@ -629,6 +662,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 0f281413db3e5719c7b79fb3116c409cde38bc3a
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Jan 13 12:00:57 2012 -0800

    sdksyms.sh: Use CPPFLAGS, not CFLAGS
    
    CFLAGS can include flags which are not useful to the preprocessor
    or can even cause it to fail.  This fixes a build issue on darwin
    when building for more than one architecture.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index c3899b5..4f48b85 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -38,7 +38,7 @@ DIST_SUBDIRS = common ddc i2c x86emu int10 fbdevhw os-support \
 bin_PROGRAMS = Xorg
 nodist_Xorg_SOURCES = sdksyms.c
 
-AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
+AM_CPPFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
 INCLUDES = $(XORG_INCS) -I$(srcdir)/parser -I$(top_srcdir)/miext/cw \
 	-I$(srcdir)/ddc -I$(srcdir)/i2c -I$(srcdir)/modes -I$(srcdir)/ramdac \
 	-I$(srcdir)/dri -I$(srcdir)/dri2
@@ -115,7 +115,7 @@ CLEANFILES = sdksyms.c sdksyms.dep
 EXTRA_DIST += sdksyms.sh
 
 sdksyms.dep sdksyms.c: sdksyms.sh
-	$(AM_V_GEN)CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $(srcdir)/sdksyms.sh $(top_srcdir) $(CFLAGS) $(AM_CFLAGS) $(INCLUDES)
+	$(AM_V_GEN)CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $(srcdir)/sdksyms.sh $(top_srcdir) $(CPPFLAGS) $(AM_CPPFLAGS) $(INCLUDES)
 
 SDKSYMS_DEP = sdksyms.dep
 include $(SDKSYMS_DEP)
commit 1a64d3cc9c319d5e9ab2365b60469fb5b83407fc
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Wed Jul 11 23:49:59 2012 -0700

    XQuartz: Fix build failure due to incorrect PseudoramiXExtensionInit prototype
    
    pseudoramiX.c:129:1: error: conflicting types for 'PseudoramiXExtensionInit' [Semantic Issue]
    PseudoramiXExtensionInit(int argc, char *argv[])
    ^
    ../../include/extinit.h:175:13: note: previous declaration is here
    extern void PseudoramiXExtensionInit(void);
                ^
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/pseudoramiX.c b/hw/xquartz/pseudoramiX.c
index a87e8ed..c650dd7 100644
--- a/hw/xquartz/pseudoramiX.c
+++ b/hw/xquartz/pseudoramiX.c
@@ -126,7 +126,7 @@ PseudoramiXAddScreen(int x, int y, int w, int h)
 // Initialize PseudoramiX.
 // Copied from PanoramiXExtensionInit
 void
-PseudoramiXExtensionInit(int argc, char *argv[])
+PseudoramiXExtensionInit(void)
 {
     Bool success = FALSE;
     ExtensionEntry      *extEntry;
commit 228f8bfe81890770f1ba109a0acca1c81a2ffee9
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Wed Jul 11 23:49:33 2012 -0700

    XQuartz: Silence an unused-variable warning
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/pseudoramiX.c b/hw/xquartz/pseudoramiX.c
index 3e10500..a87e8ed 100644
--- a/hw/xquartz/pseudoramiX.c
+++ b/hw/xquartz/pseudoramiX.c
@@ -257,7 +257,7 @@ ProcPseudoramiXGetScreenSize(ClientPtr client)
     REQUEST(xPanoramiXGetScreenSizeReq);
     WindowPtr pWin;
     xPanoramiXGetScreenSizeReply rep;
-    register int n, rc;
+    register int rc;
 
     TRACE();
 
commit deb08658e2a6b1647a7213a316c6f3019bcdce48
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Wed Jul 11 16:27:46 2012 +0200

    xfree86: Strip dangling pointers from desiredMode
    
    Based on the original patch by Chris Wilson, which was a better fix than mine.
    
    We stash a copy of the desiredMode on the crtc so that we can restore it
    after a vt switch. This copy is a simple memcpy and so also stashes a
    references to the pointers contained within the desiredMode. Those
    pointers are freed the next time the outputs are probed and mode list
    rebuilt, resulting in us chasing those dangling pointers on the next
    mode switch.
    
    ==22787== Invalid read of size 1
    ==22787==    at 0x40293C2: __GI_strlen (in
    /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==22787==    by 0x668F875: strdup (strdup.c:42)
    ==22787==    by 0x5DBA00: XNFstrdup (utils.c:1124)
    ==22787==    by 0x4D72ED: xf86DuplicateMode (xf86Modes.c:209)
    ==22787==    by 0x4CA848: xf86CrtcSetModeTransform (xf86Crtc.c:276)
    ==22787==    by 0x4D05B4: xf86SetDesiredModes (xf86Crtc.c:2677)
    ==22787==    by 0xA7479D0: sna_create_screen_resources
    (sna_driver.c:220)
    ==22787==    by 0x4CB914: xf86CrtcCreateScreenResources (xf86Crtc.c:725)
    ==22787==    by 0x425498: main (main.c:216)
    ==22787==  Address 0x72c60e0 is 0 bytes inside a block of size 9 free'd
    ==22787==    at 0x4027AAE: free (in
    /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==22787==    by 0x4A547E: xf86DeleteMode (xf86Mode.c:1984)
    ==22787==    by 0x4CD84F: xf86ProbeOutputModes (xf86Crtc.c:1578)
    ==22787==    by 0x4DC405: xf86RandR12GetInfo12 (xf86RandR12.c:1537)
    ==22787==    by 0x518119: RRGetInfo (rrinfo.c:202)
    ==22787==    by 0x51D997: rrGetScreenResources (rrscreen.c:335)
    ==22787==    by 0x51E0D0: ProcRRGetScreenResources (rrscreen.c:475)
    ==22787==    by 0x513852: ProcRRDispatch (randr.c:493)
    ==22787==    by 0x4346DB: Dispatch (dispatch.c:439)
    ==22787==    by 0x4256E4: main (main.c:287)
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>
    Reported-by: Zdenek Kabelac <zdenek.kabelac at gmail.com>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=36108
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 8dc7dcc..bb2903d 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -422,6 +422,8 @@ extern _X_EXPORT void
 xf86SetModeCrtc(DisplayModePtr p, int adjustFlags);
 extern _X_EXPORT DisplayModePtr
 xf86DuplicateMode(const DisplayModeRec * pMode);
+extern _X_EXPORT void
+xf86SaveModeContents(DisplayModePtr intern, const DisplayModeRec * pMode);
 extern _X_EXPORT DisplayModePtr
 xf86DuplicateModes(ScrnInfoPtr pScrn, DisplayModePtr modeList);
 extern _X_EXPORT Bool
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index d20152c..2628409 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -2453,7 +2453,7 @@ xf86InitialConfiguration(ScrnInfoPtr scrn, Bool canGrow)
         xf86CrtcPtr crtc = crtcs[o];
 
         if (mode && crtc) {
-            crtc->desiredMode = *mode;
+            xf86SaveModeContents(&crtc->desiredMode, mode);
             crtc->desiredRotation = output->initial_rotation;
             crtc->desiredX = output->initial_x;
             crtc->desiredY = output->initial_y;
@@ -2637,7 +2637,7 @@ xf86SetDesiredModes(ScrnInfoPtr scrn)
 
             if (!mode)
                 return FALSE;
-            crtc->desiredMode = *mode;
+            xf86SaveModeContents(&crtc->desiredMode, mode);
             crtc->desiredRotation = RR_Rotate_0;
             crtc->desiredTransformPresent = FALSE;
             crtc->desiredX = 0;
@@ -2776,7 +2776,7 @@ xf86SetSingleMode(ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation)
         if (!xf86CrtcSetModeTransform(crtc, crtc_mode, rotation, NULL, 0, 0))
             ok = FALSE;
         else {
-            crtc->desiredMode = *crtc_mode;
+            xf86SaveModeContents(&crtc->desiredMode, crtc_mode);
             crtc->desiredRotation = rotation;
             crtc->desiredTransformPresent = FALSE;
             crtc->desiredX = 0;
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
index 2a6d267..c4a3eb0 100644
--- a/hw/xfree86/modes/xf86Modes.c
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -191,6 +191,21 @@ xf86SetModeCrtc(DisplayModePtr p, int adjustFlags)
 }
 
 /**
+ * Fills in a copy of mode, removing all stale pointer references.
+ * xf86ModesEqual will return true when comparing with original mode.
+ */
+void
+xf86SaveModeContents(DisplayModePtr intern, const DisplayModeRec *mode)
+{
+    *intern = *mode;
+    intern->prev = intern->next = NULL;
+    intern->name = NULL;
+    intern->PrivSize = 0;
+    intern->PrivFlags = 0;
+    intern->Private = NULL;
+}
+
+/**
  * Allocates and returns a copy of pMode, including pointers within pMode.
  */
 DisplayModePtr
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index b4ed46a..4be0ea3 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1219,7 +1219,7 @@ xf86RandR12CrtcSet(ScreenPtr pScreen,
             /*
              * Save the last successful setting for EnterVT
              */
-            crtc->desiredMode = mode;
+            xf86SaveModeContents(&crtc->desiredMode, &mode);
             crtc->desiredRotation = rotation;
             crtc->current_scanout = randr_crtc->scanout_pixmap;
             if (transform) {
commit 59c2c4f645b4d782599c274f4bc752de9623d308
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 09:10:22 2012 +0100

    AllocDevicePair: Ensure XKB privates are initialised
    
    Since we call directly into XKB and may be doing so before the extension
    has been initialised, make sure its privates are set up first.  XTest
    had a hack to do this itself, but seems cleaner to just make sure we do
    it in AllocDevicePair.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/devices.c b/dix/devices.c
index 207b78b..9cf04ed 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2674,6 +2674,8 @@ AllocDevicePair(ClientPtr client, const char *name,
 
     *ptr = *keybd = NULL;
 
+    XkbInitPrivates();
+
     pointer = AddInputDevice(client, ptr_proc, TRUE);
 
     if (!pointer)
diff --git a/test/xtest.c b/test/xtest.c
index 99e2185..402d9ce 100644
--- a/test/xtest.c
+++ b/test/xtest.c
@@ -76,8 +76,6 @@ xtest_init_devices(void)
     InitAtoms();
     SyncExtensionInit();
 
-    XkbInitPrivates();
-
     /* this also inits the xtest devices */
     InitCoreDevices();
 
commit f937c3d50157a9a42d2f2f10590b6b139ce18a29
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 09:10:21 2012 +0100

    Sync: Always initialise system counter list
    
    Sync is designed to let you add system counters before the extension has
    been initialised, which means the system counter list may well be full
    of bees.  Make sure it's initialised before we add to it, to avoid the
    risk of fatal injury.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/sync.c b/Xext/sync.c
index 8a333dd..b8f094d 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -951,6 +951,7 @@ SyncCreateSystemCounter(const char *name,
         if (RTCounter == 0) {
             return NULL;
         }
+        xorg_list_init(&SysCounterList);
     }
 
     pCounter = SyncCreateCounter(NULL, FakeClientID(0), initial);
@@ -2448,13 +2449,12 @@ SyncExtensionInit(void)
     ExtensionEntry *extEntry;
     int s;
 
-    xorg_list_init(&SysCounterList);
-
     for (s = 0; s < screenInfo.numScreens; s++)
         miSyncSetup(screenInfo.screens[s]);
 
     if (RTCounter == 0) {
         RTCounter = CreateNewResourceType(FreeCounter, "SyncCounter");
+        xorg_list_init(&SysCounterList);
     }
     RTAlarm = CreateNewResourceType(FreeAlarm, "SyncAlarm");
     RTAwait = CreateNewResourceType(FreeAwait, "SyncAwait");
commit 34cf559bcf99dad550527b5ff53f247f0e8e73ee
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Jul 10 15:58:48 2012 -0700

    ProcGetPointerMapping uses rep.nElts before it is initialized
    
    In:
    
    	commit d792ac125a0462a04a930af543cbc732f8cdab7d
    	Author: Alan Coopersmith <alan.coopersmith at oracle.com>
    	Date:   Mon Jul 9 19:12:43 2012 -0700
    
    	    Use C99 designated initializers in dix Replies
    
    the initializer for the .length element of the xGetPointerMappingReply
    structure uses the value of rep.nElts, but that won't be set until
    after this initializer runs, so we get garbage in the length element
    and clients using it will generally wedge.
    
    Easy to verify:
    
    	$ xmodmap -pp
    
    Fixed by creating a local nElts variable and using that.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/dix/devices.c b/dix/devices.c
index 839de35..207b78b 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1890,6 +1890,7 @@ ProcGetPointerMapping(ClientPtr client)
      * the ClientPointer could change. */
     DeviceIntPtr ptr = PickPointer(client);
     ButtonClassPtr butc = ptr->button;
+    int nElts;
     int rc;
 
     REQUEST_SIZE_MATCH(xReq);
@@ -1898,15 +1899,16 @@ ProcGetPointerMapping(ClientPtr client)
     if (rc != Success)
         return rc;
 
+    nElts = (butc) ? butc->numButtons : 0;
     rep = (xGetPointerMappingReply) {
         .type = X_Reply,
-        .nElts = (butc) ? butc->numButtons : 0,
+        .nElts = nElts,
         .sequenceNumber = client->sequence,
-        .length = ((unsigned) rep.nElts + (4 - 1)) / 4
+        .length = ((unsigned) nElts + (4 - 1)) / 4
     };
     WriteReplyToClient(client, sizeof(xGetPointerMappingReply), &rep);
     if (butc)
-        WriteToClient(client, (int) rep.nElts, &butc->map[1]);
+        WriteToClient(client, nElts, &butc->map[1]);
     return Success;
 }
 
commit 44bd27cdd13b6e6c4e6fd3873361e3308ef25ffe
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Jul 10 01:14:13 2012 -0700

    Version 1.12.99.901 (1.13 RC1)
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 1d915f1..6456192 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,8 +26,8 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.12.99.0, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2012-03-14"
+AC_INIT([xorg-server], 1.12.99.901, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2012-07-10"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AM_MAINTAINER_MODE
commit 6e12cb147da58bd12a158807b2cd5afac32ae70f
Merge: 532fbc2 0231279
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Jul 10 00:52:11 2012 -0700

    Merge branch 'local-fixes'

commit 532fbc29c900469ef4867ccb7eabb953019dcab5
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:38 2012 +0100

    GE: Remove unused RT_GECLIENT
    
    Remove remnants of an earlier experiment which had the GE extension
    handling event delivery directly.  Nothing's used the resource since, so
    purge it.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/geext.c b/Xext/geext.c
index ad7f963..1e5ae6f 100644
--- a/Xext/geext.c
+++ b/Xext/geext.c
@@ -36,8 +36,6 @@
 
 DevPrivateKeyRec GEClientPrivateKeyRec;
 
-int RT_GECLIENT = 0;
-
 GEExtension GEExtensions[MAXEXTENSIONS];
 
 /* Major available requests */
commit 0e70b333d4846b166bf4a0a0c5d1a80623ba08dc
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:37 2012 +0100

    XFree86: os-support: Remove unused xf86MakeNewMapping
    
    No drivers used this, so it got unexported, and now it's so unused it
    got culled during the link.  Take the poor function out behind the shed
    and put it out of its misery.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/os-support/shared/vidmem.c b/hw/xfree86/os-support/shared/vidmem.c
index a7717d8..514fc2f 100644
--- a/hw/xfree86/os-support/shared/vidmem.c
+++ b/hw/xfree86/os-support/shared/vidmem.c
@@ -157,19 +157,6 @@ checkMtrrOption(VidMapPtr vp)
 }
 
 void
-xf86MakeNewMapping(int ScreenNum, int Flags, unsigned long Base,
-                   unsigned long Size, pointer Vbase)
-{
-    VidMapPtr vp;
-    MappingPtr mp;
-
-    vp = getVidMapRec(ScreenNum);
-    mp = newMapping(vp);
-    mp->size = Size;
-    mp->virtBase = Vbase;
-}
-
-void
 xf86InitVidMem(void)
 {
     if (!vidMemInfo.initialised) {
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index 2f0172e..ea2b16e 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -215,8 +215,6 @@ extern _X_EXPORT int xf86ProcessArgument(int, char **, int);
 extern _X_EXPORT void xf86UseMsg(void);
 extern _X_EXPORT PMClose xf86OSPMOpen(void);
 
-extern _X_EXPORT _X_DEPRECATED void xf86MakeNewMapping(int, int, unsigned long,
-                                                       unsigned long, pointer);
 extern _X_EXPORT void xf86InitVidMem(void);
 
 #endif                          /* XF86_OS_PRIVS */
commit 43f2393746c44e9d35be6a2a3555205f8e1b4ddf
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:36 2012 +0100

    Xinerama: Reset Composite request vector on close
    
    Similar (identical) to how it interacts with Render and XFixes, also
    call PanoramiXCompositeReset() to restore the Composite dispatch table
    to how it was when it started, on reset.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 3398a8d..5653c08 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -895,6 +895,9 @@ PanoramiXResetProc(ExtensionEntry * extEntry)
 #ifdef XFIXES
     PanoramiXFixesReset();
 #endif
+#ifdef COMPOSITE
+    PanoramiXCompositeReset ();
+#endif
     screenInfo.numScreens = PanoramiXNumScreens;
     for (i = 256; i--;)
         ProcVector[i] = SavedProcVector[i];
commit 766a403bc7ff249fdc6b9049329b633e73738329
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:35 2012 +0100

    XvMC: Remove unused XvMCGeneration
    
    I wonder if this even works across multiple generations.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index ad7956b..8d93cc3 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -37,8 +37,6 @@ static DevPrivateKeyRec XvMCScreenKeyRec;
 #define XvMCScreenKey (&XvMCScreenKeyRec)
 static Bool XvMCInUse;
 
-unsigned long XvMCGeneration = 0;
-
 int XvMCReqCode;
 int XvMCEventBase;
 
commit 7cef23a6dd7a5d76983cf20979e845ea6ae63a10
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:34 2012 +0100

    Render: Remove unused glyphDepths
    
    No-one has used this since 0a71e154.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/render/glyph.c b/render/glyph.c
index c121e64..e1dc662 100644
--- a/render/glyph.c
+++ b/render/glyph.c
@@ -80,8 +80,6 @@ static GlyphHashSetRec glyphHashSets[] = {
 
 #define NGLYPHHASHSETS	(sizeof(glyphHashSets)/sizeof(glyphHashSets[0]))
 
-static const CARD8 glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 };
-
 static GlyphHashRec globalGlyphs[GlyphFormatNum];
 
 void
commit 65011064d7e70aed59fb716f9ed3d76d196244ce
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:33 2012 +0100

    Xi: Remove dead Device{Enter,Leave}WindowMask
    
    These were an unused remnant of earlier MPX work; their only users got
    cleared out in dc153271, but the mask declarations remained.  Remove
    them, and move DevicePropertyNotify's mask up to be contiguous with the
    rest of the range.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xi/extinit.c b/Xi/extinit.c
index 52d248b..eac2586 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -148,10 +148,8 @@ const Mask ChangeDeviceNotifyMask = (1L << 16);
 const Mask DeviceButtonGrabMask = (1L << 17);
 const Mask DeviceOwnerGrabButtonMask = (1L << 17);
 const Mask DevicePresenceNotifyMask = (1L << 18);
-const Mask DeviceEnterWindowMask = (1L << 18);
-const Mask DeviceLeaveWindowMask = (1L << 19);
-const Mask DevicePropertyNotifyMask = (1L << 20);
-const Mask XIAllMasks = (1L << 21) - 1;
+const Mask DevicePropertyNotifyMask = (1L << 19);
+const Mask XIAllMasks = (1L << 20) - 1;
 
 int ExtEventIndex;
 Mask ExtExclusiveMasks[EMASKSIZE];
commit fadfc2947075c832cd1107d2c0866ad13fa756c4
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:32 2012 +0100

    GLX: Remove unused noGlxVisualInit
    
    No-one ever did anything with this variable except assign its default
    value to it.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index fe3dae6..a5225dc 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -42,10 +42,6 @@
 
 extern int KdTsPhyScreen;
 
-#ifdef GLXEXT
-extern Bool noGlxVisualInit;
-#endif
-
 KdKeyboardInfo *ephyrKbd;
 KdPointerInfo *ephyrMouse;
 EphyrKeySyms ephyrKeySyms;
@@ -624,12 +620,9 @@ ephyrInitScreen(ScreenPtr pScreen)
     }
 #endif /*XV*/
 #ifdef XF86DRI
-        if (!ephyrNoDRI && !hostx_has_dri()) {
+    if (!ephyrNoDRI && !hostx_has_dri()) {
         EPHYR_LOG("host x does not support DRI. Disabling DRI forwarding\n");
         ephyrNoDRI = TRUE;
-#ifdef GLXEXT
-        noGlxVisualInit = FALSE;
-#endif
     }
     if (!ephyrNoDRI) {
         ephyrDRIExtensionInit(pScreen);
@@ -637,12 +630,6 @@ ephyrInitScreen(ScreenPtr pScreen)
     }
 #endif
 
-#ifdef GLXEXT
-    if (ephyrNoDRI) {
-        noGlxVisualInit = FALSE;
-    }
-#endif
-
     return TRUE;
 }
 
diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index a62b49d..5e2eb67 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -36,7 +36,6 @@ extern Bool kdHasKbd;
 
 #ifdef GLXEXT
 extern Bool ephyrNoDRI;
-extern Bool noGlxVisualInit;
 #endif
 extern Bool ephyrNoXV;
 
@@ -233,7 +232,6 @@ ddxProcessArgument(int argc, char **argv, int i)
     }
 #ifdef GLXEXT
     else if (!strcmp(argv[i], "-nodri")) {
-        noGlxVisualInit = FALSE;
         ephyrNoDRI = TRUE;
         EPHYR_LOG("no direct rendering enabled\n");
         return 1;
diff --git a/os/utils.c b/os/utils.c
index b00d38b..b50cbdb 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -138,7 +138,6 @@ Bool noDPMSExtension = FALSE;
 #endif
 #ifdef GLXEXT
 Bool noGlxExtension = FALSE;
-Bool noGlxVisualInit = FALSE;
 #endif
 #ifdef SCREENSAVER
 Bool noScreenSaverExtension = FALSE;
commit 06e4ba8b26fb974bdd84144b3e002f0f7589e7f7
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:31 2012 +0100

    XKB: Geom: Remove unused code
    
    These codepaths were never called by anyone.  Shame there weren't more
    of them.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/xkb/XKBGAlloc.c b/xkb/XKBGAlloc.c
index f7e0176..8880784 100644
--- a/xkb/XKBGAlloc.c
+++ b/xkb/XKBGAlloc.c
@@ -249,51 +249,6 @@ XkbFreeGeomOverlayKeys(XkbOverlayRowPtr row, int first, int count, Bool freeAll)
 
 /***====================================================================***/
 
-static void
-_XkbClearOverlayRow(char *row_in)
-{
-    XkbOverlayRowPtr row = (XkbOverlayRowPtr) row_in;
-
-    if (row->keys != NULL)
-        XkbFreeGeomOverlayKeys(row, 0, row->num_keys, TRUE);
-    return;
-}
-
-void
-XkbFreeGeomOverlayRows(XkbOverlayPtr overlay, int first, int count,
-                       Bool freeAll)
-{
-    _XkbFreeGeomNonLeafElems(freeAll, first, count,
-                             &overlay->num_rows, &overlay->sz_rows,
-                             (char **) &overlay->rows,
-                             sizeof(XkbOverlayRowRec), _XkbClearOverlayRow);
-    return;
-}
-
-/***====================================================================***/
-
-static void
-_XkbClearOverlay(char *overlay_in)
-{
-    XkbOverlayPtr overlay = (XkbOverlayPtr) overlay_in;
-
-    if (overlay->rows != NULL)
-        XkbFreeGeomOverlayRows(overlay, 0, overlay->num_rows, TRUE);
-    return;
-}
-
-void
-XkbFreeGeomOverlays(XkbSectionPtr section, int first, int count, Bool freeAll)
-{
-    _XkbFreeGeomNonLeafElems(freeAll, first, count,
-                             &section->num_overlays, &section->sz_overlays,
-                             (char **) &section->overlays,
-                             sizeof(XkbOverlayRec), _XkbClearOverlay);
-    return;
-}
-
-/***====================================================================***/
-
 void
 XkbFreeGeomKeys(XkbRowPtr row, int first, int count, Bool freeAll)
 {
@@ -543,90 +498,6 @@ _XkbGeomAlloc(void **old,
 				(n),sizeof(XkbOverlayKeyRec))
 
 Status
-XkbAllocGeomProps(XkbGeometryPtr geom, int nProps)
-{
-    return _XkbAllocProps(geom, nProps);
-}
-
-Status
-XkbAllocGeomColors(XkbGeometryPtr geom, int nColors)
-{
-    return _XkbAllocColors(geom, nColors);
-}
-
-Status
-XkbAllocGeomKeyAliases(XkbGeometryPtr geom, int nKeyAliases)
-{
-    return _XkbAllocKeyAliases(geom, nKeyAliases);
-}
-
-Status
-XkbAllocGeomShapes(XkbGeometryPtr geom, int nShapes)
-{
-    return _XkbAllocShapes(geom, nShapes);
-}
-
-Status
-XkbAllocGeomSections(XkbGeometryPtr geom, int nSections)
-{
-    return _XkbAllocSections(geom, nSections);
-}
-
-Status
-XkbAllocGeomOverlays(XkbSectionPtr section, int nOverlays)
-{
-    return _XkbAllocOverlays(section, nOverlays);
-}
-
-Status
-XkbAllocGeomOverlayRows(XkbOverlayPtr overlay, int nRows)
-{
-    return _XkbAllocOverlayRows(overlay, nRows);
-}
-
-Status
-XkbAllocGeomOverlayKeys(XkbOverlayRowPtr row, int nKeys)
-{
-    return _XkbAllocOverlayKeys(row, nKeys);
-}
-
-Status
-XkbAllocGeomDoodads(XkbGeometryPtr geom, int nDoodads)
-{
-    return _XkbAllocDoodads(geom, nDoodads);
-}
-
-Status
-XkbAllocGeomSectionDoodads(XkbSectionPtr section, int nDoodads)
-{
-    return _XkbAllocDoodads(section, nDoodads);
-}
-
-Status
-XkbAllocGeomOutlines(XkbShapePtr shape, int nOL)
-{
-    return _XkbAllocOutlines(shape, nOL);
-}
-
-Status
-XkbAllocGeomRows(XkbSectionPtr section, int nRows)
-{
-    return _XkbAllocRows(section, nRows);
-}
-
-Status
-XkbAllocGeomPoints(XkbOutlinePtr ol, int nPts)
-{
-    return _XkbAllocPoints(ol, nPts);
-}
-
-Status
-XkbAllocGeomKeys(XkbRowPtr row, int nKeys)
-{
-    return _XkbAllocKeys(row, nKeys);
-}
-
-Status
 XkbAllocGeometry(XkbDescPtr xkb, XkbGeometrySizesPtr sizes)
 {
     XkbGeometryPtr geom;
diff --git a/xkb/xkbgeom.h b/xkb/xkbgeom.h
index bef3775..1999f5c 100644
--- a/xkb/xkbgeom.h
+++ b/xkb/xkbgeom.h
@@ -41,28 +41,11 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #define XkbAddGeomRow			SrvXkbAddGeomRow
 #define XkbAddGeomSection		SrvXkbAddGeomSection
 #define XkbAddGeomShape			SrvXkbAddGeomShape
-#define XkbAllocGeomKeyAliases		SrvXkbAllocGeomKeyAliases
-#define XkbAllocGeomColors		SrvXkbAllocGeomColors
-#define XkbAllocGeomDoodads		SrvXkbAllocGeomDoodads
-#define XkbAllocGeomKeys		SrvXkbAllocGeomKeys
-#define XkbAllocGeomOutlines		SrvXkbAllocGeomOutlines
-#define XkbAllocGeomPoints		SrvXkbAllocGeomPoints
-#define XkbAllocGeomProps		SrvXkbAllocGeomProps
-#define XkbAllocGeomRows		SrvXkbAllocGeomRows
-#define XkbAllocGeomSectionDoodads	SrvXkbAllocGeomSectionDoodads
-#define XkbAllocGeomSections		SrvXkbAllocGeomSections
-#define	XkbAllocGeomOverlays		SrvXkbAllocGeomOverlays
-#define	XkbAllocGeomOverlayRows		SrvXkbAllocGeomOverlayRows
-#define	XkbAllocGeomOverlayKeys		SrvXkbAllocGeomOverlayKeys
-#define XkbAllocGeomShapes		SrvXkbAllocGeomShapes
 #define XkbAllocGeometry		SrvXkbAllocGeometry
 #define XkbFreeGeomKeyAliases		SrvXkbFreeGeomKeyAliases
 #define XkbFreeGeomColors		SrvXkbFreeGeomColors
 #define XkbFreeGeomDoodads		SrvXkbFreeGeomDoodads
 #define XkbFreeGeomProperties		SrvXkbFreeGeomProperties
-#define	XkbFreeGeomOverlayKeys		SrvXkbFreeGeomOverlayKeys
-#define	XkbFreeGeomOverlayRows		SrvXkbFreeGeomOverlayRows
-#define	XkbFreeGeomOverlays		SrvXkbFreeGeomOverlays
 #define	XkbFreeGeomKeys			SrvXkbFreeGeomKeys
 #define	XkbFreeGeomRows			SrvXkbFreeGeomRows
 #define XkbFreeGeomSections		SrvXkbFreeGeomSections
commit e191e296e6e7861978ea4a0ae9aa7b780e52732b
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Mon Jul 9 20:04:15 2012 +0100

    Remove XAA
    
    Commit 0c6987df in June 2008 disabled XAA offscreen pixmaps per default,
    as they were broken, leaving XAA only able to accelerate operations
    directly on the screen pixmap and nowhere else, eliminating acceleration
    for basically every modern toolkit, and any composited environment.
    
    So, it hasn't worked for over four years.  No-one's even come close to
    fixing it.
    
    RIP.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Alex Deucher <alexdeucher at gmail.com>

diff --git a/configure.ac b/configure.ac
index 209b237..1d915f1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -620,7 +620,6 @@ AC_ARG_ENABLE(config-dbus,    AS_HELP_STRING([--enable-config-dbus], [Build D-BU
 AC_ARG_ENABLE(config-hal,     AS_HELP_STRING([--disable-config-hal], [Build HAL support (default: auto)]), [CONFIG_HAL=$enableval], [CONFIG_HAL=auto])
 AC_ARG_ENABLE(config-wscons,  AS_HELP_STRING([--enable-config-wscons], [Build wscons config support (default: auto)]), [CONFIG_WSCONS=$enableval], [CONFIG_WSCONS=auto])
 AC_ARG_ENABLE(xfree86-utils,     AS_HELP_STRING([--enable-xfree86-utils], [Build xfree86 DDX utilities (default: enabled)]), [XF86UTILS=$enableval], [XF86UTILS=yes])
-AC_ARG_ENABLE(xaa,               AS_HELP_STRING([--enable-xaa], [Build XAA (default: enabled)]), [XAA=$enableval], [XAA=yes])
 AC_ARG_ENABLE(vgahw,          AS_HELP_STRING([--enable-vgahw], [Build Xorg with vga access (default: enabled)]), [VGAHW=$enableval], [VGAHW=yes])
 AC_ARG_ENABLE(vbe,            AS_HELP_STRING([--enable-vbe], [Build Xorg with VBE module (default: enabled)]), [VBE=$enableval], [VBE=yes])
 AC_ARG_ENABLE(int10-module,     AS_HELP_STRING([--enable-int10-module], [Build Xorg with int10 module (default: enabled)]), [INT10MODULE=$enableval], [INT10MODULE=yes])
@@ -712,7 +711,6 @@ case $host_os in
 		PCI=no
 		VGAHW=no
 		VBE=no
-		XAA=no
 		XF86UTILS=no
 		XF86VIDMODE=no
 		XSELINUX=no
@@ -1209,7 +1207,6 @@ XI_LIB='$(top_builddir)/Xi/libXi.la'
 XI_INC='-I$(top_srcdir)/Xi'
 
 AM_CONDITIONAL(XF86UTILS, test "x$XF86UTILS" = xyes)
-AM_CONDITIONAL(XAA, test "x$XAA" = xyes)
 AM_CONDITIONAL(VGAHW, test "x$VGAHW" = xyes)
 AM_CONDITIONAL(VBE, test "x$VBE" = xyes)
 AM_CONDITIONAL(INT10MODULE, test "x$INT10MODULE" = xyes)
@@ -2267,7 +2264,6 @@ hw/xfree86/shadowfb/Makefile
 hw/xfree86/vbe/Makefile
 hw/xfree86/vgahw/Makefile
 hw/xfree86/x86emu/Makefile
-hw/xfree86/xaa/Makefile
 hw/xfree86/utils/Makefile
 hw/xfree86/utils/man/Makefile
 hw/xfree86/utils/cvt/Makefile
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index cd699ee..c3899b5 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -13,8 +13,6 @@ if XF86UTILS
 XF86UTILS_SUBDIR = utils
 endif
 
-XAA_SUBDIR = xaa
-
 if VGAHW
 VGAHW_SUBDIR = vgahw
 endif
@@ -29,11 +27,11 @@ endif
 
 SUBDIRS = common ddc x86emu $(INT10_SUBDIR) os-support parser \
 	  ramdac $(VGAHW_SUBDIR) loader modes $(DRI_SUBDIR) \
-	  $(DRI2_SUBDIR) . $(VBE_SUBDIR) $(XAA_SUBDIR) i2c dixmods \
+	  $(DRI2_SUBDIR) . $(VBE_SUBDIR) i2c dixmods \
 	  fbdevhw shadowfb exa $(XF86UTILS_SUBDIR) doc man
 
 DIST_SUBDIRS = common ddc i2c x86emu int10 fbdevhw os-support \
-               parser ramdac shadowfb vbe vgahw xaa \
+               parser ramdac shadowfb vbe vgahw \
                loader dixmods dri dri2 exa modes \
 	       utils doc man
 
diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index 325875d..f8fcde9 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -62,7 +62,8 @@ sdk_HEADERS = compiler.h fourcc.h xf86.h xf86Module.h xf86Opt.h \
               xf86PciInfo.h xf86Priv.h xf86Privstr.h \
               xf86cmap.h xf86fbman.h xf86str.h xf86Xinput.h xisb.h \
               $(XVSDKINCS) $(XF86VMODE_SDK) $(DGA_SDK) xorgVersion.h \
-              xf86sbusBus.h xf86VGAarbiter.h xf86Optionstr.h xf86platformBus.h
+              xf86sbusBus.h xf86VGAarbiter.h xf86Optionstr.h xf86platformBus.h \
+	      xaarop.h
 
 DISTCLEANFILES = xf86Build.h
 CLEANFILES = $(BUILT_SOURCES)
@@ -94,7 +95,8 @@ EXTRA_DIST = \
 	modeline2c.awk \
 	xf86VGAarbiter.h \
 	xf86VGAarbiterPriv.h \
-        $(DISTKBDSOURCES)
+        $(DISTKBDSOURCES) \
+	xaarop.h
 
 if LNXACPI
 XORG_CFLAGS += -DHAVE_ACPI
diff --git a/hw/xfree86/common/xaarop.h b/hw/xfree86/common/xaarop.h
new file mode 100644
index 0000000..f2acde0
--- /dev/null
+++ b/hw/xfree86/common/xaarop.h
@@ -0,0 +1,311 @@
+/*
+
+   int XAAHelpSolidROP(ScrnInfoPtr pScrn, int *fg, int pm, int *rop)
+
+	For use with solid fills emulated by solid 8x8 patterns.  You 
+	give it the foreground, planemask and X rop and it will replace 
+	the foreground with a new one and the rop with the appropriate 
+	MS triadic raster op.  The function will return which components 
+	(S-P) need to be enabled.  
+
+   int XAAHelpPatternROP(ScrnInfoPtr pScrn, int *fg, int *bg, int pm, int *rop)
+
+	For use with 8x8 opaque pattern fills.  You give it the foreground, 	
+	and background, planemask and X rop and it will replace the 
+	foreground and background with new ones and the rop with the 
+	appropriate MS triadic raster op.  The function will return which 
+	components (S-P) need to be enabled.  
+
+	   ROP_PAT - Means to enable 8x8 mono patterns (all bits 
+		     set for solid patterns).  Set the foreground and
+		     background as returned by the function.  
+
+	   ROP_SRC - Means a source of color == planemask should be used.
+
+
+*/
+
+#ifndef _XAAROP_H
+#define _XAAROP_H
+
+#define ROP_DST		0x00000001
+#define ROP_SRC		0x00000002
+#define ROP_PAT		0x00000004
+
+#define ROP_0		0x00
+#define ROP_DPSoon	0x01
+#define ROP_DPSona	0x02
+#define ROP_PSon	0x03
+#define ROP_SDPona	0x04
+#define ROP_DPon	0x05
+#define ROP_PDSxnon	0x06
+#define ROP_PDSaon	0x07
+#define ROP_SDPnaa	0x08
+#define ROP_PDSxon	0x09
+#define ROP_DPna	0x0A
+#define ROP_PSDnaon	0x0B
+#define ROP_SPna	0x0C
+#define ROP_PDSnaon	0x0D
+#define ROP_PDSonon	0x0E
+#define ROP_Pn		0x0F
+#define ROP_PDSona	0x10
+#define ROP_DSon	0x11
+#define ROP_SDPxnon	0x12
+#define ROP_SDPaon	0x13
+#define ROP_DPSxnon	0x14
+#define ROP_DPSaon	0x15
+#define ROP_PSDPSanaxx	0x16
+#define ROP_SSPxDSxaxn	0x17
+#define ROP_SPxPDxa	0x18
+#define ROP_SDPSanaxn	0x19
+#define ROP_PDSPaox	0x1A
+#define ROP_SDPSxaxn	0x1B
+#define ROP_PSDPaox	0x1C
+#define ROP_DSPDxaxn	0x1D
+#define ROP_PDSox	0x1E
+#define ROP_PDSoan	0x1F
+#define ROP_DPSnaa	0x20
+#define ROP_SDPxon	0x21
+#define ROP_DSna	0x22
+#define ROP_SPDnaon	0x23
+#define ROP_SPxDSxa	0x24
+#define ROP_PDSPanaxn	0x25
+#define ROP_SDPSaox	0x26
+#define ROP_SDPSxnox	0x27
+#define ROP_DPSxa	0x28
+#define ROP_PSDPSaoxxn	0x29
+#define ROP_DPSana	0x2A
+#define ROP_SSPxPDxaxn	0x2B
+#define ROP_SPDSoax	0x2C
+#define ROP_PSDnox	0x2D
+#define ROP_PSDPxox	0x2E
+#define ROP_PSDnoan	0x2F
+#define ROP_PSna	0x30
+#define ROP_SDPnaon	0x31
+#define ROP_SDPSoox	0x32
+#define ROP_Sn		0x33
+#define ROP_SPDSaox	0x34
+#define ROP_SPDSxnox	0x35
+#define ROP_SDPox	0x36
+#define ROP_SDPoan	0x37
+#define ROP_PSDPoax	0x38
+#define ROP_SPDnox	0x39
+#define ROP_SPDSxox	0x3A
+#define ROP_SPDnoan	0x3B
+#define ROP_PSx		0x3C
+#define ROP_SPDSonox	0x3D
+#define ROP_SPDSnaox	0x3E
+#define ROP_PSan	0x3F
+#define ROP_PSDnaa	0x40
+#define ROP_DPSxon	0x41
+#define ROP_SDxPDxa	0x42
+#define ROP_SPDSanaxn	0x43
+#define ROP_SDna	0x44
+#define ROP_DPSnaon	0x45
+#define ROP_DSPDaox	0x46
+#define ROP_PSDPxaxn	0x47
+#define ROP_SDPxa	0x48
+#define ROP_PDSPDaoxxn	0x49
+#define ROP_DPSDoax	0x4A
+#define ROP_PDSnox	0x4B
+#define ROP_SDPana	0x4C
+#define ROP_SSPxDSxoxn	0x4D
+#define ROP_PDSPxox	0x4E
+#define ROP_PDSnoan	0x4F
+#define ROP_PDna	0x50
+#define ROP_DSPnaon	0x51
+#define ROP_DPSDaox	0x52
+#define ROP_SPDSxaxn	0x53
+#define ROP_DPSonon	0x54
+#define ROP_Dn		0x55
+#define ROP_DPSox	0x56
+#define ROP_DPSoan	0x57
+#define ROP_PDSPoax	0x58
+#define ROP_DPSnox	0x59
+#define ROP_DPx		0x5A
+#define ROP_DPSDonox	0x5B
+#define ROP_DPSDxox	0x5C
+#define ROP_DPSnoan	0x5D
+#define ROP_DPSDnaox	0x5E
+#define ROP_DPan	0x5F
+#define ROP_PDSxa	0x60
+#define ROP_DSPDSaoxxn	0x61
+#define ROP_DSPDoax	0x62
+#define ROP_SDPnox	0x63
+#define ROP_SDPSoax	0x64
+#define ROP_DSPnox	0x65
+#define ROP_DSx		0x66
+#define ROP_SDPSonox	0x67
+#define ROP_DSPDSonoxxn	0x68
+#define ROP_PDSxxn	0x69
+#define ROP_DPSax	0x6A
+#define ROP_PSDPSoaxxn	0x6B
+#define ROP_SDPax	0x6C
+#define ROP_PDSPDoaxxn	0x6D
+#define ROP_SDPSnoax	0x6E
+#define ROP_PDSxnan	0x6F
+#define ROP_PDSana	0x70
+#define ROP_SSDxPDxaxn	0x71
+#define ROP_SDPSxox	0x72
+#define ROP_SDPnoan	0x73
+#define ROP_DSPDxox	0x74
+#define ROP_DSPnoan	0x75
+#define ROP_SDPSnaox	0x76
+#define ROP_DSan	0x77
+#define ROP_PDSax	0x78
+#define ROP_DSPDSoaxxn	0x79
+#define ROP_DPSDnoax	0x7A
+#define ROP_SDPxnan	0x7B
+#define ROP_SPDSnoax	0x7C
+#define ROP_DPSxnan	0x7D
+#define ROP_SPxDSxo	0x7E
+#define ROP_DPSaan	0x7F
+#define ROP_DPSaa	0x80
+#define ROP_SPxDSxon	0x81
+#define ROP_DPSxna	0x82
+#define ROP_SPDSnoaxn	0x83
+#define ROP_SDPxna	0x84
+#define ROP_PDSPnoaxn	0x85
+#define ROP_DSPDSoaxx	0x86
+#define ROP_PDSaxn	0x87
+#define ROP_DSa		0x88
+#define ROP_SDPSnaoxn	0x89
+#define ROP_DSPnoa	0x8A
+#define ROP_DSPDxoxn	0x8B
+#define ROP_SDPnoa	0x8C
+#define ROP_SDPSxoxn	0x8D
+#define ROP_SSDxPDxax	0x8E
+#define ROP_PDSanan	0x8F
+#define ROP_PDSxna	0x90
+#define ROP_SDPSnoaxn	0x91
+#define ROP_DPSDPoaxx	0x92
+#define ROP_SPDaxn	0x93
+#define ROP_PSDPSoaxx	0x94
+#define ROP_DPSaxn	0x95
+#define ROP_DPSxx	0x96
+#define ROP_PSDPSonoxx	0x97
+#define ROP_SDPSonoxn	0x98
+#define ROP_DSxn	0x99
+#define ROP_DPSnax	0x9A
+#define ROP_SDPSoaxn	0x9B
+#define ROP_SPDnax	0x9C
+#define ROP_DSPDoaxn	0x9D
+#define ROP_DSPDSaoxx	0x9E
+#define ROP_PDSxan	0x9F
+#define ROP_DPa		0xA0
+#define ROP_PDSPnaoxn	0xA1
+#define ROP_DPSnoa	0xA2
+#define ROP_DPSDxoxn	0xA3
+#define ROP_PDSPonoxn	0xA4
+#define ROP_PDxn	0xA5
+#define ROP_DSPnax	0xA6
+#define ROP_PDSPoaxn	0xA7
+#define ROP_DPSoa	0xA8
+#define ROP_DPSoxn	0xA9
+#define ROP_D		0xAA
+#define ROP_DPSono	0xAB
+#define ROP_SPDSxax	0xAC
+#define ROP_DPSDaoxn	0xAD
+#define ROP_DSPnao	0xAE
+#define ROP_DPno	0xAF
+#define ROP_PDSnoa	0xB0
+#define ROP_PDSPxoxn	0xB1
+#define ROP_SSPxDSxox	0xB2
+#define ROP_SDPanan	0xB3
+#define ROP_PSDnax	0xB4
+#define ROP_DPSDoaxn	0xB5
+#define ROP_DPSDPaoxx	0xB6
+#define ROP_SDPxan	0xB7
+#define ROP_PSDPxax	0xB8
+#define ROP_DSPDaoxn	0xB9
+#define ROP_DPSnao	0xBA
+#define ROP_DSno	0xBB
+#define ROP_SPDSanax	0xBC
+#define ROP_SDxPDxan	0xBD
+#define ROP_DPSxo	0xBE
+#define ROP_DPSano	0xBF
+#define ROP_Psa		0xC0
+#define ROP_SPDSnaoxn	0xC1
+#define ROP_SPDSonoxn	0xC2
+#define ROP_PSxn	0xC3
+#define ROP_SPDnoa	0xC4
+#define ROP_SPDSxoxn	0xC5
+#define ROP_SDPnax	0xC6
+#define ROP_PSDPoaxn	0xC7
+#define ROP_SDPoa	0xC8
+#define ROP_SPDoxn	0xC9
+#define ROP_DPSDxax	0xCA
+#define ROP_SPDSaoxn	0xCB
+#define ROP_S		0xCC
+#define ROP_SDPono	0xCD
+#define ROP_SDPnao	0xCE
+#define ROP_SPno	0xCF
+#define ROP_PSDnoa	0xD0
+#define ROP_PSDPxoxn	0xD1
+#define ROP_PDSnax	0xD2
+#define ROP_SPDSoaxn	0xD3
+#define ROP_SSPxPDxax	0xD4
+#define ROP_DPSanan	0xD5
+#define ROP_PSDPSaoxx	0xD6
+#define ROP_DPSxan	0xD7
+#define ROP_PDSPxax	0xD8
+#define ROP_SDPSaoxn	0xD9
+#define ROP_DPSDanax	0xDA
+#define ROP_SPxDSxan	0xDB
+#define ROP_SPDnao	0xDC
+#define ROP_SDno	0xDD
+#define ROP_SDPxo	0xDE
+#define ROP_SDPano	0xDF
+#define ROP_PDSoa	0xE0
+#define ROP_PDSoxn	0xE1
+#define ROP_DSPDxax	0xE2
+#define ROP_PSDPaoxn	0xE3
+#define ROP_SDPSxax	0xE4
+#define ROP_PDSPaoxn	0xE5
+#define ROP_SDPSanax	0xE6
+#define ROP_SPxPDxan	0xE7
+#define ROP_SSPxDSxax	0xE8
+#define ROP_DSPDSanaxxn	0xE9
+#define ROP_DPSao	0xEA
+#define ROP_DPSxno	0xEB
+#define ROP_SDPao	0xEC
+#define ROP_SDPxno	0xED
+#define ROP_DSo		0xEE
+#define ROP_SDPnoo	0xEF
+#define ROP_P		0xF0
+#define ROP_PDSono	0xF1
+#define ROP_PDSnao	0xF2
+#define ROP_PSno	0xF3
+#define ROP_PSDnao	0xF4
+#define ROP_PDno	0xF5
+#define ROP_PDSxo	0xF6
+#define ROP_PDSano	0xF7
+#define ROP_PDSao	0xF8
+#define ROP_PDSxno	0xF9
+#define ROP_DPo		0xFA
+#define ROP_DPSnoo	0xFB
+#define ROP_PSo		0xFC
+#define ROP_PSDnoo	0xFD
+#define ROP_DPSoo	0xFE
+#define ROP_1		0xFF
+
+#define NO_SRC_ROP(rop) \
+   ((rop == GXnoop) || (rop == GXset) || (rop == GXclear) || (rop == GXinvert))
+
+extern _X_EXPORT int XAAHelpSolidROP(ScrnInfoPtr pScrn, int *fg, int pm,
+                                     int *rop);
+extern _X_EXPORT int XAAHelpPatternROP(ScrnInfoPtr pScrn, int *fg, int *bg,
+                                       int pm, int *rop);
+
+/* XXX These four should be static, but it breaks the 6.7.0 ABI. */
+extern _X_EXPORT int XAACopyROP[16];
+extern _X_EXPORT int XAACopyROP_PM[16];
+extern _X_EXPORT int XAAPatternROP[16];
+extern _X_EXPORT int XAAPatternROP_PM[16];
+
+extern _X_EXPORT int XAAGetCopyROP(int i);
+extern _X_EXPORT int XAAGetCopyROP_PM(int i);
+extern _X_EXPORT int XAAGetPatternROP(int i);
+extern _X_EXPORT int XAAGetPatternROP_PM(int i);
+
+#endif                          /* _XAAROP_H */
diff --git a/hw/xfree86/doc/README.modes b/hw/xfree86/doc/README.modes
index 894e213..ea228e5 100644
--- a/hw/xfree86/doc/README.modes
+++ b/hw/xfree86/doc/README.modes
@@ -133,11 +133,10 @@ this function computes an initial configuration for the server. It tries to
 enable as much hardware as possible using some fairly simple heuristics. 
 
 The 'canGrow' parameter indicates that the frame buffer does not have a fixed
-size (fixed size frame buffers are required by XAA). When the frame buffer
-has a fixed size, the configuration selects a 'reasonablely large' frame
-buffer so that common reconfiguration options are possible. For resizable
-frame buffers, the frame buffer is set to the smallest size that encloses
-the desired configuration.
+size. When the frame buffer has a fixed size, the configuration selects a
+'reasonablely large' frame buffer so that common reconfiguration options are
+possible. For resizable frame buffers, the frame buffer is set to the smallest
+size that encloses the desired configuration.
     
 3.2 ScreenInit functions
 
diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml
index ce81a9d..4c2ca47 100644
--- a/hw/xfree86/doc/ddxDesign.xml
+++ b/hw/xfree86/doc/ddxDesign.xml
@@ -330,8 +330,8 @@ that.  This is a significant difference compared with the old design.
 
     <para>
 The entry points for drawing operations are already taken care of by
-the framebuffer code (including, XAA).  Extensions and enhancements to
-framebuffer code are outside the scope of this document.
+the framebuffer code.  Extensions and enhancements to framebuffer code
+are outside the scope of this document.
     </para>
 
     <para>
@@ -2003,10 +2003,9 @@ also include the video card's saved state.
       </para>
 
       <para>
-Per-screen data for other modules that the driver uses (for example,
-the XAA module) that is reset for each server generation is hooked into
-the <structname>ScrnInfoRec</structname> through it's <structfield>privates</structfield>
-field.
+Per-screen data for other modules that the driver uses that is reset for each
+server generation is hooked into the <structname>ScrnInfoRec</structname>
+through its <structfield>privates</structfield> field.
       </para>
 
       <para>
@@ -3615,14 +3614,6 @@ The following include files are typically required by video drivers:
 	  </para>
 
 	  <para>
-  If a driver uses XAA, it needs these:
-	    <literallayout><filename>
-    "xaa.h"
-    "xaalocal.h"
-	      </filename></literallayout>
-	  </para>
-
-	  <para>
   If a driver uses the fb manager, it needs this:
 	    <literallayout><filename>
     "xf86fbman.h"
@@ -3840,31 +3831,6 @@ manager is allowed to manage.  This is typically a box with a width of
 can be fit within the total video memory, however, the driver can reserve
 areas at the extremities by passing a smaller area to the manager.
     </para>
-
-    <para>
-<function>xf86InitFBManager()</function> must be called before XAA is
-initialized since XAA uses the manager for it's pixmap cache.
-    </para>
-
-    <para>
-An alternative function is provided to allow the driver to initialize
-the framebuffer manager with a Region rather than a box.
-
-    <programlisting>
-    Bool xf86InitFBManagerRegion(ScreenPtr pScreen,
-                                 RegionPtr FullRegion);
-    </programlisting>
-
-<function>xf86InitFBManagerRegion()</function>, unlike
-<function>xf86InitFBManager()</function>, does not remove the area used for
-the visible screen so that area should not be included in the region
-passed to the function.  <function>xf86InitFBManagerRegion()</function> is
-useful when non-contiguous areas are available to be managed, and is
-required when multiple framebuffers are stored in video memory (as in
-the case where an overlay of a different depth is stored as a second
-framebuffer in offscreen memory).
-    </para>
-
   </sect1>
 
   <sect1 id="cmap">
@@ -8900,12 +8866,6 @@ ZZZPreInit(ScrnInfoPtr pScrn, int flags)
         ZZZFreeRec(pScrn);
         return FALSE;
 
-    /* Load XAA if needed */
-    if (!pZzz-&gt;noAccel || pZzz-&gt;hwCursor)
-        if (!xf86LoadSubModule(pScrn, "xaa")) {
-            ZZZFreeRec(pScrn);
-            return FALSE;
-        }
 
     /* Done */
     return TRUE;
diff --git a/hw/xfree86/doc/exa-driver.txt b/hw/xfree86/doc/exa-driver.txt
index 048307e..da39d3f 100644
--- a/hw/xfree86/doc/exa-driver.txt
+++ b/hw/xfree86/doc/exa-driver.txt
@@ -8,15 +8,10 @@ from system memory, and Porter-Duff compositing and transform operations.
 
 Configuration
 -------------
-A new config file option, AccelMethod, should be added to your driver, to allow
-the user to select between the EXA and XAA acceleration APIs.
-
 Some drivers implement a per-instance useEXA flag to track whether EXA is
-active or not.  It can be helpful to also conditionalize XAA support with an
-ifdef so that it can easily be turned off/removed in the future.
+active or not.
 
-Setting the flag and checking for AccelMethod can be done in the driver's
-Options parsing routine.
+Setting the flag can be done in the driver's Options parsing routine.
 
 Loading EXA
 ------------
diff --git a/hw/xfree86/ramdac/.gitignore b/hw/xfree86/ramdac/.gitignore
deleted file mode 100644
index c55c8c1..0000000
--- a/hw/xfree86/ramdac/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-#		Add & Override for this directory and it's subdirectories
-xf86BitOrder.c
diff --git a/hw/xfree86/ramdac/Makefile.am b/hw/xfree86/ramdac/Makefile.am
index 3c37805..346af4c 100644
--- a/hw/xfree86/ramdac/Makefile.am
+++ b/hw/xfree86/ramdac/Makefile.am
@@ -1,19 +1,12 @@
 noinst_LTLIBRARIES = libramdac.la
 
 libramdac_la_SOURCES = xf86RamDac.c xf86RamDacCmap.c \
-                      xf86Cursor.c xf86HWCurs.c IBM.c BT.c TI.c \
-		      xf86BitOrder.c
+                      xf86Cursor.c xf86HWCurs.c IBM.c BT.c TI.c
 
 sdk_HEADERS = BT.h IBM.h TI.h xf86Cursor.h xf86RamDac.h
 
-DISTCLEANFILES = xf86BitOrder.c
 EXTRA_DIST = BTPriv.h IBMPriv.h TIPriv.h xf86CursorPriv.h xf86RamDacPriv.h \
 	CURSOR.NOTES
 
-AM_CFLAGS = -DXAAReverseBitOrder=xf86ReverseBitOrder -DRAMDAC_MODULE \
-            $(DIX_CFLAGS) $(XORG_CFLAGS)
+AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
 INCLUDES = $(XORG_INCS)
-
-xf86BitOrder.c:
-	$(AM_V_GEN)echo "#define XAAReverseBitOrder xf86ReverseBitOrder" > $@
-	$(AM_V_GEN)echo "#include \"$(srcdir)/../xaa/xaaBitOrder.c\"" >> $@
diff --git a/hw/xfree86/ramdac/xf86CursorPriv.h b/hw/xfree86/ramdac/xf86CursorPriv.h
index d04f932..04be141 100644
--- a/hw/xfree86/ramdac/xf86CursorPriv.h
+++ b/hw/xfree86/ramdac/xf86CursorPriv.h
@@ -43,8 +43,6 @@ void xf86MoveCursor(ScreenPtr pScreen, int x, int y);
 void xf86RecolorCursor(ScreenPtr pScreen, CursorPtr pCurs, Bool displayed);
 Bool xf86InitHardwareCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr);
 
-CARD32 xf86ReverseBitOrder(CARD32 data);
-
 extern _X_EXPORT DevPrivateKeyRec xf86CursorScreenKeyRec;
 
 #define xf86CursorScreenKey (&xf86CursorScreenKeyRec)
diff --git a/hw/xfree86/ramdac/xf86HWCurs.c b/hw/xfree86/ramdac/xf86HWCurs.c
index cb62d9b..197abff 100644
--- a/hw/xfree86/ramdac/xf86HWCurs.c
+++ b/hw/xfree86/ramdac/xf86HWCurs.c
@@ -21,6 +21,15 @@
 
 #include "servermd.h"
 
+static CARD32
+xf86ReverseBitOrder(CARD32 v)
+{
+    return (((0x01010101 & v) << 7) | ((0x02020202 & v) << 5) |
+            ((0x04040404 & v) << 3) | ((0x08080808 & v) << 1) |
+            ((0x10101010 & v) >> 1) | ((0x20202020 & v) >> 3) |
+            ((0x40404040 & v) >> 5) | ((0x80808080 & v) >> 7));
+}
+
 #if BITMAP_SCANLINE_PAD == 64
 
 #if 1
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index 420640f..c0398da 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -174,14 +174,6 @@ cat > sdksyms.c << EOF
 #endif
 
 
-/* hw/xfree86/xaa/Makefile.am -- module */
-/*
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaarop.h"
- */
-
-
 /* hw/xfree86/dixmods/extmod/Makefile.am -- module */
 #ifdef XFreeXDGA
 #include "dgaproc.h"
diff --git a/hw/xfree86/xaa/.gitignore b/hw/xfree86/xaa/.gitignore
deleted file mode 100644
index 1211d01..0000000
--- a/hw/xfree86/xaa/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-#		Add & Override for this directory and it's subdirectories
-[lms]-xaa*.c
-[lm]f3-xaa*.c
-[lm][f3]-xaa*.c
diff --git a/hw/xfree86/xaa/Makefile.am b/hw/xfree86/xaa/Makefile.am
deleted file mode 100644
index 5614d72..0000000
--- a/hw/xfree86/xaa/Makefile.am
+++ /dev/null
@@ -1,79 +0,0 @@
-LSB_FIRST = l-xaaBitmap.c l-xaaStipple.c l-xaaTEGlyph.c
-LSB_3_FIRST = l3-xaaBitmap.c l3-xaaStipple.c
-MSB_FIRST = m-xaaBitmap.c m-xaaStipple.c m-xaaTEGlyph.c
-MSB_3_FIRST = m3-xaaBitmap.c m3-xaaStipple.c
-LSB_FIXED = lf-xaaBitmap.c lf-xaaStipple.c lf-xaaTEGlyph.c
-LSB_3_FIXED = lf3-xaaBitmap.c lf3-xaaStipple.c
-MSB_FIXED = mf-xaaBitmap.c mf-xaaStipple.c mf-xaaTEGlyph.c
-MSB_3_FIXED = mf3-xaaBitmap.c mf3-xaaStipple.c
-POLYSEG = s-xaaLine.c s-xaaDashLine.c
-
-if XAA
-
-libxaa_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-libxaa_la_LIBADD = $(PIXMAN_LIBS)
-if COMPOSITE
-libxaa_la_LIBADD += $(top_builddir)/miext/cw/libcw.la
-endif
-
-module_LTLIBRARIES = libxaa.la
-libxaa_la_SOURCES = xaaInit.c xaaGC.c xaaInitAccel.c xaaFallback.c \
-                   xaaBitBlt.c xaaCpyArea.c xaaGCmisc.c xaaCpyWin.c \
-                   xaaCpyPlane.c xaaFillRect.c xaaTEText.c xaaNonTEText.c \
-                   xaaPCache.c xaaSpans.c xaaROP.c xaaImage.c \
-                   xaaRect.c xaaLineMisc.c xaaBitOrder.c \
-                   xaaFillPoly.c xaaWideLine.c xaaTables.c xaaFillArc.c \
-                   xaaLine.c xaaDashLine.c xaaOverlay.c xaaOffscreen.c \
-                   xaaOverlayDF.c xaaStateChange.c xaaPict.c $(POLYSEG) \
-                   $(LSB_FIRST) $(MSB_FIRST) $(LSB_FIXED) $(MSB_FIXED) \
-                   $(LSB_3_FIRST) $(MSB_3_FIRST) $(LSB_3_FIXED) $(MSB_3_FIXED)
-${POLYSEG}:
-	$(AM_V_GEN)echo "#define POLYSEGMENT" > $@
-	$(AM_V_GEN)echo '#include "$(srcdir)/${@:s-%=%}"' >> $@
-${LSB_FIRST}:
-	$(AM_V_GEN)echo "#define LSBFIRST" > $@
-	$(AM_V_GEN)echo '#include "$(srcdir)/${@:l-%=%}"' >> $@
-${LSB_3_FIRST}:
-	$(AM_V_GEN)echo "#define LSBFIRST" > $@
-	$(AM_V_GEN)echo "#define TRIPLE_BITS" >> $@
-	$(AM_V_GEN)echo '#include "$(srcdir)/${@:l3-%=%}"' >> $@
-${LSB_FIXED}:
-	$(AM_V_GEN)echo "#define LSBFIRST" > $@
-	$(AM_V_GEN)echo "#define FIXEDBASE" >> $@
-	$(AM_V_GEN)echo '#include "$(srcdir)/${@:lf-%=%}"' >> $@
-${LSB_3_FIXED}:
-	$(AM_V_GEN)echo "#define LSBFIRST" > $@
-	$(AM_V_GEN)echo "#define TRIPLE_BITS" >> $@
-	$(AM_V_GEN)echo "#define FIXEDBASE" >> $@
-	$(AM_V_GEN)echo '#include "$(srcdir)/${@:lf3-%=%}"' >> $@
-${MSB_FIRST}:
-	$(AM_V_GEN)echo "#define MSBFIRST" > $@
-	$(AM_V_GEN)echo '#include "$(srcdir)/${@:m-%=%}"' >> $@
-${MSB_3_FIRST}:
-	$(AM_V_GEN)echo "#define MSBFIRST" > $@
-	$(AM_V_GEN)echo "#define TRIPLE_BITS" >> $@
-	$(AM_V_GEN)echo '#include "$(srcdir)/${@:m3-%=%}"' >> $@
-${MSB_FIXED}:
-	$(AM_V_GEN)echo "#define MSBFIRST" > $@
-	$(AM_V_GEN)echo "#define FIXEDBASE" >> $@
-	$(AM_V_GEN)echo '#include "$(srcdir)/${@:mf-%=%}"' >> $@
-${MSB_3_FIXED}:
-	$(AM_V_GEN)echo "#define MSBFIRST" > $@
-	$(AM_V_GEN)echo "#define TRIPLE_BITS" >> $@
-	$(AM_V_GEN)echo "#define FIXEDBASE" >> $@
-	$(AM_V_GEN)echo '#include "$(srcdir)/${@:mf3-%=%}"' >> $@
-
-endif # XAA
-
-DISTCLEANFILES = $(POLYSEG) \
-	$(LSB_FIRST) $(LSB_FIXED) $(MSB_FIRST) $(MSB_FIXED) \
-	$(LSB_3_FIRST) $(LSB_3_FIXED) $(MSB_3_FIRST) $(MSB_3_FIXED)
-
-sdk_HEADERS = xaa.h xaalocal.h xaarop.h
-EXTRA_DIST = xaacexp.h xaawrap.h xaaLine.c xaaDashLine.c \
-             xaaStipple.c xaaTEGlyph.c xaaNonTEGlyph.c xaaBitmap.c \
-             XAA.HOWTO
-
-INCLUDES = $(XORG_INCS) -I$(srcdir)/../../../miext/cw
-
-AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
diff --git a/hw/xfree86/xaa/XAA.HOWTO b/hw/xfree86/xaa/XAA.HOWTO
deleted file mode 100644
index cbd71c1..0000000
--- a/hw/xfree86/xaa/XAA.HOWTO
+++ /dev/null
@@ -1,1427 +0,0 @@
-
-
-                          XAA.HOWTO
-
-  This file describes how to add basic XAA support to a chipset driver.
-
-0)  What is XAA
-1)  XAA Initialization and Shutdown
-2)  The Primitives
-  2.0  Generic Flags
-  2.1  Screen to Screen Copies
-  2.2  Solid Fills
-  2.3  Solid Lines
-  2.4  Dashed Lines
-  2.5  Color Expand Fills
-    2.5.1 Screen to Screen Color Expansion
-    2.5.2 CPU to Screen Color Expansion
-      2.5.2.1 The Direct Method
-      2.5.2.2 The Indirect Method
-  2.6  8x8 Mono Pattern Fills
-  2.7  8x8 Color Pattern Fills
-  2.8  Image Writes
-    2.8.1 The Direct Method
-    2.8.2 The Indirect Method
-  2.9 Clipping
-3)  The Pixmap Cache
-4)  Offscreen Pixmaps
-
-/********************************************************************/
-
-0) WHAT IS XAA
-	
-   XAA (the XFree86 Acceleration Architecture) is a device dependent
-layer that encapsulates the unaccelerated framebuffer rendering layer,
-intercepting rendering commands sent to it from higher levels of the
-server.  For rendering tasks where hardware acceleration is not 
-possible, XAA allows the requests to proceed to the software rendering
-code.  Otherwise, XAA breaks the sometimes complicated X primitives
-into simpler primitives more suitable for hardware acceleration and
-will use accelerated functions exported by the chipset driver to 
-render these.
-
-   XAA provides a simple, easy to use driver interface that allows
-the driver to communicate its acceleration capabilities and restrictions
-back to XAA.  XAA will use the information provided by the driver
-to determine whether or not acceleration will be possible for a
-particular X primitive.
-
-
-
-1) XAA INITIALIZATION AND SHUTDOWN
-
-   All relevant prototypes and defines are in xaa.h.
-
-   To Initialize the XAA layer, the driver should allocate an XAAInfoRec
-via XAACreateInfoRec(), fill it out as described in this document
-and pass it to XAAInit().  XAAInit() must be called _after_ the 
-framebuffer initialization (usually cfb?ScreenInit or similar) since 
-it is "wrapping" that layer.  XAAInit() should be called _before_ the 
-cursor initialization (usually miDCInitialize) since the cursor
-layer needs to "wrap" all the rendering code including XAA.
-
-   When shutting down, the driver should free the XAAInfoRec
-structure in its CloseScreen function via XAADestroyInfoRec().
-The prototypes for the functions mentioned above are as follows:
-
-   XAAInfoRecPtr XAACreateInfoRec(void);
-   Bool XAAInit(ScreenPtr, XAAInfoRecPtr);
-   void XAADestroyInfoRec(XAAInfoRec);
-
-   The driver informs XAA of it's acceleration capablities by
-filling out an XAAInfoRec structure and passing it to XAAInit().
-The XAAInfoRec structure contains many fields, most of which are
-function pointers and flags.  Each primitive will typically have
-two functions and a set of flags associated with it, but it may
-have more.  These two functions are the "SetupFor" and "Subsequent" 
-functions.  The "SetupFor" function tells the driver that the 
-hardware should be initialized for a particular type of graphics 
-operation.  After the "SetupFor" function, one or more calls to the 
-"Subsequent" function will be made to indicate that an instance
-of the particular primitive should be rendered by the hardware.
-The details of each instance (width, height, etc...) are given
-with each "Subsequent" function.   The set of flags associated
-with each primitive lets the driver tell XAA what its hardware
-limitations are (eg. It doesn't support a planemask, it can only
-do one of the raster-ops, etc...).
-
-  Of the XAAInfoRec fields, one is required.  This is the
-Sync function.  XAA initialization will fail if this function
-is not provided.
-
-void Sync(ScrnInfoPtr pScrn)			/* Required */
-
-   Sync will be called when XAA needs to be certain that all
-   graphics coprocessor operations are finished, such as when
-   the framebuffer must be written to or read from directly
-   and it must be certain that the accelerator will not be
-   overwriting the area of interest.
-
-   One needs to make certain that the Sync function not only
-   waits for the accelerator fifo to empty, but that it waits for
-   the rendering of that last operation to complete.
-
-   It is guaranteed that no direct framebuffer access will
-   occur after a "SetupFor" or "Subsequent" function without
-   the Sync function being called first.
-
-
-
-2)  THE PRIMITIVES
-
-2.0  Generic Flags
-
-  Each primitive type has a set of flags associated with it which
-allow the driver to tell XAA what the hardware limitations are.
-The common ones are as follows:
-
-/* Foreground, Background, rop and planemask restrictions */
-
-   GXCOPY_ONLY
-
-     This indicates that the accelerator only supports GXcopy
-     for the particular primitive.
-
-   ROP_NEEDS_SOURCE
-
-     This indicates that the accelerator doesn't supports a
-     particular primitive with rops that don't involve the source.
-     These rops are GXclear, GXnoop, GXinvert and GXset. If neither
-     this flag nor GXCOPY_ONLY is defined, it is assumed that the
-     accelerator supports all 16 raster operations (rops) for that
-     primitive.
-
-   NO_PLANEMASK
-
-     This indicates that the accelerator does not support a hardware
-     write planemask for the particular primitive.
-
-   RGB_EQUAL
-
-     This indicates that the particular primitive requires the red, 
-     green and blue bytes of the foreground color (and background color,
-     if applicable) to be equal. This is useful for 24bpp when a graphics
-     coprocessor is used in 8bpp mode, which is not uncommon in older
-     hardware since some have no support for or only limited support for 
-     acceleration at 24bpp. This way, many operations will be accelerated 
-     for the common case of "grayscale" colors.  This flag should only
-     be used in 24bpp.
-
-  In addition to the common ones listed above which are possible for
-nearly all primitives, each primitive may have its own flags specific
-to that primitive.  If such flags exist they are documented in the
-descriptions of those primitives below.
- 
-
-
-
-2.1  Screen to Screen Copies
-
-   The SetupFor and Subsequent ScreenToScreenCopy functions provide
-   an interface for copying rectangular areas from video memory to
-   video memory.  To accelerate this primitive the driver should
-   provide both the SetupFor and Subsequent functions and indicate
-   the hardware restrictions via the ScreenToScreenCopyFlags.  The
-   NO_PLANEMASK, GXCOPY_ONLY and ROP_NEEDS_SOURCE flags as described
-   in Section 2.0 are valid as well as the following:
-
-    NO_TRANSPARENCY
-     
-      This indicates that the accelerator does not support skipping
-      of color keyed pixels when copying from the source to the destination.
-
-    TRANSPARENCY_GXCOPY_ONLY
-
-      This indicates that the accelerator supports skipping of color keyed
-      pixels only when the rop is GXcopy.
-
-    ONLY_LEFT_TO_RIGHT_BITBLT
-
-      This indicates that the hardware only accepts blitting when the
-      x direction is positive.
-
-    ONLY_TWO_BITBLT_DIRECTIONS
-
-      This indicates that the hardware can only cope with blitting when
-      the direction of x is the same as the direction in y.
-
-
-void SetupForScreenToScreenCopy( ScrnInfoPtr pScrn,
-			int xdir, int ydir,
-			int rop,
-			unsigned int planemask,
-			int trans_color )
-
-    When this is called, SubsequentScreenToScreenCopy will be called
-    one or more times directly after.  If ydir is 1, then the accelerator
-    should copy starting from the top (minimum y) of the source and
-    proceed downward.  If ydir is -1, then the accelerator should copy
-    starting from the bottom of the source (maximum y) and proceed
-    upward.  If xdir is 1, then the accelerator should copy each
-    y scanline starting from the leftmost pixel of the source.  If
-    xdir is -1, it should start from the rightmost pixel.  
-       If trans_color is not -1 then trans_color indicates that the
-    accelerator should not copy pixels with the color trans_color
-    from the source to the destination, but should skip them. 
-    Trans_color is always -1 if the NO_TRANSPARENCY flag is set.
- 
-
-void SubsequentScreenToScreenCopy(ScrnInfoPtr pScrn,
-			int x1, int y1,
-			int x2, int y2,
-			int width, int height)
-
-    Copy a rectangle "width" x "height" from the source (x1,y1) to the 
-    destination (x2,y2) using the parameters passed by the last
-    SetupForScreenToScreenCopy call. (x1,y1) and (x2,y2) always denote 
-    the upper left hand corners of the source and destination regardless 
-    of which xdir and ydir values are given by SetupForScreenToScreenCopy.  
-
-
-
-2.2 Solid Fills
-
-   The SetupFor and Subsequent SolidFill(Rect/Trap) functions provide
-   an interface for filling rectangular areas of the screen with a
-   foreground color.  To accelerate this primitive the driver should
-   provide both the SetupForSolidFill and SubsequentSolidFillRect 
-   functions and indicate the hardware restrictions via the SolidFillFlags.
-   The driver may optionally provide a SubsequentSolidFillTrap if
-   it is capable of rendering the primitive correctly.  
-   The GXCOPY_ONLY, ROP_NEEDS_SOURCE, NO_PLANEMASK and RGB_EQUAL flags
-   as described in Section 2.0 are valid.
-
-  
-void SetupForSolidFill(ScrnInfoPtr pScrn, 
-                       int color, int rop, unsigned int planemask)
-
-    SetupForSolidFill indicates that any combination of the following 
-    may follow it.
-
-	SubsequentSolidFillRect
-	SubsequentSolidFillTrap
-
-
- 
-void SubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h)
-
-     Fill a rectangle of dimensions "w" by "h" with origin at (x,y) 
-     using the color, rop and planemask given by the last 
-     SetupForSolidFill call.
-
-void SubsequentSolidFillTrap(ScrnInfoPtr pScrn, int y, int h, 
-	int left, int dxL, int dyL, int eL,
-	int right, int dxR, int dyR, int eR)
-
-     These parameters describe a trapezoid via a version of
-     Bresenham's parameters. "y" is the top line. "h" is the
-     number of spans to be filled in the positive Y direction.
-     "left" and "right" indicate the starting X values of the
-     left and right edges.  dy/dx describes the edge slope.
-     These are not the deltas between the beginning and ending
-     points on an edge.  They merely describe the slope. "e" is
-     the initial error term.  It's the relationships between dx,
-     dy and e that define the edge.
-	If your engine does not do bresenham trapezoids or does
-     not allow the programmer to specify the error term then
-     you are not expected to be able to accelerate them.
-
-
-2.3  Solid Lines
-
-    XAA provides an interface for drawing thin lines.  In order to
-    draw X lines correctly a high degree of accuracy is required.
-    This usually limits line acceleration to hardware which has a
-    Bresenham line engine, though depending on the algorithm used,
-    other line engines may come close if they accept 16 bit line 
-    deltas.  XAA has both a Bresenham line interface and a two-point
-    line interface for drawing lines of arbitrary orientation.  
-    Additionally there is a SubsequentSolidHorVertLine which will
-    be used for all horizontal and vertical lines.  Horizontal and
-    vertical lines are handled separately since hardware that doesn't
-    have a line engine (or has one that is unusable due to precision
-    problems) can usually draw these lines by some other method such
-    as drawing them as thin rectangles.  Even for hardware that can
-    draw arbitrary lines via the Bresenham or two-point interfaces,
-    the SubsequentSolidHorVertLine is used for horizontal and vertical
-    lines since most hardware is able to render the horizontal lines
-    and sometimes the vertical lines faster by other methods (Hint:
-    try rendering horizontal lines as flattened rectangles).  If you have 
-    not provided a SubsequentSolidHorVertLine but you have provided 
-    Bresenham or two-point lines, a SubsequentSolidHorVertLine function 
-    will be supplied for you.
-
-    The flags field associated with Solid Lines is SolidLineFlags and 
-    the GXCOPY_ONLY, ROP_NEEDS_SOURCE, NO_PLANEMASK and RGB_EQUAL flags as
-    described in Section 2.0 are valid restrictions.  
-
-    Some line engines have line biases hardcoded to comply with
-    Microsoft line biasing rules.  A tell-tale sign of this is the
-    hardware lines not matching the software lines in the zeroth and
-    fourth octants.  The driver can set the flag:
-	
-	MICROSOFT_ZERO_LINE_BIAS
-
-    in the AccelInfoRec.Flags field to adjust the software lines to
-    match the hardware lines.   This is in the generic flags field
-    rather than the SolidLineFlags since this flag applies to all
-    software zero-width lines on the screen and not just the solid ones.
-
-
-void SetupForSolidLine(ScrnInfoPtr pScrn, 
-                       int color, int rop, unsigned int planemask)
-
-    SetupForSolidLine indicates that any combination of the following 
-    may follow it.
-
-	SubsequentSolidBresenhamLine
-	SubsequentSolidTwoPointLine
-        SubsequentSolidHorVertLine 	
-
-
-void SubsequentSolidHorVertLine( ScrnInfoPtr pScrn,
-        			int x, int y, int len, int dir )
-
-    All vertical and horizontal solid thin lines are rendered with
-    this function.  The line starts at coordinate (x,y) and extends
-    "len" pixels inclusive.  In the direction indicated by "dir."
-    The direction is either DEGREES_O or DEGREES_270.  That is, it
-    always extends to the right or down.
-
-
-
-void SubsequentSolidTwoPointLine(ScrnInfoPtr pScrn,
-        	int x1, int y1, int x2, int y2, int flags)
-
-    Draw a line from (x1,y1) to (x2,y2).  If the flags field contains
-    the flag OMIT_LAST, the last pixel should not be drawn.  Otherwise,
-    the pixel at (x2,y2) should be drawn.
-
-    If you use the TwoPoint line interface there is a good possibility
-    that your line engine has hard-coded line biases that do not match
-    the default X zero-width lines.  If so, you may need to set the
-    MICROSOFT_ZERO_LINE_BIAS flag described above.  Note that since
-    any vertex in the 16-bit signed coordinate system is valid, your
-    line engine is expected to handle 16-bit values if you have hardware
-    line clipping enabled.  If your engine cannot handle 16-bit values,
-    you should not use hardware line clipping.
-
-
-void SubsequentSolidBresenhamLine(ScrnInfoPtr pScrn,
-        int x, int y, int major, int minor, int err, int len, int octant)
-
-    "X" and "y" are the starting point of the line.  "Major" and "minor" 
-    are the major and minor step constants.  "Err" is the initial error
-    term.  "Len" is the number of pixels to be drawn (inclusive). "Octant"
-    can be any combination of the following flags OR'd together:
-
-      Y_MAJOR		Y is the major axis (X otherwise)
-      X_DECREASING	The line is drawn from right to left
-      Y_DECREASING	The line is drawn from bottom to top
-	  
-    The major, minor and err terms are the "raw" Bresenham parameters
-    consistent with a line engine that does:
-
-	e = err;
-	while(len--) {
-	   DRAW_POINT(x,y);
-	   e += minor;
-	   if(e >= 0) {
-		e -= major;
-		TAKE_ONE_STEP_ALONG_MINOR_AXIS;
-	   }
-	   TAKE_ONE_STEP_ALONG_MAJOR_AXIS;
-	}
-
-    IBM 8514 style Bresenham line interfaces require their parameters
-    modified in the following way:
-
-	Axial = minor;
-	Diagonal = minor - major;
-	Error = minor + err;
-
-SolidBresenhamLineErrorTermBits
-
-    This field allows the driver to tell XAA how many bits large its
-    Bresenham parameter registers are.  Many engines have registers that
-    only accept 12 or 13 bit Bresenham parameters, and the parameters
-    for clipped lines may overflow these if they are not scaled down.
-    If this field is not set, XAA will assume the engine can accomodate
-    16 bit parameters, otherwise, it will scale the parameters to the
-    size specified.
-
-
-2.4  Dashed Lines
-
-    The same degree of accuracy required by the solid lines is required
-    for drawing dashed lines as well.  The dash pattern itself is a
-    buffer of binary data where ones are expanded into the foreground
-    color and zeros either correspond to the background color or
-    indicate transparency depending on whether or not DoubleDash or
-    OnOffDashes are being drawn.  
-
-    The flags field associated with dashed Lines is DashedLineFlags and 
-    the GXCOPY_ONLY, ROP_NEEDS_SOURCE, NO_PLANEMASK and RGB_EQUAL flags as
-    described in Section 2.0 are valid restrictions.  Additionally, the
-    following flags are valid:
-
-      NO_TRANSPARENCY
-
-	This indicates that the driver cannot support dashed lines
-	with transparent backgrounds (OnOffDashes).
-
-      TRANSPARENCY_ONLY
-
-	This indicates that the driver cannot support dashes with
-	both a foreground and background color (DoubleDashes).
-
-      LINE_PATTERN_POWER_OF_2_ONLY
-
-	This indicates that only patterns with a power of 2 length
-	can be accelerated.
-
-      LINE_PATTERN_LSBFIRST_MSBJUSTIFIED
-      LINE_PATTERN_LSBFIRST_LSBJUSTIFIED
-      LINE_PATTERN_MSBFIRST_MSBJUSTIFIED
-      LINE_PATTERN_MSBFIRST_LSBJUSTIFIED
-
-	These describe how the line pattern should be packed.
-	The pattern buffer is DWORD padded.  LSBFIRST indicates
-	that the pattern runs from the LSB end to the MSB end.
-	MSBFIRST indicates that the pattern runs from the MSB end
-	to the LSB end.  When the pattern does not completely fill
-	the DWORD padded buffer, the pattern will be justified 
-	towards the MSB or LSB end based on the flags above.
-
-
-    The following field indicates the maximum length dash pattern that
-    should be accelerated.
-
-	int DashPatternMaxLength
-
-
-void SetupForDashedLine(ScrnInfoPtr pScrn,
-		int fg, int bg, int rop, unsigned int planemask,
-        	int length, unsigned char *pattern)
-
-    
-    SetupForDashedLine indicates that any combination of the following 
-    may follow it.
-
-	SubsequentDashedBresenhamLine
-	SubsequentDashedTwoPointLine
-
-    If "bg" is -1, then the background (pixels corresponding to clear
-    bits in the pattern) should remain unmodified. "Bg" indicates the
-    background color otherwise.  "Length" indicates the length of
-    the pattern in bits and "pattern" points to the DWORD padded buffer
-    holding the pattern which has been packed according to the flags
-    set above.  
-
-    
-void SubsequentDashedTwoPointLine( ScrnInfoPtr pScrn,
-        int x1, int y1, int x2, int y2, int flags, int phase)
-
-void SubsequentDashedBresenhamLine(ScrnInfoPtr pScrn,
-        int x1, int y1, int major, int minor, int err, int len, int octant,
-        int phase)
-  
-    These are the same as the SubsequentSolidTwoPointLine and
-    SubsequentBresenhamLine functions except for the addition
-    of the "phase" field which indicates the offset into the dash 
-    pattern that the pixel at (x1,y1) corresponds to.
-
-    As with the SubsequentBresenhamLine, there is an
- 
-	int DashedBresenhamLineErrorTermBits 
-   
-    field which indicates the size of the error term registers
-    used with dashed lines.  This is usually the same value as
-    the field for the solid lines (because it's usually the same
-    register).
-       
-      
-
-2.5   Color Expansion Fills
-
-    When filling a color expansion rectangle, the accelerator
-    paints each pixel depending on whether or not a bit in a
-    corresponding bitmap is set or clear. Opaque expansions are 
-    when a set bit corresponds to the foreground color and a clear 
-    bit corresponds to the background color.  A transparent expansion
-    is when a set bit corresponds to the foreground color and a
-    clear bit indicates that the pixel should remain unmodified.
-   
-    The graphics accelerator usually has access to the source 
-    bitmap in one of two ways: 1) the bitmap data is sent serially
-    to the accelerator by the CPU through some memory mapped aperture
-    or 2) the accelerator reads the source bitmap out of offscreen
-    video memory.  Some types of primitives are better suited towards 
-    one method or the other.  Type 2 is useful for reusable patterns
-    such as stipples which can be cached in offscreen memory.  The
-    aperature method can be used for stippling but the CPU must pass
-    the data across the bus each time a stippled fill is to be performed.  
-    For expanding 1bpp client pixmaps or text strings to the screen,
-    the aperature method is usually superior because the intermediate
-    copy in offscreen memory needed by the second method would only be 
-    used once.  Unfortunately, many accelerators can only do one of these
-    methods and not both.  
-
-    XAA provides both ScreenToScreen and CPUToScreen color expansion 
-    interfaces for doing color expansion fills.  The ScreenToScreen
-    functions can only be used with hardware that supports reading
-    of source bitmaps from offscreen video memory, and these are only
-    used for cacheable patterns such as stipples.  There are two
-    variants of the CPUToScreen routines - a direct method intended
-    for hardware that has a transfer aperature, and an indirect method
-    intended for hardware without transfer aperatures or hardware
-    with unusual transfer requirements.  Hardware that can only expand
-    bitmaps from video memory should supply ScreenToScreen routines
-    but also ScanlineCPUToScreen (indirect) routines to optimize transfers 
-    of non-cacheable data.  Hardware that can only accept source bitmaps
-    through an aperature should supply CPUToScreen (or ScanlineCPUToScreen) 
-    routines. Hardware that can do both should provide both ScreenToScreen 
-    and CPUToScreen routines.
-
-    For both ScreenToScreen and CPUToScreen interfaces, the GXCOPY_ONLY,
-    ROP_NEEDS_SOURCE, NO_PLANEMASK and RGB_EQUAL flags described in
-    Section 2.0 are valid as well as the following:
-
-    /* bit order requirements (one of these must be set) */
-   
-    BIT_ORDER_IN_BYTE_LSBFIRST
-
-      This indicates that least significant bit in each byte of the source
-      data corresponds to the leftmost of that block of 8 pixels.  This
-      is the prefered format.
-
-    BIT_ORDER_IN_BYTE_MSBFIRST    
-
-      This indicates that most significant bit in each byte of the source
-      data corresponds to the leftmost of that block of 8 pixels.
-
-    /* transparency restrictions */
-
-    NO_TRANSPARENCY
-
-      This indicates that the accelerator cannot do a transparent expansion.
-
-    TRANSPARENCY_ONLY
-
-      This indicates that the accelerator cannot do an opaque expansion.
-      In cases where where the background needs to be filled, XAA will
-      render the primitive in two passes when using the CPUToScreen
-      interface, but will not do so with the ScreenToScreen interface 
-      since that would require caching of two patterns.  Some 
-      ScreenToScreen hardware may be able to render two passes at the
-      driver level and remove the TRANSPARENCY_ONLY restriction if
-      it can render pixels corresponding to the zero bits.
-
-
-
-2.5.1  Screen To Screen Color Expansion
-
-    The ScreenToScreenColorExpandFill routines provide an interface
-    for doing expansion blits from source patterns stored in offscreen
-    video memory.
-
-    void SetupForScreenToScreenColorExpandFill (ScrnInfoPtr pScrn,
-        			int fg, int bg, 
-				int rop, unsigned int planemask)
-
-
-    Ones in the source bitmap will correspond to the fg color.
-    Zeros in the source bitmap will correspond to the bg color
-    unless bg = -1.  In that case the pixels corresponding to the
-    zeros in the bitmap shall be left unmodified by the accelerator.
-
-    For hardware that doesn't allow an easy implementation of skipleft, the
-    driver can replace CacheMonoStipple function with one that stores multiple
-    rotated copies of the stipple and select between them. In this case the
-    driver should set CacheColorExpandDensity to tell XAA how many copies of
-    the pattern are stored in the width of a cache slot. For instance if the
-    hardware can specify the starting address in bytes, then 8 rotated copies
-    of the stipple are needed and CacheColorExpandDensity should be set to 8.
-
-    void SubsequentScreenToScreenColorExpandFill( ScrnInfoPtr pScrn,
-				int x, int y, int w, int h,
-				int srcx, int srcy, int offset )
-
-   
-    Fill a rectangle "w" x "h" at location (x,y).  The source pitch
-    between scanlines is the framebuffer pitch (pScrn->displayWidth
-    pixels) and srcx and srcy indicate the start of the source pattern 
-    in units of framebuffer pixels. "Offset" indicates the bit offset
-    into the pattern that corresponds to the pixel being painted at
-    "x" on the screen.  Some hardware accepts source coordinates in
-    units of bits which makes implementation of the offset trivial.
-    In that case, the bit address of the source bit corresponding to
-    the pixel painted at (x,y) would be:
-	
-     (srcy * pScrn->displayWidth + srcx) * pScrn->bitsPerPixel + offset
-
-    It should be noted that the offset assumes LSBFIRST hardware.  
-    For MSBFIRST hardware, the driver may need to implement the 
-    offset by bliting only from byte boundaries and hardware clipping.
-
-
-
-2.5.2  CPU To Screen Color Expansion
-
-
-    The CPUToScreenColorExpandFill routines provide an interface for 
-    doing expansion blits from source patterns stored in system memory.
-    There are two varieties of this primitive, a CPUToScreenColorExpandFill
-    and a ScanlineCPUToScreenColorExpandFill.  With the 
-    CPUToScreenColorExpandFill method, the source data is sent serially
-    through a memory mapped aperature.  With the Scanline version, the
-    data is rendered scanline at a time into intermediate buffers with
-    a call to SubsequentColorExpandScanline following each scanline.
-
-    These two methods have separate flags fields, the
-    CPUToScreenColorExpandFillFlags and ScanlineCPUToScreenColorExpandFillFlags
-    respectively.  Flags specific to one method or the other are described 
-    in sections 2.5.2.1 and 2.5.2.2 but for both cases the bit order and
-    transparency restrictions listed at the beginning of section 2.5 are 
-    valid as well as the following:
-    
-    /* clipping  (optional) */
-    
-    LEFT_EDGE_CLIPPING
- 
-      This indicates that the accelerator supports omission of up to
-      31 pixels on the left edge of the rectangle to be filled.  This
-      is beneficial since it allows transfer of the source bitmap to
-      always occur from DWORD boundaries. 
-
-    LEFT_EDGE_CLIPPING_NEGATIVE_X
-
-      This flag indicates that the accelerator can render color expansion
-      rectangles even if the value of x origin is negative (off of
-      the screen on the left edge).
-
-    /* misc */
-
-    TRIPLE_BITS_24BPP
-
-      When enabled (must be in 24bpp mode), color expansion functions
-      are expected to require three times the amount of bits to be
-      transferred so that 24bpp grayscale colors can be used with color
-      expansion in 8bpp coprocessor mode. Each bit is expanded to 3
-      bits when writing the monochrome data.
-
-
- 2.5.1 The Direct Method 
-
-
-    Using the direct method of color expansion XAA will send all
-    bitmap data to the accelerator serially through an memory mapped
-    transfer window defined by the following two fields:
-
-      unsigned char *ColorExpandBase
-
-        This indicates the memory address of the beginning of the aperture.
-
-      int ColorExpandRange
-
-        This indicates the size in bytes of the aperture.
-
-    The driver should specify how the transfered data should be padded.
-    There are options for both the padding of each Y scanline and for the
-    total transfer to the aperature.
-    One of the following two flags must be set:
-
-      CPU_TRANSFER_PAD_DWORD
-
-        This indicates that the total transfer (sum of all scanlines) sent
-        to the aperature must be DWORD padded.  This is the default behavior.
-
-      CPU_TRANSFER_PAD_QWORD 
-
-	This indicates that the total transfer (sum of all scanlines) sent
-	to the aperature must be QWORD padded.  With this set, XAA will send
-        an extra DWORD to the aperature when needed to ensure that only
-        an even number of DWORDs are sent.
-
-    And then there are the flags for padding of each scanline:
-
-      SCANLINE_PAD_DWORD
-
-	This indicates that each Y scanline should be DWORD padded.
-        This is the only option available and is the default.
-
-    Finally, there is the CPU_TRANSFER_BASE_FIXED flag which indicates
-    that the aperture is a single register rather than a range of
-    registers, and XAA should write all of the data to the first DWORD.
-    If the ColorExpandRange is not large enough to accomodate scanlines
-    the width of the screen, this option will be forced. That is, the
-    ColorExpandRange must be:
-
-        ((virtualX + 31)/32) * 4   bytes or more.
-
-        ((virtualX + 62)/32 * 4) if LEFT_EDGE_CLIPPING_NEGATIVE_X is set.
-  
-    If the TRIPLE_BITS_24BPP flag is set, the required area should be 
-    multiplied by three.
-     
-    
-void SetupForCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
-        		int fg, int bg,
-			int rop,
-			unsigned int planemask)
-
-  
- 
-     Ones in the source bitmap will correspond to the fg color.
-     Zeros in the source bitmap will correspond to the bg color
-     unless bg = -1.  In that case the pixels corresponding to the
-     zeros in the bitmap shall be left unmodified by the accelerator.
-
-
-void SubsequentCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
-			int x, int y, int w, int h,
-			int skipleft )
-
-     When this function is called, the accelerator should be setup
-     to fill a rectangle of dimension "w" by "h" with origin at (x,y)
-     in the fill style prescribed by the last call to 
-     SetupForCPUToScreenColorExpandFill.  XAA will pass the data to 
-     the aperture immediately after this function is called.  If the 
-     skipleft is non-zero (and LEFT_EDGE_CLIPPING has been enabled), then 
-     the accelerator _should_not_ render skipleft pixels on the leftmost
-     edge of the rectangle.  Some engines have an alignment feature
-     like this built in, some others can do this using a clipping
-     window.
-
-     It can be arranged for XAA to call Sync() after it is through 
-     calling the Subsequent function by setting SYNC_AFTER_COLOR_EXPAND 
-     in the  CPUToScreenColorExpandFillFlags.  This can provide the driver 
-     with an oportunity to reset a clipping window if needed.
-
-    
-2.5.2  The Indirect Method 
-
-     Using the indirect method, XAA will render the bitmap data scanline
-     at a time to one or more buffers.  These buffers may be memory
-     mapped apertures or just intermediate storage.
-
-     int NumScanlineColorExpandBuffers
-
-       This indicates the number of buffers available.
-
-     unsigned char **ScanlineColorExpandBuffers
-
-       This is an array of pointers to the memory locations of each buffer.
-       Each buffer is expected to be large enough to accommodate scanlines
-       the width of the screen.  That is:
-
-        ((virtualX + 31)/32) * 4   bytes or more.
-
-        ((virtualX + 62)/32 * 4) if LEFT_EDGE_CLIPPING_NEGATIVE_X is set.
-  
-     Scanlines are always DWORD padded.
-     If the TRIPLE_BITS_24BPP flag is set, the required area should be 
-     multiplied by three.
-
-
-void SetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
-        		int fg, int bg,
-			int rop,
-			unsigned int planemask)
- 
-     Ones in the source bitmap will correspond to the fg color.
-     Zeros in the source bitmap will correspond to the bg color
-     unless bg = -1.  In that case the pixels corresponding to the
-     zeros in the bitmap shall be left unmodified by the accelerator.
-
-     
-void SubsequentScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
-			int x, int y, int w, int h,
-			int skipleft )
-
-void SubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno)
-
-
-    When SubsequentScanlineCPUToScreenColorExpandFill is called, XAA 
-    will begin transfering the source data scanline at a time, calling  
-    SubsequentColorExpandScanline after each scanline.  If more than
-    one buffer is available, XAA will cycle through the buffers.
-    Subsequent scanlines will use the next buffer and go back to the
-    buffer 0 again when the last buffer is reached.  The index into
-    the ScanlineColorExpandBuffers array is presented as "bufno"
-    with each SubsequentColorExpandScanline call.
-
-    The skipleft field is the same as for the direct method.
-
-    The indirect method can be use to send the source data directly 
-    to a memory mapped aperture represented by a single color expand
-    buffer, scanline at a time, but more commonly it is used to place 
-    the data into offscreen video memory so that the accelerator can 
-    blit it to the visible screen from there.  In the case where the
-    accelerator permits rendering into offscreen video memory while
-    the accelerator is active, several buffers can be used so that
-    XAA can be placing source data into the next buffer while the
-    accelerator is blitting the current buffer.  For cases where
-    the accelerator requires some special manipulation of the source
-    data first, the buffers can be in system memory.  The CPU can
-    manipulate these buffers and then send the data to the accelerator.
-
-
-
-2.6   8x8 Mono Pattern Fills
-
-    XAA provides support for two types of 8x8 hardware patterns -
-    "Mono" patterns and "Color" patterns.  Mono pattern data is
-    64 bits of color expansion data with ones indicating the
-    foreground color and zeros indicating the background color.
-    The source bitmaps for the 8x8 mono patterns can be presented
-    to the graphics accelerator in one of two ways.  They can be
-    passed as two DWORDS to the 8x8 mono pattern functions or
-    they can be cached in offscreen memory and their locations
-    passed to the 8x8 mono pattern functions.  In addition to the
-    GXCOPY_ONLY, ROP_NEEDS_SOURCE, NO_PLANEMASK and RGB_EQUAL flags
-    defined in Section 2.0, the following are defined for the
-    Mono8x8PatternFillFlags:
-
-    HARDWARE_PATTERN_PROGRAMMED_BITS
-
-      This indicates that the 8x8 patterns should be packed into two
-      DWORDS and passed to the 8x8 mono pattern functions.  The default
-      behavior is to cache the patterns in offscreen video memory and
-      pass the locations of these patterns to the functions instead.
-      The pixmap cache must be enabled for the default behavior (8x8 
-      pattern caching) to work.  See Section 3 for how to enable the
-      pixmap cache. The pixmap cache is not necessary for 
-      HARDWARE_PATTERN_PROGRAMMED_BITS.
-
-    HARDWARE_PATTERN_PROGRAMMED_ORIGIN
-
-      If the hardware supports programmable pattern offsets then
-      this option should be set. See the table below for further
-      infomation.
-
-    HARDWARE_PATTERN_SCREEN_ORIGIN
-
-      Some hardware wants the pattern offset specified with respect to the
-      upper left-hand corner of the primitive being drawn.  Other hardware 
-      needs the option HARDWARE_PATTERN_SCREEN_ORIGIN set to indicate that 
-      all pattern offsets should be referenced to the upper left-hand 
-      corner of the screen.  HARDWARE_PATTERN_SCREEN_ORIGIN is preferable 
-      since this is more natural for the X-Window system and offsets will 
-      have to be recalculated for each Subsequent function otherwise.
-
-    BIT_ORDER_IN_BYTE_MSBFIRST
-    BIT_ORDER_IN_BYTE_LSBFIRST
-
-      As with other color expansion routines this indicates whether the
-      most or the least significant bit in each byte from the pattern is 
-      the leftmost on the screen.
-
-    TRANSPARENCY_ONLY
-    NO_TRANSPARENCY
-
-      This means the same thing as for the color expansion rect routines
-      except that for TRANSPARENCY_ONLY XAA will not render the primitive
-      in two passes since this is more easily handled by the driver.
-      It is recommended that TRANSPARENCY_ONLY hardware handle rendering
-      of opaque patterns in two passes (the background can be filled as
-      a rectangle in GXcopy) in the Subsequent function so that the
-      TRANSPARENCY_ONLY restriction can be removed. 
-
-
-
-    Additional information about cached patterns...
-    For the case where HARDWARE_PATTERN_PROGRAMMED_BITS is not set and 
-    the pattern must be cached in offscreen memory, the first pattern
-    starts at the cache slot boundary which is set by the 
-    CachePixelGranularity field used to configure the pixmap cache.
-    One should ensure that the CachePixelGranularity reflects any 
-    alignment restrictions that the accelerator may put on 8x8 pattern 
-    storage locations.  When HARDWARE_PATTERN_PROGRAMMED_ORIGIN is set 
-    there is only one pattern stored.  When this flag is not set,
-    all 64 pre-rotated copies of the pattern are cached in offscreen memory.
-    The MonoPatternPitch field can be used to specify the X position pixel
-    granularity that each of these patterns must align on.  If the
-    MonoPatternPitch is not supplied, the patterns will be densely packed
-    within the cache slot.  The behavior of the default XAA 8x8 pattern
-    caching mechanism to store all 8x8 patterns linearly in video memory.
-    If the accelerator needs the patterns stored in a more unusual fashion,
-    the driver will need to provide its own 8x8 mono pattern caching 
-    routines for XAA to use. 
-
-    The following table describes the meanings of the "patx" and "paty"
-    fields in both the SetupFor and Subsequent functions.
-
-    With HARDWARE_PATTERN_SCREEN_ORIGIN
-    -----------------------------------
-
-    HARDWARE_PATTERN_PROGRAMMED_BITS and HARDWARE_PATTERN_PROGRAMMED_ORIGIN
-
-	SetupFor: patx and paty are the first and second DWORDS of the
-		  8x8 mono pattern.
-
-	Subsequent: patx and paty are the x,y offset into that pattern.
-		    All Subsequent calls will have the same offset in 
-		    the case of HARDWARE_PATTERN_SCREEN_ORIGIN so only
-		    the offset specified by the first Subsequent call 
-		    after a SetupFor call will need to be observed.
-
-    HARDWARE_PATTERN_PROGRAMMED_BITS only
-
-	SetupFor: patx and paty hold the first and second DWORDS of
-		  the 8x8 mono pattern pre-rotated to match the desired
-		  offset.
-
-	Subsequent: These just hold the same patterns and can be ignored.
-
-    HARDWARE_PATTERN_PROGRAMMED_ORIGIN only
-
-	SetupFor: patx and paty hold the x,y coordinates of the offscreen
-		  memory location where the 8x8 pattern is stored.  The
-		  bits are stored linearly in memory at that location.
-
-	Subsequent: patx and paty hold the offset into the pattern.
-		    All Subsequent calls will have the same offset in 
-		    the case of HARDWARE_PATTERN_SCREEN_ORIGIN so only
-		    the offset specified by the first Subsequent call 
-		    after a SetupFor call will need to be observed.
-
-    Neither programmed bits or origin
-
-	SetupFor: patx and paty hold the x,y coordinates of the offscreen 	
-		  memory location where the pre-rotated 8x8 pattern is
-		  stored.
-
-	Subsequent: patx and paty are the same as in the SetupFor function
-		    and can be ignored.
-		  
-
-    Without HARDWARE_PATTERN_SCREEN_ORIGIN
-    -------------------------------------- 
-
-    HARDWARE_PATTERN_PROGRAMMED_BITS and HARDWARE_PATTERN_PROGRAMMED_ORIGIN
-
-	SetupFor: patx and paty are the first and second DWORDS of the
-		  8x8 mono pattern.
-
-	Subsequent: patx and paty are the x,y offset into that pattern.
-
-    HARDWARE_PATTERN_PROGRAMMED_BITS only
-
-	SetupFor: patx and paty holds the first and second DWORDS of
-		  the unrotated 8x8 mono pattern.  This can be ignored. 
-
-	Subsequent: patx and paty hold the rotated 8x8 pattern to be 
-		    rendered.
-
-    HARDWARE_PATTERN_PROGRAMMED_ORIGIN only
-
-	SetupFor: patx and paty hold the x,y coordinates of the offscreen
-		  memory location where the 8x8 pattern is stored.  The
-		  bits are stored linearly in memory at that location.
-
-	Subsequent: patx and paty hold the offset into the pattern.
-
-    Neither programmed bits or origin
-
-	SetupFor: patx and paty hold the x,y coordinates of the offscreen 	
-		  memory location where the unrotated 8x8 pattern is
-		  stored.  This can be ignored.
-
-	Subsequent: patx and paty hold the x,y coordinates of the
-		    rotated 8x8 pattern to be rendered.
-
-
-
-void SetupForMono8x8PatternFill(ScrnInfoPtr pScrn, int patx, int paty,
-        int fg, int bg, int rop, unsigned int planemask)
-
-    SetupForMono8x8PatternFill indicates that any combination of the 
-    following  may follow it.
-
-	SubsequentMono8x8PatternFillRect
-	SubsequentMono8x8PatternFillTrap
-
-    The fg, bg, rop and planemask fields have the same meaning as the
-    ones used for the other color expansion routines.  Patx's and paty's
-    meaning can be determined from the table above.
-
- 
-void SubsequentMono8x8PatternFillRect( ScrnInfoPtr pScrn,
-        	int patx, int paty, int x, int y, int w, int h)
-
-     Fill a rectangle of dimensions "w" by "h" with origin at (x,y) 
-     using the parameters give by the last SetupForMono8x8PatternFill
-     call.  The meanings of patx and paty can be determined by the
-     table above.
-
-void SubsequentMono8x8PatternFillTrap( ScrnInfoPtr pScrn,
-     			   int patx, int paty, int y, int h, 
-     			   int left, int dxL, int dyL, int eL,
-     			   int right, int dxR, int dyR, int eR )
-
-     The meanings of patx and paty can be determined by the table above.
-     The rest of the fields have the same meanings as those in the 
-     SubsequentSolidFillTrap function. 
-
-
-
-2.7   8x8 Color Pattern Fills
-  
-    8x8 color pattern data is 64 pixels of full color data that
-    is stored linearly in offscreen video memory.  8x8 color patterns 
-    are useful as a substitute for 8x8 mono patterns when tiling,
-    doing opaque stipples, or in the case where transperency is
-    supported, regular stipples.  8x8 color pattern fills also have
-    the additional benefit of being able to tile full color 8x8
-    patterns instead of just 2 color ones like the mono patterns.
-    However, full color 8x8 patterns aren't used very often in the
-    X Window system so you might consider passing this primitive
-    by if you already can do mono patterns, especially if they 
-    require alot of cache area.  Color8x8PatternFillFlags is
-    the flags field for this primitive and the GXCOPY_ONLY,
-    ROP_NEEDS_SOURCE and NO_PLANEMASK flags as described in
-    Section 2.0 are valid as well as the following:
-
-
-    HARDWARE_PATTERN_PROGRAMMED_ORIGIN
-
-      If the hardware supports programmable pattern offsets then
-      this option should be set.  
-
-    HARDWARE_PATTERN_SCREEN_ORIGIN
-
-      Some hardware wants the pattern offset specified with respect to the
-      upper left-hand corner of the primitive being drawn.  Other hardware 
-      needs the option HARDWARE_PATTERN_SCREEN_ORIGIN set to indicate that 
-      all pattern offsets should be referenced to the upper left-hand 
-      corner of the screen.  HARDWARE_PATTERN_SCREEN_ORIGIN is preferable 
-      since this is more natural for the X-Window system and offsets will 
-      have to be recalculated for each Subsequent function otherwise.
-
-    NO_TRANSPARENCY
-    TRANSPARENCY_GXCOPY_ONLY
-
-      These mean the same as for the ScreenToScreenCopy functions.
-
-
-    The following table describes the meanings of patx and paty passed
-    to the SetupFor and Subsequent fields:
-
-    HARDWARE_PATTERN_PROGRAMMED_ORIGIN && HARDWARE_PATTERN_SCREEN_ORIGIN
-	
-	SetupFor: patx and paty hold the x,y location of the unrotated 
-		  pattern.
-
-	Subsequent: patx and paty hold the pattern offset.  For the case
-		    of HARDWARE_PATTERN_SCREEN_ORIGIN all Subsequent calls
-		    have the same offset so only the first call will need
-		    to be observed.
-
-    
-    HARDWARE_PATTERN_PROGRAMMED_ORIGIN only
-
-	SetupFor: patx and paty hold the x,y location of the unrotated
-		  pattern.
-
-	Subsequent: patx and paty hold the pattern offset. 
-
-    HARDWARE_PATTERN_SCREEN_ORIGIN
-
-	SetupFor: patx and paty hold the x,y location of the rotated pattern.
-
-	Subsequent: patx and paty hold the same location as the SetupFor
-		    function so these can be ignored.
-
-    neither flag
-
-	SetupFor: patx and paty hold the x,y location of the unrotated
-		  pattern.  This can be ignored.
-
-	Subsequent: patx and paty hold the x,y location of the rotated
-		    pattern.
-
-    Additional information about cached patterns...
-    All 8x8 color patterns are cached in offscreen video memory so
-    the pixmap cache must be enabled to use them. The first pattern
-    starts at the cache slot boundary which is set by the 
-    CachePixelGranularity field used to configure the pixmap cache.
-    One should ensure that the CachePixelGranularity reflects any 
-    alignment restrictions that the accelerator may put on 8x8 pattern 
-    storage locations.  When HARDWARE_PATTERN_PROGRAMMED_ORIGIN is set 
-    there is only one pattern stored.  When this flag is not set,
-    all 64 rotations off the pattern are accessible but it is assumed
-    that the accelerator is capable of accessing data stored on 8
-    pixel boundaries.  If the accelerator has stricter alignment 
-    requirements than this the dirver will need to provide its own 
-    8x8 color pattern caching routines. 
-
-
-void SetupForColor8x8PatternFill(ScrnInfoPtr pScrn, int patx, int paty,
-        	int rop, unsigned int planemask, int trans_color)
-
-    SetupForColor8x8PatternFill indicates that any combination of the 
-    following  may follow it.
-
-	SubsequentColor8x8PatternFillRect
-	SubsequentColor8x8PatternFillTrap	(not implemented yet)
-
-    For the meanings of patx and paty, see the table above.  Trans_color
-    means the same as for the ScreenToScreenCopy functions.
-
-
- 
-void SubsequentColor8x8PatternFillRect( ScrnInfoPtr pScrn,
-        	int patx, int paty, int x, int y, int w, int h)
-
-     Fill a rectangle of dimensions "w" by "h" with origin at (x,y) 
-     using the parameters give by the last SetupForColor8x8PatternFill
-     call.  The meanings of patx and paty can be determined by the
-     table above.
-
-void SubsequentColor8x8PatternFillTrap( ScrnInfoPtr pScrn,
-     			   int patx, int paty, int y, int h, 
-     			   int left, int dxL, int dyL, int eL,
-     			   int right, int dxR, int dyR, int eR )
-
-    For the meanings of patx and paty, see the table above. 
-    The rest of the fields have the same meanings as those in the 
-    SubsequentSolidFillTrap function. 
-
-
-
-2.8  Image Writes
-
-    XAA provides a mechanism for transfering full color pixel data from
-    system memory to video memory through the accelerator.  This is 
-    useful for dealing with alignment issues and performing raster ops
-    on the data when writing it to the framebuffer.  As with color
-    expansion rectangles, there is a direct and indirect method.  The
-    direct method sends all data through a memory mapped aperature.
-    The indirect method sends the data to an intermediated buffer scanline 
-    at a time.
-
-    The direct and indirect methods have separate flags fields, the
-    ImageWriteFlags and ScanlineImageWriteFlags respectively.
-    Flags specific to one method or the other are described in sections 
-    2.8.1 and 2.8.2 but for both cases the GXCOPY_ONLY, ROP_NEEDS_SOURCE
-    and NO_PLANEMASK flags described in Section 2.0 are valid as well as
-    the following:
-
-    NO_GXCOPY
-
-      In order to have accelerated image transfers faster than the 
-      software versions for GXcopy, the engine needs to support clipping,
-      be using the direct method and have a large enough image transfer
-      range so that CPU_TRANSFER_BASE_FIXED doesn't need to be set.
-      If these are not supported, then it is unlikely that transfering
-      the data through the accelerator will be of any advantage for the
-      simple case of GXcopy.  In fact, it may be much slower.  For such
-      cases it's probably best to set the NO_GXCOPY flag so that 
-      Image writes will only be used for the more complicated rops.
-
-    /* transparency restrictions */
-
-    NO_TRANSPARENCY
-     
-      This indicates that the accelerator does not support skipping
-      of color keyed pixels when copying from the source to the destination.
-
-    TRANSPARENCY_GXCOPY_ONLY
-
-      This indicates that the accelerator supports skipping of color keyed
-      pixels only when the rop is GXcopy.
-
-    /* clipping  (optional) */
-    
-    LEFT_EDGE_CLIPPING
- 
-      This indicates that the accelerator supports omission of up to
-      3 pixels on the left edge of the rectangle to be filled.  This
-      is beneficial since it allows transfer from the source pixmap to
-      always occur from DWORD boundaries. 
-
-    LEFT_EDGE_CLIPPING_NEGATIVE_X
-
-      This flag indicates that the accelerator can fill areas with
-      image write data even if the value of x origin is negative (off of
-      the screen on the left edge).
-
-
-2.8.1 The Direct Method
-
-    Using the direct method of ImageWrite XAA will send all
-    bitmap data to the accelerator serially through an memory mapped
-    transfer window defined by the following two fields:
-
-      unsigned char *ImageWriteBase
-
-        This indicates the memory address of the beginning of the aperture.
-
-      int ImageWriteRange
-
-        This indicates the size in bytes of the aperture.
-
-    The driver should specify how the transfered data should be padded.
-    There are options for both the padding of each Y scanline and for the
-    total transfer to the aperature.
-    One of the following two flags must be set:
-
-      CPU_TRANSFER_PAD_DWORD
-
-        This indicates that the total transfer (sum of all scanlines) sent
-        to the aperature must be DWORD padded.  This is the default behavior.
-
-      CPU_TRANSFER_PAD_QWORD 
-
-	This indicates that the total transfer (sum of all scanlines) sent
-	to the aperature must be QWORD padded.  With this set, XAA will send
-        an extra DWORD to the aperature when needed to ensure that only
-        an even number of DWORDs are sent.
-
-    And then there are the flags for padding of each scanline:
-
-      SCANLINE_PAD_DWORD
-
-	This indicates that each Y scanline should be DWORD padded.
-        This is the only option available and is the default.
-
-    Finally, there is the CPU_TRANSFER_BASE_FIXED flag which indicates
-    that the aperture is a single register rather than a range of
-    registers, and XAA should write all of the data to the first DWORD.
-    XAA will automatically select CPU_TRANSFER_BASE_FIXED if the 
-    ImageWriteRange is not large enough to accomodate an entire scanline.   
-
-
-void SetupForImageWrite(ScrnInfoPtr pScrn, int rop, unsigned int planemask,
-        			int trans_color, int bpp, int depth)
-
-     If trans_color is not -1 then trans_color indicates the transparency
-     color key and pixels with color trans_color passed through the 
-     aperature should not be transfered to the screen but should be 
-     skipped.  Bpp and depth indicate the bits per pixel and depth of
-     the source pixmap.  Trans_color is always -1 if the NO_TRANSPARENCY
-     flag is set.
-
-
-void SubsequentImageWriteRect(ScrnInfoPtr pScrn, 
-				int x, int y, int w, int h, int skipleft)
-
-     
-     Data passed through the aperature should be copied to a rectangle
-     of width "w" and height "h" with origin (x,y).  If LEFT_EDGE_CLIPPING
-     has been enabled, skipleft will correspond to the number of pixels
-     on the left edge that should not be drawn.  Skipleft is zero 
-     otherwise.
-
-     It can be arranged for XAA to call Sync() after it is through 
-     calling the Subsequent functions by setting SYNC_AFTER_IMAGE_WRITE 
-     in the  ImageWriteFlags.  This can provide the driver with an
-     oportunity to reset a clipping window if needed.
-
-2.8.2  The Indirect Method
-
-     Using the indirect method, XAA will render the pixel data scanline
-     at a time to one or more buffers.  These buffers may be memory
-     mapped apertures or just intermediate storage.
-
-     int NumScanlineImageWriteBuffers
-
-       This indicates the number of buffers available.
-
-     unsigned char **ScanlineImageWriteBuffers
-
-       This is an array of pointers to the memory locations of each buffer.
-       Each buffer is expected to be large enough to accommodate scanlines
-       the width of the screen.  That is:
-
-         pScrn->VirtualX * pScreen->bitsPerPixel/8   bytes or more.
-
-       If LEFT_EDGE_CLIPPING_NEGATIVE_X is set, add an additional 4
-       bytes to that requirement in 8 and 16bpp, 12 bytes in 24bpp.
-  
-     Scanlines are always DWORD padded.
-
-void SetupForScanlineImageWrite(ScrnInfoPtr pScrn, int rop, 
-				unsigned int planemask, int trans_color, 
-				int bpp, int depth)
-
-     If trans_color is not -1 then trans_color indicates the transparency
-     color key and pixels with color trans_color in the buffer should not 
-     be transfered to the screen but should be skipped.  Bpp and depth 
-     indicate the bits per pixel and depth of the source bitmap.  
-     Trans_color is always -1 if the NO_TRANSPARENCY flag is set.
-
-
-void SubsequentImageWriteRect(ScrnInfoPtr pScrn, 
-				int x, int y, int w, int h, int skipleft)
-
-     
-void SubsequentImageWriteScanline(ScrnInfoPtr pScrn, int bufno)
-
-
-    When SubsequentImageWriteRect is called, XAA will begin
-    transfering the source data scanline at a time, calling  
-    SubsequentImageWriteScanline after each scanline.  If more than
-    one buffer is available, XAA will cycle through the buffers.
-    Subsequent scanlines will use the next buffer and go back to the
-    buffer 0 again when the last buffer is reached.  The index into
-    the ScanlineImageWriteBuffers array is presented as "bufno"
-    with each SubsequentImageWriteScanline call.
-
-    The skipleft field is the same as for the direct method.
-
-    The indirect method can be use to send the source data directly 
-    to a memory mapped aperture represented by a single image write
-    buffer, scanline at a time, but more commonly it is used to place 
-    the data into offscreen video memory so that the accelerator can 
-    blit it to the visible screen from there.  In the case where the
-    accelerator permits rendering into offscreen video memory while
-    the accelerator is active, several buffers can be used so that
-    XAA can be placing source data into the next buffer while the
-    accelerator is blitting the current buffer.  For cases where
-    the accelerator requires some special manipulation of the source
-    data first, the buffers can be in system memory.  The CPU can
-    manipulate these buffers and then send the data to the accelerator.
-
-
-2.9 Clipping
-
-    XAA supports hardware clipping rectangles.  To use clipping
-    in this way it is expected that the graphics accelerator can
-    clip primitives with verticies anywhere in the 16 bit signed 
-    coordinate system. 
-
-void SetClippingRectangle ( ScrnInfoPtr pScrn,
-        		int left, int top, int right, int bottom)
-
-void DisableClipping (ScrnInfoPtr pScrn)
-
-    When SetClippingRectangle is called, all hardware rendering
-    following it should be clipped to the rectangle specified
-    until DisableClipping is called.
-
-    The ClippingFlags field indicates which operations this sort
-    of Set/Disable pairing can be used with.  Any of the following
-    flags may be OR'd together.
-
-	HARDWARE_CLIP_SCREEN_TO_SCREEN_COLOR_EXPAND
-	HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY
-	HARDWARE_CLIP_MONO_8x8_FILL
-	HARDWARE_CLIP_COLOR_8x8_FILL
-	HARDWARE_CLIP_SOLID_FILL
-	HARDWARE_CLIP_DASHED_LINE
-	HARDWARE_CLIP_SOLID_LINE
-
-
-
-3)  XAA PIXMAP CACHE
-
-   /* NOTE:  XAA has no knowledge of framebuffer particulars so until
-	the framebuffer is able to render into offscreen memory, usage
-	of the pixmap cache requires that the driver provide ImageWrite
-	routines or a WritePixmap or WritePixmapToCache replacement so
-	that patterns can even be placed in the cache.
-
-      ADDENDUM: XAA can now load the pixmap cache without requiring
-	that the driver supply an ImageWrite function, but this can
-	only be done on linear framebuffers.  If you have a linear
-	framebuffer, set LINEAR_FRAMEBUFFER in the XAAInfoRec.Flags
-	field and XAA will then be able to upload pixmaps into the
-	cache without the driver providing functions to do so.
-   */
-
-
-   The XAA pixmap cache provides a mechanism for caching of patterns
-   in offscreen video memory so that tiled fills and in some cases
-   stippling can be done by blitting the source patterns from offscreen
-   video memory. The pixmap cache also provides the mechanism for caching 
-   of 8x8 color and mono hardware patterns.  Any unused offscreen video
-   memory gets used for the pixmap cache and that information is 
-   provided by the XFree86 Offscreen Memory Manager. XAA registers a 
-   callback with the manager so that it can be informed of any changes 
-   in the offscreen memory configuration.  The driver writer does not 
-   need to deal with any of this since it is all automatic.  The driver 
-   merely needs to initialize the Offscreen Memory Manager as described 
-   in the DESIGN document and set the PIXMAP_CACHE flag in the 
-   XAAInfoRec.Flags field.  The Offscreen Memory Manager initialization 
-   must occur before XAA is initialized or else pixmap cache 
-   initialization will fail.  
-
-   PixmapCacheFlags is an XAAInfoRec field which allows the driver to
-   control pixmap cache behavior to some extent.  Currently only one
-   flag is defined:
-
-   DO_NOT_BLIT_STIPPLES
-
-     This indicates that the stippling should not be done by blitting
-     from the pixmap cache.  This does not apply to 8x8 pattern fills. 
-
-
-   CachePixelGranularity is an optional field.  If the hardware requires
-   that a 8x8 patterns have some particular pixel alignment it should
-   be reflected in this field.  Ignoring this field or setting it to
-   zero or one means there are no alignment issues.
-
-
-4)  OFFSCREEN PIXMAPS
-
-   XAA has the ability to store pixmap drawables in offscreen video 
-   memory and render into them with full hardware acceleration.  Placement
-   of pixmaps in the cache is done automatically on a first-come basis and 
-   only if there is room.  To enable this feature, set the OFFSCREEN_PIXMAPS
-   flag in the XAAInfoRec.Flags field.  This is only available when a
-   ScreenToScreenCopy function is provided, when the Offscreen memory 
-   manager has been initialized and when the LINEAR_FRAMEBUFFER flag is
-   also set.
-
-   int maxOffPixWidth
-   int maxOffPixHeight
-
-       These two fields allow the driver to limit the maximum dimensions
-     of an offscreen pixmap.  If one of these is not set, it is assumed
-     that there is no limit on that dimension.  Note that if an offscreen
-     pixmap with a particular dimension is allowed, then your driver will be
-     expected to render primitives as large as that pixmap.  
-
-$XFree86: xc/programs/Xserver/hw/xfree86/xaa/XAA.HOWTO,v 1.12 2000/04/12 14:44:42 tsi Exp $
diff --git a/hw/xfree86/xaa/xaa.h b/hw/xfree86/xaa/xaa.h
deleted file mode 100644
index b530037..0000000
--- a/hw/xfree86/xaa/xaa.h
+++ /dev/null
@@ -1,1038 +0,0 @@
-
-#ifndef _XAA_H
-#define _XAA_H
-
-#define XAA_VERSION_MAJOR   1
-#define XAA_VERSION_MINOR   2
-#define XAA_VERSION_RELEASE 1
-
-/*
-
-   ******** OPERATION SPECIFIC FLAGS *********
-
-   **** solid/dashed line flags ****
- 
----------               --------
-23           LINE_PATTERN_LSBFIRST_MSBJUSTIFIED
-22           LINE_PATTERN_LSBFIRST_LSBJUSTIFIED
-21           LINE_PATTERN_MSBFIRST_MSBJUSTIFIED
-20           LINE_PATTERN_MSBFIRST_LSBJUSTIFIED
-19           LINE_PATTERN_POWER_OF_2_ONLY
-18           LINE_LIMIT_COORDS
-17                         .
-16                         .
----------               -------
-
-   **** screen to screen copy flags ****
-
----------               --------
-23           ONLY_LEFT_TO_RIGHT_BITBLT
-22           ONLY_TWO_BITBLT_DIRECTIONS
-21                         .
-20                         .
-19                         .
-18                         .
-17                         .
-16                         .
----------               -------
-
-   ****  clipping flags ****
-
----------               --------
-23                         .
-22           HARDWARE_CLIP_SCREEN_TO_SCREEN_COLOR_EXPAND
-21           HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY
-20           HARDWARE_CLIP_MONO_8x8_FILL
-19           HARDWARE_CLIP_COLOR_8x8_FILL    
-18           HARDWARE_CLIP_SOLID_FILL
-17           HARDWARE_CLIP_DASHED_LINE
-16           HARDWARE_CLIP_SOLID_LINE
----------               -------
-
-   ****  hardware pattern flags ****
-
----------               --------
-23                         .
-22                         .
-21           HARDWARE_PATTERN_SCREEN_ORIGIN
-20                         .
-19                         .
-18                         .
-17           HARDWARE_PATTERN_PROGRAMMED_ORIGIN
-16           HARDWARE_PATTERN_PROGRAMMED_BITS
----------               -------
-
-   ****  write pixmap flags ****
-
----------               --------
-23                         .
-22                         .
-21                         .
-20                         .
-19                         .
-18                         .
-17                         .
-16           CONVERT_32BPP_TO_24BPP
----------               -------
-
-   ******** GENERIC FLAGS *********
-
----------               -------
-15           SYNC_AFTER_COLOR_EXPAND
-14           CPU_TRANSFER_PAD_QWORD
-13                         .
-12           LEFT_EDGE_CLIPPING_NEGATIVE_X
-11	     LEFT_EDGE_CLIPPING
-10	     CPU_TRANSFER_BASE_FIXED
- 9           BIT_ORDER_IN_BYTE_MSBFIRST           
- 8           TRANSPARENCY_GXCOPY_ONLY
----------               -------
- 7           NO_TRANSPARENCY
- 6           TRANSPARENCY_ONLY
- 5           ROP_NEEDS_SOURCE
- 4           TRIPLE_BITS_24BPP
- 3           RGB_EQUAL
- 2           NO_PLANEMASK
- 1           NO_GXCOPY
- 0           GXCOPY_ONLY
----------               -------
-
-
-*/
-
-#include "gcstruct.h"
-#include "pixmapstr.h"
-#include "xf86str.h"
-#include "regionstr.h"
-#include "xf86fbman.h"
-
-#include "picturestr.h"
-
-/* Flags */
-#define PIXMAP_CACHE			0x00000001
-#define MICROSOFT_ZERO_LINE_BIAS	0x00000002
-#define OFFSCREEN_PIXMAPS		0x00000004
-#define LINEAR_FRAMEBUFFER		0x00000008
-
-/* GC fg, bg, and planemask restrictions */
-#define GXCOPY_ONLY			0x00000001
-#define NO_GXCOPY			0x00000002
-#define NO_PLANEMASK			0x00000004
-#define RGB_EQUAL			0x00000008
-#define TRIPLE_BITS_24BPP		0x00000010
-#define ROP_NEEDS_SOURCE		0x00000020
-
-/* transparency restrictions */
-#define TRANSPARENCY_ONLY		0x00000040
-#define NO_TRANSPARENCY			0x00000080
-#define TRANSPARENCY_GXCOPY_ONLY     	0x00000100
-
-/* bit order restrictions */
-#define BIT_ORDER_IN_BYTE_MSBFIRST	0x00000200
-#define BIT_ORDER_IN_BYTE_LSBFIRST	0x00000000
-
-/* transfer base restriction */
-#define CPU_TRANSFER_BASE_FIXED		0x00000400
-
-/* skipleft restrictions */
-#define LEFT_EDGE_CLIPPING		0x00000800
-#define LEFT_EDGE_CLIPPING_NEGATIVE_X	0x00001000
-
-/* data padding */
-#define CPU_TRANSFER_PAD_DWORD		0x00000000
-#define CPU_TRANSFER_PAD_QWORD		0x00004000
-#define SCANLINE_PAD_DWORD		0x00000000
-
-#define SYNC_AFTER_COLOR_EXPAND		0x00008000
-#define SYNC_AFTER_IMAGE_WRITE		SYNC_AFTER_COLOR_EXPAND
-
-/* hardware pattern */
-#define HARDWARE_PATTERN_PROGRAMMED_BITS	0x00010000
-#define HARDWARE_PATTERN_PROGRAMMED_ORIGIN	0x00020000
-#define HARDWARE_PATTERN_SCREEN_ORIGIN		0x00200000
-
-/* copyarea flags */
-#define ONLY_TWO_BITBLT_DIRECTIONS	0x00400000
-#define ONLY_LEFT_TO_RIGHT_BITBLT	0x00800000
-
-/* line flags */
-#define LINE_PATTERN_LSBFIRST_MSBJUSTIFIED	0x00800000
-#define LINE_PATTERN_LSBFIRST_LSBJUSTIFIED	0x00400000
-#define LINE_PATTERN_MSBFIRST_MSBJUSTIFIED	0x00200000
-#define LINE_PATTERN_MSBFIRST_LSBJUSTIFIED	0x00100000
-#define LINE_PATTERN_POWER_OF_2_ONLY		0x00080000
-#define LINE_LIMIT_COORDS			0x00040000
-
-/* clipping flags */
-#define HARDWARE_CLIP_SCREEN_TO_SCREEN_COLOR_EXPAND	0x00400000
-#define HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY		0x00200000
-#define HARDWARE_CLIP_MONO_8x8_FILL			0x00100000
-#define HARDWARE_CLIP_COLOR_8x8_FILL			0x00080000
-#define HARDWARE_CLIP_SOLID_FILL			0x00040000
-#define HARDWARE_CLIP_DASHED_LINE			0x00020000
-#define HARDWARE_CLIP_SOLID_LINE			0x00010000
-
-#define HARDWARE_CLIP_LINE				0x00000000
-
-/* image write flags */
-#define CONVERT_32BPP_TO_24BPP			0x00010000
-
-/* pixmap cache flags */
-#define CACHE_MONO_8x8			0x00000001
-#define CACHE_COLOR_8x8			0x00000002
-#define DO_NOT_BLIT_STIPPLES		0x00000004
-#define DO_NOT_TILE_MONO_DATA		0x00000008
-#define DO_NOT_TILE_COLOR_DATA		0x00000010
-
-#define DEGREES_0	0
-#define DEGREES_90	1
-#define DEGREES_180	2
-#define DEGREES_270	3
-
-#define OMIT_LAST	1
-
-/* render flags */
-
-#define XAA_RENDER_POWER_OF_2_TILE_ONLY	0x00000008
-#define XAA_RENDER_NO_SRC_ALPHA		0x00000004
-#define XAA_RENDER_IMPRECISE_ONLY	0x00000002
-#define XAA_RENDER_NO_TILE		0x00000001
-
-#define XAA_RENDER_REPEAT		0x00000001
-
-typedef void (*ValidateGCProcPtr) (GCPtr pGC,
-                                   unsigned long changes, DrawablePtr pDraw);
-
-typedef struct {
-    unsigned char *bits;
-    int width;
-    int height;
-    int yoff;
-    int srcwidth;
-    int start;
-    int end;
-} NonTEGlyphInfo, *NonTEGlyphPtr;
-
-typedef struct {
-    int x;
-    int y;
-    int w;
-    int h;
-    int orig_w;
-    int orig_h;
-    unsigned long serialNumber;
-    int pat0;
-    int pat1;
-    int fg;
-    int bg;
-    int trans_color;
-    DDXPointPtr offsets;
-    DevUnion devPrivate;
-} XAACacheInfoRec, *XAACacheInfoPtr;
-
-typedef struct _PixmapLink {
-    PixmapPtr pPix;
-    struct _PixmapLink *next;
-    FBAreaPtr area;
-} PixmapLink, *PixmapLinkPtr;
-
-typedef struct _XAAInfoRec {
-    ScrnInfoPtr pScrn;
-    int Flags;
-
-    void (*Sync) (ScrnInfoPtr pScrn);
-
-    /* Restore Accel State is a driver callback that is used
-     * when another screen on the same device has been active.
-     * This allows multihead on a single device to work.
-     * If The entityProp has IS_SHARED_ACCEL defined then this
-     * function is required.
-     */
-
-    void (*RestoreAccelState) (ScrnInfoPtr pScrn);
-
-   /***************** Low Level *****************/
-
-/* Blits */
-    void (*SetupForScreenToScreenCopy) (ScrnInfoPtr pScrn,
-                                        int xdir, int ydir,
-                                        int rop,
-                                        unsigned int planemask,
-                                        int trans_color);
-    int ScreenToScreenCopyFlags;
-
-    void (*SubsequentScreenToScreenCopy) (ScrnInfoPtr pScrn,
-                                          int xsrc, int ysrc,
-                                          int xdst, int ydst, int w, int h);
-
-/* Solid fills */
-    void (*SetupForSolidFill) (ScrnInfoPtr pScrn,
-                               int color, int rop, unsigned int planemask);
-    int SolidFillFlags;
-
-    void (*SubsequentSolidFillRect) (ScrnInfoPtr pScrn,
-                                     int x, int y, int w, int h);
-
-    void (*SubsequentSolidFillTrap) (ScrnInfoPtr pScrn,
-                                     int y, int h,
-                                     int left, int dxL, int dyL, int eL,
-                                     int right, int dxR, int dyR, int eR);
-
-/* Solid lines */
-
-    void (*SetupForSolidLine) (ScrnInfoPtr pScrn,
-                               int color, int rop, unsigned int planemask);
-    int SolidLineFlags;
-
-    void (*SubsequentSolidTwoPointLine) (ScrnInfoPtr pScrn,
-                                         int xa, int ya, int xb, int yb,
-                                         int flags);
-
-    void (*SubsequentSolidBresenhamLine) (ScrnInfoPtr pScrn,
-                                          int x, int y, int absmaj, int absmin,
-                                          int err, int len, int octant);
-    int SolidBresenhamLineErrorTermBits;
-
-    void (*SubsequentSolidHorVertLine) (ScrnInfoPtr pScrn,
-                                        int x, int y, int len, int dir);
-
-/* Dashed lines */
-
-    void (*SetupForDashedLine) (ScrnInfoPtr pScrn,
-                                int fg, int bg,
-                                int rop,
-                                unsigned int planemask,
-                                int length, unsigned char *pattern);
-    int DashedLineFlags;
-    int DashPatternMaxLength;
-
-    void (*SubsequentDashedTwoPointLine) (ScrnInfoPtr pScrn,
-                                          int xa, int ya, int xb, int yb,
-                                          int flags, int phase);
-
-    void (*SubsequentDashedBresenhamLine) (ScrnInfoPtr pScrn,
-                                           int x, int y, int absmaj, int absmin,
-                                           int err, int len, int flags,
-                                           int phase);
-    int DashedBresenhamLineErrorTermBits;
-
-/* Clipper */
-
-    void (*SetClippingRectangle) (ScrnInfoPtr pScrn,
-                                  int left, int top, int right, int bottom);
-    int ClippingFlags;
-
-    void (*DisableClipping) (ScrnInfoPtr pScrn);
-
-/* 8x8 mono pattern fills */
-    void (*SetupForMono8x8PatternFill) (ScrnInfoPtr pScrn,
-                                        int patx, int paty,
-                                        int fg, int bg,
-                                        int rop, unsigned int planemask);
-    int Mono8x8PatternFillFlags;
-
-    void (*SubsequentMono8x8PatternFillRect) (ScrnInfoPtr pScrn,
-                                              int patx, int paty,
-                                              int x, int y, int w, int h);
-
-    void (*SubsequentMono8x8PatternFillTrap) (ScrnInfoPtr pScrn,
-                                              int patx, int paty,
-                                              int y, int h,
-                                              int left, int dxL, int dyL,
-                                              int eL, int right, int dxR,
-                                              int dyR, int eR);
-
-/* 8x8 color pattern fills */
-
-    void (*SetupForColor8x8PatternFill) (ScrnInfoPtr pScrn,
-                                         int patx, int paty,
-                                         int rop,
-                                         unsigned int planemask,
-                                         int transparency_color);
-    int Color8x8PatternFillFlags;
-
-    void (*SubsequentColor8x8PatternFillRect) (ScrnInfoPtr pScrn,
-                                               int patx, int paty,
-                                               int x, int y, int w, int h);
-
-    void (*SubsequentColor8x8PatternFillTrap) (ScrnInfoPtr pScrn,
-                                               int patx, int paty,
-                                               int y, int h,
-                                               int left, int dxL, int dyL,
-                                               int eL, int right, int dxR,
-                                               int dyR, int eR);
-
-/* Color expansion */
-
-    void (*SetupForCPUToScreenColorExpandFill) (ScrnInfoPtr pScrn,
-                                                int fg, int bg,
-                                                int rop,
-                                                unsigned int planemask);
-    int CPUToScreenColorExpandFillFlags;
-
-    void (*SubsequentCPUToScreenColorExpandFill) (ScrnInfoPtr pScrn,
-                                                  int x, int y, int w, int h,
-                                                  int skipleft);
-
-    unsigned char *ColorExpandBase;
-    int ColorExpandRange;
-
-/* Scanline color expansion  */
-
-    void (*SetupForScanlineCPUToScreenColorExpandFill) (ScrnInfoPtr pScrn,
-                                                        int fg, int bg,
-                                                        int rop,
-                                                        unsigned int planemask);
-    int ScanlineCPUToScreenColorExpandFillFlags;
-
-    void (*SubsequentScanlineCPUToScreenColorExpandFill) (ScrnInfoPtr pScrn,
-                                                          int x, int y, int w,
-                                                          int h, int skipleft);
-
-    void (*SubsequentColorExpandScanline) (ScrnInfoPtr pScrn, int bufno);
-
-    int NumScanlineColorExpandBuffers;
-    unsigned char **ScanlineColorExpandBuffers;
-
-/* Screen to screen color expansion */
-
-    void (*SetupForScreenToScreenColorExpandFill) (ScrnInfoPtr pScrn,
-                                                   int fg, int bg,
-                                                   int rop,
-                                                   unsigned int planemask);
-    int ScreenToScreenColorExpandFillFlags;
-
-    void (*SubsequentScreenToScreenColorExpandFill) (ScrnInfoPtr pScrn,
-                                                     int x, int y, int w, int h,
-                                                     int srcx, int srcy,
-                                                     int skipleft);
-
-/*  Image transfers */
-
-    void (*SetupForImageWrite) (ScrnInfoPtr pScrn,
-                                int rop,
-                                unsigned int planemask,
-                                int transparency_color, int bpp, int depth);
-    int ImageWriteFlags;
-
-    void (*SubsequentImageWriteRect) (ScrnInfoPtr pScrn,
-                                      int x, int y, int w, int h, int skipleft);
-    unsigned char *ImageWriteBase;
-    int ImageWriteRange;
-
-/*  Scanline Image transfers */
-
-    void (*SetupForScanlineImageWrite) (ScrnInfoPtr pScrn,
-                                        int rop,
-                                        unsigned int planemask,
-                                        int transparency_color,
-                                        int bpp, int depth);
-    int ScanlineImageWriteFlags;
-
-    void (*SubsequentScanlineImageWriteRect) (ScrnInfoPtr pScrn,
-                                              int x, int y, int w, int h,
-                                              int skipleft);
-
-    void (*SubsequentImageWriteScanline) (ScrnInfoPtr pScrn, int bufno);
-
-    int NumScanlineImageWriteBuffers;
-    unsigned char **ScanlineImageWriteBuffers;
-
-    /* Image Reads - OBSOLETE AND NOT USED */
-
-    void (*SetupForImageRead) (ScrnInfoPtr pScrn, int bpp, int depth);
-    int ImageReadFlags;
-
-    unsigned char *ImageReadBase;
-    int ImageReadRange;
-
-    void (*SubsequentImageReadRect) (ScrnInfoPtr pScrn,
-                                     int x, int y, int w, int h);
-
-   /***************** Mid Level *****************/
-    void (*ScreenToScreenBitBlt) (ScrnInfoPtr pScrn,
-                                  int nbox,
-                                  DDXPointPtr pptSrc,
-                                  BoxPtr pbox,
-                                  int xdir, int ydir,
-                                  int alu, unsigned int planmask);
-    int ScreenToScreenBitBltFlags;
-
-    void (*WriteBitmap) (ScrnInfoPtr pScrn,
-                         int x, int y, int w, int h,
-                         unsigned char *src,
-                         int srcwidth,
-                         int skipleft,
-                         int fg, int bg, int rop, unsigned int planemask);
-    int WriteBitmapFlags;
-
-    void (*FillSolidRects) (ScrnInfoPtr pScrn,
-                            int fg, int rop,
-                            unsigned int planemask, int nBox, BoxPtr pBox);
-    int FillSolidRectsFlags;
-
-    void (*FillMono8x8PatternRects) (ScrnInfoPtr pScrn,
-                                     int fg, int bg, int rop,
-                                     unsigned int planemask,
-                                     int nBox,
-                                     BoxPtr pBox,
-                                     int pat0, int pat1, int xorg, int yorg);
-    int FillMono8x8PatternRectsFlags;
-
-    void (*FillColor8x8PatternRects) (ScrnInfoPtr pScrn,
-                                      int rop,
-                                      unsigned int planemask,
-                                      int nBox,
-                                      BoxPtr pBox,
-                                      int xorg, int yorg,
-                                      XAACacheInfoPtr pCache);
-    int FillColor8x8PatternRectsFlags;
-
-    void (*FillCacheBltRects) (ScrnInfoPtr pScrn,
-                               int rop,
-                               unsigned int planemask,
-                               int nBox,
-                               BoxPtr pBox,
-                               int xorg, int yorg, XAACacheInfoPtr pCache);
-    int FillCacheBltRectsFlags;
-
-    void (*FillColorExpandRects) (ScrnInfoPtr pScrn,
-                                  int fg, int bg, int rop,
-                                  unsigned int planemask,
-                                  int nBox,
-                                  BoxPtr pBox,
-                                  int xorg, int yorg, PixmapPtr pPix);
-    int FillColorExpandRectsFlags;
-
-    void (*FillCacheExpandRects) (ScrnInfoPtr pScrn,
-                                  int fg, int bg, int rop,
-                                  unsigned int planemask,
-                                  int nBox,
-                                  BoxPtr pBox,
-                                  int xorg, int yorg, PixmapPtr pPix);
-    int FillCacheExpandRectsFlags;
-
-    void (*FillImageWriteRects) (ScrnInfoPtr pScrn,
-                                 int rop,
-                                 unsigned int planemask,
-                                 int nBox,
-                                 BoxPtr pBox,
-                                 int xorg, int yorg, PixmapPtr pPix);
-    int FillImageWriteRectsFlags;
-
-    void (*FillSolidSpans) (ScrnInfoPtr pScrn,
-                            int fg, int rop,
-                            unsigned int planemask,
-                            int n,
-                            DDXPointPtr points, int *widths, int fSorted);
-    int FillSolidSpansFlags;
-
-    void (*FillMono8x8PatternSpans) (ScrnInfoPtr pScrn,
-                                     int fg, int bg, int rop,
-                                     unsigned int planemask,
-                                     int n,
-                                     DDXPointPtr points,
-                                     int *widths,
-                                     int fSorted,
-                                     int pat0, int pat1, int xorg, int yorg);
-    int FillMono8x8PatternSpansFlags;
-
-    void (*FillColor8x8PatternSpans) (ScrnInfoPtr pScrn,
-                                      int rop,
-                                      unsigned int planemask,
-                                      int n,
-                                      DDXPointPtr points,
-                                      int *widths,
-                                      int fSorted,
-                                      XAACacheInfoPtr pCache,
-                                      int xorg, int yorg);
-    int FillColor8x8PatternSpansFlags;
-
-    void (*FillCacheBltSpans) (ScrnInfoPtr pScrn,
-                               int rop,
-                               unsigned int planemask,
-                               int n,
-                               DDXPointPtr points,
-                               int *widths,
-                               int fSorted,
-                               XAACacheInfoPtr pCache, int xorg, int yorg);
-    int FillCacheBltSpansFlags;
-
-    void (*FillColorExpandSpans) (ScrnInfoPtr pScrn,
-                                  int fg, int bg, int rop,
-                                  unsigned int planemask,
-                                  int n,
-                                  DDXPointPtr points,
-                                  int *widths,
-                                  int fSorted,
-                                  int xorg, int yorg, PixmapPtr pPix);
-    int FillColorExpandSpansFlags;
-
-    void (*FillCacheExpandSpans) (ScrnInfoPtr pScrn,
-                                  int fg, int bg, int rop,
-                                  unsigned int planemask,
-                                  int n,
-                                  DDXPointPtr ppt,
-                                  int *pwidth,
-                                  int fSorted,
-                                  int xorg, int yorg, PixmapPtr pPix);
-    int FillCacheExpandSpansFlags;
-
-    void (*TEGlyphRenderer) (ScrnInfoPtr pScrn,
-                             int x, int y, int w, int h, int skipleft,
-                             int startline, unsigned int **glyphs,
-                             int glyphWidth, int fg, int bg, int rop,
-                             unsigned planemask);
-    int TEGlyphRendererFlags;
-
-    void (*NonTEGlyphRenderer) (ScrnInfoPtr pScrn,
-                                int x, int y, int n,
-                                NonTEGlyphPtr glyphs,
-                                BoxPtr pbox,
-                                int fg, int rop, unsigned int planemask);
-    int NonTEGlyphRendererFlags;
-
-    void (*WritePixmap) (ScrnInfoPtr pScrn,
-                         int x, int y, int w, int h,
-                         unsigned char *src,
-                         int srcwidth,
-                         int rop,
-                         unsigned int planemask,
-                         int transparency_color, int bpp, int depth);
-    int WritePixmapFlags;
-
-    void (*ReadPixmap) (ScrnInfoPtr pScrn,
-                        int x, int y, int w, int h,
-                        unsigned char *dst, int dstwidth, int bpp, int depth);
-    int ReadPixmapFlags;
-
-   /***************** GC Level *****************/
-    RegionPtr (*CopyArea) (DrawablePtr pSrcDrawable,
-                           DrawablePtr pDstDrawable,
-                           GC * pGC,
-                           int srcx, int srcy,
-                           int width, int height, int dstx, int dsty);
-    int CopyAreaFlags;
-
-    RegionPtr (*CopyPlane) (DrawablePtr pSrc,
-                            DrawablePtr pDst,
-                            GCPtr pGC,
-                            int srcx, int srcy,
-                            int width, int height,
-                            int dstx, int dsty, unsigned long bitPlane);
-    int CopyPlaneFlags;
-
-    void (*PushPixelsSolid) (GCPtr pGC,
-                             PixmapPtr pBitMap,
-                             DrawablePtr pDrawable,
-                             int dx, int dy, int xOrg, int yOrg);
-    int PushPixelsFlags;
-
-   /** PolyFillRect **/
-
-    void (*PolyFillRectSolid) (DrawablePtr pDraw,
-                               GCPtr pGC, int nrectFill, xRectangle *prectInit);
-    int PolyFillRectSolidFlags;
-
-    void (*PolyFillRectStippled) (DrawablePtr pDraw,
-                                  GCPtr pGC,
-                                  int nrectFill, xRectangle *prectInit);
-    int PolyFillRectStippledFlags;
-
-    void (*PolyFillRectOpaqueStippled) (DrawablePtr pDraw,
-                                        GCPtr pGC,
-                                        int nrectFill, xRectangle *prectInit);
-    int PolyFillRectOpaqueStippledFlags;
-
-    void (*PolyFillRectTiled) (DrawablePtr pDraw,
-                               GCPtr pGC, int nrectFill, xRectangle *prectInit);
-    int PolyFillRectTiledFlags;
-
-   /** FillSpans **/
-
-    void (*FillSpansSolid) (DrawablePtr pDraw,
-                            GCPtr pGC,
-                            int nInit,
-                            DDXPointPtr ppt, int *pwidth, int fSorted);
-    int FillSpansSolidFlags;
-
-    void (*FillSpansStippled) (DrawablePtr pDraw,
-                               GCPtr pGC,
-                               int nInit,
-                               DDXPointPtr ppt, int *pwidth, int fSorted);
-    int FillSpansStippledFlags;
-
-    void (*FillSpansOpaqueStippled) (DrawablePtr pDraw,
-                                     GCPtr pGC,
-                                     int nInit,
-                                     DDXPointPtr ppt, int *pwidth, int fSorted);
-    int FillSpansOpaqueStippledFlags;
-
-    void (*FillSpansTiled) (DrawablePtr pDraw,
-                            GCPtr pGC,
-                            int nInit,
-                            DDXPointPtr ppt, int *pwidth, int fSorted);
-    int FillSpansTiledFlags;
-
-    int (*PolyText8TE) (DrawablePtr pDraw,
-                        GCPtr pGC, int x, int y, int count, char *chars);
-    int PolyText8TEFlags;
-
-    int (*PolyText16TE) (DrawablePtr pDraw,
-                         GCPtr pGC,
-                         int x, int y, int count, unsigned short *chars);
-    int PolyText16TEFlags;
-
-    void (*ImageText8TE) (DrawablePtr pDraw,
-                          GCPtr pGC, int x, int y, int count, char *chars);
-    int ImageText8TEFlags;
-
-    void (*ImageText16TE) (DrawablePtr pDraw,
-                           GCPtr pGC,
-                           int x, int y, int count, unsigned short *chars);
-    int ImageText16TEFlags;
-
-    void (*ImageGlyphBltTE) (DrawablePtr pDrawable,
-                             GCPtr pGC,
-                             int xInit, int yInit,
-                             unsigned int nglyph,
-                             CharInfoPtr * ppci, pointer pglyphBase);
-    int ImageGlyphBltTEFlags;
-
-    void (*PolyGlyphBltTE) (DrawablePtr pDrawable,
-                            GCPtr pGC,
-                            int xInit, int yInit,
-                            unsigned int nglyph,
-                            CharInfoPtr * ppci, pointer pglyphBase);
-    int PolyGlyphBltTEFlags;
-
-    int (*PolyText8NonTE) (DrawablePtr pDraw,
-                           GCPtr pGC, int x, int y, int count, char *chars);
-    int PolyText8NonTEFlags;
-
-    int (*PolyText16NonTE) (DrawablePtr pDraw,
-                            GCPtr pGC,
-                            int x, int y, int count, unsigned short *chars);
-    int PolyText16NonTEFlags;
-
-    void (*ImageText8NonTE) (DrawablePtr pDraw,
-                             GCPtr pGC, int x, int y, int count, char *chars);
-    int ImageText8NonTEFlags;
-
-    void (*ImageText16NonTE) (DrawablePtr pDraw,
-                              GCPtr pGC,
-                              int x, int y, int count, unsigned short *chars);
-    int ImageText16NonTEFlags;
-
-    void (*ImageGlyphBltNonTE) (DrawablePtr pDrawable,
-                                GCPtr pGC,
-                                int xInit, int yInit,
-                                unsigned int nglyph,
-                                CharInfoPtr * ppci, pointer pglyphBase);
-    int ImageGlyphBltNonTEFlags;
-
-    void (*PolyGlyphBltNonTE) (DrawablePtr pDrawable,
-                               GCPtr pGC,
-                               int xInit, int yInit,
-                               unsigned int nglyph,
-                               CharInfoPtr * ppci, pointer pglyphBase);
-    int PolyGlyphBltNonTEFlags;
-
-    void (*PolyRectangleThinSolid) (DrawablePtr pDrawable,
-                                    GCPtr pGC,
-                                    int nRectsInit, xRectangle *pRectsInit);
-    int PolyRectangleThinSolidFlags;
-
-    void (*PolylinesWideSolid) (DrawablePtr pDrawable,
-                                GCPtr pGC, int mode, int npt, DDXPointPtr pPts);
-    int PolylinesWideSolidFlags;
-
-    void (*PolylinesThinSolid) (DrawablePtr pDrawable,
-                                GCPtr pGC, int mode, int npt, DDXPointPtr pPts);
-    int PolylinesThinSolidFlags;
-
-    void (*PolySegmentThinSolid) (DrawablePtr pDrawable,
-                                  GCPtr pGC, int nseg, xSegment * pSeg);
-    int PolySegmentThinSolidFlags;
-
-    void (*PolylinesThinDashed) (DrawablePtr pDrawable,
-                                 GCPtr pGC,
-                                 int mode, int npt, DDXPointPtr pPts);
-    int PolylinesThinDashedFlags;
-
-    void (*PolySegmentThinDashed) (DrawablePtr pDrawable,
-                                   GCPtr pGC, int nseg, xSegment * pSeg);
-    int PolySegmentThinDashedFlags;
-
-    void (*FillPolygonSolid) (DrawablePtr pDrawable,
-                              GCPtr pGC,
-                              int shape,
-                              int mode, int count, DDXPointPtr ptsIn);
-    int FillPolygonSolidFlags;
-
-    void (*FillPolygonStippled) (DrawablePtr pDrawable,
-                                 GCPtr pGC,
-                                 int shape,
-                                 int mode, int count, DDXPointPtr ptsIn);
-    int FillPolygonStippledFlags;
-
-    void (*FillPolygonOpaqueStippled) (DrawablePtr pDrawable,
-                                       GCPtr pGC,
-                                       int shape,
-                                       int mode, int count, DDXPointPtr ptsIn);
-    int FillPolygonOpaqueStippledFlags;
-
-    void (*FillPolygonTiled) (DrawablePtr pDrawable,
-                              GCPtr pGC,
-                              int shape,
-                              int mode, int count, DDXPointPtr ptsIn);
-    int FillPolygonTiledFlags;
-
-    void (*PolyFillArcSolid) (DrawablePtr pDraw,
-                              GCPtr pGC, int narcs, xArc * parcs);
-    int PolyFillArcSolidFlags;
-
-    void (*PutImage) (DrawablePtr pDraw,
-                      GCPtr pGC,
-                      int depth,
-                      int x,
-                      int y,
-                      int w, int h, int leftPad, int format, char *pImage);
-    int PutImageFlags;
-
-    /* Validation masks */
-
-    unsigned long FillSpansMask;
-    ValidateGCProcPtr ValidateFillSpans;
-    unsigned long SetSpansMask;
-    ValidateGCProcPtr ValidateSetSpans;
-    unsigned long PutImageMask;
-    ValidateGCProcPtr ValidatePutImage;
-    unsigned long CopyAreaMask;
-    ValidateGCProcPtr ValidateCopyArea;
-    unsigned long CopyPlaneMask;
-    ValidateGCProcPtr ValidateCopyPlane;
-    unsigned long PolyPointMask;
-    ValidateGCProcPtr ValidatePolyPoint;
-    unsigned long PolylinesMask;
-    ValidateGCProcPtr ValidatePolylines;
-    unsigned long PolySegmentMask;
-    ValidateGCProcPtr ValidatePolySegment;
-    unsigned long PolyRectangleMask;
-    ValidateGCProcPtr ValidatePolyRectangle;
-    unsigned long PolyArcMask;
-    ValidateGCProcPtr ValidatePolyArc;
-    unsigned long FillPolygonMask;
-    ValidateGCProcPtr ValidateFillPolygon;
-    unsigned long PolyFillRectMask;
-    ValidateGCProcPtr ValidatePolyFillRect;
-    unsigned long PolyFillArcMask;
-    ValidateGCProcPtr ValidatePolyFillArc;
-    unsigned long PolyText8Mask;
-    ValidateGCProcPtr ValidatePolyText8;
-    unsigned long PolyText16Mask;
-    ValidateGCProcPtr ValidatePolyText16;
-    unsigned long ImageText8Mask;
-    ValidateGCProcPtr ValidateImageText8;
-    unsigned long ImageText16Mask;
-    ValidateGCProcPtr ValidateImageText16;
-    unsigned long PolyGlyphBltMask;
-    ValidateGCProcPtr ValidatePolyGlyphBlt;
-    unsigned long ImageGlyphBltMask;
-    ValidateGCProcPtr ValidateImageGlyphBlt;
-    unsigned long PushPixelsMask;
-    ValidateGCProcPtr ValidatePushPixels;
-
-    void (*ComputeDash) (GCPtr pGC);
-
-    /* Pixmap Cache */
-
-    int PixmapCacheFlags;
-    Bool UsingPixmapCache;
-    Bool CanDoMono8x8;
-    Bool CanDoColor8x8;
-
-    void (*InitPixmapCache) (ScreenPtr pScreen, RegionPtr areas, pointer data);
-    void (*ClosePixmapCache) (ScreenPtr pScreen);
-
-    int (*StippledFillChooser) (GCPtr pGC);
-    int (*OpaqueStippledFillChooser) (GCPtr pGC);
-    int (*TiledFillChooser) (GCPtr pGC);
-
-    int CachePixelGranularity;
-    int MaxCacheableTileWidth;
-    int MaxCacheableTileHeight;
-    int MaxCacheableStippleWidth;
-    int MaxCacheableStippleHeight;
-
-     XAACacheInfoPtr(*CacheTile) (ScrnInfoPtr Scrn, PixmapPtr pPix);
-     XAACacheInfoPtr(*CacheStipple) (ScrnInfoPtr Scrn, PixmapPtr pPix,
-                                     int fg, int bg);
-     XAACacheInfoPtr(*CacheMonoStipple) (ScrnInfoPtr Scrn, PixmapPtr pPix);
-     XAACacheInfoPtr(*CacheMono8x8Pattern) (ScrnInfoPtr Scrn, int pat0,
-                                            int pat1);
-     XAACacheInfoPtr(*CacheColor8x8Pattern) (ScrnInfoPtr Scrn, PixmapPtr pPix,
-                                             int fg, int bg);
-
-    int MonoPatternPitch;
-    int CacheWidthMono8x8Pattern;
-    int CacheHeightMono8x8Pattern;
-
-    int ColorPatternPitch;
-    int CacheWidthColor8x8Pattern;
-    int CacheHeightColor8x8Pattern;
-
-    int CacheColorExpandDensity;
-
-    void (*WriteBitmapToCache) (ScrnInfoPtr pScrn,
-                                int x, int y, int w, int h,
-                                unsigned char *src,
-                                int srcwidth, int fg, int bg);
-    void (*WritePixmapToCache) (ScrnInfoPtr pScrn,
-                                int x, int y, int w, int h,
-                                unsigned char *src,
-                                int srcwidth, int bpp, int depth);
-    void (*WriteMono8x8PatternToCache) (ScrnInfoPtr pScrn,
-                                        XAACacheInfoPtr pCache);
-    void (*WriteColor8x8PatternToCache) (ScrnInfoPtr pScrn,
-                                         PixmapPtr pPix,
-                                         XAACacheInfoPtr pCache);
-
-    char *PixmapCachePrivate;
-
-    /* Miscellaneous */
-
-    GC ScratchGC;
-    int PreAllocSize;
-    unsigned char *PreAllocMem;
-
-    CharInfoPtr CharInfo[255];
-    NonTEGlyphInfo GlyphInfo[255];
-
-    unsigned int FullPlanemask; /* deprecated */
-
-    PixmapLinkPtr OffscreenPixmaps;
-    int maxOffPixWidth;
-    int maxOffPixHeight;
-
-    XAACacheInfoRec ScratchCacheInfoRec;
-
-    BoxPtr ClipBox;
-
-    Bool NeedToSync;
-
-    char *dgaSaves;
-
-    /* These can be supplied to override the defaults */
-
-    GetImageProcPtr GetImage;
-    GetSpansProcPtr GetSpans;
-    CopyWindowProcPtr CopyWindow;
-
-    unsigned int offscreenDepths;
-    Bool offscreenDepthsInitialized;
-
-    CARD32 FullPlanemasks[32];
-
-    Bool (*Composite) (CARD8 op,
-                       PicturePtr pSrc,
-                       PicturePtr pMask,
-                       PicturePtr pDst,
-                       INT16 xSrc,
-                       INT16 ySrc,
-                       INT16 xMask,
-                       INT16 yMask,
-                       INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
-
-    Bool (*Glyphs) (CARD8 op,
-                    PicturePtr pSrc,
-                    PicturePtr pDst,
-                    PictFormatPtr maskFormat,
-                    INT16 xSrc,
-                    INT16 ySrc,
-                    int nlist, GlyphListPtr list, GlyphPtr * glyphs);
-
-    /* The old SetupForCPUToScreenAlphaTexture function is no longer used because
-     * it doesn't pass in enough information to write a conforming
-     * implementation.  See SetupForCPUToScreenAlphaTexture2.
-     */
-    Bool (*SetupForCPUToScreenAlphaTexture) (ScrnInfoPtr pScrn,
-                                             int op,
-                                             CARD16 red,
-                                             CARD16 green,
-                                             CARD16 blue,
-                                             CARD16 alpha,
-                                             int alphaType,
-                                             CARD8 *alphaPtr,
-                                             int alphaPitch,
-                                             int width, int height, int flags);
-    void (*SubsequentCPUToScreenAlphaTexture) (ScrnInfoPtr pScrn,
-                                               int dstx,
-                                               int dsty,
-                                               int srcx,
-                                               int srcy, int width, int height);
-    int CPUToScreenAlphaTextureFlags;
-    CARD32 *CPUToScreenAlphaTextureFormats;
-
-    /* The old SetupForCPUToScreenTexture function is no longer used because
-     * it doesn't pass in enough information to write a conforming
-     * implementation.  See SetupForCPUToScreenTexture2.
-     */
-    Bool (*SetupForCPUToScreenTexture) (ScrnInfoPtr pScrn,
-                                        int op,
-                                        int texType,
-                                        CARD8 *texPtr,
-                                        int texPitch,
-                                        int width, int height, int flags);
-    void (*SubsequentCPUToScreenTexture) (ScrnInfoPtr pScrn,
-                                          int dstx,
-                                          int dsty,
-                                          int srcx,
-                                          int srcy, int width, int height);
-    int CPUToScreenTextureFlags;
-    CARD32 *CPUToScreenTextureFormats;
-
-    /* these were added for 4.3.0 */
-    BoxRec SolidLineLimits;
-    BoxRec DashedLineLimits;
-
-    /* These were added for X.Org 6.8.0 */
-    Bool (*SetupForCPUToScreenAlphaTexture2) (ScrnInfoPtr pScrn,
-                                              int op,
-                                              CARD16 red,
-                                              CARD16 green,
-                                              CARD16 blue,
-                                              CARD16 alpha,
-                                              CARD32 maskFormat,
-                                              CARD32 dstFormat,
-                                              CARD8 *alphaPtr,
-                                              int alphaPitch,
-                                              int width, int height, int flags);
-    CARD32 *CPUToScreenAlphaTextureDstFormats;
-
-    Bool (*SetupForCPUToScreenTexture2) (ScrnInfoPtr pScrn,
-                                         int op,
-                                         CARD32 srcFormat,
-                                         CARD32 dstFormat,
-                                         CARD8 *texPtr,
-                                         int texPitch,
-                                         int width, int height, int flags);
-    CARD32 *CPUToScreenTextureDstFormats;
-} XAAInfoRec, *XAAInfoRecPtr;
-
-#define SET_SYNC_FLAG(infoRec)	(infoRec)->NeedToSync = TRUE
-
-extern _X_EXPORT Bool
- XAAInit(ScreenPtr pScreen, XAAInfoRecPtr infoRec);
-
-extern _X_EXPORT XAAInfoRecPtr XAACreateInfoRec(void);
-
-extern _X_EXPORT void
- XAADestroyInfoRec(XAAInfoRecPtr infoRec);
-
-typedef void (*DepthChangeFuncPtr) (ScrnInfoPtr pScrn, int depth);
-
-extern _X_EXPORT Bool
- XAAInitDualFramebufferOverlay(ScreenPtr pScreen, DepthChangeFuncPtr callback);
-
-#endif                          /* _XAA_H */
diff --git a/hw/xfree86/xaa/xaaBitBlt.c b/hw/xfree86/xaa/xaaBitBlt.c
deleted file mode 100644
index c1595c4..0000000
--- a/hw/xfree86/xaa/xaaBitBlt.c
+++ /dev/null
@@ -1,229 +0,0 @@
-
-/* 
-   This is a lighter version of cfbBitBlt.  We calculate the boxes
-   when accelerating pixmap->screen and screen->screen copies. 
-   We also pass the GC to the doBitBlt function so that it has access
-   to the fg and bg so CopyPlane can use this. 
-*/
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "mi.h"
-#include "pixmapstr.h"
-#include "gcstruct.h"
-#include "windowstr.h"
-#include "xaalocal.h"
-
-RegionPtr
-XAABitBlt(DrawablePtr pSrcDrawable,
-          DrawablePtr pDstDrawable,
-          GC * pGC,
-          int srcx, int srcy,
-          int width, int height,
-          int dstx, int dsty,
-          void (*doBitBlt) (DrawablePtr, DrawablePtr, GCPtr, RegionPtr,
-                            DDXPointPtr), unsigned long bitPlane)
-{
-
-    RegionPtr prgnSrcClip = NULL;       /* may be a new region, or just a copy */
-    RegionPtr prgnExposed;
-    Bool freeSrcClip = FALSE;
-    RegionRec rgnDst;
-    DDXPointPtr pptSrc, ppt;
-    DDXPointRec origDest;
-    BoxPtr pbox;
-    BoxRec fastBox;
-    int i, dx, dy, numRects;
-    xRectangle origSource;
-    int fastClip = 0;           /* for fast clipping with pixmap source */
-    int fastExpose = 0;         /* for fast exposures with pixmap source */
-
-    origSource.x = srcx;
-    origSource.y = srcy;
-    origSource.width = width;
-    origSource.height = height;
-    origDest.x = dstx;
-    origDest.y = dsty;
-
-    if (pSrcDrawable->pScreen->SourceValidate) {
-        (*pSrcDrawable->pScreen->SourceValidate) (pSrcDrawable, srcx, srcy,
-                                                  width, height,
-                                                  pGC->subWindowMode);
-    }
-
-    srcx += pSrcDrawable->x;
-    srcy += pSrcDrawable->y;
-
-    /* clip the source */
-    if (pSrcDrawable->type == DRAWABLE_PIXMAP) {
-        if ((pSrcDrawable == pDstDrawable) && (pGC->clientClipType == CT_NONE))
-            prgnSrcClip = pGC->pCompositeClip;
-        else
-            fastClip = 1;
-    }
-    else {                      /* Window */
-        if (pGC->subWindowMode == IncludeInferiors) {
-            if (!((WindowPtr) pSrcDrawable)->parent) {
-                /*
-                 * special case bitblt from root window in
-                 * IncludeInferiors mode; just like from a pixmap
-                 */
-                fastClip = 1;
-            }
-            else if ((pSrcDrawable == pDstDrawable) &&
-                     (pGC->clientClipType == CT_NONE)) {
-                prgnSrcClip = pGC->pCompositeClip;
-            }
-            else {
-                prgnSrcClip = NotClippedByChildren((WindowPtr) pSrcDrawable);
-                freeSrcClip = TRUE;
-            }
-        }
-        else {
-            prgnSrcClip = &((WindowPtr) pSrcDrawable)->clipList;
-        }
-    }
-
-    fastBox.x1 = srcx;
-    fastBox.y1 = srcy;
-    fastBox.x2 = srcx + width;
-    fastBox.y2 = srcy + height;
-
-    /* Don't create a source region if we are doing a fast clip */
-    if (fastClip) {
-        fastExpose = 1;
-        /*
-         * clip the source; if regions extend beyond the source size,
-         * make sure exposure events get sent
-         */
-        if (fastBox.x1 < pSrcDrawable->x) {
-            fastBox.x1 = pSrcDrawable->x;
-            fastExpose = 0;
-        }
-        if (fastBox.y1 < pSrcDrawable->y) {
-            fastBox.y1 = pSrcDrawable->y;
-            fastExpose = 0;
-        }
-        if (fastBox.x2 > pSrcDrawable->x + (int) pSrcDrawable->width) {
-            fastBox.x2 = pSrcDrawable->x + (int) pSrcDrawable->width;
-            fastExpose = 0;
-        }
-        if (fastBox.y2 > pSrcDrawable->y + (int) pSrcDrawable->height) {
-            fastBox.y2 = pSrcDrawable->y + (int) pSrcDrawable->height;
-            fastExpose = 0;
-        }
-    }
-    else {
-        RegionInit(&rgnDst, &fastBox, 1);
-        RegionIntersect(&rgnDst, &rgnDst, prgnSrcClip);
-    }
-
-    dstx += pDstDrawable->x;
-    dsty += pDstDrawable->y;
-
-    if (pDstDrawable->type == DRAWABLE_WINDOW) {
-        if (!((WindowPtr) pDstDrawable)->realized) {
-            if (!fastClip)
-                RegionUninit(&rgnDst);
-            if (freeSrcClip)
-                RegionDestroy(prgnSrcClip);
-            return NULL;
-        }
-    }
-
-    dx = srcx - dstx;
-    dy = srcy - dsty;
-
-    /* Translate and clip the dst to the destination composite clip */
-    if (fastClip) {
-        RegionPtr cclip;
-
-        /* Translate the region directly */
-        fastBox.x1 -= dx;
-        fastBox.x2 -= dx;
-        fastBox.y1 -= dy;
-        fastBox.y2 -= dy;
-
-        /* If the destination composite clip is one rectangle we can
-           do the clip directly.  Otherwise we have to create a full
-           blown region and call intersect */
-
-        cclip = pGC->pCompositeClip;
-        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;
-            if (fastBox.y1 < pBox->y1)
-                fastBox.y1 = pBox->y1;
-            if (fastBox.y2 > pBox->y2)
-                fastBox.y2 = pBox->y2;
-
-            /* Check to see if the region is empty */
-            if (fastBox.x1 >= fastBox.x2 || fastBox.y1 >= fastBox.y2) {
-                RegionNull(&rgnDst);
-            }
-            else {
-                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;
-            RegionInit(&rgnDst, &fastBox, 1);
-        }
-    }
-    else {
-        RegionTranslate(&rgnDst, -dx, -dy);
-    }
-
-    if (!fastClip) {
-        RegionIntersect(&rgnDst, &rgnDst, pGC->pCompositeClip);
-    }
-
-    /* Do bit blitting */
-    numRects = RegionNumRects(&rgnDst);
-    if (numRects && width && height) {
-        if (!(pptSrc = (DDXPointPtr) malloc(numRects * sizeof(DDXPointRec)))) {
-            RegionUninit(&rgnDst);
-            if (freeSrcClip)
-                RegionDestroy(prgnSrcClip);
-            return NULL;
-        }
-        pbox = RegionRects(&rgnDst);
-        ppt = pptSrc;
-        for (i = numRects; --i >= 0; pbox++, ppt++) {
-            ppt->x = pbox->x1 + dx;
-            ppt->y = pbox->y1 + dy;
-        }
-
-        (*doBitBlt) (pSrcDrawable, pDstDrawable, pGC, &rgnDst, pptSrc);
-        free(pptSrc);
-    }
-
-    prgnExposed = NULL;
-    if (pGC->fExpose) {
-        /* Pixmap sources generate a NoExposed (we return NULL to do this) */
-        if (!fastExpose)
-            prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC,
-                                            origSource.x, origSource.y,
-                                            (int) origSource.width,
-                                            (int) origSource.height,
-                                            origDest.x, origDest.y, bitPlane);
-    }
-    RegionUninit(&rgnDst);
-    if (freeSrcClip)
-        RegionDestroy(prgnSrcClip);
-    return prgnExposed;
-}
diff --git a/hw/xfree86/xaa/xaaBitOrder.c b/hw/xfree86/xaa/xaaBitOrder.c
deleted file mode 100644
index 3d9b980..0000000
--- a/hw/xfree86/xaa/xaaBitOrder.c
+++ /dev/null
@@ -1,16 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/Xmd.h>
-#include "xaalocal.h"
-
-CARD32
-XAAReverseBitOrder(CARD32 v)
-{
-    return (((0x01010101 & v) << 7) | ((0x02020202 & v) << 5) |
-            ((0x04040404 & v) << 3) | ((0x08080808 & v) << 1) |
-            ((0x10101010 & v) >> 1) | ((0x20202020 & v) >> 3) |
-            ((0x40404040 & v) >> 5) | ((0x80808080 & v) >> 7));
-}
diff --git a/hw/xfree86/xaa/xaaBitmap.c b/hw/xfree86/xaa/xaaBitmap.c
deleted file mode 100644
index 45d5a09..0000000
--- a/hw/xfree86/xaa/xaaBitmap.c
+++ /dev/null
@@ -1,477 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaacexp.h"
-#include "xf86.h"
-
-/********** byte swapping ***************/
-
-#ifdef FIXEDBASE
-#define DEST(i)	*dest
-#define RETURN(i)	return(dest)
-#else
-#define DEST(i)	dest[i]
-#define RETURN(i)	return(dest + i)
-#endif
-
-#ifdef MSBFIRST
-#define SOURCE(i)	SWAP_BITS_IN_BYTES(src[i])
-#else
-#define SOURCE(i)	src[i]
-#endif
-
-typedef CARD32 *(*BitmapScanlineProcPtr) (CARD32 *, CARD32 *, int, int);
-
-#ifdef TRIPLE_BITS
-static CARD32 *
-BitmapScanline(CARD32 *src, CARD32 *base, int count, int skipleft)
-{
-    CARD32 bits;
-
-    while (count >= 3) {
-        bits = *src;
-        WRITE_BITS3(bits);
-        src++;
-        count -= 3;
-    }
-    if (count == 2) {
-        bits = *src;
-        WRITE_BITS2(bits);
-    }
-    else if (count == 1) {
-        bits = *src;
-        WRITE_BITS1(bits);
-    }
-
-    return base;
-}
-
-static CARD32 *
-BitmapScanline_Inverted(CARD32 *src, CARD32 *base, int count, int skipleft)
-{
-    CARD32 bits;
-
-    while (count >= 3) {
-        bits = ~(*src);
-        WRITE_BITS3(bits);
-        src++;
-        count -= 3;
-    }
-    if (count == 2) {
-        bits = ~(*src);
-        WRITE_BITS2(bits);
-    }
-    else if (count == 1) {
-        bits = ~(*src);
-        WRITE_BITS1(bits);
-    }
-
-    return base;
-}
-
-static CARD32 *
-BitmapScanline_Shifted(CARD32 *src, CARD32 *base, int count, int skipleft)
-{
-    CARD32 bits;
-
-    while (count >= 3) {
-        bits = SHIFT_R(*src, skipleft) | SHIFT_L(*(src + 1), (32 - skipleft));
-        WRITE_BITS3(bits);
-        src++;
-        count -= 3;
-    }
-    if (count == 2) {
-        bits = SHIFT_R(*src, skipleft) | SHIFT_L(*(src + 1), (32 - skipleft));
-        WRITE_BITS2(bits);
-    }
-    else if (count == 1) {
-        bits = SHIFT_R(*src, skipleft) | SHIFT_L(*(src + 1), (32 - skipleft));
-        WRITE_BITS1(bits);
-    }
-
-    return base;
-}
-
-static CARD32 *
-BitmapScanline_Shifted_Inverted(CARD32 *src, CARD32 *base,
-                                int count, int skipleft)
-{
-    CARD32 bits;
-
-    while (count >= 3) {
-        bits =
-            ~(SHIFT_R(*src, skipleft) | SHIFT_L(*(src + 1), (32 - skipleft)));
-        WRITE_BITS3(bits);
-        src++;
-        count -= 3;
-    }
-    if (count == 2) {
-        bits =
-            ~(SHIFT_R(*src, skipleft) | SHIFT_L(*(src + 1), (32 - skipleft)));
-        WRITE_BITS2(bits);
-    }
-    else if (count == 1) {
-        bits =
-            ~(SHIFT_R(*src, skipleft) | SHIFT_L(*(src + 1), (32 - skipleft)));
-        WRITE_BITS1(bits);
-    }
-
-    return base;
-}
-
-#define BitmapScanline_Shifted_Careful BitmapScanline_Shifted
-#define BitmapScanline_Shifted_Inverted_Careful BitmapScanline_Shifted_Inverted
-
-#else
-static CARD32 *
-BitmapScanline(CARD32 *src, CARD32 *dest, int count, int skipleft)
-{
-    while (count >= 4) {
-        DEST(0) = SOURCE(0);
-        DEST(1) = SOURCE(1);
-        DEST(2) = SOURCE(2);
-        DEST(3) = SOURCE(3);
-        count -= 4;
-        src += 4;
-#ifndef FIXEDBASE
-        dest += 4;
-#endif
-    }
-
-    if (!count)
-        return dest;
-    DEST(0) = SOURCE(0);
-    if (count == 1)
-        RETURN(1);
-    DEST(1) = SOURCE(1);
-    if (count == 2)
-        RETURN(2);
-    DEST(2) = SOURCE(2);
-    RETURN(3);
-}
-
-static CARD32 *
-BitmapScanline_Inverted(CARD32 *src, CARD32 *dest, int count, int skipleft)
-{
-    while (count >= 4) {
-        DEST(0) = ~SOURCE(0);
-        DEST(1) = ~SOURCE(1);
-        DEST(2) = ~SOURCE(2);
-        DEST(3) = ~SOURCE(3);
-        count -= 4;
-        src += 4;
-#ifndef FIXEDBASE
-        dest += 4;
-#endif
-    }
-
-    if (!count)
-        return dest;
-    DEST(0) = ~SOURCE(0);
-    if (count == 1)
-        RETURN(1);
-    DEST(1) = ~SOURCE(1);
-    if (count == 2)
-        RETURN(2);
-    DEST(2) = ~SOURCE(2);
-    RETURN(3);
-}
-
-static CARD32 *
-BitmapScanline_Shifted(CARD32 *bits, CARD32 *base, int count, int skipleft)
-{
-    while (count--) {
-        register CARD32 tmp = SHIFT_R(*bits, skipleft) |
-            SHIFT_L(*(bits + 1), (32 - skipleft));
-        WRITE_BITS(tmp);
-        bits++;
-    }
-    return base;
-}
-
-static CARD32 *
-BitmapScanline_Shifted_Inverted(CARD32 *bits, CARD32 *base,
-                                int count, int skipleft)
-{
-    while (count--) {
-        register CARD32 tmp = ~(SHIFT_R(*bits, skipleft) |
-                                SHIFT_L(*(bits + 1), (32 - skipleft)));
-        WRITE_BITS(tmp);
-        bits++;
-    }
-    return base;
-}
-
-static CARD32 *
-BitmapScanline_Shifted_Careful(CARD32 *bits, CARD32 *base,
-                               int count, int skipleft)
-{
-    register CARD32 tmp;
-
-    while (--count) {
-        tmp = SHIFT_R(*bits, skipleft) | SHIFT_L(*(bits + 1), (32 - skipleft));
-        WRITE_BITS(tmp);
-        bits++;
-    }
-    tmp = SHIFT_R(*bits, skipleft);
-    WRITE_BITS(tmp);
-
-    return base;
-}
-
-static CARD32 *
-BitmapScanline_Shifted_Inverted_Careful(CARD32 *bits, CARD32 *base,
-                                        int count, int skipleft)
-{
-    register CARD32 tmp;
-
-    while (--count) {
-        tmp =
-            ~(SHIFT_R(*bits, skipleft) | SHIFT_L(*(bits + 1), (32 - skipleft)));
-        WRITE_BITS(tmp);
-        bits++;
-    }
-    tmp = ~(SHIFT_R(*bits, skipleft));
-    WRITE_BITS(tmp);
-    return base;
-}
-
-#endif
-
-/*  
-    When the accelerator is TRANSPARENCY_ONLY, WriteBitmap can do
-    the fill in two passes, inverting the source on the second pass.  
-    For GXcopy we can fill the backing rectangle as a solid rect and
-    avoid the invert.
-*/
-
-void
-#ifdef TRIPLE_BITS
- EXPNAME(XAAWriteBitmapColorExpand3) (
-#else
- EXPNAME(XAAWriteBitmapColorExpand) (
-#endif
-                                        ScrnInfoPtr pScrn,
-                                        int x, int y, int w, int H,
-                                        unsigned char *src,
-                                        int srcwidth,
-                                        int skipleft,
-                                        int fg, int bg,
-                                        int rop, unsigned int planemask) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *base;
-    unsigned char *srcp = src;
-    int SecondPassColor = -1;
-    int shift = 0, dwords;
-    BitmapScanlineProcPtr firstFunc;
-    BitmapScanlineProcPtr secondFunc;
-    int flag;
-    int h = H;
-
-#ifdef TRIPLE_BITS
-    if ((bg != -1) &&
-        ((infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY) ||
-         ((infoRec->CPUToScreenColorExpandFillFlags & RGB_EQUAL) &&
-          (!CHECK_RGB_EQUAL(bg))))) {
-#else
-    if ((bg != -1) &&
-        (infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
-#endif
-        if ((rop == GXcopy) && infoRec->SetupForSolidFill) {
-            (*infoRec->SetupForSolidFill) (pScrn, bg, rop, planemask);
-            (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, w, h);
-        }
-        else
-            SecondPassColor = bg;
-        bg = -1;
-    }
-
-#ifdef TRIPLE_BITS
-    if (skipleft) {
-#else
-    if (skipleft &&
-        (!(infoRec->CPUToScreenColorExpandFillFlags & LEFT_EDGE_CLIPPING) ||
-         (!(infoRec->
-            CPUToScreenColorExpandFillFlags & LEFT_EDGE_CLIPPING_NEGATIVE_X) &&
-          (skipleft > x)))) {
-#endif
-        if ((skipleft + ((w + 31) & ~31)) > ((skipleft + w + 31) & ~31)) {
-            /* don't read past the end */
-            firstFunc = BitmapScanline_Shifted_Careful;
-            secondFunc = BitmapScanline_Shifted_Inverted_Careful;
-        }
-        else {
-            firstFunc = BitmapScanline_Shifted;
-            secondFunc = BitmapScanline_Shifted_Inverted;
-        }
-        shift = skipleft;
-        skipleft = 0;
-    }
-    else {
-        firstFunc = BitmapScanline;
-        secondFunc = BitmapScanline_Inverted;
-        w += skipleft;
-        x -= skipleft;
-    }
-
-#ifdef TRIPLE_BITS
-    dwords = (3 * w + 31) >> 5;
-#else
-    dwords = (w + 31) >> 5;
-#endif
-
- SECOND_PASS:
-
-    flag = (infoRec->CPUToScreenColorExpandFillFlags
-            & CPU_TRANSFER_PAD_QWORD) && ((dwords * h) & 0x01);
-    (*infoRec->SetupForCPUToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                    planemask);
-    (*infoRec->SubsequentCPUToScreenColorExpandFill) (pScrn, x, y, w, h,
-                                                      skipleft);
-
-    base = (CARD32 *) infoRec->ColorExpandBase;
-
-#ifndef FIXEDBASE
-    if ((dwords * h) <= infoRec->ColorExpandRange)
-        while (h--) {
-            base = (*firstFunc) ((CARD32 *) srcp, base, dwords, shift);
-            srcp += srcwidth;
-        }
-    else
-#endif
-        while (h--) {
-            (*firstFunc) ((CARD32 *) srcp, base, dwords, shift);
-            srcp += srcwidth;
-        }
-
-    if (flag) {
-        base = (CARD32 *) infoRec->ColorExpandBase;
-        base[0] = 0x00000000;
-    }
-
-    if (SecondPassColor != -1) {
-        h = H;                  /* Reset height */
-        fg = SecondPassColor;
-        SecondPassColor = -1;
-        firstFunc = secondFunc;
-        srcp = src;
-        goto SECOND_PASS;
-    }
-
-    if (infoRec->CPUToScreenColorExpandFillFlags & SYNC_AFTER_COLOR_EXPAND)
-        (*infoRec->Sync) (pScrn);
-    else
-        SET_SYNC_FLAG(infoRec);
-}
-
-#ifndef FIXEDBASE
-
-void
-#ifdef TRIPLE_BITS
- EXPNAME(XAAWriteBitmapScanlineColorExpand3) (
-#else
- EXPNAME(XAAWriteBitmapScanlineColorExpand) (
-#endif
-                                                ScrnInfoPtr pScrn,
-                                                int x, int y, int w, int h,
-                                                unsigned char *src,
-                                                int srcwidth,
-                                                int skipleft,
-                                                int fg, int bg,
-                                                int rop,
-                                                unsigned int planemask) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *base;
-    unsigned char *srcp = src;
-    int SecondPassColor = -1;
-    int shift = 0, dwords, bufferNo;
-    BitmapScanlineProcPtr firstFunc;
-    BitmapScanlineProcPtr secondFunc;
-
-#ifdef TRIPLE_BITS
-    if ((bg != -1) &&
-        ((infoRec->ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)
-         || ((infoRec->ScanlineCPUToScreenColorExpandFillFlags & RGB_EQUAL) &&
-             (!CHECK_RGB_EQUAL(bg))))) {
-#else
-    if ((bg != -1) &&
-        (infoRec->
-         ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
-#endif
-        if ((rop == GXcopy) && infoRec->SetupForSolidFill) {
-            (*infoRec->SetupForSolidFill) (pScrn, bg, rop, planemask);
-            (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, w, h);
-        }
-        else
-            SecondPassColor = bg;
-        bg = -1;
-    }
-
-#ifdef TRIPLE_BITS
-    if (skipleft) {
-#else
-    if (skipleft &&
-        (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-           LEFT_EDGE_CLIPPING) ||
-         (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-            LEFT_EDGE_CLIPPING_NEGATIVE_X) && (skipleft > x)))) {
-#endif
-        if ((skipleft + ((w + 31) & ~31)) > ((skipleft + w + 31) & ~31)) {
-            /* don't read past the end */
-            firstFunc = BitmapScanline_Shifted_Careful;
-            secondFunc = BitmapScanline_Shifted_Inverted_Careful;
-        }
-        else {
-            firstFunc = BitmapScanline_Shifted;
-            secondFunc = BitmapScanline_Shifted_Inverted;
-        }
-        shift = skipleft;
-        skipleft = 0;
-    }
-    else {
-        firstFunc = BitmapScanline;
-        secondFunc = BitmapScanline_Inverted;
-        w += skipleft;
-        x -= skipleft;
-    }
-
-#ifdef TRIPLE_BITS
-    dwords = (3 * w + 31) >> 5;
-#else
-    dwords = (w + 31) >> 5;
-#endif
-
- SECOND_PASS:
-
-    (*infoRec->SetupForScanlineCPUToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                            planemask);
-    (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill) (pScrn, x, y, w, h,
-                                                              skipleft);
-
-    bufferNo = 0;
-
-    while (h--) {
-        base = (CARD32 *) infoRec->ScanlineColorExpandBuffers[bufferNo];
-        (*firstFunc) ((CARD32 *) srcp, base, dwords, shift);
-        (*infoRec->SubsequentColorExpandScanline) (pScrn, bufferNo++);
-        srcp += srcwidth;
-        if (bufferNo >= infoRec->NumScanlineColorExpandBuffers)
-            bufferNo = 0;
-    }
-
-    if (SecondPassColor != -1) {
-        fg = SecondPassColor;
-        SecondPassColor = -1;
-        firstFunc = secondFunc;
-        srcp = src;
-        goto SECOND_PASS;
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-#endif
diff --git a/hw/xfree86/xaa/xaaCpyArea.c b/hw/xfree86/xaa/xaaCpyArea.c
deleted file mode 100644
index 0b11b81..0000000
--- a/hw/xfree86/xaa/xaaCpyArea.c
+++ /dev/null
@@ -1,409 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "migc.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-
-/*
-  Written mostly by Harm Hanemaayer (H.Hanemaayer at inter.nl.net).
- */
-
-RegionPtr
-XAACopyArea(DrawablePtr pSrcDrawable,
-            DrawablePtr pDstDrawable,
-            GC * pGC,
-            int srcx, int srcy, int width, int height, int dstx, int dsty)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (pDstDrawable->type == DRAWABLE_WINDOW) {
-        if ((pSrcDrawable->type == DRAWABLE_WINDOW) ||
-            IS_OFFSCREEN_PIXMAP(pSrcDrawable)) {
-            if (infoRec->ScreenToScreenBitBlt &&
-                CHECK_ROP(pGC, infoRec->ScreenToScreenBitBltFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->ScreenToScreenBitBltFlags) &&
-                CHECK_PLANEMASK(pGC, infoRec->ScreenToScreenBitBltFlags))
-                return (XAABitBlt(pSrcDrawable, pDstDrawable,
-                                  pGC, srcx, srcy, width, height, dstx, dsty,
-                                  XAADoBitBlt, 0L));
-        }
-        else {
-            if (infoRec->WritePixmap &&
-                ((pDstDrawable->bitsPerPixel == pSrcDrawable->bitsPerPixel) ||
-                 ((pDstDrawable->bitsPerPixel == 24) &&
-                  (pSrcDrawable->bitsPerPixel == 32) &&
-                  (infoRec->WritePixmapFlags & CONVERT_32BPP_TO_24BPP))) &&
-                CHECK_ROP(pGC, infoRec->WritePixmapFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->WritePixmapFlags) &&
-                CHECK_PLANEMASK(pGC, infoRec->WritePixmapFlags) &&
-                CHECK_NO_GXCOPY(pGC, infoRec->WritePixmapFlags))
-                return (XAABitBlt(pSrcDrawable, pDstDrawable,
-                                  pGC, srcx, srcy, width, height, dstx, dsty,
-                                  XAADoImageWrite, 0L));
-        }
-    }
-    else if (IS_OFFSCREEN_PIXMAP(pDstDrawable)) {
-        if ((pSrcDrawable->type == DRAWABLE_WINDOW) ||
-            IS_OFFSCREEN_PIXMAP(pSrcDrawable)) {
-            if (infoRec->ScreenToScreenBitBlt &&
-                CHECK_ROP(pGC, infoRec->ScreenToScreenBitBltFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->ScreenToScreenBitBltFlags) &&
-                CHECK_PLANEMASK(pGC, infoRec->ScreenToScreenBitBltFlags))
-                return (XAABitBlt(pSrcDrawable, pDstDrawable,
-                                  pGC, srcx, srcy, width, height, dstx, dsty,
-                                  XAADoBitBlt, 0L));
-        }
-    }
-
-    return (XAAFallbackOps.CopyArea(pSrcDrawable, pDstDrawable, pGC,
-                                    srcx, srcy, width, height, dstx, dsty));
-}
-
-void
-XAADoBitBlt(DrawablePtr pSrc,
-            DrawablePtr pDst, GC * pGC, RegionPtr prgnDst, DDXPointPtr pptSrc)
-{
-    int nbox, careful;
-    BoxPtr pbox, pboxTmp, pboxNext, pboxBase, pboxNew1, pboxNew2;
-    DDXPointPtr pptTmp, pptNew1, pptNew2;
-    int xdir, ydir;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    /* XXX we have to err on the side of safety when both are windows,
-     * because we don't know if IncludeInferiors is being used.
-     */
-    careful = ((pSrc == pDst) ||
-               ((pSrc->type == DRAWABLE_WINDOW) &&
-                (pDst->type == DRAWABLE_WINDOW)));
-
-    pbox = RegionRects(prgnDst);
-    nbox = RegionNumRects(prgnDst);
-
-    pboxNew1 = NULL;
-    pptNew1 = NULL;
-    pboxNew2 = NULL;
-    pptNew2 = NULL;
-    if (careful && (pptSrc->y < pbox->y1)) {
-        /* walk source botttom to top */
-        ydir = -1;
-
-        if (nbox > 1) {
-            /* keep ordering in each band, reverse order of bands */
-            pboxNew1 = (BoxPtr) malloc(sizeof(BoxRec) * nbox);
-            if (!pboxNew1)
-                return;
-            pptNew1 = (DDXPointPtr) malloc(sizeof(DDXPointRec) * nbox);
-            if (!pptNew1) {
-                free(pboxNew1);
-                return;
-            }
-            pboxBase = pboxNext = pbox + nbox - 1;
-            while (pboxBase >= pbox) {
-                while ((pboxNext >= pbox) && (pboxBase->y1 == pboxNext->y1))
-                    pboxNext--;
-                pboxTmp = pboxNext + 1;
-                pptTmp = pptSrc + (pboxTmp - pbox);
-                while (pboxTmp <= pboxBase) {
-                    *pboxNew1++ = *pboxTmp++;
-                    *pptNew1++ = *pptTmp++;
-                }
-                pboxBase = pboxNext;
-            }
-            pboxNew1 -= nbox;
-            pbox = pboxNew1;
-            pptNew1 -= nbox;
-            pptSrc = pptNew1;
-        }
-    }
-    else {
-        /* walk source top to bottom */
-        ydir = 1;
-    }
-
-    if (careful && (pptSrc->x < pbox->x1)) {
-        /* walk source right to left */
-        xdir = -1;
-
-        if (nbox > 1) {
-            /* reverse order of rects in each band */
-            pboxNew2 = (BoxPtr) malloc(sizeof(BoxRec) * nbox);
-            pptNew2 = (DDXPointPtr) malloc(sizeof(DDXPointRec) * nbox);
-            if (!pboxNew2 || !pptNew2) {
-                free(pptNew2);
-                free(pboxNew2);
-                if (pboxNew1) {
-                    free(pptNew1);
-                    free(pboxNew1);
-                }
-                return;
-            }
-            pboxBase = pboxNext = pbox;
-            while (pboxBase < pbox + nbox) {
-                while ((pboxNext < pbox + nbox) &&
-                       (pboxNext->y1 == pboxBase->y1))
-                    pboxNext++;
-                pboxTmp = pboxNext;
-                pptTmp = pptSrc + (pboxTmp - pbox);
-                while (pboxTmp != pboxBase) {
-                    *pboxNew2++ = *--pboxTmp;
-                    *pptNew2++ = *--pptTmp;
-                }
-                pboxBase = pboxNext;
-            }
-            pboxNew2 -= nbox;
-            pbox = pboxNew2;
-            pptNew2 -= nbox;
-            pptSrc = pptNew2;
-        }
-    }
-    else {
-        /* walk source left to right */
-        xdir = 1;
-    }
-
-    (*infoRec->ScreenToScreenBitBlt) (infoRec->pScrn, nbox, pptSrc, pbox,
-                                      xdir, ydir, pGC->alu, pGC->planemask);
-
-    if (pboxNew2) {
-        free(pptNew2);
-        free(pboxNew2);
-    }
-    if (pboxNew1) {
-        free(pptNew1);
-        free(pboxNew1);
-    }
-
-}
-
-void
-XAADoImageWrite(DrawablePtr pSrc,
-                DrawablePtr pDst,
-                GC * pGC, RegionPtr prgnDst, DDXPointPtr pptSrc)
-{
-    int srcwidth;
-    unsigned char *psrcBase;    /* start of image */
-    unsigned char *srcPntr;     /* index into the image */
-    BoxPtr pbox = RegionRects(prgnDst);
-    int nbox = RegionNumRects(prgnDst);
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int Bpp = pSrc->bitsPerPixel >> 3;
-
-    psrcBase = (unsigned char *) ((PixmapPtr) pSrc)->devPrivate.ptr;
-    srcwidth = (int) ((PixmapPtr) pSrc)->devKind;
-
-    for (; nbox; pbox++, pptSrc++, nbox--) {
-        srcPntr = psrcBase + (pptSrc->y * srcwidth) + (pptSrc->x * Bpp);
-
-        (*infoRec->WritePixmap) (infoRec->pScrn, pbox->x1, pbox->y1,
-                                 pbox->x2 - pbox->x1, pbox->y2 - pbox->y1,
-                                 srcPntr, srcwidth, pGC->alu, pGC->planemask,
-                                 -1, pSrc->bitsPerPixel, pSrc->depth);
-    }
-}
-
-void
-XAADoImageRead(DrawablePtr pSrc,
-               DrawablePtr pDst,
-               GC * pGC, RegionPtr prgnDst, DDXPointPtr pptSrc)
-{
-    int dstwidth;
-    unsigned char *pdstBase;    /* start of image */
-    unsigned char *dstPntr;     /* index into the image */
-    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 */
-
-    pdstBase = (unsigned char *) ((PixmapPtr) pDst)->devPrivate.ptr;
-    dstwidth = (int) ((PixmapPtr) pDst)->devKind;
-
-    for (; nbox; pbox++, pptSrc++, nbox--) {
-        dstPntr = pdstBase + (pbox->y1 * dstwidth) + (pbox->x1 * Bpp);
-
-        (*infoRec->ReadPixmap) (infoRec->pScrn, pptSrc->x, pptSrc->y,
-                                pbox->x2 - pbox->x1, pbox->y2 - pbox->y1,
-                                dstPntr, dstwidth, pSrc->bitsPerPixel,
-                                pSrc->depth);
-    }
-}
-
-void
-XAAScreenToScreenBitBlt(ScrnInfoPtr pScrn,
-                        int nbox,
-                        DDXPointPtr pptSrc,
-                        BoxPtr pbox,
-                        int xdir, int ydir, int alu, unsigned int planemask)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int dirsetup;
-
-    if ((!(infoRec->CopyAreaFlags & ONLY_TWO_BITBLT_DIRECTIONS)
-         || (xdir == ydir)) &&
-        (!(infoRec->CopyAreaFlags & ONLY_LEFT_TO_RIGHT_BITBLT)
-         || (xdir == 1))) {
-        (*infoRec->SetupForScreenToScreenCopy) (pScrn,
-                                                xdir, ydir, alu, planemask, -1);
-        for (; nbox; pbox++, pptSrc++, nbox--)
-            (*infoRec->SubsequentScreenToScreenCopy) (pScrn, pptSrc->x,
-                                                      pptSrc->y, pbox->x1,
-                                                      pbox->y1,
-                                                      pbox->x2 - pbox->x1,
-                                                      pbox->y2 - pbox->y1);
-        SET_SYNC_FLAG(infoRec);
-        return;
-    }
-
-    if (infoRec->CopyAreaFlags & ONLY_LEFT_TO_RIGHT_BITBLT) {
-        /*
-         * This is the case of a chip that only supports xdir = 1,
-         * with ydir = 1 or ydir = -1, but we have xdir = -1.
-         */
-        (*infoRec->SetupForScreenToScreenCopy) (pScrn,
-                                                1, ydir, alu, planemask, -1);
-        for (; nbox; pbox++, pptSrc++, nbox--)
-            if (pptSrc->y != pbox->y1 || pptSrc->x >= pbox->x1)
-                /* No problem. Do a xdir = 1 blit instead. */
-                (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                          pptSrc->x, pptSrc->y,
-                                                          pbox->x1, pbox->y1,
-                                                          pbox->x2 - pbox->x1,
-                                                          pbox->y2 - pbox->y1);
-            else {
-                /*
-                 * This is the difficult case. Needs striping into
-                 * non-overlapping horizontal chunks.
-                 */
-                int stripeWidth, w, fullStripes, extra, i;
-
-                stripeWidth = 16;
-                w = pbox->x2 - pbox->x1;
-                if (pbox->x1 - pptSrc->x < stripeWidth)
-                    stripeWidth = pbox->x1 - pptSrc->x;
-                fullStripes = w / stripeWidth;
-                extra = w % stripeWidth;
-
-                /* First, take care of the little bit on the far right */
-                if (extra)
-                    (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                              pptSrc->x +
-                                                              fullStripes *
-                                                              stripeWidth,
-                                                              pptSrc->y,
-                                                              pbox->x1 +
-                                                              fullStripes *
-                                                              stripeWidth,
-                                                              pbox->y1, extra,
-                                                              pbox->y2 -
-                                                              pbox->y1);
-
-                /* Now, take care of the rest of the blit */
-                for (i = fullStripes - 1; i >= 0; i--)
-                    (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                              pptSrc->x +
-                                                              i * stripeWidth,
-                                                              pptSrc->y,
-                                                              pbox->x1 +
-                                                              i * stripeWidth,
-                                                              pbox->y1,
-                                                              stripeWidth,
-                                                              pbox->y2 -
-                                                              pbox->y1);
-            }
-        SET_SYNC_FLAG(infoRec);
-        return;
-    }
-
-    /*
-     * Now the case of a chip that only supports xdir = ydir = 1 or
-     * xdir = ydir = -1, but we have xdir != ydir.
-     */
-    dirsetup = 0;               /* No direction set up yet. */
-    for (; nbox; pbox++, pptSrc++, nbox--) {
-        if (xdir == 1 && pptSrc->y != pbox->y1) {
-            /* Do a xdir = ydir = -1 blit instead. */
-            if (dirsetup != -1) {
-                (*infoRec->SetupForScreenToScreenCopy) (pScrn,
-                                                        -1, -1, alu, planemask,
-                                                        -1);
-                dirsetup = -1;
-            }
-            (*infoRec->SubsequentScreenToScreenCopy) (pScrn, pptSrc->x,
-                                                      pptSrc->y, pbox->x1,
-                                                      pbox->y1,
-                                                      pbox->x2 - pbox->x1,
-                                                      pbox->y2 - pbox->y1);
-        }
-        else if (xdir == -1 && pptSrc->y != pbox->y1) {
-            /* Do a xdir = ydir = 1 blit instead. */
-            if (dirsetup != 1) {
-                (*infoRec->SetupForScreenToScreenCopy) (pScrn,
-                                                        1, 1, alu, planemask,
-                                                        -1);
-                dirsetup = 1;
-            }
-            (*infoRec->SubsequentScreenToScreenCopy) (pScrn, pptSrc->x,
-                                                      pptSrc->y, pbox->x1,
-                                                      pbox->y1,
-                                                      pbox->x2 - pbox->x1,
-                                                      pbox->y2 - pbox->y1);
-        }
-        else if (xdir == 1) {
-            /*
-             * xdir = 1, ydir = -1.
-             * Perform line-by-line xdir = ydir = 1 blits, going up.
-             */
-            int i;
-
-            if (dirsetup != 1) {
-                (*infoRec->SetupForScreenToScreenCopy) (pScrn,
-                                                        1, 1, alu, planemask,
-                                                        -1);
-                dirsetup = 1;
-            }
-            for (i = pbox->y2 - pbox->y1 - 1; i >= 0; i--)
-                (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                          pptSrc->x,
-                                                          pptSrc->y + i,
-                                                          pbox->x1,
-                                                          pbox->y1 + i,
-                                                          pbox->x2 - pbox->x1,
-                                                          1);
-        }
-        else {
-            /*
-             * xdir = -1, ydir = 1.
-             * Perform line-by-line xdir = ydir = -1 blits, going down.
-             */
-            int i;
-
-            if (dirsetup != -1) {
-                (*infoRec->SetupForScreenToScreenCopy) (pScrn,
-                                                        -1, -1, alu, planemask,
-                                                        -1);
-                dirsetup = -1;
-            }
-            for (i = 0; i < pbox->y2 - pbox->y1; i++)
-                (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                          pptSrc->x,
-                                                          pptSrc->y + i,
-                                                          pbox->x1,
-                                                          pbox->y1 + i,
-                                                          pbox->x2 - pbox->x1,
-                                                          1);
-        }
-    }                           /* next box */
-    SET_SYNC_FLAG(infoRec);
-}
diff --git a/hw/xfree86/xaa/xaaCpyPlane.c b/hw/xfree86/xaa/xaaCpyPlane.c
deleted file mode 100644
index b9197e4..0000000
--- a/hw/xfree86/xaa/xaaCpyPlane.c
+++ /dev/null
@@ -1,204 +0,0 @@
-
-/*
-   A CopyPlane function that handles bitmap->screen copies and
-   sends anything else to the Fallback.
-
-   Also, a PushPixels for solid fill styles.
-
-   Written by Mark Vojkovich (markv at valinux.com)
-
-*/
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <string.h>
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include "servermd.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "mi.h"
-#include "pixmapstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaawrap.h"
-
-static void XAACopyPlane1toNColorExpand(DrawablePtr pSrc, DrawablePtr pDst,
-                                        GCPtr pGC, RegionPtr rgnDst,
-                                        DDXPointPtr pptSrc);
-static void XAACopyPlaneNtoNColorExpand(DrawablePtr pSrc, DrawablePtr pDst,
-                                        GCPtr pGC, RegionPtr rgnDst,
-                                        DDXPointPtr pptSrc);
-
-static unsigned long TmpBitPlane;
-
-RegionPtr
-XAACopyPlaneColorExpansion(DrawablePtr pSrc,
-                           DrawablePtr pDst,
-                           GCPtr pGC,
-                           int srcx, int srcy,
-                           int width, int height,
-                           int dstx, int dsty, unsigned long bitPlane)
-{
-    if ((pSrc->type == DRAWABLE_PIXMAP) && !XAA_DEPTH_BUG(pGC)) {
-        if (pSrc->bitsPerPixel == 1) {
-            return (XAABitBlt(pSrc, pDst, pGC, srcx, srcy,
-                              width, height, dstx, dsty,
-                              XAACopyPlane1toNColorExpand, bitPlane));
-        }
-        else if (bitPlane < (1 << pDst->depth)) {
-            TmpBitPlane = bitPlane;
-            return (XAABitBlt(pSrc, pDst, pGC, srcx, srcy,
-                              width, height, dstx, dsty,
-                              XAACopyPlaneNtoNColorExpand, bitPlane));
-        }
-    }
-
-    return (XAAFallbackOps.CopyPlane(pSrc, pDst, pGC, srcx, srcy,
-                                     width, height, dstx, dsty, bitPlane));
-}
-
-static void
-XAACopyPlane1toNColorExpand(DrawablePtr pSrc,
-                            DrawablePtr pDst,
-                            GCPtr pGC, RegionPtr rgnDst, DDXPointPtr pptSrc)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    BoxPtr pbox = RegionRects(rgnDst);
-    int numrects = RegionNumRects(rgnDst);
-    unsigned char *src = ((PixmapPtr) pSrc)->devPrivate.ptr;
-    int srcwidth = ((PixmapPtr) pSrc)->devKind;
-
-    while (numrects--) {
-        (*infoRec->WriteBitmap) (infoRec->pScrn, pbox->x1, pbox->y1,
-                                 pbox->x2 - pbox->x1, pbox->y2 - pbox->y1,
-                                 src + (srcwidth * pptSrc->y) +
-                                 ((pptSrc->x >> 5) << 2), srcwidth,
-                                 pptSrc->x & 31, pGC->fgPixel, pGC->bgPixel,
-                                 pGC->alu, pGC->planemask);
-        pbox++;
-        pptSrc++;
-    }
-}
-
-static void
-XAACopyPlaneNtoNColorExpand(DrawablePtr pSrc,
-                            DrawablePtr pDst,
-                            GCPtr pGC, RegionPtr rgnDst, DDXPointPtr pptSrc)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    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;
-    int pitch, width, height, h, i, index, offset;
-    int Bpp = pSrc->bitsPerPixel >> 3;
-    unsigned long mask = TmpBitPlane;
-
-    if (TmpBitPlane < (1 << 8)) {
-        offset = 0;
-    }
-    else if (TmpBitPlane < (1 << 16)) {
-        offset = 1;
-        mask >>= 8;
-    }
-    else if (TmpBitPlane < (1 << 24)) {
-        offset = 2;
-        mask >>= 16;
-    }
-    else {
-        offset = 3;
-        mask >>= 24;
-    }
-
-    if (IS_OFFSCREEN_PIXMAP(pSrc))
-        SYNC_CHECK(pSrc);
-
-    while (numrects--) {
-        width = pbox->x2 - pbox->x1;
-        h = height = pbox->y2 - pbox->y1;
-        pitch = BitmapBytePad(width);
-
-        if (!(data = calloc(height, pitch)))
-            goto ALLOC_FAILED;
-
-        dataPtr = data;
-        srcPtr = ((pptSrc->y) * srcwidth) + src + ((pptSrc->x) * Bpp) + offset;
-
-        while (h--) {
-            for (i = index = 0; i < width; i++, index += Bpp) {
-                if (mask & srcPtr[index])
-                    dataPtr[i >> 3] |= (1 << (i & 7));
-            }
-            dataPtr += pitch;
-            srcPtr += srcwidth;
-        }
-
-        (*infoRec->WriteBitmap) (infoRec->pScrn,
-                                 pbox->x1, pbox->y1, width, height, data, pitch,
-                                 0, pGC->fgPixel, pGC->bgPixel, pGC->alu,
-                                 pGC->planemask);
-
-        free(data);
-
- ALLOC_FAILED:
-
-        pbox++;
-        pptSrc++;
-    }
-}
-
-void
-XAAPushPixelsSolidColorExpansion(GCPtr pGC,
-                                 PixmapPtr pBitMap,
-                                 DrawablePtr pDraw,
-                                 int dx, int dy, int xOrg, int yOrg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    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 (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    TheRect.x = xOrg;
-    TheRect.y = yOrg;
-    TheRect.width = dx;
-    TheRect.height = dy;
-
-    if (MaxBoxes > (infoRec->PreAllocSize / sizeof(BoxRec))) {
-        pClipBoxes = malloc(MaxBoxes * sizeof(BoxRec));
-        if (!pClipBoxes)
-            return;
-    }
-    else
-        pClipBoxes = (BoxPtr) infoRec->PreAllocMem;
-
-    nboxes = XAAGetRectClipBoxes(pGC, pClipBoxes, 1, &TheRect);
-    pbox = pClipBoxes;
-
-    while (nboxes--) {
-        srcx = pbox->x1 - xOrg;
-        srcy = pbox->y1 - yOrg;
-        (*infoRec->WriteBitmap) (infoRec->pScrn, pbox->x1, pbox->y1,
-                                 pbox->x2 - pbox->x1, pbox->y2 - pbox->y1,
-                                 src + (srcwidth * srcy) + ((srcx >> 5) << 2),
-                                 srcwidth, srcx & 31,
-                                 pGC->fgPixel, -1, pGC->alu, pGC->planemask);
-        pbox++;
-    }
-
-    if (pClipBoxes != (BoxPtr) infoRec->PreAllocMem)
-        free(pClipBoxes);
-}
diff --git a/hw/xfree86/xaa/xaaCpyWin.c b/hw/xfree86/xaa/xaaCpyWin.c
deleted file mode 100644
index e851f4a..0000000
--- a/hw/xfree86/xaa/xaaCpyWin.c
+++ /dev/null
@@ -1,78 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "windowstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-#include "xaawrap.h"
-
-/*
-    Written by Harm Hanemaayer (H.Hanemaayer at inter.nl.net).
-*/
-
-void
-XAACopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
-{
-    DDXPointPtr pptSrc, ppt;
-    RegionRec rgnDst;
-    BoxPtr pbox;
-    int dx, dy, nbox;
-    WindowPtr pwinRoot;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_DRAWABLE((&pWin->drawable));
-
-    if (!infoRec->pScrn->vtSema || !infoRec->ScreenToScreenBitBlt) {
-        XAA_SCREEN_PROLOGUE(pScreen, CopyWindow);
-        if (infoRec->pScrn->vtSema && infoRec->NeedToSync) {
-            (*infoRec->Sync) (infoRec->pScrn);
-            infoRec->NeedToSync = FALSE;
-        }
-        (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc);
-        XAA_SCREEN_EPILOGUE(pScreen, CopyWindow, XAACopyWindow);
-        return;
-    }
-
-    pwinRoot = pScreen->root;
-
-    RegionNull(&rgnDst);
-
-    dx = ptOldOrg.x - pWin->drawable.x;
-    dy = ptOldOrg.y - pWin->drawable.y;
-    RegionTranslate(prgnSrc, -dx, -dy);
-    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
-
-    pbox = RegionRects(&rgnDst);
-    nbox = RegionNumRects(&rgnDst);
-    if (!nbox || !(pptSrc = (DDXPointPtr) malloc(nbox * sizeof(DDXPointRec)))) {
-        RegionUninit(&rgnDst);
-        return;
-    }
-    ppt = pptSrc;
-
-    while (nbox--) {
-        ppt->x = pbox->x1 + dx;
-        ppt->y = pbox->y1 + dy;
-        ppt++;
-        pbox++;
-    }
-
-    infoRec->ScratchGC.planemask = ~0L;
-    infoRec->ScratchGC.alu = GXcopy;
-
-    XAADoBitBlt((DrawablePtr) pwinRoot, (DrawablePtr) pwinRoot,
-                &(infoRec->ScratchGC), &rgnDst, pptSrc);
-
-    free(pptSrc);
-    RegionUninit(&rgnDst);
-}
diff --git a/hw/xfree86/xaa/xaaDashLine.c b/hw/xfree86/xaa/xaaDashLine.c
deleted file mode 100644
index c7e52cd..0000000
--- a/hw/xfree86/xaa/xaaDashLine.c
+++ /dev/null
@@ -1,353 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <stdlib.h>
-
-#include <X11/X.h>
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "miline.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-
-void
-#ifdef POLYSEGMENT
- XAAPolySegmentDashed(DrawablePtr pDrawable,
-                      GCPtr pGC, int nseg, xSegment * pSeg
-#else
-XAAPolyLinesDashed(DrawablePtr pDrawable, GCPtr pGC, int mode,  /* Origin or Previous */
-                   int npt,     /* number of points */
-                   DDXPointPtr pptInit
-#endif
-    )
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAAGCPtr pGCPriv = (XAAGCPtr) dixLookupPrivate(&pGC->devPrivates,
-                                                   XAAGetGCKey());
-    BoxPtr pboxInit = RegionRects(pGC->pCompositeClip);
-    int nboxInit = RegionNumRects(pGC->pCompositeClip);
-    unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
-    int xorg = pDrawable->x;
-    int yorg = pDrawable->y;
-    int nbox;
-    BoxPtr pbox;
-
-#ifndef POLYSEGMENT
-    DDXPointPtr ppt;
-#endif
-    unsigned int oc1, oc2;
-    int dmin, dmaj, e, octant;
-    int x1, x2, y1, y2, tmp, len, offset;
-    int PatternLength, PatternOffset;
-
-    if (!nboxInit)
-        return;
-
-    if (infoRec->DashedLineFlags & LINE_LIMIT_COORDS) {
-        int minValX = infoRec->DashedLineLimits.x1;
-        int maxValX = infoRec->DashedLineLimits.x2;
-        int minValY = infoRec->DashedLineLimits.y1;
-        int maxValY = infoRec->DashedLineLimits.y2;
-
-#ifdef POLYSEGMENT
-        int n = nseg;
-        xSegment *s = pSeg;
-
-        while (n--)
-#else
-        int n = npt;
-        int xorgtmp = xorg;
-        int yorgtmp = yorg;
-
-        ppt = pptInit;
-        x2 = ppt->x + xorgtmp;
-        y2 = ppt->y + yorgtmp;
-        while (--n)
-#endif
-        {
-#ifdef POLYSEGMENT
-            x1 = s->x1 + xorg;
-            y1 = s->y1 + yorg;
-            x2 = s->x2 + xorg;
-            y2 = s->y2 + yorg;
-            s++;
-#else
-            x1 = x2;
-            y1 = y2;
-            ++ppt;
-            if (mode == CoordModePrevious) {
-                xorgtmp = x1;
-                yorgtmp = y1;
-            }
-            x2 = ppt->x + xorgtmp;
-            y2 = ppt->y + yorgtmp;
-#endif
-            if (x1 > maxValX || x1 < minValX ||
-                x2 > maxValX || x2 < minValX ||
-                y1 > maxValY || y1 < minValY || y2 > maxValY || y2 < minValY) {
-#ifdef POLYSEGMENT
-                XAAFallbackOps.PolySegment(pDrawable, pGC, nseg, pSeg);
-#else
-                XAAFallbackOps.Polylines(pDrawable, pGC, mode, npt, pptInit);
-#endif
-                return;
-            }
-        }
-    }
-
-    PatternLength = pGCPriv->DashLength;
-    PatternOffset = pGC->dashOffset % PatternLength;
-
-    (*infoRec->SetupForDashedLine) (infoRec->pScrn, pGC->fgPixel,
-                                    (pGC->lineStyle ==
-                                     LineDoubleDash) ? pGC->bgPixel : -1,
-                                    pGC->alu, pGC->planemask, PatternLength,
-                                    pGCPriv->DashPattern);
-
-#ifdef POLYSEGMENT
-    while (nseg--)
-#else
-    ppt = pptInit;
-    x2 = ppt->x + xorg;
-    y2 = ppt->y + yorg;
-    while (--npt)
-#endif
-    {
-        nbox = nboxInit;
-        pbox = pboxInit;
-
-#ifdef POLYSEGMENT
-        x1 = pSeg->x1 + xorg;
-        y1 = pSeg->y1 + yorg;
-        x2 = pSeg->x2 + xorg;
-        y2 = pSeg->y2 + yorg;
-        pSeg++;
-#else
-        x1 = x2;
-        y1 = y2;
-        ++ppt;
-        if (mode == CoordModePrevious) {
-            xorg = x1;
-            yorg = y1;
-        }
-        x2 = ppt->x + xorg;
-        y2 = ppt->y + yorg;
-#endif
-
-        if (infoRec->SubsequentDashedBresenhamLine) {
-            if ((dmaj = x2 - x1) < 0) {
-                dmaj = -dmaj;
-                octant = XDECREASING;
-            }
-            else
-                octant = 0;
-
-            if ((dmin = y2 - y1) < 0) {
-                dmin = -dmin;
-                octant |= YDECREASING;
-            }
-
-            if (dmin >= dmaj) {
-                tmp = dmin;
-                dmin = dmaj;
-                dmaj = tmp;
-                octant |= YMAJOR;
-            }
-
-            e = -dmaj - ((bias >> octant) & 1);
-            len = dmaj;
-            dmin <<= 1;
-            dmaj <<= 1;
-        }
-        else {                  /* Muffle compiler */
-            dmin = dmaj = e = octant = len = 0;
-        }
-
-        while (nbox--) {
-            oc1 = oc2 = 0;
-            OUTCODES(oc1, x1, y1, pbox);
-            OUTCODES(oc2, x2, y2, pbox);
-            if (!(oc1 | oc2)) { /* uncliped */
-                if (infoRec->SubsequentDashedTwoPointLine) {
-                    (*infoRec->SubsequentDashedTwoPointLine) (infoRec->pScrn,
-                                                              x1, y1, x2, y2,
-#ifdef POLYSEGMENT
-                                                              (pGC->capStyle !=
-                                                               CapNotLast) ? 0 :
-#endif
-                                                              OMIT_LAST,
-                                                              PatternOffset);
-                }
-                else {
-                    (*infoRec->SubsequentDashedBresenhamLine) (infoRec->pScrn,
-                                                               x1, y1, dmaj,
-                                                               dmin, e,
-#ifdef POLYSEGMENT
-                                                               (pGC->capStyle !=
-                                                                CapNotLast)
-                                                               ? (len + 1) :
-#endif
-                                                               len, octant,
-                                                               PatternOffset);
-                }
-                break;
-            }
-            else if (oc1 & oc2) {       /* completely clipped */
-                pbox++;
-            }
-            else if (infoRec->ClippingFlags & HARDWARE_CLIP_DASHED_LINE) {
-                (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                                  pbox->x1, pbox->y1,
-                                                  pbox->x2 - 1, pbox->y2 - 1);
-
-                if (infoRec->SubsequentDashedBresenhamLine) {
-                    (*infoRec->SubsequentDashedBresenhamLine) (infoRec->pScrn,
-                                                               x1, y1, dmaj,
-                                                               dmin, e,
-#ifdef POLYSEGMENT
-                                                               (pGC->capStyle !=
-                                                                CapNotLast)
-                                                               ? (len + 1) :
-#endif
-                                                               len, octant,
-                                                               PatternOffset);
-                }
-                else {
-                    (*infoRec->SubsequentDashedTwoPointLine) (infoRec->pScrn,
-                                                              x1, y1, x2, y2,
-#ifdef POLYSEGMENT
-                                                              (pGC->capStyle !=
-                                                               CapNotLast) ? 0 :
-#endif
-                                                              OMIT_LAST,
-                                                              PatternOffset);
-                }
-                (*infoRec->DisableClipping) (infoRec->pScrn);
-                pbox++;
-            }
-            else {
-                int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
-                int clip1 = 0, clip2 = 0;
-                int err, adx, ady;
-
-                if (octant & YMAJOR) {
-                    ady = dmaj >> 1;
-                    adx = dmin >> 1;
-                }
-                else {
-                    ady = dmin >> 1;
-                    adx = dmaj >> 1;
-                }
-
-                if (miZeroClipLine(pbox->x1, pbox->y1,
-                                   pbox->x2 - 1, pbox->y2 - 1,
-                                   &new_x1, &new_y1, &new_x2, &new_y2,
-                                   adx, ady, &clip1, &clip2,
-                                   octant, bias, oc1, oc2) == -1) {
-                    pbox++;
-                    continue;
-                }
-
-                if (octant & YMAJOR)
-                    len = abs(new_y2 - new_y1);
-                else
-                    len = abs(new_x2 - new_x1);
-#ifdef POLYSEGMENT
-                if (clip2 != 0 || pGC->capStyle != CapNotLast)
-                    len++;
-#else
-                len += (clip2 != 0);
-#endif
-                if (len) {
-                    int abserr, clipdx, clipdy;
-
-                    /* unwind bresenham error term to first point */
-                    if (clip1) {
-                        clipdx = abs(new_x1 - x1);
-                        clipdy = abs(new_y1 - y1);
-
-                        if (octant & YMAJOR)
-                            err = e + clipdy * dmin - clipdx * dmaj;
-                        else
-                            err = e + clipdx * dmin - clipdy * dmaj;
-                    }
-                    else
-                        err = e;
-
-#define range infoRec->DashedBresenhamLineErrorTermBits
-                    abserr = abs(err);
-                    while ((abserr & range) || (dmaj & range) || (dmin & range)) {
-                        dmin >>= 1;
-                        dmaj >>= 1;
-                        abserr >>= 1;
-                        err /= 2;
-                    }
-
-                    if (octant & YMAJOR)
-                        offset = abs(new_y1 - y1);
-                    else
-                        offset = abs(new_x1 - x1);
-
-                    offset += PatternOffset;
-                    offset %= PatternLength;
-
-                    (*infoRec->SubsequentDashedBresenhamLine) (infoRec->pScrn,
-                                                               new_x1, new_y1,
-                                                               dmaj, dmin, err,
-                                                               len, octant,
-                                                               offset);
-                }
-                pbox++;
-            }
-        }                       /* while (nbox--) */
-#ifndef POLYSEGMENT
-        len = abs(y2 - y1);
-        tmp = abs(x2 - x1);
-        PatternOffset += (len > tmp) ? len : tmp;
-        PatternOffset %= PatternLength;
-#endif
-    }                           /* while (nline--) */
-
-#ifndef POLYSEGMENT
-    /* paint the last point if the end style isn't CapNotLast.
-       (Assume that a projecting, butt, or round cap that is one
-       pixel wide is the same as the single pixel of the endpoint.)
-     */
-
-    if ((pGC->capStyle != CapNotLast) &&
-        ((ppt->x + xorg != pptInit->x + pDrawable->x) ||
-         (ppt->y + yorg != pptInit->y + pDrawable->y) ||
-         (ppt == pptInit + 1))) {
-        nbox = nboxInit;
-        pbox = pboxInit;
-        while (nbox--) {
-            if ((x2 >= pbox->x1) && (y2 >= pbox->y1) &&
-                (x2 < pbox->x2) && (y2 < pbox->y2)) {
-                if (infoRec->SubsequentDashedTwoPointLine) {
-                    (*infoRec->SubsequentDashedTwoPointLine) (infoRec->pScrn,
-                                                              x2, y2, x2, y2, 0,
-                                                              PatternOffset);
-                }
-                else {
-                    (*infoRec->SubsequentDashedBresenhamLine) (infoRec->pScrn,
-                                                               x2, y2, 2, 0, -1,
-                                                               1, 0,
-                                                               PatternOffset);
-                }
-                break;
-            }
-            else
-                pbox++;
-        }
-    }
-#endif
-
-    SET_SYNC_FLAG(infoRec);
-}
diff --git a/hw/xfree86/xaa/xaaFallback.c b/hw/xfree86/xaa/xaaFallback.c
deleted file mode 100644
index f7604ef..0000000
--- a/hw/xfree86/xaa/xaaFallback.c
+++ /dev/null
@@ -1,281 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-#include "xaawrap.h"
-
-static void
-XAAFillSpansFallback(DrawablePtr pDraw,
-                     GC * pGC,
-                     int nInit,
-                     DDXPointPtr pptInit, int *pwidthInit, int fSorted)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->FillSpans) (pDraw, pGC, nInit, pptInit, pwidthInit, fSorted);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAASetSpansFallback(DrawablePtr pDraw,
-                    GCPtr pGC,
-                    char *pcharsrc,
-                    register DDXPointPtr ppt,
-                    int *pwidth, int nspans, int fSorted)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->SetSpans) (pDraw, pGC, pcharsrc, ppt, pwidth, nspans, fSorted);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPutImageFallback(DrawablePtr pDraw,
-                    GCPtr pGC,
-                    int depth,
-                    int x, int y, int w, int h,
-                    int leftPad, int format, char *pImage)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->PutImage) (pDraw, pGC, depth, x, y, w, h,
-                           leftPad, format, pImage);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static RegionPtr
-XAACopyAreaFallback(DrawablePtr pSrc,
-                    DrawablePtr pDst,
-                    GC * pGC,
-                    int srcx, int srcy,
-                    int width, int height, int dstx, int dsty)
-{
-    RegionPtr ret;
-
-    XAA_GC_OP_PROLOGUE(pGC);
-    if ((pSrc->type == DRAWABLE_WINDOW) || (pDst->type == DRAWABLE_WINDOW) ||
-        IS_OFFSCREEN_PIXMAP(pSrc) || IS_OFFSCREEN_PIXMAP(pDst)) {
-        SYNC_CHECK(pGC);
-    }
-    ret = (*pGC->ops->CopyArea) (pSrc, pDst,
-                                 pGC, srcx, srcy, width, height, dstx, dsty);
-    XAA_GC_OP_EPILOGUE(pGC);
-    return ret;
-}
-
-static RegionPtr
-XAACopyPlaneFallback(DrawablePtr pSrc,
-                     DrawablePtr pDst,
-                     GCPtr pGC,
-                     int srcx, int srcy,
-                     int width, int height,
-                     int dstx, int dsty, unsigned long bitPlane)
-{
-    RegionPtr ret;
-
-    XAA_GC_OP_PROLOGUE(pGC);
-    if ((pSrc->type == DRAWABLE_WINDOW) || (pDst->type == DRAWABLE_WINDOW) ||
-        IS_OFFSCREEN_PIXMAP(pSrc) || IS_OFFSCREEN_PIXMAP(pDst)) {
-        SYNC_CHECK(pGC);
-    }
-    ret = (*pGC->ops->CopyPlane) (pSrc, pDst,
-                                  pGC, srcx, srcy, width, height, dstx, dsty,
-                                  bitPlane);
-    XAA_GC_OP_EPILOGUE(pGC);
-    return ret;
-}
-
-static void
-XAAPolyPointFallback(DrawablePtr pDraw,
-                     GCPtr pGC, int mode, int npt, xPoint * pptInit)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->PolyPoint) (pDraw, pGC, mode, npt, pptInit);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolylinesFallback(DrawablePtr pDraw,
-                     GCPtr pGC, int mode, int npt, DDXPointPtr pptInit)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->Polylines) (pDraw, pGC, mode, npt, pptInit);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolySegmentFallback(DrawablePtr pDraw, GCPtr pGC, int nseg, xSegment * pSeg)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->PolySegment) (pDraw, pGC, nseg, pSeg);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyRectangleFallback(DrawablePtr pDraw,
-                         GCPtr pGC, int nRectsInit, xRectangle *pRectsInit)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->PolyRectangle) (pDraw, pGC, nRectsInit, pRectsInit);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyArcFallback(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->PolyArc) (pDraw, pGC, narcs, parcs);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAFillPolygonFallback(DrawablePtr pDraw,
-                       GCPtr pGC,
-                       int shape, int mode, int count, DDXPointPtr ptsIn)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->FillPolygon) (pDraw, pGC, shape, mode, count, ptsIn);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyFillRectFallback(DrawablePtr pDraw,
-                        GCPtr pGC, int nrectFill, xRectangle *prectInit)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->PolyFillRect) (pDraw, pGC, nrectFill, prectInit);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyFillArcFallback(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, parcs);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static int
-XAAPolyText8Fallback(DrawablePtr pDraw,
-                     GCPtr pGC, int x, int y, int count, char *chars)
-{
-    int ret;
-
-    XAA_GC_OP_PROLOGUE(pGC);
-    SYNC_CHECK(pGC);
-    ret = (*pGC->ops->PolyText8) (pDraw, pGC, x, y, count, chars);
-    XAA_GC_OP_EPILOGUE(pGC);
-    return ret;
-}
-
-static int
-XAAPolyText16Fallback(DrawablePtr pDraw,
-                      GCPtr pGC, int x, int y, int count, unsigned short *chars)
-{
-    int ret;
-
-    XAA_GC_OP_PROLOGUE(pGC);
-    SYNC_CHECK(pGC);
-    ret = (*pGC->ops->PolyText16) (pDraw, pGC, x, y, count, chars);
-    XAA_GC_OP_EPILOGUE(pGC);
-    return ret;
-}
-
-static void
-XAAImageText8Fallback(DrawablePtr pDraw,
-                      GCPtr pGC, int x, int y, int count, char *chars)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->ImageText8) (pDraw, pGC, x, y, count, chars);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAImageText16Fallback(DrawablePtr pDraw,
-                       GCPtr pGC,
-                       int x, int y, int count, unsigned short *chars)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->ImageText16) (pDraw, pGC, x, y, count, chars);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAImageGlyphBltFallback(DrawablePtr pDraw,
-                         GCPtr pGC,
-                         int xInit, int yInit,
-                         unsigned int nglyph,
-                         CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->ImageGlyphBlt) (pDraw, pGC, xInit, yInit, nglyph, ppci,
-                                pglyphBase);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyGlyphBltFallback(DrawablePtr pDraw,
-                        GCPtr pGC,
-                        int xInit, int yInit,
-                        unsigned int nglyph,
-                        CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->PolyGlyphBlt) (pDraw, pGC, xInit, yInit, nglyph, ppci,
-                               pglyphBase);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPushPixelsFallback(GCPtr pGC,
-                      PixmapPtr pBitMap,
-                      DrawablePtr pDraw, int dx, int dy, int xOrg, int yOrg)
-{
-    XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC);
-    SYNC_CHECK(pGC);
-    (*pGC->ops->PushPixels) (pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg);
-    XAA_GC_OP_EPILOGUE(pGC);
-}
-
-GCOps XAAFallbackOps = {
-    XAAFillSpansFallback, XAASetSpansFallback,
-    XAAPutImageFallback, XAACopyAreaFallback,
-    XAACopyPlaneFallback, XAAPolyPointFallback,
-    XAAPolylinesFallback, XAAPolySegmentFallback,
-    XAAPolyRectangleFallback, XAAPolyArcFallback,
-    XAAFillPolygonFallback, XAAPolyFillRectFallback,
-    XAAPolyFillArcFallback, XAAPolyText8Fallback,
-    XAAPolyText16Fallback, XAAImageText8Fallback,
-    XAAImageText16Fallback, XAAImageGlyphBltFallback,
-    XAAPolyGlyphBltFallback, XAAPushPixelsFallback,
-};
-
-GCOps *
-XAAGetFallbackOps(void)
-{
-    return &XAAFallbackOps;
-}
diff --git a/hw/xfree86/xaa/xaaFillArc.c b/hw/xfree86/xaa/xaaFillArc.c
deleted file mode 100644
index fb7e720..0000000
--- a/hw/xfree86/xaa/xaaFillArc.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Copyright 1996  The XFree86 Project
- *
- * 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, and to permit persons to whom the 
- * Software is furnished to do so, subject to the following conditions:
- *
- * 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 
- * HARM HANEMAAYER 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.
- * 
- * Written by Harm Hanemaayer (H.Hanemaayer at inter.nl.net).
- */
-
-/*
- * Filled solid arcs, based on cfbfillarc.c.
- *
- * Fill arc using calls to low-level span fill. Because the math for
- * each span can be done concurrently with the drawing of the span
- * with a graphics coprocessor operation, this is faster than just
- * using miPolyFillArc, which first calculates all the spans and then
- * calls FillSpans.
- *
- * Clipped arcs are dispatched to FillSpans.
- */
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <limits.h>
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "mifillarc.h"
-#include "mi.h"
-
-/*
- * This is based on the integer-math versions from mi. Perhaps on a
- * Pentium, the floating-point (double)-math version is faster.
- */
-
-static void
-XAAFillEllipseSolid(DrawablePtr pDraw, GCPtr pGC, xArc * arc)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    register int x, y, e;
-    int yk, xk, ym, xm, dx, dy, xorg, yorg;
-    int slw;
-    miFillArcRec info;
-
-    (*infoRec->SetupForSolidFill) (infoRec->pScrn, pGC->fgPixel, pGC->alu,
-                                   pGC->planemask);
-
-    miFillArcSetup(arc, &info);
-    MIFILLARCSETUP();
-    if (pGC->miTranslate) {
-        xorg += pDraw->x;
-        yorg += pDraw->y;
-    }
-    while (y > 0) {
-        MIFILLARCSTEP(slw);
-        if (slw > 0) {
-            (*infoRec->SubsequentSolidFillRect) (infoRec->pScrn, xorg - x,
-                                                 yorg - y, slw, 1);
-            if (miFillArcLower(slw))
-                (*infoRec->SubsequentSolidFillRect) (infoRec->pScrn,
-                                                     xorg - x, yorg + y + dy,
-                                                     slw, 1);
-        }
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-#define ADDSPAN(l,r) \
-    if (r >= l) \
-	(*infoRec->SubsequentSolidFillRect)( \
-	    infoRec->pScrn, l, ya, r - l + 1, 1);
-
-#define ADDSLICESPANS(flip) \
-    if (!flip) \
-    { \
-	ADDSPAN(xl, xr); \
-    } \
-    else \
-    { \
-	xc = xorg - x; \
-	ADDSPAN(xc, xr); \
-	xc += slw - 1; \
-	ADDSPAN(xl, xc); \
-    }
-
-static void
-XAAFillArcSliceSolid(DrawablePtr pDraw, GCPtr pGC, xArc * arc)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
-    register int x, y, e;
-    miFillArcRec info;
-    miArcSliceRec slice;
-    int ya, xl, xr, xc;
-
-    (*infoRec->SetupForSolidFill) (infoRec->pScrn, pGC->fgPixel, pGC->alu,
-                                   pGC->planemask);
-
-    miFillArcSetup(arc, &info);
-    miFillArcSliceSetup(arc, &slice, pGC);
-    MIFILLARCSETUP();
-    slw = arc->height;
-    if (slice.flip_top || slice.flip_bot)
-        slw += (arc->height >> 1) + 1;
-    if (pGC->miTranslate) {
-        xorg += pDraw->x;
-        yorg += pDraw->y;
-        slice.edge1.x += pDraw->x;
-        slice.edge2.x += pDraw->x;
-    }
-    while (y > 0) {
-        MIFILLARCSTEP(slw);
-        MIARCSLICESTEP(slice.edge1);
-        MIARCSLICESTEP(slice.edge2);
-        if (miFillSliceUpper(slice)) {
-            ya = yorg - y;
-            MIARCSLICEUPPER(xl, xr, slice, slw);
-
-            ADDSLICESPANS(slice.flip_top);
-        }
-        if (miFillSliceLower(slice)) {
-            ya = yorg + y + dy;
-            MIARCSLICELOWER(xl, xr, slice, slw);
-            ADDSLICESPANS(slice.flip_bot);
-        }
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAAPolyFillArcSolid(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
-{
-    register xArc *arc;
-    register int i;
-    int x2, y2;
-    BoxRec box;
-    RegionPtr cclip;
-
-    cclip = pGC->pCompositeClip;
-
-    if (!RegionNumRects(cclip))
-        return;
-
-    for (arc = parcs, i = narcs; --i >= 0; arc++) {
-        if (miFillArcEmpty(arc))
-            continue;
-        if (miCanFillArc(arc)) {
-            box.x1 = arc->x + pDraw->x;
-            box.y1 = arc->y + pDraw->y;
-            /*
-             * Because box.x2 and box.y2 get truncated to 16 bits, and the
-             * RECT_IN_REGION test treats the resulting number as a signed
-             * integer, the RECT_IN_REGION test alone can go the wrong way.
-             * This can result in a server crash because the rendering
-             * routines in this file deal directly with cpu addresses
-             * of pixels to be stored, and do not clip or otherwise check
-             * that all such addresses are within their respective pixmaps.
-             * So we only allow the RECT_IN_REGION test to be used for
-             * values that can be expressed correctly in a signed short.
-             */
-            x2 = box.x1 + (int) arc->width + 1;
-            box.x2 = x2;
-            y2 = box.y1 + (int) arc->height + 1;
-            box.y2 = y2;
-            if ((x2 <= SHRT_MAX) && (y2 <= SHRT_MAX) &&
-                (RegionContainsRect(cclip, &box) == rgnIN)) {
-                if ((arc->angle2 >= FULLCIRCLE) || (arc->angle2 <= -FULLCIRCLE))
-                    XAAFillEllipseSolid(pDraw, pGC, arc);
-                else
-                    XAAFillArcSliceSolid(pDraw, pGC, arc);
-                continue;
-            }
-        }
-        miPolyFillArc(pDraw, pGC, 1, arc);
-    }
-}
diff --git a/hw/xfree86/xaa/xaaFillPoly.c b/hw/xfree86/xaa/xaaFillPoly.c
deleted file mode 100644
index 0cdedf5..0000000
--- a/hw/xfree86/xaa/xaaFillPoly.c
+++ /dev/null
@@ -1,991 +0,0 @@
-
-/*
- * Copyright 1996  The XFree86 Project
- *
- * 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, and to permit persons to whom the 
- * Software is furnished to do so, subject to the following conditions:
- *
- * 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 
- * HARM HANEMAAYER 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.
- * 
- */
-
-/*
- * Written by Mark Vojkovich.  Loosly based on an original version
- * written by Harm Hanemaayer (H.Hanemaayer at inter.nl.net) which
- * only did solid rectangles and didn't have trapezoid support.
- *
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "xf86str.h"
-#include "mi.h"
-#include "micoord.h"
-
-#include "xaa.h"
-#include "xaalocal.h"
-
-#define POLY_USE_MI		0
-#define POLY_FULLY_CLIPPED	1
-#define POLY_IS_EASY		2
-
-#define Setup(c,x,vertex,dx,dy,e,sign,step,DX) {\
-    x = intToX(vertex); \
-    if ((dy = intToY(c) - y)) { \
-    	DX = dx = intToX(c) - x; \
-	step = 0; \
-    	if (dx >= 0) \
-    	{ \
-	    e = 0; \
-	    sign = 1; \
-	    if (dx >= dy) {\
-	    	step = dx / dy; \
-	    	dx %= dy; \
-	    } \
-    	} \
-    	else \
-    	{ \
-	    e = 1 - dy; \
-	    sign = -1; \
-	    dx = -dx; \
-	    if (dx >= dy) { \
-		step = - (dx / dy); \
-		dx %= dy; \
-	    } \
-    	} \
-    } \
-    x += origin; \
-    vertex = c; \
-}
-
-#define Step(x,dx,dy,e,sign,step) {\
-    x += step; \
-    if ((e += dx) > 0) \
-    { \
-	x += sign; \
-	e -= dy; \
-    } \
-}
-
-#define FixError(x, dx, dy, e, sign, step, h)	{	\
-	   e += (h) * dx;				\
-	   x += (h) * step;				\
-	   if(e > 0) {					\
-		x += e * sign/dy;			\
-		e %= dy;				\
-	   	if(e) {					\
-		   x += sign;				\
-		   e -= dy;				\
-		}					\
-	   } 	 					\
-}
-
-/*
-   XAAIsEasyPoly -
-
-   Checks CoordModeOrigin one rect polygons to see if we need
-   to use Mi.
-   Returns: POLY_USE_MI, POLY_FULLY_CLIPPED or POLY_IS_EASY
-	as well as the pointer to the "top" point and the y
-	extents.
-*/
-
-int
-XAAIsEasyPolygon(DDXPointPtr ptsIn, int count, BoxPtr extents, int origin, DDXPointPtr * topPoint,      /* return */
-                 int *topY, int *bottomY,       /* return */
-                 int shape)
-{
-    int c = 0, vertex1, vertex2;
-
-    *topY = 32767;
-    *bottomY = 0;
-
-    origin -= (origin & 0x8000) << 1;
-    vertex1 = extents->x1 - origin;
-    vertex2 = extents->x2 - origin /* - 0x00010001 */ ;
-    /* I think this was an error in cfb ^ */
-
-    if (shape == Convex) {
-        while (count--) {
-            c = *((int *) ptsIn);
-            if (((c - vertex1) | (vertex2 - c)) & 0x80008000)
-                return POLY_USE_MI;
-
-            c = intToY(c);
-            if (c < *topY) {
-                *topY = c;
-                *topPoint = ptsIn;
-            }
-            ptsIn++;
-            if (c > *bottomY)
-                *bottomY = c;
-        }
-    }
-    else {
-        int yFlip = 0;
-        int dx2, dx1, x1, x2;
-
-        x2 = x1 = -1;
-        dx2 = dx1 = 1;
-
-        while (count--) {
-            c = *((int *) ptsIn);
-            if (((c - vertex1) | (vertex2 - c)) & 0x80008000)
-                return POLY_USE_MI;
-            c = intToY(c);
-            if (c < *topY) {
-                *topY = c;
-                *topPoint = ptsIn;
-            }
-            ptsIn++;
-            if (c > *bottomY)
-                *bottomY = c;
-            if (c == x1)
-                continue;
-            if (dx1 > 0) {
-                if (x2 < 0)
-                    x2 = c;
-                else
-                    dx2 = dx1 = (c - x1) >> 31;
-            }
-            else if ((c - x1) >> 31 != dx1) {
-                dx1 = ~dx1;
-                yFlip++;
-            }
-            x1 = c;
-        }
-        x1 = (x2 - c) >> 31;
-        if (x1 != dx1)
-            yFlip++;
-        if (x1 != dx2)
-            yFlip++;
-        if (yFlip != 2) {
-            if (*topY == *bottomY)
-                return POLY_FULLY_CLIPPED;
-            else
-                return POLY_USE_MI;
-        }
-    }
-    if (*topY == *bottomY)
-        return POLY_FULLY_CLIPPED;
-
-    return POLY_IS_EASY;
-}
-
-void
-XAAFillPolygonSolid(DrawablePtr pDraw,
-                    GCPtr pGC,
-                    int shape, int mode, int count, DDXPointPtr ptsIn)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int origin, vertex1, vertex2;
-    int *vertex1p, *vertex2p, *endp;
-    int x1 = 0, x2 = 0;
-    int dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
-    int DX1 = 0, DX2 = 0, e1 = 0, e2 = 0;
-    int step1 = 0, step2 = 0, sign1 = 0, sign2 = 0;
-    int c, y, maxy, h, yoffset;
-    DDXPointPtr topPoint;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    if (mode == CoordModePrevious) {
-        register DDXPointPtr ppt = ptsIn + 1;
-
-        for (origin = 1; origin < count; origin++, ppt++) {
-            ppt->x += (ppt - 1)->x;
-            ppt->y += (ppt - 1)->y;
-        }
-        mode = CoordModeOrigin;
-    }
-
-    if (RegionNumRects(pGC->pCompositeClip) != 1) {
-        miFillPolygon(pDraw, pGC, shape, mode, count, ptsIn);
-        return;
-    }
-
-    origin = coordToInt(pDraw->x, pDraw->y);
-
-    switch (XAAIsEasyPolygon(ptsIn, count, &pGC->pCompositeClip->extents,
-                             origin, &topPoint, &y, &maxy, shape)) {
-    case POLY_USE_MI:
-        miFillPolygon(pDraw, pGC, shape, mode, count, ptsIn);
-    case POLY_FULLY_CLIPPED:
-        return;
-    }
-
-    endp = (int *) ptsIn + count;
-    vertex2p = vertex1p = (int *) topPoint;
-    origin = pDraw->x;
-    yoffset = pDraw->y;
-    vertex2 = vertex1 = *vertex2p++;
-    if (vertex2p == endp)
-        vertex2p = (int *) ptsIn;
-
-    (*infoRec->SetupForSolidFill) (infoRec->pScrn, pGC->fgPixel, pGC->alu,
-                                   pGC->planemask);
-
-    while (1) {
-        if (y == intToY(vertex1)) {
-            do {
-                if (vertex1p == (int *) ptsIn)
-                    vertex1p = endp;
-                c = *--vertex1p;
-                Setup(c, x1, vertex1, dx1, dy1, e1, sign1, step1, DX1)
-            } while (y >= intToY(vertex1));
-            h = dy1;
-        }
-        else {
-            Step(x1, dx1, dy1, e1, sign1, step1)
-                h = intToY(vertex1) - y;
-        }
-        if (y == intToY(vertex2)) {
-            do {
-                c = *vertex2p++;
-                if (vertex2p == endp)
-                    vertex2p = (int *) ptsIn;
-                Setup(c, x2, vertex2, dx2, dy2, e2, sign2, step2, DX2)
-            } while (y >= intToY(vertex2));
-            if (dy2 < h)
-                h = dy2;
-        }
-        else {
-            Step(x2, dx2, dy2, e2, sign2, step2)
-                if ((c = (intToY(vertex2) - y)) < h)
-                h = c;
-        }
-
-        /* fill spans for this segment */
-        if (DX1 | DX2) {
-            if (infoRec->SubsequentSolidFillTrap && (h > 6)) {
-                if (x1 == x2) {
-                    while (x1 == x2) {
-                        y++;
-                        if (!--h)
-                            break;
-                        Step(x1, dx1, dy1, e1, sign1, step1)
-                            Step(x2, dx2, dy2, e2, sign2, step2)
-                    }
-                    if (y == maxy)
-                        break;
-                    if (!h)
-                        continue;
-                }
-
-                if (x1 < x2)
-                    (*infoRec->SubsequentSolidFillTrap) (infoRec->pScrn,
-                                                         y + yoffset, h,
-                                                         x1, DX1, dy1, e1,
-                                                         x2 - 1, DX2, dy2, e2);
-                else
-                    (*infoRec->SubsequentSolidFillTrap) (infoRec->pScrn,
-                                                         y + yoffset, h,
-                                                         x2, DX2, dy2, e2,
-                                                         x1 - 1, DX1, dy1, e1);
-                y += h;
-                if (--h) {
-                    FixError(x1, dx1, dy1, e1, sign1, step1, h);
-                    FixError(x2, dx2, dy2, e2, sign2, step2, h);
-                    h = 0;
-                }
-            }
-            else {
-                while (1) {
-                    if (x2 > x1)
-                        (*infoRec->SubsequentSolidFillRect) (infoRec->pScrn,
-                                                             x1, y + yoffset,
-                                                             x2 - x1, 1);
-                    else if (x1 > x2)
-                        (*infoRec->SubsequentSolidFillRect) (infoRec->pScrn,
-                                                             x2, y + yoffset,
-                                                             x1 - x2, 1);
-                    y++;
-                    if (!--h)
-                        break;
-                    Step(x1, dx1, dy1, e1, sign1, step1)
-                        Step(x2, dx2, dy2, e2, sign2, step2)
-                }
-            }
-        }
-        else {
-            if (x2 > x1)
-                (*infoRec->SubsequentSolidFillRect) (infoRec->pScrn,
-                                                     x1, y + yoffset, x2 - x1,
-                                                     h);
-            else if (x1 > x2)
-                (*infoRec->SubsequentSolidFillRect) (infoRec->pScrn,
-                                                     x2, y + yoffset, x1 - x2,
-                                                     h);
-
-            y += h;
-            h = 0;
-        }
-        if (y == maxy)
-            break;
-    }
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAAFillPolygonHelper(ScrnInfoPtr pScrn,
-                     DDXPointPtr ptsIn,
-                     int count,
-                     DDXPointPtr topPoint,
-                     int y,
-                     int maxy,
-                     int origin,
-                     RectFuncPtr RectFunc,
-                     TrapFuncPtr TrapFunc,
-                     int xorg, int yorg, XAACacheInfoPtr pCache)
-{
-    int *vertex1p, *vertex2p, *endp;
-    int vertex1, vertex2;
-    int x1 = 0, x2 = 0;
-    int dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
-    int DX1 = 0, DX2 = 0, e1 = 0, e2 = 0;
-    int step1 = 0, step2 = 0, sign1 = 0, sign2 = 0;
-    int c, h, yoffset;
-
-    endp = (int *) ptsIn + count;
-    vertex2p = vertex1p = (int *) topPoint;
-    yoffset = intToY(origin);
-    origin = intToX(origin);
-    vertex2 = vertex1 = *vertex2p++;
-    if (vertex2p == endp)
-        vertex2p = (int *) ptsIn;
-
-    while (1) {
-        if (y == intToY(vertex1)) {
-            do {
-                if (vertex1p == (int *) ptsIn)
-                    vertex1p = endp;
-                c = *--vertex1p;
-                Setup(c, x1, vertex1, dx1, dy1, e1, sign1, step1, DX1)
-            } while (y >= intToY(vertex1));
-            h = dy1;
-        }
-        else {
-            Step(x1, dx1, dy1, e1, sign1, step1)
-                h = intToY(vertex1) - y;
-        }
-        if (y == intToY(vertex2)) {
-            do {
-                c = *vertex2p++;
-                if (vertex2p == endp)
-                    vertex2p = (int *) ptsIn;
-                Setup(c, x2, vertex2, dx2, dy2, e2, sign2, step2, DX2)
-            } while (y >= intToY(vertex2));
-            if (dy2 < h)
-                h = dy2;
-        }
-        else {
-            Step(x2, dx2, dy2, e2, sign2, step2)
-                if ((c = (intToY(vertex2) - y)) < h)
-                h = c;
-        }
-
-        /* fill spans for this segment */
-        if (DX1 | DX2) {
-            if (TrapFunc && (h > 6)) {
-                if (x1 == x2) {
-                    while (x1 == x2) {
-                        y++;
-                        if (!--h)
-                            break;
-                        Step(x1, dx1, dy1, e1, sign1, step1)
-                            Step(x2, dx2, dy2, e2, sign2, step2)
-                    }
-                    if (y == maxy)
-                        break;
-                    if (!h)
-                        continue;
-                }
-
-                if (x1 < x2)
-                    (*TrapFunc) (pScrn, y + yoffset, h,
-                                 x1, DX1, dy1, e1,
-                                 x2 - 1, DX2, dy2, e2, xorg, yorg, pCache);
-                else
-                    (*TrapFunc) (pScrn, y + yoffset, h,
-                                 x2, DX2, dy2, e2,
-                                 x1 - 1, DX1, dy1, e1, xorg, yorg, pCache);
-                y += h;
-                if (--h) {
-                    FixError(x1, dx1, dy1, e1, sign1, step1, h);
-                    FixError(x2, dx2, dy2, e2, sign2, step2, h);
-                    h = 0;
-                }
-            }
-            else {
-                while (1) {
-                    if (x2 > x1)
-                        (*RectFunc) (pScrn,
-                                     x1, y + yoffset, x2 - x1, 1, xorg, yorg,
-                                     pCache);
-                    else if (x1 > x2)
-                        (*RectFunc) (pScrn,
-                                     x2, y + yoffset, x1 - x2, 1, xorg, yorg,
-                                     pCache);
-                    y++;
-                    if (!--h)
-                        break;
-                    Step(x1, dx1, dy1, e1, sign1, step1)
-                        Step(x2, dx2, dy2, e2, sign2, step2)
-                }
-            }
-        }
-        else {
-            if (x2 > x1)
-                (*RectFunc) (pScrn,
-                             x1, y + yoffset, x2 - x1, h, xorg, yorg, pCache);
-            else if (x1 > x2)
-                (*RectFunc) (pScrn,
-                             x2, y + yoffset, x1 - x2, h, xorg, yorg, pCache);
-
-            y += h;
-            h = 0;
-        }
-        if (y == maxy)
-            break;
-    }
-}
-
-        /*****************\
-	|  Solid Helpers  |
-	\*****************/
-
-static void
-SolidTrapHelper(ScrnInfoPtr pScrn,
-                int y, int h,
-                int x1, int dx1, int dy1, int e1,
-                int x2, int dx2, int dy2, int e2,
-                int xorg, int yorg, XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    (*infoRec->SubsequentSolidFillTrap) (pScrn,
-                                         y, h, x1, dx1, dy1, e1, x2, dx2, dy2,
-                                         e2);
-}
-
-static void
-SolidRectHelper(ScrnInfoPtr pScrn,
-                int x, int y, int w, int h,
-                int xorg, int yorg, XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, w, h);
-}
-
-        /*********************\
-	|  Mono 8x8 Patterns  |
-	\*********************/
-
-static void
-Mono8x8PatternTrapHelper_ScreenOrigin(ScrnInfoPtr pScrn,
-                                      int y, int h,
-                                      int x1, int dx1, int dy1, int e1,
-                                      int x2, int dx2, int dy2, int e2,
-                                      int xorg, int yorg,
-                                      XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    (*infoRec->SubsequentMono8x8PatternFillTrap) (pScrn, xorg, yorg,
-                                                  y, h, x1, dx1, dy1, e1, x2,
-                                                  dx2, dy2, e2);
-}
-
-static void
-Mono8x8PatternRectHelper_ScreenOrigin(ScrnInfoPtr pScrn,
-                                      int x, int y, int w, int h,
-                                      int xorg, int yorg,
-                                      XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    (*infoRec->SubsequentMono8x8PatternFillRect) (pScrn, xorg, yorg,
-                                                  x, y, w, h);
-}
-
-static void
-Mono8x8PatternRectHelper(ScrnInfoPtr pScrn,
-                         int x, int y, int w, int h,
-                         int xorg, int yorg, XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    xorg = (x - xorg) & 0x07;
-    yorg = (y - yorg) & 0x07;
-
-    if (!(infoRec->Mono8x8PatternFillFlags &
-          HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-        if (infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS) {
-            int patx = pCache->pat0;
-            int paty = pCache->pat1;
-
-            XAARotateMonoPattern(&patx, &paty, xorg, yorg,
-                                 (infoRec->Mono8x8PatternFillFlags &
-                                  BIT_ORDER_IN_BYTE_MSBFIRST));
-            xorg = patx;
-            yorg = paty;
-        }
-        else {
-            int slot = (yorg << 3) + xorg;
-
-            xorg = pCache->x + pCache->offsets[slot].x;
-            yorg = pCache->y + pCache->offsets[slot].y;
-        }
-    }
-
-    (*infoRec->SubsequentMono8x8PatternFillRect) (pScrn, xorg, yorg,
-                                                  x, y, w, h);
-}
-
-        /****************\
-	|  Cache Expand  |
-	\****************/
-
-static void
-CacheExpandRectHelper(ScrnInfoPtr pScrn,
-                      int X, int Y, int Width, int Height,
-                      int xorg, int yorg, XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int x, phaseY, phaseX, skipleft, w, blit_w, blit_h;
-    int cacheWidth;
-
-    cacheWidth = (pCache->w * pScrn->bitsPerPixel) /
-        infoRec->CacheColorExpandDensity;
-
-    phaseY = (Y - yorg) % pCache->orig_h;
-    if (phaseY < 0)
-        phaseY += pCache->orig_h;
-    phaseX = (X - xorg) % pCache->orig_w;
-    if (phaseX < 0)
-        phaseX += pCache->orig_w;
-
-    while (1) {
-        w = Width;
-        skipleft = phaseX;
-        x = X;
-        blit_h = pCache->h - phaseY;
-        if (blit_h > Height)
-            blit_h = Height;
-
-        while (1) {
-            blit_w = cacheWidth - skipleft;
-            if (blit_w > w)
-                blit_w = w;
-            (*infoRec->SubsequentScreenToScreenColorExpandFill) (pScrn, x, Y,
-                                                                 blit_w, blit_h,
-                                                                 pCache->x,
-                                                                 pCache->y +
-                                                                 phaseY,
-                                                                 skipleft);
-            w -= blit_w;
-            if (!w)
-                break;
-            x += blit_w;
-            skipleft = (skipleft + blit_w) % pCache->orig_w;
-        }
-        Height -= blit_h;
-        if (!Height)
-            break;
-        Y += blit_h;
-        phaseY = (phaseY + blit_h) % pCache->orig_h;
-    }
-}
-
-        /**************\
-	|  Cache Blit  |
-	\**************/
-
-static void
-CacheBltRectHelper(ScrnInfoPtr pScrn,
-                   int X, int Y, int Width, int Height,
-                   int xorg, int yorg, XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int x, phaseY, phaseX, skipleft, w, blit_w, blit_h;
-
-    phaseY = (Y - yorg) % pCache->orig_h;
-    if (phaseY < 0)
-        phaseY += pCache->orig_h;
-    phaseX = (X - xorg) % pCache->orig_w;
-    if (phaseX < 0)
-        phaseX += pCache->orig_w;
-
-    while (1) {
-        w = Width;
-        skipleft = phaseX;
-        x = X;
-        blit_h = pCache->h - phaseY;
-        if (blit_h > Height)
-            blit_h = Height;
-
-        while (1) {
-            blit_w = pCache->w - skipleft;
-            if (blit_w > w)
-                blit_w = w;
-            (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                      pCache->x + skipleft,
-                                                      pCache->y + phaseY, x, Y,
-                                                      blit_w, blit_h);
-            w -= blit_w;
-            if (!w)
-                break;
-            x += blit_w;
-            skipleft = (skipleft + blit_w) % pCache->orig_w;
-        }
-        Height -= blit_h;
-        if (!Height)
-            break;
-        Y += blit_h;
-        phaseY = (phaseY + blit_h) % pCache->orig_h;
-    }
-}
-
-        /**********************\
-	|   Stippled Polygons  |
-	\**********************/
-
-void
-XAAFillPolygonStippled(DrawablePtr pDraw,
-                       GCPtr pGC,
-                       int shape, int mode, int count, DDXPointPtr ptsIn)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
-    int origin, type, patx, paty, fg, bg;
-    int y, maxy, xorg, yorg;
-    DDXPointPtr topPoint;
-    XAACacheInfoPtr pCache = NULL;
-    RectFuncPtr RectFunc = NULL;
-    TrapFuncPtr TrapFunc = NULL;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    if (mode == CoordModePrevious) {
-        register DDXPointPtr ppt = ptsIn + 1;
-
-        for (origin = 1; origin < count; origin++, ppt++) {
-            ppt->x += (ppt - 1)->x;
-            ppt->y += (ppt - 1)->y;
-        }
-        mode = CoordModeOrigin;
-    }
-
-    if (RegionNumRects(pGC->pCompositeClip) != 1) {
-        miFillPolygon(pDraw, pGC, shape, mode, count, ptsIn);
-        return;
-    }
-
-    if (pGC->fillStyle == FillStippled) {
-        type = (*infoRec->StippledFillChooser) (pGC);
-        fg = pGC->fgPixel;
-        bg = -1;
-    }
-    else {
-        type = (*infoRec->OpaqueStippledFillChooser) (pGC);
-        fg = pGC->fgPixel;
-        bg = pGC->bgPixel;
-    }
-
-    if (!type) {
-        (*XAAFallbackOps.FillPolygon) (pDraw, pGC, shape, mode, count, ptsIn);
-        return;
-    }
-
-    if ((type == DO_COLOR_EXPAND) || (type == DO_COLOR_8x8)) {
-        miFillPolygon(pDraw, pGC, shape, mode, count, ptsIn);
-        return;
-    }
-
-    origin = pDraw->x;
-
-    switch (XAAIsEasyPolygon(ptsIn, count, &pGC->pCompositeClip->extents,
-                             origin, &topPoint, &y, &maxy, shape)) {
-    case POLY_USE_MI:
-        miFillPolygon(pDraw, pGC, shape, mode, count, ptsIn);
-    case POLY_FULLY_CLIPPED:
-        return;
-    }
-
-    xorg = (pDraw->x + pGC->patOrg.x);
-    yorg = (pDraw->y + pGC->patOrg.y);
-
-    if ((fg == bg) && (bg != -1) && infoRec->SetupForSolidFill) {
-
-        (*infoRec->SetupForSolidFill) (infoRec->pScrn, fg,
-                                       pGC->alu, pGC->planemask);
-
-        RectFunc = SolidRectHelper;
-        TrapFunc = infoRec->SubsequentSolidFillTrap ? SolidTrapHelper : NULL;
-    }
-    else
-        switch (type) {
-        case DO_MONO_8x8:
-            patx = pPriv->pattern0;
-            paty = pPriv->pattern1;
-            if (infoRec->Mono8x8PatternFillFlags &
-                HARDWARE_PATTERN_SCREEN_ORIGIN) {
-                xorg = (-xorg) & 0x07;
-                yorg = (-yorg) & 0x07;
-                if (infoRec->Mono8x8PatternFillFlags &
-                    HARDWARE_PATTERN_PROGRAMMED_BITS) {
-                    if (!(infoRec->Mono8x8PatternFillFlags &
-                          HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-                        XAARotateMonoPattern(&patx, &paty, xorg, yorg,
-                                             (infoRec->Mono8x8PatternFillFlags &
-                                              BIT_ORDER_IN_BYTE_MSBFIRST));
-                        xorg = patx;
-                        yorg = paty;
-                    }
-                }
-                else {
-                    XAACacheInfoPtr pCache =
-                        (*infoRec->CacheMono8x8Pattern) (infoRec->pScrn, patx,
-                                                         paty);
-                    patx = pCache->x;
-                    paty = pCache->y;
-                    if (!(infoRec->Mono8x8PatternFillFlags &
-                          HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-                        int slot = (yorg << 3) + xorg;
-
-                        patx += pCache->offsets[slot].x;
-                        paty += pCache->offsets[slot].y;
-                        xorg = patx;
-                        yorg = paty;
-                    }
-                }
-                RectFunc = Mono8x8PatternRectHelper_ScreenOrigin;
-                if (infoRec->SubsequentMono8x8PatternFillTrap)
-                    TrapFunc = Mono8x8PatternTrapHelper_ScreenOrigin;
-            }
-            else {              /* !HARDWARE_PATTERN_SCREEN_ORIGIN */
-                if (!(infoRec->Mono8x8PatternFillFlags &
-                      HARDWARE_PATTERN_PROGRAMMED_BITS)) {
-                    pCache =
-                        (*infoRec->CacheMono8x8Pattern) (infoRec->pScrn, patx,
-                                                         paty);
-                    patx = pCache->x;
-                    paty = pCache->y;
-                }
-                else {
-                    pCache = &(infoRec->ScratchCacheInfoRec);
-                    pCache->pat0 = patx;
-                    pCache->pat1 = paty;
-                }
-                RectFunc = Mono8x8PatternRectHelper;
-            }
-
-            (*infoRec->SetupForMono8x8PatternFill) (infoRec->pScrn,
-                                                    patx, paty, fg, bg,
-                                                    pGC->alu, pGC->planemask);
-            break;
-        case DO_CACHE_EXPAND:
-            pCache =
-                (*infoRec->CacheMonoStipple) (infoRec->pScrn, pGC->stipple);
-
-            (*infoRec->SetupForScreenToScreenColorExpandFill) (infoRec->pScrn,
-                                                               fg, bg, pGC->alu,
-                                                               pGC->planemask);
-
-            RectFunc = CacheExpandRectHelper;
-            break;
-        case DO_CACHE_BLT:
-            pCache = (*infoRec->CacheStipple) (infoRec->pScrn, pGC->stipple,
-                                               fg, bg);
-            (*infoRec->SetupForScreenToScreenCopy) (infoRec->pScrn, 1, 1,
-                                                    pGC->alu, pGC->planemask,
-                                                    pCache->trans_color);
-
-            RectFunc = CacheBltRectHelper;
-            break;
-        default:
-            return;
-        }
-
-    XAAFillPolygonHelper(infoRec->pScrn, ptsIn, count, topPoint,
-                         y, maxy, origin, RectFunc, TrapFunc, xorg, yorg,
-                         pCache);
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /*******************\
-	|   Tiled Polygons  |
-	\*******************/
-
-void
-XAAFillPolygonTiled(DrawablePtr pDraw,
-                    GCPtr pGC,
-                    int shape, int mode, int count, DDXPointPtr ptsIn)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
-    int origin, type, patx, paty;
-    int y, maxy, xorg, yorg;
-    DDXPointPtr topPoint;
-    XAACacheInfoPtr pCache = NULL;
-    RectFuncPtr RectFunc = NULL;
-    TrapFuncPtr TrapFunc = NULL;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    if (mode == CoordModePrevious) {
-        register DDXPointPtr ppt = ptsIn + 1;
-
-        for (origin = 1; origin < count; origin++, ppt++) {
-            ppt->x += (ppt - 1)->x;
-            ppt->y += (ppt - 1)->y;
-        }
-        mode = CoordModeOrigin;
-    }
-
-    if (RegionNumRects(pGC->pCompositeClip) != 1) {
-        miFillPolygon(pDraw, pGC, shape, mode, count, ptsIn);
-        return;
-    }
-
-    type = (*infoRec->TiledFillChooser) (pGC);
-
-    if (!type || (type == DO_IMAGE_WRITE)) {
-        (*XAAFallbackOps.FillPolygon) (pDraw, pGC, shape, mode, count, ptsIn);
-        return;
-    }
-
-    if (type == DO_COLOR_8x8) {
-        miFillPolygon(pDraw, pGC, shape, mode, count, ptsIn);
-        return;
-    }
-
-    origin = pDraw->x;
-
-    switch (XAAIsEasyPolygon(ptsIn, count, &pGC->pCompositeClip->extents,
-                             origin, &topPoint, &y, &maxy, shape)) {
-    case POLY_USE_MI:
-        miFillPolygon(pDraw, pGC, shape, mode, count, ptsIn);
-    case POLY_FULLY_CLIPPED:
-        return;
-    }
-
-    xorg = (pDraw->x + pGC->patOrg.x);
-    yorg = (pDraw->y + pGC->patOrg.y);
-
-    switch (type) {
-    case DO_MONO_8x8:
-        patx = pPriv->pattern0;
-        paty = pPriv->pattern1;
-        if (infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_SCREEN_ORIGIN) {
-            xorg = (-xorg) & 0x07;
-            yorg = (-yorg) & 0x07;
-            if (infoRec->Mono8x8PatternFillFlags &
-                HARDWARE_PATTERN_PROGRAMMED_BITS) {
-                if (!(infoRec->Mono8x8PatternFillFlags &
-                      HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-                    XAARotateMonoPattern(&patx, &paty, xorg, yorg,
-                                         (infoRec->Mono8x8PatternFillFlags &
-                                          BIT_ORDER_IN_BYTE_MSBFIRST));
-                    xorg = patx;
-                    yorg = paty;
-                }
-            }
-            else {
-                XAACacheInfoPtr pCache =
-                    (*infoRec->CacheMono8x8Pattern) (infoRec->pScrn, patx,
-                                                     paty);
-                patx = pCache->x;
-                paty = pCache->y;
-                if (!(infoRec->Mono8x8PatternFillFlags &
-                      HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-                    int slot = (yorg << 3) + xorg;
-
-                    patx += pCache->offsets[slot].x;
-                    paty += pCache->offsets[slot].y;
-                    xorg = patx;
-                    yorg = paty;
-                }
-            }
-            RectFunc = Mono8x8PatternRectHelper_ScreenOrigin;
-            if (infoRec->SubsequentMono8x8PatternFillTrap)
-                TrapFunc = Mono8x8PatternTrapHelper_ScreenOrigin;
-        }
-        else {                  /* !HARDWARE_PATTERN_SCREEN_ORIGIN */
-            if (!(infoRec->Mono8x8PatternFillFlags &
-                  HARDWARE_PATTERN_PROGRAMMED_BITS)) {
-                pCache =
-                    (*infoRec->CacheMono8x8Pattern) (infoRec->pScrn, patx,
-                                                     paty);
-                patx = pCache->x;
-                paty = pCache->y;
-            }
-            else {
-                pCache = &(infoRec->ScratchCacheInfoRec);
-                pCache->pat0 = patx;
-                pCache->pat1 = paty;
-            }
-            RectFunc = Mono8x8PatternRectHelper;
-        }
-
-        (*infoRec->SetupForMono8x8PatternFill) (infoRec->pScrn,
-                                                patx, paty, pPriv->fg,
-                                                pPriv->bg, pGC->alu,
-                                                pGC->planemask);
-        break;
-    case DO_CACHE_BLT:
-        pCache = (*infoRec->CacheTile) (infoRec->pScrn, pGC->tile.pixmap);
-        (*infoRec->SetupForScreenToScreenCopy) (infoRec->pScrn, 1, 1,
-                                                pGC->alu, pGC->planemask, -1);
-
-        RectFunc = CacheBltRectHelper;
-        break;
-    case DO_PIXMAP_COPY:
-        pCache = &(infoRec->ScratchCacheInfoRec);
-        pCache->x = pPriv->offscreenArea->box.x1;
-        pCache->y = pPriv->offscreenArea->box.y1;
-        pCache->w = pCache->orig_w = pPriv->offscreenArea->box.x2 - pCache->x;
-        pCache->h = pCache->orig_h = pPriv->offscreenArea->box.y2 - pCache->y;
-
-        (*infoRec->SetupForScreenToScreenCopy) (infoRec->pScrn, 1, 1,
-                                                pGC->alu, pGC->planemask, -1);
-
-        RectFunc = CacheBltRectHelper;
-        break;
-    default:
-        return;
-    }
-
-    XAAFillPolygonHelper(infoRec->pScrn, ptsIn, count, topPoint,
-                         y, maxy, origin, RectFunc, TrapFunc, xorg, yorg,
-                         pCache);
-
-    SET_SYNC_FLAG(infoRec);
-}
diff --git a/hw/xfree86/xaa/xaaFillRect.c b/hw/xfree86/xaa/xaaFillRect.c
deleted file mode 100644
index ec0fb9d..0000000
--- a/hw/xfree86/xaa/xaaFillRect.c
+++ /dev/null
@@ -1,1101 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-
-static void XAARenderSolidRects(GCPtr, int, BoxPtr, int, int);
-static void XAARenderColor8x8Rects(GCPtr, int, BoxPtr, int, int);
-static void XAARenderMono8x8Rects(GCPtr, int, BoxPtr, int, int);
-static void XAARenderColorExpandRects(GCPtr, int, BoxPtr, int, int);
-static void XAARenderCacheExpandRects(GCPtr, int, BoxPtr, int, int);
-static void XAARenderCacheBltRects(GCPtr, int, BoxPtr, int, int);
-static void XAARenderImageWriteRects(GCPtr, int, BoxPtr, int, int);
-static void XAARenderPixmapCopyRects(GCPtr, int, BoxPtr, int, int);
-
-void
-XAAPolyFillRect(DrawablePtr pDraw, GCPtr pGC, int nrectFill,    /* number of rectangles to fill */
-                xRectangle *prectInit   /* Pointer to first rectangle to fill */
-    )
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int xorg = pDraw->x;
-    int yorg = pDraw->y;
-    int type = 0;
-    ClipAndRenderRectsFunc function;
-
-    if ((nrectFill <= 0) || !pGC->planemask)
-        return;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    switch (pGC->fillStyle) {
-    case FillSolid:
-        type = DO_SOLID;
-        break;
-    case FillStippled:
-        type = (*infoRec->StippledFillChooser) (pGC);
-        break;
-    case FillOpaqueStippled:
-        if ((pGC->fgPixel == pGC->bgPixel) && infoRec->FillSolidRects &&
-            CHECK_PLANEMASK(pGC, infoRec->FillSolidRectsFlags) &&
-            CHECK_ROP(pGC, infoRec->FillSolidRectsFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->FillSolidRectsFlags) &&
-            CHECK_FG(pGC, infoRec->FillSolidRectsFlags))
-            type = DO_SOLID;
-        else
-            type = (*infoRec->OpaqueStippledFillChooser) (pGC);
-        break;
-    case FillTiled:
-        type = (*infoRec->TiledFillChooser) (pGC);
-        break;
-    }
-
-    switch (type) {
-    case DO_SOLID:
-        function = XAARenderSolidRects;
-        break;
-    case DO_COLOR_8x8:
-        function = XAARenderColor8x8Rects;
-        break;
-    case DO_MONO_8x8:
-        function = XAARenderMono8x8Rects;
-        break;
-    case DO_CACHE_BLT:
-        function = XAARenderCacheBltRects;
-        break;
-    case DO_COLOR_EXPAND:
-        function = XAARenderColorExpandRects;
-        break;
-    case DO_CACHE_EXPAND:
-        function = XAARenderCacheExpandRects;
-        break;
-    case DO_IMAGE_WRITE:
-        function = XAARenderImageWriteRects;
-        break;
-    case DO_PIXMAP_COPY:
-        function = XAARenderPixmapCopyRects;
-        break;
-    default:
-        (*XAAFallbackOps.PolyFillRect) (pDraw, pGC, nrectFill, prectInit);
-        return;
-    }
-
-    if (xorg | yorg) {
-        int n = nrectFill;
-        xRectangle *prect = prectInit;
-
-        while (n--) {
-            prect->x += xorg;
-            prect->y += yorg;
-            prect++;
-        }
-    }
-
-    XAAClipAndRenderRects(pGC, function, nrectFill, prectInit, xorg, yorg);
-}
-
-        /*********************\
-	|     Solid Rects     |
-	\*********************/
-
-static void
-XAARenderSolidRects(GCPtr pGC,
-                    int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    (*infoRec->FillSolidRects) (infoRec->pScrn,
-                                pGC->fgPixel, pGC->alu, pGC->planemask, nboxes,
-                                pClipBoxes);
-}
-
-        /************************\
-	|     Mono 8x8 Rects     |
-	\************************/
-
-static void
-XAARenderMono8x8Rects(GCPtr pGC,
-                      int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAAPixmapPtr pPriv;
-    int fg, bg;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
-        fg = pGC->fgPixel;
-        bg = -1;
-        break;
-    case FillOpaqueStippled:
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
-        fg = pGC->fgPixel;
-        bg = pGC->bgPixel;
-        break;
-    case FillTiled:
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
-        fg = pPriv->fg;
-        bg = pPriv->bg;
-        break;
-    default:                   /* Muffle compiler */
-        pPriv = NULL;           /* Kaboom */
-        fg = -1;
-        bg = -1;
-        break;
-    }
-
-    (*infoRec->FillMono8x8PatternRects) (infoRec->pScrn,
-                                         fg, bg, pGC->alu, pGC->planemask,
-                                         nboxes, pClipBoxes, pPriv->pattern0,
-                                         pPriv->pattern1,
-                                         (xorg + pGC->patOrg.x),
-                                         (yorg + pGC->patOrg.y));
-}
-
-        /*************************\
-	|     Color 8x8 Rects     |
-	\*************************/
-
-static void
-XAARenderColor8x8Rects(GCPtr pGC,
-                       int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAACacheInfoPtr pCache;
-    PixmapPtr pPix;
-    int fg, bg;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        pPix = pGC->stipple;
-        fg = pGC->fgPixel;
-        bg = -1;
-        break;
-    case FillOpaqueStippled:
-        pPix = pGC->stipple;
-        fg = pGC->fgPixel;
-        bg = pGC->bgPixel;
-        break;
-    case FillTiled:
-        pPix = pGC->tile.pixmap;
-        fg = -1;
-        bg = -1;
-        break;
-    default:                   /* Muffle compiler */
-        pPix = NULL;
-        fg = -1;
-        bg = -1;
-        break;
-    }
-
-    pCache = (*infoRec->CacheColor8x8Pattern) (infoRec->pScrn, pPix, fg, bg);
-    (*infoRec->FillColor8x8PatternRects) (infoRec->pScrn,
-                                          pGC->alu, pGC->planemask, nboxes,
-                                          pClipBoxes, (xorg + pGC->patOrg.x),
-                                          (yorg + pGC->patOrg.y), pCache);
-}
-
-        /****************************\
-	|     Color Expand Rects     |
-	\****************************/
-
-static void
-XAARenderColorExpandRects(GCPtr pGC,
-                          int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int fg, bg;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        fg = pGC->fgPixel;
-        bg = -1;
-        break;
-    case FillOpaqueStippled:
-        fg = pGC->fgPixel;
-        bg = pGC->bgPixel;
-        break;
-    default:                   /* Muffle compiler */
-        fg = -1;
-        bg = -1;
-        break;
-    }
-
-    (*infoRec->FillColorExpandRects) (infoRec->pScrn, fg, bg,
-                                      pGC->alu, pGC->planemask, nboxes,
-                                      pClipBoxes, (xorg + pGC->patOrg.x),
-                                      (yorg + pGC->patOrg.y), pGC->stipple);
-}
-
-        /*************************\
-	|     Cache Blt Rects     |
-	\*************************/
-
-static void
-XAARenderCacheBltRects(GCPtr pGC,
-                       int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAACacheInfoPtr pCache;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        pCache = (*infoRec->CacheStipple) (infoRec->pScrn, pGC->stipple,
-                                           pGC->fgPixel, -1);
-        break;
-    case FillOpaqueStippled:
-        pCache = (*infoRec->CacheStipple) (infoRec->pScrn, pGC->stipple,
-                                           pGC->fgPixel, pGC->bgPixel);
-        break;
-    case FillTiled:
-        pCache = (*infoRec->CacheTile) (infoRec->pScrn, pGC->tile.pixmap);
-        break;
-    default:                   /* Muffle compiler */
-        pCache = NULL;
-        break;
-    }
-
-    (*infoRec->FillCacheBltRects) (infoRec->pScrn, pGC->alu,
-                                   pGC->planemask, nboxes, pClipBoxes,
-                                   (xorg + pGC->patOrg.x),
-                                   (yorg + pGC->patOrg.y), pCache);
-}
-
-        /****************************\
-	|     Cache Expand Rects     |
-	\****************************/
-
-static void
-XAARenderCacheExpandRects(GCPtr pGC,
-                          int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int fg, bg;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        fg = pGC->fgPixel;
-        bg = -1;
-        break;
-    case FillOpaqueStippled:
-        fg = pGC->fgPixel;
-        bg = pGC->bgPixel;
-        break;
-    default:                   /* Muffle compiler */
-        fg = -1;
-        bg = -1;
-        break;
-    }
-
-    (*infoRec->FillCacheExpandRects) (infoRec->pScrn, fg, bg,
-                                      pGC->alu, pGC->planemask, nboxes,
-                                      pClipBoxes, (xorg + pGC->patOrg.x),
-                                      (yorg + pGC->patOrg.y), pGC->stipple);
-}
-
-        /***************************\
-	|     Image Write Rects     |
-	\***************************/
-
-static void
-XAARenderImageWriteRects(GCPtr pGC,
-                         int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    (*infoRec->FillImageWriteRects) (infoRec->pScrn, pGC->alu,
-                                     pGC->planemask, nboxes, pClipBoxes,
-                                     (xorg + pGC->patOrg.x),
-                                     (yorg + pGC->patOrg.y), pGC->tile.pixmap);
-}
-
-        /***************************\
-	|     Pixmap Copy Rects     |
-	\***************************/
-
-static void
-XAARenderPixmapCopyRects(GCPtr pGC,
-                         int nboxes, BoxPtr pClipBoxes, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAACacheInfoPtr pCache = &(infoRec->ScratchCacheInfoRec);
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
-
-    pCache->x = pPriv->offscreenArea->box.x1;
-    pCache->y = pPriv->offscreenArea->box.y1;
-    pCache->w = pCache->orig_w = pPriv->offscreenArea->box.x2 - pCache->x;
-    pCache->h = pCache->orig_h = pPriv->offscreenArea->box.y2 - pCache->y;
-    pCache->trans_color = -1;
-
-    (*infoRec->FillCacheBltRects) (infoRec->pScrn, pGC->alu,
-                                   pGC->planemask, nboxes, pClipBoxes,
-                                   (xorg + pGC->patOrg.x),
-                                   (yorg + pGC->patOrg.y), pCache);
-}
-
-        /************\
-	|   Solid    |
-	\************/
-
-void
-XAAFillSolidRects(ScrnInfoPtr pScrn, int fg, int rop, unsigned int planemask, int nBox, /* number of rectangles to fill */
-                  BoxPtr pBox   /* Pointer to first rectangle to fill */
-    )
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    (*infoRec->SetupForSolidFill) (pScrn, fg, rop, planemask);
-    while (nBox--) {
-        (*infoRec->SubsequentSolidFillRect) (pScrn, pBox->x1, pBox->y1,
-                                             pBox->x2 - pBox->x1,
-                                             pBox->y2 - pBox->y1);
-        pBox++;
-    }
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /*********************\
-	|  8x8 Mono Patterns  |
-	\*********************/
-
-void
-XAAFillMono8x8PatternRectsScreenOrigin(ScrnInfoPtr pScrn,
-                                       int fg, int bg, int rop,
-                                       unsigned int planemask,
-                                       int nBox,
-                                       BoxPtr pBox,
-                                       int pattern0, int pattern1,
-                                       int xorigin, int yorigin)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int patx = pattern0, paty = pattern1;
-    int xorg = (-xorigin) & 0x07;
-    int yorg = (-yorigin) & 0x07;
-
-    if (infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS) {
-        if (!(infoRec->Mono8x8PatternFillFlags &
-              HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-            XAARotateMonoPattern(&patx, &paty, xorg, yorg,
-                                 (infoRec->Mono8x8PatternFillFlags &
-                                  BIT_ORDER_IN_BYTE_MSBFIRST));
-            xorg = patx;
-            yorg = paty;
-        }
-    }
-    else {
-        XAACacheInfoPtr pCache =
-            (*infoRec->CacheMono8x8Pattern) (pScrn, pattern0, pattern1);
-        patx = pCache->x;
-        paty = pCache->y;
-        if (!(infoRec->Mono8x8PatternFillFlags &
-              HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-            int slot = (yorg << 3) + xorg;
-
-            patx += pCache->offsets[slot].x;
-            paty += pCache->offsets[slot].y;
-            xorg = patx;
-            yorg = paty;
-        }
-    }
-
-    (*infoRec->SetupForMono8x8PatternFill) (pScrn, patx, paty,
-                                            fg, bg, rop, planemask);
-
-    while (nBox--) {
-        (*infoRec->SubsequentMono8x8PatternFillRect) (pScrn,
-                                                      xorg, yorg, pBox->x1,
-                                                      pBox->y1,
-                                                      pBox->x2 - pBox->x1,
-                                                      pBox->y2 - pBox->y1);
-        pBox++;
-    }
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAAFillMono8x8PatternRects(ScrnInfoPtr pScrn,
-                           int fg, int bg, int rop,
-                           unsigned int planemask,
-                           int nBox,
-                           BoxPtr pBox,
-                           int pattern0, int pattern1, int xorigin, int yorigin)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int patx = pattern0, paty = pattern1;
-    int xorg, yorg;
-    XAACacheInfoPtr pCache = NULL;
-
-    if (!(infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS)) {
-        pCache = (*infoRec->CacheMono8x8Pattern) (pScrn, pattern0, pattern1);
-        patx = pCache->x;
-        paty = pCache->y;
-    }
-
-    (*infoRec->SetupForMono8x8PatternFill) (pScrn, patx, paty,
-                                            fg, bg, rop, planemask);
-
-    while (nBox--) {
-        xorg = (pBox->x1 - xorigin) & 0x07;
-        yorg = (pBox->y1 - yorigin) & 0x07;
-
-        if (!(infoRec->Mono8x8PatternFillFlags &
-              HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-            if (infoRec->Mono8x8PatternFillFlags &
-                HARDWARE_PATTERN_PROGRAMMED_BITS) {
-                patx = pattern0;
-                paty = pattern1;
-                XAARotateMonoPattern(&patx, &paty, xorg, yorg,
-                                     (infoRec->Mono8x8PatternFillFlags &
-                                      BIT_ORDER_IN_BYTE_MSBFIRST));
-                xorg = patx;
-                yorg = paty;
-            }
-            else {
-                int slot = (yorg << 3) + xorg;
-
-                xorg = patx + pCache->offsets[slot].x;
-                yorg = paty + pCache->offsets[slot].y;
-            }
-        }
-
-        (*infoRec->SubsequentMono8x8PatternFillRect) (pScrn,
-                                                      xorg, yorg, pBox->x1,
-                                                      pBox->y1,
-                                                      pBox->x2 - pBox->x1,
-                                                      pBox->y2 - pBox->y1);
-        pBox++;
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /**********************\
-	|  8x8 Color Patterns  |
-	\**********************/
-
-void
-XAAFillColor8x8PatternRectsScreenOrigin(ScrnInfoPtr pScrn,
-                                        int rop,
-                                        unsigned int planemask,
-                                        int nBox,
-                                        BoxPtr pBox,
-                                        int xorigin, int yorigin,
-                                        XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int patx = pCache->x, paty = pCache->y;
-    int xorg = (-xorigin) & 0x07;
-    int yorg = (-yorigin) & 0x07;
-
-    if (!(infoRec->Color8x8PatternFillFlags &
-          HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-        int slot = (yorg << 3) + xorg;
-
-        paty += pCache->offsets[slot].y;
-        patx += pCache->offsets[slot].x;
-        xorg = patx;
-        yorg = paty;
-    }
-
-    (*infoRec->SetupForColor8x8PatternFill) (pScrn, patx, paty,
-                                             rop, planemask,
-                                             pCache->trans_color);
-
-    while (nBox--) {
-        (*infoRec->SubsequentColor8x8PatternFillRect) (pScrn,
-                                                       xorg, yorg, pBox->x1,
-                                                       pBox->y1,
-                                                       pBox->x2 - pBox->x1,
-                                                       pBox->y2 - pBox->y1);
-        pBox++;
-    }
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAAFillColor8x8PatternRects(ScrnInfoPtr pScrn,
-                            int rop,
-                            unsigned int planemask,
-                            int nBox,
-                            BoxPtr pBox,
-                            int xorigin, int yorigin, XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int xorg, yorg;
-
-    (*infoRec->SetupForColor8x8PatternFill) (pScrn, pCache->x, pCache->y,
-                                             rop, planemask,
-                                             pCache->trans_color);
-
-    while (nBox--) {
-        xorg = (pBox->x1 - xorigin) & 0x07;
-        yorg = (pBox->y1 - yorigin) & 0x07;
-
-        if (!(infoRec->Color8x8PatternFillFlags &
-              HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-            int slot = (yorg << 3) + xorg;
-
-            yorg = pCache->y + pCache->offsets[slot].y;
-            xorg = pCache->x + pCache->offsets[slot].x;
-        }
-
-        (*infoRec->SubsequentColor8x8PatternFillRect) (pScrn,
-                                                       xorg, yorg, pBox->x1,
-                                                       pBox->y1,
-                                                       pBox->x2 - pBox->x1,
-                                                       pBox->y2 - pBox->y1);
-        pBox++;
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /***************\
-	|  Cache Blits  |
-	\***************/
-
-void
-XAAFillCacheBltRects(ScrnInfoPtr pScrn,
-                     int rop,
-                     unsigned int planemask,
-                     int nBox,
-                     BoxPtr pBox, int xorg, int yorg, XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int x, y, phaseY, phaseX, skipleft, height, width, w, blit_w, blit_h;
-
-    (*infoRec->SetupForScreenToScreenCopy) (pScrn, 1, 1, rop, planemask,
-                                            pCache->trans_color);
-
-    while (nBox--) {
-        y = pBox->y1;
-        phaseY = (y - yorg) % pCache->orig_h;
-        if (phaseY < 0)
-            phaseY += pCache->orig_h;
-        phaseX = (pBox->x1 - xorg) % pCache->orig_w;
-        if (phaseX < 0)
-            phaseX += pCache->orig_w;
-        height = pBox->y2 - y;
-        width = pBox->x2 - pBox->x1;
-
-#if 0
-        if (rop == GXcopy) {
-            while (1) {
-                w = width;
-                skipleft = phaseX;
-                x = pBox->x1;
-                blit_h = pCache->h - phaseY;
-                if (blit_h > height)
-                    blit_h = height;
-
-                while (1) {
-                    blit_w = pCache->w - skipleft;
-                    if (blit_w > w)
-                        blit_w = w;
-                    (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                              pCache->x +
-                                                              skipleft,
-                                                              pCache->y +
-                                                              phaseY, x, y,
-                                                              blit_w, blit_h);
-                    w -= blit_w;
-                    if (!w)
-                        break;
-                    x += blit_w;
-                    skipleft = (skipleft + blit_w) % pCache->orig_w;
-                    if (blit_w >= pCache->orig_w)
-                        break;
-                }
-
-                /* Expand horizontally */
-                if (w) {
-                    skipleft -= phaseX;
-                    if (skipleft < 0)
-                        skipleft += pCache->orig_w;
-                    blit_w = x - pBox->x1 - skipleft;
-                    while (w) {
-                        if (blit_w > w)
-                            blit_w = w;
-                        (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                                  pBox->x1 +
-                                                                  skipleft, y,
-                                                                  x, y, blit_w,
-                                                                  blit_h);
-                        w -= blit_w;
-                        x += blit_w;
-                        blit_w <<= 1;
-                    }
-                }
-
-                height -= blit_h;
-                if (!height)
-                    break;
-                y += blit_h;
-                phaseY = (phaseY + blit_h) % pCache->orig_h;
-                if (blit_h >= pCache->orig_h)
-                    break;
-            }
-
-            /* Expand vertically */
-            if (height) {
-                blit_w = pBox->x2 - pBox->x1;
-                phaseY -= (pBox->y1 - yorg) % pCache->orig_h;
-                if (phaseY < 0)
-                    phaseY += pCache->orig_h;
-                blit_h = y - pBox->y1 - phaseY;
-                while (height) {
-                    if (blit_h > height)
-                        blit_h = height;
-                    (*infoRec->SubsequentScreenToScreenCopy) (pScrn, pBox->x1,
-                                                              pBox->y1 + phaseY,
-                                                              pBox->x1, y,
-                                                              blit_w, blit_h);
-                    height -= blit_h;
-                    y += blit_h;
-                    blit_h <<= 1;
-                }
-            }
-        }
-        else
-#endif
-        {
-            while (1) {
-                w = width;
-                skipleft = phaseX;
-                x = pBox->x1;
-                blit_h = pCache->h - phaseY;
-                if (blit_h > height)
-                    blit_h = height;
-
-                while (1) {
-                    blit_w = pCache->w - skipleft;
-                    if (blit_w > w)
-                        blit_w = w;
-                    (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                              pCache->x +
-                                                              skipleft,
-                                                              pCache->y +
-                                                              phaseY, x, y,
-                                                              blit_w, blit_h);
-                    w -= blit_w;
-                    if (!w)
-                        break;
-                    x += blit_w;
-                    skipleft = (skipleft + blit_w) % pCache->orig_w;
-                }
-                height -= blit_h;
-                if (!height)
-                    break;
-                y += blit_h;
-                phaseY = (phaseY + blit_h) % pCache->orig_h;
-            }
-        }
-        pBox++;
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /*******************\
-	|  Cache Expansion  |
-	\*******************/
-
-void
-XAAFillCacheExpandRects(ScrnInfoPtr pScrn,
-                        int fg, int bg, int rop,
-                        unsigned int planemask,
-                        int nBox,
-                        BoxPtr pBox, int xorg, int yorg, PixmapPtr pPix)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int x, y, phaseY, phaseX, skipleft, height, width, w, blit_w, blit_h;
-    int cacheWidth;
-    XAACacheInfoPtr pCache;
-
-    pCache = (*infoRec->CacheMonoStipple) (pScrn, pPix);
-
-    cacheWidth = (pCache->w * pScrn->bitsPerPixel) /
-        infoRec->CacheColorExpandDensity;
-
-    (*infoRec->SetupForScreenToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                       planemask);
-
-    while (nBox--) {
-        y = pBox->y1;
-        phaseY = (y - yorg) % pCache->orig_h;
-        if (phaseY < 0)
-            phaseY += pCache->orig_h;
-        phaseX = (pBox->x1 - xorg) % pCache->orig_w;
-        if (phaseX < 0)
-            phaseX += pCache->orig_w;
-        height = pBox->y2 - y;
-        width = pBox->x2 - pBox->x1;
-
-        while (1) {
-            w = width;
-            skipleft = phaseX;
-            x = pBox->x1;
-            blit_h = pCache->h - phaseY;
-            if (blit_h > height)
-                blit_h = height;
-
-            while (1) {
-                blit_w = cacheWidth - skipleft;
-                if (blit_w > w)
-                    blit_w = w;
-                (*infoRec->SubsequentScreenToScreenColorExpandFill) (pScrn, x,
-                                                                     y, blit_w,
-                                                                     blit_h,
-                                                                     pCache->x,
-                                                                     pCache->y +
-                                                                     phaseY,
-                                                                     skipleft);
-                w -= blit_w;
-                if (!w)
-                    break;
-                x += blit_w;
-                skipleft = (skipleft + blit_w) % pCache->orig_w;
-            }
-            height -= blit_h;
-            if (!height)
-                break;
-            y += blit_h;
-            phaseY = (phaseY + blit_h) % pCache->orig_h;
-        }
-        pBox++;
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /******************\
-	|   Image Writes   |
-	\******************/
-
-/*  This requires all LEFT_EDGE clipping.  You get too many problems
-    with reading past the edge of the pattern otherwise */
-
-static void
-WriteColumn(ScrnInfoPtr pScrn,
-            unsigned char *pSrc,
-            int x, int y, int w, int h,
-            int xoff, int yoff, int pHeight, int srcwidth, int Bpp)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    unsigned char *src;
-    Bool PlusOne = FALSE;
-    int skipleft, dwords;
-
-    pSrc += (Bpp * xoff);
-
-    if ((skipleft = (long) pSrc & 0x03L)) {
-        if (Bpp == 3)
-            skipleft = 4 - skipleft;
-        else
-            skipleft /= Bpp;
-
-        x -= skipleft;
-        w += skipleft;
-
-        if (Bpp == 3)
-            pSrc -= 3 * skipleft;
-        else                    /* is this Alpha friendly ? */
-            pSrc = (unsigned char *) ((long) pSrc & ~0x03L);
-    }
-
-    src = pSrc + (yoff * srcwidth);
-
-    dwords = bytes_to_int32(w * Bpp);
-
-    if ((infoRec->ImageWriteFlags & CPU_TRANSFER_PAD_QWORD) &&
-        ((dwords * h) & 0x01)) {
-        PlusOne = TRUE;
-    }
-
-    (*infoRec->SubsequentImageWriteRect) (pScrn, x, y, w, h, skipleft);
-
-    if (dwords > infoRec->ImageWriteRange) {
-        while (h--) {
-            XAAMoveDWORDS_FixedBase((CARD32 *) infoRec->ImageWriteBase,
-                                    (CARD32 *) src, dwords);
-            src += srcwidth;
-            yoff++;
-            if (yoff >= pHeight) {
-                yoff = 0;
-                src = pSrc;
-            }
-        }
-    }
-    else {
-        if (srcwidth == (dwords << 2)) {
-            int maxLines = infoRec->ImageWriteRange / dwords;
-            int step;
-
-            while (h) {
-                step = pHeight - yoff;
-                if (step > maxLines)
-                    step = maxLines;
-                if (step > h)
-                    step = h;
-
-                XAAMoveDWORDS((CARD32 *) infoRec->ImageWriteBase,
-                              (CARD32 *) src, dwords * step);
-
-                src += (srcwidth * step);
-                yoff += step;
-                if (yoff >= pHeight) {
-                    yoff = 0;
-                    src = pSrc;
-                }
-                h -= step;
-            }
-        }
-        else {
-            while (h--) {
-                XAAMoveDWORDS((CARD32 *) infoRec->ImageWriteBase,
-                              (CARD32 *) src, dwords);
-                src += srcwidth;
-                yoff++;
-                if (yoff >= pHeight) {
-                    yoff = 0;
-                    src = pSrc;
-                }
-            }
-        }
-    }
-
-    if (PlusOne) {
-        CARD32 *base = (CARD32 *) infoRec->ImageWriteBase;
-
-        *base = 0x00000000;
-    }
-}
-
-void
-XAAFillImageWriteRects(ScrnInfoPtr pScrn,
-                       int rop,
-                       unsigned int planemask,
-                       int nBox,
-                       BoxPtr pBox, int xorg, int yorg, PixmapPtr pPix)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int x, phaseY, phaseX, height, width, blit_w;
-    int pHeight = pPix->drawable.height;
-    int pWidth = pPix->drawable.width;
-    int Bpp = pPix->drawable.bitsPerPixel >> 3;
-    int srcwidth = pPix->devKind;
-
-    (*infoRec->SetupForImageWrite) (pScrn, rop, planemask, -1,
-                                    pPix->drawable.bitsPerPixel,
-                                    pPix->drawable.depth);
-
-    while (nBox--) {
-        x = pBox->x1;
-        phaseY = (pBox->y1 - yorg) % pHeight;
-        if (phaseY < 0)
-            phaseY += pHeight;
-        phaseX = (x - xorg) % pWidth;
-        if (phaseX < 0)
-            phaseX += pWidth;
-        height = pBox->y2 - pBox->y1;
-        width = pBox->x2 - x;
-
-        while (1) {
-            blit_w = pWidth - phaseX;
-            if (blit_w > width)
-                blit_w = width;
-
-            WriteColumn(pScrn, pPix->devPrivate.ptr, x, pBox->y1,
-                        blit_w, height, phaseX, phaseY, pHeight, srcwidth, Bpp);
-
-            width -= blit_w;
-            if (!width)
-                break;
-            x += blit_w;
-            phaseX = (phaseX + blit_w) % pWidth;
-        }
-        pBox++;
-    }
-
-    if (infoRec->ImageWriteFlags & SYNC_AFTER_IMAGE_WRITE)
-        (*infoRec->Sync) (pScrn);
-    else
-        SET_SYNC_FLAG(infoRec);
-}
-
-        /*************\
-	|  Utilities  |
-	\*************/
-
-void
-XAAClipAndRenderRects(GCPtr pGC,
-                      ClipAndRenderRectsFunc BoxFunc,
-                      int nrectFill, xRectangle *prect, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int Right, Bottom, MaxBoxes;
-    BoxPtr pextent, pboxClipped, pboxClippedBase;
-
-    MaxBoxes = infoRec->PreAllocSize / sizeof(BoxRec);
-    pboxClippedBase = (BoxPtr) infoRec->PreAllocMem;
-    pboxClipped = pboxClippedBase;
-
-    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);
-
-            Right = (int) prect->x + (int) prect->width;
-            pboxClipped->x2 = min(pextent->x2, Right);
-
-            Bottom = (int) prect->y + (int) prect->height;
-            pboxClipped->y2 = min(pextent->y2, Bottom);
-
-            prect++;
-            if ((pboxClipped->x1 < pboxClipped->x2) &&
-                (pboxClipped->y1 < pboxClipped->y2)) {
-                pboxClipped++;
-                if (pboxClipped >= (pboxClippedBase + MaxBoxes)) {
-                    (*BoxFunc) (pGC, MaxBoxes, pboxClippedBase, xorg, yorg);
-                    pboxClipped = pboxClippedBase;
-                }
-            }
-        }
-    }
-    else {
-        pextent = RegionExtents(pGC->pCompositeClip);
-        while (nrectFill--) {
-            int n;
-            BoxRec box, *pbox;
-
-            box.x1 = max(pextent->x1, prect->x);
-            box.y1 = max(pextent->y1, prect->y);
-
-            Right = (int) prect->x + (int) prect->width;
-            box.x2 = min(pextent->x2, Right);
-
-            Bottom = (int) prect->y + (int) prect->height;
-            box.y2 = min(pextent->y2, Bottom);
-
-            prect++;
-
-            if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
-                continue;
-
-            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()
-             */
-            while (n--) {
-                pboxClipped->x1 = max(box.x1, pbox->x1);
-                pboxClipped->y1 = max(box.y1, pbox->y1);
-                pboxClipped->x2 = min(box.x2, pbox->x2);
-                pboxClipped->y2 = min(box.y2, pbox->y2);
-                pbox++;
-
-                /* see if clipping left anything */
-                if (pboxClipped->x1 < pboxClipped->x2 &&
-                    pboxClipped->y1 < pboxClipped->y2) {
-                    pboxClipped++;
-                    if (pboxClipped >= (pboxClippedBase + MaxBoxes)) {
-                        (*BoxFunc) (pGC, MaxBoxes, pboxClippedBase, xorg, yorg);
-                        pboxClipped = pboxClippedBase;
-                    }
-                }
-            }
-        }
-    }
-
-    if (pboxClipped != pboxClippedBase)
-        (*BoxFunc) (pGC, pboxClipped - pboxClippedBase, pboxClippedBase,
-                    xorg, yorg);
-}
-
-int
-XAAGetRectClipBoxes(GCPtr pGC,
-                    BoxPtr pboxClippedBase,
-                    int nrectFill, xRectangle *prectInit)
-{
-    int Right, Bottom;
-    BoxPtr pextent, pboxClipped = pboxClippedBase;
-    xRectangle *prect = prectInit;
-    RegionPtr prgnClip = pGC->pCompositeClip;
-
-    if (RegionNumRects(prgnClip) == 1) {
-        pextent = RegionRects(prgnClip);
-        while (nrectFill--) {
-            pboxClipped->x1 = max(pextent->x1, prect->x);
-            pboxClipped->y1 = max(pextent->y1, prect->y);
-
-            Right = (int) prect->x + (int) prect->width;
-            pboxClipped->x2 = min(pextent->x2, Right);
-
-            Bottom = (int) prect->y + (int) prect->height;
-            pboxClipped->y2 = min(pextent->y2, Bottom);
-
-            prect++;
-            if ((pboxClipped->x1 < pboxClipped->x2) &&
-                (pboxClipped->y1 < pboxClipped->y2)) {
-                pboxClipped++;
-            }
-        }
-    }
-    else {
-        pextent = RegionExtents(prgnClip);
-        while (nrectFill--) {
-            int n;
-            BoxRec box, *pbox;
-
-            box.x1 = max(pextent->x1, prect->x);
-            box.y1 = max(pextent->y1, prect->y);
-
-            Right = (int) prect->x + (int) prect->width;
-            box.x2 = min(pextent->x2, Right);
-
-            Bottom = (int) prect->y + (int) prect->height;
-            box.y2 = min(pextent->y2, Bottom);
-
-            prect++;
-
-            if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
-                continue;
-
-            n = RegionNumRects(prgnClip);
-            pbox = RegionRects(prgnClip);
-
-            /* clip the rectangle to each box in the clip region
-               this is logically equivalent to calling Intersect()
-             */
-            while (n--) {
-                pboxClipped->x1 = max(box.x1, pbox->x1);
-                pboxClipped->y1 = max(box.y1, pbox->y1);
-                pboxClipped->x2 = min(box.x2, pbox->x2);
-                pboxClipped->y2 = min(box.y2, pbox->y2);
-                pbox++;
-
-                /* see if clipping left anything */
-                if (pboxClipped->x1 < pboxClipped->x2 &&
-                    pboxClipped->y1 < pboxClipped->y2) {
-                    pboxClipped++;
-                }
-            }
-        }
-    }
-
-    return pboxClipped - pboxClippedBase;
-}
diff --git a/hw/xfree86/xaa/xaaGC.c b/hw/xfree86/xaa/xaaGC.c
deleted file mode 100644
index d55f1e4..0000000
--- a/hw/xfree86/xaa/xaaGC.c
+++ /dev/null
@@ -1,564 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <string.h>
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "migc.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-#include "xaawrap.h"
-
-static void XAAValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
-static void XAAChangeGC(GCPtr pGC, unsigned long mask);
-static void XAACopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst);
-static void XAADestroyGC(GCPtr pGC);
-static void XAAChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects);
-static void XAADestroyClip(GCPtr pGC);
-static void XAACopyClip(GCPtr pgcDst, GCPtr pgcSrc);
-
-GCFuncs XAAGCFuncs = {
-    XAAValidateGC, XAAChangeGC, XAACopyGC, XAADestroyGC,
-    XAAChangeClip, XAADestroyClip, XAACopyClip
-};
-
-extern GCOps XAAPixmapOps;
-
-Bool
-XAACreateGC(GCPtr pGC)
-{
-    ScreenPtr pScreen = pGC->pScreen;
-    XAAGCPtr pGCPriv = (XAAGCPtr) dixLookupPrivate(&pGC->devPrivates,
-                                                   XAAGetGCKey());
-    Bool ret;
-
-    XAA_SCREEN_PROLOGUE(pScreen, CreateGC);
-
-    if ((ret = (*pScreen->CreateGC) (pGC))) {
-        pGCPriv->wrapOps = NULL;
-        pGCPriv->wrapFuncs = pGC->funcs;
-        pGCPriv->XAAOps = &XAAFallbackOps;
-        pGC->funcs = &XAAGCFuncs;
-    }
-
-    XAA_SCREEN_EPILOGUE(pScreen, CreateGC, XAACreateGC);
-
-    return ret;
-}
-
-static void
-XAAValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    XAA_GC_FUNC_PROLOGUE(pGC);
-
-    (*pGC->funcs->ValidateGC) (pGC, changes, pDraw);
-
-    if ((changes & GCPlaneMask) &&
-        ((pGC->planemask & infoRec->FullPlanemasks[pGC->depth - 1]) ==
-         infoRec->FullPlanemasks[pGC->depth - 1])) {
-        pGC->planemask = ~0;
-    }
-
-    if (pGC->depth != 32) {
-        /* 0xffffffff is reserved for transparency */
-        if (pGC->bgPixel == 0xffffffff)
-            pGC->bgPixel = 0x7fffffff;
-        if (pGC->fgPixel == 0xffffffff)
-            pGC->fgPixel = 0x7fffffff;
-    }
-
-    if ((pDraw->type == DRAWABLE_PIXMAP) && !IS_OFFSCREEN_PIXMAP(pDraw)) {
-        pGCPriv->flags = OPS_ARE_PIXMAP;
-        pGCPriv->changes |= changes;
-
-        /* make sure we're not using videomemory pixmaps to render
-           onto system memory drawables */
-
-        if ((pGC->fillStyle == FillTiled) &&
-            IS_OFFSCREEN_PIXMAP(pGC->tile.pixmap) &&
-            !OFFSCREEN_PIXMAP_LOCKED(pGC->tile.pixmap)) {
-
-            XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
-            FBAreaPtr area = pPriv->offscreenArea;
-
-            XAARemoveAreaCallback(area);        /* clobbers pPriv->offscreenArea */
-            xf86FreeOffscreenArea(area);
-        }
-    }
-    else if (!infoRec->pScrn->vtSema && (pDraw->type == DRAWABLE_WINDOW)) {
-        pGCPriv->flags = 0;
-        pGCPriv->changes |= changes;
-    }
-    else {
-        if (!(pGCPriv->flags & OPS_ARE_ACCEL)) {
-            changes |= pGCPriv->changes;
-            pGCPriv->changes = 0;
-        }
-        pGCPriv->flags = OPS_ARE_ACCEL;
-
-#if 1
-        /* Ugh.  If we can't use the blitter on offscreen pixmaps used
-           as tiles, then we need to move them out as cfb can't handle
-           tiles with non-zero origins */
-
-        if ((pGC->fillStyle == FillTiled) &&
-            IS_OFFSCREEN_PIXMAP(pGC->tile.pixmap) &&
-            (DO_PIXMAP_COPY != (*infoRec->TiledFillChooser) (pGC))) {
-
-            XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
-            FBAreaPtr area = pPriv->offscreenArea;
-
-            XAARemoveAreaCallback(area);        /* clobbers pPriv->offscreenArea */
-            xf86FreeOffscreenArea(area);
-        }
-#endif
-    }
-
-    XAA_GC_FUNC_EPILOGUE(pGC);
-
-    if (!(pGCPriv->flags & OPS_ARE_ACCEL))
-        return;
-
-    if ((changes & GCTile) && !pGC->tileIsPixel && pGC->tile.pixmap) {
-        XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
-
-        if (pixPriv->flags & DIRTY) {
-            pixPriv->flags &= ~(DIRTY | REDUCIBILITY_MASK);
-            pGC->tile.pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
-        }
-    }
-    if ((changes & GCStipple) && pGC->stipple) {
-        XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
-
-        if (pixPriv->flags & DIRTY) {
-            pixPriv->flags &= ~(DIRTY | REDUCIBILITY_MASK);
-            pGC->stipple->drawable.serialNumber = NEXT_SERIAL_NUMBER;
-        }
-    }
-
-    /* If our Ops are still the default ones we need to allocate new ones */
-    if (pGC->ops == &XAAFallbackOps) {
-        if (!(pGCPriv->XAAOps = malloc(sizeof(GCOps)))) {
-            pGCPriv->XAAOps = &XAAFallbackOps;
-            return;
-        }
-        /* make a modifiable copy of the default ops */
-        memcpy(pGCPriv->XAAOps, &XAAFallbackOps, sizeof(GCOps));
-        pGC->ops = pGCPriv->XAAOps;
-        changes = ~0;
-    }
-
-    if (!changes)
-        return;
-
-    if ((changes & GCDashList) && infoRec->ComputeDash)
-        infoRec->ComputeDash(pGC);
-
-    if (changes & infoRec->FillSpansMask)
-        (*infoRec->ValidateFillSpans) (pGC, changes, pDraw);
-
-    if (changes & infoRec->SetSpansMask)
-        (*infoRec->ValidateSetSpans) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PutImageMask)
-        (*infoRec->ValidatePutImage) (pGC, changes, pDraw);
-
-    if (changes & infoRec->CopyAreaMask)
-        (*infoRec->ValidateCopyArea) (pGC, changes, pDraw);
-
-    if (changes & infoRec->CopyPlaneMask)
-        (*infoRec->ValidateCopyPlane) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolyPointMask)
-        (*infoRec->ValidatePolyPoint) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolylinesMask)
-        (*infoRec->ValidatePolylines) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolySegmentMask)
-        (*infoRec->ValidatePolySegment) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolyRectangleMask)
-        (*infoRec->ValidatePolyRectangle) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolyArcMask)
-        (*infoRec->ValidatePolyArc) (pGC, changes, pDraw);
-
-    if (changes & infoRec->FillPolygonMask)
-        (*infoRec->ValidateFillPolygon) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolyFillRectMask)
-        (*infoRec->ValidatePolyFillRect) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolyFillArcMask)
-        (*infoRec->ValidatePolyFillArc) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolyGlyphBltMask)
-        (*infoRec->ValidatePolyGlyphBlt) (pGC, changes, pDraw);
-
-    if (changes & infoRec->ImageGlyphBltMask)
-        (*infoRec->ValidateImageGlyphBlt) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolyText8Mask)
-        (*infoRec->ValidatePolyText8) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PolyText16Mask)
-        (*infoRec->ValidatePolyText16) (pGC, changes, pDraw);
-
-    if (changes & infoRec->ImageText8Mask)
-        (*infoRec->ValidateImageText8) (pGC, changes, pDraw);
-
-    if (changes & infoRec->ImageText16Mask)
-        (*infoRec->ValidateImageText16) (pGC, changes, pDraw);
-
-    if (changes & infoRec->PushPixelsMask)
-        (*infoRec->ValidatePushPixels) (pGC, changes, pDraw);
-}
-
-static void
-XAADestroyGC(GCPtr pGC)
-{
-    XAA_GC_FUNC_PROLOGUE(pGC);
-
-    if (pGCPriv->XAAOps != &XAAFallbackOps)
-        free(pGCPriv->XAAOps);
-
-    free(pGCPriv->DashPattern);
-    pGCPriv->flags = 0;
-
-    (*pGC->funcs->DestroyGC) (pGC);
-    XAA_GC_FUNC_EPILOGUE(pGC);
-}
-
-static void
-XAAChangeGC(GCPtr pGC, unsigned long mask)
-{
-    XAA_GC_FUNC_PROLOGUE(pGC);
-    (*pGC->funcs->ChangeGC) (pGC, mask);
-    XAA_GC_FUNC_EPILOGUE(pGC);
-
-    /* we have to assume that shared memory pixmaps are dirty 
-       because we can't wrap all operations on them */
-
-    if ((mask & GCTile) && !pGC->tileIsPixel &&
-        PIXMAP_IS_SHARED(pGC->tile.pixmap)) {
-        XAAPixmapPtr pPixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
-
-        pPixPriv->flags |= DIRTY;
-    }
-
-    if ((mask & GCStipple) && PIXMAP_IS_SHARED(pGC->stipple)) {
-        XAAPixmapPtr pPixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
-
-        pPixPriv->flags |= DIRTY;
-    }
-}
-
-static void
-XAACopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst)
-{
-    XAA_GC_FUNC_PROLOGUE(pGCDst);
-    (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
-    XAA_GC_FUNC_EPILOGUE(pGCDst);
-}
-
-static void
-XAAChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects)
-{
-    XAA_GC_FUNC_PROLOGUE(pGC);
-    (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
-    XAA_GC_FUNC_EPILOGUE(pGC);
-}
-
-static void
-XAACopyClip(GCPtr pgcDst, GCPtr pgcSrc)
-{
-    XAA_GC_FUNC_PROLOGUE(pgcDst);
-    (*pgcDst->funcs->CopyClip) (pgcDst, pgcSrc);
-    XAA_GC_FUNC_EPILOGUE(pgcDst);
-}
-
-static void
-XAADestroyClip(GCPtr pGC)
-{
-    XAA_GC_FUNC_PROLOGUE(pGC);
-    (*pGC->funcs->DestroyClip) (pGC);
-    XAA_GC_FUNC_EPILOGUE(pGC);
-}
-
-/**** Pixmap Wrappers ****/
-
-static void
-XAAFillSpansPixmap(DrawablePtr pDraw,
-                   GC * pGC,
-                   int nInit, DDXPointPtr pptInit, int *pwidthInit, int fSorted)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->FillSpans) (pDraw, pGC, nInit, pptInit, pwidthInit, fSorted);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAASetSpansPixmap(DrawablePtr pDraw,
-                  GCPtr pGC,
-                  char *pcharsrc,
-                  register DDXPointPtr ppt,
-                  int *pwidth, int nspans, int fSorted)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->SetSpans) (pDraw, pGC, pcharsrc, ppt, pwidth, nspans, fSorted);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPutImagePixmap(DrawablePtr pDraw,
-                  GCPtr pGC,
-                  int depth,
-                  int x, int y, int w, int h,
-                  int leftPad, int format, char *pImage)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->PutImage) (pDraw, pGC, depth, x, y, w, h,
-                           leftPad, format, pImage);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static RegionPtr
-XAACopyAreaPixmap(DrawablePtr pSrc,
-                  DrawablePtr pDst,
-                  GC * pGC,
-                  int srcx, int srcy, int width, int height, int dstx, int dsty)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    RegionPtr ret;
-
-    if (infoRec->pScrn->vtSema &&
-        ((pSrc->type == DRAWABLE_WINDOW) || IS_OFFSCREEN_PIXMAP(pSrc))) {
-        if (infoRec->ReadPixmap && (pGC->alu == GXcopy) &&
-            (pSrc->bitsPerPixel == pDst->bitsPerPixel) &&
-            ((pGC->planemask & infoRec->FullPlanemasks[pSrc->depth - 1])
-             == infoRec->FullPlanemasks[pSrc->depth - 1])) {
-            XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE((PixmapPtr) (pDst));
-
-            pixPriv->flags |= DIRTY;
-
-            return (XAABitBlt(pSrc, pDst, pGC,
-                              srcx, srcy, width, height, dstx, dsty,
-                              XAADoImageRead, 0L));
-        }
-        else if (infoRec->NeedToSync) {
-            (*infoRec->Sync) (infoRec->pScrn);
-            infoRec->NeedToSync = FALSE;
-        }
-    }
-
-    {
-        XAA_PIXMAP_OP_PROLOGUE(pGC, pDst);
-        ret = (*pGC->ops->CopyArea) (pSrc, pDst,
-                                     pGC, srcx, srcy, width, height, dstx,
-                                     dsty);
-        XAA_PIXMAP_OP_EPILOGUE(pGC);
-    }
-    return ret;
-}
-
-static RegionPtr
-XAACopyPlanePixmap(DrawablePtr pSrc,
-                   DrawablePtr pDst,
-                   GCPtr pGC,
-                   int srcx, int srcy,
-                   int width, int height,
-                   int dstx, int dsty, unsigned long bitPlane)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    RegionPtr ret;
-
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDst);
-
-    if (infoRec->pScrn->vtSema &&
-        ((pSrc->type == DRAWABLE_WINDOW) || IS_OFFSCREEN_PIXMAP(pSrc))) {
-        if (infoRec->NeedToSync) {
-            (*infoRec->Sync) (infoRec->pScrn);
-            infoRec->NeedToSync = FALSE;
-        }
-    }
-
-    ret = (*pGC->ops->CopyPlane) (pSrc, pDst,
-                                  pGC, srcx, srcy, width, height, dstx, dsty,
-                                  bitPlane);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-    return ret;
-}
-
-static void
-XAAPolyPointPixmap(DrawablePtr pDraw,
-                   GCPtr pGC, int mode, int npt, xPoint * pptInit)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->PolyPoint) (pDraw, pGC, mode, npt, pptInit);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolylinesPixmap(DrawablePtr pDraw,
-                   GCPtr pGC, int mode, int npt, DDXPointPtr pptInit)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->Polylines) (pDraw, pGC, mode, npt, pptInit);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolySegmentPixmap(DrawablePtr pDraw, GCPtr pGC, int nseg, xSegment * pSeg)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->PolySegment) (pDraw, pGC, nseg, pSeg);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyRectanglePixmap(DrawablePtr pDraw,
-                       GCPtr pGC, int nRectsInit, xRectangle *pRectsInit)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->PolyRectangle) (pDraw, pGC, nRectsInit, pRectsInit);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyArcPixmap(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->PolyArc) (pDraw, pGC, narcs, parcs);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAFillPolygonPixmap(DrawablePtr pDraw,
-                     GCPtr pGC,
-                     int shape, int mode, int count, DDXPointPtr ptsIn)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->FillPolygon) (pDraw, pGC, shape, mode, count, ptsIn);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyFillRectPixmap(DrawablePtr pDraw,
-                      GCPtr pGC, int nrectFill, xRectangle *prectInit)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->PolyFillRect) (pDraw, pGC, nrectFill, prectInit);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyFillArcPixmap(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, parcs);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static int
-XAAPolyText8Pixmap(DrawablePtr pDraw,
-                   GCPtr pGC, int x, int y, int count, char *chars)
-{
-    int ret;
-
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    ret = (*pGC->ops->PolyText8) (pDraw, pGC, x, y, count, chars);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-    return ret;
-}
-
-static int
-XAAPolyText16Pixmap(DrawablePtr pDraw,
-                    GCPtr pGC, int x, int y, int count, unsigned short *chars)
-{
-    int ret;
-
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    ret = (*pGC->ops->PolyText16) (pDraw, pGC, x, y, count, chars);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-    return ret;
-}
-
-static void
-XAAImageText8Pixmap(DrawablePtr pDraw,
-                    GCPtr pGC, int x, int y, int count, char *chars)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->ImageText8) (pDraw, pGC, x, y, count, chars);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAImageText16Pixmap(DrawablePtr pDraw,
-                     GCPtr pGC, int x, int y, int count, unsigned short *chars)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->ImageText16) (pDraw, pGC, x, y, count, chars);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAImageGlyphBltPixmap(DrawablePtr pDraw,
-                       GCPtr pGC,
-                       int xInit, int yInit,
-                       unsigned int nglyph,
-                       CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->ImageGlyphBlt) (pDraw, pGC, xInit, yInit, nglyph,
-                                ppci, pglyphBase);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPolyGlyphBltPixmap(DrawablePtr pDraw,
-                      GCPtr pGC,
-                      int xInit, int yInit,
-                      unsigned int nglyph,
-                      CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->PolyGlyphBlt) (pDraw, pGC, xInit, yInit, nglyph,
-                               ppci, pglyphBase);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-static void
-XAAPushPixelsPixmap(GCPtr pGC,
-                    PixmapPtr pBitMap,
-                    DrawablePtr pDraw, int dx, int dy, int xOrg, int yOrg)
-{
-    XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
-    (*pGC->ops->PushPixels) (pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg);
-    XAA_PIXMAP_OP_EPILOGUE(pGC);
-}
-
-GCOps XAAPixmapOps = {
-    XAAFillSpansPixmap, XAASetSpansPixmap,
-    XAAPutImagePixmap, XAACopyAreaPixmap,
-    XAACopyPlanePixmap, XAAPolyPointPixmap,
-    XAAPolylinesPixmap, XAAPolySegmentPixmap,
-    XAAPolyRectanglePixmap, XAAPolyArcPixmap,
-    XAAFillPolygonPixmap, XAAPolyFillRectPixmap,
-    XAAPolyFillArcPixmap, XAAPolyText8Pixmap,
-    XAAPolyText16Pixmap, XAAImageText8Pixmap,
-    XAAImageText16Pixmap, XAAImageGlyphBltPixmap,
-    XAAPolyGlyphBltPixmap, XAAPushPixelsPixmap,
-};
diff --git a/hw/xfree86/xaa/xaaGCmisc.c b/hw/xfree86/xaa/xaaGCmisc.c
deleted file mode 100644
index ca69aae..0000000
--- a/hw/xfree86/xaa/xaaGCmisc.c
+++ /dev/null
@@ -1,412 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include <X11/fonts/fontstruct.h>
-#include "dixfontstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "migc.h"
-#include "mi.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-
-void
-XAAValidateCopyArea(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (infoRec->CopyArea &&
-        CHECK_PLANEMASK(pGC, infoRec->CopyAreaFlags) &&
-        CHECK_ROP(pGC, infoRec->CopyAreaFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->CopyAreaFlags)
-        )
-        pGC->ops->CopyArea = infoRec->CopyArea;
-    else
-        pGC->ops->CopyArea = XAAFallbackOps.CopyArea;
-}
-
-void
-XAAValidatePutImage(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (infoRec->PutImage &&
-        CHECK_PLANEMASK(pGC, infoRec->PutImageFlags) &&
-        CHECK_ROP(pGC, infoRec->PutImageFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->PutImageFlags) &&
-        CHECK_COLORS(pGC, infoRec->PutImageFlags)
-        )
-        pGC->ops->PutImage = infoRec->PutImage;
-    else
-        pGC->ops->PutImage = XAAFallbackOps.PutImage;
-}
-
-void
-XAAValidateCopyPlane(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (infoRec->CopyPlane &&
-        CHECK_PLANEMASK(pGC, infoRec->CopyPlaneFlags) &&
-        CHECK_ROP(pGC, infoRec->CopyPlaneFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->CopyPlaneFlags) &&
-        CHECK_COLORS(pGC, infoRec->CopyPlaneFlags)
-        )
-        pGC->ops->CopyPlane = infoRec->CopyPlane;
-    else
-        pGC->ops->CopyPlane = XAAFallbackOps.CopyPlane;
-}
-
-void
-XAAValidatePushPixels(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (infoRec->PushPixelsSolid &&
-        (pGC->fillStyle == FillSolid) &&
-        CHECK_PLANEMASK(pGC, infoRec->PushPixelsFlags) &&
-        CHECK_ROP(pGC, infoRec->PushPixelsFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->PushPixelsFlags) &&
-        CHECK_FG(pGC, infoRec->PushPixelsFlags) &&
-        (!(infoRec->PushPixelsFlags & TRANSPARENCY_GXCOPY_ONLY) ||
-         (pGC->alu == GXcopy))
-        )
-        pGC->ops->PushPixels = infoRec->PushPixelsSolid;
-    else
-        pGC->ops->PushPixels = XAAFallbackOps.PushPixels;
-
-}
-
-/* We make the assumption that the FillSpans, PolyFillRect, FillPolygon
-   and PolyFillArc functions are linked in a way that they all have 
-   the same rop/color/planemask restrictions. If the driver provides 
-   a GC level replacement for these, it will need to supply a new 
-   Validate functions if it breaks this assumption */
-
-void
-XAAValidateFillSpans(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (pGC->fillStyle != FillTiled)
-        changes &= ~GCTile;
-    if ((pGC->fillStyle == FillTiled) || (pGC->fillStyle == FillSolid))
-        changes &= ~GCStipple;
-    if (!changes)
-        return;
-
-    pGC->ops->FillSpans = XAAFallbackOps.FillSpans;
-    pGC->ops->PolyFillRect = XAAFallbackOps.PolyFillRect;
-    pGC->ops->FillPolygon = XAAFallbackOps.FillPolygon;
-    pGC->ops->PolyFillArc = XAAFallbackOps.PolyFillArc;
-
-    switch (pGC->fillStyle) {
-    case FillSolid:
-        if (infoRec->FillSpansSolid &&
-            CHECK_PLANEMASK(pGC, infoRec->FillSpansSolidFlags) &&
-            CHECK_ROP(pGC, infoRec->FillSpansSolidFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->FillSpansSolidFlags) &&
-            CHECK_FG(pGC, infoRec->FillSpansSolidFlags)
-            ) {
-            pGC->ops->FillSpans = infoRec->FillSpansSolid;
-            pGC->ops->PolyFillRect = infoRec->PolyFillRectSolid;
-            pGC->ops->FillPolygon = infoRec->FillPolygonSolid;
-            pGC->ops->PolyFillArc = infoRec->PolyFillArcSolid;
-        }
-        break;
-        /* The [Stippled/OpaqueStippled/Tiled]FillChooser 
-           functions do the validating */
-    case FillStippled:
-        if (infoRec->FillSpansStippled) {
-            pGC->ops->FillSpans = infoRec->FillSpansStippled;
-            pGC->ops->PolyFillRect = infoRec->PolyFillRectStippled;
-            if (infoRec->FillPolygonStippled)
-                pGC->ops->FillPolygon = infoRec->FillPolygonStippled;
-            else
-                pGC->ops->FillPolygon = miFillPolygon;
-            pGC->ops->PolyFillArc = miPolyFillArc;
-        }
-        break;
-    case FillOpaqueStippled:
-        if (infoRec->FillSpansOpaqueStippled) {
-            pGC->ops->FillSpans = infoRec->FillSpansOpaqueStippled;
-            pGC->ops->PolyFillRect = infoRec->PolyFillRectOpaqueStippled;
-            if (infoRec->FillPolygonOpaqueStippled)
-                pGC->ops->FillPolygon = infoRec->FillPolygonOpaqueStippled;
-            else
-                pGC->ops->FillPolygon = miFillPolygon;
-            pGC->ops->PolyFillArc = miPolyFillArc;
-        }
-        break;
-    case FillTiled:
-        if (infoRec->FillSpansTiled) {
-            pGC->ops->FillSpans = infoRec->FillSpansTiled;
-            pGC->ops->PolyFillRect = infoRec->PolyFillRectTiled;
-            if (infoRec->FillPolygonTiled)
-                pGC->ops->FillPolygon = infoRec->FillPolygonTiled;
-            else
-                pGC->ops->FillPolygon = miFillPolygon;
-            pGC->ops->PolyFillArc = miPolyFillArc;
-        }
-        break;
-    default:
-        return;
-    }
-}
-
-/* We make the assumption that these Text8/16 and GlyphBlt functions
-   are linked in a way that they all have the same rop/color/planemask
-   restrictions. If the driver provides a GC level replacement for
-   these, it will need to supply a new Validate functions if it breaks
-   this assumption */
-
-void
-XAAValidatePolyGlyphBlt(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    Bool BigFont = FALSE;
-
-    pGC->ops->PolyText8 = XAAFallbackOps.PolyText8;
-    pGC->ops->PolyText16 = XAAFallbackOps.PolyText16;
-    pGC->ops->PolyGlyphBlt = XAAFallbackOps.PolyGlyphBlt;
-
-    if (!pGC->font)
-        return;
-    if (pGC->fillStyle != FillSolid)
-        return;
-
-    if ((FONTMAXBOUNDS(pGC->font, rightSideBearing) -
-         FONTMINBOUNDS(pGC->font, leftSideBearing) > 32))
-        BigFont = TRUE;
-
-    /* no funny business */
-    if ((FONTMINBOUNDS(pGC->font, characterWidth) <= 0) ||
-        ((FONTASCENT(pGC->font) + FONTDESCENT(pGC->font)) <= 0))
-        return;
-
-    /* Check for TE Fonts */
-    if (!TERMINALFONT(pGC->font) || BigFont) {
-        if (infoRec->PolyGlyphBltNonTE &&
-            CHECK_PLANEMASK(pGC, infoRec->PolyGlyphBltNonTEFlags) &&
-            CHECK_ROP(pGC, infoRec->PolyGlyphBltNonTEFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->PolyGlyphBltNonTEFlags) &&
-            CHECK_FG(pGC, infoRec->PolyGlyphBltNonTEFlags) &&
-            (!(infoRec->PolyGlyphBltNonTEFlags & TRANSPARENCY_GXCOPY_ONLY) ||
-             (pGC->alu == GXcopy))
-            ) {
-            pGC->ops->PolyText8 = infoRec->PolyText8NonTE;
-            pGC->ops->PolyText16 = infoRec->PolyText16NonTE;
-            pGC->ops->PolyGlyphBlt = infoRec->PolyGlyphBltNonTE;
-        }
-    }
-    else {
-        if (infoRec->PolyGlyphBltTE &&
-            CHECK_PLANEMASK(pGC, infoRec->PolyGlyphBltTEFlags) &&
-            CHECK_ROP(pGC, infoRec->PolyGlyphBltTEFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->PolyGlyphBltNonTEFlags) &&
-            CHECK_FG(pGC, infoRec->PolyGlyphBltTEFlags) &&
-            (!(infoRec->PolyGlyphBltTEFlags & TRANSPARENCY_GXCOPY_ONLY) ||
-             (pGC->alu == GXcopy))
-            ) {
-            pGC->ops->PolyText8 = infoRec->PolyText8TE;
-            pGC->ops->PolyText16 = infoRec->PolyText16TE;
-            pGC->ops->PolyGlyphBlt = infoRec->PolyGlyphBltTE;
-        }
-    }
-}
-
-void
-XAAValidateImageGlyphBlt(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    Bool BigFont = FALSE;
-
-    pGC->ops->ImageText8 = XAAFallbackOps.ImageText8;
-    pGC->ops->ImageText16 = XAAFallbackOps.ImageText16;
-    pGC->ops->ImageGlyphBlt = XAAFallbackOps.ImageGlyphBlt;
-
-    if (!pGC->font)
-        return;
-
-    if ((FONTMAXBOUNDS(pGC->font, rightSideBearing) -
-         FONTMINBOUNDS(pGC->font, leftSideBearing) > 32))
-        BigFont = TRUE;
-
-    /* no funny business */
-    if ((FONTMINBOUNDS(pGC->font, characterWidth) <= 0) ||
-        ((FONTASCENT(pGC->font) + FONTDESCENT(pGC->font)) <= 0))
-        return;
-
-    /* Check for TE Fonts */
-    if (!TERMINALFONT(pGC->font) || BigFont || (pGC->depth == 32)) {
-        if (infoRec->ImageGlyphBltNonTE &&
-            CHECK_PLANEMASK(pGC, infoRec->ImageGlyphBltNonTEFlags) &&
-            CHECK_FG(pGC, infoRec->ImageGlyphBltNonTEFlags) &&
-            infoRec->SetupForSolidFill &&
-            CHECK_PLANEMASK(pGC, infoRec->SolidFillFlags) &&
-            CHECK_BG(pGC, infoRec->SolidFillFlags)) {
-            pGC->ops->ImageText8 = infoRec->ImageText8NonTE;
-            pGC->ops->ImageText16 = infoRec->ImageText16NonTE;
-            pGC->ops->ImageGlyphBlt = infoRec->ImageGlyphBltNonTE;
-        }
-    }
-    else if (infoRec->ImageGlyphBltTE &&
-             CHECK_PLANEMASK(pGC, infoRec->ImageGlyphBltTEFlags)) {
-        if (!(infoRec->ImageGlyphBltTEFlags & TRANSPARENCY_ONLY) &&
-            CHECK_COLORS(pGC, infoRec->ImageGlyphBltTEFlags)) {
-            pGC->ops->ImageText8 = infoRec->ImageText8TE;
-            pGC->ops->ImageText16 = infoRec->ImageText16TE;
-            pGC->ops->ImageGlyphBlt = infoRec->ImageGlyphBltTE;
-        }
-        else {
-            if (CHECK_FG(pGC, infoRec->ImageGlyphBltTEFlags) &&
-                infoRec->SetupForSolidFill &&
-                CHECK_PLANEMASK(pGC, infoRec->SolidFillFlags) &&
-                CHECK_BG(pGC, infoRec->SolidFillFlags)) {
-                pGC->ops->ImageText8 = infoRec->ImageText8TE;
-                pGC->ops->ImageText16 = infoRec->ImageText16TE;
-                pGC->ops->ImageGlyphBlt = infoRec->ImageGlyphBltTE;
-            }
-        }
-    }
-}
-
-void
-XAAValidatePolylines(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAAGCPtr pGCPriv = (XAAGCPtr) dixLookupPrivate(&pGC->devPrivates,
-                                                   XAAGetGCKey());
-
-    if (pGC->lineStyle == LineSolid)
-        changes &= ~GCDashList;
-    if (!changes)
-        return;
-
-    pGC->ops->PolySegment = XAAFallbackOps.PolySegment;
-    pGC->ops->Polylines = XAAFallbackOps.Polylines;
-    pGC->ops->PolyRectangle = XAAFallbackOps.PolyRectangle;
-    pGC->ops->PolyArc = XAAFallbackOps.PolyArc;
-
-    if ((pGC->ops->FillSpans != XAAFallbackOps.FillSpans) &&
-        (pGC->lineWidth > 0)) {
-
-        pGC->ops->PolyArc = miPolyArc;
-        pGC->ops->PolySegment = miPolySegment;
-        pGC->ops->PolyRectangle = miPolyRectangle;
-        if (pGC->lineStyle == LineSolid)
-            pGC->ops->Polylines = miWideLine;
-        else
-            pGC->ops->Polylines = miWideDash;
-    }
-
-    if ((pGC->lineWidth == 0) && (pGC->fillStyle == FillSolid)) {
-
-        if (pGC->lineStyle == LineSolid) {
-
-            if (infoRec->PolyRectangleThinSolid &&
-                CHECK_PLANEMASK(pGC, infoRec->PolyRectangleThinSolidFlags) &&
-                CHECK_ROP(pGC, infoRec->PolyRectangleThinSolidFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->PolyRectangleThinSolidFlags) &&
-                CHECK_FG(pGC, infoRec->PolyRectangleThinSolidFlags)) {
-
-                pGC->ops->PolyRectangle = infoRec->PolyRectangleThinSolid;
-            }
-
-            if (infoRec->PolySegmentThinSolid &&
-                CHECK_PLANEMASK(pGC, infoRec->PolySegmentThinSolidFlags) &&
-                CHECK_ROP(pGC, infoRec->PolySegmentThinSolidFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->PolySegmentThinSolidFlags) &&
-                CHECK_FG(pGC, infoRec->PolySegmentThinSolidFlags)) {
-
-                pGC->ops->PolySegment = infoRec->PolySegmentThinSolid;
-            }
-
-            if (infoRec->PolylinesThinSolid &&
-                CHECK_PLANEMASK(pGC, infoRec->PolylinesThinSolidFlags) &&
-                CHECK_ROP(pGC, infoRec->PolylinesThinSolidFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->PolylinesThinSolidFlags) &&
-                CHECK_FG(pGC, infoRec->PolylinesThinSolidFlags)) {
-
-                pGC->ops->Polylines = infoRec->PolylinesThinSolid;
-            }
-        }
-        else if ((pGC->lineStyle == LineOnOffDash) && pGCPriv->DashPattern) {
-
-            if (infoRec->PolySegmentThinDashed &&
-                !(infoRec->PolySegmentThinDashedFlags & NO_TRANSPARENCY) &&
-                ((pGC->alu == GXcopy) || !(infoRec->PolySegmentThinDashedFlags &
-                                           TRANSPARENCY_GXCOPY_ONLY)) &&
-                CHECK_PLANEMASK(pGC, infoRec->PolySegmentThinDashedFlags) &&
-                CHECK_ROP(pGC, infoRec->PolySegmentThinDashedFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->PolySegmentThinDashedFlags) &&
-                CHECK_FG(pGC, infoRec->PolySegmentThinDashedFlags)) {
-
-                pGC->ops->PolySegment = infoRec->PolySegmentThinDashed;
-            }
-
-            if (infoRec->PolylinesThinDashed &&
-                !(infoRec->PolylinesThinDashedFlags & NO_TRANSPARENCY) &&
-                ((pGC->alu == GXcopy) || !(infoRec->PolylinesThinDashedFlags &
-                                           TRANSPARENCY_GXCOPY_ONLY)) &&
-                CHECK_PLANEMASK(pGC, infoRec->PolylinesThinDashedFlags) &&
-                CHECK_ROP(pGC, infoRec->PolylinesThinDashedFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->PolylinesThinDashedFlags) &&
-                CHECK_FG(pGC, infoRec->PolylinesThinDashedFlags)) {
-
-                pGC->ops->Polylines = infoRec->PolylinesThinDashed;
-            }
-
-            if (pGC->ops->Polylines != XAAFallbackOps.Polylines)
-                pGC->ops->PolyRectangle = miPolyRectangle;
-
-        }
-        else if (pGCPriv->DashPattern && (pGC->depth != 32)) {
-            /* LineDoubleDash */
-            if (infoRec->PolySegmentThinDashed &&
-                !(infoRec->PolySegmentThinDashedFlags & TRANSPARENCY_ONLY) &&
-                CHECK_PLANEMASK(pGC, infoRec->PolySegmentThinDashedFlags) &&
-                CHECK_ROP(pGC, infoRec->PolySegmentThinDashedFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->PolySegmentThinDashedFlags) &&
-                CHECK_COLORS(pGC, infoRec->PolySegmentThinDashedFlags)) {
-
-                pGC->ops->PolySegment = infoRec->PolySegmentThinDashed;
-            }
-
-            if (infoRec->PolylinesThinDashed &&
-                !(infoRec->PolylinesThinDashedFlags & TRANSPARENCY_ONLY) &&
-                CHECK_PLANEMASK(pGC, infoRec->PolylinesThinDashedFlags) &&
-                CHECK_ROP(pGC, infoRec->PolylinesThinDashedFlags) &&
-                CHECK_ROPSRC(pGC, infoRec->PolylinesThinDashedFlags) &&
-                CHECK_COLORS(pGC, infoRec->PolylinesThinDashedFlags)) {
-
-                pGC->ops->Polylines = infoRec->PolylinesThinDashed;
-            }
-
-            if (pGC->ops->Polylines != XAAFallbackOps.Polylines)
-                pGC->ops->PolyRectangle = miPolyRectangle;
-
-        }
-    }
-
-    if (infoRec->PolylinesWideSolid &&
-        (pGC->lineWidth > 0) &&
-        (pGC->fillStyle == FillSolid) &&
-        (pGC->lineStyle == LineSolid) &&
-        CHECK_PLANEMASK(pGC, infoRec->PolylinesWideSolidFlags) &&
-        CHECK_ROP(pGC, infoRec->PolylinesWideSolidFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->PolylinesWideSolidFlags) &&
-        CHECK_FG(pGC, infoRec->PolylinesWideSolidFlags)) {
-
-        pGC->ops->Polylines = infoRec->PolylinesWideSolid;
-    }
-}
diff --git a/hw/xfree86/xaa/xaaImage.c b/hw/xfree86/xaa/xaaImage.c
deleted file mode 100644
index 4457c9e..0000000
--- a/hw/xfree86/xaa/xaaImage.c
+++ /dev/null
@@ -1,534 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include "servermd.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "mi.h"
-#include "pixmapstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-
-void
-XAAMoveDWORDS_FixedBase(register CARD32 *dest,
-                        register CARD32 *src, register int dwords)
-{
-    while (dwords & ~0x03) {
-        *dest = *src;
-        *dest = *(src + 1);
-        *dest = *(src + 2);
-        *dest = *(src + 3);
-        dwords -= 4;
-        src += 4;
-    }
-
-    if (!dwords)
-        return;
-    *dest = *src;
-    if (dwords == 1)
-        return;
-    *dest = *(src + 1);
-    if (dwords == 2)
-        return;
-    *dest = *(src + 2);
-}
-
-void
-XAAMoveDWORDS(register CARD32 *dest, register CARD32 *src, register int dwords)
-{
-    while (dwords & ~0x03) {
-        *dest = *src;
-        *(dest + 1) = *(src + 1);
-        *(dest + 2) = *(src + 2);
-        *(dest + 3) = *(src + 3);
-        src += 4;
-        dest += 4;
-        dwords -= 4;
-    }
-    if (!dwords)
-        return;
-    *dest = *src;
-    if (dwords == 1)
-        return;
-    *(dest + 1) = *(src + 1);
-    if (dwords == 2)
-        return;
-    *(dest + 2) = *(src + 2);
-}
-
-void
-XAAMoveDWORDS_FixedSrc(register CARD32 *dest,
-                       register CARD32 *src, register int dwords)
-{
-    while (dwords & ~0x03) {
-        *dest = *src;
-        *(dest + 1) = *src;
-        *(dest + 2) = *src;
-        *(dest + 3) = *src;
-        dest += 4;
-        dwords -= 4;
-    }
-    if (!dwords)
-        return;
-    *dest = *src;
-    if (dwords == 1)
-        return;
-    *(dest + 1) = *src;
-    if (dwords == 2)
-        return;
-    *(dest + 2) = *src;
-}
-
-static void
-XAAWritePixmap32To24(ScrnInfoPtr pScrn, int x, int y, int w, int h, unsigned char *srcInit, int srcwidth,       /* bytes */
-                     int rop, unsigned int planemask, int trans)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int count, dwords = bytes_to_int32(w * 3);
-    CARD32 *src, *dst;
-    Bool PlusOne = FALSE;
-
-    if ((infoRec->ImageWriteFlags & CPU_TRANSFER_PAD_QWORD) &&
-        ((dwords * h) & 0x01)) {
-        PlusOne = TRUE;
-    }
-
-    (*infoRec->SetupForImageWrite) (pScrn, rop, planemask, trans, 24, 24);
-    (*infoRec->SubsequentImageWriteRect) (pScrn, x, y, w, h, 0);
-
-    if (dwords > infoRec->ImageWriteRange) {
-        dst = (CARD32 *) infoRec->ImageWriteBase;
-        while (h--) {
-            src = (CARD32 *) srcInit;
-            count = w;
-
-            while (count >= 4) {
-                *dst = (src[0] & 0x00ffffff) | (src[1] << 24);
-                *dst = ((src[1] >> 8) & 0x0000ffff) | (src[2] << 16);
-                *dst = ((src[2] >> 16) & 0x000000ff) | (src[3] << 8);
-                src += 4;
-                count -= 4;
-            }
-            switch (count) {
-            case 0:
-                break;
-            case 1:
-                *dst = src[0];
-                break;
-            case 2:
-                *dst = (src[0] & 0x00ffffff) | (src[1] << 24);
-                *dst = src[1] >> 8;
-                break;
-            default:
-                *dst = (src[0] & 0x00ffffff) | (src[1] << 24);
-                *dst = ((src[1] >> 8) & 0x0000ffff) | (src[2] << 16);
-                *dst = src[2] >> 16;
-                break;
-            }
-            srcInit += srcwidth;
-        }
-    }
-    else {
-        while (h--) {
-            dst = (CARD32 *) infoRec->ImageWriteBase;
-            src = (CARD32 *) srcInit;
-            count = w;
-
-            while (count >= 4) {
-                dst[0] = (src[0] & 0x00ffffff) | (src[1] << 24);
-                dst[1] = ((src[1] >> 8) & 0x0000ffff) | (src[2] << 16);
-                dst[2] = ((src[2] >> 16) & 0x000000ff) | (src[3] << 8);
-                dst += 3;
-                src += 4;
-                count -= 4;
-            }
-            switch (count) {
-            case 0:
-                break;
-            case 1:
-                dst[0] = src[0];
-                break;
-            case 2:
-                dst[0] = (src[0] & 0x00ffffff) | (src[1] << 24);
-                dst[1] = src[1] >> 8;
-                break;
-            default:
-                dst[0] = (src[0] & 0x00ffffff) | (src[1] << 24);
-                dst[1] = ((src[1] >> 8) & 0x0000ffff) | (src[2] << 16);
-                dst[2] = src[2] >> 16;
-                break;
-            }
-            srcInit += srcwidth;
-        }
-    }
-
-    if (PlusOne) {
-        CARD32 *base = (CARD32 *) infoRec->ImageWriteBase;
-
-        *base = 0x00000000;
-    }
-
-    if (infoRec->ImageWriteFlags & SYNC_AFTER_IMAGE_WRITE)
-        (*infoRec->Sync) (pScrn);
-    else
-        SET_SYNC_FLAG(infoRec);
-
-}
-
-void
-XAAWritePixmap(ScrnInfoPtr pScrn, int x, int y, int w, int h, unsigned char *src, int srcwidth, /* bytes */
-               int rop, unsigned int planemask, int trans, int bpp, int depth)
-{
-    XAAInfoRecPtr infoRec;
-    int dwords, skipleft, Bpp;
-    Bool beCareful, PlusOne;
-
-    if ((bpp == 32) && (pScrn->bitsPerPixel == 24)) {
-        XAAWritePixmap32To24(pScrn, x, y, w, h, src, srcwidth,
-                             rop, planemask, trans);
-        return;
-    }
-
-    infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    beCareful = PlusOne = FALSE;
-    Bpp = bpp >> 3;
-
-    if ((skipleft = (long) src & 0x03L)) {
-        if (!(infoRec->ImageWriteFlags & LEFT_EDGE_CLIPPING)) {
-            skipleft = 0;
-            beCareful = TRUE;
-            goto BAD_ALIGNMENT;
-        }
-
-        if (Bpp == 3)
-            skipleft = 4 - skipleft;
-        else
-            skipleft /= Bpp;
-
-        if ((x < skipleft) && !(infoRec->ImageWriteFlags &
-                                LEFT_EDGE_CLIPPING_NEGATIVE_X)) {
-            skipleft = 0;
-            beCareful = TRUE;
-            goto BAD_ALIGNMENT;
-        }
-
-        x -= skipleft;
-        w += skipleft;
-
-        if (Bpp == 3)
-            src -= 3 * skipleft;
-        else                    /* is this Alpha friendly ? */
-            src = (unsigned char *) ((long) src & ~0x03L);
-    }
-
- BAD_ALIGNMENT:
-
-    dwords = bytes_to_int32(w * Bpp);
-
-    if ((infoRec->ImageWriteFlags & CPU_TRANSFER_PAD_QWORD) &&
-        ((dwords * h) & 0x01)) {
-        PlusOne = TRUE;
-    }
-
-    (*infoRec->SetupForImageWrite) (pScrn, rop, planemask, trans, bpp, depth);
-    (*infoRec->SubsequentImageWriteRect) (pScrn, x, y, w, h, skipleft);
-
-    if (beCareful) {
-        /* in cases with bad alignment we have to be careful not
-           to read beyond the end of the source */
-        if (((x * Bpp) + (dwords << 2)) > srcwidth)
-            h--;
-        else
-            beCareful = FALSE;
-    }
-
-    if (dwords > infoRec->ImageWriteRange) {
-        while (h--) {
-            XAAMoveDWORDS_FixedBase((CARD32 *) infoRec->ImageWriteBase,
-                                    (CARD32 *) src, dwords);
-            src += srcwidth;
-        }
-        if (beCareful) {
-            int shift = ((long) src & 0x03L) << 3;
-
-            if (--dwords)
-                XAAMoveDWORDS_FixedBase((CARD32 *) infoRec->ImageWriteBase,
-                                        (CARD32 *) src, dwords);
-            src = (unsigned char *) ((long) (src + (dwords << 2)) & ~0x03L);
-            *((CARD32 *) infoRec->ImageWriteBase) = *((CARD32 *) src) >> shift;
-        }
-    }
-    else {
-        if (srcwidth == (dwords << 2)) {
-            int decrement = infoRec->ImageWriteRange / dwords;
-
-            while (h > decrement) {
-                XAAMoveDWORDS((CARD32 *) infoRec->ImageWriteBase,
-                              (CARD32 *) src, dwords * decrement);
-                src += (srcwidth * decrement);
-                h -= decrement;
-            }
-            if (h) {
-                XAAMoveDWORDS((CARD32 *) infoRec->ImageWriteBase,
-                              (CARD32 *) src, dwords * h);
-                if (beCareful)
-                    src += (srcwidth * h);
-            }
-        }
-        else {
-            while (h--) {
-                XAAMoveDWORDS((CARD32 *) infoRec->ImageWriteBase,
-                              (CARD32 *) src, dwords);
-                src += srcwidth;
-            }
-        }
-
-        if (beCareful) {
-            int shift = ((long) src & 0x03L) << 3;
-
-            if (--dwords)
-                XAAMoveDWORDS((CARD32 *) infoRec->ImageWriteBase,
-                              (CARD32 *) src, dwords);
-            src = (unsigned char *) ((long) (src + (dwords << 2)) & ~0x03L);
-
-            ((CARD32 *) infoRec->ImageWriteBase)[dwords] =
-                *((CARD32 *) src) >> shift;
-        }
-    }
-
-    if (PlusOne) {
-        CARD32 *base = (CARD32 *) infoRec->ImageWriteBase;
-
-        *base = 0x00000000;
-    }
-
-    if (infoRec->ImageWriteFlags & SYNC_AFTER_IMAGE_WRITE)
-        (*infoRec->Sync) (pScrn);
-    else
-        SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAAWritePixmapScanline(ScrnInfoPtr pScrn, int x, int y, int w, int h, unsigned char *src, int srcwidth, /* bytes */
-                       int rop,
-                       unsigned int planemask, int trans, int bpp, int depth)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int dwords, skipleft, bufferNo = 0, Bpp = bpp >> 3;
-    Bool beCareful = FALSE;
-    CARD32 *base;
-
-    if ((skipleft = (long) src & 0x03L)) {
-        if (!(infoRec->ScanlineImageWriteFlags & LEFT_EDGE_CLIPPING)) {
-            skipleft = 0;
-            beCareful = TRUE;
-            goto BAD_ALIGNMENT;
-        }
-
-        if (Bpp == 3)
-            skipleft = 4 - skipleft;
-        else
-            skipleft /= Bpp;
-
-        if ((x < skipleft) && !(infoRec->ScanlineImageWriteFlags &
-                                LEFT_EDGE_CLIPPING_NEGATIVE_X)) {
-            skipleft = 0;
-            beCareful = TRUE;
-            goto BAD_ALIGNMENT;
-        }
-
-        x -= skipleft;
-        w += skipleft;
-
-        if (Bpp == 3)
-            src -= 3 * skipleft;
-        else
-            src = (unsigned char *) ((long) src & ~0x03L);
-    }
-
- BAD_ALIGNMENT:
-
-    dwords = bytes_to_int32(w * Bpp);
-
-    (*infoRec->SetupForScanlineImageWrite) (pScrn, rop, planemask, trans, bpp,
-                                            depth);
-    (*infoRec->SubsequentScanlineImageWriteRect) (pScrn, x, y, w, h, skipleft);
-
-    if (beCareful) {
-        /* in cases with bad alignment we have to be careful not
-           to read beyond the end of the source */
-        if (((x * Bpp) + (dwords << 2)) > srcwidth)
-            h--;
-        else
-            beCareful = FALSE;
-    }
-
-    while (h--) {
-        base = (CARD32 *) infoRec->ScanlineImageWriteBuffers[bufferNo];
-        XAAMoveDWORDS(base, (CARD32 *) src, dwords);
-        (*infoRec->SubsequentImageWriteScanline) (pScrn, bufferNo++);
-        src += srcwidth;
-        if (bufferNo >= infoRec->NumScanlineImageWriteBuffers)
-            bufferNo = 0;
-    }
-
-    if (beCareful) {
-        int shift = ((long) src & 0x03L) << 3;
-
-        base = (CARD32 *) infoRec->ScanlineImageWriteBuffers[bufferNo];
-        if (--dwords)
-            XAAMoveDWORDS(base, (CARD32 *) src, dwords);
-        src = (unsigned char *) ((long) (src + (dwords << 2)) & ~0x03L);
-
-        base[dwords] = *((CARD32 *) src) >> shift;
-        (*infoRec->SubsequentImageWriteScanline) (pScrn, bufferNo);
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAAPutImage(DrawablePtr pDraw,
-            GCPtr pGC,
-            int depth,
-            int x, int y, int w, int h, int leftPad, int format, char *pImage)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int bpp = BitsPerPixel(depth);
-    Bool depthBug = FALSE;
-
-    if (!w || !h)
-        return;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    depthBug = XAA_DEPTH_BUG(pGC);
-
-    if (((format == ZPixmap) && infoRec->WritePixmap &&
-         ((pDraw->bitsPerPixel == bpp) ||
-          ((pDraw->bitsPerPixel == 24) && (bpp == 32) &&
-           (infoRec->WritePixmapFlags & CONVERT_32BPP_TO_24BPP))) &&
-         CHECK_ROP(pGC, infoRec->WritePixmapFlags) &&
-         CHECK_ROPSRC(pGC, infoRec->WritePixmapFlags) &&
-         CHECK_PLANEMASK(pGC, infoRec->WritePixmapFlags) &&
-         CHECK_NO_GXCOPY(pGC, infoRec->WritePixmapFlags)) ||
-        ((format == XYBitmap) && !depthBug && infoRec->WriteBitmap &&
-         CHECK_ROP(pGC, infoRec->WriteBitmapFlags) &&
-         CHECK_ROPSRC(pGC, infoRec->WriteBitmapFlags) &&
-         CHECK_PLANEMASK(pGC, infoRec->WriteBitmapFlags) &&
-         CHECK_COLORS(pGC, infoRec->WriteBitmapFlags) &&
-         !(infoRec->WriteBitmapFlags & TRANSPARENCY_ONLY)) ||
-        ((format == XYPixmap) && !depthBug && infoRec->WriteBitmap &&
-         CHECK_ROP(pGC, infoRec->WriteBitmapFlags) &&
-         CHECK_ROPSRC(pGC, infoRec->WriteBitmapFlags) &&
-         !(infoRec->WriteBitmapFlags & NO_PLANEMASK) &&
-         !(infoRec->WriteBitmapFlags & TRANSPARENCY_ONLY))) {
-
-        int MaxBoxes = RegionNumRects(pGC->pCompositeClip);
-        BoxPtr pbox, pClipBoxes;
-        int nboxes, srcx, srcy, srcwidth;
-        xRectangle TheRect;
-
-        TheRect.x = pDraw->x + x;
-        TheRect.y = pDraw->y + y;
-        TheRect.width = w;
-        TheRect.height = h;
-
-        if (MaxBoxes > (infoRec->PreAllocSize / sizeof(BoxRec))) {
-            pClipBoxes = malloc(MaxBoxes * sizeof(BoxRec));
-            if (!pClipBoxes)
-                return;
-        }
-        else
-            pClipBoxes = (BoxPtr) infoRec->PreAllocMem;
-
-        nboxes = XAAGetRectClipBoxes(pGC, pClipBoxes, 1, &TheRect);
-        pbox = pClipBoxes;
-
-        if (format == XYBitmap) {
-            srcwidth = BitmapBytePad(leftPad + w);
-            while (nboxes--) {
-                srcx = pbox->x1 - TheRect.x + leftPad;
-                srcy = pbox->y1 - TheRect.y;
-                (*infoRec->WriteBitmap) (infoRec->pScrn, pbox->x1, pbox->y1,
-                                         pbox->x2 - pbox->x1,
-                                         pbox->y2 - pbox->y1,
-                                         (unsigned char *) pImage +
-                                         (srcwidth * srcy) + ((srcx >> 5) << 2),
-                                         srcwidth, srcx & 31, pGC->fgPixel,
-                                         pGC->bgPixel, pGC->alu,
-                                         pGC->planemask);
-                pbox++;
-            }
-        }
-        else if (format == ZPixmap) {
-            int Bpp = bpp >> 3;
-
-            srcwidth = PixmapBytePad(leftPad + w, depth);
-            while (nboxes--) {
-                srcx = pbox->x1 - TheRect.x + leftPad;
-                srcy = pbox->y1 - TheRect.y;
-                (*infoRec->WritePixmap) (infoRec->pScrn, pbox->x1, pbox->y1,
-                                         pbox->x2 - pbox->x1,
-                                         pbox->y2 - pbox->y1,
-                                         (unsigned char *) pImage +
-                                         (srcwidth * srcy) + (srcx * Bpp),
-                                         srcwidth, pGC->alu, pGC->planemask, -1,
-                                         Bpp << 3, depth);
-                pbox++;
-            }
-        }
-        else {                  /* XYPixmap */
-            int depth = pGC->depth;
-            int numBox, increment;
-            unsigned long i, mask;
-            BoxPtr pntBox;
-
-            srcwidth = BitmapBytePad(w + leftPad);
-            increment = h * srcwidth;
-            i = 1 << (depth - 1);
-            mask = ~0;
-
-            if ((infoRec->pScrn->overlayFlags & OVERLAY_8_32_PLANAR) &&
-                (pGC->depth == 8)) {
-                i = 0x80000000;
-                mask = 0xff000000;
-            }
-
-            for (; i & mask; i >>= 1, pImage += increment) {
-                if (i & pGC->planemask) {
-                    pntBox = pbox;
-                    numBox = nboxes;
-                    while (numBox--) {
-                        srcx = pntBox->x1 - TheRect.x + leftPad;
-                        srcy = pntBox->y1 - TheRect.y;
-                        (*infoRec->WriteBitmap) (infoRec->pScrn,
-                                                 pntBox->x1, pntBox->y1,
-                                                 pntBox->x2 - pntBox->x1,
-                                                 pntBox->y2 - pntBox->y1,
-                                                 (unsigned char *) pImage +
-                                                 (srcwidth * srcy) +
-                                                 ((srcx >> 5) << 2), srcwidth,
-                                                 srcx & 31, ~0, 0, pGC->alu, i);
-                        pntBox++;
-                    }
-                }
-            }
-
-        }
-
-        if (pClipBoxes != (BoxPtr) infoRec->PreAllocMem)
-            free(pClipBoxes);
-    }
-    else
-        XAAFallbackOps.PutImage(pDraw, pGC, depth, x, y, w, h, leftPad,
-                                format, pImage);
-}
diff --git a/hw/xfree86/xaa/xaaInit.c b/hw/xfree86/xaa/xaaInit.c
deleted file mode 100644
index f146f3a..0000000
--- a/hw/xfree86/xaa/xaaInit.c
+++ /dev/null
@@ -1,635 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "windowstr.h"
-#include "xf86str.h"
-#include "mi.h"
-#include "miline.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaawrap.h"
-#include "xf86fbman.h"
-#include "servermd.h"
-#ifdef COMPOSITE
-#include "cw.h"
-#endif
-
-#define MAX_PREALLOC_MEM	65536   /* MUST be >= 1024 */
-
-#define MIN_OFFPIX_SIZE		(320*200)
-
-static Bool XAACloseScreen(ScreenPtr pScreen);
-static void XAAGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h,
-                        unsigned int format, unsigned long planemask,
-                        char *pdstLine);
-static void XAAGetSpans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt,
-                        int *pwidth, int nspans, char *pdstStart);
-static PixmapPtr XAACreatePixmap(ScreenPtr pScreen, int w, int h, int depth,
-                                 unsigned usage_hint);
-static Bool XAADestroyPixmap(PixmapPtr pPixmap);
-static Bool XAAEnterVT(ScrnInfoPtr pScrn);
-static void XAALeaveVT(ScrnInfoPtr pScrn);
-static int XAASetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr devRet);
-static void XAAEnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable);
-static Bool XAAChangeWindowAttributes(WindowPtr pWin, unsigned long mask);
-
-static DevPrivateKeyRec XAAScreenKeyRec;
-
-#define XAAScreenKey (&XAAScreenKeyRec)
-static DevPrivateKeyRec XAAGCKeyRec;
-
-#define XAAGCKey (&XAAGCKeyRec)
-static DevPrivateKeyRec XAAPixmapKeyRec;
-
-#define XAAPixmapKey (&XAAPixmapKeyRec)
-
-DevPrivateKey
-XAAGetScreenKey(void)
-{
-    return XAAScreenKey;
-}
-
-DevPrivateKey
-XAAGetGCKey(void)
-{
-    return XAAGCKey;
-}
-
-DevPrivateKey
-XAAGetPixmapKey(void)
-{
-    return XAAPixmapKey;
-}
-
-/* temp kludge */
-static Bool SwitchedOut = FALSE;
-
-XAAInfoRecPtr
-XAACreateInfoRec(void)
-{
-    XAAInfoRecPtr infoRec;
-
-    infoRec = calloc(1, sizeof(XAAInfoRec));
-    if (infoRec)
-        infoRec->CachePixelGranularity = -1;
-
-    return infoRec;
-}
-
-void
-XAADestroyInfoRec(XAAInfoRecPtr infoRec)
-{
-    if (!infoRec)
-        return;
-
-    if (infoRec->ClosePixmapCache)
-        (*infoRec->ClosePixmapCache) (xf86ScrnToScreen(infoRec->pScrn));
-
-    free(infoRec->PreAllocMem);
-
-    free(infoRec->PixmapCachePrivate);
-
-    free(infoRec);
-}
-
-Bool
-XAAInit(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
-{
-    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-    XAAScreenPtr pScreenPriv;
-    int i;
-    PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
-
-    /* Return successfully if no acceleration wanted */
-    if (!infoRec)
-        return TRUE;
-
-    if (!dixRegisterPrivateKey(&XAAGCKeyRec, PRIVATE_GC, sizeof(XAAGCRec)))
-        return FALSE;
-
-    if (!dixRegisterPrivateKey
-        (&XAAPixmapKeyRec, PRIVATE_PIXMAP, sizeof(XAAPixmapRec)))
-        return FALSE;
-
-    if (!dixRegisterPrivateKey(&XAAScreenKeyRec, PRIVATE_SCREEN, 0))
-        return FALSE;
-
-    if (!(pScreenPriv = malloc(sizeof(XAAScreenRec))))
-        return FALSE;
-
-    dixSetPrivate(&pScreen->devPrivates, XAAScreenKey, pScreenPriv);
-
-    if (!xf86FBManagerRunning(pScreen))
-        infoRec->Flags &= ~(PIXMAP_CACHE | OFFSCREEN_PIXMAPS);
-    if (!(infoRec->Flags & LINEAR_FRAMEBUFFER))
-        infoRec->Flags &= ~OFFSCREEN_PIXMAPS;
-
-    if (!infoRec->FullPlanemask) {      /* for backwards compatibility */
-        infoRec->FullPlanemask = (1 << pScrn->depth) - 1;
-        infoRec->FullPlanemasks[pScrn->depth - 1] = infoRec->FullPlanemask;
-    }
-
-    for (i = 0; i < 32; i++) {
-        if (!infoRec->FullPlanemasks[i])        /* keep any set by caller */
-            infoRec->FullPlanemasks[i] = (1 << (i + 1)) - 1;
-    }
-
-    if (!XAAInitAccel(pScreen, infoRec))
-        return FALSE;
-    pScreenPriv->AccelInfoRec = infoRec;
-    infoRec->ScratchGC.pScreen = pScreen;
-
-    if (!infoRec->GetImage)
-        infoRec->GetImage = XAAGetImage;
-    if (!infoRec->GetSpans)
-        infoRec->GetSpans = XAAGetSpans;
-    if (!infoRec->CopyWindow)
-        infoRec->CopyWindow = XAACopyWindow;
-
-    pScreenPriv->CreateGC = pScreen->CreateGC;
-    pScreen->CreateGC = XAACreateGC;
-    pScreenPriv->CloseScreen = pScreen->CloseScreen;
-    pScreen->CloseScreen = XAACloseScreen;
-    pScreenPriv->GetImage = pScreen->GetImage;
-    pScreen->GetImage = infoRec->GetImage;
-    pScreenPriv->GetSpans = pScreen->GetSpans;
-    pScreen->GetSpans = infoRec->GetSpans;
-    pScreenPriv->CopyWindow = pScreen->CopyWindow;
-    pScreen->CopyWindow = infoRec->CopyWindow;
-    pScreenPriv->CreatePixmap = pScreen->CreatePixmap;
-    pScreen->CreatePixmap = XAACreatePixmap;
-    pScreenPriv->DestroyPixmap = pScreen->DestroyPixmap;
-    pScreen->DestroyPixmap = XAADestroyPixmap;
-    pScreenPriv->ChangeWindowAttributes = pScreen->ChangeWindowAttributes;
-    pScreen->ChangeWindowAttributes = XAAChangeWindowAttributes;
-
-    pScreenPriv->EnterVT = pScrn->EnterVT;
-    pScrn->EnterVT = XAAEnterVT;
-    pScreenPriv->LeaveVT = pScrn->LeaveVT;
-    pScrn->LeaveVT = XAALeaveVT;
-    pScreenPriv->SetDGAMode = pScrn->SetDGAMode;
-    pScrn->SetDGAMode = XAASetDGAMode;
-    pScreenPriv->EnableDisableFBAccess = pScrn->EnableDisableFBAccess;
-    pScrn->EnableDisableFBAccess = XAAEnableDisableFBAccess;
-
-    pScreenPriv->WindowExposures = pScreen->WindowExposures;
-    if (ps) {
-        pScreenPriv->Composite = ps->Composite;
-        ps->Composite = XAAComposite;
-        pScreenPriv->Glyphs = ps->Glyphs;
-        ps->Glyphs = XAAGlyphs;
-    }
-    if (pScrn->overlayFlags & OVERLAY_8_32_PLANAR)
-        XAASetupOverlay8_32Planar(pScreen);
-
-    infoRec->PreAllocMem = malloc(MAX_PREALLOC_MEM);
-    if (infoRec->PreAllocMem)
-        infoRec->PreAllocSize = MAX_PREALLOC_MEM;
-
-    if (infoRec->Flags & PIXMAP_CACHE)
-        xf86RegisterFreeBoxCallback(pScreen, infoRec->InitPixmapCache,
-                                    (pointer) infoRec);
-
-    if (infoRec->Flags & MICROSOFT_ZERO_LINE_BIAS)
-        miSetZeroLineBias(pScreen, OCTANT1 | OCTANT2 | OCTANT3 | OCTANT4);
-
-#ifdef COMPOSITE
-    /* Initialize the composite wrapper.  This needs to happen after the
-     * wrapping above (so it comes before us), but before all other extensions,
-     * so it doesn't confuse them. (particularly damage).
-     */
-    miInitializeCompositeWrapper(pScreen);
-#endif
-
-    return TRUE;
-}
-
-static Bool
-XAACloseScreen(ScreenPtr pScreen)
-{
-    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-    XAAScreenPtr pScreenPriv =
-        (XAAScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
-
-    pScrn->EnterVT = pScreenPriv->EnterVT;
-    pScrn->LeaveVT = pScreenPriv->LeaveVT;
-    pScrn->EnableDisableFBAccess = pScreenPriv->EnableDisableFBAccess;
-
-    pScreen->CreateGC = pScreenPriv->CreateGC;
-    pScreen->CloseScreen = pScreenPriv->CloseScreen;
-    pScreen->GetImage = pScreenPriv->GetImage;
-    pScreen->GetSpans = pScreenPriv->GetSpans;
-    pScreen->CopyWindow = pScreenPriv->CopyWindow;
-    pScreen->WindowExposures = pScreenPriv->WindowExposures;
-    pScreen->CreatePixmap = pScreenPriv->CreatePixmap;
-    pScreen->DestroyPixmap = pScreenPriv->DestroyPixmap;
-    pScreen->ChangeWindowAttributes = pScreenPriv->ChangeWindowAttributes;
-
-    /* We leave it up to the client to free the XAAInfoRec */
-
-    free((pointer) pScreenPriv);
-
-    return (*pScreen->CloseScreen) (pScreen);
-}
-
-static void
-XAAGetImage(DrawablePtr pDraw,
-            int sx, int sy, int w, int h,
-            unsigned int format, unsigned long planemask, char *pdstLine)
-{
-    ScreenPtr pScreen = pDraw->pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    ScrnInfoPtr pScrn = infoRec->pScrn;
-
-    if (pScrn->vtSema &&
-        ((pDraw->type == DRAWABLE_WINDOW) || IS_OFFSCREEN_PIXMAP(pDraw))) {
-        if (infoRec->ReadPixmap && (format == ZPixmap) &&
-            ((planemask & infoRec->FullPlanemasks[pDraw->depth - 1]) ==
-             infoRec->FullPlanemasks[pDraw->depth - 1]) &&
-            (pDraw->bitsPerPixel == BitsPerPixel(pDraw->depth))) {
-            (*infoRec->ReadPixmap) (pScrn,
-                                    sx + pDraw->x, sy + pDraw->y, w, h,
-                                    (unsigned char *) pdstLine,
-                                    PixmapBytePad(w, pDraw->depth),
-                                    pDraw->bitsPerPixel, pDraw->depth);
-            return;
-        }
-        SYNC_CHECK(pDraw);
-    }
-
-    XAA_SCREEN_PROLOGUE(pScreen, GetImage);
-    (*pScreen->GetImage) (pDraw, sx, sy, w, h, format, planemask, pdstLine);
-    XAA_SCREEN_EPILOGUE(pScreen, GetImage, XAAGetImage);
-}
-
-static void
-XAAGetSpans(DrawablePtr pDraw,
-            int wMax, DDXPointPtr ppt, int *pwidth, int nspans, char *pdstStart)
-{
-    ScreenPtr pScreen = pDraw->pScreen;
-
-    XAA_SCREEN_PROLOGUE(pScreen, GetSpans);
-    if (xf86ScreenToScrn(pScreen)->vtSema &&
-        ((pDraw->type == DRAWABLE_WINDOW) || IS_OFFSCREEN_PIXMAP(pDraw))) {
-        SYNC_CHECK(pDraw);
-    }
-    (*pScreen->GetSpans) (pDraw, wMax, ppt, pwidth, nspans, pdstStart);
-    XAA_SCREEN_EPILOGUE(pScreen, GetSpans, XAAGetSpans);
-}
-
-static int
-XAAPixmapBPP(ScreenPtr pScreen, int depth)
-{
-    PixmapPtr pPix;
-    int bpp;
-    DestroyPixmapProcPtr destroyPixmap;
-
-    XAA_SCREEN_PROLOGUE(pScreen, CreatePixmap);
-    pPix = (*pScreen->CreatePixmap) (pScreen, 1, 1, depth,
-                                     CREATE_PIXMAP_USAGE_SCRATCH);
-    XAA_SCREEN_EPILOGUE(pScreen, CreatePixmap, XAACreatePixmap);
-    if (!pPix)
-        return 0;
-    bpp = pPix->drawable.bitsPerPixel;
-    destroyPixmap = pScreen->DestroyPixmap;
-    XAA_SCREEN_PROLOGUE(pScreen, DestroyPixmap);
-    (*pScreen->DestroyPixmap) (pPix);
-    XAA_SCREEN_EPILOGUE(pScreen, DestroyPixmap, destroyPixmap);
-    return bpp;
-}
-
-static void
-XAAInitializeOffscreenDepths(ScreenPtr pScreen)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-    int d, dep;
-
-    infoRec->offscreenDepthsInitialized = TRUE;
-    infoRec->offscreenDepths = 0;
-    if (infoRec->Flags & OFFSCREEN_PIXMAPS) {
-        for (d = 0; d < pScreen->numDepths; d++) {
-            dep = pScreen->allowedDepths[d].depth;
-            if (XAAPixmapBPP(pScreen, dep) == pScrn->bitsPerPixel)
-                infoRec->offscreenDepths |= (1 << (dep - 1));
-        }
-    }
-}
-
-static PixmapPtr
-XAACreatePixmap(ScreenPtr pScreen, int w, int h, int depth, unsigned usage_hint)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-    XAAPixmapPtr pPriv;
-    PixmapPtr pPix = NULL;
-    int size = w * h;
-
-    if (w > 32767 || h > 32767)
-        return NullPixmap;
-
-    if (!infoRec->offscreenDepthsInitialized)
-        XAAInitializeOffscreenDepths(pScreen);
-
-    if (pScrn->vtSema &&
-        (usage_hint != CREATE_PIXMAP_USAGE_GLYPH_PICTURE) &&
-        (infoRec->offscreenDepths & (1 << (depth - 1))) &&
-        (size >= MIN_OFFPIX_SIZE) && !SwitchedOut &&
-        (!infoRec->maxOffPixWidth || (w <= infoRec->maxOffPixWidth)) &&
-        (!infoRec->maxOffPixHeight || (h <= infoRec->maxOffPixHeight))) {
-        PixmapLinkPtr pLink;
-        PixmapPtr pScreenPix;
-        FBAreaPtr area;
-        int gran = 0;
-
-        switch (pScrn->bitsPerPixel) {
-        case 24:
-        case 8:
-            gran = 4;
-            break;
-        case 16:
-            gran = 2;
-            break;
-        case 32:
-            gran = 1;
-            break;
-        default:
-            break;
-        }
-
-        if (BITMAP_SCANLINE_PAD == 64)
-            gran *= 2;
-
-        if (!(area = xf86AllocateOffscreenArea(pScreen, w, h, gran, 0,
-                                               XAARemoveAreaCallback, NULL))) {
-            goto BAILOUT;
-        }
-
-        if (!(pLink = malloc(sizeof(PixmapLink)))) {
-            xf86FreeOffscreenArea(area);
-            goto BAILOUT;
-        }
-
-        XAA_SCREEN_PROLOGUE(pScreen, CreatePixmap);
-        pPix = (*pScreen->CreatePixmap) (pScreen, 0, 0, depth, usage_hint);
-        XAA_SCREEN_EPILOGUE(pScreen, CreatePixmap, XAACreatePixmap);
-
-        if (!pPix) {
-            free(pLink);
-            xf86FreeOffscreenArea(area);
-            goto BAILOUT;
-        }
-
-        pScreenPix = (*pScreen->GetScreenPixmap) (pScreen);
-
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
-        pPix->drawable.x = area->box.x1;
-        pPix->drawable.y = area->box.y1;
-        pPix->drawable.width = w;
-        pPix->drawable.height = h;
-        pPix->drawable.bitsPerPixel = pScrn->bitsPerPixel;
-        pPix->devKind = pScreenPix->devKind;
-        pPix->devPrivate.ptr = pScreenPix->devPrivate.ptr;
-        area->devPrivate.ptr = pPix;
-
-        pPriv->flags = OFFSCREEN;
-        pPriv->offscreenArea = area;
-        pPriv->freeData = FALSE;
-
-        pLink->next = infoRec->OffscreenPixmaps;
-        pLink->pPix = pPix;
-        infoRec->OffscreenPixmaps = pLink;
-        return pPix;
-    }
- BAILOUT:
-    XAA_SCREEN_PROLOGUE(pScreen, CreatePixmap);
-    pPix = (*pScreen->CreatePixmap) (pScreen, w, h, depth, usage_hint);
-    XAA_SCREEN_EPILOGUE(pScreen, CreatePixmap, XAACreatePixmap);
-
-    if (pPix) {
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
-        pPriv->flags = 0;
-        pPriv->offscreenArea = NULL;
-        pPriv->freeData = FALSE;
-        if (!w || !h)           /* either scratch or shared memory */
-            pPriv->flags |= SHARED_PIXMAP;
-    }
-
-    return pPix;
-}
-
-static Bool
-XAADestroyPixmap(PixmapPtr pPix)
-{
-    ScreenPtr pScreen = pPix->drawable.pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
-    Bool ret;
-
-    if (pPix->refcnt == 1) {
-        if (pPriv->flags & OFFSCREEN) {
-            if (pPriv->flags & DGA_PIXMAP)
-                free(pPriv->offscreenArea);
-            else {
-                FBAreaPtr area = pPriv->offscreenArea;
-                PixmapLinkPtr pLink = infoRec->OffscreenPixmaps;
-                PixmapLinkPtr prev = NULL;
-
-                while (pLink->pPix != pPix) {
-                    prev = pLink;
-                    pLink = pLink->next;
-                }
-
-                if (prev)
-                    prev->next = pLink->next;
-                else
-                    infoRec->OffscreenPixmaps = pLink->next;
-
-                if (!area)
-                    area = pLink->area;
-
-                xf86FreeOffscreenArea(area);
-                pPriv->offscreenArea = NULL;
-                free(pLink);
-            }
-        }
-
-        if (pPriv->freeData) {  /* pixmaps that were once in video ram */
-            free(pPix->devPrivate.ptr);
-            pPix->devPrivate.ptr = NULL;
-        }
-    }
-
-    XAA_SCREEN_PROLOGUE(pScreen, DestroyPixmap);
-    ret = (*pScreen->DestroyPixmap) (pPix);
-    XAA_SCREEN_EPILOGUE(pScreen, DestroyPixmap, XAADestroyPixmap);
-
-    return ret;
-}
-
-static Bool
-XAAChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    Bool ret;
-
-    XAA_SCREEN_PROLOGUE(pScreen, ChangeWindowAttributes);
-    ret = (*pScreen->ChangeWindowAttributes) (pWin, mask);
-    XAA_SCREEN_EPILOGUE(pScreen, ChangeWindowAttributes,
-                        XAAChangeWindowAttributes);
-
-    /* we have to assume that shared memory pixmaps are dirty
-       because we can't wrap operations on them */
-
-    if ((mask & CWBackPixmap) && (pWin->backgroundState == BackgroundPixmap) &&
-        PIXMAP_IS_SHARED(pWin->background.pixmap)) {
-        XAAPixmapPtr pPixPriv = XAA_GET_PIXMAP_PRIVATE(pWin->background.pixmap);
-
-        pPixPriv->flags |= DIRTY;
-    }
-    if ((mask & CWBorderPixmap) && !(pWin->borderIsPixel) &&
-        PIXMAP_IS_SHARED(pWin->border.pixmap)) {
-        XAAPixmapPtr pPixPriv = XAA_GET_PIXMAP_PRIVATE(pWin->border.pixmap);
-
-        pPixPriv->flags |= DIRTY;
-    }
-
-    return ret;
-}
-
-/*  These two aren't really needed for anything */
-
-static Bool
-XAAEnterVT(ScrnInfoPtr pScrn)
-{
-    Bool ret;
-    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
-    XAAScreenPtr pScreenPriv =
-        (XAAScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
-
-    pScrn->EnterVT = pScreenPriv->EnterVT;
-    ret = ((*pScreenPriv->EnterVT) (pScrn));
-    pScreenPriv->EnterVT = pScrn->EnterVT;
-    pScrn->EnterVT = XAAEnterVT;
-    return ret;
-}
-
-static void
-XAALeaveVT(ScrnInfoPtr pScrn)
-{
-    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
-    XAAScreenPtr pScreenPriv =
-        (XAAScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
-    XAAInfoRecPtr infoRec = pScreenPriv->AccelInfoRec;
-
-    if (infoRec->NeedToSync) {
-        (*infoRec->Sync) (infoRec->pScrn);
-        infoRec->NeedToSync = FALSE;
-    }
-
-    pScrn->LeaveVT = pScreenPriv->LeaveVT;
-    (*pScreenPriv->LeaveVT) (pScrn);
-    pScreenPriv->LeaveVT = pScrn->LeaveVT;
-    pScrn->LeaveVT = XAALeaveVT;
-}
-
-typedef struct {
-    Bool UsingPixmapCache;
-    Bool CanDoColor8x8;
-    Bool CanDoMono8x8;
-} SavedCacheState, *SavedCacheStatePtr;
-
-static int
-XAASetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr devRet)
-{
-    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    XAAScreenPtr pScreenPriv =
-        (XAAScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
-    int ret;
-
-    if (!num && infoRec->dgaSaves) {    /* restore old pixmap cache state */
-        SavedCacheStatePtr state = (SavedCacheStatePtr) infoRec->dgaSaves;
-
-        infoRec->UsingPixmapCache = state->UsingPixmapCache;
-        infoRec->CanDoColor8x8 = state->CanDoColor8x8;
-        infoRec->CanDoMono8x8 = state->CanDoMono8x8;
-        free(infoRec->dgaSaves);
-        infoRec->dgaSaves = NULL;
-    }
-
-    ret = (*pScreenPriv->SetDGAMode) (pScrn, num, devRet);
-    if (ret != Success)
-        return ret;
-
-    if (num && devRet->pPix) {  /* accelerate this pixmap */
-        XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE(devRet->pPix);
-        FBAreaPtr area;
-
-        if ((area = malloc(sizeof(FBArea)))) {
-            area->pScreen = pScreen;
-            area->box.x1 = 0;
-            area->box.x2 = 0;
-            area->box.y1 = devRet->mode->pixmapWidth;
-            area->box.y2 = devRet->mode->pixmapHeight;
-            area->granularity = 0;
-            area->MoveAreaCallback = 0;
-            area->RemoveAreaCallback = 0;
-            area->devPrivate.ptr = 0;
-
-            pixPriv->flags |= OFFSCREEN | DGA_PIXMAP;
-            pixPriv->offscreenArea = area;
-
-            if (!infoRec->dgaSaves) {   /* save pixmap cache state */
-                SavedCacheStatePtr state = malloc(sizeof(SavedCacheState));
-
-                state->UsingPixmapCache = infoRec->UsingPixmapCache;
-                state->CanDoColor8x8 = infoRec->CanDoColor8x8;
-                state->CanDoMono8x8 = infoRec->CanDoMono8x8;
-                infoRec->dgaSaves = (char *) state;
-
-                infoRec->UsingPixmapCache = FALSE;
-                if (infoRec->PixmapCacheFlags & CACHE_MONO_8x8)
-                    infoRec->CanDoMono8x8 = FALSE;
-                if (infoRec->PixmapCacheFlags & CACHE_COLOR_8x8)
-                    infoRec->CanDoColor8x8 = FALSE;
-            }
-        }
-    }
-
-    return ret;
-}
-
-static void
-XAAEnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable)
-{
-    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    XAAScreenPtr pScreenPriv =
-        (XAAScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
-
-    if (!enable) {
-        if ((infoRec->Flags & OFFSCREEN_PIXMAPS) && (infoRec->OffscreenPixmaps))
-            XAAMoveOutOffscreenPixmaps(pScreen);
-        if (infoRec->Flags & PIXMAP_CACHE)
-            XAAInvalidatePixmapCache(pScreen);
-        SwitchedOut = TRUE;
-    }
-
-    (*pScreenPriv->EnableDisableFBAccess) (pScrn, enable);
-
-    if (enable) {
-        if ((infoRec->Flags & OFFSCREEN_PIXMAPS) && (infoRec->OffscreenPixmaps))
-            XAAMoveInOffscreenPixmaps(pScreen);
-        SwitchedOut = FALSE;
-    }
-}
diff --git a/hw/xfree86/xaa/xaaInitAccel.c b/hw/xfree86/xaa/xaaInitAccel.c
deleted file mode 100644
index a36e0b7..0000000
--- a/hw/xfree86/xaa/xaaInitAccel.c
+++ /dev/null
@@ -1,1571 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <string.h>
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xf86fbman.h"
-#include "servermd.h"
-
-/*
- * XAA Config options
- */
-
-typedef enum {
-    XAAOPT_SCREEN_TO_SCREEN_COPY,
-    XAAOPT_SOLID_FILL_RECT,
-    XAAOPT_SOLID_FILL_TRAP,
-    XAAOPT_SOLID_TWO_POINT_LINE,
-    XAAOPT_SOLID_BRESENHAM_LINE,
-    XAAOPT_SOLID_HORVERT_LINE,
-    XAAOPT_DASHED_TWO_POINT_LINE,
-    XAAOPT_DASHED_BRESENHAM_LINE,
-    XAAOPT_MONO_8x8_PATTERN_FILL_RECT,
-    XAAOPT_MONO_8x8_PATTERN_FILL_TRAP,
-    XAAOPT_COL_8x8_PATTERN_FILL_RECT,
-    XAAOPT_COL_8x8_PATTERN_FILL_TRAP,
-    XAAOPT_CPU_TO_SCREEN_COL_EXP_FILL,
-    XAAOPT_SCANLINE_CPU_TO_SCREEN_COL_EXP_FILL,
-    XAAOPT_SCREEN_TO_SCREEN_COL_EXP_FILL,
-    XAAOPT_IMAGE_WRITE_RECT,
-    XAAOPT_SCANLINE_IMAGE_WRITE_RECT,
-    XAAOPT_WRITE_BITMAP,
-    XAAOPT_WRITE_PIXMAP,
-    XAAOPT_PIXMAP_CACHE,
-    XAAOPT_OFFSCREEN_PIXMAPS,
-    XAAOPT_HAS_DUMB_INVERTED_OPTION_SENSE
-} XAAOpts;
-
-static const OptionInfoRec XAAOptions[] = {
-    {XAAOPT_SCREEN_TO_SCREEN_COPY, "XaaNoScreenToScreenCopy",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_SOLID_FILL_RECT, "XaaNoSolidFillRect",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_SOLID_FILL_TRAP, "XaaNoSolidFillTrap",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_SOLID_TWO_POINT_LINE, "XaaNoSolidTwoPointLine",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_SOLID_BRESENHAM_LINE, "XaaNoSolidBresenhamLine",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_SOLID_HORVERT_LINE, "XaaNoSolidHorVertLine",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_DASHED_TWO_POINT_LINE, "XaaNoDashedTwoPointLine",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_DASHED_BRESENHAM_LINE, "XaaNoDashedBresenhamLine",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_MONO_8x8_PATTERN_FILL_RECT, "XaaNoMono8x8PatternFillRect",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_MONO_8x8_PATTERN_FILL_TRAP, "XaaNoMono8x8PatternFillTrap",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_COL_8x8_PATTERN_FILL_RECT, "XaaNoColor8x8PatternFillRect",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_COL_8x8_PATTERN_FILL_TRAP, "XaaNoColor8x8PatternFillTrap",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_CPU_TO_SCREEN_COL_EXP_FILL, "XaaNoCPUToScreenColorExpandFill",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_SCANLINE_CPU_TO_SCREEN_COL_EXP_FILL,
-     "XaaNoScanlineCPUToScreenColorExpandFill",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_SCREEN_TO_SCREEN_COL_EXP_FILL, "XaaNoScreenToScreenColorExpandFill",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_IMAGE_WRITE_RECT, "XaaNoImageWriteRect",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_SCANLINE_IMAGE_WRITE_RECT, "XaaNoScanlineImageWriteRect",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_WRITE_BITMAP, "XaaNoWriteBitmap",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_WRITE_PIXMAP, "XaaNoWritePixmap",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_PIXMAP_CACHE, "XaaNoPixmapCache",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_OFFSCREEN_PIXMAPS, "XaaNoOffscreenPixmaps",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {XAAOPT_HAS_DUMB_INVERTED_OPTION_SENSE, "XaaOffscreenPixmaps",
-     OPTV_BOOLEAN, {0}, FALSE},
-    {-1, NULL,
-     OPTV_NONE, {0}, FALSE}
-};
-
-static XF86ModuleVersionInfo xaaVersRec = {
-    "xaa",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    XAA_VERSION_MAJOR,
-    XAA_VERSION_MINOR,
-    XAA_VERSION_RELEASE,
-    ABI_CLASS_VIDEODRV,         /* requires the video driver ABI */
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData xaaModuleData = { &xaaVersRec, NULL, NULL };
-
-Bool
-XAAInitAccel(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
-{
-    int index = pScreen->myNum;
-    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-    Bool HaveScreenToScreenCopy = FALSE;
-    Bool HaveColorExpansion = FALSE;
-    Bool HaveScanlineColorExpansion = FALSE;
-    Bool HaveSolidFillRect = FALSE;
-    Bool HaveMono8x8PatternFillRect = FALSE;
-    Bool HaveColor8x8PatternFillRect = FALSE;
-    Bool HaveSolidFillTrap = FALSE;
-    Bool HaveMono8x8PatternFillTrap = FALSE;
-    Bool HaveColor8x8PatternFillTrap = FALSE;
-    Bool HaveSolidTwoPointLine = FALSE;
-    Bool HaveSolidBresenhamLine = FALSE;
-    Bool HaveSolidHorVertLine = FALSE;
-    Bool HaveDashedTwoPointLine = FALSE;
-    Bool HaveDashedBresenhamLine = FALSE;
-    Bool HaveImageWriteRect = FALSE;
-    Bool HaveScanlineImageWriteRect = FALSE;
-    Bool HaveScreenToScreenColorExpandFill = FALSE;
-    OptionInfoPtr options;
-    int is_shared = 0;
-    int i;
-
-    options = xnfalloc(sizeof(XAAOptions));
-    (void) memcpy(options, XAAOptions, sizeof(XAAOptions));
-    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
-
-    infoRec->pScrn = pScrn;
-    infoRec->NeedToSync = FALSE;
-
-    /* must have a Sync function */
-    if (!infoRec->Sync)
-        return FALSE;
-    for (i = 0; i < pScrn->numEntities; i++) {
-        if (xf86IsEntityShared(pScrn->entityList[i]))
-            is_shared = 1;
-    }
-
-    /* If this PCI entity has IS_SHARED_ACCEL set in entityProp
-     * then a RestoreAccelState function is required
-     */
-    if (!infoRec->RestoreAccelState && is_shared)
-        return FALSE;
-
-    if (infoRec->RestoreAccelState) {
-        if (!XAAInitStateWrap(pScreen, infoRec))
-            return FALSE;
-    }
-
-    if (serverGeneration == 1)
-        xf86DrvMsg(index, X_INFO,
-                   "Using XFree86 Acceleration Architecture (XAA)\n");
-
-    /************** Low Level *************/
-
-    if (!infoRec->SetClippingRectangle || !infoRec->DisableClipping) {
-        infoRec->ClippingFlags = 0;
-        infoRec->SetClippingRectangle = NULL;
-        infoRec->DisableClipping = NULL;
-    }
-
-    /**** CopyArea ****/
-
-    if (infoRec->SetupForScreenToScreenCopy &&
-        infoRec->SubsequentScreenToScreenCopy &&
-        !xf86ReturnOptValBool(options, XAAOPT_SCREEN_TO_SCREEN_COPY, FALSE)) {
-        HaveScreenToScreenCopy = TRUE;
-    }
-    else {
-        infoRec->ScreenToScreenCopyFlags = 0;
-        infoRec->SetupForScreenToScreenCopy = NULL;
-        infoRec->SubsequentScreenToScreenCopy = NULL;
-    }
-
-    /**** Solid Filled Rects ****/
-
-    if (infoRec->SetupForSolidFill && infoRec->SubsequentSolidFillRect &&
-        !xf86ReturnOptValBool(options, XAAOPT_SOLID_FILL_RECT, FALSE)) {
-        HaveSolidFillRect = TRUE;
-        if (infoRec->SubsequentSolidFillTrap &&
-            !xf86ReturnOptValBool(options, XAAOPT_SOLID_FILL_TRAP, FALSE))
-            HaveSolidFillTrap = TRUE;
-        else
-            infoRec->SubsequentSolidFillTrap = NULL;
-    }
-    else {
-        infoRec->SolidFillFlags = 0;
-        infoRec->SetupForSolidFill = NULL;
-        infoRec->SubsequentSolidFillRect = NULL;
-        infoRec->SubsequentSolidFillTrap = NULL;
-    }
-
-    /**** Solid lines ****/
-
-    if (infoRec->SetupForSolidLine) {
-        if (infoRec->SubsequentSolidTwoPointLine &&
-            !xf86ReturnOptValBool(options, XAAOPT_SOLID_TWO_POINT_LINE, FALSE))
-            HaveSolidTwoPointLine = TRUE;
-        if (infoRec->SubsequentSolidBresenhamLine &&
-            !xf86ReturnOptValBool(options, XAAOPT_SOLID_BRESENHAM_LINE,
-                                  FALSE)) {
-            HaveSolidBresenhamLine = TRUE;
-
-            if (infoRec->SolidBresenhamLineErrorTermBits)
-                infoRec->SolidBresenhamLineErrorTermBits =
-                    ~((1 << infoRec->SolidBresenhamLineErrorTermBits) - 1);
-        }
-
-        if (infoRec->SubsequentSolidHorVertLine &&
-            !xf86ReturnOptValBool(options, XAAOPT_SOLID_HORVERT_LINE, FALSE))
-            HaveSolidHorVertLine = TRUE;
-        else if (HaveSolidTwoPointLine) {
-            infoRec->SubsequentSolidHorVertLine = XAASolidHorVertLineAsTwoPoint;
-            HaveSolidHorVertLine = TRUE;
-        }
-        else if (HaveSolidBresenhamLine) {
-            infoRec->SubsequentSolidHorVertLine =
-                XAASolidHorVertLineAsBresenham;
-            HaveSolidHorVertLine = TRUE;
-        }
-    }
-
-    /* XXX Should this also check for XAAOPT_SOLID_HORVERT_LINE? */
-    if (!HaveSolidTwoPointLine &&
-        !HaveSolidBresenhamLine && !HaveSolidHorVertLine && HaveSolidFillRect) {
-        infoRec->SetupForSolidLine = infoRec->SetupForSolidFill;
-        infoRec->SubsequentSolidHorVertLine = XAASolidHorVertLineAsRects;
-        infoRec->SolidLineFlags = infoRec->SolidFillFlags;
-        HaveSolidHorVertLine = TRUE;
-    }
-
-    if (!HaveSolidTwoPointLine)
-        infoRec->SubsequentSolidTwoPointLine = NULL;
-    if (!HaveSolidBresenhamLine)
-        infoRec->SubsequentSolidBresenhamLine = NULL;
-    if (!HaveSolidHorVertLine)
-        infoRec->SubsequentSolidHorVertLine = NULL;
-
-    /* Disable all if nothing left over */
-    if (!HaveSolidTwoPointLine &&
-        !HaveSolidBresenhamLine && !HaveSolidHorVertLine) {
-        infoRec->SolidLineFlags = 0;
-        infoRec->SetupForSolidLine = NULL;
-    }
-
-    /**** 8x8 Mono Pattern Filled Rects ****/
-
-    if (infoRec->SetupForMono8x8PatternFill &&
-        infoRec->SubsequentMono8x8PatternFillRect &&
-        !xf86ReturnOptValBool(options,
-                              XAAOPT_MONO_8x8_PATTERN_FILL_RECT, FALSE)) {
-        HaveMono8x8PatternFillRect = TRUE;
-        if (infoRec->SubsequentMono8x8PatternFillTrap &&
-            !xf86ReturnOptValBool(options,
-                                  XAAOPT_MONO_8x8_PATTERN_FILL_TRAP, FALSE))
-            HaveMono8x8PatternFillTrap = TRUE;
-
-        if (infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS) {
-            infoRec->CanDoMono8x8 = TRUE;
-        }
-        else {                  /* others require caching */
-            int min_pitch;
-
-            infoRec->PixmapCacheFlags |= CACHE_MONO_8x8;
-
-            switch (pScrn->bitsPerPixel) {
-            case 32:
-                min_pitch = 2;
-                break;
-            case 24:
-                min_pitch = 3;
-                break;
-            case 16:
-                min_pitch = 4;
-                break;
-            default:
-                min_pitch = 8;
-                break;
-            }
-
-            if (min_pitch > infoRec->MonoPatternPitch)
-                infoRec->MonoPatternPitch = min_pitch;
-
-            if (infoRec->Mono8x8PatternFillFlags &
-                HARDWARE_PATTERN_PROGRAMMED_ORIGIN) {
-                if (!infoRec->CacheWidthMono8x8Pattern ||
-                    !infoRec->CacheHeightMono8x8Pattern) {
-                    infoRec->CacheWidthMono8x8Pattern =
-                        infoRec->MonoPatternPitch;
-                    infoRec->CacheHeightMono8x8Pattern = 1;
-                }
-            }
-            else {
-                int numPerLine = 128 / infoRec->MonoPatternPitch;
-
-                if (!infoRec->CacheWidthMono8x8Pattern ||
-                    !infoRec->CacheHeightMono8x8Pattern) {
-                    infoRec->CacheWidthMono8x8Pattern =
-                        numPerLine * infoRec->MonoPatternPitch;
-                    infoRec->CacheHeightMono8x8Pattern =
-                        (64 + numPerLine - 1) / numPerLine;
-                }
-            }
-        }
-    }
-    else {
-        infoRec->Mono8x8PatternFillFlags = 0;
-        infoRec->SetupForMono8x8PatternFill = NULL;
-        infoRec->SubsequentMono8x8PatternFillRect = NULL;
-    }
-
-    /**** Dashed lines ****/
-
-    if (infoRec->SetupForDashedLine && infoRec->DashPatternMaxLength) {
-        if (infoRec->SubsequentDashedTwoPointLine &&
-            !xf86ReturnOptValBool(options, XAAOPT_DASHED_TWO_POINT_LINE, FALSE))
-            HaveDashedTwoPointLine = TRUE;
-        if (infoRec->SubsequentDashedBresenhamLine &&
-            !xf86ReturnOptValBool(options, XAAOPT_DASHED_BRESENHAM_LINE,
-                                  FALSE)) {
-            HaveDashedBresenhamLine = TRUE;
-
-            if (infoRec->DashedBresenhamLineErrorTermBits)
-                infoRec->DashedBresenhamLineErrorTermBits =
-                    ~((1 << infoRec->DashedBresenhamLineErrorTermBits) - 1);
-        }
-    }
-
-    if (!HaveDashedTwoPointLine)
-        infoRec->SubsequentDashedTwoPointLine = NULL;
-    if (!HaveDashedBresenhamLine)
-        infoRec->SubsequentDashedBresenhamLine = NULL;
-
-    /* Disable all if nothing left over */
-    if (!HaveDashedTwoPointLine && !HaveDashedBresenhamLine) {
-        infoRec->DashedLineFlags = 0;
-        infoRec->SetupForDashedLine = NULL;
-    }
-
-    /**** 8x8 Color Pattern Filled Rects ****/
-
-    if (infoRec->SetupForColor8x8PatternFill &&
-        infoRec->SubsequentColor8x8PatternFillRect &&
-        !xf86ReturnOptValBool(options, XAAOPT_COL_8x8_PATTERN_FILL_RECT,
-                              FALSE)) {
-        HaveColor8x8PatternFillRect = TRUE;
-        if (infoRec->SubsequentColor8x8PatternFillTrap &&
-            !xf86ReturnOptValBool(options, XAAOPT_COL_8x8_PATTERN_FILL_TRAP,
-                                  FALSE))
-            HaveColor8x8PatternFillTrap = TRUE;
-        else
-            infoRec->SubsequentColor8x8PatternFillTrap = NULL;
-
-        infoRec->PixmapCacheFlags |= CACHE_COLOR_8x8;
-
-        if (infoRec->Color8x8PatternFillFlags &
-            HARDWARE_PATTERN_PROGRAMMED_ORIGIN) {
-            if (!infoRec->CacheWidthColor8x8Pattern ||
-                !infoRec->CacheHeightColor8x8Pattern) {
-                infoRec->CacheWidthColor8x8Pattern = 64;
-                infoRec->CacheHeightColor8x8Pattern = 1;
-            }
-        }
-        else {
-            if (!infoRec->CacheWidthColor8x8Pattern ||
-                !infoRec->CacheHeightColor8x8Pattern) {
-                infoRec->CacheWidthColor8x8Pattern = 128;
-                infoRec->CacheHeightColor8x8Pattern = 8;
-            }
-        }
-    }
-    else {
-        infoRec->Color8x8PatternFillFlags = 0;
-        infoRec->SetupForColor8x8PatternFill = NULL;
-        infoRec->SubsequentColor8x8PatternFillRect = NULL;
-        infoRec->SubsequentColor8x8PatternFillTrap = NULL;
-    }
-
-    /**** Color Expansion ****/
-
-    if (infoRec->SetupForCPUToScreenColorExpandFill &&
-        infoRec->ColorExpandBase &&
-        infoRec->SubsequentCPUToScreenColorExpandFill &&
-        !xf86ReturnOptValBool(options, XAAOPT_CPU_TO_SCREEN_COL_EXP_FILL,
-                              FALSE)) {
-        int dwordsNeeded = pScrn->virtualX;
-
-        infoRec->ColorExpandRange >>= 2;        /* convert to DWORDS */
-        HaveColorExpansion = TRUE;
-
-        if (infoRec->CPUToScreenColorExpandFillFlags &
-            LEFT_EDGE_CLIPPING_NEGATIVE_X)
-            dwordsNeeded += 31;
-        dwordsNeeded = (dwordsNeeded + 31) >> 5;
-        if (dwordsNeeded > infoRec->ColorExpandRange)
-            infoRec->CPUToScreenColorExpandFillFlags |= CPU_TRANSFER_BASE_FIXED;
-    }
-    else {
-        infoRec->CPUToScreenColorExpandFillFlags = 0;
-        infoRec->SetupForCPUToScreenColorExpandFill = NULL;
-        infoRec->SubsequentCPUToScreenColorExpandFill = NULL;
-    }
-
-    /**** Scanline Color Expansion ****/
-
-    if (infoRec->SetupForScanlineCPUToScreenColorExpandFill &&
-        infoRec->SubsequentScanlineCPUToScreenColorExpandFill &&
-        infoRec->SubsequentColorExpandScanline &&
-        infoRec->ScanlineColorExpandBuffers &&
-        (infoRec->NumScanlineColorExpandBuffers > 0) &&
-        !xf86ReturnOptValBool(options,
-                              XAAOPT_SCANLINE_CPU_TO_SCREEN_COL_EXP_FILL,
-                              FALSE)) {
-        HaveScanlineColorExpansion = TRUE;
-    }
-    else {
-        infoRec->ScanlineCPUToScreenColorExpandFillFlags = 0;
-        infoRec->SetupForScanlineCPUToScreenColorExpandFill = NULL;
-        infoRec->SubsequentScanlineCPUToScreenColorExpandFill = NULL;
-        infoRec->SubsequentColorExpandScanline = NULL;
-    }
-
-    /**** Screen to Screen Color Expansion ****/
-
-    if (infoRec->SetupForScreenToScreenColorExpandFill &&
-        infoRec->SubsequentScreenToScreenColorExpandFill &&
-        !xf86ReturnOptValBool(options, XAAOPT_SCREEN_TO_SCREEN_COL_EXP_FILL,
-                              FALSE)) {
-        HaveScreenToScreenColorExpandFill = TRUE;
-        if (!infoRec->CacheColorExpandDensity)
-            infoRec->CacheColorExpandDensity = 1;
-    }
-    else {
-        infoRec->ScreenToScreenColorExpandFillFlags = 0;
-        infoRec->SetupForScreenToScreenColorExpandFill = NULL;
-        infoRec->SubsequentScreenToScreenColorExpandFill = NULL;
-    }
-
-    /**** Image Writes ****/
-
-    if (infoRec->SetupForImageWrite && infoRec->ImageWriteBase &&
-        infoRec->SubsequentImageWriteRect &&
-        !xf86ReturnOptValBool(options, XAAOPT_IMAGE_WRITE_RECT, FALSE)) {
-
-        infoRec->ImageWriteRange >>= 2; /* convert to DWORDS */
-        if (infoRec->ImageWriteFlags & CPU_TRANSFER_BASE_FIXED)
-            infoRec->ImageWriteRange = 0;
-        HaveImageWriteRect = TRUE;
-    }
-    else {
-        infoRec->ImageWriteFlags = 0;
-        infoRec->SetupForImageWrite = NULL;
-        infoRec->SubsequentImageWriteRect = NULL;
-    }
-
-    /**** Scanline Image Writes ****/
-
-    if (infoRec->SetupForScanlineImageWrite &&
-        infoRec->SubsequentScanlineImageWriteRect &&
-        infoRec->SubsequentImageWriteScanline &&
-        infoRec->ScanlineImageWriteBuffers &&
-        (infoRec->NumScanlineImageWriteBuffers > 0) &&
-        !xf86ReturnOptValBool(options, XAAOPT_SCANLINE_IMAGE_WRITE_RECT,
-                              FALSE)) {
-        HaveScanlineImageWriteRect = TRUE;
-    }
-    else {
-        infoRec->ScanlineImageWriteFlags = 0;
-        infoRec->SetupForScanlineImageWrite = NULL;
-        infoRec->SubsequentScanlineImageWriteRect = NULL;
-        infoRec->SubsequentImageWriteScanline = NULL;
-    }
-
-#ifndef __i386__
-    /* XAA makes some unaligned accesses when clipping is not available */
-#define CLIP_FLAGS (LEFT_EDGE_CLIPPING | LEFT_EDGE_CLIPPING_NEGATIVE_X)
-    if (HaveImageWriteRect &&
-        ((infoRec->ImageWriteFlags & CLIP_FLAGS) != CLIP_FLAGS)) {
-        HaveImageWriteRect = FALSE;
-    }
-    if (HaveScanlineImageWriteRect &&
-        ((infoRec->ScanlineImageWriteFlags & CLIP_FLAGS) != CLIP_FLAGS)) {
-        HaveScanlineImageWriteRect = FALSE;
-    }
-#endif
-
-    if (serverGeneration == 1) {
-        if (HaveScreenToScreenCopy)
-            xf86ErrorF("\tScreen to screen bit blits\n");
-        if (HaveSolidFillRect)
-            xf86ErrorF("\tSolid filled rectangles\n");
-        if (HaveSolidFillTrap)
-            xf86ErrorF("\tSolid filled trapezoids\n");
-        if (HaveMono8x8PatternFillRect)
-            xf86ErrorF("\t8x8 mono pattern filled rectangles\n");
-        if (HaveMono8x8PatternFillTrap)
-            xf86ErrorF("\t8x8 mono pattern filled trapezoids\n");
-        if (HaveColor8x8PatternFillRect)
-            xf86ErrorF("\t8x8 color pattern filled rectangles\n");
-        if (HaveColor8x8PatternFillTrap)
-            xf86ErrorF("\t8x8 color pattern filled trapezoids\n");
-
-        if (HaveColorExpansion)
-            xf86ErrorF("\tCPU to Screen color expansion\n");
-        else if (HaveScanlineColorExpansion)
-            xf86ErrorF("\tIndirect CPU to Screen color expansion\n");
-
-        if (HaveScreenToScreenColorExpandFill)
-            xf86ErrorF("\tScreen to Screen color expansion\n");
-
-        if (HaveSolidTwoPointLine || HaveSolidBresenhamLine)
-            xf86ErrorF("\tSolid Lines\n");
-        else if (HaveSolidHorVertLine)
-            xf86ErrorF("\tSolid Horizontal and Vertical Lines\n");
-
-        if (HaveDashedTwoPointLine || HaveDashedBresenhamLine)
-            xf86ErrorF("\tDashed Lines\n");
-
-        if (HaveImageWriteRect)
-            xf86ErrorF("\tImage Writes\n");
-        else if (HaveScanlineImageWriteRect)
-            xf86ErrorF("\tScanline Image Writes\n");
-
-    }
-
-#define XAAMSG(s) do { if (serverGeneration == 1) xf86ErrorF(s); } while (0)
-
-    if ((infoRec->Flags & OFFSCREEN_PIXMAPS) && HaveScreenToScreenCopy &&
-        xf86ReturnOptValBool(options,
-                             XAAOPT_HAS_DUMB_INVERTED_OPTION_SENSE, FALSE)) {
-        XAAMSG("\tOffscreen Pixmaps\n");
-    }
-    else {
-        infoRec->Flags &= ~OFFSCREEN_PIXMAPS;
-    }
-
-    /************** Mid Level *************/
-
-    /**** ScreenToScreenBitBlt ****/
-
-    if (infoRec->ScreenToScreenBitBlt) {
-        XAAMSG("\tDriver provided ScreenToScreenBitBlt replacement\n");
-    }
-    else if (HaveScreenToScreenCopy) {
-        infoRec->ScreenToScreenBitBlt = XAAScreenToScreenBitBlt;
-        infoRec->ScreenToScreenBitBltFlags = infoRec->ScreenToScreenCopyFlags;
-    }
-
-    /**** FillSolidRects ****/
-
-    if (infoRec->FillSolidRects) {
-        XAAMSG("\tDriver provided FillSolidRects replacement\n");
-    }
-    else if (HaveSolidFillRect) {
-        infoRec->FillSolidRects = XAAFillSolidRects;
-        infoRec->FillSolidRectsFlags = infoRec->SolidFillFlags;
-    }
-
-    /**** FillSolidSpans ****/
-
-    if (infoRec->FillSolidSpans) {
-        XAAMSG("\tDriver provided FillSolidSpans replacement\n");
-    }
-    else if (HaveSolidFillRect) {
-        infoRec->FillSolidSpans = XAAFillSolidSpans;
-        infoRec->FillSolidSpansFlags = infoRec->SolidFillFlags;
-    }
-
-    /**** FillMono8x8PatternRects ****/
-
-    if (infoRec->FillMono8x8PatternRects) {
-        XAAMSG("\tDriver provided FillMono8x8PatternRects replacement\n");
-    }
-    else if (HaveMono8x8PatternFillRect) {
-        infoRec->FillMono8x8PatternRects =
-            (infoRec->
-             Mono8x8PatternFillFlags & HARDWARE_PATTERN_SCREEN_ORIGIN) ?
-            XAAFillMono8x8PatternRectsScreenOrigin : XAAFillMono8x8PatternRects;
-
-        infoRec->FillMono8x8PatternRectsFlags =
-            infoRec->Mono8x8PatternFillFlags;
-    }
-
-    /**** FillMono8x8PatternSpans ****/
-
-    if (infoRec->FillMono8x8PatternSpans) {
-        XAAMSG("\tDriver provided FillMono8x8PatternSpans replacement\n");
-    }
-    else if (HaveMono8x8PatternFillRect) {
-        infoRec->FillMono8x8PatternSpans =
-            (infoRec->
-             Mono8x8PatternFillFlags & HARDWARE_PATTERN_SCREEN_ORIGIN) ?
-            XAAFillMono8x8PatternSpansScreenOrigin : XAAFillMono8x8PatternSpans;
-
-        infoRec->FillMono8x8PatternSpansFlags =
-            infoRec->Mono8x8PatternFillFlags;
-    }
-
-    /**** FillColor8x8Rects ****/
-
-    if (infoRec->FillColor8x8PatternRects) {
-        XAAMSG("\tDriver provided FillColor8x8PatternRects replacement\n");
-    }
-    else if (HaveColor8x8PatternFillRect) {
-        infoRec->FillColor8x8PatternRects =
-            (infoRec->
-             Color8x8PatternFillFlags & HARDWARE_PATTERN_SCREEN_ORIGIN) ?
-            XAAFillColor8x8PatternRectsScreenOrigin :
-            XAAFillColor8x8PatternRects;
-
-        infoRec->FillColor8x8PatternRectsFlags =
-            infoRec->Color8x8PatternFillFlags;
-    }
-
-    /**** FillColor8x8Spans ****/
-
-    if (infoRec->FillColor8x8PatternSpans) {
-        XAAMSG("\tDriver provided FillColor8x8PatternSpans replacement\n");
-    }
-    else if (HaveColor8x8PatternFillRect) {
-        infoRec->FillColor8x8PatternSpans =
-            (infoRec->
-             Color8x8PatternFillFlags & HARDWARE_PATTERN_SCREEN_ORIGIN) ?
-            XAAFillColor8x8PatternSpansScreenOrigin :
-            XAAFillColor8x8PatternSpans;
-
-        infoRec->FillColor8x8PatternSpansFlags =
-            infoRec->Color8x8PatternFillFlags;
-    }
-
-    /**** FillCacheBltRects ****/
-
-    if (infoRec->FillCacheBltRects) {
-        XAAMSG("\tDriver provided FillCacheBltRects replacement\n");
-    }
-    else if (HaveScreenToScreenCopy) {
-        infoRec->FillCacheBltRects = XAAFillCacheBltRects;
-        infoRec->FillCacheBltRectsFlags = infoRec->ScreenToScreenCopyFlags;
-    }
-
-    /**** FillCacheBltSpans ****/
-
-    if (infoRec->FillCacheBltSpans) {
-        XAAMSG("\tDriver provided FillCacheBltSpans replacement\n");
-    }
-    else if (HaveScreenToScreenCopy) {
-        infoRec->FillCacheBltSpans = XAAFillCacheBltSpans;
-        infoRec->FillCacheBltSpansFlags = infoRec->ScreenToScreenCopyFlags;
-    }
-
-    /**** FillCacheExpandRects ****/
-
-    if (infoRec->FillCacheExpandRects) {
-        XAAMSG("\tDriver provided FillCacheExpandRects replacement\n");
-    }
-    else if (HaveScreenToScreenColorExpandFill) {
-        infoRec->FillCacheExpandRects = XAAFillCacheExpandRects;
-        infoRec->FillCacheExpandRectsFlags =
-            infoRec->ScreenToScreenColorExpandFillFlags;
-    }
-
-    /**** FillCacheExpandSpans ****/
-
-    if (infoRec->FillCacheExpandSpans) {
-        XAAMSG("\tDriver provided FillCacheExpandSpans replacement\n");
-    }
-    else if (HaveScreenToScreenColorExpandFill) {
-        infoRec->FillCacheExpandSpans = XAAFillCacheExpandSpans;
-        infoRec->FillCacheExpandSpansFlags =
-            infoRec->ScreenToScreenColorExpandFillFlags;
-    }
-
-    /**** FillColorExpandRects ****/
-
-    if (infoRec->FillColorExpandRects) {
-        XAAMSG("\tDriver provided FillColorExpandRects replacement\n");
-    }
-    else if (HaveColorExpansion) {
-        if (infoRec->CPUToScreenColorExpandFillFlags & TRIPLE_BITS_24BPP) {
-            if (infoRec->CPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST) {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->FillColorExpandRects =
-                        XAAFillColorExpandRects3MSBFirstFixedBase;
-                else
-                    infoRec->FillColorExpandRects =
-                        XAAFillColorExpandRects3MSBFirst;
-            }
-            else {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->FillColorExpandRects =
-                        XAAFillColorExpandRects3LSBFirstFixedBase;
-                else
-                    infoRec->FillColorExpandRects =
-                        XAAFillColorExpandRects3LSBFirst;
-            }
-        }
-        else {
-            if (infoRec->CPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST) {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->FillColorExpandRects =
-                        XAAFillColorExpandRectsMSBFirstFixedBase;
-                else
-                    infoRec->FillColorExpandRects =
-                        XAAFillColorExpandRectsMSBFirst;
-            }
-            else {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->FillColorExpandRects =
-                        XAAFillColorExpandRectsLSBFirstFixedBase;
-                else
-                    infoRec->FillColorExpandRects =
-                        XAAFillColorExpandRectsLSBFirst;
-            }
-        }
-        infoRec->FillColorExpandRectsFlags =
-            infoRec->CPUToScreenColorExpandFillFlags;
-    }
-    else if (HaveScanlineColorExpansion) {
-        if (infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-            TRIPLE_BITS_24BPP) {
-            if (infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST)
-                infoRec->FillColorExpandRects =
-                    XAAFillScanlineColorExpandRects3MSBFirst;
-            else
-                infoRec->FillColorExpandRects =
-                    XAAFillScanlineColorExpandRects3LSBFirst;
-        }
-        else {
-            if (infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST)
-                infoRec->FillColorExpandRects =
-                    XAAFillScanlineColorExpandRectsMSBFirst;
-            else
-                infoRec->FillColorExpandRects =
-                    XAAFillScanlineColorExpandRectsLSBFirst;
-        }
-        infoRec->FillColorExpandRectsFlags =
-            infoRec->ScanlineCPUToScreenColorExpandFillFlags;
-    }
-
-    /**** FillColorExpandSpans ****/
-
-    if (infoRec->FillColorExpandSpans) {
-        XAAMSG("\tDriver provided FillColorExpandSpans replacement\n");
-    }
-    else if (HaveColorExpansion) {
-        if (infoRec->CPUToScreenColorExpandFillFlags & TRIPLE_BITS_24BPP) {
-            if (infoRec->CPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST) {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->FillColorExpandSpans =
-                        XAAFillColorExpandSpans3MSBFirstFixedBase;
-                else
-                    infoRec->FillColorExpandSpans =
-                        XAAFillColorExpandSpans3MSBFirst;
-            }
-            else {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->FillColorExpandSpans =
-                        XAAFillColorExpandSpans3LSBFirstFixedBase;
-                else
-                    infoRec->FillColorExpandSpans =
-                        XAAFillColorExpandSpans3LSBFirst;
-            }
-        }
-        else {
-            if (infoRec->CPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST) {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->FillColorExpandSpans =
-                        XAAFillColorExpandSpansMSBFirstFixedBase;
-                else
-                    infoRec->FillColorExpandSpans =
-                        XAAFillColorExpandSpansMSBFirst;
-            }
-            else {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->FillColorExpandSpans =
-                        XAAFillColorExpandSpansLSBFirstFixedBase;
-                else
-                    infoRec->FillColorExpandSpans =
-                        XAAFillColorExpandSpansLSBFirst;
-            }
-        }
-        infoRec->FillColorExpandSpansFlags =
-            infoRec->CPUToScreenColorExpandFillFlags;
-    }
-    else if (HaveScanlineColorExpansion) {
-        if (infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-            TRIPLE_BITS_24BPP) {
-            if (infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST)
-                infoRec->FillColorExpandSpans =
-                    XAAFillScanlineColorExpandSpans3MSBFirst;
-            else
-                infoRec->FillColorExpandSpans =
-                    XAAFillScanlineColorExpandSpans3LSBFirst;
-        }
-        else {
-            if (infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST)
-                infoRec->FillColorExpandSpans =
-                    XAAFillScanlineColorExpandSpansMSBFirst;
-            else
-                infoRec->FillColorExpandSpans =
-                    XAAFillScanlineColorExpandSpansLSBFirst;
-        }
-        infoRec->FillColorExpandSpansFlags =
-            infoRec->ScanlineCPUToScreenColorExpandFillFlags;
-    }
-
-    /**** FillImageWriteRects ****/
-
-    if (infoRec->FillImageWriteRects) {
-        XAAMSG("\tDriver provided FillImageWriteRects replacement\n");
-    }
-    else if (HaveImageWriteRect &&
-             (infoRec->ImageWriteFlags & LEFT_EDGE_CLIPPING_NEGATIVE_X) &&
-             (infoRec->ImageWriteFlags & LEFT_EDGE_CLIPPING)) {
-        infoRec->FillImageWriteRects = XAAFillImageWriteRects;
-        infoRec->FillImageWriteRectsFlags = infoRec->ImageWriteFlags;
-    }
-
-    /**** WriteBitmap ****/
-
-    if (infoRec->WriteBitmap &&
-        !xf86ReturnOptValBool(options, XAAOPT_WRITE_BITMAP, FALSE)) {
-        XAAMSG("\tDriver provided WriteBitmap replacement\n");
-    }
-    else if (HaveColorExpansion) {
-        if (infoRec->CPUToScreenColorExpandFillFlags & TRIPLE_BITS_24BPP) {
-            if (infoRec->CPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST) {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->WriteBitmap =
-                        XAAWriteBitmapColorExpand3MSBFirstFixedBase;
-                else
-                    infoRec->WriteBitmap = XAAWriteBitmapColorExpand3MSBFirst;
-            }
-            else {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->WriteBitmap =
-                        XAAWriteBitmapColorExpand3LSBFirstFixedBase;
-                else
-                    infoRec->WriteBitmap = XAAWriteBitmapColorExpand3LSBFirst;
-            }
-        }
-        else {
-            if (infoRec->CPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST) {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->WriteBitmap =
-                        XAAWriteBitmapColorExpandMSBFirstFixedBase;
-                else
-                    infoRec->WriteBitmap = XAAWriteBitmapColorExpandMSBFirst;
-            }
-            else {
-                if (infoRec->CPUToScreenColorExpandFillFlags &
-                    CPU_TRANSFER_BASE_FIXED)
-                    infoRec->WriteBitmap =
-                        XAAWriteBitmapColorExpandLSBFirstFixedBase;
-                else
-                    infoRec->WriteBitmap = XAAWriteBitmapColorExpandLSBFirst;
-            }
-        }
-        infoRec->WriteBitmapFlags = infoRec->CPUToScreenColorExpandFillFlags;
-    }
-    else if (HaveScanlineColorExpansion) {
-        if (infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-            TRIPLE_BITS_24BPP) {
-            if (infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST)
-                infoRec->WriteBitmap =
-                    XAAWriteBitmapScanlineColorExpand3MSBFirst;
-            else
-                infoRec->WriteBitmap =
-                    XAAWriteBitmapScanlineColorExpand3LSBFirst;
-        }
-        else {
-            if (infoRec->ScanlineCPUToScreenColorExpandFillFlags &
-                BIT_ORDER_IN_BYTE_MSBFIRST)
-                infoRec->WriteBitmap =
-                    XAAWriteBitmapScanlineColorExpandMSBFirst;
-            else
-                infoRec->WriteBitmap =
-                    XAAWriteBitmapScanlineColorExpandLSBFirst;
-        }
-        infoRec->WriteBitmapFlags =
-            infoRec->ScanlineCPUToScreenColorExpandFillFlags;
-    }
-    else
-        infoRec->WriteBitmap = NULL;
-
-    /**** TE Glyphs ****/
-
-    if (infoRec->TEGlyphRenderer) {
-        XAAMSG("\tDriver provided TEGlyphRenderer replacement\n");
-    }
-    else if (HaveColorExpansion) {
-        infoRec->TEGlyphRendererFlags =
-            infoRec->CPUToScreenColorExpandFillFlags;
-
-        if (infoRec->TEGlyphRendererFlags & TRIPLE_BITS_24BPP) {
-            if (infoRec->TEGlyphRendererFlags & BIT_ORDER_IN_BYTE_MSBFIRST) {
-                if (infoRec->TEGlyphRendererFlags & CPU_TRANSFER_BASE_FIXED)
-                    infoRec->TEGlyphRenderer =
-                        XAATEGlyphRenderer3MSBFirstFixedBase;
-                else
-                    infoRec->TEGlyphRenderer = XAATEGlyphRenderer3MSBFirst;
-            }
-            else {
-                if (infoRec->TEGlyphRendererFlags & CPU_TRANSFER_BASE_FIXED)
-                    infoRec->TEGlyphRenderer =
-                        XAATEGlyphRenderer3LSBFirstFixedBase;
-                else
-                    infoRec->TEGlyphRenderer = XAATEGlyphRenderer3LSBFirst;
-            }
-
-            if (!HaveSolidFillRect &&
-                (infoRec->TEGlyphRendererFlags & RGB_EQUAL)) {
-                infoRec->TEGlyphRendererFlags &= ~RGB_EQUAL;
-                XAAMSG("WARNING:  TEGlyphRenderer cannot support RGB_EQUAL"
-                       " without solid fills\n");
-            }
-        }
-        else {
-            if (infoRec->TEGlyphRendererFlags & BIT_ORDER_IN_BYTE_MSBFIRST) {
-                if (infoRec->TEGlyphRendererFlags & CPU_TRANSFER_BASE_FIXED)
-                    infoRec->TEGlyphRenderer =
-                        XAATEGlyphRendererMSBFirstFixedBase;
-                else
-                    infoRec->TEGlyphRenderer = XAATEGlyphRendererMSBFirst;
-            }
-            else {
-                if (infoRec->TEGlyphRendererFlags & CPU_TRANSFER_BASE_FIXED)
-                    infoRec->TEGlyphRenderer =
-                        XAATEGlyphRendererLSBFirstFixedBase;
-                else
-                    infoRec->TEGlyphRenderer = XAATEGlyphRendererLSBFirst;
-            }
-        }
-
-        if (!HaveSolidFillRect &&
-            (infoRec->TEGlyphRendererFlags & TRANSPARENCY_ONLY)) {
-            infoRec->TEGlyphRendererFlags &= ~TRANSPARENCY_ONLY;
-            XAAMSG("WARNING:  TEGlyphRenderer cannot support TRANPARENCY_ONLY"
-                   " without solid fills\n");
-        }
-
-    }
-    else if (HaveScanlineColorExpansion) {
-        infoRec->TEGlyphRendererFlags =
-            infoRec->ScanlineCPUToScreenColorExpandFillFlags;
-
-        if (infoRec->TEGlyphRendererFlags & TRIPLE_BITS_24BPP) {
-            if (infoRec->TEGlyphRendererFlags & BIT_ORDER_IN_BYTE_MSBFIRST)
-                infoRec->TEGlyphRenderer = XAATEGlyphRendererScanline3MSBFirst;
-            else
-                infoRec->TEGlyphRenderer = XAATEGlyphRendererScanline3LSBFirst;
-
-            if (!HaveSolidFillRect &&
-                (infoRec->TEGlyphRendererFlags & RGB_EQUAL)) {
-                infoRec->TEGlyphRendererFlags &= ~RGB_EQUAL;
-                XAAMSG("WARNING:  TEGlyphRenderer cannot support RGB_EQUAL"
-                       " without solid fills\n");
-            }
-        }
-        else {
-            if (infoRec->TEGlyphRendererFlags & BIT_ORDER_IN_BYTE_MSBFIRST)
-                infoRec->TEGlyphRenderer = XAATEGlyphRendererScanlineMSBFirst;
-            else
-                infoRec->TEGlyphRenderer = XAATEGlyphRendererScanlineLSBFirst;
-        }
-
-        if (!HaveSolidFillRect &&
-            (infoRec->TEGlyphRendererFlags & TRANSPARENCY_ONLY)) {
-            infoRec->TEGlyphRendererFlags &= ~TRANSPARENCY_ONLY;
-            XAAMSG("WARNING:  TEGlyphRenderer cannot support TRANPARENCY_ONLY"
-                   " without solid fills\n");
-        }
-    }
-
-    /**** NonTE Glyphs ****/
-
-    if (infoRec->NonTEGlyphRenderer) {
-        XAAMSG("\tDriver provided NonTEGlyphRenderer replacement\n");
-    }
-    else if (infoRec->WriteBitmap &&
-             !(infoRec->WriteBitmapFlags & NO_TRANSPARENCY)) {
-        infoRec->NonTEGlyphRenderer = XAANonTEGlyphRenderer;
-        infoRec->NonTEGlyphRendererFlags = infoRec->WriteBitmapFlags;
-    }
-
-    /**** WritePixmap ****/
-
-    if (infoRec->WritePixmap &&
-        !xf86ReturnOptValBool(options, XAAOPT_WRITE_PIXMAP, FALSE)) {
-        XAAMSG("\tDriver provided WritePixmap replacement\n");
-    }
-    else if (HaveImageWriteRect) {
-        infoRec->WritePixmap = XAAWritePixmap;
-        infoRec->WritePixmapFlags =
-            infoRec->ImageWriteFlags | CONVERT_32BPP_TO_24BPP;
-    }
-    else if (HaveScanlineImageWriteRect) {
-        infoRec->WritePixmap = XAAWritePixmapScanline;
-        infoRec->WritePixmapFlags = infoRec->ScanlineImageWriteFlags;
-    }
-    else
-        infoRec->WritePixmap = NULL;
-
-    /**** ReadPixmap ****/
-
-    if (infoRec->ReadPixmap) {
-        XAAMSG("\tDriver provided ReadPixmap replacement\n");
-    }
-
-    /************** GC Level *************/
-
-    /**** CopyArea ****/
-
-    if (infoRec->CopyArea) {
-        XAAMSG("\tDriver provided GC level CopyArea replacement\n");
-    }
-    else if (infoRec->ScreenToScreenBitBlt) {
-        infoRec->CopyArea = XAACopyArea;
-        infoRec->CopyAreaFlags = infoRec->ScreenToScreenBitBltFlags;
-
-        /* most GC level primitives use one mid-level primitive so
-           the GC level primitive gets the mid-level primitive flag
-           and we use that at GC validation time.  But CopyArea uses
-           more than one mid-level primitive so we have to essentially
-           do a GC validation every time that primitive is used.
-           The CopyAreaFlags would only be used for filtering out the
-           common denominators.  Here we assume that if you don't do
-           ScreenToScreenBitBlt you aren't going to do the others.
-           We also assume that ScreenToScreenBitBlt has the least
-           restrictions. */
-    }
-
-    if (infoRec->CopyPlane) {
-        XAAMSG("\tDriver provided GC level CopyPlane replacement\n");
-    }
-    else if (infoRec->WriteBitmap &&
-             !(infoRec->WriteBitmapFlags & TRANSPARENCY_ONLY)) {
-        infoRec->CopyPlane = XAACopyPlaneColorExpansion;
-        infoRec->CopyPlaneFlags = infoRec->WriteBitmapFlags;
-    }
-
-    if (infoRec->PushPixelsSolid) {
-        XAAMSG("\tDriver provided GC level PushPixelsSolid replacement\n");
-    }
-    else if (infoRec->WriteBitmap &&
-             !(infoRec->WriteBitmapFlags & NO_TRANSPARENCY)) {
-        infoRec->PushPixelsSolid = XAAPushPixelsSolidColorExpansion;
-        infoRec->PushPixelsFlags = infoRec->WriteBitmapFlags;
-    }
-
-    if (infoRec->FillSolidRects) {
-        if (!infoRec->PolyFillRectSolid) {
-            infoRec->PolyFillRectSolid = XAAPolyFillRect;
-            infoRec->PolyFillRectSolidFlags = infoRec->FillSolidRectsFlags;
-        }
-    }
-    if (infoRec->FillSolidSpans) {
-        if (!infoRec->FillSpansSolid) {
-            infoRec->FillSpansSolid = XAAFillSpans;
-            infoRec->FillSpansSolidFlags = infoRec->FillSolidSpansFlags;
-        }
-    }
-
-    if (infoRec->FillMono8x8PatternRects || infoRec->FillColor8x8PatternRects ||
-        infoRec->FillCacheBltRects || infoRec->FillColorExpandRects ||
-        infoRec->FillCacheExpandRects) {
-        if (!infoRec->PolyFillRectStippled) {
-
-            infoRec->PolyFillRectStippled = XAAPolyFillRect;
-            infoRec->PolyFillRectStippledFlags = 0;
-        }
-    }
-
-    if (infoRec->FillMono8x8PatternSpans || infoRec->FillColor8x8PatternSpans ||
-        infoRec->FillCacheBltSpans || infoRec->FillColorExpandSpans ||
-        infoRec->FillCacheExpandSpans) {
-        if (!infoRec->FillSpansStippled) {
-
-            infoRec->FillSpansStippled = XAAFillSpans;
-            infoRec->FillSpansStippledFlags = 0;
-        }
-    }
-
-    if (infoRec->FillMono8x8PatternRects || infoRec->FillColor8x8PatternRects ||
-        infoRec->FillCacheBltRects || infoRec->FillColorExpandRects ||
-        infoRec->FillCacheExpandRects) {
-        if (!infoRec->PolyFillRectOpaqueStippled) {
-
-            infoRec->PolyFillRectOpaqueStippled = XAAPolyFillRect;
-            infoRec->PolyFillRectOpaqueStippledFlags = 0;
-        }
-    }
-
-    if (infoRec->FillMono8x8PatternSpans || infoRec->FillColor8x8PatternSpans ||
-        infoRec->FillCacheBltSpans || infoRec->FillColorExpandSpans ||
-        infoRec->FillCacheExpandSpans) {
-        if (!infoRec->FillSpansOpaqueStippled) {
-
-            infoRec->FillSpansOpaqueStippled = XAAFillSpans;
-            infoRec->FillSpansOpaqueStippledFlags = 0;
-        }
-    }
-
-    if (infoRec->FillMono8x8PatternRects || infoRec->FillColor8x8PatternRects ||
-        infoRec->FillCacheBltRects || infoRec->FillImageWriteRects) {
-        if (!infoRec->PolyFillRectTiled) {
-
-            infoRec->PolyFillRectTiled = XAAPolyFillRect;
-            infoRec->PolyFillRectTiledFlags = 0;
-        }
-    }
-
-    if (infoRec->FillMono8x8PatternSpans || infoRec->FillColor8x8PatternSpans ||
-        infoRec->FillCacheBltSpans) {
-        if (!infoRec->FillSpansTiled) {
-
-            infoRec->FillSpansTiled = XAAFillSpans;
-            infoRec->FillSpansTiledFlags = 0;
-        }
-    }
-
-    if (infoRec->TEGlyphRenderer &&
-        !(infoRec->TEGlyphRendererFlags & NO_TRANSPARENCY)) {
-
-        if (!infoRec->PolyText8TE) {
-            infoRec->PolyText8TE = XAAPolyText8TEColorExpansion;
-            infoRec->PolyText8TEFlags = infoRec->TEGlyphRendererFlags;
-        }
-
-        if (!infoRec->PolyText16TE) {
-            infoRec->PolyText16TE = XAAPolyText16TEColorExpansion;
-            infoRec->PolyText16TEFlags = infoRec->TEGlyphRendererFlags;
-        }
-
-        if (!infoRec->PolyGlyphBltTE) {
-            infoRec->PolyGlyphBltTE = XAAPolyGlyphBltTEColorExpansion;
-            infoRec->PolyGlyphBltTEFlags = infoRec->TEGlyphRendererFlags;
-        }
-    }
-
-    if (infoRec->TEGlyphRenderer &&
-        !(infoRec->TEGlyphRendererFlags & TRANSPARENCY_ONLY)) {
-
-        if (!infoRec->ImageText8TE) {
-            infoRec->ImageText8TE = XAAImageText8TEColorExpansion;
-            infoRec->ImageText8TEFlags = infoRec->TEGlyphRendererFlags;
-        }
-
-        if (!infoRec->ImageText16TE) {
-            infoRec->ImageText16TE = XAAImageText16TEColorExpansion;
-            infoRec->ImageText16TEFlags = infoRec->TEGlyphRendererFlags;
-        }
-
-        if (!infoRec->ImageGlyphBltTE) {
-            infoRec->ImageGlyphBltTE = XAAImageGlyphBltTEColorExpansion;
-            infoRec->ImageGlyphBltTEFlags = infoRec->TEGlyphRendererFlags;
-        }
-    }
-
-    if (infoRec->NonTEGlyphRenderer) {
-        if (!infoRec->PolyText8NonTE) {
-            infoRec->PolyText8NonTE = XAAPolyText8NonTEColorExpansion;
-            infoRec->PolyText8NonTEFlags = infoRec->NonTEGlyphRendererFlags;
-        }
-
-        if (!infoRec->PolyText16NonTE) {
-            infoRec->PolyText16NonTE = XAAPolyText16NonTEColorExpansion;
-            infoRec->PolyText16NonTEFlags = infoRec->NonTEGlyphRendererFlags;
-        }
-        if (!infoRec->PolyGlyphBltNonTE) {
-            infoRec->PolyGlyphBltNonTE = XAAPolyGlyphBltNonTEColorExpansion;
-            infoRec->PolyGlyphBltNonTEFlags = infoRec->NonTEGlyphRendererFlags;
-        }
-    }
-
-    if (infoRec->NonTEGlyphRenderer && HaveSolidFillRect) {
-        if (!infoRec->ImageText8NonTE) {
-            infoRec->ImageText8NonTE = XAAImageText8NonTEColorExpansion;
-            infoRec->ImageText8NonTEFlags = infoRec->NonTEGlyphRendererFlags;
-        }
-
-        if (!infoRec->ImageText16NonTE) {
-            infoRec->ImageText16NonTE = XAAImageText16NonTEColorExpansion;
-            infoRec->ImageText16NonTEFlags = infoRec->NonTEGlyphRendererFlags;
-        }
-
-        if (!infoRec->ImageGlyphBltNonTE) {
-            infoRec->ImageGlyphBltNonTE = XAAImageGlyphBltNonTEColorExpansion;
-            infoRec->ImageGlyphBltNonTEFlags = infoRec->NonTEGlyphRendererFlags;
-        }
-    }
-
-    if (!infoRec->PolyRectangleThinSolid && HaveSolidHorVertLine) {
-        infoRec->PolyRectangleThinSolid = XAAPolyRectangleThinSolid;
-        infoRec->PolyRectangleThinSolidFlags = infoRec->SolidLineFlags;
-    }
-
-    if (!infoRec->FillPolygonSolid && HaveSolidFillRect) {
-        infoRec->FillPolygonSolid = XAAFillPolygonSolid;
-        infoRec->FillPolygonSolidFlags = infoRec->SolidFillFlags;
-    }
-
-    if (!infoRec->FillPolygonStippled && (HaveMono8x8PatternFillRect ||
-                                          HaveScreenToScreenColorExpandFill ||
-                                          HaveScreenToScreenCopy)) {
-        infoRec->FillPolygonStippled = XAAFillPolygonStippled;
-        infoRec->FillPolygonStippledFlags = infoRec->SolidFillFlags;
-    }
-
-    if (!infoRec->FillPolygonOpaqueStippled && (HaveMono8x8PatternFillRect ||
-                                                HaveScreenToScreenColorExpandFill
-                                                || HaveScreenToScreenCopy)) {
-        infoRec->FillPolygonOpaqueStippled = XAAFillPolygonStippled;
-        infoRec->FillPolygonOpaqueStippledFlags = infoRec->SolidFillFlags;
-    }
-
-    if (!infoRec->FillPolygonTiled && (HaveMono8x8PatternFillRect ||
-                                       HaveScreenToScreenColorExpandFill ||
-                                       HaveScreenToScreenCopy)) {
-        infoRec->FillPolygonTiled = XAAFillPolygonTiled;
-        infoRec->FillPolygonTiledFlags = infoRec->SolidFillFlags;
-    }
-
-    if (!infoRec->PolyFillArcSolid && HaveSolidFillRect) {
-        infoRec->PolyFillArcSolid = XAAPolyFillArcSolid;
-        infoRec->PolyFillArcSolidFlags = infoRec->SolidFillFlags;
-    }
-
-    if (!infoRec->PolylinesWideSolid && HaveSolidFillRect) {
-        infoRec->PolylinesWideSolid = XAAPolylinesWideSolid;
-        infoRec->PolylinesWideSolidFlags =
-            infoRec->SolidFillFlags | GXCOPY_ONLY;
-    }
-
-    if (!infoRec->PutImage && (infoRec->WritePixmap ||
-                               (infoRec->WriteBitmap &&
-                                !(infoRec->
-                                  WriteBitmapFlags & TRANSPARENCY_ONLY)))) {
-        infoRec->PutImage = XAAPutImage;
-
-        /* See comment for CopyArea above.  But here we make fewer 
-           assumptions.  The driver can provide the PutImageFlags if
-           it wants too */
-    }
-
-    if (HaveSolidHorVertLine &&
-        (HaveSolidBresenhamLine || (HaveSolidTwoPointLine &&
-                                    (infoRec->
-                                     ClippingFlags &
-                                     HARDWARE_CLIP_SOLID_LINE)))) {
-        if (!infoRec->PolylinesThinSolid) {
-            infoRec->PolylinesThinSolid = XAAPolyLines;
-            infoRec->PolylinesThinSolidFlags = infoRec->SolidLineFlags;
-        }
-        if (!infoRec->PolySegmentThinSolid) {
-            infoRec->PolySegmentThinSolid = XAAPolySegment;
-            infoRec->PolySegmentThinSolidFlags = infoRec->SolidLineFlags;
-        }
-    }
-
-    if (HaveDashedBresenhamLine || (HaveDashedTwoPointLine &&
-                                    (infoRec->
-                                     ClippingFlags &
-                                     HARDWARE_CLIP_DASHED_LINE))) {
-        if (!infoRec->PolylinesThinDashed) {
-            infoRec->PolylinesThinDashed = XAAPolyLinesDashed;
-            infoRec->PolylinesThinDashedFlags = infoRec->DashedLineFlags;
-        }
-        if (!infoRec->PolySegmentThinDashed) {
-            infoRec->PolySegmentThinDashed = XAAPolySegmentDashed;
-            infoRec->PolySegmentThinDashedFlags = infoRec->DashedLineFlags;
-        }
-    }
-
-    if (infoRec->PolylinesThinDashed || infoRec->PolySegmentThinDashed) {
-        if (!infoRec->ComputeDash)
-            infoRec->ComputeDash = XAAComputeDash;
-    }
-
-    {
-        Bool haveTexture = infoRec->CPUToScreenTextureFormats &&
-            infoRec->CPUToScreenTextureDstFormats &&
-            infoRec->SetupForCPUToScreenTexture2 &&
-            infoRec->SubsequentCPUToScreenTexture;
-        Bool haveAlphaTexture = infoRec->CPUToScreenAlphaTextureFormats &&
-            infoRec->CPUToScreenAlphaTextureDstFormats &&
-            infoRec->SetupForCPUToScreenAlphaTexture2 &&
-            infoRec->SubsequentCPUToScreenAlphaTexture;
-
-        if (!infoRec->Composite && (haveTexture || haveAlphaTexture))
-            infoRec->Composite = XAADoComposite;
-
-        if (!infoRec->Glyphs && infoRec->WriteBitmap &&
-            !(infoRec->WriteBitmapFlags & NO_TRANSPARENCY)) {
-            infoRec->Glyphs = XAADoGlyphs;
-        }
-    }
-
-    /************  Validation Functions **************/
-
-    if (!infoRec->ValidateCopyArea && infoRec->CopyArea) {
-        infoRec->CopyAreaMask = GCWhenForced;
-        if ((infoRec->CopyAreaFlags & GXCOPY_ONLY) ||
-            (infoRec->CopyAreaFlags & ROP_NEEDS_SOURCE))
-            infoRec->CopyAreaMask |= GCFunction;
-        if (infoRec->CopyAreaFlags & NO_PLANEMASK)
-            infoRec->CopyAreaMask |= GCPlaneMask;
-        infoRec->ValidateCopyArea = XAAValidateCopyArea;
-    }
-
-    if (!infoRec->ValidateCopyPlane && infoRec->CopyPlane) {
-        infoRec->CopyPlaneMask = GCWhenForced;
-        if ((infoRec->CopyPlaneFlags & GXCOPY_ONLY) ||
-            (infoRec->CopyPlaneFlags & ROP_NEEDS_SOURCE))
-            infoRec->CopyPlaneMask |= GCFunction;
-        if (infoRec->CopyPlaneFlags & NO_PLANEMASK)
-            infoRec->CopyPlaneMask |= GCPlaneMask;
-        if (infoRec->CopyPlaneFlags & RGB_EQUAL)
-            infoRec->CopyPlaneMask |= GCForeground | GCBackground;
-        infoRec->ValidateCopyPlane = XAAValidateCopyPlane;
-    }
-
-    if (!infoRec->ValidatePutImage && infoRec->PutImage) {
-        infoRec->PutImageMask = GCWhenForced;
-        if ((infoRec->PutImageFlags & GXCOPY_ONLY) ||
-            (infoRec->PutImageFlags & ROP_NEEDS_SOURCE))
-            infoRec->PutImageMask |= GCFunction;
-        if (infoRec->PutImageFlags & NO_PLANEMASK)
-            infoRec->PutImageMask |= GCPlaneMask;
-        if (infoRec->PutImageFlags & RGB_EQUAL)
-            infoRec->PutImageMask |= GCForeground | GCBackground;
-        infoRec->ValidatePutImage = XAAValidatePutImage;
-    }
-
-    if (!infoRec->ValidatePushPixels && infoRec->PushPixelsSolid) {
-        infoRec->PushPixelsMask = GCFillStyle;
-        if ((infoRec->PushPixelsFlags & GXCOPY_ONLY) ||
-            (infoRec->PushPixelsFlags & ROP_NEEDS_SOURCE) ||
-            (infoRec->PushPixelsFlags & TRANSPARENCY_GXCOPY_ONLY))
-            infoRec->PushPixelsMask |= GCFunction;
-        if (infoRec->PushPixelsFlags & NO_PLANEMASK)
-            infoRec->PushPixelsMask |= GCPlaneMask;
-        if (infoRec->PushPixelsFlags & RGB_EQUAL)
-            infoRec->PushPixelsMask |= GCForeground;
-        infoRec->ValidatePushPixels = XAAValidatePushPixels;
-    }
-
-    /* By default XAA assumes the FillSpans, PolyFillRects, FillPolygon
-       and PolyFillArcs have the same restrictions.  If you supply GC 
-       level replacements for any of these and alter this relationship 
-       you may need to supply replacement validation routines */
-
-    if (!infoRec->ValidateFillSpans &&
-        (infoRec->FillSpansSolid || infoRec->FillSpansStippled ||
-         infoRec->FillSpansOpaqueStippled || infoRec->FillSpansTiled)) {
-
-        int compositeFlags = infoRec->FillSpansSolidFlags |
-            infoRec->FillSpansStippledFlags |
-            infoRec->FillSpansOpaqueStippledFlags |
-            infoRec->FillSpansTiledFlags;
-
-        infoRec->FillSpansMask = GCFillStyle | GCTile | GCStipple;
-
-        if ((compositeFlags & GXCOPY_ONLY) ||
-            (compositeFlags & ROP_NEEDS_SOURCE))
-            infoRec->FillSpansMask |= GCFunction;
-        if (compositeFlags & NO_PLANEMASK)
-            infoRec->FillSpansMask |= GCPlaneMask;
-        if (compositeFlags & RGB_EQUAL)
-            infoRec->FillSpansMask |= GCForeground;
-        infoRec->ValidateFillSpans = XAAValidateFillSpans;
-    }
-
-    /* By default XAA only provides Validations for the GlyphBlt
-       functions and not the text higher up. This is because the
-       Text8/16 and GlyphBlt are linked.  If you break this linkage,
-       you may need to have the driver supply its own Validation
-       routines */
-
-    if (!infoRec->ValidatePolyGlyphBlt &&
-        (infoRec->PolyGlyphBltTE || infoRec->PolyGlyphBltNonTE)) {
-        int compositeFlags = infoRec->PolyGlyphBltTEFlags |
-            infoRec->PolyGlyphBltNonTEFlags;
-
-        infoRec->PolyGlyphBltMask = GCFillStyle | GCFont;
-        if ((compositeFlags & GXCOPY_ONLY) ||
-            (compositeFlags & ROP_NEEDS_SOURCE) ||
-            (infoRec->PolyGlyphBltNonTEFlags & TRANSPARENCY_GXCOPY_ONLY))
-            infoRec->PolyGlyphBltMask |= GCFunction;
-        if (compositeFlags & NO_PLANEMASK)
-            infoRec->PolyGlyphBltMask |= GCPlaneMask;
-        if (compositeFlags & RGB_EQUAL)
-            infoRec->PolyGlyphBltMask |= GCForeground;
-        infoRec->ValidatePolyGlyphBlt = XAAValidatePolyGlyphBlt;
-    }
-
-    if (!infoRec->ValidateImageGlyphBlt &&
-        (infoRec->ImageGlyphBltTE || infoRec->ImageGlyphBltNonTE)) {
-        int compositeFlags = infoRec->ImageGlyphBltTEFlags |
-            infoRec->ImageGlyphBltNonTEFlags;
-
-        if (infoRec->ImageGlyphBltNonTE)
-            compositeFlags |= infoRec->SolidFillFlags;
-
-        infoRec->ImageGlyphBltMask = GCFont;
-        if (compositeFlags & NO_PLANEMASK)
-            infoRec->ImageGlyphBltMask |= GCPlaneMask;
-        if (compositeFlags & RGB_EQUAL)
-            infoRec->ImageGlyphBltMask |= GCForeground | GCBackground;
-        infoRec->ValidateImageGlyphBlt = XAAValidateImageGlyphBlt;
-    }
-
-    /* By default XAA only provides a Validation function for the 
-       Polylines and does segments and polylines at the same time */
-
-    if (!infoRec->ValidatePolylines && infoRec->ValidateFillSpans) {
-        int compositeFlags = infoRec->PolyRectangleThinSolidFlags |
-            infoRec->PolylinesWideSolidFlags |
-            infoRec->PolylinesThinSolidFlags |
-            infoRec->PolySegmentThinSolidFlags |
-            infoRec->PolySegmentThinDashedFlags |
-            infoRec->PolylinesThinDashedFlags;
-
-        infoRec->ValidatePolylines = XAAValidatePolylines;
-        infoRec->PolylinesMask =
-            infoRec->FillSpansMask | GCLineStyle | GCLineWidth;
-
-        if (infoRec->PolySegmentThinDashed || infoRec->PolylinesThinDashed)
-            infoRec->PolylinesMask |= GCDashList;
-        if (compositeFlags & NO_PLANEMASK)
-            infoRec->PolylinesMask |= GCPlaneMask;
-        if ((compositeFlags & GXCOPY_ONLY) ||
-            (compositeFlags & ROP_NEEDS_SOURCE))
-            infoRec->PolylinesMask |= GCFunction;
-        if (compositeFlags & RGB_EQUAL)
-            infoRec->PolylinesMask |= GCForeground;
-    }
-
-    /**** Fill choosers ****/
-
-    if (!infoRec->StippledFillChooser)
-        infoRec->StippledFillChooser = XAAStippledFillChooser;
-
-    if (!infoRec->OpaqueStippledFillChooser)
-        infoRec->OpaqueStippledFillChooser = XAAOpaqueStippledFillChooser;
-
-    if (!infoRec->TiledFillChooser)
-        infoRec->TiledFillChooser = XAATiledFillChooser;
-
-    /**** Setup the pixmap cache ****/
-
-    if (infoRec->WriteBitmapToCache) {
-    }
-    else if (infoRec->WriteBitmap &&
-             !(infoRec->WriteBitmapFlags & TRANSPARENCY_ONLY))
-        infoRec->WriteBitmapToCache = XAAWriteBitmapToCache;
-    else if (infoRec->Flags & LINEAR_FRAMEBUFFER)
-        infoRec->WriteBitmapToCache = XAAWriteBitmapToCacheLinear;
-    else
-        infoRec->PixmapCacheFlags |= DO_NOT_BLIT_STIPPLES;
-
-    if (infoRec->WritePixmapToCache) {
-    }
-    else if (infoRec->WritePixmap && !(infoRec->WritePixmapFlags & NO_GXCOPY))
-        infoRec->WritePixmapToCache = XAAWritePixmapToCache;
-    else if (infoRec->Flags & LINEAR_FRAMEBUFFER)
-        infoRec->WritePixmapToCache = XAAWritePixmapToCacheLinear;
-    else
-        infoRec->Flags &= ~PIXMAP_CACHE;
-
-    if (xf86ReturnOptValBool(options, XAAOPT_PIXMAP_CACHE, FALSE))
-        infoRec->Flags &= ~PIXMAP_CACHE;
-
-    if (infoRec->WriteMono8x8PatternToCache) {
-    }
-    else if (infoRec->PixmapCacheFlags & CACHE_MONO_8x8) {
-        if (infoRec->WritePixmapToCache)
-            infoRec->WriteMono8x8PatternToCache = XAAWriteMono8x8PatternToCache;
-        else
-            infoRec->PixmapCacheFlags &= ~CACHE_MONO_8x8;
-    }
-
-    if (infoRec->WriteColor8x8PatternToCache) {
-    }
-    else if (infoRec->PixmapCacheFlags & CACHE_COLOR_8x8) {
-        if (infoRec->WritePixmapToCache && infoRec->WriteBitmapToCache)
-            infoRec->WriteColor8x8PatternToCache =
-                XAAWriteColor8x8PatternToCache;
-        else
-            infoRec->PixmapCacheFlags &= ~CACHE_COLOR_8x8;
-    }
-
-    if (infoRec->CachePixelGranularity < 0) {
-        switch (pScrn->bitsPerPixel) {
-        case 24:
-        case 8:
-            infoRec->CachePixelGranularity = 4;
-            break;
-        case 16:
-            infoRec->CachePixelGranularity = 2;
-            break;
-        case 32:
-            infoRec->CachePixelGranularity = 1;
-            break;
-        default:
-            break;
-        }
-
-        if (BITMAP_SCANLINE_PAD == 64)
-            infoRec->CachePixelGranularity *= 2;
-    }
-
-    free(options);
-
-    if (!infoRec->CacheTile && infoRec->WritePixmapToCache)
-        infoRec->CacheTile = XAACacheTile;
-    if (!infoRec->CacheMonoStipple && infoRec->WritePixmapToCache)
-        infoRec->CacheMonoStipple = XAACacheMonoStipple;
-    if (!infoRec->CacheStipple && infoRec->WriteBitmapToCache)
-        infoRec->CacheStipple = XAACacheStipple;
-    if (!infoRec->CacheMono8x8Pattern && infoRec->WriteMono8x8PatternToCache)
-        infoRec->CacheMono8x8Pattern = XAACacheMono8x8Pattern;
-    if (!infoRec->CacheColor8x8Pattern && infoRec->WriteColor8x8PatternToCache)
-        infoRec->CacheColor8x8Pattern = XAACacheColor8x8Pattern;
-
-    if ((infoRec->Flags & PIXMAP_CACHE) && !infoRec->InitPixmapCache) {
-        infoRec->InitPixmapCache = XAAInitPixmapCache;
-        infoRec->ClosePixmapCache = XAAClosePixmapCache;
-    }
-
-    return TRUE;
-}
diff --git a/hw/xfree86/xaa/xaaLine.c b/hw/xfree86/xaa/xaaLine.c
deleted file mode 100644
index d7c6097..0000000
--- a/hw/xfree86/xaa/xaaLine.c
+++ /dev/null
@@ -1,422 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <stdlib.h>
-
-#include <X11/X.h>
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "miline.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-
-void
-#ifdef POLYSEGMENT
- XAAPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg
-#else
-XAAPolyLines(DrawablePtr pDrawable, GCPtr pGC, int mode,        /* Origin or Previous */
-             int npt,           /* number of points */
-             DDXPointPtr pptInit
-#endif
-    )
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    BoxPtr pboxInit = RegionRects(pGC->pCompositeClip);
-    int nboxInit = RegionNumRects(pGC->pCompositeClip);
-    unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
-    int xorg = pDrawable->x;
-    int yorg = pDrawable->y;
-    int nbox;
-    BoxPtr pbox;
-
-#ifndef POLYSEGMENT
-    DDXPointPtr ppt;
-#endif
-    int x1, x2, y1, y2, tmp, len;
-
-    if (!nboxInit)
-        return;
-
-    if (infoRec->SolidLineFlags & LINE_LIMIT_COORDS) {
-        int minValX = infoRec->SolidLineLimits.x1;
-        int maxValX = infoRec->SolidLineLimits.x2;
-        int minValY = infoRec->SolidLineLimits.y1;
-        int maxValY = infoRec->SolidLineLimits.y2;
-
-#ifdef POLYSEGMENT
-        int n = nseg;
-        xSegment *s = pSeg;
-
-        while (n--)
-#else
-        int n = npt;
-        int xorgtmp = xorg;
-        int yorgtmp = yorg;
-
-        ppt = pptInit;
-        x2 = ppt->x + xorgtmp;
-        y2 = ppt->y + yorgtmp;
-        while (--n)
-#endif
-        {
-#ifdef POLYSEGMENT
-            x1 = s->x1 + xorg;
-            y1 = s->y1 + yorg;
-            x2 = s->x2 + xorg;
-            y2 = s->y2 + yorg;
-            s++;
-#else
-            x1 = x2;
-            y1 = y2;
-            ++ppt;
-            if (mode == CoordModePrevious) {
-                xorgtmp = x1;
-                yorgtmp = y1;
-            }
-            x2 = ppt->x + xorgtmp;
-            y2 = ppt->y + yorgtmp;
-#endif
-            if (x1 > maxValX || x1 < minValX ||
-                x2 > maxValX || x2 < minValX ||
-                y1 > maxValY || y1 < minValY || y2 > maxValY || y2 < minValY) {
-#ifdef POLYSEGMENT
-                XAAFallbackOps.PolySegment(pDrawable, pGC, nseg, pSeg);
-#else
-                XAAFallbackOps.Polylines(pDrawable, pGC, mode, npt, pptInit);
-#endif
-                return;
-            }
-        }
-    }
-
-    (*infoRec->SetupForSolidLine) (infoRec->pScrn, pGC->fgPixel,
-                                   pGC->alu, pGC->planemask);
-
-#ifdef POLYSEGMENT
-    while (nseg--)
-#else
-    ppt = pptInit;
-    x2 = ppt->x + xorg;
-    y2 = ppt->y + yorg;
-    while (--npt)
-#endif
-    {
-        nbox = nboxInit;
-        pbox = pboxInit;
-
-#ifdef POLYSEGMENT
-        x1 = pSeg->x1 + xorg;
-        y1 = pSeg->y1 + yorg;
-        x2 = pSeg->x2 + xorg;
-        y2 = pSeg->y2 + yorg;
-        pSeg++;
-#else
-        x1 = x2;
-        y1 = y2;
-        ++ppt;
-        if (mode == CoordModePrevious) {
-            xorg = x1;
-            yorg = y1;
-        }
-        x2 = ppt->x + xorg;
-        y2 = ppt->y + yorg;
-#endif
-
-        if (x1 == x2) {         /* vertical line */
-            /* make the line go top to bottom of screen, keeping
-               endpoint semantics
-             */
-            if (y1 > y2) {
-                tmp = y2;
-                y2 = y1 + 1;
-                y1 = tmp + 1;
-#ifdef POLYSEGMENT
-                if (pGC->capStyle != CapNotLast)
-                    y1--;
-#endif
-            }
-#ifdef POLYSEGMENT
-            else if (pGC->capStyle != CapNotLast)
-                y2++;
-#endif
-            /* get to first band that might contain part of line */
-            while (nbox && (pbox->y2 <= y1)) {
-                pbox++;
-                nbox--;
-            }
-
-            /* stop when lower edge of box is beyond end of line */
-            while (nbox && (y2 >= pbox->y1)) {
-                if ((x1 >= pbox->x1) && (x1 < pbox->x2)) {
-                    tmp = max(y1, pbox->y1);
-                    len = min(y2, pbox->y2) - tmp;
-                    if (len)
-                        (*infoRec->SubsequentSolidHorVertLine) (infoRec->pScrn,
-                                                                x1, tmp, len,
-                                                                DEGREES_270);
-                }
-                nbox--;
-                pbox++;
-            }
-#ifndef POLYSEGMENT
-            y2 = ppt->y + yorg;
-#endif
-        }
-        else if (y1 == y2) {    /* horizontal line */
-            /* force line from left to right, keeping endpoint semantics */
-            if (x1 > x2) {
-                tmp = x2;
-                x2 = x1 + 1;
-                x1 = tmp + 1;
-#ifdef POLYSEGMENT
-                if (pGC->capStyle != CapNotLast)
-                    x1--;
-#endif
-            }
-#ifdef POLYSEGMENT
-            else if (pGC->capStyle != CapNotLast)
-                x2++;
-#endif
-
-            /* find the correct band */
-            while (nbox && (pbox->y2 <= y1)) {
-                pbox++;
-                nbox--;
-            }
-
-            /* try to draw the line, if we haven't gone beyond it */
-            if (nbox && (pbox->y1 <= y1)) {
-                int orig_y = pbox->y1;
-
-                /* when we leave this band, we're done */
-                while (nbox && (orig_y == pbox->y1)) {
-                    if (pbox->x2 <= x1) {
-                        /* skip boxes until one might contain start point */
-                        nbox--;
-                        pbox++;
-                        continue;
-                    }
-
-                    /* stop if left of box is beyond right of line */
-                    if (pbox->x1 >= x2) {
-                        nbox = 0;
-                        break;
-                    }
-
-                    tmp = max(x1, pbox->x1);
-                    len = min(x2, pbox->x2) - tmp;
-                    if (len)
-                        (*infoRec->SubsequentSolidHorVertLine) (infoRec->pScrn,
-                                                                tmp, y1, len,
-                                                                DEGREES_0);
-                    nbox--;
-                    pbox++;
-                }
-            }
-#ifndef POLYSEGMENT
-            x2 = ppt->x + xorg;
-#endif
-        }
-        else {                  /* sloped line */
-            unsigned int oc1, oc2;
-            int dmin, dmaj, e, octant;
-
-            if (infoRec->SubsequentSolidBresenhamLine) {
-                if ((dmaj = x2 - x1) < 0) {
-                    dmaj = -dmaj;
-                    octant = XDECREASING;
-                }
-                else
-                    octant = 0;
-
-                if ((dmin = y2 - y1) < 0) {
-                    dmin = -dmin;
-                    octant |= YDECREASING;
-                }
-
-                if (dmin >= dmaj) {
-                    tmp = dmin;
-                    dmin = dmaj;
-                    dmaj = tmp;
-                    octant |= YMAJOR;
-                }
-
-                e = -dmaj - ((bias >> octant) & 1);
-                len = dmaj;
-                dmin <<= 1;
-                dmaj <<= 1;
-            }
-            else {              /* Muffle compiler */
-                dmin = dmaj = e = octant = len = 0;
-            }
-
-            while (nbox--) {
-                oc1 = oc2 = 0;
-                OUTCODES(oc1, x1, y1, pbox);
-                OUTCODES(oc2, x2, y2, pbox);
-                if (!(oc1 | oc2)) {     /* unclipped */
-                    if (infoRec->SubsequentSolidTwoPointLine) {
-                        (*infoRec->SubsequentSolidTwoPointLine) (infoRec->pScrn,
-                                                                 x1, y1, x2, y2,
-#ifdef POLYSEGMENT
-                                                                 (pGC->
-                                                                  capStyle !=
-                                                                  CapNotLast) ?
-                                                                 0 :
-#endif
-                                                                 OMIT_LAST);
-                    }
-                    else {
-                        (*infoRec->SubsequentSolidBresenhamLine) (infoRec->
-                                                                  pScrn, x1, y1,
-                                                                  dmaj, dmin, e,
-#ifdef POLYSEGMENT
-                                                                  (pGC->
-                                                                   capStyle !=
-                                                                   CapNotLast)
-                                                                  ? (len + 1) :
-#endif
-                                                                  len, octant);
-                    }
-                    break;
-                }
-                else if (oc1 & oc2) {   /* completely clipped */
-                    pbox++;
-                }
-                else if (infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_LINE) {
-                    (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                                      pbox->x1, pbox->y1,
-                                                      pbox->x2 - 1,
-                                                      pbox->y2 - 1);
-
-                    if (infoRec->SubsequentSolidBresenhamLine) {
-                        (*infoRec->SubsequentSolidBresenhamLine) (infoRec->
-                                                                  pScrn, x1, y1,
-                                                                  dmaj, dmin, e,
-#ifdef POLYSEGMENT
-                                                                  (pGC->
-                                                                   capStyle !=
-                                                                   CapNotLast)
-                                                                  ? (len + 1) :
-#endif
-                                                                  len, octant);
-                    }
-                    else {
-                        (*infoRec->SubsequentSolidTwoPointLine) (infoRec->pScrn,
-                                                                 x1, y1, x2, y2,
-#ifdef POLYSEGMENT
-                                                                 (pGC->
-                                                                  capStyle !=
-                                                                  CapNotLast) ?
-                                                                 0 :
-#endif
-                                                                 OMIT_LAST);
-                    }
-                    (*infoRec->DisableClipping) (infoRec->pScrn);
-                    pbox++;
-                }
-                else {
-                    int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
-                    int clip1 = 0, clip2 = 0;
-                    int err, adx, ady;
-
-                    if (octant & YMAJOR) {
-                        ady = dmaj >> 1;
-                        adx = dmin >> 1;
-                    }
-                    else {
-                        ady = dmin >> 1;
-                        adx = dmaj >> 1;
-                    }
-
-                    if (miZeroClipLine(pbox->x1, pbox->y1,
-                                       pbox->x2 - 1, pbox->y2 - 1,
-                                       &new_x1, &new_y1, &new_x2, &new_y2,
-                                       adx, ady, &clip1, &clip2,
-                                       octant, bias, oc1, oc2) == -1) {
-                        pbox++;
-                        continue;
-                    }
-
-                    if (octant & YMAJOR)
-                        len = abs(new_y2 - new_y1);
-                    else
-                        len = abs(new_x2 - new_x1);
-#ifdef POLYSEGMENT
-                    if (clip2 != 0 || pGC->capStyle != CapNotLast)
-                        len++;
-#else
-                    len += (clip2 != 0);
-#endif
-                    if (len) {
-                        int abserr, clipdx, clipdy;
-
-                        /* unwind bresenham error term to first point */
-                        if (clip1) {
-                            clipdx = abs(new_x1 - x1);
-                            clipdy = abs(new_y1 - y1);
-
-                            if (octant & YMAJOR)
-                                err = e + clipdy * dmin - clipdx * dmaj;
-                            else
-                                err = e + clipdx * dmin - clipdy * dmaj;
-                        }
-                        else
-                            err = e;
-
-#define range infoRec->SolidBresenhamLineErrorTermBits
-                        abserr = abs(err);
-                        while ((abserr & range) ||
-                               (dmaj & range) || (dmin & range)) {
-                            dmin >>= 1;
-                            dmaj >>= 1;
-                            abserr >>= 1;
-                            err /= 2;
-                        }
-
-                        (*infoRec->SubsequentSolidBresenhamLine) (infoRec->
-                                                                  pScrn, new_x1,
-                                                                  new_y1, dmaj,
-                                                                  dmin, err,
-                                                                  len, octant);
-                    }
-                    pbox++;
-                }
-            }                   /* while (nbox--) */
-        }                       /* sloped line */
-    }                           /* while (nline--) */
-
-#ifndef POLYSEGMENT
-    /* paint the last point if the end style isn't CapNotLast.
-       (Assume that a projecting, butt, or round cap that is one
-       pixel wide is the same as the single pixel of the endpoint.)
-     */
-
-    if ((pGC->capStyle != CapNotLast) &&
-        ((ppt->x + xorg != pptInit->x + pDrawable->x) ||
-         (ppt->y + yorg != pptInit->y + pDrawable->y) ||
-         (ppt == pptInit + 1))) {
-        nbox = nboxInit;
-        pbox = pboxInit;
-        while (nbox--) {
-            if ((x2 >= pbox->x1) && (y2 >= pbox->y1) &&
-                (x2 < pbox->x2) && (y2 < pbox->y2)) {
-                (*infoRec->SubsequentSolidHorVertLine) (infoRec->pScrn, x2, y2,
-                                                        1, DEGREES_0);
-                break;
-            }
-            else
-                pbox++;
-        }
-    }
-#endif
-
-    SET_SYNC_FLAG(infoRec);
-}
diff --git a/hw/xfree86/xaa/xaaLineMisc.c b/hw/xfree86/xaa/xaaLineMisc.c
deleted file mode 100644
index 4379778..0000000
--- a/hw/xfree86/xaa/xaaLineMisc.c
+++ /dev/null
@@ -1,149 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "miline.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-
-void
-XAASolidHorVertLineAsRects(ScrnInfoPtr pScrn, int x, int y, int len, int dir)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    if (dir == DEGREES_0)
-        (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, len, 1);
-    else
-        (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, 1, len);
-}
-
-void
-XAASolidHorVertLineAsTwoPoint(ScrnInfoPtr pScrn, int x, int y, int len, int dir)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    len--;
-
-    if (dir == DEGREES_0)
-        (*infoRec->SubsequentSolidTwoPointLine) (pScrn, x, y, x + len, y, 0);
-    else
-        (*infoRec->SubsequentSolidTwoPointLine) (pScrn, x, y, x, y + len, 0);
-}
-
-void
-XAASolidHorVertLineAsBresenham(ScrnInfoPtr pScrn,
-                               int x, int y, int len, int dir)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    if (dir == DEGREES_0)
-        (*infoRec->SubsequentSolidBresenhamLine) (pScrn, x, y, len << 1, 0,
-                                                  -len, len, 0);
-    else
-        (*infoRec->SubsequentSolidBresenhamLine) (pScrn, x, y, len << 1, 0,
-                                                  -len, len, YMAJOR);
-}
-
-void
-XAAComputeDash(GCPtr pGC)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAAGCPtr pGCPriv = (XAAGCPtr) dixLookupPrivate(&pGC->devPrivates,
-                                                   XAAGetGCKey());
-    Bool EvenDash = (pGC->numInDashList & 0x01) ? FALSE : TRUE;
-    int PatternLength = 0;
-    unsigned char *DashPtr = (unsigned char *) pGC->dash;
-    CARD32 *ptr;
-    int count = pGC->numInDashList;
-    int shift, value, direction;
-    Bool set;
-
-    free(pGCPriv->DashPattern);
-
-    pGCPriv->DashPattern = NULL;
-    pGCPriv->DashLength = 0;
-
-    while (count--)
-        PatternLength += *(DashPtr++);
-
-    if (!EvenDash)
-        PatternLength <<= 1;
-
-    if (PatternLength > infoRec->DashPatternMaxLength)
-        return;
-
-    if ((infoRec->DashedLineFlags & LINE_PATTERN_POWER_OF_2_ONLY) &&
-        (PatternLength & (PatternLength - 1)))
-        return;
-
-    pGCPriv->DashPattern = calloc((PatternLength + 31) >> 5, 4);
-    if (!pGCPriv->DashPattern)
-        return;
-    pGCPriv->DashLength = PatternLength;
-
-    if (infoRec->DashedLineFlags & (LINE_PATTERN_LSBFIRST_MSBJUSTIFIED |
-                                    LINE_PATTERN_LSBFIRST_LSBJUSTIFIED)) {
-        direction = 1;
-        set = TRUE;
-        DashPtr = (unsigned char *) pGC->dash;
-    }
-    else {
-        direction = -1;
-        set = FALSE;
-        DashPtr = (unsigned char *) pGC->dash + pGC->numInDashList - 1;
-    }
-
-    if (infoRec->DashedLineFlags & (LINE_PATTERN_LSBFIRST_MSBJUSTIFIED |
-                                    LINE_PATTERN_MSBFIRST_MSBJUSTIFIED))
-        shift = 32 - (PatternLength & 31);
-    else
-        shift = 0;
-
-    ptr = (CARD32 *) (pGCPriv->DashPattern);
-
- CONCATENATE:
-
-    count = pGC->numInDashList;
-
-    while (count--) {
-        value = *DashPtr;
-        DashPtr += direction;
-        while (value) {
-            if (value < (32 - shift)) {
-                if (set)
-                    *ptr |= XAAShiftMasks[value] << shift;
-                shift += value;
-                break;
-            }
-            else {
-                if (set)
-                    *ptr |= ~0L << shift;
-                value -= (32 - shift);
-                shift = 0;
-                ptr++;
-            }
-        }
-        if (set)
-            set = FALSE;
-        else
-            set = TRUE;
-    }
-
-    if (!EvenDash) {
-        EvenDash = TRUE;
-        if (infoRec->DashedLineFlags & (LINE_PATTERN_LSBFIRST_MSBJUSTIFIED |
-                                        LINE_PATTERN_LSBFIRST_LSBJUSTIFIED))
-            DashPtr = (unsigned char *) pGC->dash;
-        else
-            DashPtr = (unsigned char *) pGC->dash + pGC->numInDashList;
-        goto CONCATENATE;
-    }
-}
diff --git a/hw/xfree86/xaa/xaaNonTEGlyph.c b/hw/xfree86/xaa/xaaNonTEGlyph.c
deleted file mode 100644
index bfe7f9a..0000000
--- a/hw/xfree86/xaa/xaaNonTEGlyph.c
+++ /dev/null
@@ -1,192 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaacexp.h"
-#include "xf86.h"
-
-/* Not used anymore because the algorithm isn't correct. It doesn't
-   handle overlapping characters properly */
-
-#ifdef TRIPLE_BITS
-#define NonTEGlyphFunc EXPNAME(XAANonTEGlyphScanlineFunc3)
-#else
-#define NonTEGlyphFunc EXPNAME(XAANonTEGlyphScanlineFunc)
-#endif
-
-/********************************************************************
-
-   Here we have NonTEGlyphRenders for a bunch of different color
-   expansion types.  The driver may provide its own renderer, but
-   this is the default one which renders using lower-level primitives
-   exported by the chipset driver.
-
-********************************************************************/
-
-/* Since the dimensions of the text string and the backing rectangle
-	do not always coincide, it is possible that wBack or wText
-	may be 0!  The NonTEGlyphRender must always check for this. */
-
-/* This gets built for MSBFIRST or LSBFIRST with FIXEDBASE or not,
-	with TRIPLE_BITS or not. A total of 8 versions */
-
-/* if the backing rectangle and text are of the same dimensions
-	then we can draw in one pass */
-
-void
-#ifdef TRIPLE_BITS
- EXPNAME(XAANonTEGlyphRenderer3) (
-#else
- EXPNAME(XAANonTEGlyphRenderer) (
-#endif
-                                    ScrnInfoPtr pScrn,
-                                    int xText, int wText,
-                                    int y, int h, int skipleft, int startline,
-                                    NonTEGlyphInfo * glyphp,
-                                    int fg, int rop, unsigned int planemask) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *base = (CARD32 *) infoRec->ColorExpandBase;
-
-#ifdef TRIPLE_BITS
-    int dwords = ((3 * wText + 31) >> 5) * h;
-#else
-    int dwords = ((wText + 31) >> 5) * h;
-#endif
-
-    (*infoRec->SetupForCPUToScreenColorExpandFill) (pScrn, fg, -1, rop,
-                                                    planemask);
-    (*infoRec->SubsequentCPUToScreenColorExpandFill) (pScrn, xText, y, wText, h,
-                                                      0);
-
-#ifndef FIXEDBASE
-#ifdef TRIPLE_BITS
-    if ((((3 * wText + 31) >> 5) * h) <= infoRec->ColorExpandRange)
-#else
-    if ((((wText + 31) >> 5) * h) <= infoRec->ColorExpandRange)
-#endif
-        while (h--)
-            base = NonTEGlyphFunc(base, glyphp, startline++, wText, skipleft);
-    else
-#endif
-        while (h--)
-            NonTEGlyphFunc(base, glyphp, startline++, wText, skipleft);
-
-    if ((infoRec->CPUToScreenColorExpandFillFlags & CPU_TRANSFER_PAD_QWORD) &&
-        (dwords & 1)) {
-        base = (CARD32 *) infoRec->ColorExpandBase;
-        base[0] = 0x00000000;
-    }
-
-    if (infoRec->CPUToScreenColorExpandFillFlags & SYNC_AFTER_COLOR_EXPAND)
-        (*infoRec->Sync) (pScrn);
-    else
-        SET_SYNC_FLAG(infoRec);
-}
-
-#ifndef FIXEDBASE
-/*  Scanline version of above gets built for LSBFIRST and MSBFIRST */
-
-void
-#ifdef TRIPLE_BITS
- EXPNAME(XAANonTEGlyphRendererScanline3) (
-#else
- EXPNAME(XAANonTEGlyphRendererScanline) (
-#endif
-                                            ScrnInfoPtr pScrn,
-                                            int xText, int wText,
-                                            int y, int h, int skipleft,
-                                            int startline,
-                                            NonTEGlyphInfo * glyphp, int fg,
-                                            int rop, unsigned int planemask) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int bufferNo = 0;
-    CARD32 *base;
-
-    (*infoRec->SetupForScanlineCPUToScreenColorExpandFill) (pScrn, fg, -1, rop,
-                                                            planemask);
-    (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill) (pScrn, xText, y,
-                                                              wText, h, 0);
-
-    while (h--) {
-        base = (CARD32 *) infoRec->ScanlineColorExpandBuffers[bufferNo];
-        NonTEGlyphFunc(base, glyphp, startline++, wText, skipleft);
-        (*infoRec->SubsequentColorExpandScanline) (pScrn, bufferNo++);
-        if (bufferNo >= infoRec->NumScanlineColorExpandBuffers)
-            bufferNo = 0;
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-#endif
-
-/********************************************************************
-
-   Generic NonTE scanline rendering code.
-
-********************************************************************/
-
-CARD32 *
-NonTEGlyphFunc(CARD32 *base,
-               NonTEGlyphInfo * glyphp, int line, int TotalWidth, int skipleft)
-{
-    CARD32 bits = 0;
-    int shift = glyphp->width;
-
-    if (skipleft) {
-        if ((line >= glyphp->firstline) && (line <= glyphp->lastline))
-            bits = SHIFT_R(glyphp->bitsp[line], skipleft);
-        shift -= skipleft;
-    }
-    else if ((line >= glyphp->firstline) && (line <= glyphp->lastline))
-        bits = glyphp->bitsp[line];
-
-    while (TotalWidth > 32) {
-        while (shift < 32) {
-            glyphp++;
-            if ((line >= glyphp->firstline) && (line <= glyphp->lastline))
-                bits |= SHIFT_L(glyphp->bitsp[line], shift);
-            shift += glyphp->width;
-        }
-#ifdef TRIPLE_BITS
-        WRITE_BITS3(bits);
-#else
-        WRITE_BITS(bits);
-#endif
-        shift &= 31;
-        if (shift && (line >= glyphp->firstline) && (line <= glyphp->lastline))
-            bits = SHIFT_R(glyphp->bitsp[line], glyphp->width - shift);
-        else
-            bits = 0;
-        TotalWidth -= 32;
-    }
-
-    if (TotalWidth) {
-        TotalWidth -= shift;
-        while (TotalWidth > 0) {
-            glyphp++;
-            if ((line >= glyphp->firstline) && (line <= glyphp->lastline))
-                bits |= SHIFT_L(glyphp->bitsp[line], shift);
-            shift += glyphp->width;
-            TotalWidth -= glyphp->width;
-        }
-#ifdef TRIPLE_BITS
-        if (shift >= 22) {
-            WRITE_BITS3(bits);
-        }
-        else if (shift >= 11) {
-            WRITE_BITS2(bits);
-        }
-        else {
-            WRITE_BITS1(bits);
-        }
-#else
-        WRITE_BITS(bits);
-#endif
-    }
-
-    return base;
-}
diff --git a/hw/xfree86/xaa/xaaNonTEText.c b/hw/xfree86/xaa/xaaNonTEText.c
deleted file mode 100644
index 35b4391..0000000
--- a/hw/xfree86/xaa/xaaNonTEText.c
+++ /dev/null
@@ -1,591 +0,0 @@
-
-/********************************************************************
-
-   In this file we have GC level replacements for PolyText8/16,
-   ImageText8/16, ImageGlyphBlt and PolyGlyphBlt for NonTE (proportional) 
-   fonts. The idea is that everything in this file is device independent.
-   The mentioned GCOps are merely wrappers for the 
-   PolyGlyphBltNonTEColorExpansion and ImageGlyphBltNonTEColorExpansion
-   functions which calculate the boxes containing arbitrarily clipped 
-   text and passes them to the NonTEGlyphRenderer which will usually 
-   be a lower level XAA function which renders these clipped glyphs using
-   the basic color expansion functions exported by the chipset driver.
-   The NonTEGlyphRenderer itself may optionally be driver supplied to
-   facilitate work-arounds/optimizations at a higher level than usual.
-
-   Written by Mark Vojkovich (mvojkovi at ucsd.edu)
-
-********************************************************************/
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <string.h>
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include <X11/fonts/font.h>
-#include "scrnintstr.h"
-#include "dixfontstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaacexp.h"
-#include "xaalocal.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-
-static void ImageGlyphBltNonTEColorExpansion(ScrnInfoPtr pScrn,
-                                             int xInit, int yInit, FontPtr font,
-                                             int fg, int bg, unsigned planemask,
-                                             RegionPtr cclip, int nglyph,
-                                             unsigned char *gBase,
-                                             CharInfoPtr * ppci);
-static int PolyGlyphBltNonTEColorExpansion(ScrnInfoPtr pScrn, int xInit,
-                                           int yInit, FontPtr font, int fg,
-                                           int rop, unsigned planemask,
-                                           RegionPtr cclip, int nglyph,
-                                           unsigned char *gBase,
-                                           CharInfoPtr * ppci);
-
-/********************************************************************
-
-   GC level replacements for PolyText8/16 and ImageText8/16
-   for NonTE fonts when using color expansion.
-
-********************************************************************/
-
-int
-XAAPolyText8NonTEColorExpansion(DrawablePtr pDraw,
-                                GCPtr pGC, int x, int y, int count, char *chars)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    unsigned long n;
-    int width = 0;
-
-    (*pGC->font->get_glyphs) (pGC->font, (unsigned long) count,
-                              (unsigned char *) chars, Linear8Bit, &n,
-                              infoRec->CharInfo);
-
-    if (n) {
-        width = PolyGlyphBltNonTEColorExpansion(infoRec->pScrn,
-                                                x + pDraw->x, y + pDraw->y,
-                                                pGC->font, pGC->fgPixel,
-                                                pGC->alu, pGC->planemask,
-                                                pGC->pCompositeClip, n,
-                                                FONTGLYPHS(pGC->font),
-                                                infoRec->CharInfo);
-    }
-
-    return x + width;
-}
-
-int
-XAAPolyText16NonTEColorExpansion(DrawablePtr pDraw,
-                                 GCPtr pGC,
-                                 int x, int y, int count, unsigned short *chars)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    unsigned long n;
-    int width = 0;
-
-    (*pGC->font->get_glyphs) (pGC->font, (unsigned long) count,
-                              (unsigned char *) chars,
-                              (FONTLASTROW(pGC->font) ==
-                               0) ? Linear16Bit : TwoD16Bit, &n,
-                              infoRec->CharInfo);
-
-    if (n) {
-        width = PolyGlyphBltNonTEColorExpansion(infoRec->pScrn,
-                                                x + pDraw->x, y + pDraw->y,
-                                                pGC->font, pGC->fgPixel,
-                                                pGC->alu, pGC->planemask,
-                                                pGC->pCompositeClip, n,
-                                                FONTGLYPHS(pGC->font),
-                                                infoRec->CharInfo);
-    }
-
-    return x + width;
-}
-
-void
-XAAImageText8NonTEColorExpansion(DrawablePtr pDraw,
-                                 GCPtr pGC,
-                                 int x, int y, int count, char *chars)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    unsigned long n;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    (*pGC->font->get_glyphs) (pGC->font, (unsigned long) count,
-                              (unsigned char *) chars, Linear8Bit, &n,
-                              infoRec->CharInfo);
-
-    if (n)
-        ImageGlyphBltNonTEColorExpansion(infoRec->pScrn, x + pDraw->x,
-                                         y + pDraw->y, pGC->font, pGC->fgPixel,
-                                         pGC->bgPixel, pGC->planemask,
-                                         pGC->pCompositeClip, n,
-                                         FONTGLYPHS(pGC->font),
-                                         infoRec->CharInfo);
-}
-
-void
-XAAImageText16NonTEColorExpansion(DrawablePtr pDraw,
-                                  GCPtr pGC,
-                                  int x,
-                                  int y, int count, unsigned short *chars)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    unsigned long n;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    (*pGC->font->get_glyphs) (pGC->font, (unsigned long) count,
-                              (unsigned char *) chars,
-                              (FONTLASTROW(pGC->font) ==
-                               0) ? Linear16Bit : TwoD16Bit, &n,
-                              infoRec->CharInfo);
-
-    if (n)
-        ImageGlyphBltNonTEColorExpansion(infoRec->pScrn, x + pDraw->x,
-                                         y + pDraw->y, pGC->font, pGC->fgPixel,
-                                         pGC->bgPixel, pGC->planemask,
-                                         pGC->pCompositeClip, n,
-                                         FONTGLYPHS(pGC->font),
-                                         infoRec->CharInfo);
-}
-
-/********************************************************************
-
-   GC level replacements for ImageGlyphBlt and PolyGlyphBlt for
-   NonTE fonts when using color expansion.
-
-********************************************************************/
-
-void
-XAAImageGlyphBltNonTEColorExpansion(DrawablePtr pDraw, GCPtr pGC, int xInit, int yInit, unsigned int nglyph, CharInfoPtr * ppci,        /* array of character info */
-                                    pointer pglyphBase  /* start of array of glyphs */
-    )
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    ImageGlyphBltNonTEColorExpansion(infoRec->pScrn, xInit + pDraw->x,
-                                     yInit + pDraw->y, pGC->font, pGC->fgPixel,
-                                     pGC->bgPixel, pGC->planemask,
-                                     pGC->pCompositeClip, nglyph,
-                                     (unsigned char *) pglyphBase, ppci);
-}
-
-void
-XAAPolyGlyphBltNonTEColorExpansion(DrawablePtr pDraw, GCPtr pGC, int xInit, int yInit, unsigned int nglyph, CharInfoPtr * ppci, /* array of character info */
-                                   pointer pglyphBase   /* start of array of glyphs */
-    )
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    PolyGlyphBltNonTEColorExpansion(infoRec->pScrn, xInit + pDraw->x,
-                                    yInit + pDraw->y, pGC->font, pGC->fgPixel,
-                                    pGC->alu, pGC->planemask,
-                                    pGC->pCompositeClip, nglyph,
-                                    (unsigned char *) pglyphBase, ppci);
-}
-
-/********************************************************************
-
-   ImageGlyphBltNonTEColorExpansion -
-   PolyGlyphBltNonTEColorExpansion -
-
-   These guys compute the clipped pieces of text and send it to
-   the lower-level function which will handle acceleration of 
-   arbitrarily clipped text.
-  
-********************************************************************/
-
-static int
-CollectCharacterInfo(NonTEGlyphPtr glyphs,
-                     unsigned int nglyph, CharInfoPtr * ppci, FontPtr pfont)
-{
-    int i, w = 0;
-
-    for (i = 0; i < nglyph; i++, ppci++, glyphs++) {
-        glyphs->bits = (unsigned char *) ((*ppci)->bits);
-        glyphs->start = w + (*ppci)->metrics.leftSideBearing;
-        glyphs->end = w + (*ppci)->metrics.rightSideBearing;
-        glyphs->yoff = (*ppci)->metrics.ascent;
-        glyphs->height = glyphs->yoff + (*ppci)->metrics.descent;
-        glyphs->srcwidth = PADGLYPHWIDTHBYTES(glyphs->end - glyphs->start);
-        w += (*ppci)->metrics.characterWidth;
-    }
-    return w;
-}
-
-static void
-PolyGlyphBltAsSingleBitmap(ScrnInfoPtr pScrn,
-                           int nglyph,
-                           FontPtr font,
-                           int xInit,
-                           int yInit,
-                           int nbox,
-                           BoxPtr pbox, int fg, int rop, unsigned planemask)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *block, *pntr, *bits;
-    int pitch, topLine, botLine, top, bot, height;
-    int Left, Right, Top, Bottom;
-    int LeftEdge, RightEdge;
-    int bitPitch, shift, size, i, skippix;
-    NonTEGlyphPtr glyphs = infoRec->GlyphInfo;
-    Bool extra;
-
-    Left = xInit + infoRec->GlyphInfo[0].start;
-    Right = xInit + infoRec->GlyphInfo[nglyph - 1].end;
-    Top = yInit - FONTMAXBOUNDS(font, ascent);
-    Bottom = yInit + FONTMAXBOUNDS(font, descent);
-
-    /* get into the first band that may contain part of our string */
-    while (nbox && (Top >= pbox->y2)) {
-        pbox++;
-        nbox--;
-    }
-
-    if (!nbox)
-        return;
-
-    pitch = (Right - Left + 31) >> 5;
-    size = (pitch << 2) * (Bottom - Top);
-    block = calloc(1, size);
-
-    topLine = 10000;
-    botLine = -10000;
-
-    while (nglyph--) {
-        top = -glyphs->yoff;
-        bot = top + glyphs->height;
-        if (top < topLine)
-            topLine = top;
-        if (bot > botLine)
-            botLine = bot;
-        skippix = glyphs->start - infoRec->GlyphInfo[0].start;
-        bits = (CARD32 *) glyphs->bits;
-        bitPitch = glyphs->srcwidth >> 2;
-        pntr = block + ((FONTMAXBOUNDS(font, ascent) + top) * pitch) +
-            (skippix >> 5);
-        shift = skippix & 31;
-        extra = ((shift + glyphs->end - glyphs->start) > 32);
-
-        for (i = top; i < bot; i++) {
-            *pntr |= SHIFT_L(*bits, shift);
-            if (extra)
-                *(pntr + 1) |= SHIFT_R(*bits, 32 - shift);
-            pntr += pitch;
-            bits += bitPitch;
-        }
-
-        glyphs++;
-    }
-
-    pntr = block + ((FONTMAXBOUNDS(font, ascent) + topLine) * pitch);
-
-    Top = yInit + topLine;
-    Bottom = yInit + botLine;
-
-    while (nbox && (Top >= pbox->y2)) {
-        pbox++;
-        nbox--;
-    }
-
-    while (nbox && (Bottom > pbox->y1)) {
-        LeftEdge = max(Left, pbox->x1);
-        RightEdge = min(Right, pbox->x2);
-
-        if (RightEdge > LeftEdge) {
-            skippix = LeftEdge - Left;
-            topLine = max(Top, pbox->y1);
-            botLine = min(Bottom, pbox->y2);
-            height = botLine - topLine;
-
-            if (height > 0)
-                (*infoRec->WriteBitmap) (pScrn, LeftEdge, topLine,
-                                         RightEdge - LeftEdge, height,
-                                         (unsigned char *) (pntr +
-                                                            ((topLine -
-                                                              Top) * pitch) +
-                                                            (skippix >> 5)),
-                                         pitch << 2, skippix & 31, fg, -1, rop,
-                                         planemask);
-        }
-
-        nbox--;
-        pbox++;
-    }
-
-    free(block);
-}
-
-static void
-ImageGlyphBltNonTEColorExpansion(ScrnInfoPtr pScrn,
-                                 int xInit, int yInit,
-                                 FontPtr font,
-                                 int fg, int bg,
-                                 unsigned planemask,
-                                 RegionPtr cclip,
-                                 int nglyph,
-                                 unsigned char *gBase, CharInfoPtr * ppci)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int skippix, skipglyph, width, n, i;
-    int Left, Right, Top, Bottom;
-    int LeftEdge, RightEdge, ytop, ybot;
-    int nbox = RegionNumRects(cclip);
-    BoxPtr pbox = RegionRects(cclip);
-    Bool AlreadySetup = FALSE;
-
-    width = CollectCharacterInfo(infoRec->GlyphInfo, nglyph, ppci, font);
-
-    /* find our backing rectangle dimensions */
-    Left = xInit;
-    Right = Left + width;
-    Top = yInit - FONTASCENT(font);
-    Bottom = yInit + FONTDESCENT(font);
-
-    /* get into the first band that may contain part of our box */
-    while (nbox && (Top >= pbox->y2)) {
-        pbox++;
-        nbox--;
-    }
-
-    while (nbox && (Bottom >= pbox->y1)) {
-        /* handle backing rect first */
-        LeftEdge = max(Left, pbox->x1);
-        RightEdge = min(Right, pbox->x2);
-        if (RightEdge > LeftEdge) {
-            ytop = max(Top, pbox->y1);
-            ybot = min(Bottom, pbox->y2);
-
-            if (ybot > ytop) {
-                if (!AlreadySetup) {
-                    (*infoRec->SetupForSolidFill) (pScrn, bg, GXcopy,
-                                                   planemask);
-                    AlreadySetup = TRUE;
-                }
-                (*infoRec->SubsequentSolidFillRect) (pScrn,
-                                                     LeftEdge, ytop,
-                                                     RightEdge - LeftEdge,
-                                                     ybot - ytop);
-            }
-        }
-        nbox--;
-        pbox++;
-    }
-
-    nbox = RegionNumRects(cclip);
-    pbox = RegionRects(cclip);
-
-    if (infoRec->WriteBitmap && (nglyph > 1) &&
-        ((FONTMAXBOUNDS(font, rightSideBearing) -
-          FONTMINBOUNDS(font, leftSideBearing)) <= 32)) {
-        PolyGlyphBltAsSingleBitmap(pScrn, nglyph, font,
-                                   xInit, yInit, nbox, pbox,
-                                   fg, GXcopy, planemask);
-
-        return;
-    }
-
-    /* compute an approximate but covering bounding box */
-    Left = xInit + infoRec->GlyphInfo[0].start;
-    Right = xInit + infoRec->GlyphInfo[nglyph - 1].end;
-    Top = yInit - FONTMAXBOUNDS(font, ascent);
-    Bottom = yInit + FONTMAXBOUNDS(font, descent);
-
-    /* get into the first band that may contain part of our box */
-    while (nbox && (Top >= pbox->y2)) {
-        pbox++;
-        nbox--;
-    }
-
-    /* stop when the lower edge of the box is beyond our string */
-    while (nbox && (Bottom >= pbox->y1)) {
-        LeftEdge = max(Left, pbox->x1);
-        RightEdge = min(Right, pbox->x2);
-
-        if (RightEdge > LeftEdge) {     /* we're possibly drawing something */
-            ytop = max(Top, pbox->y1);
-            ybot = min(Bottom, pbox->y2);
-            if (ybot > ytop) {
-                skippix = LeftEdge - xInit;
-                skipglyph = 0;
-                while (skippix >= infoRec->GlyphInfo[skipglyph].end)
-                    skipglyph++;
-
-                skippix = RightEdge - xInit;
-                n = 0;
-                i = skipglyph;
-                while ((i < nglyph) && (skippix > infoRec->GlyphInfo[i].start)) {
-                    i++;
-                    n++;
-                }
-
-                if (n)
-                    (*infoRec->NonTEGlyphRenderer) (pScrn,
-                                                    xInit, yInit, n,
-                                                    infoRec->GlyphInfo +
-                                                    skipglyph, pbox, fg, GXcopy,
-                                                    planemask);
-            }
-        }
-
-        nbox--;
-        pbox++;
-    }
-}
-
-static int
-PolyGlyphBltNonTEColorExpansion(ScrnInfoPtr pScrn,
-                                int xInit, int yInit,
-                                FontPtr font,
-                                int fg, int rop,
-                                unsigned planemask,
-                                RegionPtr cclip,
-                                int nglyph,
-                                unsigned char *gBase, CharInfoPtr * ppci)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int skippix, skipglyph, width, n, i;
-    int Left, Right, Top, Bottom;
-    int LeftEdge, RightEdge;
-    int nbox = RegionNumRects(cclip);
-    BoxPtr pbox = RegionRects(cclip);
-
-    width = CollectCharacterInfo(infoRec->GlyphInfo, nglyph, ppci, font);
-
-    if (!nbox)
-        return width;
-
-    if ((infoRec->WriteBitmap) && (rop == GXcopy) && (nglyph > 1) &&
-        ((FONTMAXBOUNDS(font, rightSideBearing) -
-          FONTMINBOUNDS(font, leftSideBearing)) <= 32)) {
-
-        PolyGlyphBltAsSingleBitmap(pScrn, nglyph, font,
-                                   xInit, yInit, nbox, pbox,
-                                   fg, rop, planemask);
-
-        return width;
-    }
-
-    /* compute an approximate but covering bounding box */
-    Left = xInit + infoRec->GlyphInfo[0].start;
-    Right = xInit + infoRec->GlyphInfo[nglyph - 1].end;
-    Top = yInit - FONTMAXBOUNDS(font, ascent);
-    Bottom = yInit + FONTMAXBOUNDS(font, descent);
-
-    /* get into the first band that may contain part of our string */
-    while (nbox && (Top >= pbox->y2)) {
-        pbox++;
-        nbox--;
-    }
-
-    /* stop when the lower edge of the box is beyond our string */
-    while (nbox && (Bottom >= pbox->y1)) {
-        LeftEdge = max(Left, pbox->x1);
-        RightEdge = min(Right, pbox->x2);
-
-        if (RightEdge > LeftEdge) {     /* we're possibly drawing something */
-
-            skippix = LeftEdge - xInit;
-            skipglyph = 0;
-            while (skippix >= infoRec->GlyphInfo[skipglyph].end)
-                skipglyph++;
-
-            skippix = RightEdge - xInit;
-            n = 0;
-            i = skipglyph;
-            while ((i < nglyph) && (skippix > infoRec->GlyphInfo[i].start)) {
-                i++;
-                n++;
-            }
-
-            if (n)
-                (*infoRec->NonTEGlyphRenderer) (pScrn,
-                                                xInit, yInit, n,
-                                                infoRec->GlyphInfo + skipglyph,
-                                                pbox, fg, rop, planemask);
-        }
-
-        nbox--;
-        pbox++;
-    }
-    return width;
-}
-
-/* It is possible that the none of the glyphs passed to the 
-   NonTEGlyphRenderer will be drawn.  This function being called
-   indicates that part of the text string's bounding box is visible
-   but not necessarily that any of the characters are visible */
-
-void
-XAANonTEGlyphRenderer(ScrnInfoPtr pScrn,
-                      int x, int y, int n,
-                      NonTEGlyphPtr glyphs,
-                      BoxPtr pbox, int fg, int rop, unsigned int planemask)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int x1, x2, y1, y2, i, w, h, skipleft, skiptop;
-    unsigned char *src;
-
-    for (i = 0; i < n; i++, glyphs++) {
-        x1 = x + glyphs->start;
-        x2 = x + glyphs->end;
-        y1 = y - glyphs->yoff;
-        y2 = y1 + glyphs->height;
-
-        if (y1 < pbox->y1) {
-            skiptop = pbox->y1 - y1;
-            y1 = pbox->y1;
-        }
-        else
-            skiptop = 0;
-        if (y2 > pbox->y2)
-            y2 = pbox->y2;
-        h = y2 - y1;
-        if (h <= 0)
-            continue;
-
-        if (x1 < pbox->x1) {
-            skipleft = pbox->x1 - x1;
-            x1 = pbox->x1;
-        }
-        else
-            skipleft = 0;
-        if (x2 > pbox->x2)
-            x2 = pbox->x2;
-
-        w = x2 - x1;
-
-        if (w > 0) {
-            src = glyphs->bits + (skiptop * glyphs->srcwidth);
-
-            if (skipleft) {
-                src += (skipleft >> 5) << 2;
-                skipleft &= 31;
-            }
-
-            (*infoRec->WriteBitmap) (pScrn, x1, y1, w, h, src,
-                                     glyphs->srcwidth, skipleft, fg, -1, rop,
-                                     planemask);
-        }
-    }
-
-}
diff --git a/hw/xfree86/xaa/xaaOffscreen.c b/hw/xfree86/xaa/xaaOffscreen.c
deleted file mode 100644
index 7d89fc1..0000000
--- a/hw/xfree86/xaa/xaaOffscreen.c
+++ /dev/null
@@ -1,163 +0,0 @@
-
-/*
-   Copyright (c) 1999 -  The XFree86 Project Inc.
-
-   Written by Mark Vojkovich
-
-*/
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "windowstr.h"
-#include "xf86str.h"
-#include "mi.h"
-#include "miline.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaawrap.h"
-#include "xf86fbman.h"
-#include "servermd.h"
-
-void
-XAAMoveOutOffscreenPixmaps(ScreenPtr pScreen)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    PixmapLinkPtr pLink = infoRec->OffscreenPixmaps;
-    XAAPixmapPtr pPriv;
-
-    while (pLink) {
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pLink->pPix);
-        pLink->area = pPriv->offscreenArea;
-        XAAMoveOutOffscreenPixmap(pLink->pPix);
-        pLink = pLink->next;
-    }
-}
-
-void
-XAAMoveInOffscreenPixmaps(ScreenPtr pScreen)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    PixmapLinkPtr pLink = infoRec->OffscreenPixmaps;
-    PixmapPtr pPix, pScreenPix, tmpPix;
-    pointer data;
-    XAAPixmapPtr pPriv;
-    GCPtr pGC;
-    FBAreaPtr area;
-
-    pScreenPix = (*pScreen->GetScreenPixmap) (pScreen);
-
-    while (pLink) {
-        pPix = pLink->pPix;
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
-        area = pLink->area;
-
-        data = pPix->devPrivate.ptr;
-        tmpPix = GetScratchPixmapHeader(pScreen,
-                                        pPix->drawable.width,
-                                        pPix->drawable.height,
-                                        pPix->drawable.depth,
-                                        pPix->drawable.bitsPerPixel,
-                                        pPix->devKind, data);
-
-        pPriv->freeData = FALSE;
-
-        pPix->drawable.x = area->box.x1;
-        pPix->drawable.y = area->box.y1;
-        pPix->devKind = pScreenPix->devKind;
-        pPix->devPrivate.ptr = pScreenPix->devPrivate.ptr;
-        pPix->drawable.bitsPerPixel = infoRec->pScrn->bitsPerPixel;
-        pPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
-
-        if (!tmpPix) {
-            pPriv->offscreenArea = area;
-            free(data);
-            pLink = pLink->next;
-            continue;
-        }
-
-        pGC = GetScratchGC(pPix->drawable.depth, pScreen);
-        ValidateGC((DrawablePtr) pPix, pGC);
-
-        (*pGC->ops->CopyArea) ((DrawablePtr) tmpPix, (DrawablePtr) pPix, pGC,
-                               0, 0, pPix->drawable.width,
-                               pPix->drawable.height, 0, 0);
-
-        free(data);
-        tmpPix->devPrivate.ptr = NULL;
-
-        FreeScratchGC(pGC);
-        FreeScratchPixmapHeader(tmpPix);
-
-        pPriv->offscreenArea = area;
-        pLink->area = NULL;
-        pLink = pLink->next;
-    }
-}
-
-void
-XAARemoveAreaCallback(FBAreaPtr area)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(area->pScreen);
-    PixmapPtr pPix = (PixmapPtr) area->devPrivate.ptr;
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
-
-    XAAMoveOutOffscreenPixmap(pPix);
-
-    pPriv->flags &= ~OFFSCREEN;
-
-    DELIST_OFFSCREEN_PIXMAP(pPix);
-}
-
-void
-XAAMoveOutOffscreenPixmap(PixmapPtr pPix)
-{
-    ScreenPtr pScreen = pPix->drawable.pScreen;
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
-    int width, height, devKind, bitsPerPixel;
-    PixmapPtr tmpPix;
-    unsigned char *data;
-    GCPtr pGC;
-
-    width = pPix->drawable.width;
-    height = pPix->drawable.height;
-    bitsPerPixel = pPix->drawable.bitsPerPixel;
-
-    devKind = BitmapBytePad(width * bitsPerPixel);
-    if (!(data = malloc(devKind * height)))
-        FatalError("Out of memory\n");
-
-    tmpPix = GetScratchPixmapHeader(pScreen, width, height,
-                                    pPix->drawable.depth, bitsPerPixel, devKind,
-                                    data);
-    if (!tmpPix) {
-        free(data);
-        FatalError("Out of memory\n");
-    }
-
-    pGC = GetScratchGC(pPix->drawable.depth, pScreen);
-    ValidateGC((DrawablePtr) tmpPix, pGC);
-
-    (*pGC->ops->CopyArea) ((DrawablePtr) pPix, (DrawablePtr) tmpPix,
-                           pGC, 0, 0, width, height, 0, 0);
-
-    FreeScratchGC(pGC);
-    FreeScratchPixmapHeader(tmpPix);
-
-    pPix->drawable.x = 0;
-    pPix->drawable.y = 0;
-    pPix->devKind = devKind;
-    pPix->devPrivate.ptr = data;
-    pPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
-
-    pPriv->offscreenArea = NULL;
-    pPriv->freeData = TRUE;
-}
diff --git a/hw/xfree86/xaa/xaaOverlay.c b/hw/xfree86/xaa/xaaOverlay.c
deleted file mode 100644
index 25d18da..0000000
--- a/hw/xfree86/xaa/xaaOverlay.c
+++ /dev/null
@@ -1,122 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "windowstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaawrap.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-#include "mioverlay.h"
-
-#ifdef PANORAMIX
-#include "panoramiX.h"
-#include "panoramiXsrv.h"
-#endif
-
-static void
-XAACopyWindow8_32(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
-{
-    DDXPointPtr pptSrc, ppt;
-    RegionRec rgnDst;
-    BoxPtr pbox;
-    int dx, dy, nbox;
-    WindowPtr pwinRoot;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_DRAWABLE((&pWin->drawable));
-    Bool doUnderlay = miOverlayCopyUnderlay(pScreen);
-    RegionPtr borderClip = &pWin->borderClip;
-    Bool freeReg = FALSE;
-
-    if (!infoRec->pScrn->vtSema || !infoRec->ScreenToScreenBitBlt ||
-        (infoRec->ScreenToScreenBitBltFlags & NO_PLANEMASK)) {
-        XAA_SCREEN_PROLOGUE(pScreen, CopyWindow);
-        if (infoRec->pScrn->vtSema && infoRec->NeedToSync) {
-            (*infoRec->Sync) (infoRec->pScrn);
-            infoRec->NeedToSync = FALSE;
-        }
-        (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc);
-        XAA_SCREEN_EPILOGUE(pScreen, CopyWindow, XAACopyWindow8_32);
-        return;
-    }
-
-    pwinRoot = pScreen->root;
-
-    if (doUnderlay)
-        freeReg = miOverlayCollectUnderlayRegions(pWin, &borderClip);
-
-    RegionNull(&rgnDst);
-
-    dx = ptOldOrg.x - pWin->drawable.x;
-    dy = ptOldOrg.y - pWin->drawable.y;
-    RegionTranslate(prgnSrc, -dx, -dy);
-    RegionIntersect(&rgnDst, borderClip, prgnSrc);
-
-    pbox = RegionRects(&rgnDst);
-    nbox = RegionNumRects(&rgnDst);
-    if (!nbox || !(pptSrc = (DDXPointPtr) malloc(nbox * sizeof(DDXPointRec)))) {
-        RegionUninit(&rgnDst);
-        return;
-    }
-    ppt = pptSrc;
-
-    while (nbox--) {
-        ppt->x = pbox->x1 + dx;
-        ppt->y = pbox->y1 + dy;
-        ppt++;
-        pbox++;
-    }
-
-    infoRec->ScratchGC.planemask = doUnderlay ? 0x00ffffff : 0xff000000;
-    infoRec->ScratchGC.alu = GXcopy;
-
-    XAADoBitBlt((DrawablePtr) pwinRoot, (DrawablePtr) pwinRoot,
-                &(infoRec->ScratchGC), &rgnDst, pptSrc);
-
-    free(pptSrc);
-    RegionUninit(&rgnDst);
-    if (freeReg)
-        RegionDestroy(borderClip);
-}
-
-static void
-XAASetColorKey8_32(ScreenPtr pScreen, int nbox, BoxPtr pbox)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    ScrnInfoPtr pScrn = infoRec->pScrn;
-
-    /* I'm counting on writes being clipped away while switched away.
-       If this isn't going to be true then I need to be wrapping instead. */
-    if (!infoRec->pScrn->vtSema)
-        return;
-
-    (*infoRec->FillSolidRects) (pScrn, pScrn->colorKey << 24, GXcopy,
-                                0xff000000, nbox, pbox);
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAASetupOverlay8_32Planar(ScreenPtr pScreen)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    int i;
-
-    pScreen->CopyWindow = XAACopyWindow8_32;
-
-    if (!(infoRec->FillSolidRectsFlags & NO_PLANEMASK))
-        miOverlaySetTransFunction(pScreen, XAASetColorKey8_32);
-
-    infoRec->FullPlanemask = ~0;
-    for (i = 0; i < 32; i++)    /* haven't thought about this much */
-        infoRec->FullPlanemasks[i] = ~0;
-}
diff --git a/hw/xfree86/xaa/xaaOverlayDF.c b/hw/xfree86/xaa/xaaOverlayDF.c
deleted file mode 100644
index 470694c..0000000
--- a/hw/xfree86/xaa/xaaOverlayDF.c
+++ /dev/null
@@ -1,906 +0,0 @@
-/*
-   Copyright (c) 1999 - The XFree86 Project Inc.
-
-   Written by Mark Vojkovich
-*/
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "windowstr.h"
-#include "xf86str.h"
-#include "mi.h"
-#include "miline.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaawrap.h"
-#include "servermd.h"
-
-/* Screen funcs */
-
-static void XAAOverCopyWindow(WindowPtr, DDXPointRec, RegionPtr);
-static void XAAOverWindowExposures(WindowPtr, RegionPtr, RegionPtr);
-
-static int XAAOverStippledFillChooser(GCPtr);
-static int XAAOverOpaqueStippledFillChooser(GCPtr);
-static int XAAOverTiledFillChooser(GCPtr);
-
-/* GC funcs */
-
-static RegionPtr XAAOverCopyArea(DrawablePtr, DrawablePtr, GC *,
-                                 int, int, int, int, int, int);
-static RegionPtr XAAOverCopyPlane(DrawablePtr, DrawablePtr, GCPtr,
-                                  int, int, int, int, int, int, unsigned long);
-static void XAAOverPushPixelsSolid(GCPtr, PixmapPtr, DrawablePtr, int,
-                                   int, int, int);
-static void XAAOverPolyFillRectSolid(DrawablePtr, GCPtr, int, xRectangle *);
-static void XAAOverPolyFillRectStippled(DrawablePtr, GCPtr, int, xRectangle *);
-static void XAAOverPolyFillRectOpaqueStippled(DrawablePtr, GCPtr,
-                                              int, xRectangle *);
-static void XAAOverPolyFillRectTiled(DrawablePtr, GCPtr, int, xRectangle *);
-static void XAAOverFillSpansSolid(DrawablePtr, GCPtr, int, DDXPointPtr,
-                                  int *, int);
-static void XAAOverFillSpansStippled(DrawablePtr, GCPtr, int, DDXPointPtr,
-                                     int *, int);
-static void XAAOverFillSpansOpaqueStippled(DrawablePtr, GCPtr, int,
-                                           DDXPointPtr, int *, int);
-static void XAAOverFillSpansTiled(DrawablePtr, GCPtr, int, DDXPointPtr,
-                                  int *, int);
-static int XAAOverPolyText8TE(DrawablePtr, GCPtr, int, int, int, char *);
-static int XAAOverPolyText16TE(DrawablePtr, GCPtr, int, int, int,
-                               unsigned short *);
-static void XAAOverImageText8TE(DrawablePtr, GCPtr, int, int, int, char *);
-static void XAAOverImageText16TE(DrawablePtr, GCPtr, int, int, int,
-                                 unsigned short *);
-static void XAAOverImageGlyphBltTE(DrawablePtr, GCPtr, int, int,
-                                   unsigned int, CharInfoPtr *, pointer);
-static void XAAOverPolyGlyphBltTE(DrawablePtr, GCPtr, int, int,
-                                  unsigned int, CharInfoPtr *, pointer);
-static int XAAOverPolyText8NonTE(DrawablePtr, GCPtr, int, int, int, char *);
-static int XAAOverPolyText16NonTE(DrawablePtr, GCPtr, int, int, int,
-                                  unsigned short *);
-static void XAAOverImageText8NonTE(DrawablePtr, GCPtr, int, int, int, char *);
-static void XAAOverImageText16NonTE(DrawablePtr, GCPtr, int, int, int,
-                                    unsigned short *);
-static void XAAOverImageGlyphBltNonTE(DrawablePtr, GCPtr, int, int,
-                                      unsigned int, CharInfoPtr *, pointer);
-static void XAAOverPolyGlyphBltNonTE(DrawablePtr, GCPtr, int, int,
-                                     unsigned int, CharInfoPtr *, pointer);
-static void XAAOverPolyRectangleThinSolid(DrawablePtr, GCPtr, int,
-                                          xRectangle *);
-static void XAAOverPolylinesWideSolid(DrawablePtr, GCPtr, int, int,
-                                      DDXPointPtr);
-static void XAAOverPolylinesThinSolid(DrawablePtr, GCPtr, int, int,
-                                      DDXPointPtr);
-static void XAAOverPolySegmentThinSolid(DrawablePtr, GCPtr, int, xSegment *);
-static void XAAOverPolylinesThinDashed(DrawablePtr, GCPtr, int, int,
-                                       DDXPointPtr);
-static void XAAOverPolySegmentThinDashed(DrawablePtr, GCPtr, int, xSegment *);
-static void XAAOverFillPolygonSolid(DrawablePtr, GCPtr, int, int, int,
-                                    DDXPointPtr);
-static void XAAOverFillPolygonStippled(DrawablePtr, GCPtr, int, int, int,
-                                       DDXPointPtr);
-static void XAAOverFillPolygonOpaqueStippled(DrawablePtr, GCPtr, int, int, int,
-                                             DDXPointPtr);
-static void XAAOverFillPolygonTiled(DrawablePtr, GCPtr, int, int, int,
-                                    DDXPointPtr);
-static void XAAOverPolyFillArcSolid(DrawablePtr, GCPtr, int, xArc *);
-static void XAAOverPutImage(DrawablePtr, GCPtr, int, int, int, int, int,
-                            int, int, char *);
-
-typedef struct {
-    ScrnInfoPtr pScrn;
-    DepthChangeFuncPtr callback;
-    int currentDepth;
-/* GC funcs */
-    RegionPtr (*CopyArea) (DrawablePtr, DrawablePtr, GC *,
-                           int, int, int, int, int, int);
-    RegionPtr (*CopyPlane) (DrawablePtr, DrawablePtr, GCPtr,
-                            int, int, int, int, int, int, unsigned long);
-    void (*PushPixelsSolid) (GCPtr, PixmapPtr, DrawablePtr, int, int, int, int);
-    void (*PolyFillRectSolid) (DrawablePtr, GCPtr, int, xRectangle *);
-    void (*PolyFillRectStippled) (DrawablePtr, GCPtr, int, xRectangle *);
-    void (*PolyFillRectOpaqueStippled) (DrawablePtr, GCPtr, int, xRectangle *);
-    void (*PolyFillRectTiled) (DrawablePtr, GCPtr, int, xRectangle *);
-    void (*FillSpansSolid) (DrawablePtr, GCPtr, int, DDXPointPtr, int *, int);
-    void (*FillSpansStippled) (DrawablePtr, GCPtr, int, DDXPointPtr, int *,
-                               int);
-    void (*FillSpansOpaqueStippled) (DrawablePtr, GCPtr, int, DDXPointPtr,
-                                     int *, int);
-    void (*FillSpansTiled) (DrawablePtr, GCPtr, int, DDXPointPtr, int *, int);
-    int (*PolyText8TE) (DrawablePtr, GCPtr, int, int, int, char *);
-    int (*PolyText16TE) (DrawablePtr, GCPtr, int, int, int, unsigned short *);
-    void (*ImageText8TE) (DrawablePtr, GCPtr, int, int, int, char *);
-    void (*ImageText16TE) (DrawablePtr, GCPtr, int, int, int, unsigned short *);
-    void (*ImageGlyphBltTE) (DrawablePtr, GCPtr, int, int, unsigned int,
-                             CharInfoPtr *, pointer);
-    void (*PolyGlyphBltTE) (DrawablePtr, GCPtr, int, int, unsigned int,
-                            CharInfoPtr *, pointer);
-    int (*PolyText8NonTE) (DrawablePtr, GCPtr, int, int, int, char *);
-    int (*PolyText16NonTE) (DrawablePtr, GCPtr, int, int, int,
-                            unsigned short *);
-    void (*ImageText8NonTE) (DrawablePtr, GCPtr, int, int, int, char *);
-    void (*ImageText16NonTE) (DrawablePtr, GCPtr, int, int, int,
-                              unsigned short *);
-    void (*ImageGlyphBltNonTE) (DrawablePtr, GCPtr, int, int, unsigned int,
-                                CharInfoPtr *, pointer);
-    void (*PolyGlyphBltNonTE) (DrawablePtr, GCPtr, int, int, unsigned int,
-                               CharInfoPtr *, pointer);
-    void (*PolyRectangleThinSolid) (DrawablePtr, GCPtr, int, xRectangle *);
-    void (*PolylinesWideSolid) (DrawablePtr, GCPtr, int, int, DDXPointPtr);
-
-    void (*PolylinesThinSolid) (DrawablePtr, GCPtr, int, int, DDXPointPtr);
-    void (*PolySegmentThinSolid) (DrawablePtr, GCPtr, int, xSegment *);
-    void (*PolylinesThinDashed) (DrawablePtr, GCPtr, int, int, DDXPointPtr);
-    void (*PolySegmentThinDashed) (DrawablePtr, GCPtr, int, xSegment *);
-    void (*FillPolygonSolid) (DrawablePtr, GCPtr, int, int, int, DDXPointPtr);
-    void (*FillPolygonStippled) (DrawablePtr, GCPtr, int, int, int,
-                                 DDXPointPtr);
-    void (*FillPolygonOpaqueStippled) (DrawablePtr, GCPtr, int, int, int,
-                                       DDXPointPtr);
-    void (*FillPolygonTiled) (DrawablePtr, GCPtr, int, int, int, DDXPointPtr);
-    void (*PolyFillArcSolid) (DrawablePtr, GCPtr, int, xArc *);
-    void (*PutImage) (DrawablePtr, GCPtr, int, int, int, int, int, int,
-                      int, char *);
-    int (*StippledFillChooser) (GCPtr);
-    int (*OpaqueStippledFillChooser) (GCPtr);
-    int (*TiledFillChooser) (GCPtr);
-} XAAOverlayRec, *XAAOverlayPtr;
-
-static DevPrivateKeyRec XAAOverlayKeyRec;
-
-#define XAAOverlayKey (&XAAOverlayKeyRec)
-
-#define GET_OVERLAY_PRIV(pScreen) \
-    (XAAOverlayPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAOverlayKey)
-
-#define SWITCH_DEPTH(d) \
-   if(pOverPriv->currentDepth != d) { \
-	(*pOverPriv->callback)(pOverPriv->pScrn, d); \
-	pOverPriv->currentDepth = d; \
-   }
-
-Bool
-XAAInitDualFramebufferOverlay(ScreenPtr pScreen, DepthChangeFuncPtr callback)
-{
-    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    XAAOverlayPtr pOverPriv;
-
-    if (!dixRegisterPrivateKey(&XAAOverlayKeyRec, PRIVATE_SCREEN, 0))
-        return FALSE;
-
-    if (!(pOverPriv = malloc(sizeof(XAAOverlayRec))))
-        return FALSE;
-
-    dixSetPrivate(&pScreen->devPrivates, XAAOverlayKey, pOverPriv);
-
-    pOverPriv->pScrn = pScrn;
-    pOverPriv->callback = callback;
-    pOverPriv->currentDepth = -1;
-
-    /* Overwrite key screen functions.  The XAA core will clean up */
-
-    pScreen->CopyWindow = XAAOverCopyWindow;
-    pScreen->WindowExposures = XAAOverWindowExposures;
-
-    pOverPriv->StippledFillChooser = infoRec->StippledFillChooser;
-    pOverPriv->OpaqueStippledFillChooser = infoRec->OpaqueStippledFillChooser;
-    pOverPriv->TiledFillChooser = infoRec->TiledFillChooser;
-
-    infoRec->StippledFillChooser = XAAOverStippledFillChooser;
-    infoRec->OpaqueStippledFillChooser = XAAOverOpaqueStippledFillChooser;
-    infoRec->TiledFillChooser = XAAOverTiledFillChooser;
-
-    /* wrap all XAA GC rendering */
-
-    pOverPriv->CopyArea = infoRec->CopyArea;
-    pOverPriv->CopyPlane = infoRec->CopyPlane;
-    pOverPriv->PushPixelsSolid = infoRec->PushPixelsSolid;
-    pOverPriv->PolyFillRectSolid = infoRec->PolyFillRectSolid;
-    pOverPriv->PolyFillRectStippled = infoRec->PolyFillRectStippled;
-    pOverPriv->PolyFillRectOpaqueStippled = infoRec->PolyFillRectOpaqueStippled;
-    pOverPriv->PolyFillRectTiled = infoRec->PolyFillRectTiled;
-    pOverPriv->FillSpansSolid = infoRec->FillSpansSolid;
-    pOverPriv->FillSpansStippled = infoRec->FillSpansStippled;
-    pOverPriv->FillSpansOpaqueStippled = infoRec->FillSpansOpaqueStippled;
-    pOverPriv->FillSpansTiled = infoRec->FillSpansTiled;
-    pOverPriv->PolyText8TE = infoRec->PolyText8TE;
-    pOverPriv->PolyText16TE = infoRec->PolyText16TE;
-    pOverPriv->ImageText8TE = infoRec->ImageText8TE;
-    pOverPriv->ImageText16TE = infoRec->ImageText16TE;
-    pOverPriv->ImageGlyphBltTE = infoRec->ImageGlyphBltTE;
-    pOverPriv->PolyGlyphBltTE = infoRec->PolyGlyphBltTE;
-    pOverPriv->PolyText8NonTE = infoRec->PolyText8NonTE;
-    pOverPriv->PolyText16NonTE = infoRec->PolyText16NonTE;
-    pOverPriv->ImageText8NonTE = infoRec->ImageText8NonTE;
-    pOverPriv->ImageText16NonTE = infoRec->ImageText16NonTE;
-    pOverPriv->ImageGlyphBltNonTE = infoRec->ImageGlyphBltNonTE;
-    pOverPriv->PolyGlyphBltNonTE = infoRec->PolyGlyphBltNonTE;
-    pOverPriv->PolyRectangleThinSolid = infoRec->PolyRectangleThinSolid;
-    pOverPriv->PolylinesWideSolid = infoRec->PolylinesWideSolid;
-    pOverPriv->PolylinesThinSolid = infoRec->PolylinesThinSolid;
-    pOverPriv->PolySegmentThinSolid = infoRec->PolySegmentThinSolid;
-    pOverPriv->PolylinesThinDashed = infoRec->PolylinesThinDashed;
-    pOverPriv->PolySegmentThinDashed = infoRec->PolySegmentThinDashed;
-    pOverPriv->FillPolygonSolid = infoRec->FillPolygonSolid;
-    pOverPriv->FillPolygonStippled = infoRec->FillPolygonStippled;
-    pOverPriv->FillPolygonOpaqueStippled = infoRec->FillPolygonOpaqueStippled;
-    pOverPriv->FillPolygonTiled = infoRec->FillPolygonTiled;
-    pOverPriv->PolyFillArcSolid = infoRec->PolyFillArcSolid;
-    pOverPriv->PutImage = infoRec->PutImage;
-
-    if (infoRec->CopyArea)
-        infoRec->CopyArea = XAAOverCopyArea;
-    if (infoRec->CopyPlane)
-        infoRec->CopyPlane = XAAOverCopyPlane;
-    if (infoRec->PushPixelsSolid)
-        infoRec->PushPixelsSolid = XAAOverPushPixelsSolid;
-    if (infoRec->PolyFillRectSolid)
-        infoRec->PolyFillRectSolid = XAAOverPolyFillRectSolid;
-    if (infoRec->PolyFillRectStippled)
-        infoRec->PolyFillRectStippled = XAAOverPolyFillRectStippled;
-    if (infoRec->PolyFillRectOpaqueStippled)
-        infoRec->PolyFillRectOpaqueStippled = XAAOverPolyFillRectOpaqueStippled;
-    if (infoRec->PolyFillRectTiled)
-        infoRec->PolyFillRectTiled = XAAOverPolyFillRectTiled;
-    if (infoRec->FillSpansSolid)
-        infoRec->FillSpansSolid = XAAOverFillSpansSolid;
-    if (infoRec->FillSpansStippled)
-        infoRec->FillSpansStippled = XAAOverFillSpansStippled;
-    if (infoRec->FillSpansOpaqueStippled)
-        infoRec->FillSpansOpaqueStippled = XAAOverFillSpansOpaqueStippled;
-    if (infoRec->FillSpansTiled)
-        infoRec->FillSpansTiled = XAAOverFillSpansTiled;
-    if (infoRec->PolyText8TE)
-        infoRec->PolyText8TE = XAAOverPolyText8TE;
-    if (infoRec->PolyText16TE)
-        infoRec->PolyText16TE = XAAOverPolyText16TE;
-    if (infoRec->ImageText8TE)
-        infoRec->ImageText8TE = XAAOverImageText8TE;
-    if (infoRec->ImageText16TE)
-        infoRec->ImageText16TE = XAAOverImageText16TE;
-    if (infoRec->ImageGlyphBltTE)
-        infoRec->ImageGlyphBltTE = XAAOverImageGlyphBltTE;
-    if (infoRec->PolyGlyphBltTE)
-        infoRec->PolyGlyphBltTE = XAAOverPolyGlyphBltTE;
-    if (infoRec->PolyText8NonTE)
-        infoRec->PolyText8NonTE = XAAOverPolyText8NonTE;
-    if (infoRec->PolyText16NonTE)
-        infoRec->PolyText16NonTE = XAAOverPolyText16NonTE;
-    if (infoRec->ImageText8NonTE)
-        infoRec->ImageText8NonTE = XAAOverImageText8NonTE;
-    if (infoRec->ImageText16NonTE)
-        infoRec->ImageText16NonTE = XAAOverImageText16NonTE;
-    if (infoRec->ImageGlyphBltNonTE)
-        infoRec->ImageGlyphBltNonTE = XAAOverImageGlyphBltNonTE;
-    if (infoRec->PolyGlyphBltNonTE)
-        infoRec->PolyGlyphBltNonTE = XAAOverPolyGlyphBltNonTE;
-    if (infoRec->PolyRectangleThinSolid)
-        infoRec->PolyRectangleThinSolid = XAAOverPolyRectangleThinSolid;
-    if (infoRec->PolylinesWideSolid)
-        infoRec->PolylinesWideSolid = XAAOverPolylinesWideSolid;
-    if (infoRec->PolylinesThinSolid)
-        infoRec->PolylinesThinSolid = XAAOverPolylinesThinSolid;
-    if (infoRec->PolySegmentThinSolid)
-        infoRec->PolySegmentThinSolid = XAAOverPolySegmentThinSolid;
-    if (infoRec->PolylinesThinDashed)
-        infoRec->PolylinesThinDashed = XAAOverPolylinesThinDashed;
-    if (infoRec->PolySegmentThinDashed)
-        infoRec->PolySegmentThinDashed = XAAOverPolySegmentThinDashed;
-    if (infoRec->FillPolygonSolid)
-        infoRec->FillPolygonSolid = XAAOverFillPolygonSolid;
-    if (infoRec->FillPolygonStippled)
-        infoRec->FillPolygonStippled = XAAOverFillPolygonStippled;
-    if (infoRec->FillPolygonOpaqueStippled)
-        infoRec->FillPolygonOpaqueStippled = XAAOverFillPolygonOpaqueStippled;
-    if (infoRec->FillPolygonTiled)
-        infoRec->FillPolygonTiled = XAAOverFillPolygonTiled;
-    if (infoRec->PolyFillArcSolid)
-        infoRec->PolyFillArcSolid = XAAOverPolyFillArcSolid;
-    if (infoRec->PutImage)
-        infoRec->PutImage = XAAOverPutImage;
-
-    return TRUE;
-}
-
-/***********************  Screen functions ************************/
-
-void
-XAAOverCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pScreen);
-    ScrnInfoPtr pScrn = infoRec->pScrn;
-    DDXPointPtr ppt, pptSrc;
-    RegionRec rgnDst;
-    BoxPtr pbox;
-    int i, nbox, dx, dy;
-    WindowPtr pRoot = pScreen->root;
-
-    if (!pScrn->vtSema || !infoRec->ScreenToScreenBitBlt) {
-        XAA_SCREEN_PROLOGUE(pScreen, CopyWindow);
-        if (pScrn->vtSema && infoRec->NeedToSync) {
-            (*infoRec->Sync) (pScrn);
-            infoRec->NeedToSync = FALSE;
-        }
-        (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc);
-        XAA_SCREEN_EPILOGUE(pScreen, CopyWindow, XAAOverCopyWindow);
-        return;
-    }
-
-    infoRec->ScratchGC.alu = GXcopy;
-    infoRec->ScratchGC.planemask = ~0;
-
-    RegionNull(&rgnDst);
-
-    dx = ptOldOrg.x - pWin->drawable.x;
-    dy = ptOldOrg.y - pWin->drawable.y;
-    RegionTranslate(prgnSrc, -dx, -dy);
-    RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
-
-    nbox = RegionNumRects(&rgnDst);
-    if (nbox && (pptSrc = (DDXPointPtr) malloc(nbox * sizeof(DDXPointRec)))) {
-
-        pbox = RegionRects(&rgnDst);
-        for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) {
-            ppt->x = pbox->x1 + dx;
-            ppt->y = pbox->y1 + dy;
-        }
-
-        SWITCH_DEPTH(8);
-        XAADoBitBlt((DrawablePtr) pRoot, (DrawablePtr) pRoot,
-                    &(infoRec->ScratchGC), &rgnDst, pptSrc);
-
-        if (pWin->drawable.bitsPerPixel != 8) {
-            SWITCH_DEPTH(pScrn->depth);
-            XAADoBitBlt((DrawablePtr) pRoot, (DrawablePtr) pRoot,
-                        &(infoRec->ScratchGC), &rgnDst, pptSrc);
-        }
-
-        free(pptSrc);
-    }
-
-    RegionUninit(&rgnDst);
-
-    if (pWin->drawable.depth == 8) {
-        RegionNull(&rgnDst);
-        miSegregateChildren(pWin, &rgnDst, pScrn->depth);
-        if (RegionNotEmpty(&rgnDst)) {
-            RegionIntersect(&rgnDst, &rgnDst, prgnSrc);
-            nbox = RegionNumRects(&rgnDst);
-            if (nbox &&
-                (pptSrc = (DDXPointPtr) malloc(nbox * sizeof(DDXPointRec)))) {
-
-                pbox = RegionRects(&rgnDst);
-                for (i = nbox, ppt = pptSrc; i--; ppt++, pbox++) {
-                    ppt->x = pbox->x1 + dx;
-                    ppt->y = pbox->y1 + dy;
-                }
-
-                SWITCH_DEPTH(pScrn->depth);
-                XAADoBitBlt((DrawablePtr) pRoot, (DrawablePtr) pRoot,
-                            &(infoRec->ScratchGC), &rgnDst, pptSrc);
-                free(pptSrc);
-            }
-        }
-        RegionUninit(&rgnDst);
-    }
-}
-
-void
-XAAOverWindowExposures(WindowPtr pWin, RegionPtr pReg, RegionPtr pOtherReg)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-
-    if ((pWin->drawable.bitsPerPixel != 8) && infoRec->pScrn->vtSema) {
-        if (RegionNumRects(pReg) && infoRec->FillSolidRects) {
-            XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pScreen);
-
-            SWITCH_DEPTH(8);
-            (*infoRec->FillSolidRects) (infoRec->pScrn,
-                                        infoRec->pScrn->colorKey, GXcopy, ~0,
-                                        RegionNumRects(pReg),
-                                        RegionRects(pReg));
-            miWindowExposures(pWin, pReg, pOtherReg);
-            return;
-        }
-        else if (infoRec->NeedToSync) {
-            (*infoRec->Sync) (infoRec->pScrn);
-            infoRec->NeedToSync = FALSE;
-        }
-    }
-
-    XAA_SCREEN_PROLOGUE(pScreen, WindowExposures);
-    (*pScreen->WindowExposures) (pWin, pReg, pOtherReg);
-    XAA_SCREEN_EPILOGUE(pScreen, WindowExposures, XAAOverWindowExposures);
-}
-
-/*********************  Choosers *************************/
-
-static int
-XAAOverStippledFillChooser(GCPtr pGC)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-    int ret;
-
-    ret = (*pOverPriv->StippledFillChooser) (pGC);
-
-    if ((pGC->depth == 8) && ((ret == DO_COLOR_8x8) || (ret == DO_CACHE_BLT))) {
-        ret = 0;
-    }
-
-    return ret;
-}
-
-static int
-XAAOverOpaqueStippledFillChooser(GCPtr pGC)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-    int ret;
-
-    ret = (*pOverPriv->OpaqueStippledFillChooser) (pGC);
-
-    if ((pGC->depth == 8) && ((ret == DO_COLOR_8x8) || (ret == DO_CACHE_BLT))) {
-        ret = 0;
-    }
-
-    return ret;
-}
-
-static int
-XAAOverTiledFillChooser(GCPtr pGC)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-    int ret;
-
-    ret = (*pOverPriv->TiledFillChooser) (pGC);
-
-    if ((pGC->depth == 8) && ((ret == DO_COLOR_8x8) || (ret == DO_CACHE_BLT))) {
-        ret = 0;
-    }
-
-    return ret;
-}
-
-/**************************** GC Functions **************************/
-
-static RegionPtr
-XAAOverCopyArea(DrawablePtr pSrc,
-                DrawablePtr pDst,
-                GC * pGC,
-                int srcx, int srcy, int width, int height, int dstx, int dsty)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    return (*pOverPriv->CopyArea) (pSrc, pDst,
-                                   pGC, srcx, srcy, width, height, dstx, dsty);
-}
-
-static RegionPtr
-XAAOverCopyPlane(DrawablePtr pSrc,
-                 DrawablePtr pDst,
-                 GCPtr pGC,
-                 int srcx, int srcy,
-                 int width, int height,
-                 int dstx, int dsty, unsigned long bitPlane)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    return (*pOverPriv->CopyPlane) (pSrc, pDst,
-                                    pGC, srcx, srcy, width, height, dstx, dsty,
-                                    bitPlane);
-
-}
-
-static void
-XAAOverPushPixelsSolid(GCPtr pGC,
-                       PixmapPtr pBitMap,
-                       DrawablePtr pDraw, int dx, int dy, int xOrg, int yOrg)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PushPixelsSolid) (pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg);
-}
-
-static void
-XAAOverPolyFillRectSolid(DrawablePtr pDraw,
-                         GCPtr pGC, int nrectFill, xRectangle *prectInit)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolyFillRectSolid) (pDraw, pGC, nrectFill, prectInit);
-}
-
-static void
-XAAOverPolyFillRectStippled(DrawablePtr pDraw,
-                            GCPtr pGC, int nrectFill, xRectangle *prectInit)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolyFillRectStippled) (pDraw, pGC, nrectFill, prectInit);
-}
-
-static void
-XAAOverPolyFillRectOpaqueStippled(DrawablePtr pDraw,
-                                  GCPtr pGC,
-                                  int nrectFill, xRectangle *prectInit)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolyFillRectOpaqueStippled) (pDraw, pGC, nrectFill, prectInit);
-}
-
-static void
-XAAOverPolyFillRectTiled(DrawablePtr pDraw,
-                         GCPtr pGC, int nrectFill, xRectangle *prectInit)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolyFillRectTiled) (pDraw, pGC, nrectFill, prectInit);
-}
-
-static void
-XAAOverFillSpansSolid(DrawablePtr pDraw,
-                      GCPtr pGC,
-                      int nInit, DDXPointPtr ppt, int *pwidth, int fSorted)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->FillSpansSolid) (pDraw, pGC, nInit, ppt, pwidth, fSorted);
-}
-
-static void
-XAAOverFillSpansStippled(DrawablePtr pDraw,
-                         GCPtr pGC,
-                         int nInit, DDXPointPtr ppt, int *pwidth, int fSorted)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->FillSpansStippled) (pDraw, pGC, nInit, ppt, pwidth, fSorted);
-}
-
-static void
-XAAOverFillSpansOpaqueStippled(DrawablePtr pDraw,
-                               GCPtr pGC,
-                               int nInit,
-                               DDXPointPtr ppt, int *pwidth, int fSorted)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->FillSpansOpaqueStippled) (pDraw, pGC, nInit, ppt, pwidth,
-                                           fSorted);
-}
-
-static void
-XAAOverFillSpansTiled(DrawablePtr pDraw,
-                      GCPtr pGC,
-                      int nInit, DDXPointPtr ppt, int *pwidth, int fSorted)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->FillSpansTiled) (pDraw, pGC, nInit, ppt, pwidth, fSorted);
-}
-
-static int
-XAAOverPolyText8TE(DrawablePtr pDraw,
-                   GCPtr pGC, int x, int y, int count, char *chars)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    return (*pOverPriv->PolyText8TE) (pDraw, pGC, x, y, count, chars);
-}
-
-static int
-XAAOverPolyText16TE(DrawablePtr pDraw,
-                    GCPtr pGC, int x, int y, int count, unsigned short *chars)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    return (*pOverPriv->PolyText16TE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAOverImageText8TE(DrawablePtr pDraw,
-                    GCPtr pGC, int x, int y, int count, char *chars)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->ImageText8TE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAOverImageText16TE(DrawablePtr pDraw,
-                     GCPtr pGC, int x, int y, int count, unsigned short *chars)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->ImageText16TE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAOverImageGlyphBltTE(DrawablePtr pDraw,
-                       GCPtr pGC,
-                       int xInit, int yInit,
-                       unsigned int nglyph,
-                       CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->ImageGlyphBltTE) (pDraw, pGC, xInit, yInit, nglyph, ppci,
-                                   pglyphBase);
-}
-
-static void
-XAAOverPolyGlyphBltTE(DrawablePtr pDraw,
-                      GCPtr pGC,
-                      int xInit, int yInit,
-                      unsigned int nglyph,
-                      CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolyGlyphBltTE) (pDraw, pGC, xInit, yInit, nglyph, ppci,
-                                  pglyphBase);
-}
-
-static int
-XAAOverPolyText8NonTE(DrawablePtr pDraw,
-                      GCPtr pGC, int x, int y, int count, char *chars)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    return (*pOverPriv->PolyText8NonTE) (pDraw, pGC, x, y, count, chars);
-}
-
-static int
-XAAOverPolyText16NonTE(DrawablePtr pDraw,
-                       GCPtr pGC,
-                       int x, int y, int count, unsigned short *chars)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    return (*pOverPriv->PolyText16NonTE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAOverImageText8NonTE(DrawablePtr pDraw,
-                       GCPtr pGC, int x, int y, int count, char *chars)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->ImageText8NonTE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAOverImageText16NonTE(DrawablePtr pDraw,
-                        GCPtr pGC,
-                        int x, int y, int count, unsigned short *chars)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->ImageText16NonTE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAOverImageGlyphBltNonTE(DrawablePtr pDraw,
-                          GCPtr pGC,
-                          int xInit, int yInit,
-                          unsigned int nglyph,
-                          CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->ImageGlyphBltNonTE) (pDraw, pGC, xInit, yInit, nglyph, ppci,
-                                      pglyphBase);
-}
-
-static void
-XAAOverPolyGlyphBltNonTE(DrawablePtr pDraw,
-                         GCPtr pGC,
-                         int xInit, int yInit,
-                         unsigned int nglyph,
-                         CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolyGlyphBltNonTE) (pDraw, pGC, xInit, yInit, nglyph, ppci,
-                                     pglyphBase);
-}
-
-static void
-XAAOverPolyRectangleThinSolid(DrawablePtr pDraw,
-                              GCPtr pGC, int nRectsInit, xRectangle *pRectsInit)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolyRectangleThinSolid) (pDraw, pGC, nRectsInit, pRectsInit);
-}
-
-static void
-XAAOverPolylinesWideSolid(DrawablePtr pDraw,
-                          GCPtr pGC, int mode, int npt, DDXPointPtr pPts)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolylinesWideSolid) (pDraw, pGC, mode, npt, pPts);
-}
-
-static void
-XAAOverPolylinesThinSolid(DrawablePtr pDraw,
-                          GCPtr pGC, int mode, int npt, DDXPointPtr pPts)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolylinesThinSolid) (pDraw, pGC, mode, npt, pPts);
-}
-
-static void
-XAAOverPolySegmentThinSolid(DrawablePtr pDraw,
-                            GCPtr pGC, int nseg, xSegment * pSeg)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolySegmentThinSolid) (pDraw, pGC, nseg, pSeg);
-}
-
-static void
-XAAOverPolylinesThinDashed(DrawablePtr pDraw,
-                           GCPtr pGC, int mode, int npt, DDXPointPtr pPts)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolylinesThinDashed) (pDraw, pGC, mode, npt, pPts);
-}
-
-static void
-XAAOverPolySegmentThinDashed(DrawablePtr pDraw,
-                             GCPtr pGC, int nseg, xSegment * pSeg)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolySegmentThinDashed) (pDraw, pGC, nseg, pSeg);
-}
-
-static void
-XAAOverFillPolygonSolid(DrawablePtr pDraw,
-                        GCPtr pGC,
-                        int shape, int mode, int count, DDXPointPtr ptsIn)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->FillPolygonSolid) (pDraw, pGC, shape, mode, count, ptsIn);
-}
-
-static void
-XAAOverFillPolygonStippled(DrawablePtr pDraw,
-                           GCPtr pGC,
-                           int shape, int mode, int count, DDXPointPtr ptsIn)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->FillPolygonStippled) (pDraw, pGC, shape, mode, count, ptsIn);
-}
-
-static void
-XAAOverFillPolygonOpaqueStippled(DrawablePtr pDraw,
-                                 GCPtr pGC,
-                                 int shape,
-                                 int mode, int count, DDXPointPtr ptsIn)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->FillPolygonOpaqueStippled) (pDraw, pGC, shape, mode, count,
-                                             ptsIn);
-}
-
-static void
-XAAOverFillPolygonTiled(DrawablePtr pDraw,
-                        GCPtr pGC,
-                        int shape, int mode, int count, DDXPointPtr ptsIn)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->FillPolygonTiled) (pDraw, pGC, shape, mode, count, ptsIn);
-}
-
-static void
-XAAOverPolyFillArcSolid(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PolyFillArcSolid) (pDraw, pGC, narcs, parcs);
-}
-
-static void
-XAAOverPutImage(DrawablePtr pDraw,
-                GCPtr pGC,
-                int depth,
-                int x,
-                int y, int w, int h, int leftPad, int format, char *pImage)
-{
-    XAAOverlayPtr pOverPriv = GET_OVERLAY_PRIV(pGC->pScreen);
-
-    SWITCH_DEPTH(pGC->depth);
-
-    (*pOverPriv->PutImage) (pDraw, pGC, depth, x, y, w, h,
-                            leftPad, format, pImage);
-}
diff --git a/hw/xfree86/xaa/xaaPCache.c b/hw/xfree86/xaa/xaaPCache.c
deleted file mode 100644
index 53460b3..0000000
--- a/hw/xfree86/xaa/xaaPCache.c
+++ /dev/null
@@ -1,2527 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <string.h>
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "gc.h"
-#include "mi.h"
-#include "pixmapstr.h"
-#include "windowstr.h"
-#include "regionstr.h"
-#include "servermd.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaacexp.h"
-#include "xaalocal.h"
-#include "xaawrap.h"
-
-#define MAX_COLOR	32
-#define MAX_MONO	32
-#define MAX_8		32
-#define MAX_128		32
-#define MAX_256		32
-#define MAX_512		16
-
-static int CacheInitIndex = -1;
-
-#define CACHEINIT(p) ((p)->privates[CacheInitIndex].val)
-
-typedef struct _CacheLink {
-    int x;
-    int y;
-    int w;
-    int h;
-    struct _CacheLink *next;
-} CacheLink, *CacheLinkPtr;
-
-static void
-TransferList(CacheLinkPtr list, XAACacheInfoPtr array, int num)
-{
-    while (num--) {
-        array->x = list->x;
-        array->y = list->y;
-        array->w = list->w;
-        array->h = list->h;
-        array->serialNumber = 0;
-        array->fg = array->bg = -1;
-        list = list->next;
-        array++;
-    }
-}
-
-static CacheLinkPtr
-Enlist(CacheLinkPtr link, int x, int y, int w, int h)
-{
-    CacheLinkPtr newLink;
-
-    newLink = malloc(sizeof(CacheLink));
-    newLink->next = link;
-    newLink->x = x;
-    newLink->y = y;
-    newLink->w = w;
-    newLink->h = h;
-    return newLink;
-}
-
-static CacheLinkPtr
-Delist(CacheLinkPtr link)
-{
-    CacheLinkPtr ret = NULL;
-
-    if (link) {
-        ret = link->next;
-        free(link);
-    }
-    return ret;
-}
-
-static void
-FreeList(CacheLinkPtr link)
-{
-    CacheLinkPtr tmp;
-
-    while (link) {
-        tmp = link;
-        link = link->next;
-        free(tmp);
-    }
-}
-
-static CacheLinkPtr
-QuadLinks(CacheLinkPtr big, CacheLinkPtr little)
-{
-    /* CAUTION: This doesn't free big */
-    int w1, w2, h1, h2;
-
-    while (big) {
-        w1 = big->w >> 1;
-        w2 = big->w - w1;
-        h1 = big->h >> 1;
-        h2 = big->h - h1;
-
-        little = Enlist(little, big->x, big->y, w1, h1);
-        little = Enlist(little, big->x + w1, big->y, w2, h1);
-        little = Enlist(little, big->x, big->y + h1, w1, h2);
-        little = Enlist(little, big->x + w1, big->y + h1, w2, h2);
-
-        big = big->next;
-    }
-    return little;
-}
-
-static void
-SubdivideList(CacheLinkPtr * large, CacheLinkPtr * small)
-{
-    CacheLinkPtr big = *large;
-    CacheLinkPtr little = *small;
-    int size = big->w >> 1;
-
-    little = Enlist(little, big->x, big->y, size, size);
-    little = Enlist(little, big->x + size, big->y, size, size);
-    little = Enlist(little, big->x, big->y + size, size, size);
-    little = Enlist(little, big->x + size, big->y + size, size, size);
-    *small = little;
-    big = Delist(big);
-    *large = big;
-}
-
-static void
-FreePixmapCachePrivate(XAAPixmapCachePrivatePtr pPriv)
-{
-    if (!pPriv)
-        return;
-
-    free(pPriv->Info512);
-    free(pPriv->Info256);
-    free(pPriv->Info128);
-    free(pPriv->InfoColor);
-    free(pPriv->InfoMono);
-    free(pPriv->InfoPartial);
-
-    free(pPriv);
-}
-
-void
-XAAClosePixmapCache(ScreenPtr pScreen)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-
-    if (infoRec->PixmapCachePrivate)
-        FreePixmapCachePrivate((XAAPixmapCachePrivatePtr) infoRec->
-                               PixmapCachePrivate);
-
-    infoRec->PixmapCachePrivate = NULL;
-}
-
-static CacheLinkPtr
-ThinOutPartials(CacheLinkPtr ListPartial, int *num, int *maxw, int *maxh)
-{
-/* This guy's job is to get at least 4 big slots out of a list of fragments */
-
-    CacheLinkPtr List64, List32, List16, List8, pCur, next, ListKeepers;
-    int Num64, Num32, Num16, Num8, NumKeepers;
-    int w, h;
-
-    List64 = List32 = List16 = List8 = ListKeepers = NULL;
-    Num64 = Num32 = Num16 = Num8 = NumKeepers = 0;
-    w = h = 0;
-
-    /* We sort partials by how large a square tile they can cache.
-       If a partial can't store a 64x64, 32x32, 16x16 or 8x8 tile,
-       we free it.  */
-
-    pCur = ListPartial;
-    while (pCur) {
-        next = pCur->next;
-        if ((pCur->w >= 64) && (pCur->h >= 64)) {
-            pCur->next = List64;
-            List64 = pCur;
-            Num64++;
-        }
-        else if ((pCur->w >= 32) && (pCur->h >= 32)) {
-            pCur->next = List32;
-            List32 = pCur;
-            Num32++;
-        }
-        else if ((pCur->w >= 16) && (pCur->h >= 16)) {
-            pCur->next = List16;
-            List16 = pCur;
-            Num16++;
-        }
-        else if ((pCur->w >= 8) && (pCur->h >= 8)) {
-            pCur->next = List8;
-            List8 = pCur;
-            Num8++;
-        }
-        else {
-            free(pCur);
-        }
-
-        pCur = next;
-    }
-
-    /* We save all the tiles from the largest bin that we can get
-       at least 4 of.  If there are too few of a bigger slot, we
-       cut it in fourths to make smaller slots. */
-
-    if (Num64 >= 4) {
-        ListKeepers = List64;
-        List64 = NULL;
-        NumKeepers = Num64;
-        goto GOT_EM;
-    }
-    else if (Num64) {
-        List32 = QuadLinks(List64, List32);
-        Num32 += Num64 * 4;
-        Num64 = 0;
-    }
-
-    if (Num32 >= 4) {
-        ListKeepers = List32;
-        List32 = NULL;
-        NumKeepers = Num32;
-        goto GOT_EM;
-    }
-    else if (Num32) {
-        List16 = QuadLinks(List32, List16);
-        Num16 += Num32 * 4;
-        Num32 = 0;
-    }
-
-    if (Num16 >= 4) {
-        ListKeepers = List16;
-        List16 = NULL;
-        NumKeepers = Num16;
-        goto GOT_EM;
-    }
-    else if (Num16) {
-        List8 = QuadLinks(List16, List8);
-        Num8 += Num16 * 4;
-        Num16 = 0;
-    }
-
-    if (Num8 >= 4) {
-        ListKeepers = List8;
-        List8 = NULL;
-        NumKeepers = Num8;
-        goto GOT_EM;
-    }
-
- GOT_EM:
-
-    /* Free the ones we aren't using */
-
-    if (List64)
-        FreeList(List64);
-    if (List32)
-        FreeList(List32);
-    if (List16)
-        FreeList(List16);
-    if (List8)
-        FreeList(List8);
-
-    /* Enlarge the slots if we can */
-
-    if (ListKeepers) {
-        CacheLinkPtr pLink = ListKeepers;
-
-        w = h = 128;
-
-        while (pLink) {
-            if (pLink->w < w)
-                w = pLink->w;
-            if (pLink->h < h)
-                h = pLink->h;
-            pLink = pLink->next;
-        }
-    }
-
-    *maxw = w;
-    *maxh = h;
-    *num = NumKeepers;
-    return ListKeepers;
-}
-
-static void
-ConvertColorToMono(CacheLinkPtr * ColorList,
-                   int ColorW, int ColorH,
-                   CacheLinkPtr * MonoList, int MonoW, int MonoH)
-{
-    int x, y, w;
-
-    x = (*ColorList)->x;
-    y = (*ColorList)->y;
-    *ColorList = Delist(*ColorList);
-
-    while (ColorH) {
-        ColorH -= MonoH;
-        for (w = 0; w <= (ColorW - MonoW); w += MonoW)
-            *MonoList = Enlist(*MonoList, x + w, y + ColorH, MonoW, MonoH);
-    }
-}
-
-static void
-ConvertAllPartialsTo8x8(int *NumMono, int *NumColor,
-                        CacheLinkPtr ListPartial,
-                        CacheLinkPtr * ListMono,
-                        CacheLinkPtr * ListColor, XAAInfoRecPtr infoRec)
-{
-/* This guy extracts as many 8x8 slots as it can out of fragments */
-
-    int ColorH = infoRec->CacheHeightColor8x8Pattern;
-    int ColorW = infoRec->CacheWidthColor8x8Pattern;
-    int MonoH = infoRec->CacheHeightMono8x8Pattern;
-    int MonoW = infoRec->CacheWidthMono8x8Pattern;
-    int x, y, w, Height, Width;
-    Bool DoColor = (infoRec->PixmapCacheFlags & CACHE_COLOR_8x8);
-    Bool DoMono = (infoRec->PixmapCacheFlags & CACHE_MONO_8x8);
-    CacheLinkPtr pLink = ListPartial;
-    CacheLinkPtr MonoList = *ListMono, ColorList = *ListColor;
-
-    if (DoColor && DoMono) {
-        /* we assume color patterns take more space than color ones */
-        if (MonoH > ColorH)
-            ColorH = MonoH;
-        if (MonoW > ColorW)
-            ColorW = MonoW;
-    }
-
-    /* Break up the area into as many Color and Mono slots as we can */
-
-    while (pLink) {
-        Height = pLink->h;
-        Width = pLink->w;
-        x = pLink->x;
-        y = pLink->y;
-
-        if (DoColor) {
-            while (Height >= ColorH) {
-                Height -= ColorH;
-                for (w = 0; w <= (Width - ColorW); w += ColorW) {
-                    ColorList =
-                        Enlist(ColorList, x + w, y + Height, ColorW, ColorH);
-                    (*NumColor)++;
-                }
-            }
-        }
-
-        if (DoMono && (Height >= MonoH)) {
-            while (Height >= MonoH) {
-                Height -= MonoH;
-                for (w = 0; w <= (Width - MonoW); w += MonoW) {
-                    MonoList =
-                        Enlist(MonoList, x + w, y + Height, MonoW, MonoH);
-                    (*NumMono)++;
-                }
-            }
-        }
-
-        pLink = pLink->next;
-    }
-
-    *ListMono = MonoList;
-    *ListColor = ColorList;
-    FreeList(ListPartial);
-}
-
-static CacheLinkPtr
-ExtractOneThatFits(CacheLinkPtr * initList, int w, int h)
-{
-    CacheLinkPtr list = *initList;
-    CacheLinkPtr prev = NULL;
-
-    while (list) {
-        if ((list->w >= w) && (list->h >= h))
-            break;
-        prev = list;
-        list = list->next;
-    }
-
-    if (list) {
-        if (prev)
-            prev->next = list->next;
-        else
-            *initList = list->next;
-
-        list->next = NULL;
-    }
-
-    return list;
-}
-
-static CacheLinkPtr
-ConvertSomePartialsTo8x8(int *NumMono, int *NumColor, int *NumPartial,
-                         CacheLinkPtr ListPartial,
-                         CacheLinkPtr * ListMono,
-                         CacheLinkPtr * ListColor,
-                         int *maxw, int *maxh, XAAInfoRecPtr infoRec)
-{
-/* This guy tries to get 4 of each type of 8x8 slot requested out of
-   a list of fragments all while trying to retain some big fragments
-   for the cache blits */
-
-    int ColorH = infoRec->CacheHeightColor8x8Pattern;
-    int ColorW = infoRec->CacheWidthColor8x8Pattern;
-    int MonoH = infoRec->CacheHeightMono8x8Pattern;
-    int MonoW = infoRec->CacheWidthMono8x8Pattern;
-    Bool DoColor = (infoRec->PixmapCacheFlags & CACHE_COLOR_8x8);
-    Bool DoMono = (infoRec->PixmapCacheFlags & CACHE_MONO_8x8);
-    CacheLinkPtr List64, List32, List16, List8, pCur, next, ListKeepers;
-    CacheLinkPtr MonoList = *ListMono, ColorList = *ListColor;
-    int Num64, Num32, Num16, Num8, NumKeepers;
-    int w, h, Width, Height;
-    int MonosPerColor = 1;
-
-    if (DoColor && DoMono) {
-        /* we assume color patterns take more space than color ones */
-        if (MonoH > ColorH)
-            ColorH = MonoH;
-        if (MonoW > ColorW)
-            ColorW = MonoW;
-        MonosPerColor = (ColorH / MonoH) * (ColorW / MonoW);
-    }
-
-    List64 = List32 = List16 = List8 = ListKeepers = MonoList = ColorList =
-        NULL;
-    Num64 = Num32 = Num16 = Num8 = NumKeepers = 0;
-    Width = Height = 0;
-
-    /* We sort partials by how large a square tile they can cache.
-       We make 8x8 patterns from the leftovers if we can. */
-
-    pCur = ListPartial;
-    while (pCur) {
-        next = pCur->next;
-        if ((pCur->w >= 64) && (pCur->h >= 64)) {
-            pCur->next = List64;
-            List64 = pCur;
-            Num64++;
-        }
-        else if ((pCur->w >= 32) && (pCur->h >= 32)) {
-            pCur->next = List32;
-            List32 = pCur;
-            Num32++;
-        }
-        else if ((pCur->w >= 16) && (pCur->h >= 16)) {
-            pCur->next = List16;
-            List16 = pCur;
-            Num16++;
-        }
-        else if ((pCur->w >= 8) && (pCur->h >= 8)) {
-            pCur->next = List8;
-            List8 = pCur;
-            Num8++;
-        }
-        else {
-            h = pCur->h;
-            if (DoColor && (pCur->w >= ColorW) && (h >= ColorH)) {
-                while (h >= ColorH) {
-                    h -= ColorH;
-                    for (w = 0; w <= (pCur->w - ColorW); w += ColorW) {
-                        ColorList = Enlist(ColorList,
-                                           pCur->x + w, pCur->y + h, ColorW,
-                                           ColorH);
-                        (*NumColor)++;
-                    }
-                }
-            }
-            if (DoMono && (pCur->w >= MonoW) && (h >= MonoH)) {
-                while (h >= MonoH) {
-                    h -= MonoH;
-                    for (w = 0; w <= (pCur->w - MonoW); w += MonoW) {
-                        MonoList = Enlist(MonoList,
-                                          pCur->x + w, pCur->y + h, MonoW,
-                                          MonoH);
-                        (*NumMono)++;
-                    }
-                }
-            }
-            free(pCur);
-        }
-
-        pCur = next;
-    }
-
-    /* Try to extract at least 4 of each type of 8x8 slot that we need */
-
-    if (DoColor) {
-        CacheLinkPtr theOne;
-
-        while (*NumColor < 4) {
-            theOne = NULL;
-            if (Num8) {
-                if ((theOne = ExtractOneThatFits(&List8, ColorW, ColorH)))
-                    Num8--;
-            }
-            if (Num16 && !theOne) {
-                if ((theOne = ExtractOneThatFits(&List16, ColorW, ColorH)))
-                    Num16--;
-            }
-            if (Num32 && !theOne) {
-                if ((theOne = ExtractOneThatFits(&List32, ColorW, ColorH)))
-                    Num32--;
-            }
-            if (Num64 && !theOne) {
-                if ((theOne = ExtractOneThatFits(&List64, ColorW, ColorH)))
-                    Num64--;
-            }
-
-            if (!theOne)
-                break;
-
-            ConvertAllPartialsTo8x8(NumMono, NumColor, theOne,
-                                    &MonoList, &ColorList, infoRec);
-
-            if (DoMono) {
-                while (*NumColor && (*NumMono < 4)) {
-                    ConvertColorToMono(&ColorList, ColorW, ColorH,
-                                       &MonoList, MonoW, MonoH);
-                    (*NumColor)--;
-                    *NumMono += MonosPerColor;
-                }
-            }
-        }
-    }
-
-    if (DoMono) {
-        CacheLinkPtr theOne;
-
-        while (*NumMono < 4) {
-            theOne = NULL;
-            if (Num8) {
-                if ((theOne = ExtractOneThatFits(&List8, MonoW, MonoH)))
-                    Num8--;
-            }
-            if (Num16 && !theOne) {
-                if ((theOne = ExtractOneThatFits(&List16, MonoW, MonoH)))
-                    Num16--;
-            }
-            if (Num32 && !theOne) {
-                if ((theOne = ExtractOneThatFits(&List32, MonoW, MonoH)))
-                    Num32--;
-            }
-            if (Num64 && !theOne) {
-                if ((theOne = ExtractOneThatFits(&List64, MonoW, MonoH)))
-                    Num64--;
-            }
-
-            if (!theOne)
-                break;
-
-            ConvertAllPartialsTo8x8(NumMono, NumColor, theOne,
-                                    &MonoList, &ColorList, infoRec);
-        }
-    }
-
-    /* We save all the tiles from the largest bin that we can get
-       at least 4 of.  If there are too few of a bigger slot, we
-       cut it in fourths to make smaller slots. */
-
-    if (Num64 >= 4) {
-        ListKeepers = List64;
-        List64 = NULL;
-        NumKeepers = Num64;
-        goto GOT_EM;
-    }
-    else if (Num64) {
-        List32 = QuadLinks(List64, List32);
-        Num32 += Num64 * 4;
-        Num64 = 0;
-    }
-
-    if (Num32 >= 4) {
-        ListKeepers = List32;
-        List32 = NULL;
-        NumKeepers = Num32;
-        goto GOT_EM;
-    }
-    else if (Num32) {
-        List16 = QuadLinks(List32, List16);
-        Num16 += Num32 * 4;
-        Num32 = 0;
-    }
-
-    if (Num16 >= 4) {
-        ListKeepers = List16;
-        List16 = NULL;
-        NumKeepers = Num16;
-        goto GOT_EM;
-    }
-    else if (Num16) {
-        List8 = QuadLinks(List16, List8);
-        Num8 += Num16 * 4;
-        Num16 = 0;
-    }
-
-    if (Num8 >= 4) {
-        ListKeepers = List8;
-        List8 = NULL;
-        NumKeepers = Num8;
-        goto GOT_EM;
-    }
-
- GOT_EM:
-
-    /* Free the ones we aren't using */
-
-    if (List64)
-        ConvertAllPartialsTo8x8(NumMono, NumColor, List64,
-                                &MonoList, &ColorList, infoRec);
-    if (List32)
-        ConvertAllPartialsTo8x8(NumMono, NumColor, List32,
-                                &MonoList, &ColorList, infoRec);
-    if (List16)
-        ConvertAllPartialsTo8x8(NumMono, NumColor, List16,
-                                &MonoList, &ColorList, infoRec);
-    if (List8)
-        ConvertAllPartialsTo8x8(NumMono, NumColor, List8,
-                                &MonoList, &ColorList, infoRec);
-
-    /* Enlarge the slots if we can */
-
-    if (ListKeepers) {
-        CacheLinkPtr pLink = ListKeepers;
-
-        Width = Height = 128;
-
-        while (pLink) {
-            if (pLink->w < Width)
-                Width = pLink->w;
-            if (pLink->h < Height)
-                Height = pLink->h;
-            pLink = pLink->next;
-        }
-    }
-
-    *ListMono = MonoList;
-    *ListColor = ColorList;
-    *maxw = Width;
-    *maxh = Height;
-    *NumPartial = NumKeepers;
-    return ListKeepers;
-}
-
-void
-XAAInitPixmapCache(ScreenPtr pScreen, RegionPtr areas, pointer data)
-{
-    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-    XAAInfoRecPtr infoRec = (XAAInfoRecPtr) data;
-    XAAPixmapCachePrivatePtr pCachePriv;
-    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;
-    int x, y, w, h, ntotal, granularity, width, height, i;
-    int MaxPartialWidth, MaxPartialHeight;
-
-    infoRec->MaxCacheableTileWidth = 0;
-    infoRec->MaxCacheableTileHeight = 0;
-    infoRec->MaxCacheableStippleHeight = 0;
-    infoRec->MaxCacheableStippleWidth = 0;
-    infoRec->UsingPixmapCache = FALSE;
-
-    if (!nBox || !pBox || !(infoRec->Flags & PIXMAP_CACHE))
-        return;
-
-    /* Allocate a persistent per-screen init flag to control messages */
-    if (CacheInitIndex < 0)
-        CacheInitIndex = xf86AllocateScrnInfoPrivateIndex();
-
-    /* free the old private data if it exists */
-    if (infoRec->PixmapCachePrivate) {
-        FreePixmapCachePrivate((XAAPixmapCachePrivatePtr) infoRec->
-                               PixmapCachePrivate);
-        infoRec->PixmapCachePrivate = NULL;
-    }
-
-    Num512 = Num256 = Num128 = NumPartial = NumMono = NumColor = 0;
-    List512 = List256 = List128 = ListPartial = ListMono = ListColor = NULL;
-    granularity = infoRec->CachePixelGranularity;
-    if (granularity <= 1)
-        granularity = 0;
-
-    /* go through the boxes and break it into as many pieces as we can fit */
-
-    while (nBox--) {
-        x = pBox->x1;
-        if (granularity) {
-            int tmp = x % granularity;
-
-            if (tmp)
-                x += (granularity - tmp);
-        }
-        width = pBox->x2 - x;
-        if (width <= 0) {
-            pBox++;
-            continue;
-        }
-
-        y = pBox->y1;
-        height = pBox->y2 - y;
-
-        for (h = 0; h <= (height - 512); h += 512) {
-            for (w = 0; w <= (width - 512); w += 512) {
-                List512 = Enlist(List512, x + w, y + h, 512, 512);
-                Num512++;
-            }
-            for (; w <= (width - 256); w += 256) {
-                List256 = Enlist(List256, x + w, y + h, 256, 256);
-                List256 = Enlist(List256, x + w, y + h + 256, 256, 256);
-                Num256 += 2;
-            }
-            for (; w <= (width - 128); w += 128) {
-                List128 = Enlist(List128, x + w, y + h, 128, 128);
-                List128 = Enlist(List128, x + w, y + h + 128, 128, 128);
-                List128 = Enlist(List128, x + w, y + h + 256, 128, 128);
-                List128 = Enlist(List128, x + w, y + h + 384, 128, 128);
-                Num128 += 4;
-            }
-            if (w < width) {
-                int d = width - w;
-
-                ListPartial = Enlist(ListPartial, x + w, y + h, d, 128);
-                ListPartial = Enlist(ListPartial, x + w, y + h + 128, d, 128);
-                ListPartial = Enlist(ListPartial, x + w, y + h + 256, d, 128);
-                ListPartial = Enlist(ListPartial, x + w, y + h + 384, d, 128);
-                NumPartial += 4;
-            }
-        }
-        for (; h <= (height - 256); h += 256) {
-            for (w = 0; w <= (width - 256); w += 256) {
-                List256 = Enlist(List256, x + w, y + h, 256, 256);
-                Num256++;
-            }
-            for (; w <= (width - 128); w += 128) {
-                List128 = Enlist(List128, x + w, y + h, 128, 128);
-                List128 = Enlist(List128, x + w, y + h + 128, 128, 128);
-                Num128 += 2;
-            }
-            if (w < width) {
-                int d = width - w;
-
-                ListPartial = Enlist(ListPartial, x + w, y + h, d, 128);
-                ListPartial = Enlist(ListPartial, x + w, y + h + 128, d, 128);
-                NumPartial += 2;
-            }
-        }
-        for (; h <= (height - 128); h += 128) {
-            for (w = 0; w <= (width - 128); w += 128) {
-                List128 = Enlist(List128, x + w, y + h, 128, 128);
-                Num128++;
-            }
-            if (w < width) {
-                ListPartial = Enlist(ListPartial, x + w, y + h, width - w, 128);
-                NumPartial++;
-            }
-        }
-        if (h < height) {
-            int d = height - h;
-
-            for (w = 0; w <= (width - 128); w += 128) {
-                ListPartial = Enlist(ListPartial, x + w, y + h, 128, d);
-                NumPartial++;
-            }
-            if (w < width) {
-                ListPartial = Enlist(ListPartial, x + w, y + h, width - w, d);
-                NumPartial++;
-            }
-        }
-        pBox++;
-    }
-
-/* 
-   by this point we've carved the space into as many 512x512, 256x256
-	and 128x128 blocks as we could fit.  We will then break larger
-	blocks into smaller ones if we need to.  The rules are as follows:
-
-     512x512 -
-	1) Don't take up more than half the memory.
-	2) Don't bother if you can't get at least four.
-	3) Don't make more than MAX_512.
-	4) Don't have any of there are no 256x256s.
-
-     256x256 -
-	1) Don't take up more than a quarter of the memory enless there
-		aren't any 512x512s.  Then we can take up to half.
-	2) Don't bother if you can't get at least four.
-	3) Don't make more than MAX_256.
-
-     128x128 -
-	1) Don't make more than MAX_128.
-
-     We don't bother with the partial blocks unless we can use them
-     for 8x8 pattern fills or we are short on larger blocks.
-
-*/
-
-    ntotal = Num128 + (Num256 << 2) + (Num512 << 4);
-
-    Target512 = ntotal >> 5;
-    if (Target512 < 4)
-        Target512 = 0;
-    if (!Target512)
-        Target256 = ntotal >> 3;
-    else
-        Target256 = ntotal >> 4;
-    if (Target256 < 4)
-        Target256 = 0;
-
-    if (Num512 && Num256 < 4) {
-        while (Num512 && Num256 < Target256) {
-            SubdivideList(&List512, &List256);
-            Num256 += 4;
-            Num512--;
-        }
-    }
-
-    if (!Num512) {              /* no room */
-    }
-    else if ((Num512 < 4) || (!Target512)) {
-        while (Num512) {
-            SubdivideList(&List512, &List256);
-            Num256 += 4;
-            Num512--;
-        }
-    }
-    else if ((Num512 > MAX_512) || (Num512 > Target512)) {
-        while (Num512 > MAX_512) {
-            SubdivideList(&List512, &List256);
-            Num256 += 4;
-            Num512--;
-        }
-        while (Num512 > Target512) {
-            if (Num256 < MAX_256) {
-                SubdivideList(&List512, &List256);
-                Num256 += 4;
-                Num512--;
-            }
-            else
-                break;
-        }
-    }
-
-    if (!Num256) {              /* no room */
-    }
-    else if ((Num256 < 4) || (!Target256)) {
-        while (Num256) {
-            SubdivideList(&List256, &List128);
-            Num128 += 4;
-            Num256--;
-        }
-    }
-    else if ((Num256 > MAX_256) || (Num256 > Target256)) {
-        while (Num256 > MAX_256) {
-            SubdivideList(&List256, &List128);
-            Num128 += 4;
-            Num256--;
-        }
-        while (Num256 > Target256) {
-            if (Num128 < MAX_128) {
-                SubdivideList(&List256, &List128);
-                Num128 += 4;
-                Num256--;
-            }
-            else
-                break;
-        }
-    }
-
-    if (Num128 && ((Num128 < 4) || (Num128 > MAX_128))) {
-        CacheLinkPtr next;
-        int max = (Num128 > MAX_128) ? MAX_128 : 0;
-
-        /*
-         * Note: next is set in this way to work around a code generation
-         * bug in gcc 2.7.2.3.
-         */
-        next = List128->next;
-        while (Num128 > max) {
-            List128->next = ListPartial;
-            ListPartial = List128;
-            if ((List128 = next))
-                next = List128->next;
-            NumPartial++;
-            Num128--;
-        }
-    }
-
-    MaxPartialHeight = MaxPartialWidth = 0;
-
-    /* at this point we have as many 512x512 and 256x256 slots as we
-       want but may have an excess of 128x128 slots.  We still need
-       to find out if we need 8x8 slots.  We take these from the
-       partials if we have them.  Otherwise, we break some 128x128's */
-
-    if (!(infoRec->PixmapCacheFlags & (CACHE_MONO_8x8 | CACHE_COLOR_8x8))) {
-        if (NumPartial) {
-            if (Num128) {       /* don't bother with partials */
-                FreeList(ListPartial);
-                NumPartial = 0;
-                ListPartial = NULL;
-            }
-            else {
-                /* We have no big slots.  Weed out the unusable partials */
-                ListPartial = ThinOutPartials(ListPartial, &NumPartial,
-                                              &MaxPartialWidth,
-                                              &MaxPartialHeight);
-            }
-        }
-    }
-    else {
-        int MonosPerColor = 1;
-        int ColorH = infoRec->CacheHeightColor8x8Pattern;
-        int ColorW = infoRec->CacheWidthColor8x8Pattern;
-        int MonoH = infoRec->CacheHeightMono8x8Pattern;
-        int MonoW = infoRec->CacheWidthMono8x8Pattern;
-        Bool DoColor = (infoRec->PixmapCacheFlags & CACHE_COLOR_8x8);
-        Bool DoMono = (infoRec->PixmapCacheFlags & CACHE_MONO_8x8);
-
-        if (DoColor)
-            infoRec->CanDoColor8x8 = FALSE;
-        if (DoMono)
-            infoRec->CanDoMono8x8 = FALSE;
-
-        if (DoColor && DoMono) {
-            /* we assume color patterns take more space than color ones */
-            if (MonoH > ColorH)
-                ColorH = MonoH;
-            if (MonoW > ColorW)
-                ColorW = MonoW;
-            MonosPerColor = (ColorH / MonoH) * (ColorW / MonoW);
-        }
-
-        if (Num128) {
-            if (NumPartial) {   /* use all for 8x8 slots */
-                ConvertAllPartialsTo8x8(&NumMono, &NumColor,
-                                        ListPartial, &ListMono, &ListColor,
-                                        infoRec);
-                NumPartial = 0;
-                ListPartial = NULL;
-            }
-
-            /* Get some 8x8 slots from the 128 slots */
-            while ((Num128 > 4) &&
-                   ((NumMono < MAX_MONO) && (NumColor < MAX_COLOR))) {
-                CacheLinkPtr tmp = NULL;
-
-                tmp = Enlist(tmp, List128->x, List128->y,
-                             List128->w, List128->h);
-                List128 = Delist(List128);
-                Num128--;
-
-                ConvertAllPartialsTo8x8(&NumMono, &NumColor,
-                                        tmp, &ListMono, &ListColor, infoRec);
-            }
-        }
-        else if (NumPartial) {
-            /* We have share partials between 8x8 slots and tiles. */
-            ListPartial = ConvertSomePartialsTo8x8(&NumMono, &NumColor,
-                                                   &NumPartial, ListPartial,
-                                                   &ListMono, &ListColor,
-                                                   &MaxPartialWidth,
-                                                   &MaxPartialHeight, infoRec);
-        }
-
-        if (DoMono && DoColor) {
-            if (NumColor && ((NumColor > MAX_COLOR) || (NumColor < 4))) {
-                int max = (NumColor > MAX_COLOR) ? MAX_COLOR : 0;
-
-                while (NumColor > max) {
-                    ConvertColorToMono(&ListColor, ColorW, ColorH,
-                                       &ListMono, MonoW, MonoH);
-                    NumColor--;
-                    NumMono += MonosPerColor;
-                }
-            }
-
-            /* favor Mono slots over Color ones */
-            while ((NumColor > 4) && (NumMono < MAX_MONO)) {
-                ConvertColorToMono(&ListColor, ColorW, ColorH,
-                                   &ListMono, MonoW, MonoH);
-                NumColor--;
-                NumMono += MonosPerColor;
-            }
-        }
-
-        if (NumMono && ((NumMono > MAX_MONO) || (NumMono < 4))) {
-            int max = (NumMono > MAX_MONO) ? MAX_MONO : 0;
-
-            while (NumMono > max) {
-                ListMono = Delist(ListMono);
-                NumMono--;
-            }
-        }
-        if (NumColor && ((NumColor > MAX_COLOR) || (NumColor < 4))) {
-            int max = (NumColor > MAX_COLOR) ? MAX_COLOR : 0;
-
-            while (NumColor > max) {
-                ListColor = Delist(ListColor);
-                NumColor--;
-            }
-        }
-    }
-
-    pCachePriv = calloc(1, sizeof(XAAPixmapCachePrivate));
-    if (!pCachePriv) {
-        if (Num512)
-            FreeList(List512);
-        if (Num256)
-            FreeList(List256);
-        if (Num128)
-            FreeList(List128);
-        if (NumPartial)
-            FreeList(ListPartial);
-        if (NumColor)
-            FreeList(ListColor);
-        if (NumMono)
-            FreeList(ListMono);
-        return;
-    }
-
-    infoRec->PixmapCachePrivate = (char *) pCachePriv;
-
-    if (Num512) {
-        pCachePriv->Info512 = calloc(Num512, sizeof(XAACacheInfoRec));
-        if (!pCachePriv->Info512)
-            Num512 = 0;
-        if (Num512)
-            TransferList(List512, pCachePriv->Info512, Num512);
-        FreeList(List512);
-        pCachePriv->Num512x512 = Num512;
-    }
-    if (Num256) {
-        pCachePriv->Info256 = calloc(Num256, sizeof(XAACacheInfoRec));
-        if (!pCachePriv->Info256)
-            Num256 = 0;
-        if (Num256)
-            TransferList(List256, pCachePriv->Info256, Num256);
-        FreeList(List256);
-        pCachePriv->Num256x256 = Num256;
-    }
-    if (Num128) {
-        pCachePriv->Info128 = calloc(Num128, sizeof(XAACacheInfoRec));
-        if (!pCachePriv->Info128)
-            Num128 = 0;
-        if (Num128)
-            TransferList(List128, pCachePriv->Info128, Num128);
-        FreeList(List128);
-        pCachePriv->Num128x128 = Num128;
-    }
-
-    if (NumPartial) {
-        pCachePriv->InfoPartial = calloc(NumPartial, sizeof(XAACacheInfoRec));
-        if (!pCachePriv->InfoPartial)
-            NumPartial = 0;
-        if (NumPartial)
-            TransferList(ListPartial, pCachePriv->InfoPartial, NumPartial);
-        FreeList(ListPartial);
-        pCachePriv->NumPartial = NumPartial;
-    }
-
-    if (NumColor) {
-        pCachePriv->InfoColor = calloc(NumColor, sizeof(XAACacheInfoRec));
-        if (!pCachePriv->InfoColor)
-            NumColor = 0;
-        if (NumColor)
-            TransferList(ListColor, pCachePriv->InfoColor, NumColor);
-        FreeList(ListColor);
-        pCachePriv->NumColor = NumColor;
-    }
-
-    if (NumMono) {
-        pCachePriv->InfoMono = calloc(NumMono, sizeof(XAACacheInfoRec));
-        if (!pCachePriv->InfoMono)
-            NumMono = 0;
-        if (NumMono)
-            TransferList(ListMono, pCachePriv->InfoMono, NumMono);
-        FreeList(ListMono);
-        pCachePriv->NumMono = NumMono;
-    }
-
-    if (NumPartial) {
-        infoRec->MaxCacheableTileWidth = MaxPartialWidth;
-        infoRec->MaxCacheableTileHeight = MaxPartialHeight;
-    }
-    if (Num128)
-        infoRec->MaxCacheableTileWidth = infoRec->MaxCacheableTileHeight = 128;
-    if (Num256)
-        infoRec->MaxCacheableTileWidth = infoRec->MaxCacheableTileHeight = 256;
-    if (Num512)
-        infoRec->MaxCacheableTileWidth = infoRec->MaxCacheableTileHeight = 512;
-
-    infoRec->MaxCacheableStippleHeight = infoRec->MaxCacheableTileHeight;
-    infoRec->MaxCacheableStippleWidth =
-        infoRec->MaxCacheableTileWidth * pScrn->bitsPerPixel;
-    if (infoRec->ScreenToScreenColorExpandFillFlags & TRIPLE_BITS_24BPP)
-        infoRec->MaxCacheableStippleWidth /= 3;
-
-    if (NumMono) {
-        if (!(infoRec->Mono8x8PatternFillFlags &
-              (HARDWARE_PATTERN_PROGRAMMED_ORIGIN |
-               HARDWARE_PATTERN_PROGRAMMED_BITS))) {
-            int numPerLine =
-                infoRec->CacheWidthMono8x8Pattern / infoRec->MonoPatternPitch;
-
-            for (i = 0; i < 64; i++) {
-                pCachePriv->MonoOffsets[i].y = i / numPerLine;
-                pCachePriv->MonoOffsets[i].x = (i % numPerLine) *
-                    infoRec->MonoPatternPitch;
-            }
-        }
-        infoRec->CanDoMono8x8 = TRUE;
-    }
-    if (NumColor) {
-        if (!(infoRec->Color8x8PatternFillFlags &
-              HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-
-            for (i = 0; i < 64; i++) {
-                pCachePriv->ColorOffsets[i].y = i & 0x07;
-                pCachePriv->ColorOffsets[i].x = i & ~0x07;
-            }
-        }
-        infoRec->CanDoColor8x8 = TRUE;
-    }
-
-    if (!CACHEINIT(pScrn)) {
-        xf86ErrorF("\tSetting up tile and stipple cache:\n");
-        if (NumPartial)
-            xf86ErrorF("\t\t%i %ix%i slots\n",
-                       NumPartial, MaxPartialWidth, MaxPartialHeight);
-        if (Num128)
-            xf86ErrorF("\t\t%i 128x128 slots\n", Num128);
-        if (Num256)
-            xf86ErrorF("\t\t%i 256x256 slots\n", Num256);
-        if (Num512)
-            xf86ErrorF("\t\t%i 512x512 slots\n", Num512);
-        if (NumColor)
-            xf86ErrorF("\t\t%i 8x8 color pattern slots\n", NumColor);
-        if (NumMono)
-            xf86ErrorF("\t\t%i 8x8 color expansion slots\n", NumMono);
-    }
-
-    if (!(NumPartial | Num128 | Num256 | Num512 | NumColor | NumMono)) {
-        if (!CACHEINIT(pScrn))
-            xf86ErrorF("\t\tNot enough video memory for pixmap cache\n");
-    }
-    else
-        infoRec->UsingPixmapCache = TRUE;
-
-    CACHEINIT(pScrn) = 1;
-}
-
-#if X_BYTE_ORDER == X_BIG_ENDIAN
-static CARD32 StippleMasks[4] = {
-    0x80808080,
-    0xC0C0C0C0,
-    0x00000000,
-    0xF0F0F0F0
-};
-#else
-static CARD32 StippleMasks[4] = {
-    0x01010101,
-    0x03030303,
-    0x00000000,
-    0x0F0F0F0F
-};
-#endif
-
-Bool
-XAACheckStippleReducibility(PixmapPtr pPixmap)
-{
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPixmap);
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_DRAWABLE(&pPixmap->drawable);
-    CARD32 *IntPtr = (CARD32 *) pPixmap->devPrivate.ptr;
-    int w = pPixmap->drawable.width;
-    int h = pPixmap->drawable.height;
-    int i;
-    CARD32 bits[8];
-    CARD32 mask = SHIFT_R(0xFFFFFFFF, 24);
-
-    pPriv->flags |= REDUCIBILITY_CHECKED | REDUCIBLE_TO_2_COLOR;
-    pPriv->flags &= ~REDUCIBLE_TO_8x8;
-
-    if ((w > 32) || (h > 32) || (w & (w - 1)) || (h & (h - 1)))
-        return FALSE;
-
-    i = (h > 8) ? 8 : h;
-
-    switch (w) {
-    case 32:
-        while (i--) {
-            bits[i] = IntPtr[i] & mask;
-            if ((bits[i] != SHIFT_R((IntPtr[i] & SHIFT_L(mask, 8)), 8)) ||
-                (bits[i] != SHIFT_R((IntPtr[i] & SHIFT_L(mask, 16)), 16)) ||
-                (bits[i] != SHIFT_R((IntPtr[i] & SHIFT_L(mask, 24)), 24)))
-                return FALSE;
-        }
-        break;
-    case 16:
-        while (i--) {
-            bits[i] = IntPtr[i] & mask;
-            if (bits[i] != ((IntPtr[i] & SHIFT_R(SHIFT_L(mask, 8), 8))))
-                return FALSE;
-        }
-        break;
-    default:
-        while (i--)
-            bits[i] = IntPtr[i] & mask;
-        break;
-    }
-
-    switch (h) {
-    case 32:
-        if ((IntPtr[8] != IntPtr[16]) || (IntPtr[9] != IntPtr[17]) ||
-            (IntPtr[10] != IntPtr[18]) || (IntPtr[11] != IntPtr[19]) ||
-            (IntPtr[12] != IntPtr[20]) || (IntPtr[13] != IntPtr[21]) ||
-            (IntPtr[14] != IntPtr[22]) || (IntPtr[15] != IntPtr[23]) ||
-            (IntPtr[16] != IntPtr[24]) || (IntPtr[17] != IntPtr[25]) ||
-            (IntPtr[18] != IntPtr[26]) || (IntPtr[19] != IntPtr[27]) ||
-            (IntPtr[20] != IntPtr[28]) || (IntPtr[21] != IntPtr[29]) ||
-            (IntPtr[22] != IntPtr[30]) || (IntPtr[23] != IntPtr[31]))
-            return FALSE;
-        /* fall through */
-    case 16:
-        if ((IntPtr[0] != IntPtr[8]) || (IntPtr[1] != IntPtr[9]) ||
-            (IntPtr[2] != IntPtr[10]) || (IntPtr[3] != IntPtr[11]) ||
-            (IntPtr[4] != IntPtr[12]) || (IntPtr[5] != IntPtr[13]) ||
-            (IntPtr[6] != IntPtr[14]) || (IntPtr[7] != IntPtr[15]))
-            return FALSE;
-    case 8:
-        break;
-    case 1:
-        bits[1] = bits[0];
-    case 2:
-        bits[2] = bits[0];
-        bits[3] = bits[1];
-    case 4:
-        bits[4] = bits[0];
-        bits[5] = bits[1];
-        bits[6] = bits[2];
-        bits[7] = bits[3];
-        break;
-    }
-
-    pPriv->flags |= REDUCIBLE_TO_8x8;
-
-    pPriv->pattern0 =
-        bits[0] | SHIFT_L(bits[1], 8) | SHIFT_L(bits[2], 16) | SHIFT_L(bits[3],
-                                                                       24);
-    pPriv->pattern1 =
-        bits[4] | SHIFT_L(bits[5], 8) | SHIFT_L(bits[6], 16) | SHIFT_L(bits[7],
-                                                                       24);
-
-    if (w < 8) {
-        pPriv->pattern0 &= StippleMasks[w - 1];
-        pPriv->pattern1 &= StippleMasks[w - 1];
-
-        switch (w) {
-        case 1:
-            pPriv->pattern0 |= SHIFT_L(pPriv->pattern0, 1);
-            pPriv->pattern1 |= SHIFT_L(pPriv->pattern1, 1);
-        case 2:
-            pPriv->pattern0 |= SHIFT_L(pPriv->pattern0, 2);
-            pPriv->pattern1 |= SHIFT_L(pPriv->pattern1, 2);
-        case 4:
-            pPriv->pattern0 |= SHIFT_L(pPriv->pattern0, 4);
-            pPriv->pattern1 |= SHIFT_L(pPriv->pattern1, 4);
-        }
-    }
-
-    if (infoRec->Mono8x8PatternFillFlags & BIT_ORDER_IN_BYTE_MSBFIRST) {
-        pPriv->pattern0 = SWAP_BITS_IN_BYTES(pPriv->pattern0);
-        pPriv->pattern1 = SWAP_BITS_IN_BYTES(pPriv->pattern1);
-    }
-
-    return TRUE;
-}
-
-Bool
-XAACheckTileReducibility(PixmapPtr pPixmap, Bool checkMono)
-{
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPixmap);
-    CARD32 *IntPtr;
-    int w = pPixmap->drawable.width;
-    int h = pPixmap->drawable.height;
-    int pitch = pPixmap->devKind >> 2;
-    int dwords, i, j;
-
-    pPriv->flags |= REDUCIBILITY_CHECKED;
-    pPriv->flags &= ~(REDUCIBILITY_CHECKED | REDUCIBLE_TO_2_COLOR);
-
-    if ((w > 32) || (h > 32) || (w & (w - 1)) || (h & (h - 1)))
-        return FALSE;
-
-    dwords = ((w * pPixmap->drawable.bitsPerPixel) + 31) >> 5;
-    i = (h > 8) ? 8 : h;
-
-    if (w > 8) {
-        IntPtr = (CARD32 *) pPixmap->devPrivate.ptr;
-        switch (pPixmap->drawable.bitsPerPixel) {
-        case 8:
-            while (i--) {
-                for (j = 2; j < dwords; j++)
-                    if (IntPtr[j] != IntPtr[j & 0x01])
-                        return FALSE;
-                IntPtr += pitch;
-            }
-            break;
-        case 16:
-            while (i--) {
-                for (j = 4; j < dwords; j++)
-                    if (IntPtr[j] != IntPtr[j & 0x03])
-                        return FALSE;
-                IntPtr += pitch;
-            }
-            break;
-        case 24:
-            while (i--) {
-                for (j = 6; j < dwords; j++)
-                    if (IntPtr[j] != IntPtr[j % 6])
-                        return FALSE;
-                IntPtr += pitch;
-            }
-            break;
-        case 32:
-            while (i--) {
-                for (j = 8; j < dwords; j++)
-                    if (IntPtr[j] != IntPtr[j & 0x07])
-                        return FALSE;
-                IntPtr += pitch;
-            }
-            break;
-        default:
-            return FALSE;
-        }
-
-    }
-
-    if (h == 32) {
-        CARD32 *IntPtr2, *IntPtr3, *IntPtr4;
-
-        i = 8;
-        IntPtr = (CARD32 *) pPixmap->devPrivate.ptr;
-        IntPtr2 = IntPtr + (pitch << 3);
-        IntPtr3 = IntPtr2 + (pitch << 3);
-        IntPtr4 = IntPtr3 + (pitch << 3);
-        while (i--) {
-            for (j = 0; j < dwords; j++)
-                if ((IntPtr[j] != IntPtr2[j]) || (IntPtr[j] != IntPtr3[j]) ||
-                    (IntPtr[j] != IntPtr4[j]))
-                    return FALSE;
-            IntPtr += pitch;
-            IntPtr2 += pitch;
-            IntPtr3 += pitch;
-            IntPtr4 += pitch;
-        }
-    }
-    else if (h == 16) {
-        CARD32 *IntPtr2;
-
-        i = 8;
-        IntPtr = (CARD32 *) pPixmap->devPrivate.ptr;
-        IntPtr2 = IntPtr + (pitch << 3);
-        while (i--) {
-            for (j = 0; j < dwords; j++)
-                if (IntPtr[j] != IntPtr2[j])
-                    return FALSE;
-            IntPtr += pitch;
-            IntPtr2 += pitch;
-        }
-    }
-
-    pPriv->flags |= REDUCIBLE_TO_8x8;
-
-    if (checkMono) {
-        XAAInfoRecPtr infoRec =
-            GET_XAAINFORECPTR_FROM_DRAWABLE(&pPixmap->drawable);
-        unsigned char bits[8];
-        int fg, bg = -1, x, y;
-
-        i = (h > 8) ? 8 : h;
-        j = (w > 8) ? 8 : w;
-
-        if (pPixmap->drawable.bitsPerPixel == 8) {
-            unsigned char *srcp = pPixmap->devPrivate.ptr;
-
-            fg = srcp[0];
-            pitch = pPixmap->devKind;
-            for (y = 0; y < i; y++) {
-                bits[y] = 0;
-                for (x = 0; x < j; x++) {
-                    if (srcp[x] != fg) {
-                        if (bg == -1)
-                            bg = srcp[x];
-                        else if (bg != srcp[x])
-                            return TRUE;
-                    }
-                    else
-                        bits[y] |= 1 << x;
-                }
-                srcp += pitch;
-            }
-        }
-        else if (pPixmap->drawable.bitsPerPixel == 16) {
-            unsigned short *srcp = (unsigned short *) pPixmap->devPrivate.ptr;
-
-            fg = srcp[0];
-            pitch = pPixmap->devKind >> 1;
-            for (y = 0; y < i; y++) {
-                bits[y] = 0;
-                for (x = 0; x < j; x++) {
-                    if (srcp[x] != fg) {
-                        if (bg == -1)
-                            bg = srcp[x];
-                        else if (bg != srcp[x])
-                            return TRUE;
-                    }
-                    else
-                        bits[y] |= 1 << x;
-                }
-                srcp += pitch;
-            }
-        }
-        else if (pPixmap->drawable.bitsPerPixel == 24) {
-            CARD32 val;
-            unsigned char *srcp = pPixmap->devPrivate.ptr;
-
-            fg = *((CARD32 *) srcp) & 0x00FFFFFF;
-            pitch = pPixmap->devKind;
-            j *= 3;
-            for (y = 0; y < i; y++) {
-                bits[y] = 0;
-                for (x = 0; x < j; x += 3) {
-                    val = *((CARD32 *) (srcp + x)) & 0x00FFFFFF;
-                    if (val != fg) {
-                        if (bg == -1)
-                            bg = val;
-                        else if (bg != val)
-                            return TRUE;
-                    }
-                    else
-                        bits[y] |= 1 << (x / 3);
-                }
-                srcp += pitch;
-            }
-        }
-        else if (pPixmap->drawable.bitsPerPixel == 32) {
-            IntPtr = (CARD32 *) pPixmap->devPrivate.ptr;
-            fg = IntPtr[0];
-            for (y = 0; y < i; y++) {
-                bits[y] = 0;
-                for (x = 0; x < j; x++) {
-                    if (IntPtr[x] != fg) {
-                        if (bg == -1)
-                            bg = IntPtr[x];
-                        else if (bg != IntPtr[x])
-                            return TRUE;
-                    }
-                    else
-                        bits[y] |= 1 << x;
-                }
-                IntPtr += pitch;
-            }
-        }
-        else
-            return TRUE;
-
-        pPriv->fg = fg;
-        if (bg == -1)
-            pPriv->bg = fg;
-        else
-            pPriv->bg = bg;
-
-        if (h < 8) {
-            switch (h) {
-            case 1:
-                bits[1] = bits[0];
-            case 2:
-                bits[2] = bits[0];
-                bits[3] = bits[1];
-            case 4:
-                bits[4] = bits[0];
-                bits[5] = bits[1];
-                bits[6] = bits[2];
-                bits[7] = bits[3];
-                break;
-            }
-        }
-
-        pPriv->pattern0 =
-            bits[0] | (bits[1] << 8) | (bits[2] << 16) | (bits[3] << 24);
-        pPriv->pattern1 =
-            bits[4] | (bits[5] << 8) | (bits[6] << 16) | (bits[7] << 24);
-
-        if (w < 8) {
-            switch (w) {
-            case 1:
-                pPriv->pattern0 |= (pPriv->pattern0 << 1);
-                pPriv->pattern1 |= (pPriv->pattern1 << 1);
-            case 2:
-                pPriv->pattern0 |= (pPriv->pattern0 << 2);
-                pPriv->pattern1 |= (pPriv->pattern1 << 2);
-            case 4:
-                pPriv->pattern0 |= (pPriv->pattern0 << 4);
-                pPriv->pattern1 |= (pPriv->pattern1 << 4);
-            }
-        }
-        pPriv->flags |= REDUCIBLE_TO_2_COLOR;
-
-        if (infoRec->Mono8x8PatternFillFlags & BIT_ORDER_IN_BYTE_MSBFIRST) {
-            pPriv->pattern0 = SWAP_BITS_IN_BYTES(pPriv->pattern0);
-            pPriv->pattern1 = SWAP_BITS_IN_BYTES(pPriv->pattern1);
-        }
-
-    }
-
-    return TRUE;
-}
-
-void
-XAATileCache(ScrnInfoPtr pScrn, XAACacheInfoPtr pCache, int w, int h)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    (*infoRec->SetupForScreenToScreenCopy) (pScrn, 1, 1, GXcopy, ~0, -1);
-
-    while ((w << 1) <= pCache->w) {
-        (*infoRec->SubsequentScreenToScreenCopy) (pScrn, pCache->x, pCache->y,
-                                                  pCache->x + w, pCache->y, w,
-                                                  h);
-        w <<= 1;
-    }
-    if (w != pCache->w) {
-        (*infoRec->SubsequentScreenToScreenCopy) (pScrn, pCache->x, pCache->y,
-                                                  pCache->x + w, pCache->y,
-                                                  pCache->w - w, h);
-        w = pCache->w;
-    }
-
-    while ((h << 1) <= pCache->h) {
-        (*infoRec->SubsequentScreenToScreenCopy) (pScrn, pCache->x, pCache->y,
-                                                  pCache->x, pCache->y + h, w,
-                                                  h);
-        h <<= 1;
-    }
-    if (h != pCache->h) {
-        (*infoRec->SubsequentScreenToScreenCopy) (pScrn, pCache->x, pCache->y,
-                                                  pCache->x, pCache->y + h, w,
-                                                  pCache->h - h);
-    }
-    SET_SYNC_FLAG(infoRec);
-}
-
-XAACacheInfoPtr
-XAACacheTile(ScrnInfoPtr pScrn, PixmapPtr pPix)
-{
-    int w = pPix->drawable.width;
-    int h = pPix->drawable.height;
-    int size = max(w, h);
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    XAAPixmapCachePrivatePtr pCachePriv =
-        (XAAPixmapCachePrivatePtr) infoRec->PixmapCachePrivate;
-    XAACacheInfoPtr pCache, cacheRoot = NULL;
-    int i, max = 0;
-    int *current;
-
-    if (size <= 128) {
-        if (pCachePriv->Info128) {
-            cacheRoot = pCachePriv->Info128;
-            max = pCachePriv->Num128x128;
-            current = &pCachePriv->Current128;
-        }
-        else {
-            cacheRoot = pCachePriv->InfoPartial;
-            max = pCachePriv->NumPartial;
-            current = &pCachePriv->CurrentPartial;
-        }
-    }
-    else if (size <= 256) {
-        cacheRoot = pCachePriv->Info256;
-        max = pCachePriv->Num256x256;
-        current = &pCachePriv->Current256;
-    }
-    else if (size <= 512) {
-        cacheRoot = pCachePriv->Info512;
-        max = pCachePriv->Num512x512;
-        current = &pCachePriv->Current512;
-    }
-    else {                      /* something's wrong */
-        ErrorF("Something's wrong in XAACacheTile()\n");
-        return pCachePriv->Info128;
-    }
-
-    pCache = cacheRoot;
-
-    /* lets look for it */
-    for (i = 0; i < max; i++, pCache++) {
-        if (pCache->serialNumber == pPix->drawable.serialNumber) {
-            pCache->trans_color = -1;
-            return pCache;
-        }
-    }
-
-    pCache = &cacheRoot[(*current)++];
-    if (*current >= max)
-        *current = 0;
-
-    pCache->serialNumber = pPix->drawable.serialNumber;
-    pCache->trans_color = pCache->bg = pCache->fg = -1;
-    pCache->orig_w = w;
-    pCache->orig_h = h;
-    (*infoRec->WritePixmapToCache) (pScrn, pCache->x, pCache->y, w, h,
-                                    pPix->devPrivate.ptr, pPix->devKind,
-                                    pPix->drawable.bitsPerPixel,
-                                    pPix->drawable.depth);
-    if (!(infoRec->PixmapCacheFlags & DO_NOT_TILE_COLOR_DATA) &&
-        ((w != pCache->w) || (h != pCache->h)))
-        XAATileCache(pScrn, pCache, w, h);
-
-    return pCache;
-}
-
-XAACacheInfoPtr
-XAACacheMonoStipple(ScrnInfoPtr pScrn, PixmapPtr pPix)
-{
-    int w = pPix->drawable.width;
-    int h = pPix->drawable.height;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    XAAPixmapCachePrivatePtr pCachePriv =
-        (XAAPixmapCachePrivatePtr) infoRec->PixmapCachePrivate;
-    XAACacheInfoPtr pCache, cacheRoot = NULL;
-    int i, max = 0, funcNo, pad, dwords, bpp = pScrn->bitsPerPixel;
-    int *current;
-    StippleScanlineProcPtr StippleFunc;
-    unsigned char *data, *srcPtr, *dstPtr;
-
-    if ((h <= 128) && (w <= 128 * bpp)) {
-        if (pCachePriv->Info128) {
-            cacheRoot = pCachePriv->Info128;
-            max = pCachePriv->Num128x128;
-            current = &pCachePriv->Current128;
-        }
-        else {
-            cacheRoot = pCachePriv->InfoPartial;
-            max = pCachePriv->NumPartial;
-            current = &pCachePriv->CurrentPartial;
-        }
-    }
-    else if ((h <= 256) && (w <= 256 * bpp)) {
-        cacheRoot = pCachePriv->Info256;
-        max = pCachePriv->Num256x256;
-        current = &pCachePriv->Current256;
-    }
-    else if ((h <= 512) && (w <= 526 * bpp)) {
-        cacheRoot = pCachePriv->Info512;
-        max = pCachePriv->Num512x512;
-        current = &pCachePriv->Current512;
-    }
-    else {                      /* something's wrong */
-        ErrorF("Something's wrong in XAACacheMonoStipple()\n");
-        return pCachePriv->Info128;
-    }
-
-    pCache = cacheRoot;
-
-    /* lets look for it */
-    for (i = 0; i < max; i++, pCache++) {
-        if ((pCache->serialNumber == pPix->drawable.serialNumber) &&
-            (pCache->fg == -1) && (pCache->bg == -1)) {
-            pCache->trans_color = -1;
-            return pCache;
-        }
-    }
-
-    pCache = &cacheRoot[(*current)++];
-    if (*current >= max)
-        *current = 0;
-
-    pCache->serialNumber = pPix->drawable.serialNumber;
-    pCache->trans_color = pCache->bg = pCache->fg = -1;
-    pCache->orig_w = w;
-    pCache->orig_h = h;
-
-    if (w <= 32) {
-        if (w & (w - 1))
-            funcNo = 1;
-        else
-            funcNo = 0;
-    }
-    else
-        funcNo = 2;
-
-    pad = BitmapBytePad(pCache->w * bpp);
-    dwords = bytes_to_int32(pad);
-    dstPtr = data = (unsigned char *) malloc(pad * pCache->h);
-    srcPtr = (unsigned char *) pPix->devPrivate.ptr;
-
-    if (infoRec->
-        ScreenToScreenColorExpandFillFlags & BIT_ORDER_IN_BYTE_MSBFIRST)
-        StippleFunc = XAAStippleScanlineFuncMSBFirst[funcNo];
-    else
-        StippleFunc = XAAStippleScanlineFuncLSBFirst[funcNo];
-
-    /* don't bother generating more than we'll ever use */
-    max = ((pScrn->displayWidth + w - 1) + 31) >> 5;
-    if (dwords > max)
-        dwords = max;
-
-    for (i = 0; i < h; i++) {
-        (*StippleFunc) ((CARD32 *) dstPtr, (CARD32 *) srcPtr, 0, w, dwords);
-        srcPtr += pPix->devKind;
-        dstPtr += pad;
-    }
-
-    while ((h << 1) <= pCache->h) {
-        memcpy(data + (pad * h), data, pad * h);
-        h <<= 1;
-    }
-
-    if (h < pCache->h)
-        memcpy(data + (pad * h), data, pad * (pCache->h - h));
-
-    (*infoRec->WritePixmapToCache) (pScrn, pCache->x, pCache->y, pCache->w,
-                                    pCache->h, data, pad, bpp, pScrn->depth);
-
-    free(data);
-
-    return pCache;
-}
-
-XAACacheInfoPtr
-XAACachePlanarMonoStipple(ScrnInfoPtr pScrn, PixmapPtr pPix)
-{
-    int w = pPix->drawable.width;
-    int h = pPix->drawable.height;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    XAAPixmapCachePrivatePtr pCachePriv =
-        (XAAPixmapCachePrivatePtr) infoRec->PixmapCachePrivate;
-    XAACacheInfoPtr pCache, cacheRoot = NULL;
-    int i, max = 0;
-    int *current;
-
-    if ((h <= 128) && (w <= 128)) {
-        if (pCachePriv->Info128) {
-            cacheRoot = pCachePriv->Info128;
-            max = pCachePriv->Num128x128;
-            current = &pCachePriv->Current128;
-        }
-        else {
-            cacheRoot = pCachePriv->InfoPartial;
-            max = pCachePriv->NumPartial;
-            current = &pCachePriv->CurrentPartial;
-        }
-    }
-    else if ((h <= 256) && (w <= 256)) {
-        cacheRoot = pCachePriv->Info256;
-        max = pCachePriv->Num256x256;
-        current = &pCachePriv->Current256;
-    }
-    else if ((h <= 512) && (w <= 526)) {
-        cacheRoot = pCachePriv->Info512;
-        max = pCachePriv->Num512x512;
-        current = &pCachePriv->Current512;
-    }
-    else {                      /* something's wrong */
-        ErrorF("Something's wrong in XAACachePlanarMonoStipple()\n");
-        return pCachePriv->Info128;
-    }
-
-    pCache = cacheRoot;
-
-    /* lets look for it */
-    for (i = 0; i < max; i++, pCache++) {
-        if ((pCache->serialNumber == pPix->drawable.serialNumber) &&
-            (pCache->fg == -1) && (pCache->bg == -1)) {
-            pCache->trans_color = -1;
-            return pCache;
-        }
-    }
-
-    pCache = &cacheRoot[(*current)++];
-    if (*current >= max)
-        *current = 0;
-
-    pCache->serialNumber = pPix->drawable.serialNumber;
-    pCache->trans_color = pCache->bg = pCache->fg = -1;
-    pCache->orig_w = w;
-    pCache->orig_h = h;
-
-    /* Plane 0 holds the stipple. Plane 1 holds the inverted stipple */
-    (*infoRec->WriteBitmapToCache) (pScrn, pCache->x, pCache->y,
-                                    pPix->drawable.width, pPix->drawable.height,
-                                    pPix->devPrivate.ptr, pPix->devKind, 1, 2);
-    if (!(infoRec->PixmapCacheFlags & DO_NOT_TILE_MONO_DATA) &&
-        ((w != pCache->w) || (h != pCache->h)))
-        XAATileCache(pScrn, pCache, w, h);
-
-    return pCache;
-}
-
-XAACachePlanarMonoStippleProc
-XAAGetCachePlanarMonoStipple(void)
-{
-    return XAACachePlanarMonoStipple;
-}
-
-XAACacheInfoPtr
-XAACacheStipple(ScrnInfoPtr pScrn, PixmapPtr pPix, int fg, int bg)
-{
-    int w = pPix->drawable.width;
-    int h = pPix->drawable.height;
-    int size = max(w, h);
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    XAAPixmapCachePrivatePtr pCachePriv =
-        (XAAPixmapCachePrivatePtr) infoRec->PixmapCachePrivate;
-    XAACacheInfoPtr pCache, cacheRoot = NULL;
-    int i, max = 0;
-    int *current;
-
-    if (size <= 128) {
-        if (pCachePriv->Info128) {
-            cacheRoot = pCachePriv->Info128;
-            max = pCachePriv->Num128x128;
-            current = &pCachePriv->Current128;
-        }
-        else {
-            cacheRoot = pCachePriv->InfoPartial;
-            max = pCachePriv->NumPartial;
-            current = &pCachePriv->CurrentPartial;
-        }
-    }
-    else if (size <= 256) {
-        cacheRoot = pCachePriv->Info256;
-        max = pCachePriv->Num256x256;
-        current = &pCachePriv->Current256;
-    }
-    else if (size <= 512) {
-        cacheRoot = pCachePriv->Info512;
-        max = pCachePriv->Num512x512;
-        current = &pCachePriv->Current512;
-    }
-    else {                      /* something's wrong */
-        ErrorF("Something's wrong in XAACacheStipple()\n");
-        return pCachePriv->Info128;
-    }
-
-    pCache = cacheRoot;
-    /* lets look for it */
-    if (bg == -1)
-        for (i = 0; i < max; i++, pCache++) {
-            if ((pCache->serialNumber == pPix->drawable.serialNumber) &&
-                (fg == pCache->fg) && (pCache->fg != pCache->bg)) {
-                pCache->trans_color = pCache->bg;
-                return pCache;
-            }
-        }
-    else
-        for (i = 0; i < max; i++, pCache++) {
-            if ((pCache->serialNumber == pPix->drawable.serialNumber) &&
-                (fg == pCache->fg) && (bg == pCache->bg)) {
-                pCache->trans_color = -1;
-                return pCache;
-            }
-        }
-
-    pCache = &cacheRoot[(*current)++];
-    if (*current >= max)
-        *current = 0;
-
-    pCache->serialNumber = pPix->drawable.serialNumber;
-    pCache->fg = fg;
-    if (bg == -1)
-        pCache->trans_color = bg = fg ^ 1;
-    else
-        pCache->trans_color = -1;
-    pCache->bg = bg;
-
-    pCache->orig_w = w;
-    pCache->orig_h = h;
-    (*infoRec->WriteBitmapToCache) (pScrn, pCache->x, pCache->y,
-                                    pPix->drawable.width, pPix->drawable.height,
-                                    pPix->devPrivate.ptr, pPix->devKind, fg,
-                                    bg);
-    if (!(infoRec->PixmapCacheFlags & DO_NOT_TILE_COLOR_DATA) &&
-        ((w != pCache->w) || (h != pCache->h)))
-        XAATileCache(pScrn, pCache, w, h);
-
-    return pCache;
-}
-
-XAACacheInfoPtr
-XAACacheMono8x8Pattern(ScrnInfoPtr pScrn, int pat0, int pat1)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    XAAPixmapCachePrivatePtr pCachePriv =
-        (XAAPixmapCachePrivatePtr) infoRec->PixmapCachePrivate;
-    XAACacheInfoPtr pCache = pCachePriv->InfoMono;
-    int i;
-
-    for (i = 0; i < pCachePriv->NumMono; i++, pCache++) {
-        if (pCache->serialNumber &&
-            (pCache->pat0 == pat0) && (pCache->pat1 == pat1))
-            return pCache;
-    }
-
-    /* OK, let's cache it */
-    pCache = &pCachePriv->InfoMono[pCachePriv->CurrentMono++];
-    if (pCachePriv->CurrentMono >= pCachePriv->NumMono)
-        pCachePriv->CurrentMono = 0;
-
-    pCache->serialNumber = 1;   /* we don't care since we do lookups by pattern */
-    pCache->pat0 = pat0;
-    pCache->pat1 = pat1;
-
-    (*infoRec->WriteMono8x8PatternToCache) (pScrn, pCache);
-
-    return pCache;
-}
-
-XAACacheInfoPtr
-XAACacheColor8x8Pattern(ScrnInfoPtr pScrn, PixmapPtr pPix, int fg, int bg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    XAAPixmapCachePrivatePtr pCachePriv =
-        (XAAPixmapCachePrivatePtr) infoRec->PixmapCachePrivate;
-    XAACacheInfoPtr pCache = pCachePriv->InfoColor;
-    XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
-    int i;
-
-    if (!(pixPriv->flags & REDUCIBLE_TO_2_COLOR)) {
-        for (i = 0; i < pCachePriv->NumColor; i++, pCache++) {
-            if (pCache->serialNumber == pPix->drawable.serialNumber) {
-                pCache->trans_color = -1;
-                return pCache;
-            }
-        }
-        pCache = &pCachePriv->InfoColor[pCachePriv->CurrentColor++];
-        if (pCachePriv->CurrentColor >= pCachePriv->NumColor)
-            pCachePriv->CurrentColor = 0;
-
-        pCache->serialNumber = pPix->drawable.serialNumber;
-        pCache->trans_color = pCache->fg = pCache->bg = -1;
-    }
-    else {
-        int pat0 = pixPriv->pattern0;
-        int pat1 = pixPriv->pattern1;
-
-        if (fg == -1) {         /* it's a tile */
-            fg = pixPriv->fg;
-            bg = pixPriv->bg;
-        }
-
-        if (bg == -1) {         /* stipple */
-            for (i = 0; i < pCachePriv->NumColor; i++, pCache++) {
-                if (pCache->serialNumber &&
-                    (pCache->pat0 == pat0) && (pCache->pat1 == pat1) &&
-                    (pCache->fg == fg) && (pCache->bg != fg)) {
-                    pCache->trans_color = pCache->bg;
-                    return pCache;
-                }
-            }
-        }
-        else {                  /* opaque stipple */
-            for (i = 0; i < pCachePriv->NumColor; i++, pCache++) {
-                if (pCache->serialNumber &&
-                    (pCache->pat0 == pat0) && (pCache->pat1 == pat1) &&
-                    (pCache->fg == fg) && (pCache->bg == bg)) {
-                    pCache->trans_color = -1;
-                    return pCache;
-                }
-            }
-        }
-        pCache = &pCachePriv->InfoColor[pCachePriv->CurrentColor++];
-        if (pCachePriv->CurrentColor >= pCachePriv->NumColor)
-            pCachePriv->CurrentColor = 0;
-
-        if (bg == -1)
-            pCache->trans_color = bg = fg ^ 1;
-        else
-            pCache->trans_color = -1;
-
-        pCache->pat0 = pat0;
-        pCache->pat1 = pat1;
-        pCache->fg = fg;
-        pCache->bg = bg;
-        pCache->serialNumber = 1;
-    }
-
-    (*infoRec->WriteColor8x8PatternToCache) (pScrn, pPix, pCache);
-
-    return pCache;
-}
-
-void
-XAAWriteBitmapToCache(ScrnInfoPtr pScrn,
-                      int x, int y, int w, int h,
-                      unsigned char *src, int srcwidth, int fg, int bg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    (*infoRec->WriteBitmap) (pScrn, x, y, w, h, src, srcwidth,
-                             0, fg, bg, GXcopy, ~0);
-}
-
-void
-XAAWriteBitmapToCacheLinear(ScrnInfoPtr pScrn,
-                            int x, int y, int w, int h,
-                            unsigned char *src, int srcwidth, int fg, int bg)
-{
-    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
-    PixmapPtr pScreenPix, pDstPix;
-    ChangeGCVal gcvals[2];
-    GCPtr pGC;
-
-    pScreenPix = (*pScreen->GetScreenPixmap) (pScreen);
-
-    pDstPix = GetScratchPixmapHeader(pScreen, pScreenPix->drawable.width,
-                                     y + h, pScreenPix->drawable.depth,
-                                     pScreenPix->drawable.bitsPerPixel,
-                                     pScreenPix->devKind,
-                                     pScreenPix->devPrivate.ptr);
-
-    pGC = GetScratchGC(pScreenPix->drawable.depth, pScreen);
-    gcvals[0].val = fg;
-    gcvals[1].val = bg;
-    ChangeGC(NullClient, pGC, GCForeground | GCBackground, gcvals);
-    ValidateGC((DrawablePtr) pDstPix, pGC);
-
-    /* We've unwrapped already so these ops miss a sync */
-    SYNC_CHECK(pScrn);
-
-    (*pGC->ops->PutImage) ((DrawablePtr) pDstPix, pGC, 1, x, y, w, h, 0,
-                           XYBitmap, (pointer) src);
-
-    FreeScratchGC(pGC);
-    FreeScratchPixmapHeader(pDstPix);
-}
-
-void
-XAAWritePixmapToCache(ScrnInfoPtr pScrn,
-                      int x, int y, int w, int h,
-                      unsigned char *src, int srcwidth, int bpp, int depth)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    (*infoRec->WritePixmap) (pScrn, x, y, w, h, src, srcwidth,
-                             GXcopy, ~0, -1, bpp, depth);
-}
-
-void
-XAAWritePixmapToCacheLinear(ScrnInfoPtr pScrn,
-                            int x, int y, int w, int h,
-                            unsigned char *src,
-                            int srcwidth, int bpp, int depth)
-{
-    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
-    PixmapPtr pScreenPix, pDstPix;
-    GCPtr pGC;
-
-    pScreenPix = (*pScreen->GetScreenPixmap) (pScreen);
-
-    pDstPix = GetScratchPixmapHeader(pScreen, x + w, y + h,
-                                     depth, bpp, pScreenPix->devKind,
-                                     pScreenPix->devPrivate.ptr);
-
-    pGC = GetScratchGC(depth, pScreen);
-    ValidateGC((DrawablePtr) pDstPix, pGC);
-
-    /* We've unwrapped already so these ops miss a sync */
-    SYNC_CHECK(pScrn);
-
-    if (bpp == BitsPerPixel(depth))
-        (*pGC->ops->PutImage) ((DrawablePtr) pDstPix, pGC, depth, x, y, w,
-                               h, 0, ZPixmap, (pointer) src);
-    else {
-        PixmapPtr pSrcPix;
-
-        pSrcPix = GetScratchPixmapHeader(pScreen, w, h, depth, bpp,
-                                         srcwidth, (pointer) src);
-
-        (*pGC->ops->CopyArea) ((DrawablePtr) pSrcPix, (DrawablePtr) pDstPix,
-                               pGC, 0, 0, w, h, x, y);
-
-        FreeScratchPixmapHeader(pSrcPix);
-    }
-
-    FreeScratchGC(pGC);
-    FreeScratchPixmapHeader(pDstPix);
-}
-
-void
-XAAWriteMono8x8PatternToCache(ScrnInfoPtr pScrn, XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    XAAPixmapCachePrivatePtr pCachePriv =
-        (XAAPixmapCachePrivatePtr) infoRec->PixmapCachePrivate;
-    unsigned char *data;
-    int pad, Bpp = (pScrn->bitsPerPixel >> 3);
-
-    pCache->offsets = pCachePriv->MonoOffsets;
-
-    pad = BitmapBytePad(pCache->w * pScrn->bitsPerPixel);
-
-    data = (unsigned char *) malloc(pad * pCache->h);
-    if (!data)
-        return;
-
-    if (infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_ORIGIN) {
-        CARD32 *ptr = (CARD32 *) data;
-
-        ptr[0] = pCache->pat0;
-        ptr[1] = pCache->pat1;
-    }
-    else {
-        CARD32 *ptr;
-        DDXPointPtr pPoint = pCache->offsets;
-        int patx, paty, i;
-
-        for (i = 0; i < 64; i++, pPoint++) {
-            patx = pCache->pat0;
-            paty = pCache->pat1;
-            XAARotateMonoPattern(&patx, &paty, i & 0x07, i >> 3,
-                                 (infoRec->Mono8x8PatternFillFlags &
-                                  BIT_ORDER_IN_BYTE_MSBFIRST));
-            ptr = (CARD32 *) (data + (pad * pPoint->y) + (Bpp * pPoint->x));
-            ptr[0] = patx;
-            ptr[1] = paty;
-        }
-    }
-
-    (*infoRec->WritePixmapToCache) (pScrn, pCache->x, pCache->y,
-                                    pCache->w, pCache->h, data, pad,
-                                    pScrn->bitsPerPixel, pScrn->depth);
-
-    free(data);
-}
-
-void
-XAAWriteColor8x8PatternToCache(ScrnInfoPtr pScrn,
-                               PixmapPtr pPix, XAACacheInfoPtr pCache)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE(pPix);
-    XAAPixmapCachePrivatePtr pCachePriv =
-        (XAAPixmapCachePrivatePtr) infoRec->PixmapCachePrivate;
-    int pad, i, w, h, nw, nh, Bpp;
-    unsigned char *data, *srcPtr, *dstPtr;
-
-    pCache->offsets = pCachePriv->ColorOffsets;
-
-    if (pixPriv->flags & REDUCIBLE_TO_2_COLOR) {
-        CARD32 *ptr;
-
-        pad = BitmapBytePad(pCache->w);
-        data = (unsigned char *) malloc(pad * pCache->h);
-        if (!data)
-            return;
-
-        if (infoRec->Color8x8PatternFillFlags &
-            HARDWARE_PATTERN_PROGRAMMED_ORIGIN) {
-            ptr = (CARD32 *) data;
-            ptr[0] = pCache->pat0;
-            ptr[1] = pCache->pat1;
-        }
-        else {
-            int patx, paty;
-
-            ptr = (CARD32 *) data;
-            ptr[0] = ptr[2] = pCache->pat0;
-            ptr[1] = ptr[3] = pCache->pat1;
-            for (i = 1; i < 8; i++) {
-                patx = pCache->pat0;
-                paty = pCache->pat1;
-                XAARotateMonoPattern(&patx, &paty, i, 0,
-                                     (infoRec->Mono8x8PatternFillFlags &
-                                      BIT_ORDER_IN_BYTE_MSBFIRST));
-                ptr = (CARD32 *) (data + (pad * i));
-                ptr[0] = ptr[2] = patx;
-                ptr[1] = ptr[3] = paty;
-            }
-        }
-
-        (*infoRec->WriteBitmapToCache) (pScrn, pCache->x, pCache->y,
-                                        pCache->w, pCache->h, data, pad,
-                                        pCache->fg, pCache->bg);
-
-        free(data);
-        return;
-    }
-
-    Bpp = pScrn->bitsPerPixel >> 3;
-    h = min(8, pPix->drawable.height);
-    w = min(8, pPix->drawable.width);
-    pad = BitmapBytePad(pCache->w * pScrn->bitsPerPixel);
-
-    data = (unsigned char *) malloc(pad * pCache->h);
-    if (!data)
-        return;
-
-    /* Write and expand horizontally. */
-    for (i = h, dstPtr = data, srcPtr = pPix->devPrivate.ptr; i--;
-         srcPtr += pPix->devKind, dstPtr += pScrn->bitsPerPixel) {
-        nw = w;
-        memcpy(dstPtr, srcPtr, w * Bpp);
-        while (nw != 8) {
-            memcpy(dstPtr + (nw * Bpp), dstPtr, nw * Bpp);
-            nw <<= 1;
-        }
-    }
-    nh = h;
-    /* Expand vertically. */
-    while (nh != 8) {
-        memcpy(data + (nh * pScrn->bitsPerPixel), data,
-               nh * pScrn->bitsPerPixel);
-        nh <<= 1;
-    }
-
-    if (!(infoRec->Color8x8PatternFillFlags &
-          HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-        int j;
-        unsigned char *ptr = data + (128 * Bpp);
-
-        memcpy(data + (64 * Bpp), data, 64 * Bpp);
-        for (i = 1; i < 8; i++, ptr += (128 * Bpp)) {
-            for (j = 0; j < 8; j++) {
-                memcpy(ptr + (j * 8) * Bpp, data + (j * 8 + i) * Bpp,
-                       (8 - i) * Bpp);
-                memcpy(ptr + (j * 8 + 8 - i) * Bpp, data + j * 8 * Bpp,
-                       i * Bpp);
-            }
-            memcpy(ptr + (64 * Bpp), ptr, 64 * Bpp);
-        }
-    }
-
-    (*infoRec->WritePixmapToCache) (pScrn, pCache->x, pCache->y,
-                                    pCache->w, pCache->h, data, pad,
-                                    pScrn->bitsPerPixel, pScrn->depth);
-
-    free(data);
-}
-
-int
-XAAStippledFillChooser(GCPtr pGC)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    PixmapPtr pPixmap = pGC->stipple;
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPixmap);
-
-    if (!(pPriv->flags & REDUCIBILITY_CHECKED) &&
-        (infoRec->CanDoMono8x8 || infoRec->CanDoColor8x8)) {
-        XAACheckStippleReducibility(pPixmap);
-    }
-
-    if (pPriv->flags & REDUCIBLE_TO_8x8) {
-        if (infoRec->CanDoMono8x8 &&
-            !(infoRec->FillMono8x8PatternSpansFlags & NO_TRANSPARENCY) &&
-            ((pGC->alu == GXcopy) || !(infoRec->FillMono8x8PatternSpansFlags &
-                                       TRANSPARENCY_GXCOPY_ONLY)) &&
-            CHECK_ROP(pGC, infoRec->FillMono8x8PatternSpansFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->FillMono8x8PatternSpansFlags) &&
-            CHECK_FG(pGC, infoRec->FillMono8x8PatternSpansFlags) &&
-            CHECK_PLANEMASK(pGC, infoRec->FillMono8x8PatternSpansFlags)) {
-
-            return DO_MONO_8x8;
-        }
-
-        if (infoRec->CanDoColor8x8 &&
-            !(infoRec->FillColor8x8PatternSpansFlags & NO_TRANSPARENCY) &&
-            ((pGC->alu == GXcopy) || !(infoRec->FillColor8x8PatternSpansFlags &
-                                       TRANSPARENCY_GXCOPY_ONLY)) &&
-            CHECK_ROP(pGC, infoRec->FillColor8x8PatternSpansFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->FillColor8x8PatternSpansFlags) &&
-            CHECK_PLANEMASK(pGC, infoRec->FillColor8x8PatternSpansFlags)) {
-
-            return DO_COLOR_8x8;
-        }
-    }
-
-    if (infoRec->UsingPixmapCache && infoRec->FillCacheExpandSpans &&
-        (pPixmap->drawable.height <= infoRec->MaxCacheableStippleHeight) &&
-        (pPixmap->drawable.width <= infoRec->MaxCacheableStippleWidth /
-         infoRec->CacheColorExpandDensity) &&
-        !(infoRec->FillCacheExpandSpansFlags & NO_TRANSPARENCY) &&
-        ((pGC->alu == GXcopy) || !(infoRec->FillCacheExpandSpansFlags &
-                                   TRANSPARENCY_GXCOPY_ONLY)) &&
-        CHECK_ROP(pGC, infoRec->FillCacheExpandSpansFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->FillCacheExpandSpansFlags) &&
-        CHECK_FG(pGC, infoRec->FillCacheExpandSpansFlags) &&
-        CHECK_PLANEMASK(pGC, infoRec->FillCacheExpandSpansFlags)) {
-
-        return DO_CACHE_EXPAND;
-    }
-
-    if (infoRec->UsingPixmapCache &&
-        !(infoRec->PixmapCacheFlags & DO_NOT_BLIT_STIPPLES) &&
-        infoRec->FillCacheBltSpans &&
-        (pPixmap->drawable.height <= infoRec->MaxCacheableTileHeight) &&
-        (pPixmap->drawable.width <= infoRec->MaxCacheableTileWidth) &&
-        !(infoRec->FillCacheBltSpansFlags & NO_TRANSPARENCY) &&
-        ((pGC->alu == GXcopy) || !(infoRec->FillCacheBltSpansFlags &
-                                   TRANSPARENCY_GXCOPY_ONLY)) &&
-        CHECK_ROP(pGC, infoRec->FillCacheBltSpansFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->FillCacheBltSpansFlags) &&
-        CHECK_PLANEMASK(pGC, infoRec->FillCacheBltSpansFlags)) {
-
-        return DO_CACHE_BLT;
-    }
-
-    if (infoRec->FillColorExpandSpans &&
-        !(infoRec->FillColorExpandSpansFlags & NO_TRANSPARENCY) &&
-        ((pGC->alu == GXcopy) || !(infoRec->FillColorExpandSpansFlags &
-                                   TRANSPARENCY_GXCOPY_ONLY)) &&
-        CHECK_ROP(pGC, infoRec->FillColorExpandSpansFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->FillColorExpandSpansFlags) &&
-        CHECK_FG(pGC, infoRec->FillColorExpandSpansFlags) &&
-        CHECK_PLANEMASK(pGC, infoRec->FillColorExpandSpansFlags)) {
-
-        return DO_COLOR_EXPAND;
-    }
-
-    return 0;
-}
-
-int
-XAAOpaqueStippledFillChooser(GCPtr pGC)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    PixmapPtr pPixmap = pGC->stipple;
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPixmap);
-
-    if (XAA_DEPTH_BUG(pGC))
-        return 0;
-
-    if (!(pPriv->flags & REDUCIBILITY_CHECKED) &&
-        (infoRec->CanDoMono8x8 || infoRec->CanDoColor8x8)) {
-        XAACheckStippleReducibility(pPixmap);
-    }
-
-    if (pPriv->flags & REDUCIBLE_TO_8x8) {
-        if (infoRec->CanDoMono8x8 &&
-            !(infoRec->FillMono8x8PatternSpansFlags & TRANSPARENCY_ONLY) &&
-            CHECK_ROP(pGC, infoRec->FillMono8x8PatternSpansFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->FillMono8x8PatternSpansFlags) &&
-            CHECK_COLORS(pGC, infoRec->FillMono8x8PatternSpansFlags) &&
-            CHECK_PLANEMASK(pGC, infoRec->FillMono8x8PatternSpansFlags)) {
-
-            return DO_MONO_8x8;
-        }
-
-        if (infoRec->CanDoColor8x8 &&
-            CHECK_ROP(pGC, infoRec->FillColor8x8PatternSpansFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->FillColor8x8PatternSpansFlags) &&
-            CHECK_PLANEMASK(pGC, infoRec->FillColor8x8PatternSpansFlags)) {
-
-            return DO_COLOR_8x8;
-        }
-    }
-
-    if (infoRec->UsingPixmapCache && infoRec->FillCacheExpandSpans &&
-        (pPixmap->drawable.height <= infoRec->MaxCacheableStippleHeight) &&
-        (pPixmap->drawable.width <= infoRec->MaxCacheableStippleWidth /
-         infoRec->CacheColorExpandDensity) &&
-        !(infoRec->FillCacheExpandSpansFlags & TRANSPARENCY_ONLY) &&
-        CHECK_ROP(pGC, infoRec->FillCacheExpandSpansFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->FillCacheExpandSpansFlags) &&
-        CHECK_COLORS(pGC, infoRec->FillCacheExpandSpansFlags) &&
-        CHECK_PLANEMASK(pGC, infoRec->FillCacheExpandSpansFlags)) {
-
-        return DO_CACHE_EXPAND;
-    }
-
-    if (infoRec->UsingPixmapCache &&
-        !(infoRec->PixmapCacheFlags & DO_NOT_BLIT_STIPPLES) &&
-        infoRec->FillCacheBltSpans &&
-        (pPixmap->drawable.height <= infoRec->MaxCacheableTileHeight) &&
-        (pPixmap->drawable.width <= infoRec->MaxCacheableTileWidth) &&
-        CHECK_ROP(pGC, infoRec->FillCacheBltSpansFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->FillCacheBltSpansFlags) &&
-        CHECK_PLANEMASK(pGC, infoRec->FillCacheBltSpansFlags)) {
-
-        return DO_CACHE_BLT;
-    }
-
-    if (infoRec->FillColorExpandSpans &&
-        !(infoRec->FillColorExpandSpansFlags & TRANSPARENCY_ONLY) &&
-        CHECK_ROP(pGC, infoRec->FillColorExpandSpansFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->FillColorExpandSpansFlags) &&
-        CHECK_COLORS(pGC, infoRec->FillColorExpandSpansFlags) &&
-        CHECK_PLANEMASK(pGC, infoRec->FillColorExpandSpansFlags)) {
-
-        return DO_COLOR_EXPAND;
-    }
-
-    return 0;
-}
-
-int
-XAATiledFillChooser(GCPtr pGC)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    PixmapPtr pPixmap = pGC->tile.pixmap;
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pPixmap);
-
-    if (IS_OFFSCREEN_PIXMAP(pPixmap) && infoRec->FillCacheBltSpans &&
-        CHECK_ROP(pGC, infoRec->FillCacheBltSpansFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->FillCacheBltSpansFlags) &&
-        CHECK_PLANEMASK(pGC, infoRec->FillCacheBltSpansFlags)) {
-
-        return DO_PIXMAP_COPY;
-    }
-
-    if (!(pPriv->flags & REDUCIBILITY_CHECKED) &&
-        (infoRec->CanDoMono8x8 || infoRec->CanDoColor8x8)) {
-        XAACheckTileReducibility(pPixmap, infoRec->CanDoMono8x8);
-    }
-
-    if (pPriv->flags & REDUCIBLE_TO_8x8) {
-        if ((pPriv->flags & REDUCIBLE_TO_2_COLOR) && infoRec->CanDoMono8x8 &&
-            !(infoRec->FillMono8x8PatternSpansFlags & TRANSPARENCY_ONLY) &&
-            CHECK_ROP(pGC, infoRec->FillMono8x8PatternSpansFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->FillMono8x8PatternSpansFlags) &&
-            (!(infoRec->FillMono8x8PatternSpansFlags & RGB_EQUAL) ||
-             (CHECK_RGB_EQUAL(pPriv->fg) && CHECK_RGB_EQUAL(pPriv->bg))) &&
-            CHECK_PLANEMASK(pGC, infoRec->FillMono8x8PatternSpansFlags)) {
-
-            return DO_MONO_8x8;
-        }
-
-        if (infoRec->CanDoColor8x8 &&
-            CHECK_ROP(pGC, infoRec->FillColor8x8PatternSpansFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->FillColor8x8PatternSpansFlags) &&
-            CHECK_PLANEMASK(pGC, infoRec->FillColor8x8PatternSpansFlags)) {
-
-            return DO_COLOR_8x8;
-        }
-    }
-
-    if (infoRec->UsingPixmapCache && infoRec->FillCacheBltSpans &&
-        (pPixmap->drawable.height <= infoRec->MaxCacheableTileHeight) &&
-        (pPixmap->drawable.width <= infoRec->MaxCacheableTileWidth) &&
-        CHECK_ROP(pGC, infoRec->FillCacheBltSpansFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->FillCacheBltSpansFlags) &&
-        CHECK_PLANEMASK(pGC, infoRec->FillCacheBltSpansFlags)) {
-
-        return DO_CACHE_BLT;
-    }
-
-    if (infoRec->FillImageWriteRects &&
-        CHECK_NO_GXCOPY(pGC, infoRec->FillImageWriteRectsFlags) &&
-        CHECK_ROP(pGC, infoRec->FillImageWriteRectsFlags) &&
-        CHECK_ROPSRC(pGC, infoRec->FillImageWriteRectsFlags) &&
-        CHECK_PLANEMASK(pGC, infoRec->FillImageWriteRectsFlags)) {
-
-        return DO_IMAGE_WRITE;
-    }
-
-    return 0;
-}
-
-static int RotateMasksX[8] = {
-    0xFFFFFFFF, 0x7F7F7F7F, 0x3F3F3F3F, 0x1F1F1F1F,
-    0x0F0F0F0F, 0x07070707, 0x03030303, 0x01010101
-};
-
-static int RotateMasksY[4] = {
-    0xFFFFFFFF, 0x00FFFFFF, 0x0000FFFF, 0x000000FF
-};
-
-void
-XAARotateMonoPattern(int *pat0, int *pat1, int xorg, int yorg, Bool msbfirst)
-{
-    int tmp, mask;
-
-    if (xorg) {
-        if (msbfirst)
-            xorg = 8 - xorg;
-        mask = RotateMasksX[xorg];
-        *pat0 = ((*pat0 >> xorg) & mask) | ((*pat0 << (8 - xorg)) & ~mask);
-        *pat1 = ((*pat1 >> xorg) & mask) | ((*pat1 << (8 - xorg)) & ~mask);
-    }
-    if (yorg >= 4) {
-        tmp = *pat0;
-        *pat0 = *pat1;
-        *pat1 = tmp;
-        yorg -= 4;
-    }
-    if (yorg) {
-        mask = RotateMasksY[yorg];
-        yorg <<= 3;
-        tmp = *pat0;
-        *pat0 = ((*pat0 >> yorg) & mask) | ((*pat1 << (32 - yorg)) & ~mask);
-        *pat1 = ((*pat1 >> yorg) & mask) | ((tmp << (32 - yorg)) & ~mask);
-    }
-}
-
-void
-XAAInvalidatePixmapCache(ScreenPtr pScreen)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    XAAPixmapCachePrivatePtr pCachePriv =
-        (XAAPixmapCachePrivatePtr) infoRec->PixmapCachePrivate;
-    int i;
-
-    if (!pCachePriv)
-        return;
-
-    for (i = 0; i < pCachePriv->Num512x512; i++)
-        (pCachePriv->Info512)[i].serialNumber = 0;
-    for (i = 0; i < pCachePriv->Num256x256; i++)
-        (pCachePriv->Info256)[i].serialNumber = 0;
-    for (i = 0; i < pCachePriv->Num128x128; i++)
-        (pCachePriv->Info128)[i].serialNumber = 0;
-    for (i = 0; i < pCachePriv->NumPartial; i++)
-        (pCachePriv->InfoPartial)[i].serialNumber = 0;
-    for (i = 0; i < pCachePriv->NumMono; i++)
-        (pCachePriv->InfoMono)[i].serialNumber = 0;
-    for (i = 0; i < pCachePriv->NumColor; i++)
-        (pCachePriv->InfoColor)[i].serialNumber = 0;
-}
diff --git a/hw/xfree86/xaa/xaaPict.c b/hw/xfree86/xaa/xaaPict.c
deleted file mode 100644
index 0721768..0000000
--- a/hw/xfree86/xaa/xaaPict.c
+++ /dev/null
@@ -1,654 +0,0 @@
-/*
- *
- * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
- *
- * 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 Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD 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_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <string.h>
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "windowstr.h"
-#include "xf86str.h"
-#include "mi.h"
-#include "picturestr.h"
-#include "glyphstr.h"
-#include "picture.h"
-#include "mipict.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaawrap.h"
-#include "xaacexp.h"
-#include "xf86fbman.h"
-#include "servermd.h"
-
-Bool
-XAAGetPixelFromRGBA(CARD32 *pixel,
-                    CARD16 red,
-                    CARD16 green, CARD16 blue, CARD16 alpha, CARD32 format)
-{
-    int rbits, bbits, gbits, abits;
-    int rshift, bshift, gshift, ashift;
-
-    *pixel = 0;
-
-    if (!PICT_FORMAT_COLOR(format))
-        return FALSE;
-
-    rbits = PICT_FORMAT_R(format);
-    gbits = PICT_FORMAT_G(format);
-    bbits = PICT_FORMAT_B(format);
-    abits = PICT_FORMAT_A(format);
-
-    if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ARGB) {
-        bshift = 0;
-        gshift = bbits;
-        rshift = gshift + gbits;
-        ashift = rshift + rbits;
-    }
-    else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
-        rshift = 0;
-        gshift = rbits;
-        bshift = gshift + gbits;
-        ashift = bshift + bbits;
-    }
-    else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
-        bshift = PICT_FORMAT_BPP(format) - bbits;
-        gshift = bshift - gbits;
-        rshift = gshift - rbits;
-        ashift = 0;
-    }
-    else
-        return FALSE;
-
-    *pixel |= (blue >> (16 - bbits)) << bshift;
-    *pixel |= (red >> (16 - rbits)) << rshift;
-    *pixel |= (green >> (16 - gbits)) << gshift;
-    *pixel |= (alpha >> (16 - abits)) << ashift;
-
-    return TRUE;
-}
-
-Bool
-XAAGetRGBAFromPixel(CARD32 pixel,
-                    CARD16 *red,
-                    CARD16 *green, CARD16 *blue, CARD16 *alpha, CARD32 format)
-{
-    int rbits, bbits, gbits, abits;
-    int rshift, bshift, gshift, ashift;
-
-    if (!PICT_FORMAT_COLOR(format))
-        return FALSE;
-
-    rbits = PICT_FORMAT_R(format);
-    gbits = PICT_FORMAT_G(format);
-    bbits = PICT_FORMAT_B(format);
-    abits = PICT_FORMAT_A(format);
-
-    if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ARGB) {
-        bshift = 0;
-        gshift = bbits;
-        rshift = gshift + gbits;
-        ashift = rshift + rbits;
-    }
-    else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_ABGR) {
-        rshift = 0;
-        gshift = rbits;
-        bshift = gshift + gbits;
-        ashift = bshift + bbits;
-    }
-    else if (PICT_FORMAT_TYPE(format) == PICT_TYPE_BGRA) {
-        bshift = PICT_FORMAT_BPP(format) - bbits;
-        gshift = bshift - gbits;
-        rshift = gshift - rbits;
-        ashift = 0;
-    }
-    else
-        return FALSE;
-
-    *red = ((pixel >> rshift) & ((1 << rbits) - 1)) << (16 - rbits);
-    while (rbits < 16) {
-        *red |= *red >> rbits;
-        rbits <<= 1;
-    }
-
-    *green = ((pixel >> gshift) & ((1 << gbits) - 1)) << (16 - gbits);
-    while (gbits < 16) {
-        *green |= *green >> gbits;
-        gbits <<= 1;
-    }
-
-    *blue = ((pixel >> bshift) & ((1 << bbits) - 1)) << (16 - bbits);
-    while (bbits < 16) {
-        *blue |= *blue >> bbits;
-        bbits <<= 1;
-    }
-
-    if (abits) {
-        *alpha = ((pixel >> ashift) & ((1 << abits) - 1)) << (16 - abits);
-        while (abits < 16) {
-            *alpha |= *alpha >> abits;
-            abits <<= 1;
-        }
-    }
-    else
-        *alpha = 0xffff;
-
-    return TRUE;
-}
-
-/* 8:8:8 + PICT_a8 -> 8:8:8:8 texture */
-
-void
-XAA_888_plus_PICT_a8_to_8888(CARD32 color, CARD8 *alphaPtr,     /* in bytes */
-                             int alphaPitch, CARD32 *dstPtr, int dstPitch,      /* in dwords */
-                             int width, int height)
-{
-    int x;
-
-    color &= 0x00ffffff;
-
-    while (height--) {
-        for (x = 0; x < width; x++)
-            dstPtr[x] = color | (alphaPtr[x] << 24);
-        dstPtr += dstPitch;
-        alphaPtr += alphaPitch;
-    }
-}
-
-#define DRAWABLE_IS_ON_CARD(pDraw) \
-    (pDraw->type == DRAWABLE_WINDOW || \
-     (pDraw->type == DRAWABLE_PIXMAP && IS_OFFSCREEN_PIXMAP(pDraw)))
-
-Bool
-XAADoComposite(CARD8 op,
-               PicturePtr pSrc,
-               PicturePtr pMask,
-               PicturePtr pDst,
-               INT16 xSrc,
-               INT16 ySrc,
-               INT16 xMask,
-               INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
-{
-    ScreenPtr pScreen = pDst->pDrawable->pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    RegionRec region;
-    CARD32 *formats, *dstformats;
-    int flags = 0;
-    BoxPtr pbox;
-    int nbox, w, h;
-
-    if (!RegionNumRects(pDst->pCompositeClip))
-        return TRUE;
-
-    if (!infoRec->pScrn->vtSema || !DRAWABLE_IS_ON_CARD(pDst->pDrawable))
-        return FALSE;
-
-    if (DRAWABLE_IS_ON_CARD(pSrc->pDrawable))
-        return FALSE;
-
-    if (pSrc->transform || (pMask && pMask->transform))
-        return FALSE;
-
-    if (pDst->alphaMap || pSrc->alphaMap || (pMask && pMask->alphaMap))
-        return FALSE;
-
-    if ((pSrc->repeat && pSrc->repeatType != RepeatNormal) ||
-        (pMask && pMask->repeat && pMask->repeatType != RepeatNormal)) {
-        return FALSE;
-    }
-
-    xDst += pDst->pDrawable->x;
-    yDst += pDst->pDrawable->y;
-    xSrc += pSrc->pDrawable->x;
-    ySrc += pSrc->pDrawable->y;
-
-    if (pMask) {
-        if (pMask->componentAlpha)
-            return FALSE;
-
-        /* for now we only do it if there is a 1x1 (solid) source */
-
-        if ((pSrc->pDrawable->width == 1) && (pSrc->pDrawable->height == 1)) {
-            CARD16 red, green, blue, alpha;
-            CARD32 pixel =
-                *((CARD32 *) (((PixmapPtr) (pSrc->pDrawable))->devPrivate.ptr));
-
-            if (!XAAGetRGBAFromPixel
-                (pixel, &red, &green, &blue, &alpha, pSrc->format))
-                return FALSE;
-
-            xMask += pMask->pDrawable->x;
-            yMask += pMask->pDrawable->y;
-
-            /* pull out color expandable operations here */
-            if ((pMask->format == PICT_a1) && (alpha == 0xffff) &&
-                (op == PictOpOver) && infoRec->WriteBitmap && !pMask->repeat &&
-                !(infoRec->WriteBitmapFlags & NO_TRANSPARENCY) &&
-                (!(infoRec->WriteBitmapFlags & RGB_EQUAL) ||
-                 ((red == green) && (green == blue)))) {
-                PixmapPtr pPix = (PixmapPtr) (pMask->pDrawable);
-                int skipleft;
-
-                if (!miComputeCompositeRegion(&region, pSrc, pMask, pDst,
-                                              xSrc, ySrc, xMask, yMask, xDst,
-                                              yDst, width, height))
-                    return TRUE;
-
-                nbox = RegionNumRects(&region);
-                pbox = RegionRects(&region);
-
-                if (!nbox)
-                    return TRUE;
-
-                XAAGetPixelFromRGBA(&pixel, red, green, blue, 0, pDst->format);
-
-                xMask -= xDst;
-                yMask -= yDst;
-
-                while (nbox--) {
-                    skipleft = pbox->x1 + xMask;
-
-                    (*infoRec->WriteBitmap) (infoRec->pScrn,
-                                             pbox->x1, pbox->y1,
-                                             pbox->x2 - pbox->x1,
-                                             pbox->y2 - pbox->y1,
-                                             (unsigned char *) (pPix->
-                                                                devPrivate.
-                                                                ptr) +
-                                             (pPix->devKind *
-                                              (pbox->y1 + yMask)) +
-                                             ((skipleft >> 3) & ~3),
-                                             pPix->devKind, skipleft & 31,
-                                             pixel, -1, GXcopy, ~0);
-                    pbox++;
-                }
-
-                /* WriteBitmap sets the Sync flag */
-                RegionUninit(&region);
-                return TRUE;
-            }
-
-            formats = infoRec->CPUToScreenAlphaTextureFormats;
-            dstformats = infoRec->CPUToScreenAlphaTextureDstFormats;
-            if (!formats || !dstformats)
-                return FALSE;
-
-            w = pMask->pDrawable->width;
-            h = pMask->pDrawable->height;
-
-            if (pMask->repeat) {
-                if ((infoRec->CPUToScreenAlphaTextureFlags & XAA_RENDER_NO_TILE)
-                    ||
-                    ((infoRec->
-                      CPUToScreenAlphaTextureFlags &
-                      XAA_RENDER_POWER_OF_2_TILE_ONLY) && ((h & (h - 1)) ||
-                                                           (w & (w - 1))))) {
-                    return FALSE;
-                }
-                flags |= XAA_RENDER_REPEAT;
-            }
-
-            if ((alpha != 0xffff) &&
-                (infoRec->
-                 CPUToScreenAlphaTextureFlags & XAA_RENDER_NO_SRC_ALPHA))
-                return FALSE;
-
-            while (*formats != pMask->format) {
-                if (!(*formats))
-                    return FALSE;
-                formats++;
-            }
-            while (*dstformats != pDst->format) {
-                if (!(*dstformats))
-                    return FALSE;
-                dstformats++;
-            }
-
-            if (!miComputeCompositeRegion(&region, pSrc, pMask, pDst,
-                                          xSrc, ySrc, xMask, yMask, xDst, yDst,
-                                          width, height))
-                return TRUE;
-
-            nbox = RegionNumRects(&region);
-            pbox = RegionRects(&region);
-
-            if (!nbox) {
-                RegionUninit(&region);
-                return TRUE;
-            }
-
-            if (!(infoRec->SetupForCPUToScreenAlphaTexture2) (infoRec->pScrn,
-                                                              op, red, green,
-                                                              blue, alpha,
-                                                              pMask->format,
-                                                              pDst->format,
-                                                              ((PixmapPtr)
-                                                               (pMask->
-                                                                pDrawable))->
-                                                              devPrivate.ptr,
-                                                              ((PixmapPtr)
-                                                               (pMask->
-                                                                pDrawable))->
-                                                              devKind, w, h,
-                                                              flags)) {
-                RegionUninit(&region);
-                return FALSE;
-            }
-
-            xMask -= xDst;
-            yMask -= yDst;
-
-            while (nbox--) {
-                (*infoRec->SubsequentCPUToScreenAlphaTexture) (infoRec->pScrn,
-                                                               pbox->x1,
-                                                               pbox->y1,
-                                                               pbox->x1 + xMask,
-                                                               pbox->y1 + yMask,
-                                                               pbox->x2 -
-                                                               pbox->x1,
-                                                               pbox->y2 -
-                                                               pbox->y1);
-                pbox++;
-            }
-
-            SET_SYNC_FLAG(infoRec);
-            RegionUninit(&region);
-            return TRUE;
-        }
-    }
-    else {
-        formats = infoRec->CPUToScreenTextureFormats;
-        dstformats = infoRec->CPUToScreenTextureDstFormats;
-        if (!formats || !dstformats)
-            return FALSE;
-
-        w = pSrc->pDrawable->width;
-        h = pSrc->pDrawable->height;
-
-        if (pSrc->repeat) {
-            if ((infoRec->CPUToScreenTextureFlags & XAA_RENDER_NO_TILE) ||
-                ((infoRec->CPUToScreenTextureFlags &
-                  XAA_RENDER_POWER_OF_2_TILE_ONLY) &&
-                 ((h & (h - 1)) || (w & (w - 1))))) {
-                return FALSE;
-            }
-            flags |= XAA_RENDER_REPEAT;
-        }
-
-        while (*formats != pSrc->format) {
-            if (!(*formats))
-                return FALSE;
-            formats++;
-        }
-        while (*dstformats != pDst->format) {
-            if (!(*dstformats))
-                return FALSE;
-            dstformats++;
-        }
-
-        if (!miComputeCompositeRegion(&region, pSrc, pMask, pDst,
-                                      xSrc, ySrc, xMask, yMask, xDst, yDst,
-                                      width, height))
-            return TRUE;
-
-        nbox = RegionNumRects(&region);
-        pbox = RegionRects(&region);
-
-        if (!nbox) {
-            RegionUninit(&region);
-            return TRUE;
-        }
-
-        if (!(infoRec->SetupForCPUToScreenTexture2) (infoRec->pScrn,
-                                                     op, pSrc->format,
-                                                     pDst->format,
-                                                     ((PixmapPtr)
-                                                      (pSrc->pDrawable))->
-                                                     devPrivate.ptr,
-                                                     ((PixmapPtr)
-                                                      (pSrc->pDrawable))->
-                                                     devKind, w, h, flags)) {
-            RegionUninit(&region);
-            return FALSE;
-        }
-
-        xSrc -= xDst;
-        ySrc -= yDst;
-
-        while (nbox--) {
-            (*infoRec->SubsequentCPUToScreenTexture) (infoRec->pScrn,
-                                                      pbox->x1, pbox->y1,
-                                                      pbox->x1 + xSrc,
-                                                      pbox->y1 + ySrc,
-                                                      pbox->x2 - pbox->x1,
-                                                      pbox->y2 - pbox->y1);
-            pbox++;
-        }
-
-        SET_SYNC_FLAG(infoRec);
-        RegionUninit(&region);
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-static void
-XAACompositeSrcCopy(PicturePtr pSrc,
-                    PicturePtr pDst,
-                    INT16 xSrc,
-                    INT16 ySrc,
-                    INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
-{
-    ScreenPtr pScreen = pDst->pDrawable->pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-    int i, nbox;
-    int xoff, yoff;
-    BoxPtr pbox;
-    DDXPointPtr pptSrc;
-    RegionRec region;
-
-    xDst += pDst->pDrawable->x;
-    yDst += pDst->pDrawable->y;
-    xSrc += pSrc->pDrawable->x;
-    ySrc += pSrc->pDrawable->y;
-
-    if (!miComputeCompositeRegion(&region, pSrc, NULL, pDst,
-                                  xSrc, ySrc, 0, 0, xDst, yDst, width, height))
-        return;
-
-    nbox = RegionNumRects(&region);
-    pbox = RegionRects(&region);
-
-    if (!nbox) {
-        RegionUninit(&region);
-        return;
-    }
-    pptSrc = malloc(sizeof(DDXPointRec) * nbox);
-    if (!pptSrc) {
-        RegionUninit(&region);
-        return;
-    }
-    xoff = xSrc - xDst;
-    yoff = ySrc - yDst;
-    for (i = 0; i < nbox; i++) {
-        pptSrc[i].x = pbox[i].x1 + xoff;
-        pptSrc[i].y = pbox[i].y1 + yoff;
-    }
-
-    infoRec->ScratchGC.planemask = ~0L;
-    infoRec->ScratchGC.alu = GXcopy;
-
-    XAADoBitBlt(pSrc->pDrawable, pDst->pDrawable, &infoRec->ScratchGC, &region,
-                pptSrc);
-
-    free(pptSrc);
-    RegionUninit(&region);
-    return;
-}
-
-void
-XAAComposite(CARD8 op,
-             PicturePtr pSrc,
-             PicturePtr pMask,
-             PicturePtr pDst,
-             INT16 xSrc,
-             INT16 ySrc,
-             INT16 xMask,
-             INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
-{
-    ScreenPtr pScreen = pDst->pDrawable->pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-
-    XAA_RENDER_PROLOGUE(pScreen, Composite);
-
-    if (!pMask && infoRec->pScrn->vtSema &&
-        infoRec->ScreenToScreenBitBlt &&
-        pSrc->pDrawable &&
-        DRAWABLE_IS_ON_CARD(pSrc->pDrawable) &&
-        DRAWABLE_IS_ON_CARD(pDst->pDrawable) &&
-        !pSrc->transform &&
-        (!pSrc->repeat || (xSrc >= 0 && ySrc >= 0 &&
-                           xSrc + width <= pSrc->pDrawable->width &&
-                           ySrc + height <= pSrc->pDrawable->height)) &&
-        ((op == PictOpSrc &&
-          ((pSrc->format == pDst->format) ||
-           (pSrc->format == PICT_a8r8g8b8 && pDst->format == PICT_x8r8g8b8) ||
-           (pSrc->format == PICT_a8b8g8r8 && pDst->format == PICT_x8b8g8r8))) ||
-         (op == PictOpOver && !pSrc->alphaMap && !pDst->alphaMap &&
-          pSrc->format == pDst->format &&
-          (pSrc->format == PICT_x8r8g8b8 || pSrc->format == PICT_x8b8g8r8)))) {
-        XAACompositeSrcCopy(pSrc, pDst, xSrc, ySrc, xDst, yDst, width, height);
-    }
-    else if (!pSrc->pDrawable || (pMask && !pMask->pDrawable) ||
-             !infoRec->Composite ||
-             !(*infoRec->Composite) (op, pSrc, pMask, pDst,
-                                     xSrc, ySrc, xMask, yMask, xDst, yDst,
-                                     width, height)) {
-        if (infoRec->pScrn->vtSema &&
-            ((pSrc->pDrawable &&
-              (pSrc->pDrawable->type == DRAWABLE_WINDOW ||
-               IS_OFFSCREEN_PIXMAP(pSrc->pDrawable))) ||
-             pDst->pDrawable->type == DRAWABLE_WINDOW ||
-             IS_OFFSCREEN_PIXMAP(pDst->pDrawable))) {
-            SYNC_CHECK(pDst->pDrawable);
-        }
-        (*GetPictureScreen(pScreen)->Composite) (op,
-                                                 pSrc,
-                                                 pMask,
-                                                 pDst,
-                                                 xSrc,
-                                                 ySrc,
-                                                 xMask,
-                                                 yMask,
-                                                 xDst, yDst, width, height);
-    }
-
-    if (pDst->pDrawable->type == DRAWABLE_PIXMAP)
-        (XAA_GET_PIXMAP_PRIVATE((PixmapPtr) (pDst->pDrawable)))->flags |= DIRTY;
-
-    XAA_RENDER_EPILOGUE(pScreen, Composite, XAAComposite);
-}
-
-Bool
-XAADoGlyphs(CARD8 op,
-            PicturePtr pSrc,
-            PicturePtr pDst,
-            PictFormatPtr maskFormat,
-            INT16 xSrc,
-            INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr * glyphs)
-{
-    ScreenPtr pScreen = pDst->pDrawable->pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-
-    if (!RegionNumRects(pDst->pCompositeClip))
-        return TRUE;
-
-    if (!infoRec->pScrn->vtSema ||
-        ((pDst->pDrawable->type != DRAWABLE_WINDOW) &&
-         !IS_OFFSCREEN_PIXMAP(pDst->pDrawable)))
-        return FALSE;
-
-    if ((pSrc->pDrawable->type != DRAWABLE_PIXMAP) ||
-        IS_OFFSCREEN_PIXMAP(pSrc->pDrawable))
-        return FALSE;
-
-    /*
-     * If it looks like we have a chance of being able to draw these
-     * glyphs with an accelerated Composite, do that now to avoid
-     * unneeded and costly syncs.
-     */
-    if (maskFormat) {
-        if (!infoRec->CPUToScreenAlphaTextureFormats)
-            return FALSE;
-    }
-    else {
-        if (!infoRec->CPUToScreenTextureFormats)
-            return FALSE;
-    }
-
-    miGlyphs(op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, list, glyphs);
-
-    return TRUE;
-}
-
-void
-XAAGlyphs(CARD8 op,
-          PicturePtr pSrc,
-          PicturePtr pDst,
-          PictFormatPtr maskFormat,
-          INT16 xSrc,
-          INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr * glyphs)
-{
-    ScreenPtr pScreen = pDst->pDrawable->pScreen;
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
-
-    XAA_RENDER_PROLOGUE(pScreen, Glyphs);
-
-    if (!pSrc->pDrawable || !infoRec->Glyphs ||
-        !(*infoRec->Glyphs) (op, pSrc, pDst, maskFormat,
-                             xSrc, ySrc, nlist, list, glyphs)) {
-        if (infoRec->pScrn->vtSema &&
-            ((pSrc->pDrawable &&
-              (pSrc->pDrawable->type == DRAWABLE_WINDOW ||
-               IS_OFFSCREEN_PIXMAP(pSrc->pDrawable))) ||
-             pDst->pDrawable->type == DRAWABLE_WINDOW ||
-             IS_OFFSCREEN_PIXMAP(pDst->pDrawable))) {
-            SYNC_CHECK(pDst->pDrawable);
-        }
-        (*GetPictureScreen(pScreen)->Glyphs) (op, pSrc, pDst, maskFormat,
-                                              xSrc, ySrc, nlist, list, glyphs);
-    }
-
-    if (pDst->pDrawable->type == DRAWABLE_PIXMAP)
-        (XAA_GET_PIXMAP_PRIVATE((PixmapPtr) (pDst->pDrawable)))->flags |= DIRTY;
-
-    XAA_RENDER_EPILOGUE(pScreen, Glyphs, XAAGlyphs);
-}
diff --git a/hw/xfree86/xaa/xaaROP.c b/hw/xfree86/xaa/xaaROP.c
deleted file mode 100644
index 3b6ec93..0000000
--- a/hw/xfree86/xaa/xaaROP.c
+++ /dev/null
@@ -1,182 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include "scrnintstr.h"
-#include "xf86str.h"
-#include "xaarop.h"
-#include "xaa.h"
-#include "xaalocal.h"
-
-int XAACopyROP[16] = {
-    ROP_0,                      /* GXclear */
-    ROP_DSa,                    /* GXand */
-    ROP_SDna,                   /* GXandReverse */
-    ROP_S,                      /* GXcopy */
-    ROP_DSna,                   /* GXandInverted */
-    ROP_D,                      /* GXnoop */
-    ROP_DSx,                    /* GXxor */
-    ROP_DSo,                    /* GXor */
-    ROP_DSon,                   /* GXnor */
-    ROP_DSxn,                   /* GXequiv */
-    ROP_Dn,                     /* GXinvert */
-    ROP_SDno,                   /* GXorReverse */
-    ROP_Sn,                     /* GXcopyInverted */
-    ROP_DSno,                   /* GXorInverted */
-    ROP_DSan,                   /* GXnand */
-    ROP_1                       /* GXset */
-};
-
-int XAACopyROP_PM[16] = {
-    ROP_0,                      /* not used */
-    ROP_DSPnoa,
-    ROP_DPSnaon,
-    ROP_DPSDxax,
-    ROP_DPSana,
-    ROP_D,                      /* not used */
-    ROP_DPSax,
-    ROP_DPSao,
-    ROP_DPSaon,
-    ROP_DPSaxn,
-    ROP_Dn,                     /* not used */
-    ROP_DPSanan,
-    ROP_PSDPxox,                /* is that correct ? */
-    ROP_DPSnao,
-    ROP_DSPnoan,
-    ROP_1                       /* not used */
-};
-
-int XAAPatternROP[16] = {
-    ROP_0,
-    ROP_DPa,
-    ROP_PDna,
-    ROP_P,
-    ROP_DPna,
-    ROP_D,
-    ROP_DPx,
-    ROP_DPo,
-    ROP_DPon,
-    ROP_PDxn,
-    ROP_Dn,
-    ROP_PDno,
-    ROP_Pn,
-    ROP_DPno,
-    ROP_DPan,
-    ROP_1
-};
-
-int XAAPatternROP_PM[16] = {
-    ROP_DPna,
-    ROP_DPSnoa,
-    ROP_DSPnaon,
-    ROP_DSPDxax,
-    ROP_DPSana,
-    ROP_D,
-    ROP_DPSax,
-    ROP_DPSao,
-    ROP_DPSaon,
-    ROP_DPSaxn,
-    ROP_DPx,
-    ROP_DPSanan,
-    ROP_SPDSxox,                /* is that correct ? */
-    ROP_DSPnao,
-    ROP_DPSnoan,
-    ROP_DPo
-};
-
-int
-XAAGetCopyROP(int i)
-{
-    return XAACopyROP[i];
-}
-
-int
-XAAGetCopyROP_PM(int i)
-{
-    return XAACopyROP_PM[i];
-}
-
-int
-XAAGetPatternROP(int i)
-{
-    return XAAPatternROP[i];
-}
-
-int
-XAAGetPatternROP_PM(int i)
-{
-    return XAAPatternROP_PM[i];
-}
-
-int
-XAAHelpPatternROP(ScrnInfoPtr pScrn, int *fg, int *bg, int pm, int *rop)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int ret = 0;
-
-    pm &= infoRec->FullPlanemasks[pScrn->depth - 1];
-
-    if (pm == infoRec->FullPlanemasks[pScrn->depth - 1]) {
-        if (!NO_SRC_ROP(*rop))
-            ret |= ROP_PAT;
-        *rop = XAAPatternROP[*rop];
-    }
-    else {
-        switch (*rop) {
-        case GXnoop:
-            break;
-        case GXset:
-        case GXclear:
-        case GXinvert:
-            ret |= ROP_PAT;
-            *fg = pm;
-            if (*bg != -1)
-                *bg = pm;
-            break;
-        default:
-            ret |= ROP_PAT | ROP_SRC;
-            break;
-        }
-        *rop = XAAPatternROP_PM[*rop];
-    }
-
-    return ret;
-}
-
-int
-XAAHelpSolidROP(ScrnInfoPtr pScrn, int *fg, int pm, int *rop)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int ret = 0;
-
-    pm &= infoRec->FullPlanemasks[pScrn->depth - 1];
-
-    if (pm == infoRec->FullPlanemasks[pScrn->depth - 1]) {
-        if (!NO_SRC_ROP(*rop))
-            ret |= ROP_PAT;
-        *rop = XAAPatternROP[*rop];
-    }
-    else {
-        switch (*rop) {
-        case GXnoop:
-            break;
-        case GXset:
-        case GXclear:
-        case GXinvert:
-            ret |= ROP_PAT;
-            *fg = pm;
-            break;
-        default:
-            ret |= ROP_PAT | ROP_SRC;
-            break;
-        }
-        *rop = XAAPatternROP_PM[*rop];
-    }
-
-    return ret;
-}
diff --git a/hw/xfree86/xaa/xaaRect.c b/hw/xfree86/xaa/xaaRect.c
deleted file mode 100644
index 0020900..0000000
--- a/hw/xfree86/xaa/xaaRect.c
+++ /dev/null
@@ -1,121 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-
-/*
-   Much of this file based on code by 
-	Harm Hanemaayer (H.Hanemaayer at inter.nl.net).
-*/
-
-void
-XAAPolyRectangleThinSolid(DrawablePtr pDrawable,
-                          GCPtr pGC, int nRectsInit, xRectangle *pRectsInit)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int nClipRects;             /* number of clip rectangles */
-    BoxPtr pClipRects;          /* points to the list of clip rects */
-    int xOrigin;                /* Drawables x origin */
-    int yOrigin;                /* Drawables x origin */
-    xRectangle *pRect;          /* list of rects */
-    int nRects;                 /* running count of number of rects */
-    int origX1, origY1;         /* original rectangle's U/L corner */
-    int origX2, origY2;         /* original rectangle's L/R corner */
-    int clippedX1;              /* clipped rectangle's left x */
-    int clippedY1;              /* clipped rectangle's top y */
-    int clippedX2;              /* clipped rectangle's right x */
-    int clippedY2;              /* clipped rectangle's bottom y */
-    int clipXMin;               /* upper left corner of clip rect */
-    int clipYMin;               /* upper left corner of clip rect */
-    int clipXMax;               /* lower right corner of clip rect */
-    int clipYMax;               /* lower right corner of clip rect */
-    int width, height;          /* width and height of rect */
-
-    nClipRects = RegionNumRects(pGC->pCompositeClip);
-    pClipRects = RegionRects(pGC->pCompositeClip);
-
-    if (!nClipRects)
-        return;
-
-    xOrigin = pDrawable->x;
-    yOrigin = pDrawable->y;
-
-    (*infoRec->SetupForSolidLine) (infoRec->pScrn,
-                                   pGC->fgPixel, pGC->alu, pGC->planemask);
-
-    for (; nClipRects > 0; nClipRects--, pClipRects++) {
-        clipYMin = pClipRects->y1;
-        clipYMax = pClipRects->y2 - 1;
-        clipXMin = pClipRects->x1;
-        clipXMax = pClipRects->x2 - 1;
-
-        for (pRect = pRectsInit, nRects = nRectsInit;
-             nRects > 0; nRects--, pRect++) {
-            /* translate rectangle data over to the drawable */
-            origX1 = pRect->x + xOrigin;
-            origY1 = pRect->y + yOrigin;
-            origX2 = origX1 + pRect->width;
-            origY2 = origY1 + pRect->height;
-
-            /* reject entire rectangle if completely outside clip rect */
-            if ((origX1 > clipXMax) || (origX2 < clipXMin) ||
-                (origY1 > clipYMax) || (origY2 < clipYMin))
-                continue;
-
-            /* clip the rectangle */
-            clippedX1 = max(origX1, clipXMin);
-            clippedX2 = min(origX2, clipXMax);
-            clippedY1 = max(origY1, clipYMin);
-            clippedY2 = min(origY2, clipYMax);
-
-            width = clippedX2 - clippedX1 + 1;
-
-            if (origY1 >= clipYMin) {
-                (*infoRec->SubsequentSolidHorVertLine) (infoRec->pScrn,
-                                                        clippedX1, clippedY1,
-                                                        width, DEGREES_0);
-
-                /* don't overwrite corner */
-                clippedY1++;
-            }
-
-            if ((origY2 <= clipYMax) && (origY1 != origY2)) {
-                (*infoRec->SubsequentSolidHorVertLine) (infoRec->pScrn,
-                                                        clippedX1, clippedY2,
-                                                        width, DEGREES_0);
-
-                /* don't overwrite corner */
-                clippedY2--;
-            }
-
-            if (clippedY2 < clippedY1)
-                continue;
-
-            height = clippedY2 - clippedY1 + 1;
-
-            /* draw vertical edges using lines if not clipped out */
-            if (origX1 >= clipXMin)
-                (*infoRec->SubsequentSolidHorVertLine) (infoRec->pScrn,
-                                                        clippedX1, clippedY1,
-                                                        height, DEGREES_270);
-
-            if ((origX2 <= clipXMax) && (origX2 != origX1))
-                (*infoRec->SubsequentSolidHorVertLine) (infoRec->pScrn,
-                                                        clippedX2, clippedY1,
-                                                        height, DEGREES_270);
-        }
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
diff --git a/hw/xfree86/xaa/xaaSpans.c b/hw/xfree86/xaa/xaaSpans.c
deleted file mode 100644
index f03452a..0000000
--- a/hw/xfree86/xaa/xaaSpans.c
+++ /dev/null
@@ -1,876 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "xf86str.h"
-#include "mi.h"
-#include "mispans.h"
-#include "xaa.h"
-#include "xaalocal.h"
-
-static void XAARenderSolidSpans(GCPtr, int, DDXPointPtr, int *, int, int, int);
-static void XAARenderColor8x8Spans(GCPtr, int, DDXPointPtr, int *, int, int,
-                                   int);
-static void XAARenderMono8x8Spans(GCPtr, int, DDXPointPtr, int *, int, int,
-                                  int);
-static void XAARenderCacheBltSpans(GCPtr, int, DDXPointPtr, int *, int, int,
-                                   int);
-static void XAARenderColorExpandSpans(GCPtr, int, DDXPointPtr, int *, int, int,
-                                      int);
-static void XAARenderCacheExpandSpans(GCPtr, int, DDXPointPtr, int *, int, int,
-                                      int);
-static void XAARenderPixmapCopySpans(GCPtr, int, DDXPointPtr, int *, int, int,
-                                     int);
-
-void
-XAAFillSpans(DrawablePtr pDraw, GC * pGC, int nInit,    /* number of spans to fill */
-             DDXPointPtr pptInit,       /* pointer to list of start points */
-             int *pwidthInit,   /* pointer to list of n widths */
-             int fSorted)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int type = 0;
-    ClipAndRenderSpansFunc function;
-    Bool fastClip = FALSE;
-
-    if ((nInit <= 0) || !pGC->planemask)
-        return;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    switch (pGC->fillStyle) {
-    case FillSolid:
-        type = DO_SOLID;
-        break;
-    case FillStippled:
-        type = (*infoRec->StippledFillChooser) (pGC);
-        break;
-    case FillOpaqueStippled:
-        if ((pGC->fgPixel == pGC->bgPixel) && infoRec->FillSpansSolid &&
-            CHECK_PLANEMASK(pGC, infoRec->FillSpansSolidFlags) &&
-            CHECK_ROP(pGC, infoRec->FillSpansSolidFlags) &&
-            CHECK_ROPSRC(pGC, infoRec->FillSpansSolidFlags) &&
-            CHECK_FG(pGC, infoRec->FillSpansSolidFlags))
-            type = DO_SOLID;
-        else
-            type = (*infoRec->OpaqueStippledFillChooser) (pGC);
-        break;
-    case FillTiled:
-        type = (*infoRec->TiledFillChooser) (pGC);
-        break;
-    }
-
-    switch (type) {
-    case DO_SOLID:
-        function = XAARenderSolidSpans;
-        if (infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_FILL)
-            fastClip = TRUE;
-        break;
-    case DO_COLOR_8x8:
-        function = XAARenderColor8x8Spans;
-        if (infoRec->ClippingFlags & HARDWARE_CLIP_COLOR_8x8_FILL)
-            fastClip = TRUE;
-        break;
-    case DO_MONO_8x8:
-        function = XAARenderMono8x8Spans;
-        if (infoRec->ClippingFlags & HARDWARE_CLIP_MONO_8x8_FILL)
-            fastClip = TRUE;
-        break;
-    case DO_CACHE_BLT:
-        function = XAARenderCacheBltSpans;
-        if (infoRec->ClippingFlags & HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY)
-            fastClip = TRUE;
-        break;
-    case DO_COLOR_EXPAND:
-        function = XAARenderColorExpandSpans;
-        break;
-    case DO_CACHE_EXPAND:
-        function = XAARenderCacheExpandSpans;
-        if (infoRec->ClippingFlags &
-            HARDWARE_CLIP_SCREEN_TO_SCREEN_COLOR_EXPAND)
-            fastClip = TRUE;
-        break;
-    case DO_PIXMAP_COPY:
-        function = XAARenderPixmapCopySpans;
-        if (infoRec->ClippingFlags & HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY)
-            fastClip = TRUE;
-        break;
-    case DO_IMAGE_WRITE:
-    default:
-        (*XAAFallbackOps.FillSpans) (pDraw, pGC, nInit, pptInit,
-                                     pwidthInit, fSorted);
-        return;
-    }
-
-    if ((nInit < 10) || (RegionNumRects(pGC->pCompositeClip) != 1))
-        fastClip = FALSE;
-
-    if (fastClip) {
-        infoRec->ClipBox = &pGC->pCompositeClip->extents;
-        (*function) (pGC, nInit, pptInit, pwidthInit, fSorted,
-                     pDraw->x, pDraw->y);
-        infoRec->ClipBox = NULL;
-    }
-    else
-        XAAClipAndRenderSpans(pGC, pptInit, pwidthInit, nInit, fSorted,
-                              function, pDraw->x, pDraw->y);
-}
-
-        /*********************\
-	|     Solid Spans     |
-	\*********************/
-
-static void
-XAARenderSolidSpans(GCPtr pGC,
-                    int n,
-                    DDXPointPtr ppt,
-                    int *pwidth, int fSorted, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    (*infoRec->FillSolidSpans) (infoRec->pScrn, pGC->fgPixel,
-                                pGC->alu, pGC->planemask, n, ppt, pwidth,
-                                fSorted);
-}
-
-        /************************\
-	|     Mono 8x8 Spans     |
-	\************************/
-
-static void
-XAARenderMono8x8Spans(GCPtr pGC,
-                      int n,
-                      DDXPointPtr ppt,
-                      int *pwidth, int fSorted, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAAPixmapPtr pPriv;
-    int fg, bg;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
-        fg = pGC->fgPixel;
-        bg = -1;
-        break;
-    case FillOpaqueStippled:
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
-        fg = pGC->fgPixel;
-        bg = pGC->bgPixel;
-        break;
-    case FillTiled:
-        pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
-        fg = pPriv->fg;
-        bg = pPriv->bg;
-        break;
-    default:                   /* Muffle compiler */
-        pPriv = NULL;           /* Kaboom */
-        fg = -1;
-        bg = -1;
-        break;
-    }
-
-    (*infoRec->FillMono8x8PatternSpans) (infoRec->pScrn,
-                                         fg, bg, pGC->alu, pGC->planemask,
-                                         n, ppt, pwidth, fSorted,
-                                         pPriv->pattern0, pPriv->pattern1,
-                                         (xorg + pGC->patOrg.x),
-                                         (yorg + pGC->patOrg.y));
-}
-
-        /*************************\
-	|     Color 8x8 Spans     |
-	\*************************/
-
-static void
-XAARenderColor8x8Spans(GCPtr pGC,
-                       int n,
-                       DDXPointPtr ppt,
-                       int *pwidth, int fSorted, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAACacheInfoPtr pCache;
-    PixmapPtr pPix;
-    int fg, bg;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        pPix = pGC->stipple;
-        fg = pGC->fgPixel;
-        bg = -1;
-        break;
-    case FillOpaqueStippled:
-        pPix = pGC->stipple;
-        fg = pGC->fgPixel;
-        bg = pGC->bgPixel;
-        break;
-    case FillTiled:
-        pPix = pGC->tile.pixmap;
-        fg = -1;
-        bg = -1;
-        break;
-    default:                   /* Muffle compiler */
-        pPix = NULL;
-        fg = -1;
-        bg = -1;
-        break;
-    }
-
-    pCache = (*infoRec->CacheColor8x8Pattern) (infoRec->pScrn, pPix, fg, bg);
-
-    (*infoRec->FillColor8x8PatternSpans) (infoRec->pScrn,
-                                          pGC->alu, pGC->planemask, n, ppt,
-                                          pwidth, fSorted, pCache,
-                                          (yorg + pGC->patOrg.x),
-                                          (xorg + pGC->patOrg.y));
-}
-
-        /****************************\
-	|     Color Expand Spans     |
-	\****************************/
-
-static void
-XAARenderColorExpandSpans(GCPtr pGC,
-                          int n,
-                          DDXPointPtr ppt,
-                          int *pwidth, int fSorted, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int fg, bg;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        fg = pGC->fgPixel;
-        bg = -1;
-        break;
-    case FillOpaqueStippled:
-        fg = pGC->fgPixel;
-        bg = pGC->bgPixel;
-        break;
-    default:                   /* Muffle compiler */
-        fg = -1;
-        bg = -1;
-        break;
-    }
-
-    (*infoRec->FillColorExpandSpans) (infoRec->pScrn, fg, bg,
-                                      pGC->alu, pGC->planemask, n, ppt, pwidth,
-                                      fSorted, (xorg + pGC->patOrg.x),
-                                      (yorg + pGC->patOrg.y), pGC->stipple);
-
-}
-
-        /*************************\
-	|     Cache Blt Spans     |
-	\*************************/
-
-static void
-XAARenderCacheBltSpans(GCPtr pGC,
-                       int n,
-                       DDXPointPtr ppt,
-                       int *pwidth, int fSorted, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAACacheInfoPtr pCache;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        pCache = (*infoRec->CacheStipple) (infoRec->pScrn, pGC->stipple,
-                                           pGC->fgPixel, -1);
-        break;
-    case FillOpaqueStippled:
-        pCache = (*infoRec->CacheStipple) (infoRec->pScrn, pGC->stipple,
-                                           pGC->fgPixel, pGC->bgPixel);
-        break;
-    case FillTiled:
-        pCache = (*infoRec->CacheTile) (infoRec->pScrn, pGC->tile.pixmap);
-        break;
-    default:                   /* Muffle compiler */
-        pCache = NULL;
-        break;
-    }
-
-    (*infoRec->FillCacheBltSpans) (infoRec->pScrn,
-                                   pGC->alu, pGC->planemask, n, ppt, pwidth,
-                                   fSorted, pCache, (xorg + pGC->patOrg.x),
-                                   (yorg + pGC->patOrg.y));
-
-}
-
-        /****************************\
-	|     Cache Expand Spans     |
-	\****************************/
-
-static void
-XAARenderCacheExpandSpans(GCPtr pGC,
-                          int n,
-                          DDXPointPtr ppt,
-                          int *pwidth, int fSorted, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int fg, bg;
-
-    switch (pGC->fillStyle) {
-    case FillStippled:
-        fg = pGC->fgPixel;
-        bg = -1;
-        break;
-    case FillOpaqueStippled:
-        fg = pGC->fgPixel;
-        bg = pGC->bgPixel;
-        break;
-    default:                   /* Muffle compiler */
-        fg = -1;
-        bg = -1;
-        break;
-    }
-
-    (*infoRec->FillCacheExpandSpans) (infoRec->pScrn, fg, bg,
-                                      pGC->alu, pGC->planemask, n, ppt, pwidth,
-                                      fSorted, (xorg + pGC->patOrg.x),
-                                      (yorg + pGC->patOrg.y), pGC->stipple);
-}
-
-        /***************************\
-	|     Pixmap Copy Spans     |
-	\***************************/
-
-static void
-XAARenderPixmapCopySpans(GCPtr pGC,
-                         int n,
-                         DDXPointPtr ppt,
-                         int *pwidth, int fSorted, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAACacheInfoPtr pCache = &(infoRec->ScratchCacheInfoRec);
-    XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
-
-    pCache->x = pPriv->offscreenArea->box.x1;
-    pCache->y = pPriv->offscreenArea->box.y1;
-    pCache->w = pCache->orig_w = pPriv->offscreenArea->box.x2 - pCache->x;
-    pCache->h = pCache->orig_h = pPriv->offscreenArea->box.y2 - pCache->y;
-    pCache->trans_color = -1;
-
-    (*infoRec->FillCacheBltSpans) (infoRec->pScrn,
-                                   pGC->alu, pGC->planemask, n, ppt, pwidth,
-                                   fSorted, pCache, (xorg + pGC->patOrg.x),
-                                   (yorg + pGC->patOrg.y));
-}
-
-        /****************\
-	|     Solid      |
-	\****************/
-
-void
-XAAFillSolidSpans(ScrnInfoPtr pScrn,
-                  int fg, int rop,
-                  unsigned int planemask,
-                  int n, DDXPointPtr ppt, int *pwidth, int fSorted)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-
-    (*infoRec->SetupForSolidFill) (pScrn, fg, rop, planemask);
-
-    if (infoRec->ClipBox)
-        (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                          infoRec->ClipBox->x1,
-                                          infoRec->ClipBox->y1,
-                                          infoRec->ClipBox->x2 - 1,
-                                          infoRec->ClipBox->y2 - 1);
-
-    while (n--) {
-        if (*pwidth > 0)
-            (*infoRec->SubsequentSolidFillRect) (pScrn, ppt->x, ppt->y,
-                                                 *pwidth, 1);
-        ppt++;
-        pwidth++;
-    }
-
-    if (infoRec->ClipBox)
-        (*infoRec->DisableClipping) (infoRec->pScrn);
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /***************\
-	|   Mono 8x8    |
-	\***************/
-
-void
-XAAFillMono8x8PatternSpansScreenOrigin(ScrnInfoPtr pScrn,
-                                       int fg, int bg, int rop,
-                                       unsigned int planemask,
-                                       int n,
-                                       DDXPointPtr ppt,
-                                       int *pwidth, int fSorted,
-                                       int pattern0, int pattern1,
-                                       int xorigin, int yorigin)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int patx = pattern0, paty = pattern1;
-    int xorg = (-xorigin) & 0x07;
-    int yorg = (-yorigin) & 0x07;
-
-    if (infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS) {
-        if (!(infoRec->Mono8x8PatternFillFlags &
-              HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-            XAARotateMonoPattern(&patx, &paty, xorg, yorg,
-                                 (infoRec->Mono8x8PatternFillFlags &
-                                  BIT_ORDER_IN_BYTE_MSBFIRST));
-            xorg = patx;
-            yorg = paty;
-        }
-    }
-    else {
-        XAACacheInfoPtr pCache =
-            (*infoRec->CacheMono8x8Pattern) (pScrn, pattern0, pattern1);
-        patx = pCache->x;
-        paty = pCache->y;
-        if (!(infoRec->Mono8x8PatternFillFlags &
-              HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-            int slot = (yorg << 3) + xorg;
-
-            patx += pCache->offsets[slot].x;
-            paty += pCache->offsets[slot].y;
-            xorg = patx;
-            yorg = paty;
-        }
-    }
-
-    (*infoRec->SetupForMono8x8PatternFill) (pScrn, patx, paty,
-                                            fg, bg, rop, planemask);
-
-    if (infoRec->ClipBox)
-        (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                          infoRec->ClipBox->x1,
-                                          infoRec->ClipBox->y1,
-                                          infoRec->ClipBox->x2 - 1,
-                                          infoRec->ClipBox->y2 - 1);
-
-    while (n--) {
-        (*infoRec->SubsequentMono8x8PatternFillRect) (pScrn,
-                                                      xorg, yorg, ppt->x,
-                                                      ppt->y, *pwidth, 1);
-        ppt++;
-        pwidth++;
-    }
-
-    if (infoRec->ClipBox)
-        (*infoRec->DisableClipping) (infoRec->pScrn);
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAAFillMono8x8PatternSpans(ScrnInfoPtr pScrn,
-                           int fg, int bg, int rop,
-                           unsigned int planemask,
-                           int n,
-                           DDXPointPtr ppt,
-                           int *pwidth, int fSorted,
-                           int pattern0, int pattern1, int xorigin, int yorigin)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int patx = pattern0, paty = pattern1;
-    int xorg, yorg, slot;
-    XAACacheInfoPtr pCache = NULL;
-
-    if (!(infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS)) {
-        pCache = (*infoRec->CacheMono8x8Pattern) (pScrn, pattern0, pattern1);
-        patx = pCache->x;
-        paty = pCache->y;
-    }
-
-    (*infoRec->SetupForMono8x8PatternFill) (pScrn, patx, paty,
-                                            fg, bg, rop, planemask);
-
-    if (infoRec->ClipBox)
-        (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                          infoRec->ClipBox->x1,
-                                          infoRec->ClipBox->y1,
-                                          infoRec->ClipBox->x2 - 1,
-                                          infoRec->ClipBox->y2 - 1);
-
-    while (n--) {
-        xorg = (ppt->x - xorigin) & 0x07;
-        yorg = (ppt->y - yorigin) & 0x07;
-
-        if (!(infoRec->Mono8x8PatternFillFlags &
-              HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-            if (infoRec->Mono8x8PatternFillFlags &
-                HARDWARE_PATTERN_PROGRAMMED_BITS) {
-                patx = pattern0;
-                paty = pattern1;
-                XAARotateMonoPattern(&patx, &paty, xorg, yorg,
-                                     (infoRec->Mono8x8PatternFillFlags &
-                                      BIT_ORDER_IN_BYTE_MSBFIRST));
-                xorg = patx;
-                yorg = paty;
-            }
-            else {
-                slot = (yorg << 3) + xorg;
-                xorg = patx + pCache->offsets[slot].x;
-                yorg = paty + pCache->offsets[slot].y;
-            }
-        }
-
-        (*infoRec->SubsequentMono8x8PatternFillRect) (pScrn,
-                                                      xorg, yorg, ppt->x,
-                                                      ppt->y, *pwidth, 1);
-        ppt++;
-        pwidth++;
-    }
-
-    if (infoRec->ClipBox)
-        (*infoRec->DisableClipping) (infoRec->pScrn);
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /****************\
-	|   Color 8x8    |
-	\****************/
-
-void
-XAAFillColor8x8PatternSpansScreenOrigin(ScrnInfoPtr pScrn,
-                                        int rop,
-                                        unsigned int planemask,
-                                        int n,
-                                        DDXPointPtr ppt,
-                                        int *pwidth, int fSorted,
-                                        XAACacheInfoPtr pCache,
-                                        int xorigin, int yorigin)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int patx = pCache->x, paty = pCache->y;
-    int xorg = (-xorigin) & 0x07;
-    int yorg = (-yorigin) & 0x07;
-
-    if (!(infoRec->Color8x8PatternFillFlags &
-          HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-        int slot = (yorg << 3) + xorg;
-
-        paty += pCache->offsets[slot].y;
-        patx += pCache->offsets[slot].x;
-        xorg = patx;
-        yorg = paty;
-    }
-
-    (*infoRec->SetupForColor8x8PatternFill) (pScrn, patx, paty,
-                                             rop, planemask,
-                                             pCache->trans_color);
-
-    if (infoRec->ClipBox)
-        (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                          infoRec->ClipBox->x1,
-                                          infoRec->ClipBox->y1,
-                                          infoRec->ClipBox->x2 - 1,
-                                          infoRec->ClipBox->y2 - 1);
-
-    while (n--) {
-        (*infoRec->SubsequentColor8x8PatternFillRect) (pScrn,
-                                                       xorg, yorg, ppt->x,
-                                                       ppt->y, *pwidth, 1);
-        ppt++;
-        pwidth++;
-    }
-
-    if (infoRec->ClipBox)
-        (*infoRec->DisableClipping) (infoRec->pScrn);
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAAFillColor8x8PatternSpans(ScrnInfoPtr pScrn,
-                            int rop,
-                            unsigned int planemask,
-                            int n,
-                            DDXPointPtr ppt,
-                            int *pwidth, int fSorted,
-                            XAACacheInfoPtr pCache, int xorigin, int yorigin)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int xorg, yorg, slot;
-
-    (*infoRec->SetupForColor8x8PatternFill) (pScrn, pCache->x, pCache->y,
-                                             rop, planemask,
-                                             pCache->trans_color);
-
-    if (infoRec->ClipBox)
-        (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                          infoRec->ClipBox->x1,
-                                          infoRec->ClipBox->y1,
-                                          infoRec->ClipBox->x2 - 1,
-                                          infoRec->ClipBox->y2 - 1);
-
-    while (n--) {
-        xorg = (ppt->x - xorigin) & 0x07;
-        yorg = (ppt->y - yorigin) & 0x07;
-
-        if (!(infoRec->Color8x8PatternFillFlags &
-              HARDWARE_PATTERN_PROGRAMMED_ORIGIN)) {
-            slot = (yorg << 3) + xorg;
-            yorg = pCache->y + pCache->offsets[slot].y;
-            xorg = pCache->x + pCache->offsets[slot].x;
-        }
-
-        (*infoRec->SubsequentColor8x8PatternFillRect) (pScrn,
-                                                       xorg, yorg, ppt->x,
-                                                       ppt->y, *pwidth, 1);
-        ppt++;
-        pwidth++;
-    }
-
-    if (infoRec->ClipBox)
-        (*infoRec->DisableClipping) (infoRec->pScrn);
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /*****************\
-	|   Cache Blit    |
-	\*****************/
-
-void
-XAAFillCacheBltSpans(ScrnInfoPtr pScrn,
-                     int rop,
-                     unsigned int planemask,
-                     int n,
-                     DDXPointPtr ppt,
-                     int *pwidth,
-                     int fSorted, XAACacheInfoPtr pCache, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int x, w, phaseX, phaseY, blit_w;
-
-    (*infoRec->SetupForScreenToScreenCopy) (pScrn, 1, 1, rop, planemask,
-                                            pCache->trans_color);
-
-    if (infoRec->ClipBox)
-        (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                          infoRec->ClipBox->x1,
-                                          infoRec->ClipBox->y1,
-                                          infoRec->ClipBox->x2 - 1,
-                                          infoRec->ClipBox->y2 - 1);
-
-    while (n--) {
-        x = ppt->x;
-        w = *pwidth;
-        phaseX = (x - xorg) % pCache->orig_w;
-        if (phaseX < 0)
-            phaseX += pCache->orig_w;
-        phaseY = (ppt->y - yorg) % pCache->orig_h;
-        if (phaseY < 0)
-            phaseY += pCache->orig_h;
-
-        while (1) {
-            blit_w = pCache->w - phaseX;
-            if (blit_w > w)
-                blit_w = w;
-
-            (*infoRec->SubsequentScreenToScreenCopy) (pScrn,
-                                                      pCache->x + phaseX,
-                                                      pCache->y + phaseY, x,
-                                                      ppt->y, blit_w, 1);
-
-            w -= blit_w;
-            if (!w)
-                break;
-            x += blit_w;
-            phaseX = (phaseX + blit_w) % pCache->orig_w;
-        }
-        ppt++;
-        pwidth++;
-    }
-
-    if (infoRec->ClipBox)
-        (*infoRec->DisableClipping) (infoRec->pScrn);
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-        /****************\
-	|  Cache Expand  |
-	\****************/
-
-void
-XAAFillCacheExpandSpans(ScrnInfoPtr pScrn,
-                        int fg, int bg, int rop,
-                        unsigned int planemask,
-                        int n,
-                        DDXPointPtr ppt,
-                        int *pwidth,
-                        int fSorted, int xorg, int yorg, PixmapPtr pPix)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int x, w, phaseX, phaseY, blit_w, cacheWidth;
-    XAACacheInfoPtr pCache;
-
-    pCache = (*infoRec->CacheMonoStipple) (pScrn, pPix);
-
-    cacheWidth = (pCache->w * pScrn->bitsPerPixel) /
-        infoRec->CacheColorExpandDensity;
-
-    (*infoRec->SetupForScreenToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                       planemask);
-
-    if (infoRec->ClipBox)
-        (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                          infoRec->ClipBox->x1,
-                                          infoRec->ClipBox->y1,
-                                          infoRec->ClipBox->x2 - 1,
-                                          infoRec->ClipBox->y2 - 1);
-
-    while (n--) {
-        x = ppt->x;
-        w = *pwidth;
-        phaseX = (x - xorg) % pCache->orig_w;
-        if (phaseX < 0)
-            phaseX += pCache->orig_w;
-        phaseY = (ppt->y - yorg) % pCache->orig_h;
-        if (phaseY < 0)
-            phaseY += pCache->orig_h;
-
-        while (1) {
-            blit_w = cacheWidth - phaseX;
-            if (blit_w > w)
-                blit_w = w;
-
-            (*infoRec->SubsequentScreenToScreenColorExpandFill) (pScrn, x,
-                                                                 ppt->y, blit_w,
-                                                                 1, pCache->x,
-                                                                 pCache->y +
-                                                                 phaseY,
-                                                                 phaseX);
-
-            w -= blit_w;
-            if (!w)
-                break;
-            x += blit_w;
-            phaseX = (phaseX + blit_w) % pCache->orig_w;
-        }
-        ppt++;
-        pwidth++;
-    }
-
-    if (infoRec->ClipBox)
-        (*infoRec->DisableClipping) (infoRec->pScrn);
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-XAAClipAndRenderSpans(GCPtr pGC,
-                      DDXPointPtr ppt,
-                      int *pwidth,
-                      int nspans,
-                      int fSorted,
-                      ClipAndRenderSpansFunc func, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    DDXPointPtr pptNew, pptBase;
-    int *pwidthBase, *pwidthNew;
-    int Right, numRects, MaxBoxes;
-
-    MaxBoxes = infoRec->PreAllocSize / (sizeof(DDXPointRec) + sizeof(int));
-    pptBase = (DDXPointRec *) infoRec->PreAllocMem;
-    pwidthBase = (int *) (&pptBase[MaxBoxes]);
-
-    pptNew = pptBase;
-    pwidthNew = pwidthBase;
-
-    numRects = RegionNumRects(pGC->pCompositeClip);
-
-    if (numRects == 1) {
-        BoxPtr pextent = RegionRects(pGC->pCompositeClip);
-
-        while (nspans--) {
-            if ((pextent->y1 <= ppt->y) && (ppt->y < pextent->y2)) {
-                pptNew->x = max(pextent->x1, ppt->x);
-                Right = ppt->x + *pwidth;
-                *pwidthNew = min(pextent->x2, Right) - pptNew->x;
-
-                if (*pwidthNew > 0) {
-                    pptNew->y = ppt->y;
-                    pptNew++;
-                    pwidthNew++;
-
-                    if (pptNew >= (pptBase + MaxBoxes)) {
-                        (*func) (pGC, MaxBoxes, pptBase, pwidthBase, fSorted,
-                                 xorg, yorg);
-                        pptNew = pptBase;
-                        pwidthNew = pwidthBase;
-                    }
-                }
-            }
-            ppt++;
-            pwidth++;
-        }
-    }
-    else if (numRects) {
-        BoxPtr pbox;
-        int nbox;
-
-        while (nspans--) {
-            nbox = numRects;
-            pbox = RegionRects(pGC->pCompositeClip);
-
-            /* find the first band */
-            while (nbox && (pbox->y2 <= ppt->y)) {
-                pbox++;
-                nbox--;
-            }
-
-            if (nbox && (pbox->y1 <= ppt->y)) {
-                int orig_y = pbox->y1;
-
-                Right = ppt->x + *pwidth;
-                while (nbox && (orig_y == pbox->y1)) {
-                    if (pbox->x2 <= ppt->x) {
-                        nbox--;
-                        pbox++;
-                        continue;
-                    }
-
-                    if (pbox->x1 >= Right) {
-                        nbox = 0;
-                        break;
-                    }
-
-                    pptNew->x = max(pbox->x1, ppt->x);
-                    *pwidthNew = min(pbox->x2, Right) - pptNew->x;
-                    if (*pwidthNew > 0) {
-                        pptNew->y = ppt->y;
-                        pptNew++;
-                        pwidthNew++;
-
-                        if (pptNew >= (pptBase + MaxBoxes)) {
-                            (*func) (pGC, MaxBoxes, pptBase, pwidthBase,
-                                     fSorted, xorg, yorg);
-                            pptNew = pptBase;
-                            pwidthNew = pwidthBase;
-                        }
-                    }
-                    pbox++;
-                    nbox--;
-                }
-            }
-            ppt++;
-            pwidth++;
-        }
-    }
-
-    if (pptNew != pptBase)
-        (*func) (pGC, pptNew - pptBase, pptBase, pwidthBase, fSorted,
-                 xorg, yorg);
-}
diff --git a/hw/xfree86/xaa/xaaStateChange.c b/hw/xfree86/xaa/xaaStateChange.c
deleted file mode 100644
index cd2b601..0000000
--- a/hw/xfree86/xaa/xaaStateChange.c
+++ /dev/null
@@ -1,1665 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "scrnintstr.h"
-#include "pixmapstr.h"
-#include "windowstr.h"
-#include "xf86str.h"
-#include "mi.h"
-#include "miline.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaawrap.h"
-#include "servermd.h"
-
-#define XAA_STATE_WRAP(func) do {\
-if(infoRec->func) { \
-   pStatePriv->func = infoRec->func;\
-   infoRec->func = XAAStateWrap##func;\
-}} while(0)
-
-/* Wrap all XAA functions and allocate our private structure.
- */
-
-typedef struct _XAAStateWrapRec {
-    ScrnInfoPtr pScrn;
-    void (*RestoreAccelState) (ScrnInfoPtr pScrn);
-    void (*Sync) (ScrnInfoPtr pScrn);
-    void (*SetupForScreenToScreenCopy) (ScrnInfoPtr pScrn, int xdir, int ydir,
-                                        int rop, unsigned int planemask,
-                                        int trans_color);
-    void (*SetupForSolidFill) (ScrnInfoPtr pScrn, int color, int rop,
-                               unsigned int planemask);
-    void (*SetupForSolidLine) (ScrnInfoPtr pScrn, int color, int rop,
-                               unsigned int planemask);
-    void (*SetupForDashedLine) (ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                unsigned int planemask, int length,
-                                unsigned char *pattern);
-    void (*SetClippingRectangle) (ScrnInfoPtr pScrn, int left, int top,
-                                  int right, int bottom);
-    void (*DisableClipping) (ScrnInfoPtr pScrn);
-    void (*SetupForMono8x8PatternFill) (ScrnInfoPtr pScrn, int patx, int paty,
-                                        int fg, int bg, int rop,
-                                        unsigned int planemask);
-    void (*SetupForColor8x8PatternFill) (ScrnInfoPtr pScrn, int patx, int paty,
-                                         int rop, unsigned int planemask,
-                                         int transparency_color);
-    void (*SetupForCPUToScreenColorExpandFill) (ScrnInfoPtr pScrn, int fg,
-                                                int bg, int rop,
-                                                unsigned int planemask);
-    void (*SetupForScanlineCPUToScreenColorExpandFill) (ScrnInfoPtr pScrn,
-                                                        int fg, int bg, int rop,
-                                                        unsigned int planemask);
-    void (*SetupForScreenToScreenColorExpandFill) (ScrnInfoPtr pScrn,
-                                                   int fg, int bg, int rop,
-                                                   unsigned int planemask);
-    void (*SetupForImageWrite) (ScrnInfoPtr pScrn, int rop,
-                                unsigned int planemask, int transparency_color,
-                                int bpp, int depth);
-    void (*SetupForScanlineImageWrite) (ScrnInfoPtr pScrn, int rop,
-                                        unsigned int planemask,
-                                        int transparency_color,
-                                        int bpp, int depth);
-    void (*SetupForImageRead) (ScrnInfoPtr pScrn, int bpp, int depth);
-    void (*ScreenToScreenBitBlt) (ScrnInfoPtr pScrn, int nbox,
-                                  DDXPointPtr pptSrc, BoxPtr pbox, int xdir,
-                                  int ydir, int alu, unsigned int planmask);
-    void (*WriteBitmap) (ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                         unsigned char *src, int srcwidth, int skipleft,
-                         int fg, int bg, int rop, unsigned int planemask);
-    void (*FillSolidRects) (ScrnInfoPtr pScrn, int fg, int rop,
-                            unsigned int planemask, int nBox, BoxPtr pBox);
-    void (*FillMono8x8PatternRects) (ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                     unsigned int planemask, int nBox,
-                                     BoxPtr pBox, int pat0, int pat1,
-                                     int xorg, int yorg);
-    void (*FillColor8x8PatternRects) (ScrnInfoPtr pScrn, int rop,
-                                      unsigned int planemask, int nBox,
-                                      BoxPtr pBox, int xorg, int yorg,
-                                      XAACacheInfoPtr pCache);
-    void (*FillCacheBltRects) (ScrnInfoPtr pScrn, int rop,
-                               unsigned int planemask, int nBox, BoxPtr pBox,
-                               int xorg, int yorg, XAACacheInfoPtr pCache);
-    void (*FillColorExpandRects) (ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                  unsigned int planemask, int nBox,
-                                  BoxPtr pBox, int xorg, int yorg,
-                                  PixmapPtr pPix);
-    void (*FillCacheExpandRects) (ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                  unsigned int planemask, int nBox, BoxPtr pBox,
-                                  int xorg, int yorg, PixmapPtr pPix);
-    void (*FillImageWriteRects) (ScrnInfoPtr pScrn, int rop,
-                                 unsigned int planemask, int nBox, BoxPtr pBox,
-                                 int xorg, int yorg, PixmapPtr pPix);
-    void (*FillSolidSpans) (ScrnInfoPtr pScrn, int fg, int rop,
-                            unsigned int planemask, int n, DDXPointPtr points,
-                            int *widths, int fSorted);
-    void (*FillMono8x8PatternSpans) (ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                     unsigned int planemask, int n,
-                                     DDXPointPtr points, int *widths,
-                                     int fSorted, int pat0, int pat1,
-                                     int xorg, int yorg);
-    void (*FillColor8x8PatternSpans) (ScrnInfoPtr pScrn, int rop,
-                                      unsigned int planemask, int n,
-                                      DDXPointPtr points, int *widths,
-                                      int fSorted, XAACacheInfoPtr pCache,
-                                      int xorg, int yorg);
-    void (*FillCacheBltSpans) (ScrnInfoPtr pScrn, int rop,
-                               unsigned int planemask, int n,
-                               DDXPointPtr points, int *widths, int fSorted,
-                               XAACacheInfoPtr pCache, int xorg, int yorg);
-    void (*FillColorExpandSpans) (ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                  unsigned int planemask, int n,
-                                  DDXPointPtr points, int *widths, int fSorted,
-                                  int xorg, int yorg, PixmapPtr pPix);
-    void (*FillCacheExpandSpans) (ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                  unsigned int planemask, int n,
-                                  DDXPointPtr ppt, int *pwidth, int fSorted,
-                                  int xorg, int yorg, PixmapPtr pPix);
-    void (*TEGlyphRenderer) (ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                             int skipleft, int startline, unsigned int **glyphs,
-                             int glyphWidth, int fg, int bg, int rop,
-                             unsigned planemask);
-    void (*NonTEGlyphRenderer) (ScrnInfoPtr pScrn, int x, int y, int n,
-                                NonTEGlyphPtr glyphs, BoxPtr pbox, int fg,
-                                int rop, unsigned int planemask);
-    void (*WritePixmap) (ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                         unsigned char *src, int srcwidth, int rop,
-                         unsigned int planemask, int transparency_color,
-                         int bpp, int depth);
-    void (*ReadPixmap) (ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                        unsigned char *dst, int dstwidth, int bpp, int depth);
-    RegionPtr (*CopyArea) (DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
-                           GC * pGC, int srcx, int srcy, int width, int height,
-                           int dstx, int dsty);
-    RegionPtr (*CopyPlane) (DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
-                            int srcx, int srcy, int width, int height, int dstx,
-                            int dsty, unsigned long bitPlane);
-    void (*PushPixelsSolid) (GCPtr pGC, PixmapPtr pBitMap,
-                             DrawablePtr pDrawable, int dx, int dy, int xOrg,
-                             int yOrg);
-    void (*PolyFillRectSolid) (DrawablePtr pDraw, GCPtr pGC, int nrectFill,
-                               xRectangle *prectInit);
-    void (*PolyFillRectStippled) (DrawablePtr pDraw, GCPtr pGC, int nrectFill,
-                                  xRectangle *prectInit);
-    void (*PolyFillRectOpaqueStippled) (DrawablePtr pDraw, GCPtr pGC,
-                                        int nrectFill, xRectangle *prectInit);
-    void (*PolyFillRectTiled) (DrawablePtr pDraw, GCPtr pGC, int nrectFill,
-                               xRectangle *prectInit);
-    void (*FillSpansSolid) (DrawablePtr pDraw, GCPtr pGC, int nInit,
-                            DDXPointPtr ppt, int *pwidth, int fSorted);
-    void (*FillSpansStippled) (DrawablePtr pDraw, GCPtr pGC, int nInit,
-                               DDXPointPtr ppt, int *pwidth, int fSorted);
-    void (*FillSpansOpaqueStippled) (DrawablePtr pDraw, GCPtr pGC, int nInit,
-                                     DDXPointPtr ppt, int *pwidth, int fSorted);
-    void (*FillSpansTiled) (DrawablePtr pDraw, GCPtr pGC, int nInit,
-                            DDXPointPtr ppt, int *pwidth, int fSorted);
-    int (*PolyText8TE) (DrawablePtr pDraw, GCPtr pGC, int x, int y, int count,
-                        char *chars);
-    int (*PolyText16TE) (DrawablePtr pDraw, GCPtr pGC, int x, int y, int count,
-                         unsigned short *chars);
-    void (*ImageText8TE) (DrawablePtr pDraw, GCPtr pGC, int x, int y, int count,
-                          char *chars);
-    void (*ImageText16TE) (DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                           int count, unsigned short *chars);
-    void (*ImageGlyphBltTE) (DrawablePtr pDrawable, GCPtr pGC, int xInit,
-                             int yInit, unsigned int nglyph, CharInfoPtr * ppci,
-                             pointer pglyphBase);
-    void (*PolyGlyphBltTE) (DrawablePtr pDrawable, GCPtr pGC, int xInit,
-                            int yInit, unsigned int nglyph, CharInfoPtr * ppci,
-                            pointer pglyphBase);
-    int (*PolyText8NonTE) (DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                           int count, char *chars);
-    int (*PolyText16NonTE) (DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                            int count, unsigned short *chars);
-    void (*ImageText8NonTE) (DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                             int count, char *chars);
-    void (*ImageText16NonTE) (DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                              int count, unsigned short *chars);
-    void (*ImageGlyphBltNonTE) (DrawablePtr pDrawable, GCPtr pGC, int xInit,
-                                int yInit, unsigned int nglyph,
-                                CharInfoPtr * ppci, pointer pglyphBase);
-    void (*PolyGlyphBltNonTE) (DrawablePtr pDrawable, GCPtr pGC, int xInit,
-                               int yInit, unsigned int nglyph,
-                               CharInfoPtr * ppci, pointer pglyphBase);
-    void (*PolyRectangleThinSolid) (DrawablePtr pDrawable, GCPtr pGC,
-                                    int nRectsInit, xRectangle *pRectsInit);
-    void (*PolylinesWideSolid) (DrawablePtr pDrawable, GCPtr pGC, int mode,
-                                int npt, DDXPointPtr pPts);
-    void (*PolylinesThinSolid) (DrawablePtr pDrawable, GCPtr pGC, int mode,
-                                int npt, DDXPointPtr pPts);
-    void (*PolySegmentThinSolid) (DrawablePtr pDrawable, GCPtr pGC, int nseg,
-                                  xSegment * pSeg);
-    void (*PolylinesThinDashed) (DrawablePtr pDrawable, GCPtr pGC, int mode,
-                                 int npt, DDXPointPtr pPts);
-    void (*PolySegmentThinDashed) (DrawablePtr pDrawable, GCPtr pGC, int nseg,
-                                   xSegment * pSeg);
-    void (*FillPolygonSolid) (DrawablePtr pDrawable, GCPtr pGC, int shape,
-                              int mode, int count, DDXPointPtr ptsIn);
-    void (*FillPolygonStippled) (DrawablePtr pDrawable, GCPtr pGC, int shape,
-                                 int mode, int count, DDXPointPtr ptsIn);
-    void (*FillPolygonOpaqueStippled) (DrawablePtr pDrawable, GCPtr pGC,
-                                       int shape, int mode, int count,
-                                       DDXPointPtr ptsIn);
-    void (*FillPolygonTiled) (DrawablePtr pDrawable, GCPtr pGC, int shape,
-                              int mode, int count, DDXPointPtr ptsIn);
-    void (*PolyFillArcSolid) (DrawablePtr pDraw, GCPtr pGC, int narcs,
-                              xArc * parcs);
-    void (*PutImage) (DrawablePtr pDraw, GCPtr pGC, int depth, int x, int y,
-                      int w, int h, int leftPad, int format, char *pImage);
-    ValidateGCProcPtr ValidateFillSpans;
-    ValidateGCProcPtr ValidateSetSpans;
-    ValidateGCProcPtr ValidatePutImage;
-    ValidateGCProcPtr ValidateCopyArea;
-    ValidateGCProcPtr ValidateCopyPlane;
-    ValidateGCProcPtr ValidatePolyPoint;
-    ValidateGCProcPtr ValidatePolylines;
-    ValidateGCProcPtr ValidatePolySegment;
-    ValidateGCProcPtr ValidatePolyRectangle;
-    ValidateGCProcPtr ValidatePolyArc;
-    ValidateGCProcPtr ValidateFillPolygon;
-    ValidateGCProcPtr ValidatePolyFillRect;
-    ValidateGCProcPtr ValidatePolyFillArc;
-    ValidateGCProcPtr ValidatePolyText8;
-    ValidateGCProcPtr ValidatePolyText16;
-    ValidateGCProcPtr ValidateImageText8;
-    ValidateGCProcPtr ValidateImageText16;
-    ValidateGCProcPtr ValidatePolyGlyphBlt;
-    ValidateGCProcPtr ValidateImageGlyphBlt;
-    ValidateGCProcPtr ValidatePushPixels;
-    void (*ComputeDash) (GCPtr pGC);
-    void (*InitPixmapCache) (ScreenPtr pScreen, RegionPtr areas, pointer data);
-    void (*ClosePixmapCache) (ScreenPtr pScreen);
-    int (*StippledFillChooser) (GCPtr pGC);
-    int (*OpaqueStippledFillChooser) (GCPtr pGC);
-    int (*TiledFillChooser) (GCPtr pGC);
-     XAACacheInfoPtr(*CacheTile) (ScrnInfoPtr Scrn, PixmapPtr pPix);
-     XAACacheInfoPtr(*CacheStipple) (ScrnInfoPtr Scrn, PixmapPtr pPix, int fg,
-                                     int bg);
-     XAACacheInfoPtr(*CacheMonoStipple) (ScrnInfoPtr Scrn, PixmapPtr pPix);
-     XAACacheInfoPtr(*CacheMono8x8Pattern) (ScrnInfoPtr Scrn, int pat0,
-                                            int pat1);
-     XAACacheInfoPtr(*CacheColor8x8Pattern) (ScrnInfoPtr Scrn, PixmapPtr pPix,
-                                             int fg, int bg);
-    void (*WriteBitmapToCache) (ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                                unsigned char *src, int srcwidth, int fg,
-                                int bg);
-    void (*WritePixmapToCache) (ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                                unsigned char *src, int srcwidth, int bpp,
-                                int depth);
-    void (*WriteMono8x8PatternToCache) (ScrnInfoPtr pScrn,
-                                        XAACacheInfoPtr pCache);
-    void (*WriteColor8x8PatternToCache) (ScrnInfoPtr pScrn, PixmapPtr pPix,
-                                         XAACacheInfoPtr pCache);
-    GetImageProcPtr GetImage;
-    GetSpansProcPtr GetSpans;
-    CopyWindowProcPtr CopyWindow;
-    Bool (*SetupForCPUToScreenAlphaTexture2) (ScrnInfoPtr pScrn, int op,
-                                              CARD16 red, CARD16 green,
-                                              CARD16 blue, CARD16 alpha,
-                                              CARD32 maskFormat,
-                                              CARD32 dstFormat, CARD8 *alphaPtr,
-                                              int alphaPitch, int width,
-                                              int height, int flags);
-    Bool (*SetupForCPUToScreenTexture2) (ScrnInfoPtr pScrn, int op,
-                                         CARD32 srcFormat, CARD32 dstFormat,
-                                         CARD8 *texPtr, int texPitch, int width,
-                                         int height, int flags);
-} XAAStateWrapRec, *XAAStateWrapPtr;
-
-static DevPrivateKeyRec XAAStateKeyRec;
-
-#define XAAStateKey (&XAAStateKeyRec)
-
-/* Wrap functions start here */
-#define GET_STATEPRIV_GC(pGC)   XAAStateWrapPtr pStatePriv =\
-(XAAStateWrapPtr)dixLookupPrivate(&(pGC)->pScreen->devPrivates, XAAStateKey)
-
-#define GET_STATEPRIV_SCREEN(pScreen)   XAAStateWrapPtr pStatePriv =\
-(XAAStateWrapPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAStateKey)
-
-#define GET_STATEPRIV_PSCRN(pScrn)   XAAStateWrapPtr pStatePriv =\
-(XAAStateWrapPtr)dixLookupPrivate(&(pScrn)->pScreen->devPrivates, XAAStateKey)
-
-#define STATE_CHECK_SP(pStatePriv) {\
-	ScrnInfoPtr pScrn = pStatePriv->pScrn;\
-	int i = 0;\
-	int need_change = 0;\
-	while(i < pScrn->numEntities) {\
-		if(xf86IsEntityShared(pScrn->entityList[i]) &&\
-		   xf86GetLastScrnFlag(pScrn->entityList[i]) != pScrn->scrnIndex) {\
-			need_change = 1;\
-			xf86SetLastScrnFlag(pScrn->entityList[i],\
-					    pScrn->scrnIndex);\
-		}\
-		i++;\
-	}\
-	if(need_change == 1) (*pStatePriv->RestoreAccelState)(pScrn);\
-}
-
-#define STATE_CHECK_PSCRN(pScrn) {\
-	int i = 0;\
-	int need_change = 0;\
-	while(i < pScrn->numEntities) {\
-		if(xf86IsEntityShared(pScrn->entityList[i]) &&\
-		   xf86GetLastScrnFlag(pScrn->entityList[i]) != pScrn->scrnIndex) {\
-			need_change = 1;\
-			xf86SetLastScrnFlag(pScrn->entityList[i],\
-					    pScrn->scrnIndex);\
-		}\
-		i++;\
-	}\
-	if(need_change == 1) (*pStatePriv->RestoreAccelState)(pScrn);\
-}
-
-static void
-XAAStateWrapSync(ScrnInfoPtr pScrn)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->Sync) (pScrn);
-}
-
-static void
-XAAStateWrapSetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir, int ydir,
-                                       int rop, unsigned int planemask,
-                                       int trans_color)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForScreenToScreenCopy) (pScrn, xdir, ydir, rop,
-                                               planemask, trans_color);
-}
-
-static void
-XAAStateWrapSetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop,
-                              unsigned int planemask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForSolidFill) (pScrn, color, rop, planemask);
-}
-
-static void
-XAAStateWrapSetupForSolidLine(ScrnInfoPtr pScrn, int color, int rop,
-                              unsigned int planemask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForSolidLine) (pScrn, color, rop, planemask);
-}
-
-static void
-XAAStateWrapSetupForDashedLine(ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                               unsigned int planemask, int length,
-                               unsigned char *pattern)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForDashedLine) (pScrn, fg, bg, rop, planemask, length,
-                                       pattern);
-}
-
-static void
-XAAStateWrapSetClippingRectangle(ScrnInfoPtr pScrn, int left, int top,
-                                 int right, int bottom)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetClippingRectangle) (pScrn, left, top, right, bottom);
-}
-
-static void
-XAAStateWrapDisableClipping(ScrnInfoPtr pScrn)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->DisableClipping) (pScrn);
-}
-
-static void
-XAAStateWrapSetupForMono8x8PatternFill(ScrnInfoPtr pScrn, int patx, int paty,
-                                       int fg, int bg, int rop,
-                                       unsigned int planemask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForMono8x8PatternFill) (pScrn, patx, paty, fg, bg, rop,
-                                               planemask);
-}
-
-static void
-XAAStateWrapSetupForColor8x8PatternFill(ScrnInfoPtr pScrn, int patx, int paty,
-                                        int rop, unsigned int planemask,
-                                        int transparency_color)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForColor8x8PatternFill) (pScrn, patx, paty, rop,
-                                                planemask, transparency_color);
-}
-
-static void
-XAAStateWrapSetupForCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, int fg,
-                                               int bg, int rop,
-                                               unsigned int planemask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForCPUToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                       planemask);
-}
-
-static void
-XAAStateWrapSetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
-                                                       int fg, int bg,
-                                                       int rop,
-                                                       unsigned int planemask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForScanlineCPUToScreenColorExpandFill) (pScrn, fg, bg,
-                                                               rop, planemask);
-}
-
-static void
-XAAStateWrapSetupForScreenToScreenColorExpandFill(ScrnInfoPtr pScrn,
-                                                  int fg, int bg, int rop,
-                                                  unsigned int planemask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForScreenToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                          planemask);
-}
-
-static void
-XAAStateWrapSetupForImageWrite(ScrnInfoPtr pScrn, int rop,
-                               unsigned int planemask, int transparency_color,
-                               int bpp, int depth)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForImageWrite) (pScrn, rop, planemask,
-                                       transparency_color, bpp, depth);
-}
-
-static void
-XAAStateWrapSetupForScanlineImageWrite(ScrnInfoPtr pScrn, int rop,
-                                       unsigned int planemask,
-                                       int transparency_color,
-                                       int bpp, int depth)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForScanlineImageWrite) (pScrn, rop, planemask,
-                                               transparency_color, bpp, depth);
-}
-
-static void
-XAAStateWrapSetupForImageRead(ScrnInfoPtr pScrn, int bpp, int depth)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->SetupForImageRead) (pScrn, bpp, depth);
-}
-
-static void
-XAAStateWrapScreenToScreenBitBlt(ScrnInfoPtr pScrn, int nbox,
-                                 DDXPointPtr pptSrc, BoxPtr pbox, int xdir,
-                                 int ydir, int alu, unsigned int planmask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->ScreenToScreenBitBlt) (pScrn, nbox,
-                                         pptSrc, pbox, xdir,
-                                         ydir, alu, planmask);
-}
-
-static void
-XAAStateWrapWriteBitmap(ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                        unsigned char *src, int srcwidth, int skipleft,
-                        int fg, int bg, int rop, unsigned int planemask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->WriteBitmap) (pScrn, x, y, w, h,
-                                src, srcwidth, skipleft,
-                                fg, bg, rop, planemask);
-}
-
-static void
-XAAStateWrapFillSolidRects(ScrnInfoPtr pScrn, int fg, int rop,
-                           unsigned int planemask, int nBox, BoxPtr pBox)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillSolidRects) (pScrn, fg, rop, planemask, nBox, pBox);
-}
-
-static void
-XAAStateWrapFillMono8x8PatternRects(ScrnInfoPtr pScrn, int fg, int bg,
-                                    int rop, unsigned int planemask, int nBox,
-                                    BoxPtr pBox, int pat0, int pat1,
-                                    int xorg, int yorg)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillMono8x8PatternRects) (pScrn, fg, bg,
-                                            rop, planemask, nBox,
-                                            pBox, pat0, pat1, xorg, yorg);
-}
-
-static void
-XAAStateWrapFillColor8x8PatternRects(ScrnInfoPtr pScrn, int rop,
-                                     unsigned int planemask, int nBox,
-                                     BoxPtr pBox, int xorg, int yorg,
-                                     XAACacheInfoPtr pCache)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillColor8x8PatternRects) (pScrn, rop,
-                                             planemask, nBox,
-                                             pBox, xorg, yorg, pCache);
-}
-
-static void
-XAAStateWrapFillCacheBltRects(ScrnInfoPtr pScrn, int rop,
-                              unsigned int planemask, int nBox, BoxPtr pBox,
-                              int xorg, int yorg, XAACacheInfoPtr pCache)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillCacheBltRects) (pScrn, rop,
-                                      planemask, nBox, pBox,
-                                      xorg, yorg, pCache);
-}
-
-static void
-XAAStateWrapFillColorExpandRects(ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                 unsigned int planemask, int nBox,
-                                 BoxPtr pBox, int xorg, int yorg,
-                                 PixmapPtr pPix)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillColorExpandRects) (pScrn, fg, bg, rop,
-                                         planemask, nBox,
-                                         pBox, xorg, yorg, pPix);
-}
-
-static void
-XAAStateWrapFillCacheExpandRects(ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                 unsigned int planemask, int nBox,
-                                 BoxPtr pBox, int xorg, int yorg,
-                                 PixmapPtr pPix)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillCacheExpandRects) (pScrn, fg, bg, rop,
-                                         planemask, nBox,
-                                         pBox, xorg, yorg, pPix);
-}
-
-static void
-XAAStateWrapFillImageWriteRects(ScrnInfoPtr pScrn, int rop,
-                                unsigned int planemask, int nBox, BoxPtr pBox,
-                                int xorg, int yorg, PixmapPtr pPix)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillImageWriteRects) (pScrn, rop,
-                                        planemask, nBox, pBox,
-                                        xorg, yorg, pPix);
-}
-
-static void
-XAAStateWrapFillSolidSpans(ScrnInfoPtr pScrn, int fg, int rop,
-                           unsigned int planemask, int n, DDXPointPtr points,
-                           int *widths, int fSorted)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillSolidSpans) (pScrn, fg, rop,
-                                   planemask, n, points, widths, fSorted);
-}
-
-static void
-XAAStateWrapFillMono8x8PatternSpans(ScrnInfoPtr pScrn, int fg, int bg,
-                                    int rop, unsigned int planemask, int n,
-                                    DDXPointPtr points, int *widths,
-                                    int fSorted, int pat0, int pat1,
-                                    int xorg, int yorg)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillMono8x8PatternSpans) (pScrn, fg, bg,
-                                            rop, planemask, n,
-                                            points, widths,
-                                            fSorted, pat0, pat1, xorg, yorg);
-}
-
-static void
-XAAStateWrapFillColor8x8PatternSpans(ScrnInfoPtr pScrn, int rop,
-                                     unsigned int planemask, int n,
-                                     DDXPointPtr points, int *widths,
-                                     int fSorted, XAACacheInfoPtr pCache,
-                                     int xorg, int yorg)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillColor8x8PatternSpans) (pScrn, rop,
-                                             planemask, n,
-                                             points, widths,
-                                             fSorted, pCache, xorg, yorg);
-}
-
-static void
-XAAStateWrapFillCacheBltSpans(ScrnInfoPtr pScrn, int rop,
-                              unsigned int planemask, int n,
-                              DDXPointPtr points, int *widths,
-                              int fSorted, XAACacheInfoPtr pCache,
-                              int xorg, int yorg)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillCacheBltSpans) (pScrn, rop,
-                                      planemask, n,
-                                      points, widths,
-                                      fSorted, pCache, xorg, yorg);
-}
-
-static void
-XAAStateWrapFillColorExpandSpans(ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                 unsigned int planemask, int n,
-                                 DDXPointPtr points, int *widths, int fSorted,
-                                 int xorg, int yorg, PixmapPtr pPix)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillColorExpandSpans) (pScrn, fg, bg, rop,
-                                         planemask, n,
-                                         points, widths, fSorted,
-                                         xorg, yorg, pPix);
-}
-
-static void
-XAAStateWrapFillCacheExpandSpans(ScrnInfoPtr pScrn, int fg, int bg, int rop,
-                                 unsigned int planemask, int n,
-                                 DDXPointPtr ppt, int *pwidth, int fSorted,
-                                 int xorg, int yorg, PixmapPtr pPix)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->FillCacheExpandSpans) (pScrn, fg, bg, rop,
-                                         planemask, n,
-                                         ppt, pwidth, fSorted,
-                                         xorg, yorg, pPix);
-}
-
-static void
-XAAStateWrapTEGlyphRenderer(ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                            int skipleft, int startline,
-                            unsigned int **glyphs,
-                            int glyphWidth, int fg, int bg, int rop,
-                            unsigned planemask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->TEGlyphRenderer) (pScrn, x, y, w, h,
-                                    skipleft, startline,
-                                    glyphs, glyphWidth, fg, bg, rop, planemask);
-}
-
-static void
-XAAStateWrapNonTEGlyphRenderer(ScrnInfoPtr pScrn, int x, int y, int n,
-                               NonTEGlyphPtr glyphs, BoxPtr pbox,
-                               int fg, int rop, unsigned int planemask)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->NonTEGlyphRenderer) (pScrn, x, y, n,
-                                       glyphs, pbox, fg, rop, planemask);
-}
-
-static void
-XAAStateWrapWritePixmap(ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                        unsigned char *src, int srcwidth, int rop,
-                        unsigned int planemask, int transparency_color,
-                        int bpp, int depth)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->WritePixmap) (pScrn, x, y, w, h,
-                                src, srcwidth, rop,
-                                planemask, transparency_color, bpp, depth);
-}
-
-static void
-XAAStateWrapReadPixmap(ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                       unsigned char *dst, int dstwidth, int bpp, int depth)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->ReadPixmap) (pScrn, x, y, w, h, dst, dstwidth, bpp, depth);
-}
-
-static RegionPtr
-XAAStateWrapCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
-                     GC * pGC, int srcx, int srcy, int width, int height,
-                     int dstx, int dsty)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    return (*pStatePriv->CopyArea) (pSrcDrawable, pDstDrawable,
-                                    pGC, srcx, srcy, width, height, dstx, dsty);
-}
-
-static RegionPtr
-XAAStateWrapCopyPlane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
-                      int srcx, int srcy, int width, int height,
-                      int dstx, int dsty, unsigned long bitPlane)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    return (*pStatePriv->CopyPlane) (pSrc, pDst, pGC,
-                                     srcx, srcy, width, height,
-                                     dstx, dsty, bitPlane);
-}
-
-static void
-XAAStateWrapPushPixelsSolid(GCPtr pGC, PixmapPtr pBitMap,
-                            DrawablePtr pDrawable, int dx, int dy, int xOrg,
-                            int yOrg)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PushPixelsSolid) (pGC, pBitMap,
-                                    pDrawable, dx, dy, xOrg, yOrg);
-}
-
-static void
-XAAStateWrapPolyFillRectSolid(DrawablePtr pDraw, GCPtr pGC, int nrectFill,
-                              xRectangle *prectInit)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolyFillRectSolid) (pDraw, pGC, nrectFill, prectInit);
-}
-
-static void
-XAAStateWrapPolyFillRectStippled(DrawablePtr pDraw, GCPtr pGC, int nrectFill,
-                                 xRectangle *prectInit)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolyFillRectStippled) (pDraw, pGC, nrectFill, prectInit);
-}
-
-static void
-XAAStateWrapPolyFillRectOpaqueStippled(DrawablePtr pDraw, GCPtr pGC,
-                                       int nrectFill, xRectangle *prectInit)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolyFillRectOpaqueStippled) (pDraw, pGC,
-                                               nrectFill, prectInit);
-}
-
-static void
-XAAStateWrapPolyFillRectTiled(DrawablePtr pDraw, GCPtr pGC, int nrectFill,
-                              xRectangle *prectInit)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolyFillRectTiled) (pDraw, pGC, nrectFill, prectInit);
-}
-
-static void
-XAAStateWrapFillSpansSolid(DrawablePtr pDraw, GCPtr pGC, int nInit,
-                           DDXPointPtr ppt, int *pwidth, int fSorted)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->FillSpansSolid) (pDraw, pGC, nInit, ppt, pwidth, fSorted);
-}
-
-static void
-XAAStateWrapFillSpansStippled(DrawablePtr pDraw, GCPtr pGC, int nInit,
-                              DDXPointPtr ppt, int *pwidth, int fSorted)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->FillSpansStippled) (pDraw, pGC, nInit, ppt, pwidth, fSorted);
-}
-
-static void
-XAAStateWrapFillSpansOpaqueStippled(DrawablePtr pDraw, GCPtr pGC, int nInit,
-                                    DDXPointPtr ppt, int *pwidth, int fSorted)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->FillSpansOpaqueStippled) (pDraw, pGC, nInit,
-                                            ppt, pwidth, fSorted);
-}
-
-static void
-XAAStateWrapFillSpansTiled(DrawablePtr pDraw, GCPtr pGC, int nInit,
-                           DDXPointPtr ppt, int *pwidth, int fSorted)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->FillSpansTiled) (pDraw, pGC, nInit, ppt, pwidth, fSorted);
-}
-
-static int
-XAAStateWrapPolyText8TE(DrawablePtr pDraw, GCPtr pGC, int x, int y, int count,
-                        char *chars)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    return (*pStatePriv->PolyText8TE) (pDraw, pGC, x, y, count, chars);
-}
-
-static int
-XAAStateWrapPolyText16TE(DrawablePtr pDraw, GCPtr pGC, int x, int y, int count,
-                         unsigned short *chars)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    return (*pStatePriv->PolyText16TE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAStateWrapImageText8TE(DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                         int count, char *chars)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ImageText8TE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAStateWrapImageText16TE(DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                          int count, unsigned short *chars)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ImageText16TE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAStateWrapImageGlyphBltTE(DrawablePtr pDrawable, GCPtr pGC, int xInit,
-                            int yInit, unsigned int nglyph, CharInfoPtr * ppci,
-                            pointer pglyphBase)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ImageGlyphBltTE) (pDrawable, pGC, xInit,
-                                    yInit, nglyph, ppci, pglyphBase);
-}
-
-static void
-XAAStateWrapPolyGlyphBltTE(DrawablePtr pDrawable, GCPtr pGC, int xInit,
-                           int yInit, unsigned int nglyph, CharInfoPtr * ppci,
-                           pointer pglyphBase)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolyGlyphBltTE) (pDrawable, pGC, xInit,
-                                   yInit, nglyph, ppci, pglyphBase);
-}
-
-static int
-XAAStateWrapPolyText8NonTE(DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                           int count, char *chars)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    return (*pStatePriv->PolyText8NonTE) (pDraw, pGC, x, y, count, chars);
-}
-
-static int
-XAAStateWrapPolyText16NonTE(DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                            int count, unsigned short *chars)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    return (*pStatePriv->PolyText16NonTE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAStateWrapImageText8NonTE(DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                            int count, char *chars)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ImageText8NonTE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAStateWrapImageText16NonTE(DrawablePtr pDraw, GCPtr pGC, int x, int y,
-                             int count, unsigned short *chars)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ImageText16NonTE) (pDraw, pGC, x, y, count, chars);
-}
-
-static void
-XAAStateWrapImageGlyphBltNonTE(DrawablePtr pDrawable, GCPtr pGC, int xInit,
-                               int yInit, unsigned int nglyph,
-                               CharInfoPtr * ppci, pointer pglyphBase)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ImageGlyphBltNonTE) (pDrawable, pGC, xInit,
-                                       yInit, nglyph, ppci, pglyphBase);
-}
-
-static void
-XAAStateWrapPolyGlyphBltNonTE(DrawablePtr pDrawable, GCPtr pGC, int xInit,
-                              int yInit, unsigned int nglyph,
-                              CharInfoPtr * ppci, pointer pglyphBase)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolyGlyphBltNonTE) (pDrawable, pGC, xInit,
-                                      yInit, nglyph, ppci, pglyphBase);
-}
-
-static void
-XAAStateWrapPolyRectangleThinSolid(DrawablePtr pDrawable, GCPtr pGC,
-                                   int nRectsInit, xRectangle *pRectsInit)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolyRectangleThinSolid) (pDrawable, pGC,
-                                           nRectsInit, pRectsInit);
-}
-
-static void
-XAAStateWrapPolylinesWideSolid(DrawablePtr pDrawable, GCPtr pGC, int mode,
-                               int npt, DDXPointPtr pPts)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolylinesWideSolid) (pDrawable, pGC, mode, npt, pPts);
-}
-
-static void
-XAAStateWrapPolylinesThinSolid(DrawablePtr pDrawable, GCPtr pGC, int mode,
-                               int npt, DDXPointPtr pPts)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolylinesThinSolid) (pDrawable, pGC, mode, npt, pPts);
-}
-
-static void
-XAAStateWrapPolySegmentThinSolid(DrawablePtr pDrawable, GCPtr pGC, int nseg,
-                                 xSegment * pSeg)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolySegmentThinSolid) (pDrawable, pGC, nseg, pSeg);
-}
-
-static void
-XAAStateWrapPolylinesThinDashed(DrawablePtr pDrawable, GCPtr pGC, int mode,
-                                int npt, DDXPointPtr pPts)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolylinesThinDashed) (pDrawable, pGC, mode, npt, pPts);
-}
-
-static void
-XAAStateWrapPolySegmentThinDashed(DrawablePtr pDrawable, GCPtr pGC, int nseg,
-                                  xSegment * pSeg)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolySegmentThinDashed) (pDrawable, pGC, nseg, pSeg);
-}
-
-static void
-XAAStateWrapFillPolygonSolid(DrawablePtr pDrawable, GCPtr pGC, int shape,
-                             int mode, int count, DDXPointPtr ptsIn)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->FillPolygonSolid) (pDrawable, pGC, shape, mode, count, ptsIn);
-}
-
-static void
-XAAStateWrapFillPolygonStippled(DrawablePtr pDrawable, GCPtr pGC, int shape,
-                                int mode, int count, DDXPointPtr ptsIn)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->FillPolygonStippled) (pDrawable, pGC, shape,
-                                        mode, count, ptsIn);
-}
-
-static void
-XAAStateWrapFillPolygonOpaqueStippled(DrawablePtr pDrawable, GCPtr pGC,
-                                      int shape, int mode, int count,
-                                      DDXPointPtr ptsIn)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->FillPolygonOpaqueStippled) (pDrawable, pGC,
-                                              shape, mode, count, ptsIn);
-}
-
-static void
-XAAStateWrapFillPolygonTiled(DrawablePtr pDrawable, GCPtr pGC, int shape,
-                             int mode, int count, DDXPointPtr ptsIn)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->FillPolygonTiled) (pDrawable, pGC, shape, mode, count, ptsIn);
-}
-
-static void
-XAAStateWrapPolyFillArcSolid(DrawablePtr pDraw, GCPtr pGC, int narcs,
-                             xArc * parcs)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PolyFillArcSolid) (pDraw, pGC, narcs, parcs);
-}
-
-static void
-XAAStateWrapPutImage(DrawablePtr pDraw, GCPtr pGC, int depth, int x, int y,
-                     int w, int h, int leftPad, int format, char *pImage)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->PutImage) (pDraw, pGC, depth, x, y,
-                             w, h, leftPad, format, pImage);
-}
-
-static void
-XAAStateWrapValidateFillSpans(GCPtr pGC, unsigned long changes,
-                              DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidateFillSpans) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidateSetSpans(GCPtr pGC, unsigned long changes,
-                             DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidateSetSpans) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePutImage(GCPtr pGC, unsigned long changes,
-                             DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePutImage) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidateCopyArea(GCPtr pGC, unsigned long changes,
-                             DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidateCopyArea) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidateCopyPlane(GCPtr pGC, unsigned long changes,
-                              DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidateCopyPlane) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolyPoint(GCPtr pGC, unsigned long changes,
-                              DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolyPoint) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolylines(GCPtr pGC, unsigned long changes,
-                              DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolylines) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolySegment(GCPtr pGC, unsigned long changes,
-                                DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolySegment) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolyRectangle(GCPtr pGC, unsigned long changes,
-                                  DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolyRectangle) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolyArc(GCPtr pGC, unsigned long changes, DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolyArc) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidateFillPolygon(GCPtr pGC, unsigned long changes,
-                                DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidateFillPolygon) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolyFillRect(GCPtr pGC, unsigned long changes,
-                                 DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolyFillRect) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolyFillArc(GCPtr pGC, unsigned long changes,
-                                DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolyFillArc) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolyText8(GCPtr pGC, unsigned long changes,
-                              DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolyText8) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolyText16(GCPtr pGC, unsigned long changes,
-                               DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolyText16) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidateImageText8(GCPtr pGC, unsigned long changes,
-                               DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidateImageText8) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidateImageText16(GCPtr pGC, unsigned long changes,
-                                DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidateImageText16) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePolyGlyphBlt(GCPtr pGC, unsigned long changes,
-                                 DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePolyGlyphBlt) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidateImageGlyphBlt(GCPtr pGC, unsigned long changes,
-                                  DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-    (*pStatePriv->ValidateImageGlyphBlt) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapValidatePushPixels(GCPtr pGC, unsigned long changes,
-                               DrawablePtr pDraw)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ValidatePushPixels) (pGC, changes, pDraw);
-}
-
-static void
-XAAStateWrapComputeDash(GCPtr pGC)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ComputeDash) (pGC);
-}
-
-static void
-XAAStateWrapInitPixmapCache(ScreenPtr pScreen, RegionPtr areas, pointer data)
-{
-    GET_STATEPRIV_SCREEN(pScreen);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->InitPixmapCache) (pScreen, areas, data);
-}
-
-static void
-XAAStateWrapClosePixmapCache(ScreenPtr pScreen)
-{
-    GET_STATEPRIV_SCREEN(pScreen);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->ClosePixmapCache) (pScreen);
-}
-
-static int
-XAAStateWrapStippledFillChooser(GCPtr pGC)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    return (*pStatePriv->StippledFillChooser) (pGC);
-}
-
-static int
-XAAStateWrapOpaqueStippledFillChooser(GCPtr pGC)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    return (*pStatePriv->OpaqueStippledFillChooser) (pGC);
-}
-
-static int
-XAAStateWrapTiledFillChooser(GCPtr pGC)
-{
-    GET_STATEPRIV_GC(pGC);
-    STATE_CHECK_SP(pStatePriv);
-
-    return (*pStatePriv->TiledFillChooser) (pGC);
-}
-
-static XAACacheInfoPtr
-XAAStateWrapCacheTile(ScrnInfoPtr pScrn, PixmapPtr pPix)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    return (*pStatePriv->CacheTile) (pScrn, pPix);
-}
-
-static XAACacheInfoPtr
-XAAStateWrapCacheStipple(ScrnInfoPtr pScrn, PixmapPtr pPix, int fg, int bg)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    return (*pStatePriv->CacheStipple) (pScrn, pPix, fg, bg);
-}
-
-static XAACacheInfoPtr
-XAAStateWrapCacheMonoStipple(ScrnInfoPtr pScrn, PixmapPtr pPix)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    return (*pStatePriv->CacheMonoStipple) (pScrn, pPix);
-}
-
-static XAACacheInfoPtr
-XAAStateWrapCacheMono8x8Pattern(ScrnInfoPtr pScrn, int pat0, int pat1)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    return (*pStatePriv->CacheMono8x8Pattern) (pScrn, pat0, pat1);
-}
-
-static XAACacheInfoPtr
-XAAStateWrapCacheColor8x8Pattern(ScrnInfoPtr pScrn, PixmapPtr pPix,
-                                 int fg, int bg)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    return (*pStatePriv->CacheColor8x8Pattern) (pScrn, pPix, fg, bg);
-}
-
-static void
-XAAStateWrapWriteBitmapToCache(ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                               unsigned char *src, int srcwidth, int fg, int bg)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->WriteBitmapToCache) (pScrn, x, y, w, h,
-                                       src, srcwidth, fg, bg);
-}
-
-static void
-XAAStateWrapWritePixmapToCache(ScrnInfoPtr pScrn, int x, int y, int w, int h,
-                               unsigned char *src, int srcwidth, int bpp,
-                               int depth)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->WritePixmapToCache) (pScrn, x, y, w, h,
-                                       src, srcwidth, bpp, depth);
-}
-
-static void
-XAAStateWrapWriteMono8x8PatternToCache(ScrnInfoPtr pScrn,
-                                       XAACacheInfoPtr pCache)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->WriteMono8x8PatternToCache) (pScrn, pCache);
-}
-
-static void
-XAAStateWrapWriteColor8x8PatternToCache(ScrnInfoPtr pScrn, PixmapPtr pPix,
-                                        XAACacheInfoPtr pCache)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    (*pStatePriv->WriteColor8x8PatternToCache) (pScrn, pPix, pCache);
-}
-
-static void
-XAAStateWrapGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h,
-                     unsigned int format, unsigned long planeMask,
-                     char *pdstLine)
-{
-    GET_STATEPRIV_SCREEN(pDrawable->pScreen);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->GetImage) (pDrawable, sx, sy, w, h,
-                             format, planeMask, pdstLine);
-}
-
-static void
-XAAStateWrapGetSpans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt,
-                     int *pwidth, int nspans, char *pdstStart)
-{
-    GET_STATEPRIV_SCREEN(pDrawable->pScreen);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
-}
-
-static void
-XAAStateWrapCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg,
-                       RegionPtr prgnSrc)
-{
-    GET_STATEPRIV_SCREEN(pWindow->drawable.pScreen);
-    STATE_CHECK_SP(pStatePriv);
-
-    (*pStatePriv->CopyWindow) (pWindow, ptOldOrg, prgnSrc);
-}
-
-static Bool
-XAAStateWrapSetupForCPUToScreenAlphaTexture2(ScrnInfoPtr pScrn,
-                                             int op, CARD16 red,
-                                             CARD16 green,
-                                             CARD16 blue,
-                                             CARD16 alpha,
-                                             CARD32 srcFormat,
-                                             CARD32 dstFormat,
-                                             CARD8 *alphaPtr,
-                                             int alphaPitch,
-                                             int width, int height, int flags)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    return (*pStatePriv->SetupForCPUToScreenAlphaTexture2) (pScrn, op, red,
-                                                            green, blue, alpha,
-                                                            srcFormat,
-                                                            dstFormat, alphaPtr,
-                                                            alphaPitch, width,
-                                                            height, flags);
-}
-
-static Bool
-XAAStateWrapSetupForCPUToScreenTexture2(ScrnInfoPtr pScrn, int op,
-                                        CARD32 srcFormat,
-                                        CARD32 dstFormat,
-                                        CARD8 *texPtr, int texPitch,
-                                        int width, int height, int flags)
-{
-    GET_STATEPRIV_PSCRN(pScrn);
-    STATE_CHECK_PSCRN(pScrn);
-
-    return (*pStatePriv->SetupForCPUToScreenTexture2) (pScrn, op, srcFormat,
-                                                       dstFormat, texPtr,
-                                                       texPitch, width, height,
-                                                       flags);
-}
-
-/* Setup Function */
-Bool
-XAAInitStateWrap(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
-{
-    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-    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;
-    pStatePriv->pScrn = pScrn;
-
-    /* Initialize the last screen to -1 so whenever an accel function
-     * is called the proper state is setup
-     */
-    while (i < pScrn->numEntities) {
-        xf86SetLastScrnFlag(pScrn->entityList[i], -1);
-        i++;
-    }
-/* Do the wrapping */
-    XAA_STATE_WRAP(Sync);
-    XAA_STATE_WRAP(SetupForScreenToScreenCopy);
-    XAA_STATE_WRAP(SetupForSolidFill);
-    XAA_STATE_WRAP(SetupForSolidLine);
-    XAA_STATE_WRAP(SetupForDashedLine);
-    XAA_STATE_WRAP(SetClippingRectangle);
-    XAA_STATE_WRAP(DisableClipping);
-    XAA_STATE_WRAP(SetupForMono8x8PatternFill);
-    XAA_STATE_WRAP(SetupForColor8x8PatternFill);
-    XAA_STATE_WRAP(SetupForCPUToScreenColorExpandFill);
-    XAA_STATE_WRAP(SetupForScanlineCPUToScreenColorExpandFill);
-    XAA_STATE_WRAP(SetupForScreenToScreenColorExpandFill);
-    XAA_STATE_WRAP(SetupForImageWrite);
-    XAA_STATE_WRAP(SetupForScanlineImageWrite);
-    XAA_STATE_WRAP(SetupForImageRead);
-    XAA_STATE_WRAP(ScreenToScreenBitBlt);
-    XAA_STATE_WRAP(WriteBitmap);
-    XAA_STATE_WRAP(FillSolidRects);
-    XAA_STATE_WRAP(FillMono8x8PatternRects);
-    XAA_STATE_WRAP(FillColor8x8PatternRects);
-    XAA_STATE_WRAP(FillCacheBltRects);
-    XAA_STATE_WRAP(FillColorExpandRects);
-    XAA_STATE_WRAP(FillCacheExpandRects);
-    XAA_STATE_WRAP(FillImageWriteRects);
-    XAA_STATE_WRAP(FillSolidSpans);
-    XAA_STATE_WRAP(FillMono8x8PatternSpans);
-    XAA_STATE_WRAP(FillColor8x8PatternSpans);
-    XAA_STATE_WRAP(FillCacheBltSpans);
-    XAA_STATE_WRAP(FillColorExpandSpans);
-    XAA_STATE_WRAP(FillCacheExpandSpans);
-    XAA_STATE_WRAP(TEGlyphRenderer);
-    XAA_STATE_WRAP(NonTEGlyphRenderer);
-    XAA_STATE_WRAP(WritePixmap);
-    XAA_STATE_WRAP(ReadPixmap);
-    XAA_STATE_WRAP(CopyArea);
-    XAA_STATE_WRAP(CopyPlane);
-    XAA_STATE_WRAP(PushPixelsSolid);
-    XAA_STATE_WRAP(PolyFillRectSolid);
-    XAA_STATE_WRAP(PolyFillRectStippled);
-    XAA_STATE_WRAP(PolyFillRectOpaqueStippled);
-    XAA_STATE_WRAP(PolyFillRectTiled);
-    XAA_STATE_WRAP(FillSpansSolid);
-    XAA_STATE_WRAP(FillSpansStippled);
-    XAA_STATE_WRAP(FillSpansOpaqueStippled);
-    XAA_STATE_WRAP(FillSpansTiled);
-    XAA_STATE_WRAP(PolyText8TE);
-    XAA_STATE_WRAP(PolyText16TE);
-    XAA_STATE_WRAP(ImageText8TE);
-    XAA_STATE_WRAP(ImageText16TE);
-    XAA_STATE_WRAP(ImageGlyphBltTE);
-    XAA_STATE_WRAP(PolyGlyphBltTE);
-    XAA_STATE_WRAP(PolyText8NonTE);
-    XAA_STATE_WRAP(PolyText16NonTE);
-    XAA_STATE_WRAP(ImageText8NonTE);
-    XAA_STATE_WRAP(ImageText16NonTE);
-    XAA_STATE_WRAP(ImageGlyphBltNonTE);
-    XAA_STATE_WRAP(PolyGlyphBltNonTE);
-    XAA_STATE_WRAP(PolyRectangleThinSolid);
-    XAA_STATE_WRAP(PolylinesWideSolid);
-    XAA_STATE_WRAP(PolylinesThinSolid);
-    XAA_STATE_WRAP(PolySegmentThinSolid);
-    XAA_STATE_WRAP(PolylinesThinDashed);
-    XAA_STATE_WRAP(PolySegmentThinDashed);
-    XAA_STATE_WRAP(FillPolygonSolid);
-    XAA_STATE_WRAP(FillPolygonStippled);
-    XAA_STATE_WRAP(FillPolygonOpaqueStippled);
-    XAA_STATE_WRAP(FillPolygonTiled);
-    XAA_STATE_WRAP(PolyFillArcSolid);
-    XAA_STATE_WRAP(PutImage);
-    XAA_STATE_WRAP(ValidateFillSpans);
-    XAA_STATE_WRAP(ValidateSetSpans);
-    XAA_STATE_WRAP(ValidatePutImage);
-    XAA_STATE_WRAP(ValidateCopyArea);
-    XAA_STATE_WRAP(ValidateCopyPlane);
-    XAA_STATE_WRAP(ValidatePolyPoint);
-    XAA_STATE_WRAP(ValidatePolylines);
-    XAA_STATE_WRAP(ValidatePolySegment);
-    XAA_STATE_WRAP(ValidatePolyRectangle);
-    XAA_STATE_WRAP(ValidatePolyArc);
-    XAA_STATE_WRAP(ValidateFillPolygon);
-    XAA_STATE_WRAP(ValidatePolyFillRect);
-    XAA_STATE_WRAP(ValidatePolyFillArc);
-    XAA_STATE_WRAP(ValidatePolyText8);
-    XAA_STATE_WRAP(ValidatePolyText16);
-    XAA_STATE_WRAP(ValidateImageText8);
-    XAA_STATE_WRAP(ValidateImageText16);
-    XAA_STATE_WRAP(ValidatePolyGlyphBlt);
-    XAA_STATE_WRAP(ValidateImageGlyphBlt);
-    XAA_STATE_WRAP(ValidatePushPixels);
-    XAA_STATE_WRAP(ComputeDash);
-    XAA_STATE_WRAP(InitPixmapCache);
-    XAA_STATE_WRAP(ClosePixmapCache);
-    XAA_STATE_WRAP(StippledFillChooser);
-    XAA_STATE_WRAP(OpaqueStippledFillChooser);
-    XAA_STATE_WRAP(TiledFillChooser);
-    XAA_STATE_WRAP(CacheTile);
-    XAA_STATE_WRAP(CacheStipple);
-    XAA_STATE_WRAP(CacheMonoStipple);
-    XAA_STATE_WRAP(CacheMono8x8Pattern);
-    XAA_STATE_WRAP(CacheColor8x8Pattern);
-    XAA_STATE_WRAP(WriteBitmapToCache);
-    XAA_STATE_WRAP(WritePixmapToCache);
-    XAA_STATE_WRAP(WriteMono8x8PatternToCache);
-    XAA_STATE_WRAP(WriteColor8x8PatternToCache);
-    XAA_STATE_WRAP(GetImage);
-    XAA_STATE_WRAP(GetSpans);
-    XAA_STATE_WRAP(CopyWindow);
-    XAA_STATE_WRAP(SetupForCPUToScreenAlphaTexture2);
-    XAA_STATE_WRAP(SetupForCPUToScreenTexture2);
-    return TRUE;
-}
diff --git a/hw/xfree86/xaa/xaaStipple.c b/hw/xfree86/xaa/xaaStipple.c
deleted file mode 100644
index fc74e39..0000000
--- a/hw/xfree86/xaa/xaaStipple.c
+++ /dev/null
@@ -1,915 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaacexp.h"
-#include "xf86.h"
-
-static CARD32 *StipplePowerOfTwo(CARD32 *, CARD32 *, int, int, int);
-static CARD32 *StipplePowerOfTwo_Inverted(CARD32 *, CARD32 *, int, int, int);
-static CARD32 *StippleUpTo32(CARD32 *, CARD32 *, int, int, int);
-static CARD32 *StippleUpTo32_Inverted(CARD32 *, CARD32 *, int, int, int);
-static CARD32 *StippleOver32(CARD32 *, CARD32 *, int, int, int);
-static CARD32 *StippleOver32_Inverted(CARD32 *, CARD32 *, int, int, int);
-
-#ifdef TRIPLE_BITS
-#define stipple_scanline_func EXPNAME(XAAStippleScanlineFunc3)
-#define stipple_get_scanline_func EXPNAME(XAAGetStippleScanlineFunc3)
-#else
-#define stipple_scanline_func EXPNAME(XAAStippleScanlineFunc)
-#define stipple_get_scanline_func EXPNAME(XAAGetStippleScanlineFunc)
-#endif
-
-StippleScanlineProcPtr stipple_scanline_func[6] = {
-    StipplePowerOfTwo,
-    StippleUpTo32,
-    StippleOver32,
-    StipplePowerOfTwo_Inverted,
-    StippleUpTo32_Inverted,
-    StippleOver32_Inverted
-};
-
-StippleScanlineProcPtr *
-stipple_get_scanline_func(void)
-{
-    return stipple_scanline_func;
-}
-
-#ifdef FIXEDBASE
-#define DEST(i)	*dest
-#define RETURN(i)	return(dest)
-#else
-#define DEST(i)	dest[i]
-#define RETURN(i)	return(dest + i)
-#endif
-
-/* TRIPLE_BITS pattern expansion */
-#ifdef TRIPLE_BITS
-#define EXPAND_PAT \
-	CARD32 pat1 = byte_expand3[pat & 0xFF], \
-	       pat2 = byte_expand3[(pat & 0xFF00) >> 8], \
-	       pat3 = byte_expand3[(pat & 0xFF0000) >> 16], \
-	       pat4 = byte_expand3[(pat & 0xFF000000) >> 24], \
-	       patA = pat1 | (pat2 << 24), \
-	       patB = (pat2 >> 8) | (pat3 << 16), \
-	       patC = (pat3 >> 16) | (pat4 << 8)
-#ifdef FIXED_BASE
-#define WRITE_PAT1 { \
-	*dest = patA; }
-#define WRITE_PAT2 { \
-	*dest = patA; \
-	*dest = patB; }
-#define WRITE_PAT3 { \
-	*dest = patA; \
-	*dest = patB; \
-	*dest = patC; }
-#else
-#define WRITE_PAT1 { \
-	*(dest++) = patA; }
-#define WRITE_PAT2 { \
-	*(dest) = patA; \
-	*(dest + 1) = patB; \
-	dest += 2; }
-#define WRITE_PAT3 { \
-	*(dest) = patA; \
-	*(dest + 1) = patB; \
-	*(dest + 2) = patC; \
-	dest += 3; }
-#endif
-#endif
-
-#if !defined(FIXEDBASE) && !defined(MSBFIRST) && !defined(TRIPLE_BITS)
-
-unsigned int XAAShiftMasks[32] = {
-    /* gcc is rather pedantic about SHIFT_R(0xFFFFFFFF,32) */
-    0x00000000, SHIFT_R(0xFFFFFFFF, 31),
-    SHIFT_R(0xFFFFFFFF, 30), SHIFT_R(0xFFFFFFFF, 29),
-    SHIFT_R(0xFFFFFFFF, 28), SHIFT_R(0xFFFFFFFF, 27),
-    SHIFT_R(0xFFFFFFFF, 26), SHIFT_R(0xFFFFFFFF, 25),
-    SHIFT_R(0xFFFFFFFF, 24), SHIFT_R(0xFFFFFFFF, 23),
-    SHIFT_R(0xFFFFFFFF, 22), SHIFT_R(0xFFFFFFFF, 21),
-    SHIFT_R(0xFFFFFFFF, 20), SHIFT_R(0xFFFFFFFF, 19),
-    SHIFT_R(0xFFFFFFFF, 18), SHIFT_R(0xFFFFFFFF, 17),
-    SHIFT_R(0xFFFFFFFF, 16), SHIFT_R(0xFFFFFFFF, 15),
-    SHIFT_R(0xFFFFFFFF, 14), SHIFT_R(0xFFFFFFFF, 13),
-    SHIFT_R(0xFFFFFFFF, 12), SHIFT_R(0xFFFFFFFF, 11),
-    SHIFT_R(0xFFFFFFFF, 10), SHIFT_R(0xFFFFFFFF, 9),
-    SHIFT_R(0xFFFFFFFF, 8), SHIFT_R(0xFFFFFFFF, 7),
-    SHIFT_R(0xFFFFFFFF, 6), SHIFT_R(0xFFFFFFFF, 5),
-    SHIFT_R(0xFFFFFFFF, 4), SHIFT_R(0xFFFFFFFF, 3),
-    SHIFT_R(0xFFFFFFFF, 2), SHIFT_R(0xFFFFFFFF, 1)
-};
-
-#endif
-
-void
-#ifdef TRIPLE_BITS
- EXPNAME(XAAFillColorExpandRects3) (
-#else
- EXPNAME(XAAFillColorExpandRects) (
-#endif
-                                      ScrnInfoPtr pScrn,
-                                      int fg, int bg, int rop,
-                                      unsigned int planemask,
-                                      int nBox,
-                                      BoxPtr pBox,
-                                      int xorg, int yorg, PixmapPtr pPix) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *base;
-    Bool TwoPass = FALSE, FirstPass = TRUE;
-    StippleScanlineProcPtr StippleFunc, FirstFunc, SecondFunc;
-    int stipplewidth = pPix->drawable.width;
-    int stippleheight = pPix->drawable.height;
-    int srcwidth = pPix->devKind;
-    int dwords, srcy, srcx, funcNo = 2, h;
-    unsigned char *src = (unsigned char *) pPix->devPrivate.ptr;
-    unsigned char *srcp;
-    int flag;
-
-    if (stipplewidth <= 32) {
-        if (stipplewidth & (stipplewidth - 1))
-            funcNo = 1;
-        else
-            funcNo = 0;
-    }
-    StippleFunc = stipple_scanline_func[funcNo];
-    SecondFunc = stipple_scanline_func[funcNo];
-    FirstFunc = stipple_scanline_func[funcNo + 3];
-
-#ifdef TRIPLE_BITS
-    if ((bg == -1) ||
-        (!(infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY) &&
-         (!(infoRec->CPUToScreenColorExpandFillFlags & RGB_EQUAL) ||
-          (CHECK_RGB_EQUAL(bg))))) {
-#else
-    if ((bg == -1) ||
-        !(infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
-#endif
-        /* one pass */
-    }
-    else if ((rop == GXcopy) && infoRec->FillSolidRects) {
-        /* one pass but we fill background rects first */
-        (*infoRec->FillSolidRects) (pScrn, bg, rop, planemask, nBox, pBox);
-        bg = -1;
-    }
-    else {
-        /* gotta do two passes */
-        TwoPass = TRUE;
-    }
-
-    if (!TwoPass)
-        (*infoRec->SetupForCPUToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                        planemask);
-
-    while (nBox--) {
-#ifdef TRIPLE_BITS
-        dwords = (3 * (pBox->x2 - pBox->x1) + 31) >> 5;
-#else
-        dwords = (pBox->x2 - pBox->x1 + 31) >> 5;
-#endif
-
- SECOND_PASS:
-        if (TwoPass) {
-            (*infoRec->SetupForCPUToScreenColorExpandFill) (pScrn,
-                                                            (FirstPass) ? bg :
-                                                            fg, -1, rop,
-                                                            planemask);
-            StippleFunc = (FirstPass) ? FirstFunc : SecondFunc;
-        }
-
-        h = pBox->y2 - pBox->y1;
-        flag = (infoRec->CPUToScreenColorExpandFillFlags
-                & CPU_TRANSFER_PAD_QWORD) && ((dwords * h) & 0x01);
-
-        (*infoRec->SubsequentCPUToScreenColorExpandFill) (pScrn, pBox->x1,
-                                                          pBox->y1,
-                                                          pBox->x2 - pBox->x1,
-                                                          h, 0);
-
-        base = (CARD32 *) infoRec->ColorExpandBase;
-
-        srcy = (pBox->y1 - yorg) % stippleheight;
-        if (srcy < 0)
-            srcy += stippleheight;
-        srcx = (pBox->x1 - xorg) % stipplewidth;
-        if (srcx < 0)
-            srcx += stipplewidth;
-
-        srcp = (srcwidth * srcy) + src;
-
-#ifndef FIXEDBASE
-        if ((dwords * h) <= infoRec->ColorExpandRange) {
-            while (h--) {
-                base =
-                    (*StippleFunc) (base, (CARD32 *) srcp, srcx, stipplewidth,
-                                    dwords);
-                srcy++;
-                srcp += srcwidth;
-                if (srcy >= stippleheight) {
-                    srcy = 0;
-                    srcp = src;
-                }
-            }
-        }
-        else
-#endif
-            while (h--) {
-                (*StippleFunc) (base, (CARD32 *) srcp, srcx, stipplewidth,
-                                dwords);
-                srcy++;
-                srcp += srcwidth;
-                if (srcy >= stippleheight) {
-                    srcy = 0;
-                    srcp = src;
-                }
-            }
-
-        if (flag) {
-            base = (CARD32 *) infoRec->ColorExpandBase;
-            base[0] = 0x00000000;
-        }
-
-        if (TwoPass) {
-            if (FirstPass) {
-                FirstPass = FALSE;
-                goto SECOND_PASS;
-            }
-            else
-                FirstPass = TRUE;
-        }
-
-        pBox++;
-    }
-
-    if (infoRec->CPUToScreenColorExpandFillFlags & SYNC_AFTER_COLOR_EXPAND)
-        (*infoRec->Sync) (pScrn);
-    else
-        SET_SYNC_FLAG(infoRec);
-}
-
-void
-#ifdef TRIPLE_BITS
- EXPNAME(XAAFillColorExpandSpans3) (
-#else
- EXPNAME(XAAFillColorExpandSpans) (
-#endif
-                                      ScrnInfoPtr pScrn,
-                                      int fg, int bg, int rop,
-                                      unsigned int planemask,
-                                      int n,
-                                      DDXPointPtr ppt,
-                                      int *pwidth,
-                                      int fSorted,
-                                      int xorg, int yorg, PixmapPtr pPix) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *base;
-    Bool TwoPass = FALSE, FirstPass = TRUE;
-    StippleScanlineProcPtr StippleFunc, FirstFunc, SecondFunc;
-    int stipplewidth = pPix->drawable.width;
-    int stippleheight = pPix->drawable.height;
-    int dwords, srcy, srcx, funcNo = 2;
-    unsigned char *srcp;
-
-    if (stipplewidth <= 32) {
-        if (stipplewidth & (stipplewidth - 1))
-            funcNo = 1;
-        else
-            funcNo = 0;
-    }
-    StippleFunc = stipple_scanline_func[funcNo];
-    SecondFunc = stipple_scanline_func[funcNo];
-    FirstFunc = stipple_scanline_func[funcNo + 3];
-
-#ifdef TRIPLE_BITS
-    if ((bg == -1) ||
-        (!(infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY) &&
-         (!(infoRec->CPUToScreenColorExpandFillFlags & RGB_EQUAL) ||
-          (CHECK_RGB_EQUAL(bg))))) {
-#else
-    if ((bg == -1) ||
-        !(infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
-#endif
-        /* one pass */
-    }
-    else if ((rop == GXcopy) && infoRec->FillSolidSpans) {
-        /* one pass but we fill background rects first */
-        (*infoRec->FillSolidSpans) (pScrn, bg, rop, planemask, n, ppt, pwidth,
-                                    fSorted);
-        bg = -1;
-    }
-    else {
-        /* gotta do two passes */
-        TwoPass = TRUE;
-    }
-
-    if (!TwoPass)
-        (*infoRec->SetupForCPUToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                        planemask);
-
-    while (n--) {
-#ifdef TRIPLE_BITS
-        dwords = (3 * *pwidth + 31) >> 5;
-#else
-        dwords = (*pwidth + 31) >> 5;
-#endif
-
-        srcy = (ppt->y - yorg) % stippleheight;
-        if (srcy < 0)
-            srcy += stippleheight;
-        srcx = (ppt->x - xorg) % stipplewidth;
-        if (srcx < 0)
-            srcx += stipplewidth;
-
-        srcp = (pPix->devKind * srcy) + (unsigned char *) pPix->devPrivate.ptr;
-
- SECOND_PASS:
-        if (TwoPass) {
-            (*infoRec->SetupForCPUToScreenColorExpandFill) (pScrn,
-                                                            (FirstPass) ? bg :
-                                                            fg, -1, rop,
-                                                            planemask);
-            StippleFunc = (FirstPass) ? FirstFunc : SecondFunc;
-        }
-
-        (*infoRec->SubsequentCPUToScreenColorExpandFill) (pScrn, ppt->x, ppt->y,
-                                                          *pwidth, 1, 0);
-
-        base = (CARD32 *) infoRec->ColorExpandBase;
-
-        (*StippleFunc) (base, (CARD32 *) srcp, srcx, stipplewidth, dwords);
-
-        if ((infoRec->CPUToScreenColorExpandFillFlags & CPU_TRANSFER_PAD_QWORD)
-            && (dwords & 0x01)) {
-            base = (CARD32 *) infoRec->ColorExpandBase;
-            base[0] = 0x00000000;
-        }
-
-        if (TwoPass) {
-            if (FirstPass) {
-                FirstPass = FALSE;
-                goto SECOND_PASS;
-            }
-            else
-                FirstPass = TRUE;
-        }
-
-        ppt++;
-        pwidth++;
-    }
-
-    if (infoRec->CPUToScreenColorExpandFillFlags & SYNC_AFTER_COLOR_EXPAND)
-        (*infoRec->Sync) (pScrn);
-    else
-        SET_SYNC_FLAG(infoRec);
-}
-
-#ifndef FIXEDBASE
-
-void
-#ifdef TRIPLE_BITS
- EXPNAME(XAAFillScanlineColorExpandRects3) (
-#else
- EXPNAME(XAAFillScanlineColorExpandRects) (
-#endif
-                                              ScrnInfoPtr pScrn,
-                                              int fg, int bg, int rop,
-                                              unsigned int planemask,
-                                              int nBox,
-                                              BoxPtr pBox,
-                                              int xorg, int yorg,
-                                              PixmapPtr pPix) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *base;
-    Bool TwoPass = FALSE, FirstPass = TRUE;
-    StippleScanlineProcPtr StippleFunc, FirstFunc, SecondFunc;
-    int stipplewidth = pPix->drawable.width;
-    int stippleheight = pPix->drawable.height;
-    int srcwidth = pPix->devKind;
-    int dwords, srcy, srcx, funcNo = 2, bufferNo, h;
-    unsigned char *src = pPix->devPrivate.ptr;
-    unsigned char *srcp;
-
-    if (stipplewidth <= 32) {
-        if (stipplewidth & (stipplewidth - 1))
-            funcNo = 1;
-        else
-            funcNo = 0;
-    }
-    StippleFunc = stipple_scanline_func[funcNo];
-    SecondFunc = stipple_scanline_func[funcNo];
-    FirstFunc = stipple_scanline_func[funcNo + 3];
-
-#ifdef TRIPLE_BITS
-    if ((bg == -1) ||
-        (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)
-         && (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags & RGB_EQUAL) ||
-             (CHECK_RGB_EQUAL(bg))))) {
-#else
-    if ((bg == -1) ||
-        !(infoRec->
-          ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
-#endif
-        /* one pass */
-    }
-    else if ((rop == GXcopy) && infoRec->FillSolidRects) {
-        /* one pass but we fill background rects first */
-        (*infoRec->FillSolidRects) (pScrn, bg, rop, planemask, nBox, pBox);
-        bg = -1;
-    }
-    else {
-        /* gotta do two passes */
-        TwoPass = TRUE;
-    }
-
-    if (!TwoPass)
-        (*infoRec->SetupForScanlineCPUToScreenColorExpandFill) (pScrn, fg, bg,
-                                                                rop, planemask);
-
-    while (nBox--) {
-#ifdef TRIPLE_BITS
-        dwords = (3 * (pBox->x2 - pBox->x1) + 31) >> 5;
-#else
-        dwords = (pBox->x2 - pBox->x1 + 31) >> 5;
-#endif
-
- SECOND_PASS:
-        if (TwoPass) {
-            (*infoRec->SetupForScanlineCPUToScreenColorExpandFill) (pScrn,
-                                                                    (FirstPass)
-                                                                    ? bg : fg,
-                                                                    -1, rop,
-                                                                    planemask);
-            StippleFunc = (FirstPass) ? FirstFunc : SecondFunc;
-        }
-
-        h = pBox->y2 - pBox->y1;
-
-        (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill) (pScrn,
-                                                                  pBox->x1,
-                                                                  pBox->y1,
-                                                                  pBox->x2 -
-                                                                  pBox->x1, h,
-                                                                  0);
-
-        bufferNo = 0;
-
-        srcy = (pBox->y1 - yorg) % stippleheight;
-        if (srcy < 0)
-            srcy += stippleheight;
-        srcx = (pBox->x1 - xorg) % stipplewidth;
-        if (srcx < 0)
-            srcx += stipplewidth;
-
-        srcp = (srcwidth * srcy) + src;
-
-        while (h--) {
-            base = (CARD32 *) infoRec->ScanlineColorExpandBuffers[bufferNo];
-            (*StippleFunc) (base, (CARD32 *) srcp, srcx, stipplewidth, dwords);
-            (*infoRec->SubsequentColorExpandScanline) (pScrn, bufferNo++);
-            if (bufferNo >= infoRec->NumScanlineColorExpandBuffers)
-                bufferNo = 0;
-            srcy++;
-            srcp += srcwidth;
-            if (srcy >= stippleheight) {
-                srcy = 0;
-                srcp = src;
-            }
-        }
-
-        if (TwoPass) {
-            if (FirstPass) {
-                FirstPass = FALSE;
-                goto SECOND_PASS;
-            }
-            else
-                FirstPass = TRUE;
-        }
-
-        pBox++;
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-#ifdef TRIPLE_BITS
- EXPNAME(XAAFillScanlineColorExpandSpans3) (
-#else
- EXPNAME(XAAFillScanlineColorExpandSpans) (
-#endif
-                                              ScrnInfoPtr pScrn,
-                                              int fg, int bg, int rop,
-                                              unsigned int planemask,
-                                              int n,
-                                              DDXPointPtr ppt,
-                                              int *pwidth,
-                                              int fSorted,
-                                              int xorg, int yorg,
-                                              PixmapPtr pPix) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *base;
-    Bool TwoPass = FALSE, FirstPass = TRUE;
-    StippleScanlineProcPtr StippleFunc, FirstFunc, SecondFunc;
-    int stipplewidth = pPix->drawable.width;
-    int stippleheight = pPix->drawable.height;
-    int dwords, srcy, srcx, funcNo = 2;
-    unsigned char *srcp;
-
-    if (stipplewidth <= 32) {
-        if (stipplewidth & (stipplewidth - 1))
-            funcNo = 1;
-        else
-            funcNo = 0;
-    }
-    StippleFunc = stipple_scanline_func[funcNo];
-    SecondFunc = stipple_scanline_func[funcNo];
-    FirstFunc = stipple_scanline_func[funcNo + 3];
-
-#ifdef TRIPLE_BITS
-    if ((bg == -1) ||
-        (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)
-         && (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags & RGB_EQUAL) ||
-             (CHECK_RGB_EQUAL(bg))))) {
-#else
-    if ((bg == -1) ||
-        !(infoRec->
-          ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
-#endif
-        /* one pass */
-    }
-    else if ((rop == GXcopy) && infoRec->FillSolidSpans) {
-        /* one pass but we fill background rects first */
-        (*infoRec->FillSolidSpans) (pScrn, bg, rop, planemask, n, ppt, pwidth,
-                                    fSorted);
-        bg = -1;
-    }
-    else {
-        /* gotta do two passes */
-        TwoPass = TRUE;
-    }
-
-    if (!TwoPass)
-        (*infoRec->SetupForScanlineCPUToScreenColorExpandFill) (pScrn, fg, bg,
-                                                                rop, planemask);
-
-    while (n--) {
-#ifdef TRIPLE_BITS
-        dwords = (3 * *pwidth + 31) >> 5;
-#else
-        dwords = (*pwidth + 31) >> 5;
-#endif
-
-        srcy = (ppt->y - yorg) % stippleheight;
-        if (srcy < 0)
-            srcy += stippleheight;
-        srcx = (ppt->x - xorg) % stipplewidth;
-        if (srcx < 0)
-            srcx += stipplewidth;
-
-        srcp = (pPix->devKind * srcy) + (unsigned char *) pPix->devPrivate.ptr;
-
- SECOND_PASS:
-        if (TwoPass) {
-            (*infoRec->SetupForScanlineCPUToScreenColorExpandFill) (pScrn,
-                                                                    (FirstPass)
-                                                                    ? bg : fg,
-                                                                    -1, rop,
-                                                                    planemask);
-            StippleFunc = (FirstPass) ? FirstFunc : SecondFunc;
-        }
-
-        (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill) (pScrn, ppt->x,
-                                                                  ppt->y,
-                                                                  *pwidth, 1,
-                                                                  0);
-
-        base = (CARD32 *) infoRec->ScanlineColorExpandBuffers[0];
-
-        (*StippleFunc) (base, (CARD32 *) srcp, srcx, stipplewidth, dwords);
-        (*infoRec->SubsequentColorExpandScanline) (pScrn, 0);
-
-        if (TwoPass) {
-            if (FirstPass) {
-                FirstPass = FALSE;
-                goto SECOND_PASS;
-            }
-            else
-                FirstPass = TRUE;
-        }
-
-        ppt++;
-        pwidth++;
-    }
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-#endif
-
-static CARD32 *
-StipplePowerOfTwo(CARD32 *dest, CARD32 *src, int shift, int width, int dwords)
-{
-    CARD32 pat = *src;
-
-    if (width < 32) {
-        pat &= XAAShiftMasks[width];
-        while (width < 32) {
-            pat |= SHIFT_L(pat, width);
-            width <<= 1;
-        }
-    }
-
-    if (shift)
-        pat = SHIFT_R(pat, shift) | SHIFT_L(pat, 32 - shift);
-
-#ifdef MSBFIRST
-    pat = SWAP_BITS_IN_BYTES(pat);
-#endif
-
-#ifdef TRIPLE_BITS
-    {
-        EXPAND_PAT;
-
-        while (dwords >= 3) {
-            WRITE_PAT3;
-            dwords -= 3;
-        }
-        if (dwords == 2) {
-            WRITE_PAT2;
-        }
-        else if (dwords == 1) {
-            WRITE_PAT1;
-        }
-
-        return dest;
-    }
-#else                           /* TRIPLE_BITS */
-    while (dwords >= 4) {
-        DEST(0) = pat;
-        DEST(1) = pat;
-        DEST(2) = pat;
-        DEST(3) = pat;
-        dwords -= 4;
-#ifndef FIXEDBASE
-        dest += 4;
-#endif
-    }
-
-    if (!dwords)
-        return dest;
-    DEST(0) = pat;
-    if (dwords == 1)
-        RETURN(1);
-    DEST(1) = pat;
-    if (dwords == 2)
-        RETURN(2);
-    DEST(2) = pat;
-    RETURN(3);
-#endif                          /* TRIPLE_BITS */
-}
-
-static CARD32 *
-StipplePowerOfTwo_Inverted(CARD32 *dest, CARD32 *src,
-                           int shift, int width, int dwords)
-{
-    CARD32 pat = *src;
-
-    if (width < 32) {
-        pat &= XAAShiftMasks[width];
-        while (width < 32) {
-            pat |= SHIFT_L(pat, width);
-            width <<= 1;
-        }
-    }
-
-    if (shift)
-        pat = SHIFT_R(pat, shift) | SHIFT_L(pat, 32 - shift);
-
-#ifdef MSBFIRST
-    pat = SWAP_BITS_IN_BYTES(pat);
-#endif
-
-    pat = ~pat;
-
-#ifdef TRIPLE_BITS
-    {
-        EXPAND_PAT;
-
-        while (dwords >= 3) {
-            WRITE_PAT3;
-            dwords -= 3;
-        }
-        if (dwords == 2) {
-            WRITE_PAT2;
-        }
-        else if (dwords == 1) {
-            WRITE_PAT1;
-        }
-
-        return dest;
-    }
-#else                           /* TRIPLE_BITS */
-    while (dwords >= 4) {
-        DEST(0) = pat;
-        DEST(1) = pat;
-        DEST(2) = pat;
-        DEST(3) = pat;
-        dwords -= 4;
-#ifndef FIXEDBASE
-        dest += 4;
-#endif
-    }
-
-    if (!dwords)
-        return dest;
-    DEST(0) = pat;
-    if (dwords == 1)
-        RETURN(1);
-    DEST(1) = pat;
-    if (dwords == 2)
-        RETURN(2);
-    DEST(2) = pat;
-    RETURN(3);
-#endif                          /* TRIPLE_BITS */
-}
-
-static CARD32 *
-StippleUpTo32(CARD32 *base, CARD32 *src, int shift, int width, int dwords)
-{
-    CARD32 pat = *src & XAAShiftMasks[width];
-
-    while (width <= 15) {
-        pat |= SHIFT_L(pat, width);
-        width <<= 1;
-    }
-    pat |= SHIFT_L(pat, width);
-
-    while (dwords--) {
-        CARD32 bits = SHIFT_R(pat, shift) | SHIFT_L(pat, width - shift);
-
-#ifdef TRIPLE_BITS
-        if (dwords >= 2) {
-            WRITE_BITS3(bits);
-            dwords -= 2;
-        }
-        else if (dwords > 0) {
-            WRITE_BITS2(bits);
-            dwords--;
-        }
-        else {
-            WRITE_BITS1(bits);
-        }
-#else
-        WRITE_BITS(bits);
-#endif
-
-        shift += 32;
-        shift %= width;
-    }
-    return base;
-}
-
-static CARD32 *
-StippleUpTo32_Inverted(CARD32 *base, CARD32 *src,
-                       int shift, int width, int dwords)
-{
-    CARD32 pat = *src & XAAShiftMasks[width];
-
-    while (width <= 15) {
-        pat |= SHIFT_L(pat, width);
-        width <<= 1;
-    }
-    pat |= SHIFT_L(pat, width);
-
-    while (dwords--) {
-        CARD32 bits = ~(SHIFT_R(pat, shift) | SHIFT_L(pat, width - shift));
-
-#ifdef TRIPLE_BITS
-        if (dwords >= 2) {
-            WRITE_BITS3(bits);
-            dwords -= 2;
-        }
-        else if (dwords > 0) {
-            WRITE_BITS2(bits);
-            dwords--;
-        }
-        else {
-            WRITE_BITS1(bits);
-        }
-#else
-        WRITE_BITS(bits);
-#endif
-
-        shift += 32;
-        shift %= width;
-    }
-    return base;
-}
-
-static CARD32 *
-StippleOver32(CARD32 *base, CARD32 *src, int offset, int width, int dwords)
-{
-    CARD32 *srcp;
-    CARD32 bits;
-    int bitsleft, shift, usable;
-
-    while (dwords--) {
-        bitsleft = width - offset;
-        srcp = src + (offset >> 5);
-        shift = offset & 31;
-        usable = 32 - shift;
-
-        if (bitsleft < 32) {
-            if (bitsleft <= usable) {
-                bits = SHIFT_L(*src, bitsleft) |
-                    (SHIFT_R(*srcp, shift) & XAAShiftMasks[bitsleft]);
-            }
-            else {
-                bits = SHIFT_L(*src, bitsleft) |
-                    (SHIFT_L(srcp[1], usable) & XAAShiftMasks[bitsleft]) |
-                    (SHIFT_R(*srcp, shift) & XAAShiftMasks[usable]);
-            }
-        }
-        else if (shift)
-            bits = SHIFT_R(*srcp, shift) | SHIFT_L(srcp[1], usable);
-        else
-            bits = *srcp;
-
-#ifdef TRIPLE_BITS
-        if (dwords >= 2) {
-            WRITE_BITS3(bits);
-            dwords -= 2;
-        }
-        else if (dwords > 0) {
-            WRITE_BITS2(bits);
-            dwords--;
-        }
-        else {
-            WRITE_BITS1(bits);
-        }
-#else
-        WRITE_BITS(bits);
-#endif
-
-        offset += 32;
-        offset %= width;
-    }
-    return base;
-}
-
-static CARD32 *
-StippleOver32_Inverted(CARD32 *base, CARD32 *src,
-                       int offset, int width, int dwords)
-{
-    CARD32 *srcp;
-    CARD32 bits;
-    int bitsleft, shift, usable;
-
-    while (dwords--) {
-        bitsleft = width - offset;
-        srcp = src + (offset >> 5);
-        shift = offset & 31;
-        usable = 32 - shift;
-
-        if (bitsleft < 32) {
-            if (bitsleft <= usable) {
-                bits = SHIFT_L(*src, bitsleft) |
-                    (SHIFT_R(*srcp, shift) & XAAShiftMasks[bitsleft]);
-            }
-            else {
-                bits = SHIFT_L(*src, bitsleft) |
-                    (SHIFT_L(srcp[1], usable) & XAAShiftMasks[bitsleft]) |
-                    (SHIFT_R(*srcp, shift) & XAAShiftMasks[usable]);
-            }
-        }
-        else if (shift)
-            bits = SHIFT_R(*srcp, shift) | SHIFT_L(srcp[1], usable);
-        else
-            bits = *srcp;
-
-        bits = ~bits;
-
-#ifdef TRIPLE_BITS
-        if (dwords >= 2) {
-            WRITE_BITS3(bits);
-            dwords -= 2;
-        }
-        else if (dwords > 0) {
-            WRITE_BITS2(bits);
-            dwords--;
-        }
-        else {
-            WRITE_BITS1(bits);
-        }
-#else
-        WRITE_BITS(bits);
-#endif
-
-        offset += 32;
-        offset %= width;
-    }
-    return base;
-}
diff --git a/hw/xfree86/xaa/xaaTEGlyph.c b/hw/xfree86/xaa/xaaTEGlyph.c
deleted file mode 100644
index 2926c1d..0000000
--- a/hw/xfree86/xaa/xaaTEGlyph.c
+++ /dev/null
@@ -1,1083 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xaa.h"
-#include "xaalocal.h"
-#include "xaacexp.h"
-#include "xf86.h"
-
-/* scanline function for TRIPLE_BITS_24BPP */
-static CARD32 *DrawTextScanline3(CARD32 *base, CARD32 *mem, int width);
-
-/* Loop unrolled functions for common font widths */
-static CARD32 *DrawTETextScanlineGeneric(CARD32 *base, unsigned int **glyphp,
-                                         int line, int width, int glyphwidth);
-static CARD32 *DrawTETextScanlineWidth7(CARD32 *base, unsigned int **glyphp,
-                                        int line, int width, int glyphwidth);
-static CARD32 *DrawTETextScanlineWidth10(CARD32 *base, unsigned int **glyphp,
-                                         int line, int width, int glyphwidth);
-static CARD32 *DrawTETextScanlineWidth12(CARD32 *base, unsigned int **glyphp,
-                                         int line, int width, int glyphwidth);
-static CARD32 *DrawTETextScanlineWidth14(CARD32 *base, unsigned int **glyphp,
-                                         int line, int width, int glyphwidth);
-static CARD32 *DrawTETextScanlineWidth16(CARD32 *base, unsigned int **glyphp,
-                                         int line, int width, int glyphwidth);
-static CARD32 *DrawTETextScanlineWidth18(CARD32 *base, unsigned int **glyphp,
-                                         int line, int width, int glyphwidth);
-static CARD32 *DrawTETextScanlineWidth24(CARD32 *base, unsigned int **glyphp,
-                                         int line, int width, int glyphwidth);
-
-#ifdef USEASSEMBLER
-#ifdef FIXEDBASE
-#ifdef MSBFIRST
-CARD32 *DrawTETextScanlineWidth6PMSBFirstFixedBase(CARD32 *base,
-                                                   unsigned int **glyphp,
-                                                   int line, int width,
-                                                   int glyphwidth);
-CARD32 *DrawTETextScanlineWidth8PMSBFirstFixedBase(CARD32 *base,
-                                                   unsigned int **glyphp,
-                                                   int line, int width,
-                                                   int glyphwidth);
-CARD32 *DrawTETextScanlineWidth9PMSBFirstFixedBase(CARD32 *base,
-                                                   unsigned int **glyphp,
-                                                   int line, int width,
-                                                   int glyphwidth);
-#else
-CARD32 *DrawTETextScanlineWidth6PLSBFirstFixedBase(CARD32 *base,
-                                                   unsigned int **glyphp,
-                                                   int line, int width,
-                                                   int glyphwidth);
-CARD32 *DrawTETextScanlineWidth8PLSBFirstFixedBase(CARD32 *base,
-                                                   unsigned int **glyphp,
-                                                   int line, int width,
-                                                   int glyphwidth);
-CARD32 *DrawTETextScanlineWidth9PLSBFirstFixedBase(CARD32 *base,
-                                                   unsigned int **glyphp,
-                                                   int line, int width,
-                                                   int glyphwidth);
-#endif
-#else
-#ifdef MSBFIRST
-CARD32 *DrawTETextScanlineWidth6PMSBFirst(CARD32 *base, unsigned int **glyphp,
-                                          int line, int width, int glyphwidth);
-CARD32 *DrawTETextScanlineWidth8PMSBFirst(CARD32 *base, unsigned int **glyphp,
-                                          int line, int width, int glyphwidth);
-CARD32 *DrawTETextScanlineWidth9PMSBFirst(CARD32 *base, unsigned int **glyphp,
-                                          int line, int width, int glyphwidth);
-#else
-CARD32 *DrawTETextScanlineWidth6PLSBFirst(CARD32 *base, unsigned int **glyphp,
-                                          int line, int width, int glyphwidth);
-CARD32 *DrawTETextScanlineWidth8PLSBFirst(CARD32 *base, unsigned int **glyphp,
-                                          int line, int width, int glyphwidth);
-CARD32 *DrawTETextScanlineWidth9PLSBFirst(CARD32 *base, unsigned int **glyphp,
-                                          int line, int width, int glyphwidth);
-#endif
-#endif
-#else
-static CARD32 *DrawTETextScanlineWidth6(CARD32 *base, unsigned int **glyphp,
-                                        int line, int width, int glyphwidth);
-static CARD32 *DrawTETextScanlineWidth8(CARD32 *base, unsigned int **glyphp,
-                                        int line, int width, int glyphwidth);
-static CARD32 *DrawTETextScanlineWidth9(CARD32 *base, unsigned int **glyphp,
-                                        int line, int width, int glyphwidth);
-#endif
-
-#define glyph_scanline_func EXPNAME(XAAGlyphScanlineFunc)
-#define glyph_get_scanline_func EXPNAME(XAAGetGlyphScanlineFunc)
-
-GlyphScanlineFuncPtr glyph_scanline_func[32] = {
-    DrawTETextScanlineGeneric, DrawTETextScanlineGeneric,
-    DrawTETextScanlineGeneric, DrawTETextScanlineGeneric,
-    DrawTETextScanlineGeneric,
-#ifdef USEASSEMBLER
-#ifdef FIXEDBASE
-#ifdef MSBFIRST
-    DrawTETextScanlineWidth6PMSBFirstFixedBase,
-    DrawTETextScanlineWidth7,
-    DrawTETextScanlineWidth8PMSBFirstFixedBase,
-    DrawTETextScanlineWidth9PMSBFirstFixedBase,
-#else
-    DrawTETextScanlineWidth6PLSBFirstFixedBase,
-    DrawTETextScanlineWidth7,
-    DrawTETextScanlineWidth8PLSBFirstFixedBase,
-    DrawTETextScanlineWidth9PLSBFirstFixedBase,
-#endif
-#else
-#ifdef MSBFIRST
-    DrawTETextScanlineWidth6PMSBFirst,
-    DrawTETextScanlineWidth7,
-    DrawTETextScanlineWidth8PMSBFirst,
-    DrawTETextScanlineWidth9PMSBFirst,
-#else
-    DrawTETextScanlineWidth6PLSBFirst,
-    DrawTETextScanlineWidth7,
-    DrawTETextScanlineWidth8PLSBFirst,
-    DrawTETextScanlineWidth9PLSBFirst,
-#endif
-#endif
-#else
-    DrawTETextScanlineWidth6, DrawTETextScanlineWidth7,
-    DrawTETextScanlineWidth8, DrawTETextScanlineWidth9,
-#endif
-    DrawTETextScanlineWidth10,
-    DrawTETextScanlineGeneric, DrawTETextScanlineWidth12,
-    DrawTETextScanlineGeneric, DrawTETextScanlineWidth14,
-    DrawTETextScanlineGeneric, DrawTETextScanlineWidth16,
-    DrawTETextScanlineGeneric, DrawTETextScanlineWidth18,
-    DrawTETextScanlineGeneric, DrawTETextScanlineGeneric,
-    DrawTETextScanlineGeneric, DrawTETextScanlineGeneric,
-    DrawTETextScanlineGeneric, DrawTETextScanlineWidth24,
-    DrawTETextScanlineGeneric, DrawTETextScanlineGeneric,
-    DrawTETextScanlineGeneric, DrawTETextScanlineGeneric,
-    DrawTETextScanlineGeneric, DrawTETextScanlineGeneric,
-    DrawTETextScanlineGeneric, DrawTETextScanlineGeneric
-};
-
-GlyphScanlineFuncPtr *
-glyph_get_scanline_func(void)
-{
-    return glyph_scanline_func;
-}
-
-/********************************************************************
-
-   Here we have TEGlyphRenders for a bunch of different color
-   expansion types.  The driver may provide its own renderer, but
-   this is the default one which renders using lower-level primitives
-   exported by the chipset driver.
-
-********************************************************************/
-
-/* This gets built for MSBFIRST or LSBFIRST with FIXEDBASE or not.
-	A total of 4 versions */
-
-void
-
-EXPNAME(XAATEGlyphRenderer) (ScrnInfoPtr pScrn,
-                             int x, int y, int w, int h, int skipleft,
-                             int startline, unsigned int **glyphs,
-                             int glyphWidth, int fg, int bg, int rop,
-                             unsigned planemask) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *base;
-    GlyphScanlineFuncPtr GlyphFunc = glyph_scanline_func[glyphWidth - 1];
-    int dwords = 0;
-
-    if ((bg != -1) && (infoRec->TEGlyphRendererFlags & TRANSPARENCY_ONLY)) {
-        (*infoRec->SetupForSolidFill) (pScrn, bg, rop, planemask);
-        (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, w, h);
-        bg = -1;
-    }
-
-    (*infoRec->SetupForCPUToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                    planemask);
-
-    if (skipleft &&
-        (!(infoRec->TEGlyphRendererFlags & LEFT_EDGE_CLIPPING) ||
-         (!(infoRec->TEGlyphRendererFlags & LEFT_EDGE_CLIPPING_NEGATIVE_X) &&
-          (skipleft > x)))) {
-        /* draw the first character only */
-
-        int count = h, line = startline;
-        int width = glyphWidth - skipleft;
-
-        if (width > w)
-            width = w;
-
-        (*infoRec->SubsequentCPUToScreenColorExpandFill) (pScrn, x, y, width, h,
-                                                          0);
-
-        base = (CARD32 *) infoRec->ColorExpandBase;
-
-        while (count--) {
-            register CARD32 tmp = SHIFT_R(glyphs[0][line++], skipleft);
-
-            WRITE_BITS(tmp);
-        }
-
-        w -= width;
-        if ((infoRec->TEGlyphRendererFlags & CPU_TRANSFER_PAD_QWORD) &&
-            ((((width + 31) >> 5) * h) & 1)) {
-            base = (CARD32 *) infoRec->ColorExpandBase;
-            base[0] = 0x00000000;
-        }
-        if (!w)
-            goto THE_END;
-        glyphs++;
-        x += width;
-        skipleft = 0;           /* nicely aligned again */
-    }
-
-    w += skipleft;
-    x -= skipleft;
-    dwords = ((w + 31) >> 5) * h;
-
-    (*infoRec->SubsequentCPUToScreenColorExpandFill) (pScrn, x, y, w, h,
-                                                      skipleft);
-
-    base = (CARD32 *) infoRec->ColorExpandBase;
-
-#ifndef FIXEDBASE
-    if ((((w + 31) >> 5) * h) <= infoRec->ColorExpandRange)
-        while (h--) {
-            base = (*GlyphFunc) (base, glyphs, startline++, w, glyphWidth);
-        }
-    else
-#endif
-        while (h--) {
-            (*GlyphFunc) (base, glyphs, startline++, w, glyphWidth);
-        }
-
-    if ((infoRec->TEGlyphRendererFlags & CPU_TRANSFER_PAD_QWORD) &&
-        (dwords & 1)) {
-        base = (CARD32 *) infoRec->ColorExpandBase;
-        base[0] = 0x00000000;
-    }
-
- THE_END:
-
-    if (infoRec->TEGlyphRendererFlags & SYNC_AFTER_COLOR_EXPAND)
-        (*infoRec->Sync) (pScrn);
-    else
-        SET_SYNC_FLAG(infoRec);
-}
-
-/********************************************************************
- 
-   This is the GlyphRenderer for TRIPLE_BITS_24BPP. It renders to a buffer
-   with the non FIXEDBASE LSB_FIRST code before tripling, and possibly
-   reversing the bits and sending them to the screen
-
-********************************************************************/
-
-void
-
-EXPNAME(XAATEGlyphRenderer3) (ScrnInfoPtr pScrn,
-                              int x, int y, int w, int h, int skipleft,
-                              int startline, unsigned int **glyphs,
-                              int glyphWidth, int fg, int bg, int rop,
-                              unsigned planemask) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    CARD32 *base, *mem;
-    GlyphScanlineFuncPtr GlyphFunc =
-        XAAGlyphScanlineFuncLSBFirst[glyphWidth - 1];
-    int dwords = 0;
-
-    if ((bg != -1) &&
-        ((infoRec->TEGlyphRendererFlags & TRANSPARENCY_ONLY) ||
-         ((infoRec->TEGlyphRendererFlags & RGB_EQUAL) &&
-          (!CHECK_RGB_EQUAL(bg))))) {
-        (*infoRec->SetupForSolidFill) (pScrn, bg, rop, planemask);
-        (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, w, h);
-        bg = -1;
-    }
-
-    (*infoRec->SetupForCPUToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                    planemask);
-
-    if (skipleft) {
-        /* draw the first character only */
-
-        int count = h, line = startline;
-        int width = glyphWidth - skipleft;
-        CARD32 bits;
-
-        if (width > w)
-            width = w;
-        (*infoRec->SubsequentCPUToScreenColorExpandFill) (pScrn, x, y, width, h,
-                                                          0);
-
-        base = (CARD32 *) infoRec->ColorExpandBase;
-
-        while (count--) {
-            bits = SHIFT_R(glyphs[0][line++], skipleft);
-            if (width >= 22) {
-                WRITE_BITS3(bits);
-            }
-            else if (width >= 11) {
-                WRITE_BITS2(bits);
-            }
-            else {
-                WRITE_BITS1(bits);
-            }
-        }
-
-        w -= width;
-        if ((infoRec->TEGlyphRendererFlags & CPU_TRANSFER_PAD_QWORD) &&
-            ((((3 * width + 31) >> 5) * h) & 1)) {
-            base = (CARD32 *) infoRec->ColorExpandBase;
-            base[0] = 0x00000000;
-        }
-        if (!w)
-            goto THE_END;
-        glyphs++;
-        x += width;
-        skipleft = 0;           /* nicely aligned again */
-    }
-
-    dwords = ((3 * w + 31) >> 5) * h;
-    mem = (CARD32 *) malloc(((w + 31) >> 3) * sizeof(char));
-    if (!mem)
-        return;
-
-    (*infoRec->SubsequentCPUToScreenColorExpandFill) (pScrn, x, y, w, h, 0);
-
-    base = (CARD32 *) infoRec->ColorExpandBase;
-
-#ifndef FIXEDBASE
-    if ((((3 * w + 31) >> 5) * h) <= infoRec->ColorExpandRange)
-        while (h--) {
-            (*GlyphFunc) (mem, glyphs, startline++, w, glyphWidth);
-            base = DrawTextScanline3(base, mem, w);
-        }
-    else
-#endif
-        while (h--) {
-            (*GlyphFunc) (mem, glyphs, startline++, w, glyphWidth);
-            DrawTextScanline3(base, mem, w);
-        }
-
-    free(mem);
-
-    if ((infoRec->TEGlyphRendererFlags & CPU_TRANSFER_PAD_QWORD) &&
-        (dwords & 1)) {
-        base = (CARD32 *) infoRec->ColorExpandBase;
-        base[0] = 0x00000000;
-    }
-
- THE_END:
-
-    if (infoRec->TEGlyphRendererFlags & SYNC_AFTER_COLOR_EXPAND)
-        (*infoRec->Sync) (pScrn);
-    else
-        SET_SYNC_FLAG(infoRec);
-}
-
-#ifndef FIXEDBASE
-/*  Scanline version of above gets built for LSBFIRST and MSBFIRST */
-
-void
-
-EXPNAME(XAATEGlyphRendererScanline) (ScrnInfoPtr pScrn,
-                                     int x, int y, int w, int h, int skipleft,
-                                     int startline, unsigned int **glyphs,
-                                     int glyphWidth, int fg, int bg, int rop,
-                                     unsigned planemask) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int bufferNo;
-    CARD32 *base;
-    GlyphScanlineFuncPtr GlyphFunc = glyph_scanline_func[glyphWidth - 1];
-
-    if ((bg != -1) && (infoRec->TEGlyphRendererFlags & TRANSPARENCY_ONLY)) {
-        (*infoRec->SetupForSolidFill) (pScrn, bg, rop, planemask);
-        (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, w, h);
-        bg = -1;
-    }
-
-    (*infoRec->SetupForScanlineCPUToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                            planemask);
-
-    if (skipleft &&
-        (!(infoRec->TEGlyphRendererFlags & LEFT_EDGE_CLIPPING) ||
-         (!(infoRec->TEGlyphRendererFlags & LEFT_EDGE_CLIPPING_NEGATIVE_X) &&
-          (skipleft > x)))) {
-        /* draw the first character only */
-
-        int count = h, line = startline;
-        int width = glyphWidth - skipleft;
-
-        if (width > w)
-            width = w;
-
-        (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill) (pScrn, x, y,
-                                                                  width, h, 0);
-
-        bufferNo = 0;
-
-        while (count--) {
-            register CARD32 tmp = SHIFT_R(glyphs[0][line++], skipleft);
-
-            base = (CARD32 *) infoRec->ScanlineColorExpandBuffers[bufferNo];
-            WRITE_BITS(tmp);
-            (*infoRec->SubsequentColorExpandScanline) (pScrn, bufferNo++);
-            if (bufferNo >= infoRec->NumScanlineColorExpandBuffers)
-                bufferNo = 0;
-        }
-
-        w -= width;
-        if (!w)
-            goto THE_END;
-        glyphs++;
-        x += width;
-        skipleft = 0;           /* nicely aligned again */
-    }
-
-    w += skipleft;
-    x -= skipleft;
-
-    (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill) (pScrn, x, y, w, h,
-                                                              skipleft);
-
-    bufferNo = 0;
-
-    while (h--) {
-        base = (CARD32 *) infoRec->ScanlineColorExpandBuffers[bufferNo];
-        (*GlyphFunc) (base, glyphs, startline++, w, glyphWidth);
-        (*infoRec->SubsequentColorExpandScanline) (pScrn, bufferNo++);
-        if (bufferNo >= infoRec->NumScanlineColorExpandBuffers)
-            bufferNo = 0;
-    }
-
- THE_END:
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-void
-
-EXPNAME(XAATEGlyphRendererScanline3) (ScrnInfoPtr pScrn,
-                                      int x, int y, int w, int h, int skipleft,
-                                      int startline, unsigned int **glyphs,
-                                      int glyphWidth, int fg, int bg, int rop,
-                                      unsigned planemask) {
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int bufferNo;
-    CARD32 *base, *mem;
-    GlyphScanlineFuncPtr GlyphFunc =
-        XAAGlyphScanlineFuncLSBFirst[glyphWidth - 1];
-
-    if ((bg != -1) &&
-        ((infoRec->TEGlyphRendererFlags & TRANSPARENCY_ONLY) ||
-         ((infoRec->TEGlyphRendererFlags & RGB_EQUAL) &&
-          (!CHECK_RGB_EQUAL(bg))))) {
-        (*infoRec->SetupForSolidFill) (pScrn, bg, rop, planemask);
-        (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, w, h);
-        bg = -1;
-    }
-
-    (*infoRec->SetupForScanlineCPUToScreenColorExpandFill) (pScrn, fg, bg, rop,
-                                                            planemask);
-
-    if (skipleft) {
-        /* draw the first character only */
-
-        int count = h, line = startline;
-        int width = glyphWidth - skipleft;
-        CARD32 bits;
-
-        if (width > w)
-            width = w;
-
-        (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill) (pScrn, x, y,
-                                                                  width, h, 0);
-
-        bufferNo = 0;
-
-        while (count--) {
-            base = (CARD32 *) infoRec->ScanlineColorExpandBuffers[bufferNo];
-            bits = SHIFT_R(glyphs[0][line++], skipleft);
-            if (width >= 22) {
-                WRITE_BITS3(bits);
-            }
-            else if (width >= 11) {
-                WRITE_BITS2(bits);
-            }
-            else {
-                WRITE_BITS1(bits);
-            }
-            (*infoRec->SubsequentColorExpandScanline) (pScrn, bufferNo++);
-            if (bufferNo >= infoRec->NumScanlineColorExpandBuffers)
-                bufferNo = 0;
-        }
-
-        w -= width;
-        if (!w)
-            goto THE_END;
-        glyphs++;
-        x += width;
-        skipleft = 0;           /* nicely aligned again */
-    }
-
-    w += skipleft;
-    x -= skipleft;
-    mem = (CARD32 *) malloc(((w + 31) >> 3) * sizeof(char));
-    if (!mem)
-        return;
-
-    (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill) (pScrn, x, y, w, h,
-                                                              skipleft);
-
-    bufferNo = 0;
-
-    while (h--) {
-        base = (CARD32 *) infoRec->ScanlineColorExpandBuffers[bufferNo];
-        (*GlyphFunc) (mem, glyphs, startline++, w, glyphWidth);
-        DrawTextScanline3(base, mem, w);
-        (*infoRec->SubsequentColorExpandScanline) (pScrn, bufferNo++);
-        if (bufferNo >= infoRec->NumScanlineColorExpandBuffers)
-            bufferNo = 0;
-    }
-
-    free(mem);
-
- THE_END:
-
-    SET_SYNC_FLAG(infoRec);
-}
-
-#endif
-
-/********************************************************************
-
-   TRIPLE_BITS_24BPP scanline rendering code.
-
-********************************************************************/
-
-static CARD32 *
-DrawTextScanline3(CARD32 *base, CARD32 *mem, int width)
-{
-
-    while (width > 32) {
-        WRITE_BITS3(*mem);
-        mem++;
-        width -= 32;
-    }
-    if (width) {
-        if (width >= 22) {
-            WRITE_BITS3(*mem);
-        }
-        else if (width >= 11) {
-            WRITE_BITS2(*mem);
-        }
-        else {
-            WRITE_BITS1(*mem);
-        }
-    }
-
-    return base;
-}
-
-/********************************************************************
-
-   Generic TE scanline rendering code.
-
-********************************************************************/
-
-static CARD32 *
-DrawTETextScanlineGeneric(CARD32 *base,
-                          unsigned int **glyphp,
-                          int line, int width, int glyphwidth)
-{
-    CARD32 bits = (*glyphp)[line];
-    int shift = glyphwidth;
-
-    while (width > 32) {
-        while (shift < 32) {
-            glyphp++;
-            bits |= SHIFT_L((*glyphp)[line], shift);
-            shift += glyphwidth;
-        }
-        WRITE_BITS(bits);
-        shift &= 31;
-        if (shift)
-            bits = SHIFT_R((*glyphp)[line], (glyphwidth - shift));
-        else
-            bits = 0;
-        width -= 32;
-    }
-
-    if (width) {
-        width -= shift;
-        while (width > 0) {
-            glyphp++;
-            bits |= SHIFT_L((*glyphp)[line], shift);
-            shift += glyphwidth;
-            width -= glyphwidth;
-        }
-        WRITE_BITS(bits);
-    }
-
-    return base;
-}
-
-/********************************************************************
-
-   Loop unrolled TE font scanline rendering code
-
-********************************************************************/
-
-#ifndef USEASSEMBLER
-static CARD32 *
-DrawTETextScanlineWidth6(CARD32 *base,
-                         unsigned int **glyphp,
-                         int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 6);
-        bits |= SHIFT_L(glyphp[2][line], 12);
-        bits |= SHIFT_L(glyphp[3][line], 18);
-        bits |= SHIFT_L(glyphp[4][line], 24);
-        bits |= SHIFT_L(glyphp[5][line], 30);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = SHIFT_R(glyphp[5][line], 2);
-        bits |= SHIFT_L(glyphp[6][line], 4);
-        bits |= SHIFT_L(glyphp[7][line], 10);
-        bits |= SHIFT_L(glyphp[8][line], 16);
-        bits |= SHIFT_L(glyphp[9][line], 22);
-        bits |= SHIFT_L(glyphp[10][line], 28);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-        bits = SHIFT_R(glyphp[10][line], 4);
-        bits |= SHIFT_L(glyphp[11][line], 2);
-        bits |= SHIFT_L(glyphp[12][line], 8);
-        bits |= SHIFT_L(glyphp[13][line], 14);
-        bits |= SHIFT_L(glyphp[14][line], 20);
-        bits |= SHIFT_L(glyphp[15][line], 26);
-        WRITE_IN_BITORDER(base, 2, bits);
-        CHECKRETURN(3);
-#ifndef FIXEDBASE
-        base += 3;
-#endif
-        width -= 96;
-        glyphp += 16;
-    }
-    return base;
-}
-#endif
-
-static CARD32 *
-DrawTETextScanlineWidth7(CARD32 *base,
-                         unsigned int **glyphp,
-                         int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 7);
-        bits |= SHIFT_L(glyphp[2][line], 14);
-        bits |= SHIFT_L(glyphp[3][line], 21);
-        bits |= SHIFT_L(glyphp[4][line], 28);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = SHIFT_R(glyphp[4][line], 4);
-        bits |= SHIFT_L(glyphp[5][line], 3);
-        bits |= SHIFT_L(glyphp[6][line], 10);
-        bits |= SHIFT_L(glyphp[7][line], 17);
-        bits |= SHIFT_L(glyphp[8][line], 24);
-        bits |= SHIFT_L(glyphp[9][line], 31);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-        bits = SHIFT_R(glyphp[9][line], 1);
-        bits |= SHIFT_L(glyphp[10][line], 6);
-        bits |= SHIFT_L(glyphp[11][line], 13);
-        bits |= SHIFT_L(glyphp[12][line], 20);
-        bits |= SHIFT_L(glyphp[13][line], 27);
-        WRITE_IN_BITORDER(base, 2, bits);
-        CHECKRETURN(3);
-        bits = SHIFT_R(glyphp[13][line], 5);
-        bits |= SHIFT_L(glyphp[14][line], 2);
-        bits |= SHIFT_L(glyphp[15][line], 9);
-        bits |= SHIFT_L(glyphp[16][line], 16);
-        bits |= SHIFT_L(glyphp[17][line], 23);
-        bits |= SHIFT_L(glyphp[18][line], 30);
-        WRITE_IN_BITORDER(base, 3, bits);
-        CHECKRETURN(4);
-        bits = SHIFT_R(glyphp[18][line], 2);
-        bits |= SHIFT_L(glyphp[19][line], 5);
-        bits |= SHIFT_L(glyphp[20][line], 12);
-        bits |= SHIFT_L(glyphp[21][line], 19);
-        bits |= SHIFT_L(glyphp[22][line], 26);
-        WRITE_IN_BITORDER(base, 4, bits);
-        CHECKRETURN(5);
-        bits = SHIFT_R(glyphp[22][line], 6);
-        bits |= SHIFT_L(glyphp[23][line], 1);
-        bits |= SHIFT_L(glyphp[24][line], 8);
-        bits |= SHIFT_L(glyphp[25][line], 15);
-        bits |= SHIFT_L(glyphp[26][line], 22);
-        bits |= SHIFT_L(glyphp[27][line], 29);
-        WRITE_IN_BITORDER(base, 5, bits);
-        CHECKRETURN(6);
-        bits = SHIFT_R(glyphp[27][line], 3);
-        bits |= SHIFT_L(glyphp[28][line], 4);
-        bits |= SHIFT_L(glyphp[29][line], 11);
-        bits |= SHIFT_L(glyphp[30][line], 18);
-        bits |= SHIFT_L(glyphp[31][line], 25);
-        WRITE_IN_BITORDER(base, 6, bits);
-        CHECKRETURN(7);
-#ifndef FIXEDBASE
-        base += 7;
-#endif
-        width -= 224;
-        glyphp += 32;
-    }
-    return base;
-}
-
-#ifndef USEASSEMBLER
-static CARD32 *
-DrawTETextScanlineWidth8(CARD32 *base,
-                         unsigned int **glyphp,
-                         int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 8);
-        bits |= SHIFT_L(glyphp[2][line], 16);
-        bits |= SHIFT_L(glyphp[3][line], 24);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = glyphp[4][line];
-        bits |= SHIFT_L(glyphp[5][line], 8);
-        bits |= SHIFT_L(glyphp[6][line], 16);
-        bits |= SHIFT_L(glyphp[7][line], 24);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-#ifndef FIXEDBASE
-        base += 2;
-#endif
-        width -= 64;
-        glyphp += 8;
-    }
-    return base;
-}
-#endif
-
-#ifndef USEASSEMBLER
-static CARD32 *
-DrawTETextScanlineWidth9(CARD32 *base,
-                         unsigned int **glyphp,
-                         int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 9);
-        bits |= SHIFT_L(glyphp[2][line], 18);
-        bits |= SHIFT_L(glyphp[3][line], 27);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = SHIFT_R(glyphp[3][line], 5);
-        bits |= SHIFT_L(glyphp[4][line], 4);
-        bits |= SHIFT_L(glyphp[5][line], 13);
-        bits |= SHIFT_L(glyphp[6][line], 22);
-        bits |= SHIFT_L(glyphp[7][line], 31);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-        bits = SHIFT_R(glyphp[7][line], 1);
-        bits |= SHIFT_L(glyphp[8][line], 8);
-        bits |= SHIFT_L(glyphp[9][line], 17);
-        bits |= SHIFT_L(glyphp[10][line], 26);
-        WRITE_IN_BITORDER(base, 2, bits);
-        CHECKRETURN(3);
-        bits = SHIFT_R(glyphp[10][line], 6);
-        bits |= SHIFT_L(glyphp[11][line], 3);
-        bits |= SHIFT_L(glyphp[12][line], 12);
-        bits |= SHIFT_L(glyphp[13][line], 21);
-        bits |= SHIFT_L(glyphp[14][line], 30);
-        WRITE_IN_BITORDER(base, 3, bits);
-        CHECKRETURN(4);
-        bits = SHIFT_R(glyphp[14][line], 2);
-        bits |= SHIFT_L(glyphp[15][line], 7);
-        bits |= SHIFT_L(glyphp[16][line], 16);
-        bits |= SHIFT_L(glyphp[17][line], 25);
-        WRITE_IN_BITORDER(base, 4, bits);
-        CHECKRETURN(5);
-        bits = SHIFT_R(glyphp[17][line], 7);
-        bits |= SHIFT_L(glyphp[18][line], 2);
-        bits |= SHIFT_L(glyphp[19][line], 11);
-        bits |= SHIFT_L(glyphp[20][line], 20);
-        bits |= SHIFT_L(glyphp[21][line], 29);
-        WRITE_IN_BITORDER(base, 5, bits);
-        CHECKRETURN(6);
-        bits = SHIFT_R(glyphp[21][line], 3);
-        bits |= SHIFT_L(glyphp[22][line], 6);
-        bits |= SHIFT_L(glyphp[23][line], 15);
-        bits |= SHIFT_L(glyphp[24][line], 24);
-        WRITE_IN_BITORDER(base, 6, bits);
-        CHECKRETURN(7);
-        bits = SHIFT_R(glyphp[24][line], 8);
-        bits |= SHIFT_L(glyphp[25][line], 1);
-        bits |= SHIFT_L(glyphp[26][line], 10);
-        bits |= SHIFT_L(glyphp[27][line], 19);
-        bits |= SHIFT_L(glyphp[28][line], 28);
-        WRITE_IN_BITORDER(base, 7, bits);
-        CHECKRETURN(8);
-        bits = SHIFT_R(glyphp[28][line], 4);
-        bits |= SHIFT_L(glyphp[29][line], 5);
-        bits |= SHIFT_L(glyphp[30][line], 14);
-        bits |= SHIFT_L(glyphp[31][line], 23);
-        WRITE_IN_BITORDER(base, 8, bits);
-        CHECKRETURN(9);
-#ifndef FIXEDBASE
-        base += 9;
-#endif
-        width -= 288;
-        glyphp += 32;
-    }
-    return base;
-}
-#endif
-
-static CARD32 *
-DrawTETextScanlineWidth10(CARD32 *base,
-                          unsigned int **glyphp,
-                          int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 10);
-        bits |= SHIFT_L(glyphp[2][line], 20);
-        bits |= SHIFT_L(glyphp[3][line], 30);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = SHIFT_R(glyphp[3][line], 2);
-        bits |= SHIFT_L(glyphp[4][line], 8);
-        bits |= SHIFT_L(glyphp[5][line], 18);
-        bits |= SHIFT_L(glyphp[6][line], 28);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-        bits = SHIFT_R(glyphp[6][line], 4);
-        bits |= SHIFT_L(glyphp[7][line], 6);
-        bits |= SHIFT_L(glyphp[8][line], 16);
-        bits |= SHIFT_L(glyphp[9][line], 26);
-        WRITE_IN_BITORDER(base, 2, bits);
-        CHECKRETURN(3);
-        bits = SHIFT_R(glyphp[9][line], 6);
-        bits |= SHIFT_L(glyphp[10][line], 4);
-        bits |= SHIFT_L(glyphp[11][line], 14);
-        bits |= SHIFT_L(glyphp[12][line], 24);
-        WRITE_IN_BITORDER(base, 3, bits);
-        CHECKRETURN(4);
-        bits = SHIFT_R(glyphp[12][line], 8);
-        bits |= SHIFT_L(glyphp[13][line], 2);
-        bits |= SHIFT_L(glyphp[14][line], 12);
-        bits |= SHIFT_L(glyphp[15][line], 22);
-        WRITE_IN_BITORDER(base, 4, bits);
-        CHECKRETURN(5);
-#ifndef FIXEDBASE
-        base += 5;
-#endif
-        width -= 160;
-        glyphp += 16;
-    }
-    return base;
-}
-
-static CARD32 *
-DrawTETextScanlineWidth12(CARD32 *base,
-                          unsigned int **glyphp,
-                          int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 12);
-        bits |= SHIFT_L(glyphp[2][line], 24);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = SHIFT_R(glyphp[2][line], 8);
-        bits |= SHIFT_L(glyphp[3][line], 4);
-        bits |= SHIFT_L(glyphp[4][line], 16);
-        bits |= SHIFT_L(glyphp[5][line], 28);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-        bits = SHIFT_R(glyphp[5][line], 4);
-        bits |= SHIFT_L(glyphp[6][line], 8);
-        bits |= SHIFT_L(glyphp[7][line], 20);
-        WRITE_IN_BITORDER(base, 2, bits);
-        CHECKRETURN(3);
-#ifndef FIXEDBASE
-        base += 3;
-#endif
-        width -= 96;
-        glyphp += 8;
-    }
-    return base;
-}
-
-static CARD32 *
-DrawTETextScanlineWidth14(CARD32 *base,
-                          unsigned int **glyphp,
-                          int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 14);
-        bits |= SHIFT_L(glyphp[2][line], 28);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = SHIFT_R(glyphp[2][line], 4);
-        bits |= SHIFT_L(glyphp[3][line], 10);
-        bits |= SHIFT_L(glyphp[4][line], 24);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-        bits = SHIFT_R(glyphp[4][line], 8);
-        bits |= SHIFT_L(glyphp[5][line], 6);
-        bits |= SHIFT_L(glyphp[6][line], 20);
-        WRITE_IN_BITORDER(base, 2, bits);
-        CHECKRETURN(3);
-        bits = SHIFT_R(glyphp[6][line], 12);
-        bits |= SHIFT_L(glyphp[7][line], 2);
-        bits |= SHIFT_L(glyphp[8][line], 16);
-        bits |= SHIFT_L(glyphp[9][line], 30);
-        WRITE_IN_BITORDER(base, 3, bits);
-        CHECKRETURN(4);
-        bits = SHIFT_R(glyphp[9][line], 2);
-        bits |= SHIFT_L(glyphp[10][line], 12);
-        bits |= SHIFT_L(glyphp[11][line], 26);
-        WRITE_IN_BITORDER(base, 4, bits);
-        CHECKRETURN(5);
-        bits = SHIFT_R(glyphp[11][line], 6);
-        bits |= SHIFT_L(glyphp[12][line], 8);
-        bits |= SHIFT_L(glyphp[13][line], 22);
-        WRITE_IN_BITORDER(base, 5, bits);
-        CHECKRETURN(6);
-        bits = SHIFT_R(glyphp[13][line], 10);
-        bits |= SHIFT_L(glyphp[14][line], 4);
-        bits |= SHIFT_L(glyphp[15][line], 18);
-        WRITE_IN_BITORDER(base, 6, bits);
-        CHECKRETURN(7);
-#ifndef FIXEDBASE
-        base += 7;
-#endif
-        width -= 224;
-        glyphp += 16;
-    }
-    return base;
-}
-
-static CARD32 *
-DrawTETextScanlineWidth16(CARD32 *base,
-                          unsigned int **glyphp,
-                          int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 16);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = glyphp[2][line];
-        bits |= SHIFT_L(glyphp[3][line], 16);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-        bits = glyphp[4][line];
-        bits |= SHIFT_L(glyphp[5][line], 16);
-        WRITE_IN_BITORDER(base, 2, bits);
-        CHECKRETURN(3);
-        bits = glyphp[6][line];
-        bits |= SHIFT_L(glyphp[7][line], 16);
-        WRITE_IN_BITORDER(base, 3, bits);
-        CHECKRETURN(4);
-#ifndef FIXEDBASE
-        base += 4;
-#endif
-        width -= 128;
-        glyphp += 8;
-    }
-    return base;
-}
-
-static CARD32 *
-DrawTETextScanlineWidth18(CARD32 *base,
-                          unsigned int **glyphp,
-                          int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 18);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = SHIFT_R(glyphp[1][line], 14);
-        bits |= SHIFT_L(glyphp[2][line], 4);
-        bits |= SHIFT_L(glyphp[3][line], 22);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-        bits = SHIFT_R(glyphp[3][line], 10);
-        bits |= SHIFT_L(glyphp[4][line], 8);
-        bits |= SHIFT_L(glyphp[5][line], 26);
-        WRITE_IN_BITORDER(base, 2, bits);
-        CHECKRETURN(3);
-        bits = SHIFT_R(glyphp[5][line], 6);
-        bits |= SHIFT_L(glyphp[6][line], 12);
-        bits |= SHIFT_L(glyphp[7][line], 30);
-        WRITE_IN_BITORDER(base, 3, bits);
-        CHECKRETURN(4);
-        bits = SHIFT_R(glyphp[7][line], 2);
-        bits |= SHIFT_L(glyphp[8][line], 16);
-        WRITE_IN_BITORDER(base, 4, bits);
-        CHECKRETURN(5);
-        bits = SHIFT_R(glyphp[8][line], 16);
-        bits |= SHIFT_L(glyphp[9][line], 2);
-        bits |= SHIFT_L(glyphp[10][line], 20);
-        WRITE_IN_BITORDER(base, 5, bits);
-        CHECKRETURN(6);
-        bits = SHIFT_R(glyphp[10][line], 12);
-        bits |= SHIFT_L(glyphp[11][line], 6);
-        bits |= SHIFT_L(glyphp[12][line], 24);
-        WRITE_IN_BITORDER(base, 6, bits);
-        CHECKRETURN(7);
-        bits = SHIFT_R(glyphp[12][line], 8);
-        bits |= SHIFT_L(glyphp[13][line], 10);
-        bits |= SHIFT_L(glyphp[14][line], 28);
-        WRITE_IN_BITORDER(base, 7, bits);
-        CHECKRETURN(8);
-        bits = SHIFT_R(glyphp[14][line], 4);
-        bits |= SHIFT_L(glyphp[15][line], 14);
-        WRITE_IN_BITORDER(base, 8, bits);
-        CHECKRETURN(9);
-#ifndef FIXEDBASE
-        base += 9;
-#endif
-        width -= 288;
-        glyphp += 16;
-    }
-    return base;
-}
-
-static CARD32 *
-DrawTETextScanlineWidth24(CARD32 *base,
-                          unsigned int **glyphp,
-                          int line, int width, int glyphwidth)
-{
-    while (1) {
-        unsigned int bits;
-
-        bits = glyphp[0][line];
-        bits |= SHIFT_L(glyphp[1][line], 24);
-        WRITE_IN_BITORDER(base, 0, bits);
-        CHECKRETURN(1);
-        bits = SHIFT_R(glyphp[1][line], 8);
-        bits |= SHIFT_L(glyphp[2][line], 16);
-        WRITE_IN_BITORDER(base, 1, bits);
-        CHECKRETURN(2);
-        bits = SHIFT_R(glyphp[2][line], 16);
-        bits |= SHIFT_L(glyphp[3][line], 8);
-        WRITE_IN_BITORDER(base, 2, bits);
-        CHECKRETURN(3);
-#ifndef FIXEDBASE
-        base += 3;
-#endif
-        width -= 96;
-        glyphp += 4;
-    }
-    return base;
-}
diff --git a/hw/xfree86/xaa/xaaTEText.c b/hw/xfree86/xaa/xaaTEText.c
deleted file mode 100644
index a5ef447..0000000
--- a/hw/xfree86/xaa/xaaTEText.c
+++ /dev/null
@@ -1,295 +0,0 @@
-
-/********************************************************************
-
-   In this file we have GC level replacements for PolyText8/16,
-   ImageText8/16, ImageGlyphBlt and PolyGlyphBlt for TE (fixed) fonts.
-   The idea is that everything in this file is device independent.
-   The mentioned GCOps are merely wrappers for XAAGlyphBltTEColorExpansion
-   which calculates the boxes containing arbitrarily clipped text
-   and passes them to the TEGlyphRenderer which will usually be a lower 
-   level XAA function which renders these clipped glyphs using
-   the basic color expansion functions exported by the chipset driver.
-   The TEGlyphRenderer itself may optionally be driver supplied to
-   facilitate work-arounds/optimizations at a higher level than usual.
-
-   v1.0 - Mark Vojkovich (mvojkovi at ucsd.edu)
-
-********************************************************************/
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include <X11/fonts/font.h>
-#include "scrnintstr.h"
-#include "dixfontstr.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-#include "gcstruct.h"
-#include "pixmapstr.h"
-
-static void XAAGlyphBltTEColorExpansion(ScrnInfoPtr pScrn, int xInit,
-                                        int yInit, FontPtr font, int fg, int bg,
-                                        int rop, unsigned int planemask,
-                                        RegionPtr cclip, int nglyph,
-                                        unsigned char *gBase,
-                                        CharInfoPtr * ppci);
-
-/********************************************************************
-
-   GC level replacements for PolyText8/16 and ImageText8/16
-   for TE fonts when using color expansion.
-
-********************************************************************/
-
-int
-XAAPolyText8TEColorExpansion(DrawablePtr pDraw,
-                             GCPtr pGC, int x, int y, int count, char *chars)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    unsigned long n;
-
-    (*pGC->font->get_glyphs) (pGC->font, (unsigned long) count,
-                              (unsigned char *) chars, Linear8Bit, &n,
-                              infoRec->CharInfo);
-
-    /* we have divorced XAAGlyphBltTEColorExpansion from the drawable */
-    if (n)
-        XAAGlyphBltTEColorExpansion(infoRec->pScrn, x + pDraw->x, y + pDraw->y,
-                                    pGC->font, pGC->fgPixel, -1, pGC->alu,
-                                    pGC->planemask, pGC->pCompositeClip, n,
-                                    FONTGLYPHS(pGC->font), infoRec->CharInfo);
-
-    return (x + (n * FONTMAXBOUNDS(pGC->font, characterWidth)));
-}
-
-int
-XAAPolyText16TEColorExpansion(DrawablePtr pDraw,
-                              GCPtr pGC,
-                              int x, int y, int count, unsigned short *chars)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    unsigned long n;
-
-    (*pGC->font->get_glyphs) (pGC->font, (unsigned long) count,
-                              (unsigned char *) chars,
-                              (FONTLASTROW(pGC->font) ==
-                               0) ? Linear16Bit : TwoD16Bit, &n,
-                              infoRec->CharInfo);
-
-    if (n)
-        XAAGlyphBltTEColorExpansion(infoRec->pScrn, x + pDraw->x, y + pDraw->y,
-                                    pGC->font, pGC->fgPixel, -1, pGC->alu,
-                                    pGC->planemask, pGC->pCompositeClip, n,
-                                    FONTGLYPHS(pGC->font), infoRec->CharInfo);
-
-    return (x + (n * FONTMAXBOUNDS(pGC->font, characterWidth)));
-}
-
-void
-XAAImageText8TEColorExpansion(DrawablePtr pDraw,
-                              GCPtr pGC, int x, int y, int count, char *chars)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    unsigned long n;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    (*pGC->font->get_glyphs) (pGC->font, (unsigned long) count,
-                              (unsigned char *) chars, Linear8Bit, &n,
-                              infoRec->CharInfo);
-
-    if (n)
-        XAAGlyphBltTEColorExpansion(infoRec->pScrn, x + pDraw->x, y + pDraw->y,
-                                    pGC->font, pGC->fgPixel, pGC->bgPixel,
-                                    GXcopy, pGC->planemask, pGC->pCompositeClip,
-                                    n, FONTGLYPHS(pGC->font),
-                                    infoRec->CharInfo);
-}
-
-void
-XAAImageText16TEColorExpansion(DrawablePtr pDraw,
-                               GCPtr pGC,
-                               int x, int y, int count, unsigned short *chars)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    unsigned long n;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    (*pGC->font->get_glyphs) (pGC->font, (unsigned long) count,
-                              (unsigned char *) chars,
-                              (FONTLASTROW(pGC->font) ==
-                               0) ? Linear16Bit : TwoD16Bit, &n,
-                              infoRec->CharInfo);
-
-    if (n)
-        XAAGlyphBltTEColorExpansion(infoRec->pScrn, x + pDraw->x, y + pDraw->y,
-                                    pGC->font, pGC->fgPixel, pGC->bgPixel,
-                                    GXcopy, pGC->planemask, pGC->pCompositeClip,
-                                    n, FONTGLYPHS(pGC->font),
-                                    infoRec->CharInfo);
-}
-
-/********************************************************************
-
-   GC level replacements for ImageGlyphBlt and PolyGlyphBlt for
-   TE fonts when using color expansion.
-
-********************************************************************/
-
-void
-XAAImageGlyphBltTEColorExpansion(DrawablePtr pDrawable,
-                                 GCPtr pGC,
-                                 int xInit, int yInit,
-                                 unsigned int nglyph,
-                                 CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    XAAGlyphBltTEColorExpansion(infoRec->pScrn, xInit + pDrawable->x,
-                                yInit + pDrawable->y, pGC->font, pGC->fgPixel,
-                                pGC->bgPixel, GXcopy, pGC->planemask,
-                                pGC->pCompositeClip, nglyph,
-                                (unsigned char *) pglyphBase, ppci);
-}
-
-void
-XAAPolyGlyphBltTEColorExpansion(DrawablePtr pDrawable,
-                                GCPtr pGC,
-                                int xInit, int yInit,
-                                unsigned int nglyph,
-                                CharInfoPtr * ppci, pointer pglyphBase)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    XAAGlyphBltTEColorExpansion(infoRec->pScrn, xInit + pDrawable->x,
-                                yInit + pDrawable->y, pGC->font, pGC->fgPixel,
-                                -1, pGC->alu, pGC->planemask,
-                                pGC->pCompositeClip, nglyph,
-                                (unsigned char *) pglyphBase, ppci);
-}
-
-/********************************************************************
-
-   XAAGlyphBltTEColorExpansion -
-
-   This guy computes the clipped pieces of text and sends it to
-   the lower-level function which will handle acceleration of 
-   arbitrarily clipped text.
-  
-********************************************************************/
-
-static void
-XAAGlyphBltTEColorExpansion(ScrnInfoPtr pScrn,
-                            int xInit, int yInit,
-                            FontPtr font,
-                            int fg, int bg,
-                            int rop,
-                            unsigned int planemask,
-                            RegionPtr cclip,
-                            int nglyph,
-                            unsigned char *gBase, CharInfoPtr * ppci)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    int skippix, skipglyphs;
-    int Left, Right, Top, Bottom;
-    int LeftEdge, RightEdge, ytop, ybot;
-    int nbox = RegionNumRects(cclip);
-    BoxPtr pbox = RegionRects(cclip);
-    unsigned int **glyphs = NULL;
-    int glyphWidth = FONTMAXBOUNDS(font, characterWidth);
-
-    /* find the size of the box */
-    Left = xInit;
-    Right = Left + (glyphWidth * nglyph);
-    Top = yInit - FONTASCENT(font);
-    Bottom = yInit + FONTDESCENT(font);
-
-    /* get into the first band that may contain part of our string */
-    while (nbox && (Top >= pbox->y2)) {
-        pbox++;
-        nbox--;
-    }
-
-    /* stop when the lower edge of the box is beyond our string */
-    while (nbox && (Bottom > pbox->y1)) {
-        LeftEdge = max(Left, pbox->x1);
-        RightEdge = min(Right, pbox->x2);
-
-        if (RightEdge > LeftEdge) {     /* we have something to draw */
-            unsigned int *fallbackBits = NULL;
-
-            ytop = max(Top, pbox->y1);
-            ybot = min(Bottom, pbox->y2);
-
-            if ((skippix = LeftEdge - Left)) {
-                skipglyphs = skippix / glyphWidth;
-                skippix %= glyphWidth;
-            }
-            else
-                skipglyphs = 0;
-
-            if (!glyphs) {
-                int count;
-
-                glyphs = (unsigned int **) (infoRec->PreAllocMem);
-
-                for (count = 0; count < nglyph; count++) {
-                    glyphs[count] = (unsigned int *)
-                        FONTGLYPHBITS(gBase, *ppci++);
-                    if (!glyphs[count]) {
-                        /* Glyphs with NULL bits do exist in the wild.
-                           Replace with blank bits in that case */
-
-                        if (!fallbackBits) {
-                            int fontHeight = Bottom - Top + 1;
-
-                            fallbackBits = calloc(glyphWidth * fontHeight, 1);
-                            if (!fallbackBits)
-                                return;
-                        }
-                        glyphs[count] = fallbackBits;
-                    }
-                }
-
-                /* our new unrolled TE code only writes DWORDS at a time 
-                   so it can read up to 6 characters past the last one 
-                   we're displaying */
-                glyphs[count + 0] = glyphs[0];
-                glyphs[count + 1] = glyphs[0];
-                glyphs[count + 2] = glyphs[0];
-                glyphs[count + 3] = glyphs[0];
-                glyphs[count + 4] = glyphs[0];
-                glyphs[count + 5] = glyphs[0];
-            }
-
-            /* x, y, w, h, skipleft, skiptop, glyphp, glyphWidth, fg, bg, rop, pm */
-
-            (*infoRec->TEGlyphRenderer) (pScrn,
-                                         LeftEdge, ytop, RightEdge - LeftEdge,
-                                         ybot - ytop, skippix, ytop - Top,
-                                         glyphs + skipglyphs, glyphWidth, fg,
-                                         bg, rop, planemask);
-
-            free(fallbackBits);
-        }
-
-        nbox--;
-        pbox++;
-    }
-}
diff --git a/hw/xfree86/xaa/xaaTables.c b/hw/xfree86/xaa/xaaTables.c
deleted file mode 100644
index 35641da..0000000
--- a/hw/xfree86/xaa/xaaTables.c
+++ /dev/null
@@ -1,152 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-#include "xaalocal.h"
-/*
- * This is a table of 24-bit values, indexed with an 8-bit byte value, then
- * expands each bit to three consecutive bits. This is required for color
- * expansion in 24bpp mode with the coprocessor in 8bpp mode, with LSB-first
- * bit order within a byte.
- */
-
-unsigned int byte_expand3[256] = {
-    0x000000, 0x000007, 0x000038, 0x00003F, 0x0001C0, 0x0001C7, 0x0001F8,
-        0x0001FF,
-    0x000E00, 0x000E07, 0x000E38, 0x000E3F, 0x000FC0, 0x000FC7, 0x000FF8,
-        0x000FFF,
-    0x007000, 0x007007, 0x007038, 0x00703F, 0x0071C0, 0x0071C7, 0x0071F8,
-        0x0071FF,
-    0x007E00, 0x007E07, 0x007E38, 0x007E3F, 0x007FC0, 0x007FC7, 0x007FF8,
-        0x007FFF,
-    0x038000, 0x038007, 0x038038, 0x03803F, 0x0381C0, 0x0381C7, 0x0381F8,
-        0x0381FF,
-    0x038E00, 0x038E07, 0x038E38, 0x038E3F, 0x038FC0, 0x038FC7, 0x038FF8,
-        0x038FFF,
-    0x03F000, 0x03F007, 0x03F038, 0x03F03F, 0x03F1C0, 0x03F1C7, 0x03F1F8,
-        0x03F1FF,
-    0x03FE00, 0x03FE07, 0x03FE38, 0x03FE3F, 0x03FFC0, 0x03FFC7, 0x03FFF8,
-        0x03FFFF,
-    0x1C0000, 0x1C0007, 0x1C0038, 0x1C003F, 0x1C01C0, 0x1C01C7, 0x1C01F8,
-        0x1C01FF,
-    0x1C0E00, 0x1C0E07, 0x1C0E38, 0x1C0E3F, 0x1C0FC0, 0x1C0FC7, 0x1C0FF8,
-        0x1C0FFF,
-    0x1C7000, 0x1C7007, 0x1C7038, 0x1C703F, 0x1C71C0, 0x1C71C7, 0x1C71F8,
-        0x1C71FF,
-    0x1C7E00, 0x1C7E07, 0x1C7E38, 0x1C7E3F, 0x1C7FC0, 0x1C7FC7, 0x1C7FF8,
-        0x1C7FFF,
-    0x1F8000, 0x1F8007, 0x1F8038, 0x1F803F, 0x1F81C0, 0x1F81C7, 0x1F81F8,
-        0x1F81FF,
-    0x1F8E00, 0x1F8E07, 0x1F8E38, 0x1F8E3F, 0x1F8FC0, 0x1F8FC7, 0x1F8FF8,
-        0x1F8FFF,
-    0x1FF000, 0x1FF007, 0x1FF038, 0x1FF03F, 0x1FF1C0, 0x1FF1C7, 0x1FF1F8,
-        0x1FF1FF,
-    0x1FFE00, 0x1FFE07, 0x1FFE38, 0x1FFE3F, 0x1FFFC0, 0x1FFFC7, 0x1FFFF8,
-        0x1FFFFF,
-    0xE00000, 0xE00007, 0xE00038, 0xE0003F, 0xE001C0, 0xE001C7, 0xE001F8,
-        0xE001FF,
-    0xE00E00, 0xE00E07, 0xE00E38, 0xE00E3F, 0xE00FC0, 0xE00FC7, 0xE00FF8,
-        0xE00FFF,
-    0xE07000, 0xE07007, 0xE07038, 0xE0703F, 0xE071C0, 0xE071C7, 0xE071F8,
-        0xE071FF,
-    0xE07E00, 0xE07E07, 0xE07E38, 0xE07E3F, 0xE07FC0, 0xE07FC7, 0xE07FF8,
-        0xE07FFF,
-    0xE38000, 0xE38007, 0xE38038, 0xE3803F, 0xE381C0, 0xE381C7, 0xE381F8,
-        0xE381FF,
-    0xE38E00, 0xE38E07, 0xE38E38, 0xE38E3F, 0xE38FC0, 0xE38FC7, 0xE38FF8,
-        0xE38FFF,
-    0xE3F000, 0xE3F007, 0xE3F038, 0xE3F03F, 0xE3F1C0, 0xE3F1C7, 0xE3F1F8,
-        0xE3F1FF,
-    0xE3FE00, 0xE3FE07, 0xE3FE38, 0xE3FE3F, 0xE3FFC0, 0xE3FFC7, 0xE3FFF8,
-        0xE3FFFF,
-    0xFC0000, 0xFC0007, 0xFC0038, 0xFC003F, 0xFC01C0, 0xFC01C7, 0xFC01F8,
-        0xFC01FF,
-    0xFC0E00, 0xFC0E07, 0xFC0E38, 0xFC0E3F, 0xFC0FC0, 0xFC0FC7, 0xFC0FF8,
-        0xFC0FFF,
-    0xFC7000, 0xFC7007, 0xFC7038, 0xFC703F, 0xFC71C0, 0xFC71C7, 0xFC71F8,
-        0xFC71FF,
-    0xFC7E00, 0xFC7E07, 0xFC7E38, 0xFC7E3F, 0xFC7FC0, 0xFC7FC7, 0xFC7FF8,
-        0xFC7FFF,
-    0xFF8000, 0xFF8007, 0xFF8038, 0xFF803F, 0xFF81C0, 0xFF81C7, 0xFF81F8,
-        0xFF81FF,
-    0xFF8E00, 0xFF8E07, 0xFF8E38, 0xFF8E3F, 0xFF8FC0, 0xFF8FC7, 0xFF8FF8,
-        0xFF8FFF,
-    0xFFF000, 0xFFF007, 0xFFF038, 0xFFF03F, 0xFFF1C0, 0xFFF1C7, 0xFFF1F8,
-        0xFFF1FF,
-    0xFFFE00, 0xFFFE07, 0xFFFE38, 0xFFFE3F, 0xFFFFC0, 0xFFFFC7, 0xFFFFF8,
-        0xFFFFFF
-};
-
-/*
- * This is a table of 24-bit values, indexed with an 8-bit byte value,
- * that reverses the bit order of a byte and then expands each bit to three
- * consecutive bits. This is required for color expansion in 24bpp mode
- * with the coprocessor in 8bpp mode, with MSB-first bit order within a
- * byte.
- */
-
-unsigned int byte_reversed_expand3[256] = {
-    0x000000, 0x0000E0, 0x00001C, 0x0000FC, 0x008003, 0x0080E3, 0x00801F,
-        0x0080FF,
-    0x007000, 0x0070E0, 0x00701C, 0x0070FC, 0x00F003, 0x00F0E3, 0x00F01F,
-        0x00F0FF,
-    0x000E00, 0x000EE0, 0x000E1C, 0x000EFC, 0x008E03, 0x008EE3, 0x008E1F,
-        0x008EFF,
-    0x007E00, 0x007EE0, 0x007E1C, 0x007EFC, 0x00FE03, 0x00FEE3, 0x00FE1F,
-        0x00FEFF,
-    0xC00100, 0xC001E0, 0xC0011C, 0xC001FC, 0xC08103, 0xC081E3, 0xC0811F,
-        0xC081FF,
-    0xC07100, 0xC071E0, 0xC0711C, 0xC071FC, 0xC0F103, 0xC0F1E3, 0xC0F11F,
-        0xC0F1FF,
-    0xC00F00, 0xC00FE0, 0xC00F1C, 0xC00FFC, 0xC08F03, 0xC08FE3, 0xC08F1F,
-        0xC08FFF,
-    0xC07F00, 0xC07FE0, 0xC07F1C, 0xC07FFC, 0xC0FF03, 0xC0FFE3, 0xC0FF1F,
-        0xC0FFFF,
-    0x380000, 0x3800E0, 0x38001C, 0x3800FC, 0x388003, 0x3880E3, 0x38801F,
-        0x3880FF,
-    0x387000, 0x3870E0, 0x38701C, 0x3870FC, 0x38F003, 0x38F0E3, 0x38F01F,
-        0x38F0FF,
-    0x380E00, 0x380EE0, 0x380E1C, 0x380EFC, 0x388E03, 0x388EE3, 0x388E1F,
-        0x388EFF,
-    0x387E00, 0x387EE0, 0x387E1C, 0x387EFC, 0x38FE03, 0x38FEE3, 0x38FE1F,
-        0x38FEFF,
-    0xF80100, 0xF801E0, 0xF8011C, 0xF801FC, 0xF88103, 0xF881E3, 0xF8811F,
-        0xF881FF,
-    0xF87100, 0xF871E0, 0xF8711C, 0xF871FC, 0xF8F103, 0xF8F1E3, 0xF8F11F,
-        0xF8F1FF,
-    0xF80F00, 0xF80FE0, 0xF80F1C, 0xF80FFC, 0xF88F03, 0xF88FE3, 0xF88F1F,
-        0xF88FFF,
-    0xF87F00, 0xF87FE0, 0xF87F1C, 0xF87FFC, 0xF8FF03, 0xF8FFE3, 0xF8FF1F,
-        0xF8FFFF,
-    0x070000, 0x0700E0, 0x07001C, 0x0700FC, 0x078003, 0x0780E3, 0x07801F,
-        0x0780FF,
-    0x077000, 0x0770E0, 0x07701C, 0x0770FC, 0x07F003, 0x07F0E3, 0x07F01F,
-        0x07F0FF,
-    0x070E00, 0x070EE0, 0x070E1C, 0x070EFC, 0x078E03, 0x078EE3, 0x078E1F,
-        0x078EFF,
-    0x077E00, 0x077EE0, 0x077E1C, 0x077EFC, 0x07FE03, 0x07FEE3, 0x07FE1F,
-        0x07FEFF,
-    0xC70100, 0xC701E0, 0xC7011C, 0xC701FC, 0xC78103, 0xC781E3, 0xC7811F,
-        0xC781FF,
-    0xC77100, 0xC771E0, 0xC7711C, 0xC771FC, 0xC7F103, 0xC7F1E3, 0xC7F11F,
-        0xC7F1FF,
-    0xC70F00, 0xC70FE0, 0xC70F1C, 0xC70FFC, 0xC78F03, 0xC78FE3, 0xC78F1F,
-        0xC78FFF,
-    0xC77F00, 0xC77FE0, 0xC77F1C, 0xC77FFC, 0xC7FF03, 0xC7FFE3, 0xC7FF1F,
-        0xC7FFFF,
-    0x3F0000, 0x3F00E0, 0x3F001C, 0x3F00FC, 0x3F8003, 0x3F80E3, 0x3F801F,
-        0x3F80FF,
-    0x3F7000, 0x3F70E0, 0x3F701C, 0x3F70FC, 0x3FF003, 0x3FF0E3, 0x3FF01F,
-        0x3FF0FF,
-    0x3F0E00, 0x3F0EE0, 0x3F0E1C, 0x3F0EFC, 0x3F8E03, 0x3F8EE3, 0x3F8E1F,
-        0x3F8EFF,
-    0x3F7E00, 0x3F7EE0, 0x3F7E1C, 0x3F7EFC, 0x3FFE03, 0x3FFEE3, 0x3FFE1F,
-        0x3FFEFF,
-    0xFF0100, 0xFF01E0, 0xFF011C, 0xFF01FC, 0xFF8103, 0xFF81E3, 0xFF811F,
-        0xFF81FF,
-    0xFF7100, 0xFF71E0, 0xFF711C, 0xFF71FC, 0xFFF103, 0xFFF1E3, 0xFFF11F,
-        0xFFF1FF,
-    0xFF0F00, 0xFF0FE0, 0xFF0F1C, 0xFF0FFC, 0xFF8F03, 0xFF8FE3, 0xFF8F1F,
-        0xFF8FFF,
-    0xFF7F00, 0xFF7FE0, 0xFF7F1C, 0xFF7FFC, 0xFFFF03, 0xFFFFE3, 0xFFFF1F,
-        0xFFFFFF,
-};
diff --git a/hw/xfree86/xaa/xaaWideLine.c b/hw/xfree86/xaa/xaaWideLine.c
deleted file mode 100644
index b8a53c1..0000000
--- a/hw/xfree86/xaa/xaaWideLine.c
+++ /dev/null
@@ -1,924 +0,0 @@
-/*
-
-XAAPolylinesWideSolid does not maintain a span list and subsequently does
-not follow the "touch-each-pixel-once" rules for wide lines and arcs.
-This means it can only be used in the case where we have
-miSpansEasyRop(pGC->alu).  Since we clip spans on the fly, we
-limited usage of this function to one rect situations. This
-function is used only for solid lines. 
-
-  Adapted from miWideLine by Mark Vojkovich (mvojkovi at ucsd.edu)
-Original mi code written by Keith Packard.
-
-*/
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <math.h>
-
-#include "misc.h"
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include <X11/X.h>
-#include "windowstr.h"
-#include "gcstruct.h"
-#include "regionstr.h"
-#include "miwideline.h"
-#include "mi.h"
-#include "xf86str.h"
-#include "xaa.h"
-#include "xaalocal.h"
-
-#define DRAW_POINT(pScrn, x, y) \
-  if(hardClip) (*infoRec->SubsequentSolidFillRect)(pScrn, x, y, 1, 1); \
-  else XAAPointHelper(pScrn, x, y)
-
-#define FILL_RECT(pScrn, x, y, w, h) \
-  if(hardClip) (*infoRec->SubsequentSolidFillRect)(pScrn, x, y, w, h); \
-  else XAAFillRectHelper(pScrn, x, y, w, h)
-
-#define FILL_SPAN(pScrn, x, y, w) \
-  if(hardClip) (*infoRec->SubsequentSolidFillRect)(pScrn, x, y, w, 1); \
-  else XAASpanHelper(pScrn, x, y, w)
-
-#define CLIPSTEPEDGE(edgey,edge,edgeleft) \
-    if (ybase == edgey) { \
-	if (edgeleft) { \
-	    if (edge->x > xcl) \
-		xcl = edge->x; \
-	} else { \
-	    if (edge->x < xcr) \
-		xcr = edge->x; \
-	} \
-	edgey++; \
-	edge->x += edge->stepx; \
-	edge->e += edge->dx; \
-	if (edge->e > 0) { \
-	    edge->x += edge->signdx; \
-	    edge->e -= edge->dy; \
-	} \
-    }
-
-static void
-XAAPointHelper(ScrnInfoPtr pScrn, int x, int y)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    BoxPtr extents = infoRec->ClipBox;
-
-    if ((x >= extents->x1) && (x < extents->x2) &&
-        (y >= extents->y1) && (y < extents->y2))
-        (*infoRec->SubsequentSolidFillRect) (pScrn, x, y, 1, 1);
-}
-
-static void
-XAAFillRectHelper(ScrnInfoPtr pScrn, int x1, int y1, int dx, int dy)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    BoxPtr extents = infoRec->ClipBox;
-    int x2 = x1 + dx;
-    int y2 = y1 + dy;
-
-    if (x1 < extents->x1)
-        x1 = extents->x1;
-    if (x2 >= extents->x2)
-        x2 = extents->x2;
-    if ((dx = x2 - x1) < 1)
-        return;
-    if (y1 < extents->y1)
-        y1 = extents->y1;
-    if (y2 >= extents->y2)
-        y2 = extents->y2;
-    if ((dy = y2 - y1) < 1)
-        return;
-
-    (*infoRec->SubsequentSolidFillRect) (pScrn, x1, y1, dx, dy);
-}
-
-static void
-XAASpanHelper(ScrnInfoPtr pScrn, int x1, int y, int width)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
-    BoxPtr extents = infoRec->ClipBox;
-    int x2;
-
-    if ((y < extents->y1) || (y >= extents->y2))
-        return;
-
-    x2 = x1 + width;
-    if (x1 < extents->x1)
-        x1 = extents->x1;
-    if (x2 > extents->x2)
-        x2 = extents->x2;
-    width = x2 - x1;
-
-    if (width > 0)
-        (*infoRec->SubsequentSolidFillRect) (pScrn, x1, y, width, 1);
-
-}
-
-#define FixError(x, dx, dy, e, sign, step, h)	{	\
-	   e += (h) * dx;				\
-	   x += (h) * step;				\
-	   if(e > 0) {					\
-		x += e * sign/dy;			\
-		e %= dy;				\
-	   	if(e) {					\
-		   x += sign;				\
-		   e -= dy;				\
-		}					\
-	   } 	 					\
-}
-
-static void
-XAAFillPolyHelper(GCPtr pGC, int y,     /* start y coordinate */
-                  int overall_height,   /* height of entire segment */
-                  PolyEdgePtr left, PolyEdgePtr right,
-                  int left_count, int right_count)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    BoxPtr extents = infoRec->ClipBox;
-    int left_x, left_e, left_stepx, left_signdx, left_dy, left_dx;
-    int right_x, right_e, right_stepx, right_signdx, right_dy, right_dx;
-    int height, left_height, right_height;
-    int xorg;
-    Bool hardClip;
-
-    if ((y >= extents->y2) || ((y + overall_height) <= extents->y1))
-        return;
-
-    /* Muffle compiler */
-    left_x = left_e = left_stepx = left_signdx = left_dy = left_dx = 0;
-    right_x = right_e = right_stepx = right_signdx = right_dy = right_dx = 0;
-
-    left_height = right_height = 0;
-    xorg = 0;
-
-    hardClip = (infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_FILL);
-
-    while ((left_count || left_height) && (right_count || right_height)) {
-        if (!left_height && left_count) {
-            left_height = left->height;
-            left_x = left->x + xorg;
-            left_stepx = left->stepx;
-            left_signdx = left->signdx;
-            left_e = left->e;
-            left_dy = left->dy;
-            left_dx = left->dx;
-            left_count--;
-            left++;
-        }
-        if (!right_height && right_count) {
-            right_height = right->height;
-            right_x = right->x + xorg + 1;
-            right_stepx = right->stepx;
-            right_signdx = right->signdx;
-            right_e = right->e;
-            right_dy = right->dy;
-            right_dx = right->dx;
-            right_count--;
-            right++;
-        }
-
-        height = (left_height > right_height) ? right_height : left_height;
-
-        left_height -= height;
-        right_height -= height;
-
-        if (hardClip && infoRec->SubsequentSolidFillTrap && (height > 6)) {
-            int right_DX, left_DX;
-
-            right_DX = (right_dx * right_signdx) + (right_stepx * right_dy);
-            left_DX = (left_dx * left_signdx) + (left_stepx * left_dy);
-
-            (*infoRec->SubsequentSolidFillTrap) (infoRec->pScrn, y, height,
-                                                 left_x, left_DX, left_dy,
-                                                 left_e, right_x - 1, right_DX,
-                                                 right_dy, right_e);
-
-            FixError(left_x, left_dx, left_dy, left_e, left_signdx,
-                     left_stepx, height);
-            FixError(right_x, right_dx, right_dy, right_e, right_signdx,
-                     right_stepx, height);
-            y += height;
-            continue;
-        }
-
-        while (height--) {
-            if (right_x > left_x) {
-                FILL_SPAN(infoRec->pScrn, left_x, y, right_x - left_x);
-            }
-            y++;
-
-            left_x += left_stepx;
-            left_e += left_dx;
-            if (left_e > 0) {
-                left_x += left_signdx;
-                left_e -= left_dy;
-            }
-            right_x += right_stepx;
-            right_e += right_dx;
-            if (right_e > 0) {
-                right_x += right_signdx;
-                right_e -= right_dy;
-            }
-
-        }
-    }
-}
-
-static void
-XAAWideSegment(GCPtr pGC,
-               int x1, int y1, int x2, int y2,
-               Bool projectLeft, Bool projectRight,
-               LineFacePtr leftFace, LineFacePtr rightFace)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    double l, L, r;
-    double xa, ya;
-    double projectXoff, projectYoff;
-    double k;
-    double maxy;
-    int x, y;
-    int dx, dy;
-    int finaly;
-    PolyEdgePtr left, right;
-    PolyEdgePtr top, bottom;
-    int lefty, righty, topy, bottomy;
-    int signdx;
-    PolyEdgeRec lefts[2], rights[2];
-    LineFacePtr tface;
-    int lw = pGC->lineWidth;
-    Bool hardClip = (infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_FILL);
-
-    /* draw top-to-bottom always */
-    if ((y2 < y1) || ((y2 == y1) && (x2 < x1))) {
-        x = x1;
-        x1 = x2;
-        x2 = x;
-
-        y = y1;
-        y1 = y2;
-        y2 = y;
-
-        x = projectLeft;
-        projectLeft = projectRight;
-        projectRight = x;
-
-        tface = leftFace;
-        leftFace = rightFace;
-        rightFace = tface;
-    }
-
-    dy = y2 - y1;
-    signdx = 1;
-    dx = x2 - x1;
-    if (dx < 0)
-        signdx = -1;
-
-    leftFace->x = x1;
-    leftFace->y = y1;
-    leftFace->dx = dx;
-    leftFace->dy = dy;
-
-    rightFace->x = x2;
-    rightFace->y = y2;
-    rightFace->dx = -dx;
-    rightFace->dy = -dy;
-
-    if (!dy) {
-        rightFace->xa = 0;
-        rightFace->ya = (double) lw / 2.0;
-        rightFace->k = -(double) (lw * dx) / 2.0;
-        leftFace->xa = 0;
-        leftFace->ya = -rightFace->ya;
-        leftFace->k = rightFace->k;
-        x = x1;
-        if (projectLeft)
-            x -= (lw >> 1);
-        y = y1 - (lw >> 1);
-        dx = x2 - x;
-        if (projectRight)
-            dx += ((lw + 1) >> 1);
-        dy = lw;
-        FILL_RECT(infoRec->pScrn, x, y, dx, dy);
-    }
-    else if (!dx) {
-        leftFace->xa = (double) lw / 2.0;
-        leftFace->ya = 0;
-        leftFace->k = (double) (lw * dy) / 2.0;
-        rightFace->xa = -leftFace->xa;
-        rightFace->ya = 0;
-        rightFace->k = leftFace->k;
-        y = y1;
-        if (projectLeft)
-            y -= lw >> 1;
-        x = x1 - (lw >> 1);
-        dy = y2 - y;
-        if (projectRight)
-            dy += ((lw + 1) >> 1);
-        dx = lw;
-        FILL_RECT(infoRec->pScrn, x, y, dx, dy);
-    }
-    else {
-        l = ((double) lw) / 2.0;
-        L = sqrt((double) (dx * dx + dy * dy));
-
-        if (dx < 0) {
-            right = &rights[1];
-            left = &lefts[0];
-            top = &rights[0];
-            bottom = &lefts[1];
-        }
-        else {
-            right = &rights[0];
-            left = &lefts[1];
-            top = &lefts[0];
-            bottom = &rights[1];
-        }
-        r = l / L;
-
-        /* coord of upper bound at integral y */
-        ya = -r * dx;
-        xa = r * dy;
-
-        projectXoff = -ya;
-        projectYoff = xa;
-
-        /* xa * dy - ya * dx */
-        k = l * L;
-
-        leftFace->xa = xa;
-        leftFace->ya = ya;
-        leftFace->k = k;
-        rightFace->xa = -xa;
-        rightFace->ya = -ya;
-        rightFace->k = k;
-
-        if (projectLeft)
-            righty = miPolyBuildEdge(xa - projectXoff, ya - projectYoff,
-                                     k, dx, dy, x1, y1, 0, right);
-        else
-            righty = miPolyBuildEdge(xa, ya, k, dx, dy, x1, y1, 0, right);
-
-        /* coord of lower bound at integral y */
-        ya = -ya;
-        xa = -xa;
-
-        /* xa * dy - ya * dx */
-        k = -k;
-
-        if (projectLeft)
-            lefty = miPolyBuildEdge(xa - projectXoff, ya - projectYoff,
-                                    k, dx, dy, x1, y1, 1, left);
-        else
-            lefty = miPolyBuildEdge(xa, ya, k, dx, dy, x1, y1, 1, left);
-
-        /* coord of top face at integral y */
-
-        if (signdx > 0) {
-            ya = -ya;
-            xa = -xa;
-        }
-
-        if (projectLeft) {
-            double xap = xa - projectXoff;
-            double yap = ya - projectYoff;
-
-            topy = miPolyBuildEdge(xap, yap, xap * dx + yap * dy,
-                                   -dy, dx, x1, y1, dx > 0, top);
-        }
-        else
-            topy = miPolyBuildEdge(xa, ya, 0.0, -dy, dx, x1, y1, dx > 0, top);
-
-        /* coord of bottom face at integral y */
-
-        if (projectRight) {
-            double xap = xa + projectXoff;
-            double yap = ya + projectYoff;
-
-            bottomy = miPolyBuildEdge(xap, yap, xap * dx + yap * dy,
-                                      -dy, dx, x2, y2, dx < 0, bottom);
-            maxy = -ya + projectYoff;
-        }
-        else {
-            bottomy = miPolyBuildEdge(xa, ya, 0.0,
-                                      -dy, dx, x2, y2, dx < 0, bottom);
-            maxy = -ya;
-        }
-
-        finaly = ICEIL(maxy) + y2;
-
-        if (dx < 0) {
-            left->height = bottomy - lefty;
-            right->height = finaly - righty;
-            top->height = righty - topy;
-        }
-        else {
-            right->height = bottomy - righty;
-            left->height = finaly - lefty;
-            top->height = lefty - topy;
-        }
-        bottom->height = finaly - bottomy;
-        XAAFillPolyHelper(pGC, topy,
-                          bottom->height + bottomy - topy, lefts, rights, 2, 2);
-    }
-}
-
-static void
-XAALineArcI(GCPtr pGC, int xorg, int yorg)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int x, y, e, ex;
-    int slw = pGC->lineWidth;
-    Bool hardClip = (infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_FILL);
-
-    y = (slw >> 1) + 1;
-    if (slw & 1)
-        e = -((y << 2) + 3);
-    else
-        e = -(y << 3);
-    ex = -4;
-    x = 0;
-    while (y) {
-        e += (y << 3) - 4;
-        while (e >= 0) {
-            x++;
-            e += (ex = -((x << 3) + 4));
-        }
-        y--;
-        slw = (x << 1) + 1;
-        if ((e == ex) && (slw > 1))
-            slw--;
-
-        FILL_SPAN(infoRec->pScrn, xorg - x, yorg - y, slw);
-
-        if ((y != 0) && ((slw > 1) || (e != ex))) {
-            FILL_SPAN(infoRec->pScrn, xorg - x, yorg + y, slw);
-        }
-    }
-}
-
-static void
-XAALineArcD(GCPtr pGC,
-            double xorg,
-            double yorg,
-            PolyEdgePtr edge1,
-            int edgey1,
-            Bool edgeleft1, PolyEdgePtr edge2, int edgey2, Bool edgeleft2)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    double radius, x0, y0, el, er, yk, xlk, xrk, k;
-    int xbase, ybase, y, boty, xl, xr, xcl, xcr;
-    int ymin, ymax;
-    Bool edge1IsMin, edge2IsMin;
-    int ymin1, ymin2;
-    Bool hardClip = (infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_FILL);
-
-    xbase = floor(xorg);
-    x0 = xorg - xbase;
-    ybase = ICEIL(yorg);
-    y0 = yorg - ybase;
-
-    xlk = x0 + x0 + 1.0;
-    xrk = x0 + x0 - 1.0;
-    yk = y0 + y0 - 1.0;
-    radius = ((double) pGC->lineWidth) / 2.0;
-    y = floor(radius - y0 + 1.0);
-    ybase -= y;
-    ymin = ybase;
-    ymax = 65536;
-    edge1IsMin = FALSE;
-    ymin1 = edgey1;
-    if (edge1->dy >= 0) {
-        if (!edge1->dy) {
-            if (edgeleft1)
-                edge1IsMin = TRUE;
-            else
-                ymax = edgey1;
-            edgey1 = 65536;
-        }
-        else if ((edge1->signdx < 0) == edgeleft1)
-            edge1IsMin = TRUE;
-    }
-    edge2IsMin = FALSE;
-    ymin2 = edgey2;
-    if (edge2->dy >= 0) {
-        if (!edge2->dy) {
-            if (edgeleft2)
-                edge2IsMin = TRUE;
-            else
-                ymax = edgey2;
-            edgey2 = 65536;
-        }
-        else if ((edge2->signdx < 0) == edgeleft2)
-            edge2IsMin = TRUE;
-    }
-    if (edge1IsMin) {
-        ymin = ymin1;
-        if (edge2IsMin && (ymin1 > ymin2))
-            ymin = ymin2;
-    }
-    else if (edge2IsMin)
-        ymin = ymin2;
-    el = radius * radius - ((y + y0) * (y + y0)) - (x0 * x0);
-    er = el + xrk;
-    xl = 1;
-    xr = 0;
-    if (x0 < 0.5) {
-        xl = 0;
-        el -= xlk;
-    }
-    boty = (y0 < -0.5) ? 1 : 0;
-    if (ybase + y - boty > ymax)
-        boty = ymax - ybase - y;
-    while (y > boty) {
-        k = (y << 1) + yk;
-        er += k;
-        while (er > 0.0) {
-            xr++;
-            er += xrk - (xr << 1);
-        }
-        el += k;
-        while (el >= 0.0) {
-            xl--;
-            el += (xl << 1) - xlk;
-        }
-        y--;
-        ybase++;
-        if (ybase < ymin)
-            continue;
-        xcl = xl + xbase;
-        xcr = xr + xbase;
-        CLIPSTEPEDGE(edgey1, edge1, edgeleft1);
-        CLIPSTEPEDGE(edgey2, edge2, edgeleft2);
-        if (xcr >= xcl) {
-            FILL_SPAN(infoRec->pScrn, xcl, ybase, xcr - xcl + 1);
-        }
-    }
-    er = xrk - (xr << 1) - er;
-    el = (xl << 1) - xlk - el;
-    boty = floor(-y0 - radius + 1.0);
-    if (ybase + y - boty > ymax)
-        boty = ymax - ybase - y;
-    while (y > boty) {
-        k = (y << 1) + yk;
-        er -= k;
-        while ((er >= 0.0) && (xr >= 0)) {
-            xr--;
-            er += xrk - (xr << 1);
-        }
-        el -= k;
-        while ((el > 0.0) && (xl <= 0)) {
-            xl++;
-            el += (xl << 1) - xlk;
-        }
-        y--;
-        ybase++;
-        if (ybase < ymin)
-            continue;
-        xcl = xl + xbase;
-        xcr = xr + xbase;
-        CLIPSTEPEDGE(edgey1, edge1, edgeleft1);
-        CLIPSTEPEDGE(edgey2, edge2, edgeleft2);
-        if (xcr >= xcl) {
-            FILL_SPAN(infoRec->pScrn, xcl, ybase, xcr - xcl + 1);
-        }
-    }
-}
-
-static void
-XAALineArc(GCPtr pGC,
-           LineFacePtr leftFace,
-           LineFacePtr rightFace, double xorg, double yorg, Bool isInt)
-{
-    int xorgi, yorgi;
-    PolyEdgeRec edge1, edge2;
-    int edgey1, edgey2;
-    Bool edgeleft1, edgeleft2;
-
-    if (isInt) {
-        xorgi = leftFace ? leftFace->x : rightFace->x;
-        yorgi = leftFace ? leftFace->y : rightFace->y;
-    }
-    else {                      /* Muffle compiler */
-        xorgi = yorgi = 0;
-    }
-    edgey1 = 65536;
-    edgey2 = 65536;
-    edge1.x = 0;                /* not used, keep memory checkers happy */
-    edge1.dy = -1;
-    edge2.x = 0;                /* not used, keep memory checkers happy */
-    edge2.dy = -1;
-    edgeleft1 = FALSE;
-    edgeleft2 = FALSE;
-
-    if ((pGC->lineWidth > 2) &&
-        ((pGC->capStyle == CapRound && pGC->joinStyle != JoinRound) ||
-         (pGC->joinStyle == JoinRound && pGC->capStyle == CapButt))) {
-        if (isInt) {
-            xorg = (double) xorgi;
-            yorg = (double) yorgi;
-        }
-
-        if (leftFace && rightFace)
-            miRoundJoinClip(leftFace, rightFace, &edge1, &edge2,
-                            &edgey1, &edgey2, &edgeleft1, &edgeleft2);
-        else if (leftFace)
-            edgey1 = miRoundCapClip(leftFace, isInt, &edge1, &edgeleft1);
-        else if (rightFace)
-            edgey2 = miRoundCapClip(rightFace, isInt, &edge2, &edgeleft2);
-
-        isInt = FALSE;
-    }
-
-    if (isInt) {
-        if (pGC->lineWidth == 1) {
-            XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-            Bool hardClip = (infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_FILL);
-
-            DRAW_POINT(infoRec->pScrn, xorgi, yorgi);
-        }
-        else
-            XAALineArcI(pGC, xorgi, yorgi);
-    }
-    else
-        XAALineArcD(pGC, xorg, yorg, &edge1, edgey1, edgeleft1,
-                    &edge2, edgey2, edgeleft2);
-
-}
-
-static void
-XAALineJoin(GCPtr pGC, LineFacePtr pLeft, LineFacePtr pRight)
-{
-    double mx = 0, my = 0;
-    double denom = 0;
-    PolyVertexRec vertices[4];
-    PolySlopeRec slopes[4];
-    int edgecount;
-    PolyEdgeRec left[4], right[4];
-    int nleft, nright;
-    int y, height;
-    int swapslopes;
-    int joinStyle = pGC->joinStyle;
-    int lw = pGC->lineWidth;
-
-    if (lw == 1) {
-        /* Lines going in the same direction have no join */
-        if ((pLeft->dx >= 0) == (pRight->dx <= 0))
-            return;
-        if (joinStyle != JoinRound) {
-            denom = -pLeft->dx * (double) pRight->dy + pRight->dx *
-                (double) pLeft->dy;
-            if (denom == 0.0)
-                return;         /* no join to draw */
-        }
-        if (joinStyle != JoinMiter) {
-            XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-            Bool hardClip = (infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_FILL);
-
-            DRAW_POINT(infoRec->pScrn, pLeft->x, pLeft->y);
-            return;
-        }
-    }
-    else {
-        if (joinStyle == JoinRound) {
-            XAALineArc(pGC, pLeft, pRight, (double) 0.0, (double) 0.0, TRUE);
-            return;
-        }
-        denom = -pLeft->dx * (double) pRight->dy + pRight->dx *
-            (double) pLeft->dy;
-        if (denom == 0.0)
-            return;             /* no join to draw */
-    }
-
-    swapslopes = 0;
-    if (denom > 0) {
-        pLeft->xa = -pLeft->xa;
-        pLeft->ya = -pLeft->ya;
-        pLeft->dx = -pLeft->dx;
-        pLeft->dy = -pLeft->dy;
-    }
-    else {
-        swapslopes = 1;
-        pRight->xa = -pRight->xa;
-        pRight->ya = -pRight->ya;
-        pRight->dx = -pRight->dx;
-        pRight->dy = -pRight->dy;
-    }
-
-    vertices[0].x = pRight->xa;
-    vertices[0].y = pRight->ya;
-    slopes[0].dx = -pRight->dy;
-    slopes[0].dy = pRight->dx;
-    slopes[0].k = 0;
-
-    vertices[1].x = 0;
-    vertices[1].y = 0;
-    slopes[1].dx = pLeft->dy;
-    slopes[1].dy = -pLeft->dx;
-    slopes[1].k = 0;
-
-    vertices[2].x = pLeft->xa;
-    vertices[2].y = pLeft->ya;
-
-    if (joinStyle == JoinMiter) {
-        my = (pLeft->dy * (pRight->xa * pRight->dy - pRight->ya * pRight->dx) -
-              pRight->dy * (pLeft->xa * pLeft->dy - pLeft->ya * pLeft->dx)) /
-            denom;
-        if (pLeft->dy != 0)
-            mx = pLeft->xa + (my - pLeft->ya) *
-                (double) pLeft->dx / (double) pLeft->dy;
-        else
-            mx = pRight->xa + (my - pRight->ya) *
-                (double) pRight->dx / (double) pRight->dy;
-
-        /* check miter limit */
-        if ((mx * mx + my * my) * 4 > SQSECANT * lw * lw)
-            joinStyle = JoinBevel;
-    }
-
-    if (joinStyle == JoinMiter) {
-        slopes[2].dx = pLeft->dx;
-        slopes[2].dy = pLeft->dy;
-        slopes[2].k = pLeft->k;
-        if (swapslopes) {
-            slopes[2].dx = -slopes[2].dx;
-            slopes[2].dy = -slopes[2].dy;
-            slopes[2].k = -slopes[2].k;
-        }
-        vertices[3].x = mx;
-        vertices[3].y = my;
-        slopes[3].dx = pRight->dx;
-        slopes[3].dy = pRight->dy;
-        slopes[3].k = pRight->k;
-        if (swapslopes) {
-            slopes[3].dx = -slopes[3].dx;
-            slopes[3].dy = -slopes[3].dy;
-            slopes[3].k = -slopes[3].k;
-        }
-        edgecount = 4;
-    }
-    else {
-        double scale, dx, dy, adx, ady;
-
-        adx = dx = pRight->xa - pLeft->xa;
-        ady = dy = pRight->ya - pLeft->ya;
-        if (adx < 0)
-            adx = -adx;
-        if (ady < 0)
-            ady = -ady;
-        scale = ady;
-        if (adx > ady)
-            scale = adx;
-        slopes[2].dx = (dx * 65536) / scale;
-        slopes[2].dy = (dy * 65536) / scale;
-        slopes[2].k = ((pLeft->xa + pRight->xa) * slopes[2].dy -
-                       (pLeft->ya + pRight->ya) * slopes[2].dx) / 2.0;
-        edgecount = 3;
-    }
-
-    y = miPolyBuildPoly(vertices, slopes, edgecount, pLeft->x, pLeft->y,
-                        left, right, &nleft, &nright, &height);
-    XAAFillPolyHelper(pGC, y, height, left, right, nleft, nright);
-}
-
-void
-XAAPolylinesWideSolid(DrawablePtr pDrawable,
-                      GCPtr pGC, int mode, int npt, DDXPointPtr pPts)
-{
-    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    int x1, y1, x2, y2;
-    Bool projectLeft, projectRight;
-    LineFaceRec leftFace, rightFace, prevRightFace, firstFace;
-    int first = TRUE;
-    Bool somethingDrawn = FALSE;
-    Bool selfJoin = FALSE;
-    int xorg = pDrawable->x;
-    int yorg = pDrawable->y;
-    Bool hardClip = FALSE;
-
-    if (!RegionNumRects(pGC->pCompositeClip))
-        return;
-
-    if (RegionNumRects(pGC->pCompositeClip) != 1) {
-        miWideLine(pDrawable, pGC, mode, npt, pPts);
-        return;
-    }
-
-    x2 = pPts->x;
-    y2 = pPts->y;
-    if (npt > 1) {
-        if (mode == CoordModePrevious) {
-            int nptTmp;
-            register DDXPointPtr pPtsTmp;
-
-            x1 = x2;
-            y1 = y2;
-            nptTmp = npt;
-            pPtsTmp = pPts + 1;
-            while (--nptTmp) {
-                x1 += pPtsTmp->x;
-                y1 += pPtsTmp->y;
-                ++pPtsTmp;
-            }
-            if ((x2 == x1) && (y2 == y1))
-                selfJoin = TRUE;
-        }
-        else if ((x2 == pPts[npt - 1].x) && (y2 == pPts[npt - 1].y))
-            selfJoin = TRUE;
-    }
-
-    projectLeft = ((pGC->capStyle == CapProjecting) && !selfJoin);
-    projectRight = FALSE;
-
-    (*infoRec->SetupForSolidFill) (infoRec->pScrn, pGC->fgPixel, pGC->alu,
-                                   pGC->planemask);
-
-    infoRec->ClipBox = &pGC->pCompositeClip->extents;
-
-    if (infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_FILL) {
-        hardClip = TRUE;
-        (*infoRec->SetClippingRectangle) (infoRec->pScrn,
-                                          infoRec->ClipBox->x1,
-                                          infoRec->ClipBox->y1,
-                                          infoRec->ClipBox->x2 - 1,
-                                          infoRec->ClipBox->y2 - 1);
-    }
-
-    x2 += xorg;
-    y2 += yorg;
-    while (--npt) {
-        x1 = x2;
-        y1 = y2;
-        ++pPts;
-        x2 = pPts->x;
-        y2 = pPts->y;
-        if (mode == CoordModePrevious) {
-            x2 += x1;
-            y2 += y1;
-        }
-        else {
-            x2 += xorg;
-            y2 += yorg;
-        }
-        if ((x1 != x2) || (y1 != y2)) {
-            somethingDrawn = TRUE;
-            if ((npt == 1) && (pGC->capStyle == CapProjecting) && !selfJoin)
-                projectRight = TRUE;
-            XAAWideSegment(pGC, x1, y1, x2, y2,
-                           projectLeft, projectRight, &leftFace, &rightFace);
-            if (first) {
-                if (selfJoin)
-                    firstFace = leftFace;
-                else if (pGC->capStyle == CapRound) {
-                    if (pGC->lineWidth == 1) {
-                        DRAW_POINT(infoRec->pScrn, x1, y1);
-                    }
-                    else
-                        XAALineArc(pGC, &leftFace, (LineFacePtr) NULL,
-                                   (double) 0.0, (double) 0.0, TRUE);
-                }
-            }
-            else
-                XAALineJoin(pGC, &leftFace, &prevRightFace);
-
-            prevRightFace = rightFace;
-            first = FALSE;
-            projectLeft = FALSE;
-        }
-        if (npt == 1 && somethingDrawn) {
-            if (selfJoin)
-                XAALineJoin(pGC, &firstFace, &rightFace);
-            else if (pGC->capStyle == CapRound) {
-                if (pGC->lineWidth == 1) {
-                    DRAW_POINT(infoRec->pScrn, x2, y2);
-                }
-                else
-                    XAALineArc(pGC, (LineFacePtr) NULL, &rightFace,
-                               (double) 0.0, (double) 0.0, TRUE);
-            }
-        }
-    }
-    /* handle crock where all points are coincedent */
-    if (!somethingDrawn) {
-        projectLeft = (pGC->capStyle == CapProjecting);
-        XAAWideSegment(pGC, x2, y2, x2, y2, projectLeft, projectLeft,
-                       &leftFace, &rightFace);
-        if (pGC->capStyle == CapRound) {
-            XAALineArc(pGC, &leftFace, (LineFacePtr) NULL,
-                       (double) 0.0, (double) 0.0, TRUE);
-            rightFace.dx = -1;  /* sleezy hack to make it work */
-            XAALineArc(pGC, (LineFacePtr) NULL, &rightFace,
-                       (double) 0.0, (double) 0.0, TRUE);
-        }
-    }
-
-    infoRec->ClipBox = NULL;
-    if (hardClip)
-        (*infoRec->DisableClipping) (infoRec->pScrn);
-
-    SET_SYNC_FLAG(infoRec);
-}
diff --git a/hw/xfree86/xaa/xaacexp.h b/hw/xfree86/xaa/xaacexp.h
deleted file mode 100644
index 6fde54c..0000000
--- a/hw/xfree86/xaa/xaacexp.h
+++ /dev/null
@@ -1,126 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/Xarch.h>
-
-#ifndef FIXEDBASE
-#define CHECKRETURN(b) if(width <= ((b) * 32)) return(base + (b))
-#else
-#define CHECKRETURN(b) if(width <= ((b) * 32)) return(base)
-#endif
-
-#if X_BYTE_ORDER == X_BIG_ENDIAN
-#define SHIFT_L(value, shift) ((value) >> (shift))
-#define SHIFT_R(value, shift) ((value) << (shift))
-#else
-#define SHIFT_L(value, shift) ((value) << (shift))
-#define SHIFT_R(value, shift) ((value) >> (shift))
-#endif
-
-#ifndef MSBFIRST
-#ifdef FIXEDBASE
-#define WRITE_IN_BITORDER(dest, offset, data) *(dest) = data;
-#else
-#define WRITE_IN_BITORDER(dest, offset, data) *(dest + offset) = data;
-#endif
-#else
-#ifdef FIXEDBASE
-#define WRITE_IN_BITORDER(dest, offset, data) *(dest) = SWAP_BITS_IN_BYTES(data);
-#else
-#define WRITE_IN_BITORDER(dest, offset, data) *(dest + offset) = SWAP_BITS_IN_BYTES(data)
-#endif
-#endif
-
-#ifdef FIXEDBASE
-#ifdef MSBFIRST
-#define WRITE_BITS(b)   *base = SWAP_BITS_IN_BYTES(b)
-#define WRITE_BITS1(b) { \
-	*base = byte_reversed_expand3[(b) & 0xFF] | \
-		byte_reversed_expand3[((b) & 0xFF00) >> 8] << 24; }
-#define WRITE_BITS2(b) { \
-	*base = byte_reversed_expand3[(b) & 0xFF] | \
-		byte_reversed_expand3[((b) & 0xFF00) >> 8] << 24; \
-	*base = byte_reversed_expand3[((b) & 0xFF00) >> 8] >> 8 | \
-		byte_reversed_expand3[((b) & 0xFF0000) >> 16] << 16; }
-#define WRITE_BITS3(b) { \
-	*base = byte_reversed_expand3[(b) & 0xFF] | \
-		byte_reversed_expand3[((b) & 0xFF00) >> 8] << 24; \
-	*base = byte_reversed_expand3[((b) & 0xFF00) >> 8] >> 8 | \
-		byte_reversed_expand3[((b) & 0xFF0000) >> 16] << 16; \
-	*base = byte_reversed_expand3[((b) & 0xFF0000) >> 16] >> 16 | \
-		byte_reversed_expand3[((b) & 0xFF000000) >> 24] << 8; }
-#else
-#define WRITE_BITS(b)   *base = (b)
-#define WRITE_BITS1(b) { \
-	*base = byte_expand3[(b) & 0xFF] | \
-		byte_expand3[((b) & 0xFF00) >> 8] << 24; }
-#define WRITE_BITS2(b) { \
-	*base = byte_expand3[(b) & 0xFF] | \
-		byte_expand3[((b) & 0xFF00) >> 8] << 24; \
-	*base = byte_expand3[((b) & 0xFF00) >> 8] >> 8 | \
-		byte_expand3[((b) & 0xFF0000) >> 16] << 16; }
-#define WRITE_BITS3(b) { \
-	*base = byte_expand3[(b) & 0xFF] | \
-		byte_expand3[((b) & 0xFF00) >> 8] << 24; \
-	*base = byte_expand3[((b) & 0xFF00) >> 8] >> 8 | \
-		byte_expand3[((b) & 0xFF0000) >> 16] << 16; \
-	*base = byte_expand3[((b) & 0xFF0000) >> 16] >> 16 | \
-		byte_expand3[((b) & 0xFF000000) >> 24] << 8; }
-#endif
-#else
-#ifdef MSBFIRST
-#define WRITE_BITS(b)   *(base++) = SWAP_BITS_IN_BYTES(b)
-#define WRITE_BITS1(b) { \
-	*(base++) = byte_reversed_expand3[(b) & 0xFF] | \
-		byte_reversed_expand3[((b) & 0xFF00) >> 8] << 24; }
-#define WRITE_BITS2(b) { \
-	*(base) = byte_reversed_expand3[(b) & 0xFF] | \
-		byte_reversed_expand3[((b) & 0xFF00) >> 8] << 24; \
-	*(base + 1) = byte_reversed_expand3[((b) & 0xFF00) >> 8] >> 8 | \
-		byte_reversed_expand3[((b) & 0xFF0000) >> 16] << 16; \
-	base += 2; }
-#define WRITE_BITS3(b) { \
-	*(base) = byte_reversed_expand3[(b) & 0xFF] | \
-		byte_reversed_expand3[((b) & 0xFF00) >> 8] << 24; \
-	*(base + 1) = byte_reversed_expand3[((b) & 0xFF00) >> 8] >> 8 | \
-		byte_reversed_expand3[((b) & 0xFF0000) >> 16] << 16; \
-	*(base + 2) = byte_reversed_expand3[((b) & 0xFF0000) >> 16] >> 16 | \
-		byte_reversed_expand3[((b) & 0xFF000000) >> 24] << 8; \
-	base += 3; }
-#else
-#define WRITE_BITS(b)   *(base++) = (b)
-#define WRITE_BITS1(b) { \
-	*(base++) = byte_expand3[(b) & 0xFF] | \
-		byte_expand3[((b) & 0xFF00) >> 8] << 24; }
-#define WRITE_BITS2(b) { \
-	*(base) = byte_expand3[(b) & 0xFF] | \
-		byte_expand3[((b) & 0xFF00) >> 8] << 24; \
-	*(base + 1) = byte_expand3[((b) & 0xFF00) >> 8] >> 8 | \
-		byte_expand3[((b) & 0xFF0000) >> 16] << 16; \
-	base += 2; }
-#define WRITE_BITS3(b) { \
-	*(base) = byte_expand3[(b) & 0xFF] | \
-		byte_expand3[((b) & 0xFF00) >> 8] << 24; \
-	*(base + 1) = byte_expand3[((b) & 0xFF00) >> 8] >> 8 | \
-		byte_expand3[((b) & 0xFF0000) >> 16] << 16; \
-	*(base + 2) = byte_expand3[((b) & 0xFF0000) >> 16] >> 16 | \
-		byte_expand3[((b) & 0xFF000000) >> 24] << 8; \
-	base += 3; }
-#endif
-#endif
-
-#ifdef FIXEDBASE
-#ifdef MSBFIRST
-#define EXPNAME(x) x##MSBFirstFixedBase
-#else
-#define EXPNAME(x) x##LSBFirstFixedBase
-#endif
-#else
-#ifdef MSBFIRST
-#define EXPNAME(x) x##MSBFirst
-#else
-#define EXPNAME(x) x##LSBFirst
-#endif
-#endif
diff --git a/hw/xfree86/xaa/xaalocal.h b/hw/xfree86/xaa/xaalocal.h
deleted file mode 100644
index 61d9eeb..0000000
--- a/hw/xfree86/xaa/xaalocal.h
+++ /dev/null
@@ -1,1437 +0,0 @@
-
-#ifndef _XAALOCAL_H
-#define _XAALOCAL_H
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-/* This file is very unorganized ! */
-
-#include "gcstruct.h"
-#include "regionstr.h"
-#include "xf86fbman.h"
-#include "xaa.h"
-#include "mi.h"
-#include "picturestr.h"
-
-#define GCWhenForced		(GCArcMode << 1)
-
-#define DO_COLOR_8x8		0x00000001
-#define DO_MONO_8x8		0x00000002
-#define DO_CACHE_BLT		0x00000003
-#define DO_COLOR_EXPAND		0x00000004
-#define DO_CACHE_EXPAND		0x00000005
-#define DO_IMAGE_WRITE		0x00000006
-#define DO_PIXMAP_COPY		0x00000007
-#define DO_SOLID		0x00000008
-
-typedef CARD32 *(*GlyphScanlineFuncPtr) (CARD32 *base, unsigned int **glyphp,
-                                         int line, int nglyph, int width);
-
-typedef CARD32 *(*StippleScanlineProcPtr) (CARD32 *, CARD32 *, int, int, int);
-
-typedef void (*RectFuncPtr) (ScrnInfoPtr, int, int, int, int, int, int,
-                             XAACacheInfoPtr);
-typedef void (*TrapFuncPtr) (ScrnInfoPtr, int, int, int, int, int, int,
-                             int, int, int, int, int, int, XAACacheInfoPtr);
-
-typedef struct _XAAScreen {
-    CreateGCProcPtr CreateGC;
-    CloseScreenProcPtr CloseScreen;
-    GetImageProcPtr GetImage;
-    GetSpansProcPtr GetSpans;
-    CopyWindowProcPtr CopyWindow;
-    WindowExposuresProcPtr WindowExposures;
-    CreatePixmapProcPtr CreatePixmap;
-    DestroyPixmapProcPtr DestroyPixmap;
-    ChangeWindowAttributesProcPtr ChangeWindowAttributes;
-    XAAInfoRecPtr AccelInfoRec;
-    Bool (*EnterVT) (ScrnInfoPtr);
-    void (*LeaveVT) (ScrnInfoPtr);
-    int (*SetDGAMode) (ScrnInfoPtr, int, DGADevicePtr);
-    void (*EnableDisableFBAccess) (ScrnInfoPtr, Bool);
-    CompositeProcPtr Composite;
-    GlyphsProcPtr Glyphs;
-} XAAScreenRec, *XAAScreenPtr;
-
-#define	OPS_ARE_PIXMAP		0x00000001
-#define OPS_ARE_ACCEL		0x00000002
-
-typedef struct _XAAGC {
-    GCOps *wrapOps;
-    GCFuncs *wrapFuncs;
-    GCOps *XAAOps;
-    int DashLength;
-    unsigned char *DashPattern;
-    unsigned long changes;
-    unsigned long flags;
-} XAAGCRec, *XAAGCPtr;
-
-#define REDUCIBILITY_CHECKED	0x00000001
-#define REDUCIBLE_TO_8x8	0x00000002
-#define REDUCIBLE_TO_2_COLOR	0x00000004
-#define DIRTY			0x00010000
-#define OFFSCREEN		0x00020000
-#define DGA_PIXMAP		0x00040000
-#define SHARED_PIXMAP		0x00080000
-#define LOCKED_PIXMAP		0x00100000
-
-#define REDUCIBILITY_MASK \
- (REDUCIBILITY_CHECKED | REDUCIBLE_TO_8x8 | REDUCIBLE_TO_2_COLOR)
-
-typedef struct _XAAPixmap {
-    unsigned long flags;
-    CARD32 pattern0;
-    CARD32 pattern1;
-    int fg;
-    int bg;
-    FBAreaPtr offscreenArea;
-    Bool freeData;
-} XAAPixmapRec, *XAAPixmapPtr;
-
-extern _X_EXPORT Bool
- XAACreateGC(GCPtr pGC);
-
-extern _X_EXPORT Bool
- XAAInitAccel(ScreenPtr pScreen, XAAInfoRecPtr infoRec);
-
-extern _X_EXPORT RegionPtr
-
-XAABitBlt(DrawablePtr pSrcDrawable,
-          DrawablePtr pDstDrawable,
-          GC * pGC,
-          int srcx,
-          int srcy,
-          int width,
-          int height,
-          int dstx,
-          int dsty,
-          void (*doBitBlt) (DrawablePtr, DrawablePtr, GCPtr, RegionPtr,
-                            DDXPointPtr), unsigned long bitPlane);
-
-extern _X_EXPORT void
-
-XAAScreenToScreenBitBlt(ScrnInfoPtr pScrn,
-                        int nbox,
-                        DDXPointPtr pptSrc,
-                        BoxPtr pbox,
-                        int xdir, int ydir, int alu, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAADoBitBlt(DrawablePtr pSrc,
-            DrawablePtr pDst, GC * pGC, RegionPtr prgnDst, DDXPointPtr pptSrc);
-
-extern _X_EXPORT void
-
-XAADoImageWrite(DrawablePtr pSrc,
-                DrawablePtr pDst,
-                GC * pGC, RegionPtr prgnDst, DDXPointPtr pptSrc);
-
-extern _X_EXPORT void
-
-XAADoImageRead(DrawablePtr pSrc,
-               DrawablePtr pDst,
-               GC * pGC, RegionPtr prgnDst, DDXPointPtr pptSrc);
-
-extern _X_EXPORT void
- XAACopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
-
-extern _X_EXPORT RegionPtr
-
-XAACopyArea(DrawablePtr pSrcDrawable,
-            DrawablePtr pDstDrawable,
-            GC * pGC,
-            int srcx, int srcy, int width, int height, int dstx, int dsty);
-
-extern _X_EXPORT void
- XAAValidateCopyArea(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
-
-extern _X_EXPORT void
- XAAValidatePutImage(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
-
-extern _X_EXPORT void
- XAAValidateCopyPlane(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
-
-extern _X_EXPORT void
- XAAValidatePushPixels(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
-
-extern _X_EXPORT void
- XAAValidateFillSpans(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
-
-extern _X_EXPORT void
- XAAValidatePolyGlyphBlt(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
-
-extern _X_EXPORT void
- XAAValidateImageGlyphBlt(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
-
-extern _X_EXPORT void
- XAAValidatePolylines(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
-
-extern _X_EXPORT RegionPtr
-
-XAACopyPlaneColorExpansion(DrawablePtr pSrc,
-                           DrawablePtr pDst,
-                           GCPtr pGC,
-                           int srcx,
-                           int srcy,
-                           int width,
-                           int height,
-                           int dstx, int dsty, unsigned long bitPlane);
-
-extern _X_EXPORT void
-
-XAAPushPixelsSolidColorExpansion(GCPtr pGC,
-                                 PixmapPtr pBitMap,
-                                 DrawablePtr pDrawable,
-                                 int dx, int dy, int xOrg, int yOrg);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapColorExpandMSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                           int x, int y, int w, int h,
-                                           unsigned char *src,
-                                           int srcwidth,
-                                           int skipleft,
-                                           int fg, int bg,
-                                           int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapColorExpand3MSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                            int x, int y, int w, int h,
-                                            unsigned char *src,
-                                            int srcwidth,
-                                            int skipleft,
-                                            int fg, int bg,
-                                            int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapColorExpandMSBFirst(ScrnInfoPtr pScrn,
-                                  int x, int y, int w, int h,
-                                  unsigned char *src,
-                                  int srcwidth,
-                                  int skipleft,
-                                  int fg, int bg,
-                                  int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapColorExpand3MSBFirst(ScrnInfoPtr pScrn,
-                                   int x, int y, int w, int h,
-                                   unsigned char *src,
-                                   int srcwidth,
-                                   int skipleft,
-                                   int fg, int bg,
-                                   int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapColorExpandLSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                           int x, int y, int w, int h,
-                                           unsigned char *src,
-                                           int srcwidth,
-                                           int skipleft,
-                                           int fg, int bg,
-                                           int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapColorExpand3LSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                            int x, int y, int w, int h,
-                                            unsigned char *src,
-                                            int srcwidth,
-                                            int skipleft,
-                                            int fg, int bg,
-                                            int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapColorExpandLSBFirst(ScrnInfoPtr pScrn,
-                                  int x, int y, int w, int h,
-                                  unsigned char *src,
-                                  int srcwidth,
-                                  int skipleft,
-                                  int fg, int bg,
-                                  int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapColorExpand3LSBFirst(ScrnInfoPtr pScrn,
-                                   int x, int y, int w, int h,
-                                   unsigned char *src,
-                                   int srcwidth,
-                                   int skipleft,
-                                   int fg, int bg,
-                                   int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapScanlineColorExpandMSBFirst(ScrnInfoPtr pScrn,
-                                          int x, int y, int w, int h,
-                                          unsigned char *src,
-                                          int srcwidth,
-                                          int skipleft,
-                                          int fg, int bg,
-                                          int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapScanlineColorExpand3MSBFirst(ScrnInfoPtr pScrn,
-                                           int x, int y, int w, int h,
-                                           unsigned char *src,
-                                           int srcwidth,
-                                           int skipleft,
-                                           int fg, int bg,
-                                           int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapScanlineColorExpandMSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                                   int x, int y, int w, int h,
-                                                   unsigned char *src,
-                                                   int srcwidth,
-                                                   int skipleft,
-                                                   int fg, int bg,
-                                                   int rop,
-                                                   unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapScanlineColorExpand3MSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                                    int x, int y, int w, int h,
-                                                    unsigned char *src,
-                                                    int srcwidth,
-                                                    int skipleft,
-                                                    int fg, int bg,
-                                                    int rop,
-                                                    unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapScanlineColorExpandLSBFirst(ScrnInfoPtr pScrn,
-                                          int x, int y, int w, int h,
-                                          unsigned char *src,
-                                          int srcwidth,
-                                          int skipleft,
-                                          int fg, int bg,
-                                          int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapScanlineColorExpand3LSBFirst(ScrnInfoPtr pScrn,
-                                           int x, int y, int w, int h,
-                                           unsigned char *src,
-                                           int srcwidth,
-                                           int skipleft,
-                                           int fg, int bg,
-                                           int rop, unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapScanlineColorExpandLSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                                   int x, int y, int w, int h,
-                                                   unsigned char *src,
-                                                   int srcwidth,
-                                                   int skipleft,
-                                                   int fg, int bg,
-                                                   int rop,
-                                                   unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapScanlineColorExpand3LSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                                    int x, int y, int w, int h,
-                                                    unsigned char *src,
-                                                    int srcwidth,
-                                                    int skipleft,
-                                                    int fg, int bg,
-                                                    int rop,
-                                                    unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAWritePixmap(ScrnInfoPtr pScrn,
-               int x, int y, int w, int h,
-               unsigned char *src,
-               int srcwidth,
-               int rop,
-               unsigned int planemask,
-               int transparency_color, int bpp, int depth);
-
-extern _X_EXPORT void
-
-XAAWritePixmapScanline(ScrnInfoPtr pScrn,
-                       int x, int y, int w, int h,
-                       unsigned char *src,
-                       int srcwidth,
-                       int rop,
-                       unsigned int planemask,
-                       int transparency_color, int bpp, int depth);
-
-typedef void (*ClipAndRenderRectsFunc) (GCPtr, int, BoxPtr, int, int);
-
-extern _X_EXPORT void
-
-XAAClipAndRenderRects(GCPtr pGC,
-                      ClipAndRenderRectsFunc func,
-                      int nrectFill, xRectangle *prectInit, int xorg, int yorg);
-
-typedef void (*ClipAndRenderSpansFunc) (GCPtr, int, DDXPointPtr, int *,
-                                        int, int, int);
-
-extern _X_EXPORT void
-
-XAAClipAndRenderSpans(GCPtr pGC,
-                      DDXPointPtr ppt,
-                      int *pwidth,
-                      int nspans,
-                      int fSorted,
-                      ClipAndRenderSpansFunc func, int xorg, int yorg);
-
-extern _X_EXPORT void
-
-XAAFillSolidRects(ScrnInfoPtr pScrn,
-                  int fg, int rop,
-                  unsigned int planemask, int nBox, BoxPtr pBox);
-
-extern _X_EXPORT void
-
-XAAFillMono8x8PatternRects(ScrnInfoPtr pScrn,
-                           int fg, int bg, int rop,
-                           unsigned int planemask,
-                           int nBox,
-                           BoxPtr pBox, int pat0, int pat1, int xorg, int yorg);
-
-extern _X_EXPORT void
-
-XAAFillMono8x8PatternRectsScreenOrigin(ScrnInfoPtr pScrn,
-                                       int fg, int bg, int rop,
-                                       unsigned int planemask,
-                                       int nBox,
-                                       BoxPtr pBox,
-                                       int pat0, int pat1, int xorg, int yorg);
-
-extern _X_EXPORT void
-
-XAAFillColor8x8PatternRectsScreenOrigin(ScrnInfoPtr pScrn,
-                                        int rop,
-                                        unsigned int planemask,
-                                        int nBox,
-                                        BoxPtr pBox,
-                                        int xorigin, int yorigin,
-                                        XAACacheInfoPtr pCache);
-
-extern _X_EXPORT void
-
-XAAFillColor8x8PatternRects(ScrnInfoPtr pScrn,
-                            int rop,
-                            unsigned int planemask,
-                            int nBox,
-                            BoxPtr pBox,
-                            int xorigin, int yorigin, XAACacheInfoPtr pCache);
-
-extern _X_EXPORT void
-
-XAAFillCacheBltRects(ScrnInfoPtr pScrn,
-                     int rop,
-                     unsigned int planemask,
-                     int nBox,
-                     BoxPtr pBox, int xorg, int yorg, XAACacheInfoPtr pCache);
-
-extern _X_EXPORT void
-
-XAAFillCacheExpandRects(ScrnInfoPtr pScrn,
-                        int fg, int bg, int rop,
-                        unsigned int planemask,
-                        int nBox,
-                        BoxPtr pBox, int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillImageWriteRects(ScrnInfoPtr pScrn,
-                       int rop,
-                       unsigned int planemask,
-                       int nBox,
-                       BoxPtr pBox, int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAPolyFillRect(DrawablePtr pDraw,
-                GCPtr pGC, int nrectFill, xRectangle *prectInit);
-
-extern _X_EXPORT void
-
-XAATEGlyphRendererMSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                    int x, int y, int w, int h, int skipleft,
-                                    int startline, unsigned int **glyphs,
-                                    int glyphWidth, int fg, int bg, int rop,
-                                    unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRenderer3MSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                     int x, int y, int w, int h, int skipleft,
-                                     int startline, unsigned int **glyphs,
-                                     int glyphWidth, int fg, int bg, int rop,
-                                     unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRendererMSBFirst(ScrnInfoPtr pScrn,
-                           int x, int y, int w, int h, int skipleft,
-                           int startline, unsigned int **glyphs, int glyphWidth,
-                           int fg, int bg, int rop, unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRenderer3MSBFirst(ScrnInfoPtr pScrn,
-                            int x, int y, int w, int h, int skipleft,
-                            int startline, unsigned int **glyphs,
-                            int glyphWidth, int fg, int bg, int rop,
-                            unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRendererLSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                    int x, int y, int w, int h, int skipleft,
-                                    int startline, unsigned int **glyphs,
-                                    int glyphWidth, int fg, int bg, int rop,
-                                    unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRenderer3LSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                     int x, int y, int w, int h, int skipleft,
-                                     int startline, unsigned int **glyphs,
-                                     int glyphWidth, int fg, int bg, int rop,
-                                     unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRendererLSBFirst(ScrnInfoPtr pScrn,
-                           int x, int y, int w, int h, int skipleft,
-                           int startline, unsigned int **glyphs, int glyphWidth,
-                           int fg, int bg, int rop, unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRenderer3LSBFirst(ScrnInfoPtr pScrn,
-                            int x, int y, int w, int h, int skipleft,
-                            int startline, unsigned int **glyphs,
-                            int glyphWidth, int fg, int bg, int rop,
-                            unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRendererScanlineMSBFirst(ScrnInfoPtr pScrn,
-                                   int x, int y, int w, int h, int skipleft,
-                                   int startline, unsigned int **glyphs,
-                                   int glyphWidth, int fg, int bg, int rop,
-                                   unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRendererScanline3MSBFirst(ScrnInfoPtr pScrn,
-                                    int x, int y, int w, int h, int skipleft,
-                                    int startline, unsigned int **glyphs,
-                                    int glyphWidth, int fg, int bg, int rop,
-                                    unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRendererScanlineLSBFirst(ScrnInfoPtr pScrn,
-                                   int x, int y, int w, int h, int skipleft,
-                                   int startline, unsigned int **glyphs,
-                                   int glyphWidth, int fg, int bg, int rop,
-                                   unsigned planemask);
-
-extern _X_EXPORT void
-
-XAATEGlyphRendererScanline3LSBFirst(ScrnInfoPtr pScrn,
-                                    int x, int y, int w, int h, int skipleft,
-                                    int startline, unsigned int **glyphs,
-                                    int glyphWidth, int fg, int bg, int rop,
-                                    unsigned planemask);
-
-extern _X_EXPORT CARD32 *(*XAAGlyphScanlineFuncMSBFirstFixedBase[32]) (CARD32
-                                                                       *base,
-                                                                       unsigned
-                                                                       int
-                                                                       **glyphp,
-                                                                       int line,
-                                                                       int
-                                                                       nglyph,
-                                                                       int
-                                                                       width);
-
-extern _X_EXPORT CARD32 *(*XAAGlyphScanlineFuncMSBFirst[32]) (CARD32 *base,
-                                                              unsigned int
-                                                              **glyphp,
-                                                              int line,
-                                                              int nglyph,
-                                                              int width);
-
-extern _X_EXPORT CARD32 *(*XAAGlyphScanlineFuncLSBFirstFixedBase[32]) (CARD32
-                                                                       *base,
-                                                                       unsigned
-                                                                       int
-                                                                       **glyphp,
-                                                                       int line,
-                                                                       int
-                                                                       nglyph,
-                                                                       int
-                                                                       width);
-
-extern _X_EXPORT CARD32 *(*XAAGlyphScanlineFuncLSBFirst[32]) (CARD32 *base,
-                                                              unsigned int
-                                                              **glyphp,
-                                                              int line,
-                                                              int nglyph,
-                                                              int width);
-
-extern _X_EXPORT GlyphScanlineFuncPtr
-    *XAAGetGlyphScanlineFuncMSBFirstFixedBase(void);
-extern _X_EXPORT GlyphScanlineFuncPtr *XAAGetGlyphScanlineFuncMSBFirst(void);
-extern _X_EXPORT GlyphScanlineFuncPtr
-    *XAAGetGlyphScanlineFuncLSBFirstFixedBase(void);
-extern _X_EXPORT GlyphScanlineFuncPtr *XAAGetGlyphScanlineFuncLSBFirst(void);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandRectsLSBFirst(ScrnInfoPtr pScrn,
-                                int fg, int bg, int rop,
-                                unsigned int planemask,
-                                int nBox,
-                                BoxPtr pBox,
-                                int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandRects3LSBFirst(ScrnInfoPtr pScrn,
-                                 int fg, int bg, int rop,
-                                 unsigned int planemask,
-                                 int nBox,
-                                 BoxPtr pBox,
-                                 int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandRectsLSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                         int fg, int bg, int rop,
-                                         unsigned int planemask,
-                                         int nBox,
-                                         BoxPtr pBox,
-                                         int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandRects3LSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                          int fg, int bg, int rop,
-                                          unsigned int planemask,
-                                          int nBox,
-                                          BoxPtr pBox,
-                                          int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandRectsMSBFirst(ScrnInfoPtr pScrn,
-                                int fg, int bg, int rop,
-                                unsigned int planemask,
-                                int nBox,
-                                BoxPtr pBox,
-                                int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandRects3MSBFirst(ScrnInfoPtr pScrn,
-                                 int fg, int bg, int rop,
-                                 unsigned int planemask,
-                                 int nBox,
-                                 BoxPtr pBox,
-                                 int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandRectsMSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                         int fg, int bg, int rop,
-                                         unsigned int planemask,
-                                         int nBox,
-                                         BoxPtr pBox,
-                                         int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandRects3MSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                          int fg, int bg, int rop,
-                                          unsigned int planemask,
-                                          int nBox,
-                                          BoxPtr pBox,
-                                          int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillScanlineColorExpandRectsLSBFirst(ScrnInfoPtr pScrn,
-                                        int fg, int bg, int rop,
-                                        unsigned int planemask,
-                                        int nBox,
-                                        BoxPtr pBox,
-                                        int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillScanlineColorExpandRects3LSBFirst(ScrnInfoPtr pScrn,
-                                         int fg, int bg, int rop,
-                                         unsigned int planemask,
-                                         int nBox,
-                                         BoxPtr pBox,
-                                         int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillScanlineColorExpandRectsMSBFirst(ScrnInfoPtr pScrn,
-                                        int fg, int bg, int rop,
-                                        unsigned int planemask,
-                                        int nBox,
-                                        BoxPtr pBox,
-                                        int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillScanlineColorExpandRects3MSBFirst(ScrnInfoPtr pScrn,
-                                         int fg, int bg, int rop,
-                                         unsigned int planemask,
-                                         int nBox,
-                                         BoxPtr pBox,
-                                         int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandSpansLSBFirst(ScrnInfoPtr pScrn,
-                                int fg, int bg, int rop,
-                                unsigned int planemask,
-                                int n,
-                                DDXPointPtr ppt,
-                                int *pwidth,
-                                int fSorted,
-                                int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandSpans3LSBFirst(ScrnInfoPtr pScrn,
-                                 int fg, int bg, int rop,
-                                 unsigned int planemask,
-                                 int n,
-                                 DDXPointPtr ppt,
-                                 int *pwidth,
-                                 int fSorted,
-                                 int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandSpansLSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                         int fg, int bg, int rop,
-                                         unsigned int planemask,
-                                         int n,
-                                         DDXPointPtr ppt,
-                                         int *pwidth,
-                                         int fSorted,
-                                         int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandSpans3LSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                          int fg, int bg, int rop,
-                                          unsigned int planemask,
-                                          int n,
-                                          DDXPointPtr ppt,
-                                          int *pwidth,
-                                          int fSorted,
-                                          int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandSpansMSBFirst(ScrnInfoPtr pScrn,
-                                int fg, int bg, int rop,
-                                unsigned int planemask,
-                                int n,
-                                DDXPointPtr ppt,
-                                int *pwidth,
-                                int fSorted,
-                                int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandSpans3MSBFirst(ScrnInfoPtr pScrn,
-                                 int fg, int bg, int rop,
-                                 unsigned int planemask,
-                                 int n,
-                                 DDXPointPtr ppt,
-                                 int *pwidth,
-                                 int fSorted,
-                                 int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandSpansMSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                         int fg, int bg, int rop,
-                                         unsigned int planemask,
-                                         int n,
-                                         DDXPointPtr ppt,
-                                         int *pwidth,
-                                         int fSorted,
-                                         int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillColorExpandSpans3MSBFirstFixedBase(ScrnInfoPtr pScrn,
-                                          int fg, int bg, int rop,
-                                          unsigned int planemask,
-                                          int n,
-                                          DDXPointPtr ppt,
-                                          int *pwidth,
-                                          int fSorted,
-                                          int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillScanlineColorExpandSpansLSBFirst(ScrnInfoPtr pScrn,
-                                        int fg, int bg, int rop,
-                                        unsigned int planemask,
-                                        int n,
-                                        DDXPointPtr ppt,
-                                        int *pwidth,
-                                        int fSorted,
-                                        int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillScanlineColorExpandSpans3LSBFirst(ScrnInfoPtr pScrn,
-                                         int fg, int bg, int rop,
-                                         unsigned int planemask,
-                                         int n,
-                                         DDXPointPtr ppt,
-                                         int *pwidth,
-                                         int fSorted,
-                                         int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAPutImage(DrawablePtr pDraw,
-            GCPtr pGC,
-            int depth,
-            int x, int y, int w, int h, int leftPad, int format, char *pImage);
-
-extern _X_EXPORT void
-
-XAAFillScanlineColorExpandSpansMSBFirst(ScrnInfoPtr pScrn,
-                                        int fg, int bg, int rop,
-                                        unsigned int planemask,
-                                        int n,
-                                        DDXPointPtr ppt,
-                                        int *pwidth,
-                                        int fSorted,
-                                        int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillScanlineColorExpandSpans3MSBFirst(ScrnInfoPtr pScrn,
-                                         int fg, int bg, int rop,
-                                         unsigned int planemask,
-                                         int n,
-                                         DDXPointPtr ppt,
-                                         int *pwidth,
-                                         int fSorted,
-                                         int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT CARD32 *(*XAAStippleScanlineFuncMSBFirstFixedBase[6]) (CARD32
-                                                                        *base,
-                                                                        CARD32
-                                                                        *src,
-                                                                        int
-                                                                        offset,
-                                                                        int
-                                                                        width,
-                                                                        int
-                                                                        dwords);
-
-extern _X_EXPORT CARD32 *(*XAAStippleScanlineFuncMSBFirst[6]) (CARD32 *base,
-                                                               CARD32 *src,
-                                                               int offset,
-                                                               int width,
-                                                               int dwords);
-
-extern _X_EXPORT CARD32 *(*XAAStippleScanlineFuncLSBFirstFixedBase[6]) (CARD32
-                                                                        *base,
-                                                                        CARD32
-                                                                        *src,
-                                                                        int
-                                                                        offset,
-                                                                        int
-                                                                        width,
-                                                                        int
-                                                                        dwords);
-
-extern _X_EXPORT CARD32 *(*XAAStippleScanlineFuncLSBFirst[6]) (CARD32 *base,
-                                                               CARD32 *src,
-                                                               int offset,
-                                                               int width,
-                                                               int dwords);
-
-extern _X_EXPORT StippleScanlineProcPtr
-    *XAAGetStippleScanlineFuncMSBFirstFixedBase(void);
-extern _X_EXPORT StippleScanlineProcPtr
-    *XAAGetStippleScanlineFuncMSBFirst(void);
-extern _X_EXPORT StippleScanlineProcPtr
-    *XAAGetStippleScanlineFuncLSBFirstFixedBase(void);
-extern _X_EXPORT StippleScanlineProcPtr
-    *XAAGetStippleScanlineFuncLSBFirst(void);
-extern _X_EXPORT StippleScanlineProcPtr
-    *XAAGetStippleScanlineFunc3MSBFirstFixedBase(void);
-extern _X_EXPORT StippleScanlineProcPtr
-    *XAAGetStippleScanlineFunc3MSBFirst(void);
-extern _X_EXPORT StippleScanlineProcPtr
-    *XAAGetStippleScanlineFunc3LSBFirstFixedBase(void);
-extern _X_EXPORT StippleScanlineProcPtr
-    *XAAGetStippleScanlineFunc3LSBFirst(void);
-
-extern _X_EXPORT int
-
-XAAPolyText8TEColorExpansion(DrawablePtr pDraw,
-                             GCPtr pGC, int x, int y, int count, char *chars);
-
-extern _X_EXPORT int
-
-XAAPolyText16TEColorExpansion(DrawablePtr pDraw,
-                              GCPtr pGC,
-                              int x, int y, int count, unsigned short *chars);
-
-extern _X_EXPORT void
-
-XAAImageText8TEColorExpansion(DrawablePtr pDraw,
-                              GCPtr pGC, int x, int y, int count, char *chars);
-
-extern _X_EXPORT void
-
-XAAImageText16TEColorExpansion(DrawablePtr pDraw,
-                               GCPtr pGC,
-                               int x, int y, int count, unsigned short *chars);
-
-extern _X_EXPORT void
-
-XAAImageGlyphBltTEColorExpansion(DrawablePtr pDrawable,
-                                 GCPtr pGC,
-                                 int xInit, int yInit,
-                                 unsigned int nglyph,
-                                 CharInfoPtr * ppci, pointer pglyphBase);
-
-extern _X_EXPORT void
-
-XAAPolyGlyphBltTEColorExpansion(DrawablePtr pDrawable,
-                                GCPtr pGC,
-                                int xInit, int yInit,
-                                unsigned int nglyph,
-                                CharInfoPtr * ppci, pointer pglyphBase);
-
-extern _X_EXPORT int
-
-XAAPolyText8NonTEColorExpansion(DrawablePtr pDraw,
-                                GCPtr pGC,
-                                int x, int y, int count, char *chars);
-
-extern _X_EXPORT int
-
-XAAPolyText16NonTEColorExpansion(DrawablePtr pDraw,
-                                 GCPtr pGC,
-                                 int x, int y,
-                                 int count, unsigned short *chars);
-
-extern _X_EXPORT void
-
-XAAImageText8NonTEColorExpansion(DrawablePtr pDraw,
-                                 GCPtr pGC,
-                                 int x, int y, int count, char *chars);
-
-extern _X_EXPORT void
-
-XAAImageText16NonTEColorExpansion(DrawablePtr pDraw,
-                                  GCPtr pGC,
-                                  int x, int y,
-                                  int count, unsigned short *chars);
-
-extern _X_EXPORT void
-
-XAAImageGlyphBltNonTEColorExpansion(DrawablePtr pDrawable,
-                                    GCPtr pGC,
-                                    int xInit, int yInit,
-                                    unsigned int nglyph,
-                                    CharInfoPtr * ppci, pointer pglyphBase);
-
-extern _X_EXPORT void
-
-XAAPolyGlyphBltNonTEColorExpansion(DrawablePtr pDrawable,
-                                   GCPtr pGC,
-                                   int xInit, int yInit,
-                                   unsigned int nglyph,
-                                   CharInfoPtr * ppci, pointer pglyphBase);
-
-extern _X_EXPORT void XAANonTEGlyphRenderer(ScrnInfoPtr pScrn,
-                                            int x, int y, int n,
-                                            NonTEGlyphPtr glyphs,
-                                            BoxPtr pbox,
-                                            int fg, int rop,
-                                            unsigned int planemask);
-
-extern _X_EXPORT void
-
-XAAFillSolidSpans(ScrnInfoPtr pScrn,
-                  int fg, int rop,
-                  unsigned int planemask,
-                  int n, DDXPointPtr ppt, int *pwidth, int fSorted);
-
-extern _X_EXPORT void
-
-XAAFillMono8x8PatternSpans(ScrnInfoPtr pScrn,
-                           int fg, int bg, int rop,
-                           unsigned int planemask,
-                           int n,
-                           DDXPointPtr ppt,
-                           int *pwidth, int fSorted,
-                           int patx, int paty, int xorg, int yorg);
-
-extern _X_EXPORT void
-
-XAAFillMono8x8PatternSpansScreenOrigin(ScrnInfoPtr pScrn,
-                                       int fg, int bg, int rop,
-                                       unsigned int planemask,
-                                       int n,
-                                       DDXPointPtr ppt,
-                                       int *pwidth, int fSorted,
-                                       int patx, int paty, int xorg, int yorg);
-
-extern _X_EXPORT void
-
-XAAFillColor8x8PatternSpansScreenOrigin(ScrnInfoPtr pScrn,
-                                        int rop,
-                                        unsigned int planemask,
-                                        int n,
-                                        DDXPointPtr ppt,
-                                        int *pwidth, int fSorted,
-                                        XAACacheInfoPtr,
-                                        int xorigin, int yorigin);
-
-extern _X_EXPORT void
-
-XAAFillColor8x8PatternSpans(ScrnInfoPtr pScrn,
-                            int rop,
-                            unsigned int planemask,
-                            int n,
-                            DDXPointPtr ppt,
-                            int *pwidth, int fSorted,
-                            XAACacheInfoPtr, int xorigin, int yorigin);
-
-extern _X_EXPORT void
-
-XAAFillCacheBltSpans(ScrnInfoPtr pScrn,
-                     int rop,
-                     unsigned int planemask,
-                     int n,
-                     DDXPointPtr points,
-                     int *widths,
-                     int fSorted, XAACacheInfoPtr pCache, int xorg, int yorg);
-
-extern _X_EXPORT void
-
-XAAFillCacheExpandSpans(ScrnInfoPtr pScrn,
-                        int fg, int bg, int rop,
-                        unsigned int planemask,
-                        int n,
-                        DDXPointPtr ppt,
-                        int *pwidth,
-                        int fSorted, int xorg, int yorg, PixmapPtr pPix);
-
-extern _X_EXPORT void
-
-XAAFillSpans(DrawablePtr pDrawable,
-             GC * pGC,
-             int nInit, DDXPointPtr pptInit, int *pwidth, int fSorted);
-
-extern _X_EXPORT void
- XAAInitPixmapCache(ScreenPtr pScreen, RegionPtr areas, pointer data);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapToCache(ScrnInfoPtr pScrn,
-                      int x, int y, int w, int h,
-                      unsigned char *src, int srcwidth, int fg, int bg);
-
-extern _X_EXPORT void
-
-XAAWriteBitmapToCacheLinear(ScrnInfoPtr pScrn,
-                            int x, int y, int w, int h,
-                            unsigned char *src, int srcwidth, int fg, int bg);
-
-extern _X_EXPORT void
-
-XAAWritePixmapToCache(ScrnInfoPtr pScrn,
-                      int x, int y, int w, int h,
-                      unsigned char *src, int srcwidth, int bpp, int depth);
-
-extern _X_EXPORT void
-
-XAAWritePixmapToCacheLinear(ScrnInfoPtr pScrn,
-                            int x, int y, int w, int h,
-                            unsigned char *src,
-                            int srcwidth, int bpp, int depth);
-
-extern _X_EXPORT void
- XAASolidHorVertLineAsRects(ScrnInfoPtr pScrn, int x, int y, int len, int dir);
-
-extern _X_EXPORT void
-
-XAASolidHorVertLineAsTwoPoint(ScrnInfoPtr pScrn,
-                              int x, int y, int len, int dir);
-
-extern _X_EXPORT void
-
-XAASolidHorVertLineAsBresenham(ScrnInfoPtr pScrn,
-                               int x, int y, int len, int dir);
-
-extern _X_EXPORT void
-
-XAAPolyRectangleThinSolid(DrawablePtr pDrawable,
-                          GCPtr pGC, int nRectsInit, xRectangle *pRectsInit);
-
-extern _X_EXPORT void
-
-XAAPolylinesWideSolid(DrawablePtr pDrawable,
-                      GCPtr pGC, int mode, int npt, DDXPointPtr pPts);
-
-extern _X_EXPORT void
-
-XAAFillPolygonSolid(DrawablePtr pDrawable,
-                    GCPtr pGC,
-                    int shape, int mode, int count, DDXPointPtr ptsIn);
-
-extern _X_EXPORT void
-
-XAAFillPolygonStippled(DrawablePtr pDrawable,
-                       GCPtr pGC,
-                       int shape, int mode, int count, DDXPointPtr ptsIn);
-
-extern _X_EXPORT void
-
-XAAFillPolygonTiled(DrawablePtr pDrawable,
-                    GCPtr pGC,
-                    int shape, int mode, int count, DDXPointPtr ptsIn);
-
-extern _X_EXPORT int
-
-XAAIsEasyPolygon(DDXPointPtr ptsIn,
-                 int count,
-                 BoxPtr extents,
-                 int origin,
-                 DDXPointPtr * topPoint, int *topY, int *bottomY, int shape);
-
-extern _X_EXPORT void
-
-XAAFillPolygonHelper(ScrnInfoPtr pScrn,
-                     DDXPointPtr ptsIn,
-                     int count,
-                     DDXPointPtr topPoint,
-                     int y,
-                     int maxy,
-                     int origin,
-                     RectFuncPtr RectFunc,
-                     TrapFuncPtr TrapFunc,
-                     int xorg, int yorg, XAACacheInfoPtr pCache);
-
-extern _X_EXPORT void
- XAAPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg);
-
-extern _X_EXPORT void
-
-XAAPolyLines(DrawablePtr pDrawable,
-             GCPtr pGC, int mode, int npt, DDXPointPtr pptInit);
-
-extern _X_EXPORT void
-
-XAAPolySegmentDashed(DrawablePtr pDrawable,
-                     GCPtr pGC, int nseg, xSegment * pSeg);
-
-extern _X_EXPORT void
-
-XAAPolyLinesDashed(DrawablePtr pDrawable,
-                   GCPtr pGC, int mode, int npt, DDXPointPtr pptInit);
-
-extern _X_EXPORT void
- XAAWriteMono8x8PatternToCache(ScrnInfoPtr pScrn, XAACacheInfoPtr pCache);
-
-extern _X_EXPORT void
-
-XAAWriteColor8x8PatternToCache(ScrnInfoPtr pScrn,
-                               PixmapPtr pPix, XAACacheInfoPtr pCache);
-
-extern _X_EXPORT void
-
-XAARotateMonoPattern(int *pat0, int *pat1,
-                     int xoffset, int yoffset, Bool msbfirst);
-
-extern _X_EXPORT void XAAComputeDash(GCPtr pGC);
-
-extern _X_EXPORT void XAAMoveDWORDS_FixedBase(register CARD32 *dest,
-                                              register CARD32 *src,
-                                              register int dwords);
-
-extern _X_EXPORT void XAAMoveDWORDS_FixedSrc(register CARD32 *dest,
-                                             register CARD32 *src,
-                                             register int dwords);
-
-extern _X_EXPORT void XAAMoveDWORDS(register CARD32 *dest,
-                                    register CARD32 *src, register int dwords);
-
-extern _X_EXPORT int
-
-XAAGetRectClipBoxes(GCPtr pGC,
-                    BoxPtr pboxClippedBase,
-                    int nrectFill, xRectangle *prectInit);
-
-extern _X_EXPORT void
- XAASetupOverlay8_32Planar(ScreenPtr);
-
-extern _X_EXPORT void
- XAAPolyFillArcSolid(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs);
-
-extern _X_EXPORT XAACacheInfoPtr XAACacheTile(ScrnInfoPtr Scrn, PixmapPtr pPix);
-
-extern _X_EXPORT XAACacheInfoPtr
-XAACacheMonoStipple(ScrnInfoPtr Scrn, PixmapPtr pPix);
-
-extern _X_EXPORT XAACacheInfoPtr
-XAACachePlanarMonoStipple(ScrnInfoPtr Scrn, PixmapPtr pPix);
-
-typedef XAACacheInfoPtr(*XAACachePlanarMonoStippleProc) (ScrnInfoPtr,
-                                                         PixmapPtr);
-extern _X_EXPORT XAACachePlanarMonoStippleProc
-XAAGetCachePlanarMonoStipple(void);
-
-extern _X_EXPORT XAACacheInfoPtr
-XAACacheStipple(ScrnInfoPtr Scrn, PixmapPtr pPix, int fg, int bg);
-
-extern _X_EXPORT XAACacheInfoPtr
-XAACacheMono8x8Pattern(ScrnInfoPtr Scrn, int pat0, int pat1);
-
-extern _X_EXPORT XAACacheInfoPtr
-XAACacheColor8x8Pattern(ScrnInfoPtr Scrn, PixmapPtr pPix, int fg, int bg);
-
-extern _X_EXPORT void
- XAATileCache(ScrnInfoPtr pScrn, XAACacheInfoPtr pCache, int w, int h);
-
-extern _X_EXPORT void XAAClosePixmapCache(ScreenPtr pScreen);
-void XAAInvalidatePixmapCache(ScreenPtr pScreen);
-
-extern _X_EXPORT Bool XAACheckStippleReducibility(PixmapPtr pPixmap);
-extern _X_EXPORT Bool XAACheckTileReducibility(PixmapPtr pPixmap,
-                                               Bool checkMono);
-
-extern _X_EXPORT int XAAStippledFillChooser(GCPtr pGC);
-extern _X_EXPORT int XAAOpaqueStippledFillChooser(GCPtr pGC);
-extern _X_EXPORT int XAATiledFillChooser(GCPtr pGC);
-
-extern _X_EXPORT void XAAMoveInOffscreenPixmaps(ScreenPtr pScreen);
-extern _X_EXPORT void XAAMoveOutOffscreenPixmaps(ScreenPtr pScreen);
-extern _X_EXPORT void XAARemoveAreaCallback(FBAreaPtr area);
-extern _X_EXPORT void XAAMoveOutOffscreenPixmap(PixmapPtr pPix);
-extern _X_EXPORT Bool XAAInitStateWrap(ScreenPtr pScreen,
-                                       XAAInfoRecPtr infoRec);
-
-extern _X_EXPORT void
-
-XAAComposite(CARD8 op,
-             PicturePtr pSrc,
-             PicturePtr pMask,
-             PicturePtr pDst,
-             INT16 xSrc,
-             INT16 ySrc,
-             INT16 xMask,
-             INT16 yMask, INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
-
-extern _X_EXPORT Bool
-
-XAADoComposite(CARD8 op,
-               PicturePtr pSrc,
-               PicturePtr pMask,
-               PicturePtr pDst,
-               INT16 xSrc,
-               INT16 ySrc,
-               INT16 xMask,
-               INT16 yMask,
-               INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
-
-extern _X_EXPORT void
-
-XAAGlyphs(CARD8 op,
-          PicturePtr pSrc,
-          PicturePtr pDst,
-          PictFormatPtr maskFormat,
-          INT16 xSrc,
-          INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr * glyphs);
-
-extern _X_EXPORT Bool
-
-XAADoGlyphs(CARD8 op,
-            PicturePtr pSrc,
-            PicturePtr pDst,
-            PictFormatPtr maskFormat,
-            INT16 xSrc,
-            INT16 ySrc, int nlist, GlyphListPtr list, GlyphPtr * glyphs);
-
-/* helpers */
-extern _X_EXPORT void
- XAA_888_plus_PICT_a8_to_8888(CARD32 color, CARD8 *alphaPtr,    /* in bytes */
-                              int alphaPitch, CARD32 *dstPtr, int dstPitch,     /* in dwords */
-                              int width, int height);
-
-extern _X_EXPORT Bool
-
-XAAGetRGBAFromPixel(CARD32 pixel,
-                    CARD16 *red,
-                    CARD16 *green, CARD16 *blue, CARD16 *alpha, CARD32 format);
-
-extern _X_EXPORT Bool
-
-XAAGetPixelFromRGBA(CARD32 *pixel,
-                    CARD16 red,
-                    CARD16 green, CARD16 blue, CARD16 alpha, CARD32 format);
-
-/* XXX should be static */
-extern _X_EXPORT GCOps XAAFallbackOps;
-extern _X_EXPORT GCOps *XAAGetFallbackOps(void);
-extern _X_EXPORT GCFuncs XAAGCFuncs;
-extern _X_EXPORT DevPrivateKey XAAGetScreenKey(void);
-extern _X_EXPORT DevPrivateKey XAAGetGCKey(void);
-extern _X_EXPORT DevPrivateKey XAAGetPixmapKey(void);
-
-extern _X_EXPORT unsigned int XAAShiftMasks[32];
-
-extern _X_EXPORT unsigned int byte_expand3[256], byte_reversed_expand3[256];
-
-extern _X_EXPORT CARD32 XAAReverseBitOrder(CARD32 data);
-
-#define GET_XAASCREENPTR_FROM_SCREEN(pScreen)\
-    dixLookupPrivate(&(pScreen)->devPrivates, XAAGetScreenKey())
-
-#define GET_XAASCREENPTR_FROM_GC(pGC)\
-    dixLookupPrivate(&(pGC)->pScreen->devPrivates, XAAGetScreenKey())
-
-#define GET_XAASCREENPTR_FROM_DRAWABLE(pDraw)\
-    dixLookupPrivate(&(pDraw)->pScreen->devPrivates, XAAGetScreenKey())
-
-#define GET_XAAINFORECPTR_FROM_SCREEN(pScreen)\
-((XAAScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAGetScreenKey()))->AccelInfoRec
-
-#define GET_XAAINFORECPTR_FROM_GC(pGC)\
-((XAAScreenPtr)dixLookupPrivate(&(pGC)->pScreen->devPrivates, XAAGetScreenKey()))->AccelInfoRec
-
-#define GET_XAAINFORECPTR_FROM_DRAWABLE(pDraw)\
-((XAAScreenPtr)dixLookupPrivate(&(pDraw)->pScreen->devPrivates, XAAGetScreenKey()))->AccelInfoRec
-
-#define GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn)\
-((XAAScreenPtr)dixLookupPrivate(&(pScrn)->pScreen->devPrivates, XAAGetScreenKey()))->AccelInfoRec
-
-#define XAA_GET_PIXMAP_PRIVATE(pix)\
-    (XAAPixmapPtr)dixLookupPrivate(&(pix)->devPrivates, XAAGetPixmapKey())
-
-#define CHECK_RGB_EQUAL(c) (!((((c) >> 8) ^ (c)) & 0xffff))
-
-#define CHECK_FG(pGC, flags) \
-	(!(flags & RGB_EQUAL) || CHECK_RGB_EQUAL(pGC->fgPixel))
-
-#define CHECK_BG(pGC, flags) \
-	(!(flags & RGB_EQUAL) || CHECK_RGB_EQUAL(pGC->bgPixel))
-
-#define CHECK_ROP(pGC, flags) \
-	(!(flags & GXCOPY_ONLY) || (pGC->alu == GXcopy))
-
-#define CHECK_ROPSRC(pGC, flags) \
-	(!(flags & ROP_NEEDS_SOURCE) || ((pGC->alu != GXclear) && \
-	(pGC->alu != GXnoop) && (pGC->alu != GXinvert) && \
-	(pGC->alu != GXset)))
-
-#define CHECK_PLANEMASK(pGC, flags) \
-	(!(flags & NO_PLANEMASK) || \
-	((pGC->planemask & infoRec->FullPlanemasks[pGC->depth - 1]) == \
-          infoRec->FullPlanemasks[pGC->depth - 1]))
-
-#define CHECK_COLORS(pGC, flags) \
-	(!(flags & RGB_EQUAL) || \
-	(CHECK_RGB_EQUAL(pGC->fgPixel) && CHECK_RGB_EQUAL(pGC->bgPixel)))
-
-#define CHECK_NO_GXCOPY(pGC, flags) \
-	((pGC->alu != GXcopy) || !(flags & NO_GXCOPY) || \
-	((pGC->planemask & infoRec->FullPlanemask) != infoRec->FullPlanemask))
-
-#define IS_OFFSCREEN_PIXMAP(pPix)\
-        ((XAA_GET_PIXMAP_PRIVATE((PixmapPtr)(pPix)))->offscreenArea)
-
-#define PIXMAP_IS_SHARED(pPix)\
-        ((XAA_GET_PIXMAP_PRIVATE((PixmapPtr)(pPix)))->flags & SHARED_PIXMAP)
-
-#define OFFSCREEN_PIXMAP_LOCKED(pPix)\
-        ((XAA_GET_PIXMAP_PRIVATE((PixmapPtr)(pPix)))->flags & LOCKED_PIXMAP)
-
-#define XAA_DEPTH_BUG(pGC) \
-        ((pGC->depth == 32) && (pGC->bgPixel == 0xffffffff))
-
-#define DELIST_OFFSCREEN_PIXMAP(pPix) { \
-	PixmapLinkPtr _pLink, _prev; \
-	_pLink = infoRec->OffscreenPixmaps; \
-	_prev = NULL; \
-	while(_pLink) { \
-	    if(_pLink->pPix == pPix) { \
-		if(_prev) _prev->next = _pLink->next; \
-		else infoRec->OffscreenPixmaps = _pLink->next; \
-		free(_pLink); \
-		break; \
-	    } \
-	    _prev = _pLink; \
-	    _pLink = _pLink->next; \
-        }}
-
-#define SWAP_BITS_IN_BYTES(v) \
- (((0x01010101 & (v)) << 7) | ((0x02020202 & (v)) << 5) | \
-  ((0x04040404 & (v)) << 3) | ((0x08080808 & (v)) << 1) | \
-  ((0x10101010 & (v)) >> 1) | ((0x20202020 & (v)) >> 3) | \
-  ((0x40404040 & (v)) >> 5) | ((0x80808080 & (v)) >> 7))
-
-/*
- * Moved XAAPixmapCachePrivate here from xaaPCache.c, since driver
- * replacements for CacheMonoStipple need access to it
- */
-
-typedef struct {
-    int Num512x512;
-    int Current512;
-    XAACacheInfoPtr Info512;
-    int Num256x256;
-    int Current256;
-    XAACacheInfoPtr Info256;
-    int Num128x128;
-    int Current128;
-    XAACacheInfoPtr Info128;
-    int NumMono;
-    int CurrentMono;
-    XAACacheInfoPtr InfoMono;
-    int NumColor;
-    int CurrentColor;
-    XAACacheInfoPtr InfoColor;
-    int NumPartial;
-    int CurrentPartial;
-    XAACacheInfoPtr InfoPartial;
-    DDXPointRec MonoOffsets[64];
-    DDXPointRec ColorOffsets[64];
-} XAAPixmapCachePrivate, *XAAPixmapCachePrivatePtr;
-
-#endif                          /* _XAALOCAL_H */
diff --git a/hw/xfree86/xaa/xaarop.h b/hw/xfree86/xaa/xaarop.h
deleted file mode 100644
index f2acde0..0000000
--- a/hw/xfree86/xaa/xaarop.h
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
-
-   int XAAHelpSolidROP(ScrnInfoPtr pScrn, int *fg, int pm, int *rop)
-
-	For use with solid fills emulated by solid 8x8 patterns.  You 
-	give it the foreground, planemask and X rop and it will replace 
-	the foreground with a new one and the rop with the appropriate 
-	MS triadic raster op.  The function will return which components 
-	(S-P) need to be enabled.  
-
-   int XAAHelpPatternROP(ScrnInfoPtr pScrn, int *fg, int *bg, int pm, int *rop)
-
-	For use with 8x8 opaque pattern fills.  You give it the foreground, 	
-	and background, planemask and X rop and it will replace the 
-	foreground and background with new ones and the rop with the 
-	appropriate MS triadic raster op.  The function will return which 
-	components (S-P) need to be enabled.  
-
-	   ROP_PAT - Means to enable 8x8 mono patterns (all bits 
-		     set for solid patterns).  Set the foreground and
-		     background as returned by the function.  
-
-	   ROP_SRC - Means a source of color == planemask should be used.
-
-
-*/
-
-#ifndef _XAAROP_H
-#define _XAAROP_H
-
-#define ROP_DST		0x00000001
-#define ROP_SRC		0x00000002
-#define ROP_PAT		0x00000004
-
-#define ROP_0		0x00
-#define ROP_DPSoon	0x01
-#define ROP_DPSona	0x02
-#define ROP_PSon	0x03
-#define ROP_SDPona	0x04
-#define ROP_DPon	0x05
-#define ROP_PDSxnon	0x06
-#define ROP_PDSaon	0x07
-#define ROP_SDPnaa	0x08
-#define ROP_PDSxon	0x09
-#define ROP_DPna	0x0A
-#define ROP_PSDnaon	0x0B
-#define ROP_SPna	0x0C
-#define ROP_PDSnaon	0x0D
-#define ROP_PDSonon	0x0E
-#define ROP_Pn		0x0F
-#define ROP_PDSona	0x10
-#define ROP_DSon	0x11
-#define ROP_SDPxnon	0x12
-#define ROP_SDPaon	0x13
-#define ROP_DPSxnon	0x14
-#define ROP_DPSaon	0x15
-#define ROP_PSDPSanaxx	0x16
-#define ROP_SSPxDSxaxn	0x17
-#define ROP_SPxPDxa	0x18
-#define ROP_SDPSanaxn	0x19
-#define ROP_PDSPaox	0x1A
-#define ROP_SDPSxaxn	0x1B
-#define ROP_PSDPaox	0x1C
-#define ROP_DSPDxaxn	0x1D
-#define ROP_PDSox	0x1E
-#define ROP_PDSoan	0x1F
-#define ROP_DPSnaa	0x20
-#define ROP_SDPxon	0x21
-#define ROP_DSna	0x22
-#define ROP_SPDnaon	0x23
-#define ROP_SPxDSxa	0x24
-#define ROP_PDSPanaxn	0x25
-#define ROP_SDPSaox	0x26
-#define ROP_SDPSxnox	0x27
-#define ROP_DPSxa	0x28
-#define ROP_PSDPSaoxxn	0x29
-#define ROP_DPSana	0x2A
-#define ROP_SSPxPDxaxn	0x2B
-#define ROP_SPDSoax	0x2C
-#define ROP_PSDnox	0x2D
-#define ROP_PSDPxox	0x2E
-#define ROP_PSDnoan	0x2F
-#define ROP_PSna	0x30
-#define ROP_SDPnaon	0x31
-#define ROP_SDPSoox	0x32
-#define ROP_Sn		0x33
-#define ROP_SPDSaox	0x34
-#define ROP_SPDSxnox	0x35
-#define ROP_SDPox	0x36
-#define ROP_SDPoan	0x37
-#define ROP_PSDPoax	0x38
-#define ROP_SPDnox	0x39
-#define ROP_SPDSxox	0x3A
-#define ROP_SPDnoan	0x3B
-#define ROP_PSx		0x3C
-#define ROP_SPDSonox	0x3D
-#define ROP_SPDSnaox	0x3E
-#define ROP_PSan	0x3F
-#define ROP_PSDnaa	0x40
-#define ROP_DPSxon	0x41
-#define ROP_SDxPDxa	0x42
-#define ROP_SPDSanaxn	0x43
-#define ROP_SDna	0x44
-#define ROP_DPSnaon	0x45
-#define ROP_DSPDaox	0x46
-#define ROP_PSDPxaxn	0x47
-#define ROP_SDPxa	0x48
-#define ROP_PDSPDaoxxn	0x49
-#define ROP_DPSDoax	0x4A
-#define ROP_PDSnox	0x4B
-#define ROP_SDPana	0x4C
-#define ROP_SSPxDSxoxn	0x4D
-#define ROP_PDSPxox	0x4E
-#define ROP_PDSnoan	0x4F
-#define ROP_PDna	0x50
-#define ROP_DSPnaon	0x51
-#define ROP_DPSDaox	0x52
-#define ROP_SPDSxaxn	0x53
-#define ROP_DPSonon	0x54
-#define ROP_Dn		0x55
-#define ROP_DPSox	0x56
-#define ROP_DPSoan	0x57
-#define ROP_PDSPoax	0x58
-#define ROP_DPSnox	0x59
-#define ROP_DPx		0x5A
-#define ROP_DPSDonox	0x5B
-#define ROP_DPSDxox	0x5C
-#define ROP_DPSnoan	0x5D
-#define ROP_DPSDnaox	0x5E
-#define ROP_DPan	0x5F
-#define ROP_PDSxa	0x60
-#define ROP_DSPDSaoxxn	0x61
-#define ROP_DSPDoax	0x62
-#define ROP_SDPnox	0x63
-#define ROP_SDPSoax	0x64
-#define ROP_DSPnox	0x65
-#define ROP_DSx		0x66
-#define ROP_SDPSonox	0x67
-#define ROP_DSPDSonoxxn	0x68
-#define ROP_PDSxxn	0x69
-#define ROP_DPSax	0x6A
-#define ROP_PSDPSoaxxn	0x6B
-#define ROP_SDPax	0x6C
-#define ROP_PDSPDoaxxn	0x6D
-#define ROP_SDPSnoax	0x6E
-#define ROP_PDSxnan	0x6F
-#define ROP_PDSana	0x70
-#define ROP_SSDxPDxaxn	0x71
-#define ROP_SDPSxox	0x72
-#define ROP_SDPnoan	0x73
-#define ROP_DSPDxox	0x74
-#define ROP_DSPnoan	0x75
-#define ROP_SDPSnaox	0x76
-#define ROP_DSan	0x77
-#define ROP_PDSax	0x78
-#define ROP_DSPDSoaxxn	0x79
-#define ROP_DPSDnoax	0x7A
-#define ROP_SDPxnan	0x7B
-#define ROP_SPDSnoax	0x7C
-#define ROP_DPSxnan	0x7D
-#define ROP_SPxDSxo	0x7E
-#define ROP_DPSaan	0x7F
-#define ROP_DPSaa	0x80
-#define ROP_SPxDSxon	0x81
-#define ROP_DPSxna	0x82
-#define ROP_SPDSnoaxn	0x83
-#define ROP_SDPxna	0x84
-#define ROP_PDSPnoaxn	0x85
-#define ROP_DSPDSoaxx	0x86
-#define ROP_PDSaxn	0x87
-#define ROP_DSa		0x88
-#define ROP_SDPSnaoxn	0x89
-#define ROP_DSPnoa	0x8A
-#define ROP_DSPDxoxn	0x8B
-#define ROP_SDPnoa	0x8C
-#define ROP_SDPSxoxn	0x8D
-#define ROP_SSDxPDxax	0x8E
-#define ROP_PDSanan	0x8F
-#define ROP_PDSxna	0x90
-#define ROP_SDPSnoaxn	0x91
-#define ROP_DPSDPoaxx	0x92
-#define ROP_SPDaxn	0x93
-#define ROP_PSDPSoaxx	0x94
-#define ROP_DPSaxn	0x95
-#define ROP_DPSxx	0x96
-#define ROP_PSDPSonoxx	0x97
-#define ROP_SDPSonoxn	0x98
-#define ROP_DSxn	0x99
-#define ROP_DPSnax	0x9A
-#define ROP_SDPSoaxn	0x9B
-#define ROP_SPDnax	0x9C
-#define ROP_DSPDoaxn	0x9D
-#define ROP_DSPDSaoxx	0x9E
-#define ROP_PDSxan	0x9F
-#define ROP_DPa		0xA0
-#define ROP_PDSPnaoxn	0xA1
-#define ROP_DPSnoa	0xA2
-#define ROP_DPSDxoxn	0xA3
-#define ROP_PDSPonoxn	0xA4
-#define ROP_PDxn	0xA5
-#define ROP_DSPnax	0xA6
-#define ROP_PDSPoaxn	0xA7
-#define ROP_DPSoa	0xA8
-#define ROP_DPSoxn	0xA9
-#define ROP_D		0xAA
-#define ROP_DPSono	0xAB
-#define ROP_SPDSxax	0xAC
-#define ROP_DPSDaoxn	0xAD
-#define ROP_DSPnao	0xAE
-#define ROP_DPno	0xAF
-#define ROP_PDSnoa	0xB0
-#define ROP_PDSPxoxn	0xB1
-#define ROP_SSPxDSxox	0xB2
-#define ROP_SDPanan	0xB3
-#define ROP_PSDnax	0xB4
-#define ROP_DPSDoaxn	0xB5
-#define ROP_DPSDPaoxx	0xB6
-#define ROP_SDPxan	0xB7
-#define ROP_PSDPxax	0xB8
-#define ROP_DSPDaoxn	0xB9
-#define ROP_DPSnao	0xBA
-#define ROP_DSno	0xBB
-#define ROP_SPDSanax	0xBC
-#define ROP_SDxPDxan	0xBD
-#define ROP_DPSxo	0xBE
-#define ROP_DPSano	0xBF
-#define ROP_Psa		0xC0
-#define ROP_SPDSnaoxn	0xC1
-#define ROP_SPDSonoxn	0xC2
-#define ROP_PSxn	0xC3
-#define ROP_SPDnoa	0xC4
-#define ROP_SPDSxoxn	0xC5
-#define ROP_SDPnax	0xC6
-#define ROP_PSDPoaxn	0xC7
-#define ROP_SDPoa	0xC8
-#define ROP_SPDoxn	0xC9
-#define ROP_DPSDxax	0xCA
-#define ROP_SPDSaoxn	0xCB
-#define ROP_S		0xCC
-#define ROP_SDPono	0xCD
-#define ROP_SDPnao	0xCE
-#define ROP_SPno	0xCF
-#define ROP_PSDnoa	0xD0
-#define ROP_PSDPxoxn	0xD1
-#define ROP_PDSnax	0xD2
-#define ROP_SPDSoaxn	0xD3
-#define ROP_SSPxPDxax	0xD4
-#define ROP_DPSanan	0xD5
-#define ROP_PSDPSaoxx	0xD6
-#define ROP_DPSxan	0xD7
-#define ROP_PDSPxax	0xD8
-#define ROP_SDPSaoxn	0xD9
-#define ROP_DPSDanax	0xDA
-#define ROP_SPxDSxan	0xDB
-#define ROP_SPDnao	0xDC
-#define ROP_SDno	0xDD
-#define ROP_SDPxo	0xDE
-#define ROP_SDPano	0xDF
-#define ROP_PDSoa	0xE0
-#define ROP_PDSoxn	0xE1
-#define ROP_DSPDxax	0xE2
-#define ROP_PSDPaoxn	0xE3
-#define ROP_SDPSxax	0xE4
-#define ROP_PDSPaoxn	0xE5
-#define ROP_SDPSanax	0xE6
-#define ROP_SPxPDxan	0xE7
-#define ROP_SSPxDSxax	0xE8
-#define ROP_DSPDSanaxxn	0xE9
-#define ROP_DPSao	0xEA
-#define ROP_DPSxno	0xEB
-#define ROP_SDPao	0xEC
-#define ROP_SDPxno	0xED
-#define ROP_DSo		0xEE
-#define ROP_SDPnoo	0xEF
-#define ROP_P		0xF0
-#define ROP_PDSono	0xF1
-#define ROP_PDSnao	0xF2
-#define ROP_PSno	0xF3
-#define ROP_PSDnao	0xF4
-#define ROP_PDno	0xF5
-#define ROP_PDSxo	0xF6
-#define ROP_PDSano	0xF7
-#define ROP_PDSao	0xF8
-#define ROP_PDSxno	0xF9
-#define ROP_DPo		0xFA
-#define ROP_DPSnoo	0xFB
-#define ROP_PSo		0xFC
-#define ROP_PSDnoo	0xFD
-#define ROP_DPSoo	0xFE
-#define ROP_1		0xFF
-
-#define NO_SRC_ROP(rop) \
-   ((rop == GXnoop) || (rop == GXset) || (rop == GXclear) || (rop == GXinvert))
-
-extern _X_EXPORT int XAAHelpSolidROP(ScrnInfoPtr pScrn, int *fg, int pm,
-                                     int *rop);
-extern _X_EXPORT int XAAHelpPatternROP(ScrnInfoPtr pScrn, int *fg, int *bg,
-                                       int pm, int *rop);
-
-/* XXX These four should be static, but it breaks the 6.7.0 ABI. */
-extern _X_EXPORT int XAACopyROP[16];
-extern _X_EXPORT int XAACopyROP_PM[16];
-extern _X_EXPORT int XAAPatternROP[16];
-extern _X_EXPORT int XAAPatternROP_PM[16];
-
-extern _X_EXPORT int XAAGetCopyROP(int i);
-extern _X_EXPORT int XAAGetCopyROP_PM(int i);
-extern _X_EXPORT int XAAGetPatternROP(int i);
-extern _X_EXPORT int XAAGetPatternROP_PM(int i);
-
-#endif                          /* _XAAROP_H */
diff --git a/hw/xfree86/xaa/xaawrap.h b/hw/xfree86/xaa/xaawrap.h
deleted file mode 100644
index 2d2d788..0000000
--- a/hw/xfree86/xaa/xaawrap.h
+++ /dev/null
@@ -1,75 +0,0 @@
-
-#define XAA_SCREEN_PROLOGUE(pScreen, field)\
-  ((pScreen)->field = \
-   ((XAAScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAGetScreenKey()))->field)
-
-#define XAA_SCREEN_EPILOGUE(pScreen, field, wrapper)\
-    ((pScreen)->field = wrapper)
-
-#define XAA_GC_FUNC_PROLOGUE(pGC)\
-    XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&(pGC)->devPrivates, XAAGetGCKey()); \
-    (pGC)->funcs = pGCPriv->wrapFuncs;\
-    if(pGCPriv->flags)\
-	(pGC)->ops = pGCPriv->wrapOps
-
-#define XAA_GC_FUNC_EPILOGUE(pGC)\
-    pGCPriv->wrapFuncs = (pGC)->funcs;\
-    (pGC)->funcs = &XAAGCFuncs;\
-    if(pGCPriv->flags) {\
-	pGCPriv->wrapOps = (pGC)->ops;\
-	(pGC)->ops = (pGCPriv->flags & OPS_ARE_ACCEL) ? pGCPriv->XAAOps :\
-				&XAAPixmapOps;\
-    }
-
-#define XAA_GC_OP_PROLOGUE(pGC)\
-    XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&(pGC)->devPrivates, XAAGetGCKey()); \
-    GCFuncs *oldFuncs = pGC->funcs;\
-    pGC->funcs = pGCPriv->wrapFuncs;\
-    pGC->ops = pGCPriv->wrapOps
-
-#define XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC)\
-    XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&(pGC)->devPrivates, XAAGetGCKey()); \
-    GCFuncs *oldFuncs = pGC->funcs;\
-    if(!RegionNumRects(pGC->pCompositeClip)) return; \
-    pGC->funcs = pGCPriv->wrapFuncs;\
-    pGC->ops = pGCPriv->wrapOps
-
-#define XAA_GC_OP_EPILOGUE(pGC)\
-    pGCPriv->wrapOps = pGC->ops;\
-    pGC->funcs = oldFuncs;\
-    pGC->ops   = pGCPriv->XAAOps
-
-#define XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw)\
-    XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&(pGC)->devPrivates, XAAGetGCKey()); \
-    XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE((PixmapPtr)(pDraw));\
-    GCFuncs *oldFuncs = pGC->funcs;\
-    pGC->funcs = pGCPriv->wrapFuncs;\
-    pGC->ops = pGCPriv->wrapOps; \
-    SYNC_CHECK(pGC)
-
-#define XAA_PIXMAP_OP_EPILOGUE(pGC)\
-    pGCPriv->wrapOps = pGC->ops;\
-    pGC->funcs = oldFuncs;\
-    pGC->ops   = &XAAPixmapOps;\
-    pixPriv->flags |= DIRTY
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#define XAA_RENDER_PROLOGUE(pScreen,field)\
-    (GetPictureScreen(pScreen)->field = \
-     ((XAAScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAGetScreenKey()))->field)
-
-#define XAA_RENDER_EPILOGUE(pScreen, field, wrapper)\
-    (GetPictureScreen(pScreen)->field = wrapper)
-
-/* This also works fine for drawables */
-
-#define SYNC_CHECK(pGC) {\
-     XAAInfoRecPtr infoRec =\
-((XAAScreenPtr)dixLookupPrivate(&(pGC)->pScreen->devPrivates, XAAGetScreenKey()))->AccelInfoRec;	\
-    if(infoRec->NeedToSync) {\
-	(*infoRec->Sync)(infoRec->pScrn);\
-	infoRec->NeedToSync = FALSE;\
-    }}
commit 66362441867f68dac97de33744bd0ca478fb65d3
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:29 2012 +0100

    Remove last renmants of XFree86LOADER define
    
    Not to be confused with XFree86Loader or XorgLoader.  Which are both now
    dead too.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index b225632..209b237 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1817,7 +1817,6 @@ if test "x$XORG" = xyes; then
 	AC_DEFINE(XORG_SERVER, 1, [Building Xorg server])
 	AC_DEFINE(XORGSERVER, 1, [Building Xorg server])
 	AC_DEFINE(XFree86Server, 1, [Building XFree86 server])
-	AC_DEFINE(XFree86LOADER, 1, [Building loadable XFree86 server])
 	AC_DEFINE_UNQUOTED(XORG_VERSION_CURRENT, [$VENDOR_RELEASE], [Current Xorg version])
 	AC_DEFINE(NEED_XF86_TYPES, 1, [Need XFree86 typedefs])
 	AC_DEFINE(NEED_XF86_PROTOTYPES, 1, [Need XFree86 helper functions])
diff --git a/hw/xquartz/xpr/dri.c b/hw/xquartz/xpr/dri.c
index 663d61d..03af163 100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@ -38,13 +38,8 @@
 #include <dix-config.h>
 #endif
 
-#ifdef XFree86LOADER
-#include "xf86.h"
-#include "xf86_ansic.h"
-#else
 #include <sys/time.h>
 #include <unistd.h>
-#endif
 
 #include <X11/X.h>
 #include <X11/Xproto.h>
diff --git a/include/xorg-server.h.in b/include/xorg-server.h.in
index c0761f7..81935be 100644
--- a/include/xorg-server.h.in
+++ b/include/xorg-server.h.in
@@ -197,7 +197,7 @@
 #undef WSCONS_SUPPORT
 
 /* Loadable XFree86 server awesomeness */
-#undef XFree86LOADER
+#define XFree86LOADER
 
 /* Use libpciaccess */
 #undef XSERVER_LIBPCIACCESS
commit a15dac550918c55b08bbe0007f068cc5096ebaa1
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:28 2012 +0100

    Remove unused setupFunc from extensions
    
    setupFunc was used as an early callback for half-modular extensions such
    as Xv, XvMC and DGA to set up hooks between the core server and the
    modular component.  Now we've rid ourselves of that, we can also bin
    setupFunc.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c
index 8cbeedf..d5309d5 100644
--- a/hw/xfree86/common/xf86Extensions.c
+++ b/hw/xfree86/common/xf86Extensions.c
@@ -58,32 +58,28 @@ static ExtensionModule extensionModules[] = {
     {
 	XFree86VidModeExtensionInit,
 	XF86VIDMODENAME,
-	&noXFree86VidModeExtension,
-	NULL
+	&noXFree86VidModeExtension
     },
 #endif
 #ifdef XFreeXDGA
     {
 	XFree86DGAExtensionInit,
 	XF86DGANAME,
-	&noXFree86DGAExtension,
-	NULL
+	&noXFree86DGAExtension
     },
 #endif
 #ifdef XF86DRI
     {
         XFree86DRIExtensionInit,
         "XFree86-DRI",
-        &noXFree86DRIExtension,
-        NULL
+        &noXFree86DRIExtension
     },
 #endif
 #ifdef DRI2
     {
         DRI2ExtensionInit,
         DRI2_NAME,
-        &noDRI2Extension,
-        NULL
+        &noDRI2Extension
     }
 #endif
 };
diff --git a/hw/xfree86/dixmods/glxmodule.c b/hw/xfree86/dixmods/glxmodule.c
index 2f0a3dd..5a9e845 100644
--- a/hw/xfree86/dixmods/glxmodule.c
+++ b/hw/xfree86/dixmods/glxmodule.c
@@ -49,8 +49,7 @@ static MODULESETUPPROTO(glxSetup);
 static ExtensionModule GLXExt = {
     GlxExtensionInit,
     "GLX",
-    &noGlxExtension,
-    NULL
+    &noGlxExtension
 };
 
 static XF86ModuleVersionInfo VersRec = {
diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml
index 118b58f..ce81a9d 100644
--- a/hw/xfree86/doc/ddxDesign.xml
+++ b/hw/xfree86/doc/ddxDesign.xml
@@ -5973,7 +5973,6 @@ typedef struct {
     InitExtension       initFunc;
     char *              name;
     Bool                *disablePtr;
-    InitExtension       setupFunc;
 } ExtensionModule;
 	      </programlisting>
 	    </para>
diff --git a/include/extension.h b/include/extension.h
index cc1dfa1..0f55d90 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -84,7 +84,6 @@ typedef struct {
     InitExtension initFunc;
     const char *name;
     Bool *disablePtr;
-    InitExtension setupFunc;
 } ExtensionModule;
 
 extern _X_EXPORT unsigned short StandardMinorOpcode(ClientPtr /*client */ );
diff --git a/mi/miinitext.c b/mi/miinitext.c
index a84d486..86fc31c 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -235,65 +235,63 @@ EnableDisableExtensionError(const char *name, Bool enable)
 
 /* List of built-in (statically linked) extensions */
 static ExtensionModule staticExtensions[] = {
-    {GEExtensionInit, "Generic Event Extension", &noGEExtension, NULL},
-    {ShapeExtensionInit, "SHAPE", NULL, NULL},
+    {GEExtensionInit, "Generic Event Extension", &noGEExtension},
+    {ShapeExtensionInit, "SHAPE", NULL},
 #ifdef MITSHM
-    {ShmExtensionInit, SHMNAME, &noMITShmExtension, NULL},
+    {ShmExtensionInit, SHMNAME, &noMITShmExtension},
 #endif
-    {XInputExtensionInit, "XInputExtension", NULL, NULL},
+    {XInputExtensionInit, "XInputExtension", NULL},
 #ifdef XTEST
-    {XTestExtensionInit, XTestExtensionName, &noTestExtensions, NULL},
+    {XTestExtensionInit, XTestExtensionName, &noTestExtensions},
 #endif
-    {BigReqExtensionInit, "BIG-REQUESTS", NULL, NULL},
-    {SyncExtensionInit, "SYNC", NULL, NULL},
-    {XkbExtensionInit, XkbName, NULL, NULL},
-    {XCMiscExtensionInit, "XC-MISC", NULL, NULL},
+    {BigReqExtensionInit, "BIG-REQUESTS", NULL},
+    {SyncExtensionInit, "SYNC", NULL},
+    {XkbExtensionInit, XkbName, NULL},
+    {XCMiscExtensionInit, "XC-MISC", NULL},
 #ifdef XCSECURITY
-    {SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, NULL},
+    {SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension},
 #endif
 #ifdef PANORAMIX
-    {PanoramiXExtensionInit, PANORAMIX_PROTOCOL_NAME, &noPanoramiXExtension,
-     NULL},
+    {PanoramiXExtensionInit, PANORAMIX_PROTOCOL_NAME, &noPanoramiXExtension},
 #endif
 #ifdef XFIXES
     /* must be before Render to layer DisplayCursor correctly */
-    {XFixesExtensionInit, "XFIXES", &noXFixesExtension, NULL},
+    {XFixesExtensionInit, "XFIXES", &noXFixesExtension},
 #endif
 #ifdef XF86BIGFONT
-    {XFree86BigfontExtensionInit, XF86BIGFONTNAME, &noXFree86BigfontExtension,
-     NULL},
+    {XFree86BigfontExtensionInit, XF86BIGFONTNAME, &noXFree86BigfontExtension},
 #endif
-    {RenderExtensionInit, "RENDER", &noRenderExtension, NULL},
+    {RenderExtensionInit, "RENDER", &noRenderExtension},
 #ifdef RANDR
-    {RRExtensionInit, "RANDR", &noRRExtension, NULL},
+    {RRExtensionInit, "RANDR", &noRRExtension},
 #endif
 #ifdef COMPOSITE
-    {CompositeExtensionInit, "COMPOSITE", &noCompositeExtension, NULL},
+    {CompositeExtensionInit, "COMPOSITE", &noCompositeExtension},
 #endif
 #ifdef DAMAGE
-    {DamageExtensionInit, "DAMAGE", &noDamageExtension, NULL},
+    {DamageExtensionInit, "DAMAGE", &noDamageExtension},
 #endif
 #ifdef SCREENSAVER
-    {ScreenSaverExtensionInit, ScreenSaverName, &noScreenSaverExtension, NULL},
+    {ScreenSaverExtensionInit, ScreenSaverName, &noScreenSaverExtension},
 #endif
 #ifdef DBE
-    {DbeExtensionInit, "DOUBLE-BUFFER", &noDbeExtension, NULL},
+    {DbeExtensionInit, "DOUBLE-BUFFER", &noDbeExtension},
 #endif
 #ifdef XRECORD
-    {RecordExtensionInit, "RECORD", &noTestExtensions, NULL},
+    {RecordExtensionInit, "RECORD", &noTestExtensions},
 #endif
 #ifdef DPMSExtension
-    {DPMSExtensionInit, DPMSExtensionName, &noDPMSExtension, NULL},
+    {DPMSExtensionInit, DPMSExtensionName, &noDPMSExtension},
 #endif
 #ifdef RES
-    {ResExtensionInit, XRES_NAME, &noResExtension, NULL},
+    {ResExtensionInit, XRES_NAME, &noResExtension},
 #endif
 #ifdef XV
-    {XvExtensionInit, XvName, &noXvExtension, NULL},
-    {XvMCExtensionInit, XvMCName, &noXvExtension, NULL},
+    {XvExtensionInit, XvName, &noXvExtension},
+    {XvMCExtensionInit, XvMCName, &noXvExtension},
 #endif
 #ifdef XSELINUX
-    {SELinuxExtensionInit, SELINUX_EXTENSION_NAME, &noSELinuxExtension, NULL},
+    {SELinuxExtensionInit, SELINUX_EXTENSION_NAME, &noSELinuxExtension},
 #endif
 };
 
@@ -379,8 +377,4 @@ LoadExtension(ExtensionModule * e, Bool builtin)
     newext->name = e->name;
     newext->initFunc = e->initFunc;
     newext->disablePtr = e->disablePtr;
-    newext->setupFunc = e->setupFunc;
-
-    if (e->setupFunc != NULL)
-        e->setupFunc();
 }
commit 710318e803c6d5c6b8ae170d38c8253f5d780472
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:27 2012 +0100

    Replace NO_HW_ONLY_EXTS with Xorg DDX test
    
    Turns out the only thing we use NO_HW_ONLY_EXTS for is to check whether
    or not we're building inside the Xorg DDX.  Replace it with an
    XorgLoader test instead, and remove all its users.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/vfb/Makefile.am b/hw/vfb/Makefile.am
index ed46dbb..9f4992c 100644
--- a/hw/vfb/Makefile.am
+++ b/hw/vfb/Makefile.am
@@ -4,8 +4,6 @@ bin_PROGRAMS = Xvfb
 noinst_LIBRARIES = libfbcmap.a
 
 AM_CFLAGS = -DHAVE_DIX_CONFIG_H \
-            -DNO_HW_ONLY_EXTS \
-            -DNO_MODULE_EXTS \
             $(XVFBMODULES_CFLAGS) \
 	    $(DIX_CFLAGS)
 
diff --git a/hw/xnest/Makefile.am b/hw/xnest/Makefile.am
index c395b4d..3c099cd 100644
--- a/hw/xnest/Makefile.am
+++ b/hw/xnest/Makefile.am
@@ -4,7 +4,6 @@ bin_PROGRAMS = Xnest
 noinst_LIBRARIES = libfbcmap.a
 
 AM_CFLAGS = -DHAVE_XNEST_CONFIG_H \
-            -DNO_HW_ONLY_EXTS \
             $(DIX_CFLAGS) \
             $(XNESTMODULES_CFLAGS)
 
diff --git a/mi/miinitext.c b/mi/miinitext.c
index a143831..a84d486 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -157,7 +157,7 @@ static ExtensionToggle ExtensionToggleList[] = {
 #ifdef XF86BIGFONT
     {"XFree86-Bigfont", &noXFree86BigfontExtension},
 #endif
-#ifndef NO_HW_ONLY_EXTS
+#ifdef XorgLoader
 #ifdef XFreeXDGA
     {"XFree86-DGA", &noXFree86DGAExtension},
 #endif
commit 5f5bbbe543f65c48ecbb5cce80116a86ca3fbe86
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:26 2012 +0100

    Unify miinitext.c
    
    Rather than having a non-Xorg and an Xorg-specific path which basically
    just duplicated each other for no reason, we could ... just have one.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/dixmods/Makefile.am b/hw/xfree86/dixmods/Makefile.am
index 1ad122a..f161db6 100644
--- a/hw/xfree86/dixmods/Makefile.am
+++ b/hw/xfree86/dixmods/Makefile.am
@@ -45,6 +45,6 @@ endif
 libshadow_la_SOURCES = shmodule.c
 
 libdixmods_la_SOURCES = $(top_srcdir)/mi/miinitext.c
-libdixmods_la_CFLAGS = -DXFree86LOADER $(AM_CFLAGS)
+libdixmods_la_CFLAGS = $(AM_CFLAGS)
 
 libxorgxkb_la_SOURCES = xkbVT.c xkbPrivate.c xkbKillSrv.c
diff --git a/mi/miinitext.c b/mi/miinitext.c
index d76d796..a143831 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -77,6 +77,7 @@ SOFTWARE.
 
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
+#include "xf86Extensions.h"
 #endif
 
 #ifdef HAVE_DMX_CONFIG_H
@@ -111,11 +112,6 @@ SOFTWARE.
 #include "micmap.h"
 #include "globals.h"
 
-#ifdef XFree86LOADER
-#include "loaderProcs.h"
-#include "xf86Extensions.h"
-#endif
-
 /* The following is only a small first step towards run-time
  * configurable extensions.
  */
@@ -237,120 +233,6 @@ EnableDisableExtensionError(const char *name, Bool enable)
     }
 }
 
-#ifndef XFree86LOADER
-
- /*ARGSUSED*/ void
-InitExtensions(int argc, char *argv[])
-{
-    if (!noGEExtension)
-        GEExtensionInit();
-
-    ShapeExtensionInit();
-
-#ifdef MITSHM
-    if (!noMITShmExtension)
-        ShmExtensionInit();
-#endif
-
-    XInputExtensionInit();
-
-#ifdef XTEST
-    if (!noTestExtensions)
-        XTestExtensionInit();
-#endif
-
-    BigReqExtensionInit();
-    SyncExtensionInit();
-    XkbExtensionInit();
-    XCMiscExtensionInit();
-
-#ifdef XCSECURITY
-    if (!noSecurityExtension)
-        SecurityExtensionInit();
-#endif
-
-#ifdef PANORAMIX
-    if (!noPanoramiXExtension)
-        PanoramiXExtensionInit();
-#endif
-
-#ifdef XFIXES
-    /* must be before Render to layer DisplayCursor correctly */
-    if (!noXFixesExtension)
-        XFixesExtensionInit();
-#endif
-
-#ifdef XF86BIGFONT
-    if (!noXFree86BigfontExtension)
-        XFree86BigfontExtensionInit();
-#endif
-
-    if (!noRenderExtension)
-        RenderExtensionInit();
-
-#ifdef RANDR
-    if (!noRRExtension)
-        RRExtensionInit();
-#endif
-
-#ifdef COMPOSITE
-    if (!noCompositeExtension)
-        CompositeExtensionInit();
-#endif
-
-#ifdef DAMAGE
-    if (!noDamageExtension)
-        DamageExtensionInit();
-#endif
-
-#ifdef XSELINUX
-    if (!noSELinuxExtension)
-        SELinuxExtensionInit();
-#endif
-
-#if defined(SCREENSAVER)
-    if (!noScreenSaverExtension)
-        ScreenSaverExtensionInit();
-#endif
-
-#if !defined(NO_HW_ONLY_EXTS) && defined(DPMSExtension)
-    if (!noDPMSExtension)
-        DPMSExtensionInit();
-#endif
-
-#ifdef XV
-    if (!noXvExtension) {
-        XvExtensionInit();
-        XvMCExtensionInit();
-    }
-#endif
-
-#ifdef RES
-    if (!noResExtension)
-        ResExtensionInit();
-#endif
-
-#ifdef XRECORD
-    if (!noTestExtensions)
-        RecordExtensionInit();
-#endif
-
-#ifdef DBE
-    if (!noDbeExtension)
-        DbeExtensionInit();
-#endif
-
-#ifdef DMXEXT
-    DMXExtensionInit();         /* server-specific extension, cannot be disabled */
-#endif
-
-#ifdef GLXEXT
-    if (!noGlxExtension)
-        GlxExtensionInit();
-#endif
-}
-
-#else                           /* XFree86LOADER */
 /* List of built-in (statically linked) extensions */
 static ExtensionModule staticExtensions[] = {
     {GEExtensionInit, "Generic Event Extension", &noGEExtension, NULL},
@@ -502,5 +384,3 @@ LoadExtension(ExtensionModule * e, Bool builtin)
     if (e->setupFunc != NULL)
         e->setupFunc();
 }
-
-#endif                          /* XFree86LOADER */
commit 147967f67d4976a87ed07fe11b59b174907f5d43
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:25 2012 +0100

    Remove Xorg-specific extensions from non-Xorg miinitext
    
    miinitext.c had a completely separate codepath for non-Xorg servers,
    which included tests for Xorg-specific extensions such as
    XFree86-VidMode, which were external even to the Xorg DDX.  So we can
    just remove them, and the associated #undefs.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/mi/miinitext.c b/mi/miinitext.c
index 69ed97b..d76d796 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -83,9 +83,6 @@ SOFTWARE.
 #include <dmx-config.h>
 #undef XV
 #undef DBE
-#undef XF86VIDMODE
-#undef XFreeXDGA
-#undef XF86DRI
 #undef SCREENSAVER
 #undef RANDR
 #undef XFIXES
@@ -102,17 +99,10 @@ SOFTWARE.
 
 #ifdef HAVE_KDRIVE_CONFIG_H
 #include <kdrive-config.h>
-/* there must be a better way... */
-#undef XFreeXDGA
-#undef XF86DRI
-#undef XF86VIDMODE
 #endif
 
 #ifdef HAVE_XGL_CONFIG_H
 #include <xgl-config.h>
-#undef XFreeXDGA
-#undef XF86DRI
-#undef XF86VIDMODE
 #endif
 
 #include "misc.h"
@@ -323,20 +313,10 @@ InitExtensions(int argc, char *argv[])
         ScreenSaverExtensionInit();
 #endif
 
-#if !defined(NO_HW_ONLY_EXTS)
-#if defined(XF86VIDMODE)
-    if (!noXFree86VidModeExtension)
-        XFree86VidModeExtensionInit();
-#endif
-#if defined(XFreeXDGA)
-    if (!noXFree86DGAExtension)
-        XFree86DGAExtensionInit();
-#endif
-#ifdef DPMSExtension
+#if !defined(NO_HW_ONLY_EXTS) && defined(DPMSExtension)
     if (!noDPMSExtension)
         DPMSExtensionInit();
 #endif
-#endif
 
 #ifdef XV
     if (!noXvExtension) {
@@ -360,11 +340,6 @@ InitExtensions(int argc, char *argv[])
         DbeExtensionInit();
 #endif
 
-#if !defined(NO_HW_ONLY_EXTS) && defined(XF86DRI)
-    if (!noXFree86DRIExtension)
-        XFree86DRIExtensionInit();
-#endif
-
 #ifdef DMXEXT
     DMXExtensionInit();         /* server-specific extension, cannot be disabled */
 #endif
commit 27a624bee66d2797eacf90317054207dcf248028
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:24 2012 +0100

    Quartz: Move PseudoramiX initialisation to DDX
    
    As PseudoramiX is a DDX-specific extension, move its loading and
    initialisation to hw/xquartz.  This creates a QuartzExtensionInit()
    similar in spirit to xf86ExtensionInit.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 62a2852..3de223b 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -42,6 +42,7 @@
 #include "darwin.h"
 #include "darwinEvents.h"
 #include "pseudoramiX.h"
+#include "extension.h"
 #define _APPLEWM_SERVER_
 #include "applewmExt.h"
 
@@ -143,6 +144,22 @@ QuartzSetupScreen(int index,
     return TRUE;
 }
 
+static const ExtensionModule quartzExtensions[] = {
+    { PseudoramiXExtensionInit, "PseudoramiX", &noPseudoramiXExtension, NULL },
+};
+
+/*
+ * QuartzExtensionInit
+ * Initialises XQuartz-specific extensions.
+ */
+void QuartzExtensionInit(void)
+{
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(quartzExtensions); i++)
+        LoadExtension(&quartzExtensions[i], TRUE);
+}
+
 /*
  * QuartzInitOutput
  *  Quartz display initialization.
@@ -182,6 +199,8 @@ QuartzInitOutput(int argc,
 
     // Do display mode specific initialization
     quartzProcs->DisplayInit();
+
+    QuartzExtensionInit();
 }
 
 /*
diff --git a/mi/miinitext.c b/mi/miinitext.c
index e5acec4..69ed97b 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -284,11 +284,6 @@ InitExtensions(int argc, char *argv[])
         PanoramiXExtensionInit();
 #endif
 
-#ifdef INXQUARTZ
-    if (!noPseudoramiXExtension)
-        PseudoramiXExtensionInit();
-#endif
-
 #ifdef XFIXES
     /* must be before Render to layer DisplayCursor correctly */
     if (!noXFixesExtension)
commit 79d14d9fc3d92ba866864d3a5910a8c6c8e9b64f
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:23 2012 +0100

    Move the remnants of loadext.c to miinitext.c
    
    There was nothing XFree86-specific or loader-specific about this, aside
    from using xf86MsgVerb instead of ErrorF.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 70aeb6d..d93405e 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -169,11 +169,6 @@ typedef struct {
 
 #define INITARGS void
 
-/* This really shouldn't be here, but gets moved in about three commits'
- * time.  So odds are the only people who ever see this comment are doing
- * patch review, in which case, thanks! */
-extern _X_EXPORT void AddStaticExtensions(void);
-
 /* Prototypes for Loader functions that are exported to modules */
 extern _X_EXPORT pointer LoadSubModule(pointer, const char *, const char **,
                                        const char **, pointer,
@@ -184,7 +179,6 @@ extern _X_EXPORT pointer LoaderSymbol(const char *);
 extern _X_EXPORT char **LoaderListDirs(const char **, const char **);
 extern _X_EXPORT void LoaderFreeDirList(char **);
 extern _X_EXPORT void LoaderErrorMsg(const char *, const char *, int, int);
-extern _X_EXPORT void LoadExtension(ExtensionModule *, Bool);
 extern _X_EXPORT void LoaderGetOS(const char **name, int *major, int *minor,
                                   int *teeny);
 extern _X_EXPORT Bool LoaderShouldIgnoreABI(void);
diff --git a/hw/xfree86/loader/Makefile.am b/hw/xfree86/loader/Makefile.am
index d6ddbec..bd47a63 100644
--- a/hw/xfree86/loader/Makefile.am
+++ b/hw/xfree86/loader/Makefile.am
@@ -14,7 +14,6 @@ EXTRA_DIST = \
 libloader_la_SOURCES = \
 	loader.c \
 	loaderProcs.h \
-	loadext.c \
         loadmod.c \
 	os.c
 
diff --git a/hw/xfree86/loader/loadext.c b/hw/xfree86/loader/loadext.c
deleted file mode 100644
index 62355bb..0000000
--- a/hw/xfree86/loader/loadext.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 2000 by The XFree86 Project, Inc.
- *
- * 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, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 copyright holder(s)
- * and author(s) 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 copyright holder(s) and author(s).
- */
-
-/* Maybe this file belongs elsewhere? */
-
-#define LOADERDECLARATIONS
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "loaderProcs.h"
-#include "misc.h"
-#include "xf86.h"
-
-/*
- * This should be static, but miinitext wants it.  FIXME: make extension
- * initialization not completely terrible.
- */
-ExtensionModule *ExtensionModuleList = NULL;
-static int numExtensionModules = 0;
-
-static ExtensionModule *
-NewExtensionModule(void)
-{
-    ExtensionModule *save = ExtensionModuleList;
-    int n;
-
-    /* Make sure built-in extensions get added to the list before those
-     * in modules. */
-    AddStaticExtensions();
-
-    /* Sanity check */
-    if (!ExtensionModuleList)
-        numExtensionModules = 0;
-
-    n = numExtensionModules + 1;
-    ExtensionModuleList = realloc(ExtensionModuleList,
-                                  (n + 1) * sizeof(ExtensionModule));
-    if (ExtensionModuleList == NULL) {
-        ExtensionModuleList = save;
-        return NULL;
-    }
-    else {
-        numExtensionModules++;
-        ExtensionModuleList[numExtensionModules].name = NULL;
-        return ExtensionModuleList + (numExtensionModules - 1);
-    }
-}
-
-void
-LoadExtension(ExtensionModule * e, Bool builtin)
-{
-    ExtensionModule *newext;
-
-    if (e == NULL || e->name == NULL)
-        return;
-
-    if (!(newext = NewExtensionModule()))
-        return;
-
-    if (builtin)
-        xf86MsgVerb(X_INFO, 2, "Initializing built-in extension %s\n", e->name);
-    else
-        xf86MsgVerb(X_INFO, 2, "Loading extension %s\n", e->name);
-
-    newext->name = e->name;
-    newext->initFunc = e->initFunc;
-    newext->disablePtr = e->disablePtr;
-    newext->setupFunc = e->setupFunc;
-
-    if (e->setupFunc != NULL)
-        e->setupFunc();
-}
diff --git a/include/extension.h b/include/extension.h
index dbe1afc..cc1dfa1 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -87,8 +87,6 @@ typedef struct {
     InitExtension setupFunc;
 } ExtensionModule;
 
-extern ExtensionModule *ExtensionModuleList;
-
 extern _X_EXPORT unsigned short StandardMinorOpcode(ClientPtr /*client */ );
 
 extern _X_EXPORT Bool EnableDisableExtension(const char *name, Bool enable);
@@ -100,4 +98,6 @@ extern _X_EXPORT void InitExtensions(int argc, char **argv);
 
 extern _X_EXPORT void CloseDownExtensions(void);
 
+extern _X_EXPORT void LoadExtension(ExtensionModule *ext, Bool external);
+
 #endif                          /* EXTENSION_H */
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 500e882..e5acec4 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -44,6 +44,33 @@ SOFTWARE.
 
 ******************************************************************/
 
+/*
+ * Copyright (c) 2000 by The XFree86 Project, Inc.
+ *
+ * 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, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 copyright holder(s)
+ * and author(s) 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 copyright holder(s) and author(s).
+ */
+
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
 #endif
@@ -418,7 +445,10 @@ static ExtensionModule staticExtensions[] = {
 #endif
 };
 
-void
+static ExtensionModule *ExtensionModuleList = NULL;
+static int numExtensionModules = 0;
+
+static void
 AddStaticExtensions(void)
 {
     static Bool listInitialised = FALSE;
@@ -450,4 +480,57 @@ InitExtensions(int argc, char *argv[])
     }
 }
 
+static ExtensionModule *
+NewExtensionModule(void)
+{
+    ExtensionModule *save = ExtensionModuleList;
+    int n;
+
+    /* Make sure built-in extensions get added to the list before those
+     * in modules. */
+    AddStaticExtensions();
+
+    /* Sanity check */
+    if (!ExtensionModuleList)
+        numExtensionModules = 0;
+
+    n = numExtensionModules + 1;
+    ExtensionModuleList = realloc(ExtensionModuleList,
+                                  (n + 1) * sizeof(ExtensionModule));
+    if (ExtensionModuleList == NULL) {
+        ExtensionModuleList = save;
+        return NULL;
+    }
+    else {
+        numExtensionModules++;
+        ExtensionModuleList[numExtensionModules].name = NULL;
+        return ExtensionModuleList + (numExtensionModules - 1);
+    }
+}
+
+void
+LoadExtension(ExtensionModule * e, Bool builtin)
+{
+    ExtensionModule *newext;
+
+    if (e == NULL || e->name == NULL)
+        return;
+
+    if (!(newext = NewExtensionModule()))
+        return;
+
+    if (builtin)
+        ErrorF("Initializing built-in extension %s\n", e->name);
+    else
+        ErrorF("Loading extension %s\n", e->name);
+
+    newext->name = e->name;
+    newext->initFunc = e->initFunc;
+    newext->disablePtr = e->disablePtr;
+    newext->setupFunc = e->setupFunc;
+
+    if (e->setupFunc != NULL)
+        e->setupFunc();
+}
+
 #endif                          /* XFree86LOADER */
commit a089af3477dd01a831b89c06f982679c60e42975
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:22 2012 +0100

    Loader: Move ExtensionModule types to DIX
    
    In preparation for gutting loadext.c, move the ExtensionModule struct to
    the DIX, and unexport ExtensionModuleList (why, why, why, why was this
    ever exported in the first place, tbqh).
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index d528a5d..70aeb6d 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -42,6 +42,7 @@
 #define _XF86MODULE_H
 
 #include "misc.h"
+#include "extension.h"
 #ifndef NULL
 #define NULL ((void *)0)
 #endif
@@ -168,17 +169,6 @@ typedef struct {
 
 #define INITARGS void
 
-typedef void (*InitExtension) (void);
-
-typedef struct {
-    InitExtension initFunc;
-    const char *name;
-    Bool *disablePtr;
-    InitExtension setupFunc;
-} ExtensionModule;
-
-extern _X_EXPORT ExtensionModule *ExtensionModuleList;
-
 /* This really shouldn't be here, but gets moved in about three commits'
  * time.  So odds are the only people who ever see this comment are doing
  * patch review, in which case, thanks! */
diff --git a/include/extension.h b/include/extension.h
index f0560d7..dbe1afc 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -44,6 +44,33 @@ SOFTWARE.
 
 ******************************************************************/
 
+/*
+ * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
+ *
+ * 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, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 copyright holder(s)
+ * and author(s) 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 copyright holder(s) and author(s).
+ */
+
 #ifndef EXTENSION_H
 #define EXTENSION_H
 
@@ -51,6 +78,17 @@ SOFTWARE.
 
 #include "dixstruct.h"
 
+typedef void (*InitExtension) (void);
+
+typedef struct {
+    InitExtension initFunc;
+    const char *name;
+    Bool *disablePtr;
+    InitExtension setupFunc;
+} ExtensionModule;
+
+extern ExtensionModule *ExtensionModuleList;
+
 extern _X_EXPORT unsigned short StandardMinorOpcode(ClientPtr /*client */ );
 
 extern _X_EXPORT Bool EnableDisableExtension(const char *name, Bool enable);
diff --git a/mi/miinitext.c b/mi/miinitext.c
index a2bbdaa..500e882 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -94,9 +94,7 @@ SOFTWARE.
 #include "micmap.h"
 #include "globals.h"
 
-#ifndef XFree86LOADER
-typedef void (*InitExtension) (void);
-#else                           /* XFree86Loader */
+#ifdef XFree86LOADER
 #include "loaderProcs.h"
 #include "xf86Extensions.h"
 #endif
commit 8171108602556446f12c1cfbc37c6abf3b0195eb
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:21 2012 +0100

    Loader: Remove extension initialisation sorting
    
    Extensions could previously declare initialisation dependencies on other
    extensions, which would then get nicely sorted by the loader.  We only
    had one user for this, GLX, which had one pointless (Composite) and one
    possibly useful dependency (DBE).  As DBE is now a built-in, it will
    always be sorted by GLX, so we no longer have any users for it.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/COPYING b/COPYING
index cd9e80a..7aa0df0 100644
--- a/COPYING
+++ b/COPYING
@@ -1788,7 +1788,7 @@ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 PERFORMANCE OF THIS SOFTWARE.
 
 
-Copyright (c) 1989, 1990, 1993, 1994
+Copyright (c) 1987, 1990, 1993
      The Regents of the University of California.  All rights reserved.
 
 This code is derived from software contributed to Berkeley by
diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c
index 15bab42..8cbeedf 100644
--- a/hw/xfree86/common/xf86Extensions.c
+++ b/hw/xfree86/common/xf86Extensions.c
@@ -59,7 +59,6 @@ static ExtensionModule extensionModules[] = {
 	XFree86VidModeExtensionInit,
 	XF86VIDMODENAME,
 	&noXFree86VidModeExtension,
-	NULL,
 	NULL
     },
 #endif
@@ -68,7 +67,6 @@ static ExtensionModule extensionModules[] = {
 	XFree86DGAExtensionInit,
 	XF86DGANAME,
 	&noXFree86DGAExtension,
-	NULL,
 	NULL
     },
 #endif
@@ -77,7 +75,6 @@ static ExtensionModule extensionModules[] = {
         XFree86DRIExtensionInit,
         "XFree86-DRI",
         &noXFree86DRIExtension,
-        NULL,
         NULL
     },
 #endif
@@ -86,7 +83,6 @@ static ExtensionModule extensionModules[] = {
         DRI2ExtensionInit,
         DRI2_NAME,
         &noDRI2Extension,
-        NULL,
         NULL
     }
 #endif
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index dc5d0a8..d528a5d 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -175,7 +175,6 @@ typedef struct {
     const char *name;
     Bool *disablePtr;
     InitExtension setupFunc;
-    const char **initDependencies;
 } ExtensionModule;
 
 extern _X_EXPORT ExtensionModule *ExtensionModuleList;
diff --git a/hw/xfree86/dixmods/glxmodule.c b/hw/xfree86/dixmods/glxmodule.c
index a2b06a2..2f0a3dd 100644
--- a/hw/xfree86/dixmods/glxmodule.c
+++ b/hw/xfree86/dixmods/glxmodule.c
@@ -50,7 +50,6 @@ static ExtensionModule GLXExt = {
     GlxExtensionInit,
     "GLX",
     &noGlxExtension,
-    NULL,
     NULL
 };
 
diff --git a/hw/xfree86/loader/loaderProcs.h b/hw/xfree86/loader/loaderProcs.h
index a7b752b..8b4b53f 100644
--- a/hw/xfree86/loader/loaderProcs.h
+++ b/hw/xfree86/loader/loaderProcs.h
@@ -80,7 +80,6 @@ ModuleDescPtr LoadModule(const char *, const char *, const char **,
 ModuleDescPtr DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent);
 void UnloadDriver(ModuleDescPtr);
 void LoaderSetPath(const char *path);
-void LoaderSortExtensions(void);
 
 void LoaderUnload(const char *, void *);
 unsigned long LoaderGetModuleVersion(ModuleDescPtr mod);
diff --git a/hw/xfree86/loader/loadext.c b/hw/xfree86/loader/loadext.c
index 0754ea9..62355bb 100644
--- a/hw/xfree86/loader/loadext.c
+++ b/hw/xfree86/loader/loadext.c
@@ -91,354 +91,7 @@ LoadExtension(ExtensionModule * e, Bool builtin)
     newext->initFunc = e->initFunc;
     newext->disablePtr = e->disablePtr;
     newext->setupFunc = e->setupFunc;
-    newext->initDependencies = e->initDependencies;
 
     if (e->setupFunc != NULL)
         e->setupFunc();
 }
-
-/*
- * Sort ExtensionModuleList according to the initialisation order
- * dependencies.  The code for this is taken from BSD's tsort,
- * and carries the following copyright/license:
- *
- *
- * Copyright (c) 1989, 1993, 1994
- *      The Regents of the University of California.  All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Michael Rendell of Memorial University of Newfoundland.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by the University of
- *      California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#define	NF_MARK		0x1     /* marker for cycle detection */
-#define	NF_ACYCLIC	0x2     /* this node is cycle free */
-#define	NF_NODEST	0x4     /* Unreachable */
-
-typedef struct node_str NODE;
-struct node_str {
-    NODE **n_prevp;             /* pointer to previous node's n_next */
-    NODE *n_next;               /* next node in graph */
-    NODE **n_arcs;              /* array of arcs to other nodes */
-    int n_narcs;                /* number of arcs in n_arcs[] */
-    int n_arcsize;              /* size of n_arcs[] array */
-    int n_refcnt;               /* # of arcs pointing to this node */
-    int n_flags;                /* NF_* */
-    const char *n_name;         /* name of this node */
-};
-
-static NODE *graph = NULL, **cycle_buf = NULL, **longest_cycle = NULL;
-static int longest = 0;
-static NODE *sorted = NULL, *last = NULL;
-
-/* Find a node in the graph (insert if not found) and return a pointer to it. */
-static NODE *
-get_node(const char *name)
-{
-    NODE *n;
-
-    for (n = graph; n && n->n_name && strcmp(n->n_name, name); n = n->n_next);
-    if (n)
-        return n;
-
-    n = xnfalloc(sizeof(NODE));
-
-    n->n_narcs = 0;
-    n->n_arcsize = 0;
-    n->n_arcs = NULL;
-    n->n_refcnt = 0;
-    n->n_flags = 0;
-    n->n_name = name;
-
-    /* Add to linked list. */
-    if ((n->n_next = graph) != NULL)
-        graph->n_prevp = &n->n_next;
-    n->n_prevp = &graph;
-    graph = n;
-
-    return n;
-}
-
-/*
- * add an arc from node s1 to node s2 in the graph.  If s1 or s2 are not in
- * the graph, then add them.
- */
-static void
-add_arc(const char *s1, const char *s2)
-{
-    NODE *n1;
-    NODE *n2;
-    int bsize, i;
-
-    n1 = get_node(s1);
-
-    if (!strcmp(s1, s2))
-        return;
-
-    n2 = get_node(s2);
-
-    /*
-     * Check if this arc is already here.
-     */
-    for (i = 0; i < n1->n_narcs; i++)
-        if (n1->n_arcs[i] == n2)
-            return;
-    /*
-     * Add it.
-     */
-    if (n1->n_narcs == n1->n_arcsize) {
-        if (!n1->n_arcsize)
-            n1->n_arcsize = 10;
-        bsize = n1->n_arcsize * sizeof(*n1->n_arcs) * 2;
-        n1->n_arcs = xnfrealloc(n1->n_arcs, bsize);
-        n1->n_arcsize = bsize / sizeof(*n1->n_arcs);
-    }
-    n1->n_arcs[n1->n_narcs++] = n2;
-    ++n2->n_refcnt;
-}
-
-/*
- * Clear the NODEST flag from all nodes.
- */
-static void
-clear_cycle(void)
-{
-    NODE *n;
-
-    for (n = graph; n != NULL; n = n->n_next)
-        n->n_flags &= ~NF_NODEST;
-}
-
-/* print node and remove from graph (does not actually free node) */
-static void
-remove_node(NODE * n)
-{
-    NODE **np;
-    NODE *newnode;
-    int i;
-
-#ifdef DEBUG
-    ErrorF("%s\n", n->n_name);
-#endif
-    newnode = xnfalloc(sizeof(NODE));
-    memcpy(newnode, n, sizeof(NODE));
-    if (last)
-        last->n_next = newnode;
-    else
-        sorted = newnode;
-    last = newnode;
-    newnode->n_next = NULL;
-
-    for (np = n->n_arcs, i = n->n_narcs; --i >= 0; np++)
-        --(*np)->n_refcnt;
-    n->n_narcs = 0;
-    *n->n_prevp = n->n_next;
-    if (n->n_next)
-        n->n_next->n_prevp = n->n_prevp;
-}
-
-static void
-free_nodes(NODE * nodelist)
-{
-    NODE *n, *nextnode;
-
-    for (n = nodelist; n;) {
-        nextnode = n->n_next;
-        free(n);
-        n = nextnode;
-    }
-}
-
-/* look for the longest? cycle from node from to node to. */
-static int
-find_cycle(NODE * from, NODE * to, int longest_len, int depth)
-{
-    NODE **np;
-    int i, len;
-
-    /*
-     * avoid infinite loops and ignore portions of the graph known
-     * to be acyclic
-     */
-    if (from->n_flags & (NF_NODEST | NF_MARK | NF_ACYCLIC))
-        return 0;
-    from->n_flags |= NF_MARK;
-
-    for (np = from->n_arcs, i = from->n_narcs; --i >= 0; np++) {
-        cycle_buf[depth] = *np;
-        if (*np == to) {
-            if (depth + 1 > longest_len) {
-                longest_len = depth + 1;
-                memcpy((char *) longest_cycle,
-                       (char *) cycle_buf, longest_len * sizeof(NODE *));
-            }
-        }
-        else {
-            if ((*np)->n_flags & (NF_MARK | NF_ACYCLIC | NF_NODEST))
-                continue;
-            len = find_cycle(*np, to, longest_len, depth + 1);
-
-#ifdef DEBUG
-            ErrorF("%*s %s->%s %d\n", depth, "", from->n_name, to->n_name, len);
-#endif
-
-            if (len == 0)
-                (*np)->n_flags |= NF_NODEST;
-
-            if (len > longest_len)
-                longest_len = len;
-
-            if (len > 0 && !longest)
-                break;
-        }
-    }
-    from->n_flags &= ~NF_MARK;
-    return longest_len;
-}
-
-/* do topological sort on graph */
-static void
-tsort(void)
-{
-    NODE *n, *next;
-    int cnt, i;
-
-    while (graph != NULL) {
-        /*
-         * Keep getting rid of simple cases until there are none left,
-         * if there are any nodes still in the graph, then there is
-         * a cycle in it.
-         */
-        do {
-            for (cnt = 0, n = graph; n != NULL; n = next) {
-                next = n->n_next;
-                if (n->n_refcnt == 0) {
-                    remove_node(n);
-                    ++cnt;
-                }
-            }
-        } while (graph != NULL && cnt);
-
-        if (graph == NULL)
-            break;
-
-        if (!cycle_buf) {
-            /*
-             * Allocate space for two cycle logs - one to be used
-             * as scratch space, the other to save the longest
-             * cycle.
-             */
-            for (cnt = 0, n = graph; n != NULL; n = n->n_next)
-                ++cnt;
-            cycle_buf = xnfalloc(sizeof(NODE *) * cnt);
-            longest_cycle = xnfalloc(sizeof(NODE *) * cnt);
-            if (cycle_buf == NULL || longest_cycle == NULL)
-                return;
-        }
-        for (n = graph; n != NULL; n = n->n_next)
-            if (!(n->n_flags & NF_ACYCLIC)) {
-                if ((cnt = find_cycle(n, n, 0, 0))) {
-                    ErrorF("tsort: cycle in data");
-                    for (i = 0; i < cnt; i++)
-                        ErrorF("%s", longest_cycle[i]->n_name);
-                    remove_node(n);
-                    clear_cycle();
-                    break;
-                }
-                else {
-                    /* to avoid further checks */
-                    n->n_flags |= NF_ACYCLIC;
-                    clear_cycle();
-                }
-            }
-
-        if (n == NULL)
-            ErrorF("tsort: internal error -- could not find cycle");
-    }
-    free(cycle_buf);
-    free(longest_cycle);
-    if (graph)
-        free_nodes(graph);
-}
-
-void
-LoaderSortExtensions(void)
-{
-    int i, j;
-    ExtensionModule *ext, *newList;
-    NODE *node;
-
-    graph = NULL;
-    longest = 0;
-    sorted = NULL;
-    last = NULL;
-    cycle_buf = NULL;
-    longest_cycle = NULL;
-
-    /*
-     * Parse list and build the graph.  Enter them in reverse order
-     * because tsort() will reverse those that have no depedencies.
-     */
-    for (i = numExtensionModules - 1; i >= 0; i--) {
-        ext = &ExtensionModuleList[i];
-        add_arc(ext->name, ext->name);
-#ifdef DEBUG
-        ErrorF("Extension %s:\n", ext->name);
-#endif
-        if (ext->initDependencies)
-            for (j = 0; ext->initDependencies[j]; j++) {
-                add_arc(ext->initDependencies[j], ext->name);
-#ifdef DEBUG
-                ErrorF("\t%s\n", ext->initDependencies[j]);
-#endif
-            }
-    }
-    tsort();
-    newList = xnfalloc((numExtensionModules + 1) * sizeof(ExtensionModule));
-    i = 0;
-    for (node = sorted; node; node = node->n_next) {
-        for (j = 0; j < numExtensionModules; j++)
-            if (!strcmp(node->n_name, ExtensionModuleList[j].name))
-                break;
-        if (j != numExtensionModules)
-            newList[i++] = ExtensionModuleList[j];
-    }
-    if (sorted)
-        free_nodes(sorted);
-    if (graph)
-        free_nodes(graph);
-    newList[i].name = NULL;
-    free(ExtensionModuleList);
-    ExtensionModuleList = newList;
-#ifdef DEBUG
-    for (i = 0; ExtensionModuleList[i].name; i++)
-        ErrorF("Extension %s\n", ExtensionModuleList[i].name);
-#endif
-}
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 30c428c..a2bbdaa 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -358,38 +358,37 @@ InitExtensions(int argc, char *argv[])
 #else                           /* XFree86LOADER */
 /* List of built-in (statically linked) extensions */
 static ExtensionModule staticExtensions[] = {
-    {GEExtensionInit, "Generic Event Extension", &noGEExtension, NULL, NULL},
-    {ShapeExtensionInit, "SHAPE", NULL, NULL, NULL},
+    {GEExtensionInit, "Generic Event Extension", &noGEExtension, NULL},
+    {ShapeExtensionInit, "SHAPE", NULL, NULL},
 #ifdef MITSHM
-    {ShmExtensionInit, SHMNAME, &noMITShmExtension, NULL, NULL},
+    {ShmExtensionInit, SHMNAME, &noMITShmExtension, NULL},
 #endif
-    {XInputExtensionInit, "XInputExtension", NULL, NULL, NULL},
+    {XInputExtensionInit, "XInputExtension", NULL, NULL},
 #ifdef XTEST
-    {XTestExtensionInit, XTestExtensionName, &noTestExtensions, NULL, NULL},
+    {XTestExtensionInit, XTestExtensionName, &noTestExtensions, NULL},
 #endif
-    {BigReqExtensionInit, "BIG-REQUESTS", NULL, NULL, NULL},
-    {SyncExtensionInit, "SYNC", NULL, NULL, NULL},
-    {XkbExtensionInit, XkbName, NULL, NULL, NULL},
-    {XCMiscExtensionInit, "XC-MISC", NULL, NULL, NULL},
+    {BigReqExtensionInit, "BIG-REQUESTS", NULL, NULL},
+    {SyncExtensionInit, "SYNC", NULL, NULL},
+    {XkbExtensionInit, XkbName, NULL, NULL},
+    {XCMiscExtensionInit, "XC-MISC", NULL, NULL},
 #ifdef XCSECURITY
-    {SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, NULL,
-     NULL},
+    {SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, NULL},
 #endif
 #ifdef PANORAMIX
     {PanoramiXExtensionInit, PANORAMIX_PROTOCOL_NAME, &noPanoramiXExtension,
-     NULL, NULL},
+     NULL},
 #endif
 #ifdef XFIXES
     /* must be before Render to layer DisplayCursor correctly */
-    {XFixesExtensionInit, "XFIXES", &noXFixesExtension, NULL, NULL},
+    {XFixesExtensionInit, "XFIXES", &noXFixesExtension, NULL},
 #endif
 #ifdef XF86BIGFONT
     {XFree86BigfontExtensionInit, XF86BIGFONTNAME, &noXFree86BigfontExtension,
-     NULL, NULL},
+     NULL},
 #endif
-    {RenderExtensionInit, "RENDER", &noRenderExtension, NULL, NULL},
+    {RenderExtensionInit, "RENDER", &noRenderExtension, NULL},
 #ifdef RANDR
-    {RRExtensionInit, "RANDR", &noRRExtension, NULL, NULL},
+    {RRExtensionInit, "RANDR", &noRRExtension, NULL},
 #endif
 #ifdef COMPOSITE
     {CompositeExtensionInit, "COMPOSITE", &noCompositeExtension, NULL},
@@ -442,10 +441,7 @@ InitExtensions(int argc, char *argv[])
     int i;
     ExtensionModule *ext;
 
-    /* Make sure all static extensions have been added, then sort the
-     * extensions according to their init dependencies. */
     AddStaticExtensions();
-    LoaderSortExtensions();
 
     for (i = 0; ExtensionModuleList[i].name != NULL; i++) {
         ext = &ExtensionModuleList[i];
commit d52ab85c7ef5058dcbd8a75eb84058908dc22906
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:20 2012 +0100

    GLX: Remove extension init dependencies
    
    GLX was the only user of extension init order dependencies, using them
    to depend on Composite, which has always been built-in anyway, and DBE,
    which is now built-in.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/dixmods/glxmodule.c b/hw/xfree86/dixmods/glxmodule.c
index f263324..a2b06a2 100644
--- a/hw/xfree86/dixmods/glxmodule.c
+++ b/hw/xfree86/dixmods/glxmodule.c
@@ -46,14 +46,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 static MODULESETUPPROTO(glxSetup);
 
-static const char *initdeps[] = { "DOUBLE-BUFFER", "COMPOSITE", NULL };
-
 static ExtensionModule GLXExt = {
     GlxExtensionInit,
     "GLX",
     &noGlxExtension,
     NULL,
-    initdeps
+    NULL
 };
 
 static XF86ModuleVersionInfo VersRec = {
commit 2fba9445a0357f67641e41ac334b5529c37774a2
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:19 2012 +0100

    Add static extensions before those in modules
    
    Make sure we add static extensions before anything in a module.  This is
    more or less a no-op at the moment, but will come in handy later when
    extension dependency sorting is removed.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index c48f041..dc5d0a8 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -180,6 +180,11 @@ typedef struct {
 
 extern _X_EXPORT ExtensionModule *ExtensionModuleList;
 
+/* This really shouldn't be here, but gets moved in about three commits'
+ * time.  So odds are the only people who ever see this comment are doing
+ * patch review, in which case, thanks! */
+extern _X_EXPORT void AddStaticExtensions(void);
+
 /* Prototypes for Loader functions that are exported to modules */
 extern _X_EXPORT pointer LoadSubModule(pointer, const char *, const char **,
                                        const char **, pointer,
diff --git a/hw/xfree86/loader/loadext.c b/hw/xfree86/loader/loadext.c
index daa1abf..0754ea9 100644
--- a/hw/xfree86/loader/loadext.c
+++ b/hw/xfree86/loader/loadext.c
@@ -49,6 +49,10 @@ NewExtensionModule(void)
     ExtensionModule *save = ExtensionModuleList;
     int n;
 
+    /* Make sure built-in extensions get added to the list before those
+     * in modules. */
+    AddStaticExtensions();
+
     /* Sanity check */
     if (!ExtensionModuleList)
         numExtensionModules = 0;
diff --git a/mi/miinitext.c b/mi/miinitext.c
index a8644db..30c428c 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -421,22 +421,31 @@ static ExtensionModule staticExtensions[] = {
 #endif
 };
 
- /*ARGSUSED*/ void
+void
+AddStaticExtensions(void)
+{
+    static Bool listInitialised = FALSE;
+    int i;
+
+    if (listInitialised)
+        return;
+    listInitialised = TRUE;
+
+    /* Add built-in extensions to the list. */
+    for (i = 0; i < ARRAY_SIZE(staticExtensions); i++)
+        LoadExtension(&staticExtensions[i], TRUE);
+}
+
+void
 InitExtensions(int argc, char *argv[])
 {
     int i;
     ExtensionModule *ext;
-    static Bool listInitialised = FALSE;
-
-    if (!listInitialised) {
-        /* Add built-in extensions to the list. */
-        for (i = 0; i < ARRAY_SIZE(staticExtensions); i++)
-            LoadExtension(&staticExtensions[i], TRUE);
 
-        /* Sort the extensions according the init dependencies. */
-        LoaderSortExtensions();
-        listInitialised = TRUE;
-    }
+    /* Make sure all static extensions have been added, then sort the
+     * extensions according to their init dependencies. */
+    AddStaticExtensions();
+    LoaderSortExtensions();
 
     for (i = 0; ExtensionModuleList[i].name != NULL; i++) {
         ext = &ExtensionModuleList[i];
commit 9a953e0e9dcb8a8e43cc27ffaef460268fbe1916
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:18 2012 +0100

    Move DRI2 from external module to built-in
    
    Instead of keeping a tiny amount of code in an external module, just man
    up and build it into the core server.
    
    v2: Fix test/Makefile.am to only link libdri2.la if DRI2 is set
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 0c3801d..cd699ee 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -6,6 +6,7 @@ endif
 
 if DRI2
 DRI2_SUBDIR = dri2
+DRI2_LIB = dri2/libdri2.la
 endif
 
 if XF86UTILS
@@ -27,8 +28,8 @@ INT10_SUBDIR = int10
 endif
 
 SUBDIRS = common ddc x86emu $(INT10_SUBDIR) os-support parser \
-	  ramdac $(VGAHW_SUBDIR) loader modes $(DRI_SUBDIR) . \
-	  $(VBE_SUBDIR) $(XAA_SUBDIR) $(DRI2_SUBDIR) i2c dixmods \
+	  ramdac $(VGAHW_SUBDIR) loader modes $(DRI_SUBDIR) \
+	  $(DRI2_SUBDIR) . $(VBE_SUBDIR) $(XAA_SUBDIR) i2c dixmods \
 	  fbdevhw shadowfb exa $(XF86UTILS_SUBDIR) doc man
 
 DIST_SUBDIRS = common ddc i2c x86emu int10 fbdevhw os-support \
@@ -42,7 +43,7 @@ nodist_Xorg_SOURCES = sdksyms.c
 AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
 INCLUDES = $(XORG_INCS) -I$(srcdir)/parser -I$(top_srcdir)/miext/cw \
 	-I$(srcdir)/ddc -I$(srcdir)/i2c -I$(srcdir)/modes -I$(srcdir)/ramdac \
-	-I$(srcdir)/dri
+	-I$(srcdir)/dri -I$(srcdir)/dri2
 
 LOCAL_LIBS = \
             $(MAIN_LIB) \
@@ -59,6 +60,7 @@ LOCAL_LIBS = \
             $(XORG_LIBS) \
             dixmods/libxorgxkb.la \
             $(DRI_LIB) \
+            $(DRI2_LIB) \
             $(top_builddir)/mi/libmi.la \
             $(top_builddir)/os/libos.la
 Xorg_LDADD = \
diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index cb6d0d4..325875d 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -56,7 +56,7 @@ INCLUDES = $(XORG_INCS) -I$(srcdir)/../ddc -I$(srcdir)/../i2c \
 	   -I$(srcdir)/../loader -I$(srcdir)/../parser \
            -I$(srcdir)/../vbe -I$(srcdir)/../int10 \
 	   -I$(srcdir)/../vgahw -I$(srcdir)/../dixmods/extmod \
-	   -I$(srcdir)/../modes -I$(srcdir)/../ramdac
+	   -I$(srcdir)/../modes -I$(srcdir)/../ramdac -I$(srcdir)/../dri2
 
 sdk_HEADERS = compiler.h fourcc.h xf86.h xf86Module.h xf86Opt.h \
               xf86PciInfo.h xf86Priv.h xf86Privstr.h \
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 0dbfa98..486752b 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -112,9 +112,6 @@ static ModuleDefault ModuleDefaults[] = {
 #ifdef GLXEXT
     {.name = "glx",.toLoad = TRUE,.load_opt = NULL},
 #endif
-#ifdef DRI2
-    {.name = "dri2",.toLoad = TRUE,.load_opt = NULL},
-#endif
 #ifdef __CYGWIN__
     /* load DIX modules used by drivers first */
     {.name = "fb",.toLoad = TRUE,.load_opt = NULL},
diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c
index b38ecf2..15bab42 100644
--- a/hw/xfree86/common/xf86Extensions.c
+++ b/hw/xfree86/common/xf86Extensions.c
@@ -81,6 +81,15 @@ static ExtensionModule extensionModules[] = {
         NULL
     },
 #endif
+#ifdef DRI2
+    {
+        DRI2ExtensionInit,
+        DRI2_NAME,
+        &noDRI2Extension,
+        NULL,
+        NULL
+    }
+#endif
 };
 
 static void
diff --git a/hw/xfree86/common/xf86Extensions.h b/hw/xfree86/common/xf86Extensions.h
index f86a421..9b8448d 100644
--- a/hw/xfree86/common/xf86Extensions.h
+++ b/hw/xfree86/common/xf86Extensions.h
@@ -35,6 +35,7 @@ extern void XFree86DRIExtensionInit(void);
 
 #ifdef DRI2
 #include <X11/extensions/dri2proto.h>
+extern Bool noDRI2Extension;
 extern void DRI2ExtensionInit(void);
 #endif
 
diff --git a/hw/xfree86/dri2/Makefile.am b/hw/xfree86/dri2/Makefile.am
index ad3419b..502a2ee 100644
--- a/hw/xfree86/dri2/Makefile.am
+++ b/hw/xfree86/dri2/Makefile.am
@@ -1,16 +1,14 @@
-libdri2_la_LTLIBRARIES = libdri2.la
-libdri2_la_CFLAGS = \
+noinst_LTLIBRARIES = libdri2.la
+AM_CFLAGS = \
 	-DHAVE_XORG_CONFIG_H \
-	@DIX_CFLAGS@ @XORG_CFLAGS@ @DRI2PROTO_CFLAGS@ @LIBDRM_CFLAGS@ \
+	@DIX_CFLAGS@ @XORG_CFLAGS@ \
 	-I$(top_srcdir)/hw/xfree86/common \
 	-I$(top_srcdir)/hw/xfree86/os-support/bus
 
-libdri2_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-libdri2_la_LIBADD = @LIBDRM_LIBS@ $(PIXMAN_LIBS)
-libdri2_ladir = $(moduledir)/extensions
 libdri2_la_SOURCES = \
 	dri2.c \
 	dri2.h \
-	dri2ext.c
+	dri2ext.c \
+	dri2int.h
 
 sdk_HEADERS = dri2.h
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 887ce46..2ea0c33 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -44,6 +44,7 @@
 #include "windowstr.h"
 #include "dixstruct.h"
 #include "dri2.h"
+#include "dri2int.h"
 #include "xf86VGAarbiter.h"
 #include "damage.h"
 #include "xf86.h"
@@ -1552,7 +1553,6 @@ DRI2CloseScreen(ScreenPtr pScreen)
     dixSetPrivate(&pScreen->devPrivates, dri2ScreenPrivateKey, NULL);
 }
 
-extern ExtensionModule dri2ExtensionModule;
 extern Bool DRI2ModuleSetup(void);
 
 /* Called by InitExtensions() */
@@ -1566,46 +1566,14 @@ DRI2ModuleSetup(void)
     return TRUE;
 }
 
-static pointer
-DRI2Setup(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    static Bool setupDone = FALSE;
-
-    if (!setupDone) {
-        setupDone = TRUE;
-        LoadExtension(&dri2ExtensionModule, FALSE);
-    }
-    else {
-        if (errmaj)
-            *errmaj = LDR_ONCEONLY;
-    }
-
-    return (pointer) 1;
-}
-
-static XF86ModuleVersionInfo DRI2VersRec = {
-    "dri2",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 2, 0,
-    ABI_CLASS_EXTENSION,
-    ABI_EXTENSION_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData dri2ModuleData = { &DRI2VersRec, DRI2Setup, NULL };
-
 void
 DRI2Version(int *major, int *minor)
 {
     if (major != NULL)
-        *major = DRI2VersRec.majorversion;
+        *major = 1;
 
     if (minor != NULL)
-        *minor = DRI2VersRec.minorversion;
+        *minor = 2;
 }
 
 int
diff --git a/hw/xfree86/dri2/dri2.h b/hw/xfree86/dri2/dri2.h
index 28f2d75..da7825e 100644
--- a/hw/xfree86/dri2/dri2.h
+++ b/hw/xfree86/dri2/dri2.h
@@ -254,8 +254,6 @@ typedef struct {
     DRI2CopyRegion2ProcPtr CopyRegion2;
 } DRI2InfoRec, *DRI2InfoPtr;
 
-extern _X_EXPORT int DRI2EventBase;
-
 extern _X_EXPORT Bool DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info);
 
 extern _X_EXPORT void DRI2CloseScreen(ScreenPtr pScreen);
diff --git a/hw/xfree86/dri2/dri2ext.c b/hw/xfree86/dri2/dri2ext.c
index c73fe9d..eb6fd44 100644
--- a/hw/xfree86/dri2/dri2ext.c
+++ b/hw/xfree86/dri2/dri2ext.c
@@ -44,13 +44,15 @@
 #include "extnsionst.h"
 #include "xfixes.h"
 #include "dri2.h"
+#include "dri2int.h"
 #include "protocol-versions.h"
 
-/* The only xf86 include */
+/* The only xf86 includes */
 #include "xf86Module.h"
+#include "xf86Extensions.h"
+
+static int DRI2EventBase;
 
-static ExtensionEntry *dri2Extension;
-extern Bool DRI2ModuleSetup(void);
 
 static Bool
 validDrawable(ClientPtr client, XID drawable, Mask access_mode,
@@ -664,11 +666,11 @@ SProcDRI2Dispatch(ClientPtr client)
     }
 }
 
-int DRI2EventBase;
-
-static void
+void
 DRI2ExtensionInit(void)
 {
+    ExtensionEntry *dri2Extension;
+
     dri2Extension = AddExtension(DRI2_NAME,
                                  DRI2NumberEvents,
                                  DRI2NumberErrors,
@@ -679,13 +681,3 @@ DRI2ExtensionInit(void)
 
     DRI2ModuleSetup();
 }
-
-extern Bool noDRI2Extension;
-
-_X_HIDDEN ExtensionModule dri2ExtensionModule = {
-    DRI2ExtensionInit,
-    DRI2_NAME,
-    &noDRI2Extension,
-    NULL,
-    NULL
-};
diff --git a/hw/xfree86/dri2/dri2int.h b/hw/xfree86/dri2/dri2int.h
new file mode 100644
index 0000000..7f53eba
--- /dev/null
+++ b/hw/xfree86/dri2/dri2int.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright © 2011 Daniel Stone
+ *
+ * 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, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Author: Daniel Stone <daniel at fooishbar.org>
+ */
+
+extern Bool DRI2ModuleSetup(void);
diff --git a/hw/xfree86/loader/Makefile.am b/hw/xfree86/loader/Makefile.am
index 6605042..d6ddbec 100644
--- a/hw/xfree86/loader/Makefile.am
+++ b/hw/xfree86/loader/Makefile.am
@@ -2,7 +2,7 @@ noinst_LTLIBRARIES = libloader.la
 
 INCLUDES = $(XORG_INCS) -I$(srcdir)/../parser -I$(top_srcdir)/miext/cw \
 	   -I$(srcdir)/../ddc -I$(srcdir)/../i2c -I$(srcdir)/../modes \
-	   -I$(srcdir)/../ramdac -I$(srcdir)/../dri
+	   -I$(srcdir)/../ramdac -I$(srcdir)/../dri -I$(srcdir)/../dri2
 
 #AM_LDFLAGS = -r
 AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 1ef8791..2347b8e 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -837,6 +837,7 @@ static const char *compiled_in_modules[] = {
     "record",
     "extmod",
     "dri",
+    "dri2",
     NULL
 };
 
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index d8a7efb..420640f 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -93,11 +93,9 @@ cat > sdksyms.c << EOF
 
 
 /* hw/xfree86/dri2/Makefile.am -- module */
-/*
 #if DRI2
 # include "dri2.h"
 #endif
- */
 
 
 /* hw/xfree86/vgahw/Makefile.am -- module */
diff --git a/test/Makefile.am b/test/Makefile.am
index b388888..aa018c9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -18,7 +18,8 @@ if XORG
 INCLUDES += -I$(top_srcdir)/hw/xfree86/parser \
 	-I$(top_srcdir)/hw/xfree86/ddc \
 	-I$(top_srcdir)/hw/xfree86/i2c -I$(top_srcdir)/hw/xfree86/modes \
-	-I$(top_srcdir)/hw/xfree86/ramdac -I$(top_srcdir)/hw/xfree86/dri
+	-I$(top_srcdir)/hw/xfree86/ramdac -I$(top_srcdir)/hw/xfree86/dri \
+	-I$(top_srcdir)/hw/xfree86/dri2
 endif
 TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) $(GLX_SYS_LIBS)
 
@@ -61,6 +62,10 @@ if DRI
 libxservertest_la_LIBADD += $(top_builddir)/hw/xfree86/dri/libdri.la
 endif
 
+if DRI2
+libxservertest_la_LIBADD += $(top_builddir)/hw/xfree86/dri2/libdri2.la
+endif
+
 else
 nodist_libxservertest_la_SOURCES = \
             ddxstubs.c \
commit b8a3267c36e2e335b888bd4f2ef2f2c477cdfdce
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:17 2012 +0100

    DRI2: Remove prototype for DRI2DestroyDrawable
    
    DRI2DestroyDrawable() was still being _X_EXPORTed, but hasn't existed
    since 1da1f33f last year.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/dri2/dri2.h b/hw/xfree86/dri2/dri2.h
index a59e680..28f2d75 100644
--- a/hw/xfree86/dri2/dri2.h
+++ b/hw/xfree86/dri2/dri2.h
@@ -276,8 +276,6 @@ extern _X_EXPORT int DRI2CreateDrawable(ClientPtr client,
                                         DRI2InvalidateProcPtr invalidate,
                                         void *priv);
 
-extern _X_EXPORT void DRI2DestroyDrawable(DrawablePtr pDraw);
-
 extern _X_EXPORT DRI2BufferPtr *DRI2GetBuffers(DrawablePtr pDraw,
                                                int *width,
                                                int *height,
commit 7025a909bfe4d1f5518ec6fc5f89e2c3fb6501fd
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:16 2012 +0100

    XFree86: DRI: Don't use per-target CFLAGS
    
    AM_CFLAGS will suffice, given we only have one target in this directory.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Cyril Brulebois <kibi at debian.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/dri/Makefile.am b/hw/xfree86/dri/Makefile.am
index 7c2026f..ced04ff 100644
--- a/hw/xfree86/dri/Makefile.am
+++ b/hw/xfree86/dri/Makefile.am
@@ -1,15 +1,15 @@
 noinst_LTLIBRARIES = libdri.la
-libdri_la_CFLAGS = -I$(top_srcdir)/hw/xfree86/common \
-                   -I$(top_srcdir)/hw/xfree86/os-support \
-                   -I$(top_srcdir)/hw/xfree86/modes \
-                   -I$(top_srcdir)/hw/xfree86/ddc \
-                   -I$(top_srcdir)/hw/xfree86/i2c \
-                   -I$(top_srcdir)/hw/xfree86/parser \
-                   -I$(top_srcdir)/hw/xfree86/ramdac \
-                   -I$(top_srcdir)/hw/xfree86/os-support/bus \
-                   -I$(top_srcdir)/glx \
-                   -DHAVE_XORG_CONFIG_H \
-                   @DIX_CFLAGS@ @XORG_CFLAGS@
+AM_CFLAGS = -I$(top_srcdir)/hw/xfree86/common \
+            -I$(top_srcdir)/hw/xfree86/os-support \
+            -I$(top_srcdir)/hw/xfree86/modes \
+            -I$(top_srcdir)/hw/xfree86/ddc \
+            -I$(top_srcdir)/hw/xfree86/i2c \
+            -I$(top_srcdir)/hw/xfree86/parser \
+            -I$(top_srcdir)/hw/xfree86/ramdac \
+            -I$(top_srcdir)/hw/xfree86/os-support/bus \
+            -I$(top_srcdir)/glx \
+            -DHAVE_XORG_CONFIG_H \
+            @DIX_CFLAGS@ @XORG_CFLAGS@
 libdri_la_SOURCES = \
 	dri.c \
 	dri.h \
commit 459c6da0f907ba33d733c7e62a116184ba2f14e5
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:15 2012 +0100

    Move DRI1 from external module to built-in
    
    Rather than building the tiny amount of code required for XFree86-DRI as
    an external module, build it in if it's enabled at configure time.
    
    v2: Fix test/Makefile.am to only link libdri.la if DRI is set
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>
    
    fixup for DRI1 move
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index beeb5fd..b225632 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1087,9 +1087,8 @@ AC_SUBST([GLX_SYS_LIBS])
 AM_CONDITIONAL(DRI, test "x$DRI" = xyes)
 if test "x$DRI" = xyes; then
 	AC_DEFINE(XF86DRI, 1, [Build DRI extension])
-	PKG_CHECK_MODULES([DRIPROTO], [$DRIPROTO])
-	PKG_CHECK_MODULES([DRI], $GLPROTO $LIBDRI)
-	AC_SUBST(DRIPROTO_CFLAGS)
+	REQUIRED_MODULES="$REQUIRED_MODULES $DRIPROTO $GLPROTO $LIBDRI"
+	SDK_REQUIRED_MODULES="$SDK_REQUIRED_MODULES $DRIPROTO $GLPROTO $LIBDRI"
 fi
 
 PKG_CHECK_MODULES([DRI2PROTO], $DRI2PROTO,
@@ -1659,7 +1658,7 @@ if test "x$XORG" = xyes; then
 	PKG_CHECK_MODULES([PCIACCESS], $LIBPCIACCESS)
 	SDK_REQUIRED_MODULES="$SDK_REQUIRED_MODULES $LIBPCIACCESS"
 	XORG_SYS_LIBS="$XORG_SYS_LIBS $PCIACCESS_LIBS $GLX_SYS_LIBS $LIBDRM_LIBS"
-	XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
+	XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS $LIBDRM_CFLAGS"
 
 	AC_DEFINE(XSERVER_LIBPCIACCESS, 1, [Use libpciaccess for all pci manipulation])
 	AC_DEFINE_DIR(PCI_TXT_IDS_PATH, PCI_TXT_IDS_DIR, [Default PCI text file ID path])
diff --git a/glx/Makefile.am b/glx/Makefile.am
index ced78b7..591c4ac 100644
--- a/glx/Makefile.am
+++ b/glx/Makefile.am
@@ -7,10 +7,8 @@ noinst_LTLIBRARIES = libglx.la $(GLXDRI_LIBRARY)
 AM_CFLAGS = \
 	@DIX_CFLAGS@ \
 	@GL_CFLAGS@ \
-	@DRI_CFLAGS@ \
 	@XLIB_CFLAGS@ \
 	@LIBDRM_CFLAGS@ \
-	@DRIPROTO_CFLAGS@ \
 	@GLX_DEFINES@ \
 	@GLX_ARCH_DEFINES@
 
diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index 9d9b64e..2e0613a 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -5,7 +5,6 @@ INCLUDES = 			\
 	@KDRIVE_CFLAGS@		\
 	@XEPHYR_INCS@		\
 	@XEPHYR_CFLAGS@		\
-	@DRIPROTO_CFLAGS@	\
 	-I$(top_srcdir)		\
 	-I$(top_srcdir)/exa
 
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index f74691b..0c3801d 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -1,6 +1,7 @@
 
 if DRI
 DRI_SUBDIR = dri
+DRI_LIB = dri/libdri.la
 endif
 
 if DRI2
@@ -26,8 +27,8 @@ INT10_SUBDIR = int10
 endif
 
 SUBDIRS = common ddc x86emu $(INT10_SUBDIR) os-support parser \
-	  ramdac $(VGAHW_SUBDIR) loader modes . $(VBE_SUBDIR) \
-	  $(XAA_SUBDIR) $(DRI_SUBDIR) $(DRI2_SUBDIR) i2c dixmods \
+	  ramdac $(VGAHW_SUBDIR) loader modes $(DRI_SUBDIR) . \
+	  $(VBE_SUBDIR) $(XAA_SUBDIR) $(DRI2_SUBDIR) i2c dixmods \
 	  fbdevhw shadowfb exa $(XF86UTILS_SUBDIR) doc man
 
 DIST_SUBDIRS = common ddc i2c x86emu int10 fbdevhw os-support \
@@ -40,7 +41,8 @@ nodist_Xorg_SOURCES = sdksyms.c
 
 AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
 INCLUDES = $(XORG_INCS) -I$(srcdir)/parser -I$(top_srcdir)/miext/cw \
-	-I$(srcdir)/ddc -I$(srcdir)/i2c -I$(srcdir)/modes -I$(srcdir)/ramdac
+	-I$(srcdir)/ddc -I$(srcdir)/i2c -I$(srcdir)/modes -I$(srcdir)/ramdac \
+	-I$(srcdir)/dri
 
 LOCAL_LIBS = \
             $(MAIN_LIB) \
@@ -56,6 +58,7 @@ LOCAL_LIBS = \
             i2c/libi2c.la \
             $(XORG_LIBS) \
             dixmods/libxorgxkb.la \
+            $(DRI_LIB) \
             $(top_builddir)/mi/libmi.la \
             $(top_builddir)/os/libos.la
 Xorg_LDADD = \
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index a701d87..0dbfa98 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -112,9 +112,6 @@ static ModuleDefault ModuleDefaults[] = {
 #ifdef GLXEXT
     {.name = "glx",.toLoad = TRUE,.load_opt = NULL},
 #endif
-#ifdef XF86DRI
-    {.name = "dri",.toLoad = TRUE,.load_opt = NULL},
-#endif
 #ifdef DRI2
     {.name = "dri2",.toLoad = TRUE,.load_opt = NULL},
 #endif
diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c
index 63950e6..b38ecf2 100644
--- a/hw/xfree86/common/xf86Extensions.c
+++ b/hw/xfree86/common/xf86Extensions.c
@@ -72,6 +72,15 @@ static ExtensionModule extensionModules[] = {
 	NULL
     },
 #endif
+#ifdef XF86DRI
+    {
+        XFree86DRIExtensionInit,
+        "XFree86-DRI",
+        &noXFree86DRIExtension,
+        NULL,
+        NULL
+    },
+#endif
 };
 
 static void
diff --git a/hw/xfree86/dri/Makefile.am b/hw/xfree86/dri/Makefile.am
index 9528d53..7c2026f 100644
--- a/hw/xfree86/dri/Makefile.am
+++ b/hw/xfree86/dri/Makefile.am
@@ -1,4 +1,4 @@
-libdri_la_LTLIBRARIES = libdri.la
+noinst_LTLIBRARIES = libdri.la
 libdri_la_CFLAGS = -I$(top_srcdir)/hw/xfree86/common \
                    -I$(top_srcdir)/hw/xfree86/os-support \
                    -I$(top_srcdir)/hw/xfree86/modes \
@@ -9,16 +9,10 @@ libdri_la_CFLAGS = -I$(top_srcdir)/hw/xfree86/common \
                    -I$(top_srcdir)/hw/xfree86/os-support/bus \
                    -I$(top_srcdir)/glx \
                    -DHAVE_XORG_CONFIG_H \
-                   @DIX_CFLAGS@ @XORG_CFLAGS@ @DRIPROTO_CFLAGS@ \
-                   @LIBDRM_CFLAGS@ \
-                   @DRI_CFLAGS@
-libdri_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-libdri_la_LIBADD = @LIBDRM_LIBS@ $(PIXMAN_LIBS)
-libdri_ladir = $(moduledir)/extensions
+                   @DIX_CFLAGS@ @XORG_CFLAGS@
 libdri_la_SOURCES = \
 	dri.c \
 	dri.h \
-	drimodule.c \
 	dristruct.h \
 	sarea.h \
 	xf86dri.c
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index a3e7870..398178e 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -791,6 +791,8 @@ DRIExtensionInit(void)
 
     RegisterBlockAndWakeupHandlers(DRIBlockHandler, DRIWakeupHandler, NULL);
 
+    drmSetServerInfo(&DRIDRMServerInfo);
+
     return TRUE;
 }
 
diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h
index 0a4036c..4bfaf16 100644
--- a/hw/xfree86/dri/dri.h
+++ b/hw/xfree86/dri/dri.h
@@ -197,7 +197,7 @@ extern _X_EXPORT Bool DRIScreenInit(ScreenPtr pScreen,
 
 extern _X_EXPORT void DRICloseScreen(ScreenPtr pScreen);
 
-extern _X_EXPORT Bool DRIExtensionInit(void);
+extern Bool DRIExtensionInit(void);
 
 extern _X_EXPORT void DRIReset(void);
 
diff --git a/hw/xfree86/dri/drimodule.c b/hw/xfree86/dri/drimodule.c
deleted file mode 100644
index 6cb3bfb..0000000
--- a/hw/xfree86/dri/drimodule.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/**************************************************************************
-
-Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
-All Rights Reserved.
-
-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, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) 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 NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
-
-**************************************************************************/
-
-/*
- * Authors:
- *   Kevin E. Martin <kevin at precisioninsight.com>
- *   Rickard E. Faith <faith at precisioninsight.com>
- *
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-#include "xf86Extensions.h"
-#include "globals.h"
-
-#include "xf86drm.h"
-static MODULESETUPPROTO(driSetup);
-
-drmServerInfo DRIDRMServerInfo;
-
-static XF86ModuleVersionInfo VersRec = {
-    "dri",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_EXTENSION,
-    ABI_EXTENSION_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-#define _XF86DRI_SERVER_
-#include <X11/dri/xf86driproto.h>
-
-static ExtensionModule XF86DRIExt = {
-    XFree86DRIExtensionInit,
-    XF86DRINAME,
-    &noXFree86DRIExtension,
-    NULL,
-    NULL
-};
-
-_X_EXPORT XF86ModuleData driModuleData = { &VersRec, driSetup, NULL };
-
-static pointer
-driSetup(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    static Bool setupDone = FALSE;
-
-    if (!setupDone) {
-        setupDone = TRUE;
-        LoadExtension(&XF86DRIExt, FALSE);
-    }
-    else {
-        if (errmaj)
-            *errmaj = LDR_ONCEONLY;
-    }
-
-    drmSetServerInfo(&DRIDRMServerInfo);
-
-    /* Need a non-NULL return value to indicate success */
-    return (pointer) 1;
-}
diff --git a/hw/xfree86/dri2/Makefile.am b/hw/xfree86/dri2/Makefile.am
index 390ed12..ad3419b 100644
--- a/hw/xfree86/dri2/Makefile.am
+++ b/hw/xfree86/dri2/Makefile.am
@@ -1,7 +1,6 @@
 libdri2_la_LTLIBRARIES = libdri2.la
 libdri2_la_CFLAGS = \
 	-DHAVE_XORG_CONFIG_H \
-	@DRI_CFLAGS@ \
 	@DIX_CFLAGS@ @XORG_CFLAGS@ @DRI2PROTO_CFLAGS@ @LIBDRM_CFLAGS@ \
 	-I$(top_srcdir)/hw/xfree86/common \
 	-I$(top_srcdir)/hw/xfree86/os-support/bus
diff --git a/hw/xfree86/loader/Makefile.am b/hw/xfree86/loader/Makefile.am
index ebe0c81..6605042 100644
--- a/hw/xfree86/loader/Makefile.am
+++ b/hw/xfree86/loader/Makefile.am
@@ -2,7 +2,7 @@ noinst_LTLIBRARIES = libloader.la
 
 INCLUDES = $(XORG_INCS) -I$(srcdir)/../parser -I$(top_srcdir)/miext/cw \
 	   -I$(srcdir)/../ddc -I$(srcdir)/../i2c -I$(srcdir)/../modes \
-	   -I$(srcdir)/../ramdac
+	   -I$(srcdir)/../ramdac -I$(srcdir)/../dri
 
 #AM_LDFLAGS = -r
 AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 1ec4ff0..1ef8791 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -836,6 +836,7 @@ static const char *compiled_in_modules[] = {
     "dbe",
     "record",
     "extmod",
+    "dri",
     NULL
 };
 
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index f3d7640..d8a7efb 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -203,13 +203,11 @@ cat > sdksyms.c << EOF
 
 
 /* hw/xfree86/dri/Makefile.am -- module */
-/*
 #if XF86DRI
 # include "dri.h"
 # include "sarea.h"
 # include "dristruct.h"
 #endif
- */
 
 
 /* mi/Makefile.am */
diff --git a/test/Makefile.am b/test/Makefile.am
index 15c51ed..b388888 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -18,7 +18,7 @@ if XORG
 INCLUDES += -I$(top_srcdir)/hw/xfree86/parser \
 	-I$(top_srcdir)/hw/xfree86/ddc \
 	-I$(top_srcdir)/hw/xfree86/i2c -I$(top_srcdir)/hw/xfree86/modes \
-	-I$(top_srcdir)/hw/xfree86/ramdac
+	-I$(top_srcdir)/hw/xfree86/ramdac -I$(top_srcdir)/hw/xfree86/dri
 endif
 TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) $(GLX_SYS_LIBS)
 
@@ -42,6 +42,7 @@ os_LDADD=$(TEST_LDADD)
 
 libxservertest_la_LIBADD = $(XSERVER_LIBS)
 if XORG
+
 nodist_libxservertest_la_SOURCES = $(top_builddir)/hw/xfree86/sdksyms.c
 libxservertest_la_LIBADD += \
             $(top_builddir)/hw/xfree86/loader/libloader.la \
@@ -56,6 +57,10 @@ libxservertest_la_LIBADD += \
             $(top_builddir)/hw/xfree86/dixmods/libxorgxkb.la \
             @XORG_LIBS@
 
+if DRI
+libxservertest_la_LIBADD += $(top_builddir)/hw/xfree86/dri/libdri.la
+endif
+
 else
 nodist_libxservertest_la_SOURCES = \
             ddxstubs.c \
commit b905d87ba0a9b045ea41bb1ad36a4f9f1170a1b8
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:14 2012 +0100

    Xext: Only build one library
    
    Now that libXextmodule.la is both empty and unused, we can just build
    the one libXext.la for everyone, rather than having Xorg be special and
    unique.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 0420951..8e31f13 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -1,14 +1,4 @@
-# libXext.la:        includes all extensions and should be linked into Xvfb,
-#                    Xnest, Xdmx and Xprt
-# libXextbuiltin.la: includes those extensions that are built directly into
-#                    Xorg by default
-# libXextmodule.la:  includes those extensions that are built into a module
-#                    that Xorg loads
-if XORG
-noinst_LTLIBRARIES = libXext.la libXextbuiltin.la libXextmodule.la
-else
 noinst_LTLIBRARIES = libXext.la
-endif
 
 AM_CFLAGS = $(DIX_CFLAGS)
 
@@ -30,10 +20,6 @@ BUILTIN_SRCS =			\
 	xtest.c
 BUILTIN_LIBS =
 
-# Sources always included in libXextmodule.la & libXext.la. That's right, zero.
-MODULE_SRCS =
-MODULE_LIBS =
-
 # Optional sources included if extension enabled by configure.ac rules
 
 # MIT Shared Memory extension
@@ -107,16 +93,8 @@ endif
 
 # Now take all of the above, mix well, bake for 10 minutes and get libXext*.la
 
-libXext_la_SOURCES =		$(BUILTIN_SRCS) $(MODULE_SRCS)
-libXext_la_LIBADD =		$(BUILTIN_LIBS) $(MODULE_LIBS)
-
-if XORG
-libXextbuiltin_la_SOURCES =	$(BUILTIN_SRCS)
-libXextbuiltin_la_LIBADD = 	$(BUILTIN_LIBS)
-
-libXextmodule_la_SOURCES =	$(MODULE_SRCS)
-libXextmodule_la_LIBADD =	$(MODULE_LIBS)
-endif
+libXext_la_SOURCES =		$(BUILTIN_SRCS)
+libXext_la_LIBADD =		$(BUILTIN_LIBS)
 
 EXTRA_DIST = \
 	$(MITSHM_SRCS) \
diff --git a/configure.ac b/configure.ac
index 14459d6..beeb5fd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -766,7 +766,6 @@ dnl Extension section
 dnl ---------------------------------------------------------------------------
 XEXT_INC='-I$(top_srcdir)/Xext'
 XEXT_LIB='$(top_builddir)/Xext/libXext.la'
-XEXTXORG_LIB='$(top_builddir)/Xext/libXextbuiltin.la'
 
 dnl Optional modules
 VIDEOPROTO="videoproto"
@@ -1605,7 +1604,7 @@ if test "x$XORG" = xyes; then
 	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
 	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
 	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
-	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $XI_LIB $XKB_LIB"
+	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $XI_LIB $XKB_LIB"
 
 	dnl ==================================================================
 	dnl symbol visibility
commit a7a2f9f66ddc27df96557093f3dd266e24eb653b
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:13 2012 +0100

    Remove the last remnants of extmod
    
    extmod was originally a big pointless module.  Now it's an empty,
    pointless module.  This commit makes it unexist.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 957fa67..0420951 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -10,8 +10,6 @@ else
 noinst_LTLIBRARIES = libXext.la
 endif
 
-INCLUDES = -I$(top_srcdir)/hw/xfree86/dixmods/extmod
-
 AM_CFLAGS = $(DIX_CFLAGS)
 
 if XORG
diff --git a/configure.ac b/configure.ac
index fc5e2d9..14459d6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2244,7 +2244,6 @@ hw/xfree86/common/Makefile
 hw/xfree86/common/xf86Build.h
 hw/xfree86/ddc/Makefile
 hw/xfree86/dixmods/Makefile
-hw/xfree86/dixmods/extmod/Makefile
 hw/xfree86/doc/Makefile
 hw/xfree86/dri/Makefile
 hw/xfree86/dri2/Makefile
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 7b68e35..a701d87 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -109,7 +109,6 @@
 #endif
 
 static ModuleDefault ModuleDefaults[] = {
-    {.name = "extmod",.toLoad = TRUE,.load_opt = NULL},
 #ifdef GLXEXT
     {.name = "glx",.toLoad = TRUE,.load_opt = NULL},
 #endif
diff --git a/hw/xfree86/dixmods/Makefile.am b/hw/xfree86/dixmods/Makefile.am
index 3aa7d27..1ad122a 100644
--- a/hw/xfree86/dixmods/Makefile.am
+++ b/hw/xfree86/dixmods/Makefile.am
@@ -1,7 +1,5 @@
 noinst_LTLIBRARIES = libdixmods.la libxorgxkb.la
 
-SUBDIRS = extmod
-
 if GLX
 GLXMODS = libglx.la
 endif
diff --git a/hw/xfree86/dixmods/extmod/Makefile.am b/hw/xfree86/dixmods/extmod/Makefile.am
deleted file mode 100644
index d5e0cde..0000000
--- a/hw/xfree86/dixmods/extmod/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-extsmoduledir = $(moduledir)/extensions
-extsmodule_LTLIBRARIES = libextmod.la
-
-AM_CFLAGS = @DIX_CFLAGS@ @XORG_CFLAGS@
-INCLUDES = @XORG_INCS@ \
-           -I$(top_srcdir)/dbe \
-           -I$(top_srcdir)/hw/xfree86/loader \
-           -I$(top_srcdir)/miext/shadow
-
-libextmod_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-libextmod_la_SOURCES = modinit.c
-libextmod_la_LIBADD = $(top_builddir)/Xext/libXextmodule.la
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
deleted file mode 100644
index 74171cf..0000000
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (c) 1997 Matthieu Herrb
- *
- * 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 Matthieu Herrb not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Matthieu Herrb makes no
- * representations about the suitability of this software for any purpose.
- *  It is provided "as is" without express or implied warranty.
- *
- * MATTHIEU HERRB DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL MATTHIEU HERRB 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_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-#include "xf86Opt.h"
-
-#include <X11/Xproto.h>
-
-#include "extinit.h"
-#include "xf86Extensions.h"
-#include "globals.h"
-
-static MODULESETUPPROTO(extmodSetup);
-
-/*
- * Array describing extensions to be initialized
- */
-static ExtensionModule extensionModules[] = {
-};
-
-static XF86ModuleVersionInfo VersRec = {
-    "extmod",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_EXTENSION,
-    ABI_EXTENSION_VERSION,
-    MOD_CLASS_EXTENSION,
-    {0, 0, 0, 0}
-};
-
-/*
- * Data for the loader
- */
-_X_EXPORT XF86ModuleData extmodModuleData = { &VersRec, extmodSetup, NULL };
-
-static pointer
-extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    int i;
-
-    for (i = 0; i < ARRAY_SIZE(extensionModules); i++)
-	LoadExtension(&extensionModules[i], FALSE);
-
-    /* Need a non-NULL return */
-    return (pointer) 1;
-}
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 9ce5813..1ec4ff0 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -835,6 +835,7 @@ static const char *compiled_in_modules[] = {
     "ramdac",
     "dbe",
     "record",
+    "extmod",
     NULL
 };
 
commit 6e74fdda42fb4bd80fd48e1ae6471bffbb837804
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Jun 22 00:28:18 2011 +0100

    Move XFree86-VidMode from extmod to built-in
    
    As with DGA, move VidMode from being part of extmod to a built-in part
    of the server, if compiled as such.  This is initialised from
    xf86ExtensionInit rather than miinitext because it's wholly dependent on
    the Xorg DDX.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index ea98449..cb6d0d4 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -47,7 +47,7 @@ libcommon_la_SOURCES = xf86Configure.c xf86Bus.c xf86Config.c \
                       xf86VidMode.c xf86fbman.c xf86cmap.c \
                       xf86Helper.c xf86PM.c xf86Xinput.c xisb.c \
                       xf86Mode.c xorgHelper.c xf86Extensions.h \
-		      xf86Extensions.c \
+		      xf86Extensions.c xf86vmode.c \
                       $(XVSOURCES) $(BUSSOURCES) $(RANDRSOURCES)
 nodist_libcommon_la_SOURCES = xf86DefModeSet.c xf86Build.h
 libcommon_la_LIBADD = $(top_builddir)/config/libconfig.la
diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c
index 5ee6be8..63950e6 100644
--- a/hw/xfree86/common/xf86Extensions.c
+++ b/hw/xfree86/common/xf86Extensions.c
@@ -45,10 +45,24 @@
 #include <X11/extensions/xf86dgaproto.h>
 #endif
 
+#ifdef XF86VIDMODE
+#include <X11/extensions/xf86vmproto.h>
+#include "vidmodeproc.h"
+#endif
+
 /*
  * DDX-specific extensions.
  */
 static ExtensionModule extensionModules[] = {
+#ifdef XF86VIDMODE
+    {
+	XFree86VidModeExtensionInit,
+	XF86VIDMODENAME,
+	&noXFree86VidModeExtension,
+	NULL,
+	NULL
+    },
+#endif
 #ifdef XFreeXDGA
     {
 	XFree86DGAExtensionInit,
diff --git a/hw/xfree86/common/xf86vmode.c b/hw/xfree86/common/xf86vmode.c
new file mode 100644
index 0000000..7cd2eed
--- /dev/null
+++ b/hw/xfree86/common/xf86vmode.c
@@ -0,0 +1,2165 @@
+
+/*
+
+Copyright 1995  Kaleb S. KEITHLEY
+
+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, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+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 Kaleb S. KEITHLEY 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 Kaleb S. KEITHLEY 
+shall not be used in advertising or otherwise to promote the sale, use 
+or other dealings in this Software without prior written authorization
+from Kaleb S. KEITHLEY
+
+*/
+/* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "xf86Extensions.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+#include <X11/extensions/xf86vmproto.h>
+#include "swaprep.h"
+#include "xf86.h"
+#include "vidmodeproc.h"
+#include "globals.h"
+#include "protocol-versions.h"
+
+#define DEFAULT_XF86VIDMODE_VERBOSITY	3
+
+static int VidModeErrorBase;
+static DevPrivateKeyRec VidModeClientPrivateKeyRec;
+
+#define VidModeClientPrivateKey (&VidModeClientPrivateKeyRec)
+
+/* This holds the client's version information */
+typedef struct {
+    int major;
+    int minor;
+} VidModePrivRec, *VidModePrivPtr;
+
+#define VM_GETPRIV(c) ((VidModePrivPtr) \
+    dixLookupPrivate(&(c)->devPrivates, VidModeClientPrivateKey))
+#define VM_SETPRIV(c,p) \
+    dixSetPrivate(&(c)->devPrivates, VidModeClientPrivateKey, p)
+
+#if 0
+static unsigned char XF86VidModeReqCode = 0;
+#endif
+
+/* The XF86VIDMODE_EVENTS code is far from complete */
+
+#ifdef XF86VIDMODE_EVENTS
+static int XF86VidModeEventBase = 0;
+
+static void SXF86VidModeNotifyEvent(xXF86VidModeNotifyEvent * /* from */ , xXF86VidModeNotifyEvent *    /* to */
+    );
+
+static RESTYPE EventType;       /* resource type for event masks */
+
+typedef struct _XF86VidModeEvent *XF86VidModeEventPtr;
+
+typedef struct _XF86VidModeEvent {
+    XF86VidModeEventPtr next;
+    ClientPtr client;
+    ScreenPtr screen;
+    XID resource;
+    CARD32 mask;
+} XF86VidModeEventRec;
+
+static int XF86VidModeFreeEvents();
+
+typedef struct _XF86VidModeScreenPrivate {
+    XF86VidModeEventPtr events;
+    Bool hasWindow;
+} XF86VidModeScreenPrivateRec, *XF86VidModeScreenPrivatePtr;
+
+static DevPrivateKeyRec ScreenPrivateKeyRec;
+
+#define ScreenPrivateKey (&ScreenPrivateKeyRec)
+
+#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \
+    dixLookupPrivate(&(s)->devPrivates, ScreenPrivateKey))
+#define SetScreenPrivate(s,v) \
+    dixSetPrivate(&(s)->devPrivates, ScreenPrivateKey, v)
+#define SetupScreen(s)  ScreenSaverScreenPrivatePtr pPriv = GetScreenPrivate(s)
+
+#define New(t)  (malloc(sizeof (t)))
+#endif
+
+#ifdef DEBUG
+#define DEBUG_P(x) ErrorF(x"\n");
+#else
+#define DEBUG_P(x) /**/
+#endif
+    static int
+ClientMajorVersion(ClientPtr client)
+{
+    VidModePrivPtr pPriv;
+
+    pPriv = VM_GETPRIV(client);
+    if (!pPriv)
+        return 0;
+    else
+        return pPriv->major;
+}
+
+#ifdef XF86VIDMODE_EVENTS
+static void
+CheckScreenPrivate(pScreen)
+ScreenPtr
+ pScreen;
+{
+    SetupScreen(pScreen);
+
+    if (!pPriv)
+        return;
+    if (!pPriv->events && !pPriv->hasWindow) {
+        free(pPriv);
+        SetScreenPrivate(pScreen, NULL);
+    }
+}
+
+static XF86VidModeScreenPrivatePtr
+MakeScreenPrivate(pScreen)
+ScreenPtr
+ pScreen;
+{
+    SetupScreen(pScreen);
+
+    if (pPriv)
+        return pPriv;
+    pPriv = New(XF86VidModeScreenPrivateRec);
+    if (!pPriv)
+        return 0;
+    pPriv->events = 0;
+    pPriv->hasWindow = FALSE;
+    SetScreenPrivate(pScreen, pPriv);
+    return pPriv;
+}
+
+static unsigned long
+getEventMask(ScreenPtr pScreen, ClientPtr client)
+{
+    SetupScreen(pScreen);
+    XF86VidModeEventPtr pEv;
+
+    if (!pPriv)
+        return 0;
+    for (pEv = pPriv->events; pEv; pEv = pEv->next)
+        if (pEv->client == client)
+            return pEv->mask;
+    return 0;
+}
+
+static Bool
+setEventMask(ScreenPtr pScreen, ClientPtr client, unsigned long mask)
+{
+    SetupScreen(pScreen);
+    XF86VidModeEventPtr pEv, *pPrev;
+
+    if (getEventMask(pScreen, client) == mask)
+        return TRUE;
+    if (!pPriv) {
+        pPriv = MakeScreenPrivate(pScreen);
+        if (!pPriv)
+            return FALSE;
+    }
+    for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
+        if (pEv->client == client)
+            break;
+    if (mask == 0) {
+        *pPrev = pEv->next;
+        free(pEv);
+        CheckScreenPrivate(pScreen);
+    }
+    else {
+        if (!pEv) {
+            pEv = New(ScreenSaverEventRec);
+            if (!pEv) {
+                CheckScreenPrivate(pScreen);
+                return FALSE;
+            }
+            *pPrev = pEv;
+            pEv->next = NULL;
+            pEv->client = client;
+            pEv->screen = pScreen;
+            pEv->resource = FakeClientID(client->index);
+        }
+        pEv->mask = mask;
+    }
+    return TRUE;
+}
+
+static int
+XF86VidModeFreeEvents(pointer value, XID id)
+{
+    XF86VidModeEventPtr pOld = (XF86VidModeEventPtr) value;
+    ScreenPtr pScreen = pOld->screen;
+
+    SetupScreen(pScreen);
+    XF86VidModeEventPtr pEv, *pPrev;
+
+    if (!pPriv)
+        return TRUE;
+    for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
+        if (pEv == pOld)
+            break;
+    if (!pEv)
+        return TRUE;
+    *pPrev = pEv->next;
+    free(pEv);
+    CheckScreenPrivate(pScreen);
+    return TRUE;
+}
+
+static void
+SendXF86VidModeNotify(ScreenPtr pScreen, int state, Bool forced)
+{
+    XF86VidModeScreenPrivatePtr pPriv;
+    unsigned long mask;
+    xXF86VidModeNotifyEvent ev;
+    int kind;
+
+    UpdateCurrentTimeIf();
+    mask = XF86VidModeNotifyMask;
+    pScreen = screenInfo.screens[pScreen->myNum];
+    pPriv = GetScreenPrivate(pScreen);
+    if (!pPriv)
+        return;
+    kind = XF86VidModeModeChange;
+    for (pEv = pPriv->events; pEv; pEv = pEv->next) {
+        if (pEv->mask & mask) {
+            XF86VidModeEventPtr pEv = {
+                .type = XF86VidModeNotify + XF86VidModeEventBase,
+                .state = state,
+                .timestamp = currentTime.milliseconds,
+                .root = pScreen->root->drawable.id,
+                .kind = kind,
+                .forced = forced
+            };
+            WriteEventsToClient(pEv->client, 1, (xEvent *) &ev);
+        }
+    }
+}
+
+static void
+SXF86VidModeNotifyEvent(xXF86VidModeNotifyEvent * from,
+                        xXF86VidModeNotifyEvent * to)
+{
+    to->type = from->type;
+    to->state = from->state;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->timestamp, to->timestamp);
+    cpswapl(from->root, to->root);
+    to->kind = from->kind;
+    to->forced = from->forced;
+}
+#endif
+
+static int
+ProcXF86VidModeQueryVersion(ClientPtr client)
+{
+    xXF86VidModeQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_XF86VIDMODE_MAJOR_VERSION,
+        .minorVersion = SERVER_XF86VIDMODE_MINOR_VERSION
+    };
+
+    DEBUG_P("XF86VidModeQueryVersion");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeQueryVersionReq);
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swaps(&rep.majorVersion);
+        swaps(&rep.minorVersion);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeQueryVersionReply), &rep);
+    return Success;
+}
+
+static int
+ProcXF86VidModeGetModeLine(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetModeLineReq);
+    xXF86VidModeGetModeLineReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence
+    };
+    pointer mode;
+    int dotClock;
+    int ver;
+
+    DEBUG_P("XF86VidModeGetModeline");
+
+    ver = ClientMajorVersion(client);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
+
+    if (ver < 2) {
+        rep.length = bytes_to_int32(SIZEOF(xXF86OldVidModeGetModeLineReply) -
+                                    SIZEOF(xGenericReply));
+    }
+    else {
+        rep.length = bytes_to_int32(SIZEOF(xXF86VidModeGetModeLineReply) -
+                                    SIZEOF(xGenericReply));
+    }
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
+        return BadValue;
+
+    rep.dotclock = dotClock;
+    rep.hdisplay = VidModeGetModeValue(mode, VIDMODE_H_DISPLAY);
+    rep.hsyncstart = VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART);
+    rep.hsyncend = VidModeGetModeValue(mode, VIDMODE_H_SYNCEND);
+    rep.htotal = VidModeGetModeValue(mode, VIDMODE_H_TOTAL);
+    rep.hskew = VidModeGetModeValue(mode, VIDMODE_H_SKEW);
+    rep.vdisplay = VidModeGetModeValue(mode, VIDMODE_V_DISPLAY);
+    rep.vsyncstart = VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART);
+    rep.vsyncend = VidModeGetModeValue(mode, VIDMODE_V_SYNCEND);
+    rep.vtotal = VidModeGetModeValue(mode, VIDMODE_V_TOTAL);
+    rep.flags = VidModeGetModeValue(mode, VIDMODE_FLAGS);
+
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+        ErrorF("GetModeLine - scrn: %d clock: %ld\n",
+               stuff->screen, (unsigned long) rep.dotclock);
+        ErrorF("GetModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               rep.hdisplay, rep.hsyncstart, rep.hsyncend, rep.htotal);
+        ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
+               rep.vdisplay, rep.vsyncstart, rep.vsyncend,
+               rep.vtotal, (unsigned long) rep.flags);
+    }
+
+    /*
+     * Older servers sometimes had server privates that the VidMode 
+     * extention made available. So to be compatiable pretend that
+     * there are no server privates to pass to the client
+     */
+    rep.privsize = 0;
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.dotclock);
+        swaps(&rep.hdisplay);
+        swaps(&rep.hsyncstart);
+        swaps(&rep.hsyncend);
+        swaps(&rep.htotal);
+        swaps(&rep.hskew);
+        swaps(&rep.vdisplay);
+        swaps(&rep.vsyncstart);
+        swaps(&rep.vsyncend);
+        swaps(&rep.vtotal);
+        swapl(&rep.flags);
+        swapl(&rep.privsize);
+    }
+    if (ver < 2) {
+        xXF86OldVidModeGetModeLineReply oldrep = {
+            .type = rep.type,
+            .sequenceNumber = rep.sequenceNumber,
+            .length = rep.length,
+            .dotclock = rep.dotclock,
+            .hdisplay = rep.hdisplay,
+            .hsyncstart = rep.hsyncstart,
+            .hsyncend = rep.hsyncend,
+            .htotal = rep.htotal,
+            .vdisplay = rep.vdisplay,
+            .vsyncstart = rep.vsyncstart,
+            .vsyncend = rep.vsyncend,
+            .vtotal = rep.vtotal,
+            .flags = rep.flags,
+            .privsize = rep.privsize
+        };
+        WriteToClient(client, sizeof(xXF86OldVidModeGetModeLineReply), &oldrep);
+    }
+    else {
+        WriteToClient(client, sizeof(xXF86VidModeGetModeLineReply), &rep);
+    }
+    return Success;
+}
+
+static int
+ProcXF86VidModeGetAllModeLines(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetAllModeLinesReq);
+    xXF86VidModeGetAllModeLinesReply rep;
+    pointer mode;
+    int modecount, dotClock;
+    int ver;
+
+    DEBUG_P("XF86VidModeGetAllModelines");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    ver = ClientMajorVersion(client);
+
+    modecount = VidModeGetNumOfModes(stuff->screen);
+    if (modecount < 1)
+        return VidModeErrorBase + XF86VidModeExtensionDisabled;
+
+    if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
+        return BadValue;
+
+    rep = (xXF86VidModeGetAllModeLinesReply) {
+        .type = X_Reply,
+        .length = SIZEOF(xXF86VidModeGetAllModeLinesReply) -
+            SIZEOF(xGenericReply),
+        .sequenceNumber = client->sequence,
+        .modecount = modecount
+    };
+    if (ver < 2)
+        rep.length += modecount * sizeof(xXF86OldVidModeModeInfo);
+    else
+        rep.length += modecount * sizeof(xXF86VidModeModeInfo);
+    rep.length >>= 2;
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.modecount);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeGetAllModeLinesReply), &rep);
+
+    do {
+        xXF86VidModeModeInfo mdinf = {
+            .dotclock = dotClock,
+            .hdisplay = VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
+            .hsyncstart = VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
+            .hsyncend = VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
+            .htotal = VidModeGetModeValue(mode, VIDMODE_H_TOTAL),
+            .hskew = VidModeGetModeValue(mode, VIDMODE_H_SKEW),
+            .vdisplay = VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
+            .vsyncstart = VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
+            .vsyncend = VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
+            .vtotal = VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
+            .flags = VidModeGetModeValue(mode, VIDMODE_FLAGS),
+            .privsize = 0
+        };
+        if (client->swapped) {
+            swapl(&mdinf.dotclock);
+            swaps(&mdinf.hdisplay);
+            swaps(&mdinf.hsyncstart);
+            swaps(&mdinf.hsyncend);
+            swaps(&mdinf.htotal);
+            swapl(&mdinf.hskew);
+            swaps(&mdinf.vdisplay);
+            swaps(&mdinf.vsyncstart);
+            swaps(&mdinf.vsyncend);
+            swaps(&mdinf.vtotal);
+            swapl(&mdinf.flags);
+            swapl(&mdinf.privsize);
+        }
+        if (ver < 2) {
+            xXF86OldVidModeModeInfo oldmdinf = {
+                .dotclock = mdinf.dotclock,
+                .hdisplay = mdinf.hdisplay,
+                .hsyncstart = mdinf.hsyncstart,
+                .hsyncend = mdinf.hsyncend,
+                .htotal = mdinf.htotal,
+                .vdisplay = mdinf.vdisplay,
+                .vsyncstart = mdinf.vsyncstart,
+                .vsyncend = mdinf.vsyncend,
+                .vtotal = mdinf.vtotal,
+                .flags = mdinf.flags,
+                .privsize = mdinf.privsize
+            };
+            WriteToClient(client, sizeof(xXF86OldVidModeModeInfo), &oldmdinf);
+        }
+        else {
+            WriteToClient(client, sizeof(xXF86VidModeModeInfo), &mdinf);
+        }
+
+    } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
+
+    return Success;
+}
+
+#define MODEMATCH(mode,stuff)	  \
+     (VidModeGetModeValue(mode, VIDMODE_H_DISPLAY)  == stuff->hdisplay \
+     && VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART)  == stuff->hsyncstart \
+     && VidModeGetModeValue(mode, VIDMODE_H_SYNCEND)  == stuff->hsyncend \
+     && VidModeGetModeValue(mode, VIDMODE_H_TOTAL)  == stuff->htotal \
+     && VidModeGetModeValue(mode, VIDMODE_V_DISPLAY)  == stuff->vdisplay \
+     && VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART)  == stuff->vsyncstart \
+     && VidModeGetModeValue(mode, VIDMODE_V_SYNCEND)  == stuff->vsyncend \
+     && VidModeGetModeValue(mode, VIDMODE_V_TOTAL)  == stuff->vtotal \
+     && VidModeGetModeValue(mode, VIDMODE_FLAGS)  == stuff->flags )
+
+static int
+ProcXF86VidModeAddModeLine(ClientPtr client)
+{
+    REQUEST(xXF86VidModeAddModeLineReq);
+    xXF86OldVidModeAddModeLineReq *oldstuff =
+        (xXF86OldVidModeAddModeLineReq *) client->requestBuffer;
+    xXF86VidModeAddModeLineReq newstuff;
+    pointer mode;
+    int len;
+    int dotClock;
+    int ver;
+
+    DEBUG_P("XF86VidModeAddModeline");
+
+    ver = ClientMajorVersion(client);
+    if (ver < 2) {
+        /* convert from old format */
+        stuff = &newstuff;
+        stuff->length = oldstuff->length;
+        stuff->screen = oldstuff->screen;
+        stuff->dotclock = oldstuff->dotclock;
+        stuff->hdisplay = oldstuff->hdisplay;
+        stuff->hsyncstart = oldstuff->hsyncstart;
+        stuff->hsyncend = oldstuff->hsyncend;
+        stuff->htotal = oldstuff->htotal;
+        stuff->hskew = 0;
+        stuff->vdisplay = oldstuff->vdisplay;
+        stuff->vsyncstart = oldstuff->vsyncstart;
+        stuff->vsyncend = oldstuff->vsyncend;
+        stuff->vtotal = oldstuff->vtotal;
+        stuff->flags = oldstuff->flags;
+        stuff->privsize = oldstuff->privsize;
+        stuff->after_dotclock = oldstuff->after_dotclock;
+        stuff->after_hdisplay = oldstuff->after_hdisplay;
+        stuff->after_hsyncstart = oldstuff->after_hsyncstart;
+        stuff->after_hsyncend = oldstuff->after_hsyncend;
+        stuff->after_htotal = oldstuff->after_htotal;
+        stuff->after_hskew = 0;
+        stuff->after_vdisplay = oldstuff->after_vdisplay;
+        stuff->after_vsyncstart = oldstuff->after_vsyncstart;
+        stuff->after_vsyncend = oldstuff->after_vsyncend;
+        stuff->after_vtotal = oldstuff->after_vtotal;
+        stuff->after_flags = oldstuff->after_flags;
+    }
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+        ErrorF("AddModeLine - scrn: %d clock: %ld\n",
+               (int) stuff->screen, (unsigned long) stuff->dotclock);
+        ErrorF("AddModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+        ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
+               stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+               stuff->vtotal, (unsigned long) stuff->flags);
+        ErrorF("      after - scrn: %d clock: %ld\n",
+               (int) stuff->screen, (unsigned long) stuff->after_dotclock);
+        ErrorF("              hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->after_hdisplay, stuff->after_hsyncstart,
+               stuff->after_hsyncend, stuff->after_htotal);
+        ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
+               stuff->after_vdisplay, stuff->after_vsyncstart,
+               stuff->after_vsyncend, stuff->after_vtotal,
+               (unsigned long) stuff->after_flags);
+    }
+
+    if (ver < 2) {
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeAddModeLineReq);
+        len =
+            client->req_len -
+            bytes_to_int32(sizeof(xXF86OldVidModeAddModeLineReq));
+    }
+    else {
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
+        len =
+            client->req_len -
+            bytes_to_int32(sizeof(xXF86VidModeAddModeLineReq));
+    }
+    if (len != stuff->privsize)
+        return BadLength;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (stuff->hsyncstart < stuff->hdisplay ||
+        stuff->hsyncend < stuff->hsyncstart ||
+        stuff->htotal < stuff->hsyncend ||
+        stuff->vsyncstart < stuff->vdisplay ||
+        stuff->vsyncend < stuff->vsyncstart || stuff->vtotal < stuff->vsyncend)
+        return BadValue;
+
+    if (stuff->after_hsyncstart < stuff->after_hdisplay ||
+        stuff->after_hsyncend < stuff->after_hsyncstart ||
+        stuff->after_htotal < stuff->after_hsyncend ||
+        stuff->after_vsyncstart < stuff->after_vdisplay ||
+        stuff->after_vsyncend < stuff->after_vsyncstart ||
+        stuff->after_vtotal < stuff->after_vsyncend)
+        return BadValue;
+
+    if (stuff->after_htotal != 0 || stuff->after_vtotal != 0) {
+        Bool found = FALSE;
+
+        if (VidModeGetFirstModeline(stuff->screen, &mode, &dotClock)) {
+            do {
+                if ((VidModeGetDotClock(stuff->screen, stuff->dotclock)
+                     == dotClock) && MODEMATCH(mode, stuff)) {
+                    found = TRUE;
+                    break;
+                }
+            } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
+        }
+        if (!found)
+            return BadValue;
+    }
+
+    mode = VidModeCreateMode();
+    if (mode == NULL)
+        return BadValue;
+
+    VidModeSetModeValue(mode, VIDMODE_CLOCK, stuff->dotclock);
+    VidModeSetModeValue(mode, VIDMODE_H_DISPLAY, stuff->hdisplay);
+    VidModeSetModeValue(mode, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
+    VidModeSetModeValue(mode, VIDMODE_H_SYNCEND, stuff->hsyncend);
+    VidModeSetModeValue(mode, VIDMODE_H_TOTAL, stuff->htotal);
+    VidModeSetModeValue(mode, VIDMODE_H_SKEW, stuff->hskew);
+    VidModeSetModeValue(mode, VIDMODE_V_DISPLAY, stuff->vdisplay);
+    VidModeSetModeValue(mode, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
+    VidModeSetModeValue(mode, VIDMODE_V_SYNCEND, stuff->vsyncend);
+    VidModeSetModeValue(mode, VIDMODE_V_TOTAL, stuff->vtotal);
+    VidModeSetModeValue(mode, VIDMODE_FLAGS, stuff->flags);
+
+    if (stuff->privsize)
+        ErrorF("AddModeLine - Privates in request have been ignored\n");
+
+    /* Check that the mode is consistent with the monitor specs */
+    switch (VidModeCheckModeForMonitor(stuff->screen, mode)) {
+    case MODE_OK:
+        break;
+    case MODE_HSYNC:
+    case MODE_H_ILLEGAL:
+        free(mode);
+        return VidModeErrorBase + XF86VidModeBadHTimings;
+    case MODE_VSYNC:
+    case MODE_V_ILLEGAL:
+        free(mode);
+        return VidModeErrorBase + XF86VidModeBadVTimings;
+    default:
+        free(mode);
+        return VidModeErrorBase + XF86VidModeModeUnsuitable;
+    }
+
+    /* Check that the driver is happy with the mode */
+    if (VidModeCheckModeForDriver(stuff->screen, mode) != MODE_OK) {
+        free(mode);
+        return VidModeErrorBase + XF86VidModeModeUnsuitable;
+    }
+
+    VidModeSetCrtcForMode(stuff->screen, mode);
+
+    VidModeAddModeline(stuff->screen, mode);
+
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
+        ErrorF("AddModeLine - Succeeded\n");
+    return Success;
+}
+
+static int
+ProcXF86VidModeDeleteModeLine(ClientPtr client)
+{
+    REQUEST(xXF86VidModeDeleteModeLineReq);
+    xXF86OldVidModeDeleteModeLineReq *oldstuff =
+        (xXF86OldVidModeDeleteModeLineReq *) client->requestBuffer;
+    xXF86VidModeDeleteModeLineReq newstuff;
+    pointer mode;
+    int len, dotClock;
+    int ver;
+
+    DEBUG_P("XF86VidModeDeleteModeline");
+
+    ver = ClientMajorVersion(client);
+    if (ver < 2) {
+        /* convert from old format */
+        stuff = &newstuff;
+        stuff->length = oldstuff->length;
+        stuff->screen = oldstuff->screen;
+        stuff->dotclock = oldstuff->dotclock;
+        stuff->hdisplay = oldstuff->hdisplay;
+        stuff->hsyncstart = oldstuff->hsyncstart;
+        stuff->hsyncend = oldstuff->hsyncend;
+        stuff->htotal = oldstuff->htotal;
+        stuff->hskew = 0;
+        stuff->vdisplay = oldstuff->vdisplay;
+        stuff->vsyncstart = oldstuff->vsyncstart;
+        stuff->vsyncend = oldstuff->vsyncend;
+        stuff->vtotal = oldstuff->vtotal;
+        stuff->flags = oldstuff->flags;
+        stuff->privsize = oldstuff->privsize;
+    }
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+        ErrorF("DeleteModeLine - scrn: %d clock: %ld\n",
+               (int) stuff->screen, (unsigned long) stuff->dotclock);
+        ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+        ErrorF
+            ("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
+             stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
+             (unsigned long) stuff->flags);
+    }
+
+    if (ver < 2) {
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeDeleteModeLineReq);
+        len =
+            client->req_len -
+            bytes_to_int32(sizeof(xXF86OldVidModeDeleteModeLineReq));
+    }
+    else {
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
+        len =
+            client->req_len -
+            bytes_to_int32(sizeof(xXF86VidModeDeleteModeLineReq));
+    }
+    if (len != stuff->privsize) {
+        if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+            ErrorF("req_len = %ld, sizeof(Req) = %d, privsize = %ld, "
+                   "len = %d, length = %d\n",
+                   (unsigned long) client->req_len,
+                   (int) sizeof(xXF86VidModeDeleteModeLineReq) >> 2,
+                   (unsigned long) stuff->privsize, len, stuff->length);
+        }
+        return BadLength;
+    }
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
+        return BadValue;
+
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+        ErrorF("Checking against clock: %d (%d)\n",
+               VidModeGetModeValue(mode, VIDMODE_CLOCK), dotClock);
+        ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
+               VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
+               VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
+               VidModeGetModeValue(mode, VIDMODE_H_TOTAL));
+        ErrorF
+            ("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+             VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
+             VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
+             VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
+             VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
+             VidModeGetModeValue(mode, VIDMODE_FLAGS));
+    }
+    if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock) &&
+        MODEMATCH(mode, stuff))
+        return BadValue;
+
+    if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
+        return BadValue;
+
+    do {
+        if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+            ErrorF("Checking against clock: %d (%d)\n",
+                   VidModeGetModeValue(mode, VIDMODE_CLOCK), dotClock);
+            ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
+                   VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
+                   VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
+                   VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
+                   VidModeGetModeValue(mode, VIDMODE_H_TOTAL));
+            ErrorF
+                ("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+                 VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
+                 VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
+                 VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
+                 VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
+                 VidModeGetModeValue(mode, VIDMODE_FLAGS));
+        }
+        if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock) &&
+            MODEMATCH(mode, stuff)) {
+            VidModeDeleteModeline(stuff->screen, mode);
+            if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
+                ErrorF("DeleteModeLine - Succeeded\n");
+            return Success;
+        }
+    } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
+
+    return BadValue;
+}
+
+static int
+ProcXF86VidModeModModeLine(ClientPtr client)
+{
+    REQUEST(xXF86VidModeModModeLineReq);
+    xXF86OldVidModeModModeLineReq *oldstuff =
+        (xXF86OldVidModeModModeLineReq *) client->requestBuffer;
+    xXF86VidModeModModeLineReq newstuff;
+    pointer mode, modetmp;
+    int len, dotClock;
+    int ver;
+
+    DEBUG_P("XF86VidModeModModeline");
+
+    ver = ClientMajorVersion(client);
+    if (ver < 2) {
+        /* convert from old format */
+        stuff = &newstuff;
+        stuff->length = oldstuff->length;
+        stuff->screen = oldstuff->screen;
+        stuff->hdisplay = oldstuff->hdisplay;
+        stuff->hsyncstart = oldstuff->hsyncstart;
+        stuff->hsyncend = oldstuff->hsyncend;
+        stuff->htotal = oldstuff->htotal;
+        stuff->hskew = 0;
+        stuff->vdisplay = oldstuff->vdisplay;
+        stuff->vsyncstart = oldstuff->vsyncstart;
+        stuff->vsyncend = oldstuff->vsyncend;
+        stuff->vtotal = oldstuff->vtotal;
+        stuff->flags = oldstuff->flags;
+        stuff->privsize = oldstuff->privsize;
+    }
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+        ErrorF("ModModeLine - scrn: %d hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               (int) stuff->screen, stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+        ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
+               stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
+               stuff->vtotal, (unsigned long) stuff->flags);
+    }
+
+    if (ver < 2) {
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeModModeLineReq);
+        len =
+            client->req_len -
+            bytes_to_int32(sizeof(xXF86OldVidModeModModeLineReq));
+    }
+    else {
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
+        len =
+            client->req_len -
+            bytes_to_int32(sizeof(xXF86VidModeModModeLineReq));
+    }
+    if (len != stuff->privsize)
+        return BadLength;
+
+    if (stuff->hsyncstart < stuff->hdisplay ||
+        stuff->hsyncend < stuff->hsyncstart ||
+        stuff->htotal < stuff->hsyncend ||
+        stuff->vsyncstart < stuff->vdisplay ||
+        stuff->vsyncend < stuff->vsyncstart || stuff->vtotal < stuff->vsyncend)
+        return BadValue;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
+        return BadValue;
+
+    modetmp = VidModeCreateMode();
+    VidModeCopyMode(mode, modetmp);
+
+    VidModeSetModeValue(modetmp, VIDMODE_H_DISPLAY, stuff->hdisplay);
+    VidModeSetModeValue(modetmp, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
+    VidModeSetModeValue(modetmp, VIDMODE_H_SYNCEND, stuff->hsyncend);
+    VidModeSetModeValue(modetmp, VIDMODE_H_TOTAL, stuff->htotal);
+    VidModeSetModeValue(modetmp, VIDMODE_H_SKEW, stuff->hskew);
+    VidModeSetModeValue(modetmp, VIDMODE_V_DISPLAY, stuff->vdisplay);
+    VidModeSetModeValue(modetmp, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
+    VidModeSetModeValue(modetmp, VIDMODE_V_SYNCEND, stuff->vsyncend);
+    VidModeSetModeValue(modetmp, VIDMODE_V_TOTAL, stuff->vtotal);
+    VidModeSetModeValue(modetmp, VIDMODE_FLAGS, stuff->flags);
+
+    if (stuff->privsize)
+        ErrorF("ModModeLine - Privates in request have been ignored\n");
+
+    /* Check that the mode is consistent with the monitor specs */
+    switch (VidModeCheckModeForMonitor(stuff->screen, modetmp)) {
+    case MODE_OK:
+        break;
+    case MODE_HSYNC:
+    case MODE_H_ILLEGAL:
+        free(modetmp);
+        return VidModeErrorBase + XF86VidModeBadHTimings;
+    case MODE_VSYNC:
+    case MODE_V_ILLEGAL:
+        free(modetmp);
+        return VidModeErrorBase + XF86VidModeBadVTimings;
+    default:
+        free(modetmp);
+        return VidModeErrorBase + XF86VidModeModeUnsuitable;
+    }
+
+    /* Check that the driver is happy with the mode */
+    if (VidModeCheckModeForDriver(stuff->screen, modetmp) != MODE_OK) {
+        free(modetmp);
+        return VidModeErrorBase + XF86VidModeModeUnsuitable;
+    }
+    free(modetmp);
+
+    VidModeSetModeValue(mode, VIDMODE_H_DISPLAY, stuff->hdisplay);
+    VidModeSetModeValue(mode, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
+    VidModeSetModeValue(mode, VIDMODE_H_SYNCEND, stuff->hsyncend);
+    VidModeSetModeValue(mode, VIDMODE_H_TOTAL, stuff->htotal);
+    VidModeSetModeValue(mode, VIDMODE_H_SKEW, stuff->hskew);
+    VidModeSetModeValue(mode, VIDMODE_V_DISPLAY, stuff->vdisplay);
+    VidModeSetModeValue(mode, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
+    VidModeSetModeValue(mode, VIDMODE_V_SYNCEND, stuff->vsyncend);
+    VidModeSetModeValue(mode, VIDMODE_V_TOTAL, stuff->vtotal);
+    VidModeSetModeValue(mode, VIDMODE_FLAGS, stuff->flags);
+
+    VidModeSetCrtcForMode(stuff->screen, mode);
+    VidModeSwitchMode(stuff->screen, mode);
+
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
+        ErrorF("ModModeLine - Succeeded\n");
+    return Success;
+}
+
+static int
+ProcXF86VidModeValidateModeLine(ClientPtr client)
+{
+    REQUEST(xXF86VidModeValidateModeLineReq);
+    xXF86OldVidModeValidateModeLineReq *oldstuff =
+        (xXF86OldVidModeValidateModeLineReq *) client->requestBuffer;
+    xXF86VidModeValidateModeLineReq newstuff;
+    xXF86VidModeValidateModeLineReply rep;
+    pointer mode, modetmp = NULL;
+    int len, status, dotClock;
+    int ver;
+
+    DEBUG_P("XF86VidModeValidateModeline");
+
+    ver = ClientMajorVersion(client);
+    if (ver < 2) {
+        /* convert from old format */
+        stuff = &newstuff;
+        stuff->length = oldstuff->length;
+        stuff->screen = oldstuff->screen;
+        stuff->dotclock = oldstuff->dotclock;
+        stuff->hdisplay = oldstuff->hdisplay;
+        stuff->hsyncstart = oldstuff->hsyncstart;
+        stuff->hsyncend = oldstuff->hsyncend;
+        stuff->htotal = oldstuff->htotal;
+        stuff->hskew = 0;
+        stuff->vdisplay = oldstuff->vdisplay;
+        stuff->vsyncstart = oldstuff->vsyncstart;
+        stuff->vsyncend = oldstuff->vsyncend;
+        stuff->vtotal = oldstuff->vtotal;
+        stuff->flags = oldstuff->flags;
+        stuff->privsize = oldstuff->privsize;
+    }
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+        ErrorF("ValidateModeLine - scrn: %d clock: %ld\n",
+               (int) stuff->screen, (unsigned long) stuff->dotclock);
+        ErrorF("                   hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+        ErrorF
+            ("                   vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
+             stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
+             (unsigned long) stuff->flags);
+    }
+
+    if (ver < 2) {
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeValidateModeLineReq);
+        len = client->req_len -
+            bytes_to_int32(sizeof(xXF86OldVidModeValidateModeLineReq));
+    }
+    else {
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
+        len =
+            client->req_len -
+            bytes_to_int32(sizeof(xXF86VidModeValidateModeLineReq));
+    }
+    if (len != stuff->privsize)
+        return BadLength;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    status = MODE_OK;
+
+    if (stuff->hsyncstart < stuff->hdisplay ||
+        stuff->hsyncend < stuff->hsyncstart ||
+        stuff->htotal < stuff->hsyncend ||
+        stuff->vsyncstart < stuff->vdisplay ||
+        stuff->vsyncend < stuff->vsyncstart ||
+        stuff->vtotal < stuff->vsyncend) {
+        status = MODE_BAD;
+        goto status_reply;
+    }
+
+    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
+        return BadValue;
+
+    modetmp = VidModeCreateMode();
+    VidModeCopyMode(mode, modetmp);
+
+    VidModeSetModeValue(modetmp, VIDMODE_H_DISPLAY, stuff->hdisplay);
+    VidModeSetModeValue(modetmp, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
+    VidModeSetModeValue(modetmp, VIDMODE_H_SYNCEND, stuff->hsyncend);
+    VidModeSetModeValue(modetmp, VIDMODE_H_TOTAL, stuff->htotal);
+    VidModeSetModeValue(modetmp, VIDMODE_H_SKEW, stuff->hskew);
+    VidModeSetModeValue(modetmp, VIDMODE_V_DISPLAY, stuff->vdisplay);
+    VidModeSetModeValue(modetmp, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
+    VidModeSetModeValue(modetmp, VIDMODE_V_SYNCEND, stuff->vsyncend);
+    VidModeSetModeValue(modetmp, VIDMODE_V_TOTAL, stuff->vtotal);
+    VidModeSetModeValue(modetmp, VIDMODE_FLAGS, stuff->flags);
+    if (stuff->privsize)
+        ErrorF("ValidateModeLine - Privates in request have been ignored\n");
+
+    /* Check that the mode is consistent with the monitor specs */
+    if ((status =
+         VidModeCheckModeForMonitor(stuff->screen, modetmp)) != MODE_OK)
+        goto status_reply;
+
+    /* Check that the driver is happy with the mode */
+    status = VidModeCheckModeForDriver(stuff->screen, modetmp);
+
+ status_reply:
+    free(modetmp);
+
+    rep = (xXF86VidModeValidateModeLineReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(SIZEOF(xXF86VidModeValidateModeLineReply)
+                                 - SIZEOF(xGenericReply)),
+        .status = status
+    };
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.status);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeValidateModeLineReply), &rep);
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
+        ErrorF("ValidateModeLine - Succeeded (status = %d)\n", status);
+    return Success;
+}
+
+static int
+ProcXF86VidModeSwitchMode(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSwitchModeReq);
+
+    DEBUG_P("XF86VidModeSwitchMode");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    VidModeZoomViewport(stuff->screen, (short) stuff->zoom);
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeSwitchToMode(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSwitchToModeReq);
+    xXF86OldVidModeSwitchToModeReq *oldstuff =
+        (xXF86OldVidModeSwitchToModeReq *) client->requestBuffer;
+    xXF86VidModeSwitchToModeReq newstuff;
+    pointer mode;
+    int len, dotClock;
+    int ver;
+
+    DEBUG_P("XF86VidModeSwitchToMode");
+
+    ver = ClientMajorVersion(client);
+    if (ver < 2) {
+        /* convert from old format */
+        stuff = &newstuff;
+        stuff->length = oldstuff->length;
+        stuff->screen = oldstuff->screen;
+        stuff->dotclock = oldstuff->dotclock;
+        stuff->hdisplay = oldstuff->hdisplay;
+        stuff->hsyncstart = oldstuff->hsyncstart;
+        stuff->hsyncend = oldstuff->hsyncend;
+        stuff->htotal = oldstuff->htotal;
+        stuff->hskew = 0;
+        stuff->vdisplay = oldstuff->vdisplay;
+        stuff->vsyncstart = oldstuff->vsyncstart;
+        stuff->vsyncend = oldstuff->vsyncend;
+        stuff->vtotal = oldstuff->vtotal;
+        stuff->flags = oldstuff->flags;
+        stuff->privsize = oldstuff->privsize;
+    }
+    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+        ErrorF("SwitchToMode - scrn: %d clock: %ld\n",
+               (int) stuff->screen, (unsigned long) stuff->dotclock);
+        ErrorF("               hdsp: %d hbeg: %d hend: %d httl: %d\n",
+               stuff->hdisplay, stuff->hsyncstart,
+               stuff->hsyncend, stuff->htotal);
+        ErrorF
+            ("               vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
+             stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
+             (unsigned long) stuff->flags);
+    }
+
+    if (ver < 2) {
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeSwitchToModeReq);
+        len =
+            client->req_len -
+            bytes_to_int32(sizeof(xXF86OldVidModeSwitchToModeReq));
+    }
+    else {
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeSwitchToModeReq);
+        len =
+            client->req_len -
+            bytes_to_int32(sizeof(xXF86VidModeSwitchToModeReq));
+    }
+    if (len != stuff->privsize)
+        return BadLength;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
+        return BadValue;
+
+    if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock)
+        && MODEMATCH(mode, stuff))
+        return Success;
+
+    if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
+        return BadValue;
+
+    do {
+        if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
+            ErrorF("Checking against clock: %d (%d)\n",
+                   VidModeGetModeValue(mode, VIDMODE_CLOCK), dotClock);
+            ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
+                   VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
+                   VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
+                   VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
+                   VidModeGetModeValue(mode, VIDMODE_H_TOTAL));
+            ErrorF
+                ("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
+                 VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
+                 VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
+                 VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
+                 VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
+                 VidModeGetModeValue(mode, VIDMODE_FLAGS));
+        }
+        if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock) &&
+            MODEMATCH(mode, stuff)) {
+
+            if (!VidModeSwitchMode(stuff->screen, mode))
+                return BadValue;
+
+            if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
+                ErrorF("SwitchToMode - Succeeded\n");
+            return Success;
+        }
+    } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
+
+    return BadValue;
+}
+
+static int
+ProcXF86VidModeLockModeSwitch(ClientPtr client)
+{
+    REQUEST(xXF86VidModeLockModeSwitchReq);
+
+    REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
+
+    DEBUG_P("XF86VidModeLockModeSwitch");
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!VidModeLockZoom(stuff->screen, (short) stuff->lock))
+        return VidModeErrorBase + XF86VidModeZoomLocked;
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeGetMonitor(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetMonitorReq);
+    xXF86VidModeGetMonitorReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence
+    };
+    CARD32 *hsyncdata, *vsyncdata;
+    int i, nHsync, nVrefresh;
+    pointer monitor;
+
+    DEBUG_P("XF86VidModeGetMonitor");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!VidModeGetMonitor(stuff->screen, &monitor))
+        return BadValue;
+
+    nHsync = VidModeGetMonitorValue(monitor, VIDMODE_MON_NHSYNC, 0).i;
+    nVrefresh = VidModeGetMonitorValue(monitor, VIDMODE_MON_NVREFRESH, 0).i;
+
+    if ((char *) (VidModeGetMonitorValue(monitor, VIDMODE_MON_VENDOR, 0)).ptr)
+        rep.vendorLength = strlen((char *) (VidModeGetMonitorValue(monitor,
+                                                                   VIDMODE_MON_VENDOR,
+                                                                   0)).ptr);
+    else
+        rep.vendorLength = 0;
+    if ((char *) (VidModeGetMonitorValue(monitor, VIDMODE_MON_MODEL, 0)).ptr)
+        rep.modelLength = strlen((char *) (VidModeGetMonitorValue(monitor,
+                                                                  VIDMODE_MON_MODEL,
+                                                                  0)).ptr);
+    else
+        rep.modelLength = 0;
+    rep.length =
+        bytes_to_int32(SIZEOF(xXF86VidModeGetMonitorReply) -
+                       SIZEOF(xGenericReply) + (nHsync +
+                                                nVrefresh) * sizeof(CARD32) +
+                       pad_to_int32(rep.vendorLength) +
+                       pad_to_int32(rep.modelLength));
+    rep.nhsync = nHsync;
+    rep.nvsync = nVrefresh;
+    hsyncdata = malloc(nHsync * sizeof(CARD32));
+    if (!hsyncdata) {
+        return BadAlloc;
+    }
+    vsyncdata = malloc(nVrefresh * sizeof(CARD32));
+
+    if (!vsyncdata) {
+        free(hsyncdata);
+        return BadAlloc;
+    }
+
+    for (i = 0; i < nHsync; i++) {
+        hsyncdata[i] = (unsigned short) (VidModeGetMonitorValue(monitor,
+                                                                VIDMODE_MON_HSYNC_LO,
+                                                                i)).f |
+            (unsigned
+             short) (VidModeGetMonitorValue(monitor, VIDMODE_MON_HSYNC_HI,
+                                            i)).f << 16;
+    }
+    for (i = 0; i < nVrefresh; i++) {
+        vsyncdata[i] = (unsigned short) (VidModeGetMonitorValue(monitor,
+                                                                VIDMODE_MON_VREFRESH_LO,
+                                                                i)).f |
+            (unsigned
+             short) (VidModeGetMonitorValue(monitor, VIDMODE_MON_VREFRESH_HI,
+                                            i)).f << 16;
+    }
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+    }
+    WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), &rep);
+    client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+    WriteSwappedDataToClient(client, nHsync * sizeof(CARD32), hsyncdata);
+    WriteSwappedDataToClient(client, nVrefresh * sizeof(CARD32), vsyncdata);
+    if (rep.vendorLength)
+        WriteToClient(client, rep.vendorLength,
+                 (VidModeGetMonitorValue(monitor, VIDMODE_MON_VENDOR, 0)).ptr);
+    if (rep.modelLength)
+        WriteToClient(client, rep.modelLength,
+                 (VidModeGetMonitorValue(monitor, VIDMODE_MON_MODEL, 0)).ptr);
+
+    free(hsyncdata);
+    free(vsyncdata);
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeGetViewPort(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetViewPortReq);
+    xXF86VidModeGetViewPortReply rep;
+    int x, y;
+
+    DEBUG_P("XF86VidModeGetViewPort");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    VidModeGetViewPort(stuff->screen, &x, &y);
+
+    rep = (xXF86VidModeGetViewPortReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .x = x,
+        .y = y
+    };
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.x);
+        swapl(&rep.y);
+    }
+    WriteToClient(client, SIZEOF(xXF86VidModeGetViewPortReply), &rep);
+    return Success;
+}
+
+static int
+ProcXF86VidModeSetViewPort(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSetViewPortReq);
+
+    DEBUG_P("XF86VidModeSetViewPort");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!VidModeSetViewPort(stuff->screen, stuff->x, stuff->y))
+        return BadValue;
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeGetDotClocks(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetDotClocksReq);
+    xXF86VidModeGetDotClocksReply rep;
+    int n;
+    int numClocks;
+    CARD32 dotclock;
+    int *Clocks = NULL;
+    Bool ClockProg;
+
+    DEBUG_P("XF86VidModeGetDotClocks");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetDotClocksReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    numClocks = VidModeGetNumOfClocks(stuff->screen, &ClockProg);
+
+    rep = (xXF86VidModeGetDotClocksReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(SIZEOF(xXF86VidModeGetDotClocksReply)
+                                 - SIZEOF(xGenericReply) + numClocks),
+        .clocks = numClocks,
+        .maxclocks = MAXCLOCKS,
+        .flags = 0
+    };
+
+    if (!ClockProg) {
+        Clocks = calloc(numClocks, sizeof(int));
+        if (!Clocks)
+            return BadValue;
+        if (!VidModeGetClocks(stuff->screen, Clocks)) {
+            free(Clocks);
+            return BadValue;
+        }
+    }
+    if (ClockProg) {
+        rep.flags |= CLKFLAG_PROGRAMABLE;
+    }
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.clocks);
+        swapl(&rep.maxclocks);
+        swapl(&rep.flags);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeGetDotClocksReply), &rep);
+    if (!ClockProg) {
+        for (n = 0; n < numClocks; n++) {
+            dotclock = *Clocks++;
+            if (client->swapped) {
+                WriteSwappedDataToClient(client, 4, (char *) &dotclock);
+            }
+            else {
+                WriteToClient(client, 4, &dotclock);
+            }
+        }
+    }
+
+    free(Clocks);
+    return Success;
+}
+
+static int
+ProcXF86VidModeSetGamma(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSetGammaReq);
+
+    DEBUG_P("XF86VidModeSetGamma");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeSetGammaReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!VidModeSetGamma(stuff->screen, ((float) stuff->red) / 10000.,
+                         ((float) stuff->green) / 10000.,
+                         ((float) stuff->blue) / 10000.))
+        return BadValue;
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeGetGamma(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetGammaReq);
+    xXF86VidModeGetGammaReply rep;
+    float red, green, blue;
+
+    DEBUG_P("XF86VidModeGetGamma");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!VidModeGetGamma(stuff->screen, &red, &green, &blue))
+        return BadValue;
+    rep = (xXF86VidModeGetGammaReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .red = (CARD32) (red * 10000.),
+        .green = (CARD32) (green * 10000.),
+        .blue = (CARD32) (blue * 10000.)
+    };
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.red);
+        swapl(&rep.green);
+        swapl(&rep.blue);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeGetGammaReply), &rep);
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeSetGammaRamp(ClientPtr client)
+{
+    CARD16 *r, *g, *b;
+    int length;
+
+    REQUEST(xXF86VidModeSetGammaRampReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (stuff->size != VidModeGetGammaRampSize(stuff->screen))
+        return BadValue;
+
+    length = (stuff->size + 1) & ~1;
+
+    REQUEST_FIXED_SIZE(xXF86VidModeSetGammaRampReq, length * 6);
+
+    r = (CARD16 *) &stuff[1];
+    g = r + length;
+    b = g + length;
+
+    if (!VidModeSetGammaRamp(stuff->screen, stuff->size, r, g, b))
+        return BadValue;
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeGetGammaRamp(ClientPtr client)
+{
+    CARD16 *ramp = NULL;
+    int length;
+    size_t ramplen = 0;
+    xXF86VidModeGetGammaRampReply rep;
+
+    REQUEST(xXF86VidModeGetGammaRampReq);
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (stuff->size != VidModeGetGammaRampSize(stuff->screen))
+        return BadValue;
+
+    length = (stuff->size + 1) & ~1;
+
+    if (stuff->size) {
+        ramplen = length * 3 * sizeof(CARD16);
+        if (!(ramp = malloc(ramplen)))
+            return BadAlloc;
+
+        if (!VidModeGetGammaRamp(stuff->screen, stuff->size,
+                                 ramp, ramp + length, ramp + (length * 2))) {
+            free(ramp);
+            return BadValue;
+        }
+    }
+    rep = (xXF86VidModeGetGammaRampReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = (length >> 1) * 3,
+        .size = stuff->size
+    };
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swaps(&rep.size);
+        SwapShorts((short *) ramp, length * 3);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeGetGammaRampReply), &rep);
+
+    if (stuff->size) {
+        WriteToClient(client, ramplen, ramp);
+        free(ramp);
+    }
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeGetGammaRampSize(ClientPtr client)
+{
+    xXF86VidModeGetGammaRampSizeReply rep;
+
+    REQUEST(xXF86VidModeGetGammaRampSizeReq);
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampSizeReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    rep = (xXF86VidModeGetGammaRampSizeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .size = VidModeGetGammaRampSize(stuff->screen)
+    };
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swaps(&rep.size);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeGetGammaRampSizeReply), &rep);
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeGetPermissions(ClientPtr client)
+{
+    xXF86VidModeGetPermissionsReply rep =  {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .permissions = XF86VM_READ_PERMISSION
+    };
+
+    REQUEST(xXF86VidModeGetPermissionsReq);
+
+    REQUEST_SIZE_MATCH(xXF86VidModeGetPermissionsReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (xf86GetVidModeEnabled() &&
+        (xf86GetVidModeAllowNonLocal() || LocalClient(client))) {
+        rep.permissions |= XF86VM_WRITE_PERMISSION;
+    }
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.permissions);
+    }
+    WriteToClient(client, sizeof(xXF86VidModeGetPermissionsReply), &rep);
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeSetClientVersion(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSetClientVersionReq);
+
+    VidModePrivPtr pPriv;
+
+    DEBUG_P("XF86VidModeSetClientVersion");
+
+    REQUEST_SIZE_MATCH(xXF86VidModeSetClientVersionReq);
+
+    if ((pPriv = VM_GETPRIV(client)) == NULL) {
+        pPriv = malloc(sizeof(VidModePrivRec));
+        if (!pPriv)
+            return BadAlloc;
+        VM_SETPRIV(client, pPriv);
+    }
+    pPriv->major = stuff->major;
+
+    pPriv->minor = stuff->minor;
+
+    return Success;
+}
+
+static int
+ProcXF86VidModeDispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+    switch (stuff->data) {
+    case X_XF86VidModeQueryVersion:
+        return ProcXF86VidModeQueryVersion(client);
+    case X_XF86VidModeGetModeLine:
+        return ProcXF86VidModeGetModeLine(client);
+    case X_XF86VidModeGetMonitor:
+        return ProcXF86VidModeGetMonitor(client);
+    case X_XF86VidModeGetAllModeLines:
+        return ProcXF86VidModeGetAllModeLines(client);
+    case X_XF86VidModeValidateModeLine:
+        return ProcXF86VidModeValidateModeLine(client);
+    case X_XF86VidModeGetViewPort:
+        return ProcXF86VidModeGetViewPort(client);
+    case X_XF86VidModeGetDotClocks:
+        return ProcXF86VidModeGetDotClocks(client);
+    case X_XF86VidModeSetClientVersion:
+        return ProcXF86VidModeSetClientVersion(client);
+    case X_XF86VidModeGetGamma:
+        return ProcXF86VidModeGetGamma(client);
+    case X_XF86VidModeGetGammaRamp:
+        return ProcXF86VidModeGetGammaRamp(client);
+    case X_XF86VidModeGetGammaRampSize:
+        return ProcXF86VidModeGetGammaRampSize(client);
+    case X_XF86VidModeGetPermissions:
+        return ProcXF86VidModeGetPermissions(client);
+    default:
+        if (!xf86GetVidModeEnabled())
+            return VidModeErrorBase + XF86VidModeExtensionDisabled;
+        if (xf86GetVidModeAllowNonLocal() || LocalClient(client)) {
+            switch (stuff->data) {
+            case X_XF86VidModeAddModeLine:
+                return ProcXF86VidModeAddModeLine(client);
+            case X_XF86VidModeDeleteModeLine:
+                return ProcXF86VidModeDeleteModeLine(client);
+            case X_XF86VidModeModModeLine:
+                return ProcXF86VidModeModModeLine(client);
+            case X_XF86VidModeSwitchMode:
+                return ProcXF86VidModeSwitchMode(client);
+            case X_XF86VidModeSwitchToMode:
+                return ProcXF86VidModeSwitchToMode(client);
+            case X_XF86VidModeLockModeSwitch:
+                return ProcXF86VidModeLockModeSwitch(client);
+            case X_XF86VidModeSetViewPort:
+                return ProcXF86VidModeSetViewPort(client);
+            case X_XF86VidModeSetGamma:
+                return ProcXF86VidModeSetGamma(client);
+            case X_XF86VidModeSetGammaRamp:
+                return ProcXF86VidModeSetGammaRamp(client);
+            default:
+                return BadRequest;
+            }
+        }
+        else
+            return VidModeErrorBase + XF86VidModeClientNotLocal;
+    }
+}
+
+static int
+SProcXF86VidModeQueryVersion(ClientPtr client)
+{
+    REQUEST(xXF86VidModeQueryVersionReq);
+    swaps(&stuff->length);
+    return ProcXF86VidModeQueryVersion(client);
+}
+
+static int
+SProcXF86VidModeGetModeLine(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetModeLineReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
+    swaps(&stuff->screen);
+    return ProcXF86VidModeGetModeLine(client);
+}
+
+static int
+SProcXF86VidModeGetAllModeLines(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetAllModeLinesReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
+    swaps(&stuff->screen);
+    return ProcXF86VidModeGetAllModeLines(client);
+}
+
+static int
+SProcXF86VidModeAddModeLine(ClientPtr client)
+{
+    xXF86OldVidModeAddModeLineReq *oldstuff =
+        (xXF86OldVidModeAddModeLineReq *) client->requestBuffer;
+    int ver;
+
+    REQUEST(xXF86VidModeAddModeLineReq);
+    ver = ClientMajorVersion(client);
+    if (ver < 2) {
+        swaps(&oldstuff->length);
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeAddModeLineReq);
+        swapl(&oldstuff->screen);
+        swaps(&oldstuff->hdisplay);
+        swaps(&oldstuff->hsyncstart);
+        swaps(&oldstuff->hsyncend);
+        swaps(&oldstuff->htotal);
+        swaps(&oldstuff->vdisplay);
+        swaps(&oldstuff->vsyncstart);
+        swaps(&oldstuff->vsyncend);
+        swaps(&oldstuff->vtotal);
+        swapl(&oldstuff->flags);
+        swapl(&oldstuff->privsize);
+        SwapRestL(oldstuff);
+    }
+    else {
+        swaps(&stuff->length);
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
+        swapl(&stuff->screen);
+        swaps(&stuff->hdisplay);
+        swaps(&stuff->hsyncstart);
+        swaps(&stuff->hsyncend);
+        swaps(&stuff->htotal);
+        swaps(&stuff->hskew);
+        swaps(&stuff->vdisplay);
+        swaps(&stuff->vsyncstart);
+        swaps(&stuff->vsyncend);
+        swaps(&stuff->vtotal);
+        swapl(&stuff->flags);
+        swapl(&stuff->privsize);
+        SwapRestL(stuff);
+    }
+    return ProcXF86VidModeAddModeLine(client);
+}
+
+static int
+SProcXF86VidModeDeleteModeLine(ClientPtr client)
+{
+    xXF86OldVidModeDeleteModeLineReq *oldstuff =
+        (xXF86OldVidModeDeleteModeLineReq *) client->requestBuffer;
+    int ver;
+
+    REQUEST(xXF86VidModeDeleteModeLineReq);
+    ver = ClientMajorVersion(client);
+    if (ver < 2) {
+        swaps(&oldstuff->length);
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeDeleteModeLineReq);
+        swapl(&oldstuff->screen);
+        swaps(&oldstuff->hdisplay);
+        swaps(&oldstuff->hsyncstart);
+        swaps(&oldstuff->hsyncend);
+        swaps(&oldstuff->htotal);
+        swaps(&oldstuff->vdisplay);
+        swaps(&oldstuff->vsyncstart);
+        swaps(&oldstuff->vsyncend);
+        swaps(&oldstuff->vtotal);
+        swapl(&oldstuff->flags);
+        swapl(&oldstuff->privsize);
+        SwapRestL(oldstuff);
+    }
+    else {
+        swaps(&stuff->length);
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
+        swapl(&stuff->screen);
+        swaps(&stuff->hdisplay);
+        swaps(&stuff->hsyncstart);
+        swaps(&stuff->hsyncend);
+        swaps(&stuff->htotal);
+        swaps(&stuff->hskew);
+        swaps(&stuff->vdisplay);
+        swaps(&stuff->vsyncstart);
+        swaps(&stuff->vsyncend);
+        swaps(&stuff->vtotal);
+        swapl(&stuff->flags);
+        swapl(&stuff->privsize);
+        SwapRestL(stuff);
+    }
+    return ProcXF86VidModeDeleteModeLine(client);
+}
+
+static int
+SProcXF86VidModeModModeLine(ClientPtr client)
+{
+    xXF86OldVidModeModModeLineReq *oldstuff =
+        (xXF86OldVidModeModModeLineReq *) client->requestBuffer;
+    int ver;
+
+    REQUEST(xXF86VidModeModModeLineReq);
+    ver = ClientMajorVersion(client);
+    if (ver < 2) {
+        swaps(&oldstuff->length);
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeModModeLineReq);
+        swapl(&oldstuff->screen);
+        swaps(&oldstuff->hdisplay);
+        swaps(&oldstuff->hsyncstart);
+        swaps(&oldstuff->hsyncend);
+        swaps(&oldstuff->htotal);
+        swaps(&oldstuff->vdisplay);
+        swaps(&oldstuff->vsyncstart);
+        swaps(&oldstuff->vsyncend);
+        swaps(&oldstuff->vtotal);
+        swapl(&oldstuff->flags);
+        swapl(&oldstuff->privsize);
+        SwapRestL(oldstuff);
+    }
+    else {
+        swaps(&stuff->length);
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
+        swapl(&stuff->screen);
+        swaps(&stuff->hdisplay);
+        swaps(&stuff->hsyncstart);
+        swaps(&stuff->hsyncend);
+        swaps(&stuff->htotal);
+        swaps(&stuff->hskew);
+        swaps(&stuff->vdisplay);
+        swaps(&stuff->vsyncstart);
+        swaps(&stuff->vsyncend);
+        swaps(&stuff->vtotal);
+        swapl(&stuff->flags);
+        swapl(&stuff->privsize);
+        SwapRestL(stuff);
+    }
+    return ProcXF86VidModeModModeLine(client);
+}
+
+static int
+SProcXF86VidModeValidateModeLine(ClientPtr client)
+{
+    xXF86OldVidModeValidateModeLineReq *oldstuff =
+        (xXF86OldVidModeValidateModeLineReq *) client->requestBuffer;
+    int ver;
+
+    REQUEST(xXF86VidModeValidateModeLineReq);
+    ver = ClientMajorVersion(client);
+    if (ver < 2) {
+        swaps(&oldstuff->length);
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeValidateModeLineReq);
+        swapl(&oldstuff->screen);
+        swaps(&oldstuff->hdisplay);
+        swaps(&oldstuff->hsyncstart);
+        swaps(&oldstuff->hsyncend);
+        swaps(&oldstuff->htotal);
+        swaps(&oldstuff->vdisplay);
+        swaps(&oldstuff->vsyncstart);
+        swaps(&oldstuff->vsyncend);
+        swaps(&oldstuff->vtotal);
+        swapl(&oldstuff->flags);
+        swapl(&oldstuff->privsize);
+        SwapRestL(oldstuff);
+    }
+    else {
+        swaps(&stuff->length);
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
+        swapl(&stuff->screen);
+        swaps(&stuff->hdisplay);
+        swaps(&stuff->hsyncstart);
+        swaps(&stuff->hsyncend);
+        swaps(&stuff->htotal);
+        swaps(&stuff->hskew);
+        swaps(&stuff->vdisplay);
+        swaps(&stuff->vsyncstart);
+        swaps(&stuff->vsyncend);
+        swaps(&stuff->vtotal);
+        swapl(&stuff->flags);
+        swapl(&stuff->privsize);
+        SwapRestL(stuff);
+    }
+    return ProcXF86VidModeValidateModeLine(client);
+}
+
+static int
+SProcXF86VidModeSwitchMode(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSwitchModeReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
+    swaps(&stuff->screen);
+    swaps(&stuff->zoom);
+    return ProcXF86VidModeSwitchMode(client);
+}
+
+static int
+SProcXF86VidModeSwitchToMode(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSwitchToModeReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeSwitchToModeReq);
+    swapl(&stuff->screen);
+    return ProcXF86VidModeSwitchToMode(client);
+}
+
+static int
+SProcXF86VidModeLockModeSwitch(ClientPtr client)
+{
+    REQUEST(xXF86VidModeLockModeSwitchReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
+    swaps(&stuff->screen);
+    swaps(&stuff->lock);
+    return ProcXF86VidModeLockModeSwitch(client);
+}
+
+static int
+SProcXF86VidModeGetMonitor(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetMonitorReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
+    swaps(&stuff->screen);
+    return ProcXF86VidModeGetMonitor(client);
+}
+
+static int
+SProcXF86VidModeGetViewPort(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetViewPortReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
+    swaps(&stuff->screen);
+    return ProcXF86VidModeGetViewPort(client);
+}
+
+static int
+SProcXF86VidModeSetViewPort(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSetViewPortReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
+    swaps(&stuff->screen);
+    swapl(&stuff->x);
+    swapl(&stuff->y);
+    return ProcXF86VidModeSetViewPort(client);
+}
+
+static int
+SProcXF86VidModeGetDotClocks(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetDotClocksReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetDotClocksReq);
+    swaps(&stuff->screen);
+    return ProcXF86VidModeGetDotClocks(client);
+}
+
+static int
+SProcXF86VidModeSetClientVersion(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSetClientVersionReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeSetClientVersionReq);
+    swaps(&stuff->major);
+    swaps(&stuff->minor);
+    return ProcXF86VidModeSetClientVersion(client);
+}
+
+static int
+SProcXF86VidModeSetGamma(ClientPtr client)
+{
+    REQUEST(xXF86VidModeSetGammaReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeSetGammaReq);
+    swaps(&stuff->screen);
+    swapl(&stuff->red);
+    swapl(&stuff->green);
+    swapl(&stuff->blue);
+    return ProcXF86VidModeSetGamma(client);
+}
+
+static int
+SProcXF86VidModeGetGamma(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetGammaReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaReq);
+    swaps(&stuff->screen);
+    return ProcXF86VidModeGetGamma(client);
+}
+
+static int
+SProcXF86VidModeSetGammaRamp(ClientPtr client)
+{
+    int length;
+
+    REQUEST(xXF86VidModeSetGammaRampReq);
+    swaps(&stuff->length);
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeSetGammaRampReq);
+    swaps(&stuff->size);
+    swaps(&stuff->screen);
+    length = ((stuff->size + 1) & ~1) * 6;
+    REQUEST_FIXED_SIZE(xXF86VidModeSetGammaRampReq, length);
+    SwapRestS(stuff);
+    return ProcXF86VidModeSetGammaRamp(client);
+}
+
+static int
+SProcXF86VidModeGetGammaRamp(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetGammaRampReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampReq);
+    swaps(&stuff->size);
+    swaps(&stuff->screen);
+    return ProcXF86VidModeGetGammaRamp(client);
+}
+
+static int
+SProcXF86VidModeGetGammaRampSize(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetGammaRampSizeReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampSizeReq);
+    swaps(&stuff->screen);
+    return ProcXF86VidModeGetGammaRampSize(client);
+}
+
+static int
+SProcXF86VidModeGetPermissions(ClientPtr client)
+{
+    REQUEST(xXF86VidModeGetPermissionsReq);
+    swaps(&stuff->length);
+    REQUEST_SIZE_MATCH(xXF86VidModeGetPermissionsReq);
+    swaps(&stuff->screen);
+    return ProcXF86VidModeGetPermissions(client);
+}
+
+static int
+SProcXF86VidModeDispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+    switch (stuff->data) {
+    case X_XF86VidModeQueryVersion:
+        return SProcXF86VidModeQueryVersion(client);
+    case X_XF86VidModeGetModeLine:
+        return SProcXF86VidModeGetModeLine(client);
+    case X_XF86VidModeGetMonitor:
+        return SProcXF86VidModeGetMonitor(client);
+    case X_XF86VidModeGetAllModeLines:
+        return SProcXF86VidModeGetAllModeLines(client);
+    case X_XF86VidModeGetViewPort:
+        return SProcXF86VidModeGetViewPort(client);
+    case X_XF86VidModeValidateModeLine:
+        return SProcXF86VidModeValidateModeLine(client);
+    case X_XF86VidModeGetDotClocks:
+        return SProcXF86VidModeGetDotClocks(client);
+    case X_XF86VidModeSetClientVersion:
+        return SProcXF86VidModeSetClientVersion(client);
+    case X_XF86VidModeGetGamma:
+        return SProcXF86VidModeGetGamma(client);
+    case X_XF86VidModeGetGammaRamp:
+        return SProcXF86VidModeGetGammaRamp(client);
+    case X_XF86VidModeGetGammaRampSize:
+        return SProcXF86VidModeGetGammaRampSize(client);
+    case X_XF86VidModeGetPermissions:
+        return SProcXF86VidModeGetPermissions(client);
+    default:
+        if (!xf86GetVidModeEnabled())
+            return VidModeErrorBase + XF86VidModeExtensionDisabled;
+        if (xf86GetVidModeAllowNonLocal() || LocalClient(client)) {
+            switch (stuff->data) {
+            case X_XF86VidModeAddModeLine:
+                return SProcXF86VidModeAddModeLine(client);
+            case X_XF86VidModeDeleteModeLine:
+                return SProcXF86VidModeDeleteModeLine(client);
+            case X_XF86VidModeModModeLine:
+                return SProcXF86VidModeModModeLine(client);
+            case X_XF86VidModeSwitchMode:
+                return SProcXF86VidModeSwitchMode(client);
+            case X_XF86VidModeSwitchToMode:
+                return SProcXF86VidModeSwitchToMode(client);
+            case X_XF86VidModeLockModeSwitch:
+                return SProcXF86VidModeLockModeSwitch(client);
+            case X_XF86VidModeSetViewPort:
+                return SProcXF86VidModeSetViewPort(client);
+            case X_XF86VidModeSetGamma:
+                return SProcXF86VidModeSetGamma(client);
+            case X_XF86VidModeSetGammaRamp:
+                return SProcXF86VidModeSetGammaRamp(client);
+            default:
+                return BadRequest;
+            }
+        }
+        else
+            return VidModeErrorBase + XF86VidModeClientNotLocal;
+    }
+}
+
+void
+XFree86VidModeExtensionInit(void)
+{
+    ExtensionEntry *extEntry;
+    ScreenPtr pScreen;
+    int i;
+    Bool enabled = FALSE;
+
+    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
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+        pScreen = screenInfo.screens[i];
+        if (VidModeExtensionInit(pScreen))
+            enabled = TRUE;
+    }
+    /* This means that the DDX doesn't want the vidmode extension enabled */
+    if (!enabled)
+        return;
+
+    if (
+#ifdef XF86VIDMODE_EVENTS
+           EventType &&
+#endif
+           (extEntry = AddExtension(XF86VIDMODENAME,
+                                    XF86VidModeNumberEvents,
+                                    XF86VidModeNumberErrors,
+                                    ProcXF86VidModeDispatch,
+                                    SProcXF86VidModeDispatch,
+                                    NULL, StandardMinorOpcode))) {
+#if 0
+        XF86VidModeReqCode = (unsigned char) extEntry->base;
+#endif
+        VidModeErrorBase = extEntry->errorBase;
+#ifdef XF86VIDMODE_EVENTS
+        XF86VidModeEventBase = extEntry->eventBase;
+        EventSwapVector[XF86VidModeEventBase] =
+            (EventSwapPtr) SXF86VidModeNotifyEvent;
+#endif
+    }
+}
diff --git a/hw/xfree86/dixmods/extmod/Makefile.am b/hw/xfree86/dixmods/extmod/Makefile.am
index d3a9fc8..d5e0cde 100644
--- a/hw/xfree86/dixmods/extmod/Makefile.am
+++ b/hw/xfree86/dixmods/extmod/Makefile.am
@@ -1,10 +1,6 @@
 extsmoduledir = $(moduledir)/extensions
 extsmodule_LTLIBRARIES = libextmod.la
 
-if XF86VIDMODE
-XF86VMODE_SRCS = xf86vmode.c
-endif
-
 AM_CFLAGS = @DIX_CFLAGS@ @XORG_CFLAGS@
 INCLUDES = @XORG_INCS@ \
            -I$(top_srcdir)/dbe \
@@ -12,6 +8,5 @@ INCLUDES = @XORG_INCS@ \
            -I$(top_srcdir)/miext/shadow
 
 libextmod_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-libextmod_la_SOURCES = modinit.c \
-                       $(XF86VMODE_SRCS)
+libextmod_la_SOURCES = modinit.c
 libextmod_la_LIBADD = $(top_builddir)/Xext/libXextmodule.la
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index f05a570..74171cf 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -39,14 +39,6 @@ static MODULESETUPPROTO(extmodSetup);
  * Array describing extensions to be initialized
  */
 static ExtensionModule extensionModules[] = {
-#ifdef XF86VIDMODE
-    {
-     XFree86VidModeExtensionInit,
-     XF86VIDMODENAME,
-     &noXFree86VidModeExtension,
-     NULL,
-     NULL},
-#endif
 };
 
 static XF86ModuleVersionInfo VersRec = {
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
deleted file mode 100644
index 7cd2eed..0000000
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ /dev/null
@@ -1,2165 +0,0 @@
-
-/*
-
-Copyright 1995  Kaleb S. KEITHLEY
-
-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, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-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 Kaleb S. KEITHLEY 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 Kaleb S. KEITHLEY 
-shall not be used in advertising or otherwise to promote the sale, use 
-or other dealings in this Software without prior written authorization
-from Kaleb S. KEITHLEY
-
-*/
-/* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "dixstruct.h"
-#include "extnsionst.h"
-#include "xf86Extensions.h"
-#include "scrnintstr.h"
-#include "servermd.h"
-#include <X11/extensions/xf86vmproto.h>
-#include "swaprep.h"
-#include "xf86.h"
-#include "vidmodeproc.h"
-#include "globals.h"
-#include "protocol-versions.h"
-
-#define DEFAULT_XF86VIDMODE_VERBOSITY	3
-
-static int VidModeErrorBase;
-static DevPrivateKeyRec VidModeClientPrivateKeyRec;
-
-#define VidModeClientPrivateKey (&VidModeClientPrivateKeyRec)
-
-/* This holds the client's version information */
-typedef struct {
-    int major;
-    int minor;
-} VidModePrivRec, *VidModePrivPtr;
-
-#define VM_GETPRIV(c) ((VidModePrivPtr) \
-    dixLookupPrivate(&(c)->devPrivates, VidModeClientPrivateKey))
-#define VM_SETPRIV(c,p) \
-    dixSetPrivate(&(c)->devPrivates, VidModeClientPrivateKey, p)
-
-#if 0
-static unsigned char XF86VidModeReqCode = 0;
-#endif
-
-/* The XF86VIDMODE_EVENTS code is far from complete */
-
-#ifdef XF86VIDMODE_EVENTS
-static int XF86VidModeEventBase = 0;
-
-static void SXF86VidModeNotifyEvent(xXF86VidModeNotifyEvent * /* from */ , xXF86VidModeNotifyEvent *    /* to */
-    );
-
-static RESTYPE EventType;       /* resource type for event masks */
-
-typedef struct _XF86VidModeEvent *XF86VidModeEventPtr;
-
-typedef struct _XF86VidModeEvent {
-    XF86VidModeEventPtr next;
-    ClientPtr client;
-    ScreenPtr screen;
-    XID resource;
-    CARD32 mask;
-} XF86VidModeEventRec;
-
-static int XF86VidModeFreeEvents();
-
-typedef struct _XF86VidModeScreenPrivate {
-    XF86VidModeEventPtr events;
-    Bool hasWindow;
-} XF86VidModeScreenPrivateRec, *XF86VidModeScreenPrivatePtr;
-
-static DevPrivateKeyRec ScreenPrivateKeyRec;
-
-#define ScreenPrivateKey (&ScreenPrivateKeyRec)
-
-#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \
-    dixLookupPrivate(&(s)->devPrivates, ScreenPrivateKey))
-#define SetScreenPrivate(s,v) \
-    dixSetPrivate(&(s)->devPrivates, ScreenPrivateKey, v)
-#define SetupScreen(s)  ScreenSaverScreenPrivatePtr pPriv = GetScreenPrivate(s)
-
-#define New(t)  (malloc(sizeof (t)))
-#endif
-
-#ifdef DEBUG
-#define DEBUG_P(x) ErrorF(x"\n");
-#else
-#define DEBUG_P(x) /**/
-#endif
-    static int
-ClientMajorVersion(ClientPtr client)
-{
-    VidModePrivPtr pPriv;
-
-    pPriv = VM_GETPRIV(client);
-    if (!pPriv)
-        return 0;
-    else
-        return pPriv->major;
-}
-
-#ifdef XF86VIDMODE_EVENTS
-static void
-CheckScreenPrivate(pScreen)
-ScreenPtr
- pScreen;
-{
-    SetupScreen(pScreen);
-
-    if (!pPriv)
-        return;
-    if (!pPriv->events && !pPriv->hasWindow) {
-        free(pPriv);
-        SetScreenPrivate(pScreen, NULL);
-    }
-}
-
-static XF86VidModeScreenPrivatePtr
-MakeScreenPrivate(pScreen)
-ScreenPtr
- pScreen;
-{
-    SetupScreen(pScreen);
-
-    if (pPriv)
-        return pPriv;
-    pPriv = New(XF86VidModeScreenPrivateRec);
-    if (!pPriv)
-        return 0;
-    pPriv->events = 0;
-    pPriv->hasWindow = FALSE;
-    SetScreenPrivate(pScreen, pPriv);
-    return pPriv;
-}
-
-static unsigned long
-getEventMask(ScreenPtr pScreen, ClientPtr client)
-{
-    SetupScreen(pScreen);
-    XF86VidModeEventPtr pEv;
-
-    if (!pPriv)
-        return 0;
-    for (pEv = pPriv->events; pEv; pEv = pEv->next)
-        if (pEv->client == client)
-            return pEv->mask;
-    return 0;
-}
-
-static Bool
-setEventMask(ScreenPtr pScreen, ClientPtr client, unsigned long mask)
-{
-    SetupScreen(pScreen);
-    XF86VidModeEventPtr pEv, *pPrev;
-
-    if (getEventMask(pScreen, client) == mask)
-        return TRUE;
-    if (!pPriv) {
-        pPriv = MakeScreenPrivate(pScreen);
-        if (!pPriv)
-            return FALSE;
-    }
-    for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
-        if (pEv->client == client)
-            break;
-    if (mask == 0) {
-        *pPrev = pEv->next;
-        free(pEv);
-        CheckScreenPrivate(pScreen);
-    }
-    else {
-        if (!pEv) {
-            pEv = New(ScreenSaverEventRec);
-            if (!pEv) {
-                CheckScreenPrivate(pScreen);
-                return FALSE;
-            }
-            *pPrev = pEv;
-            pEv->next = NULL;
-            pEv->client = client;
-            pEv->screen = pScreen;
-            pEv->resource = FakeClientID(client->index);
-        }
-        pEv->mask = mask;
-    }
-    return TRUE;
-}
-
-static int
-XF86VidModeFreeEvents(pointer value, XID id)
-{
-    XF86VidModeEventPtr pOld = (XF86VidModeEventPtr) value;
-    ScreenPtr pScreen = pOld->screen;
-
-    SetupScreen(pScreen);
-    XF86VidModeEventPtr pEv, *pPrev;
-
-    if (!pPriv)
-        return TRUE;
-    for (pPrev = &pPriv->events; pEv = *pPrev; pPrev = &pEv->next)
-        if (pEv == pOld)
-            break;
-    if (!pEv)
-        return TRUE;
-    *pPrev = pEv->next;
-    free(pEv);
-    CheckScreenPrivate(pScreen);
-    return TRUE;
-}
-
-static void
-SendXF86VidModeNotify(ScreenPtr pScreen, int state, Bool forced)
-{
-    XF86VidModeScreenPrivatePtr pPriv;
-    unsigned long mask;
-    xXF86VidModeNotifyEvent ev;
-    int kind;
-
-    UpdateCurrentTimeIf();
-    mask = XF86VidModeNotifyMask;
-    pScreen = screenInfo.screens[pScreen->myNum];
-    pPriv = GetScreenPrivate(pScreen);
-    if (!pPriv)
-        return;
-    kind = XF86VidModeModeChange;
-    for (pEv = pPriv->events; pEv; pEv = pEv->next) {
-        if (pEv->mask & mask) {
-            XF86VidModeEventPtr pEv = {
-                .type = XF86VidModeNotify + XF86VidModeEventBase,
-                .state = state,
-                .timestamp = currentTime.milliseconds,
-                .root = pScreen->root->drawable.id,
-                .kind = kind,
-                .forced = forced
-            };
-            WriteEventsToClient(pEv->client, 1, (xEvent *) &ev);
-        }
-    }
-}
-
-static void
-SXF86VidModeNotifyEvent(xXF86VidModeNotifyEvent * from,
-                        xXF86VidModeNotifyEvent * to)
-{
-    to->type = from->type;
-    to->state = from->state;
-    cpswaps(from->sequenceNumber, to->sequenceNumber);
-    cpswapl(from->timestamp, to->timestamp);
-    cpswapl(from->root, to->root);
-    to->kind = from->kind;
-    to->forced = from->forced;
-}
-#endif
-
-static int
-ProcXF86VidModeQueryVersion(ClientPtr client)
-{
-    xXF86VidModeQueryVersionReply rep = {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = 0,
-        .majorVersion = SERVER_XF86VIDMODE_MAJOR_VERSION,
-        .minorVersion = SERVER_XF86VIDMODE_MINOR_VERSION
-    };
-
-    DEBUG_P("XF86VidModeQueryVersion");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeQueryVersionReq);
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swaps(&rep.majorVersion);
-        swaps(&rep.minorVersion);
-    }
-    WriteToClient(client, sizeof(xXF86VidModeQueryVersionReply), &rep);
-    return Success;
-}
-
-static int
-ProcXF86VidModeGetModeLine(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetModeLineReq);
-    xXF86VidModeGetModeLineReply rep = {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence
-    };
-    pointer mode;
-    int dotClock;
-    int ver;
-
-    DEBUG_P("XF86VidModeGetModeline");
-
-    ver = ClientMajorVersion(client);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
-
-    if (ver < 2) {
-        rep.length = bytes_to_int32(SIZEOF(xXF86OldVidModeGetModeLineReply) -
-                                    SIZEOF(xGenericReply));
-    }
-    else {
-        rep.length = bytes_to_int32(SIZEOF(xXF86VidModeGetModeLineReply) -
-                                    SIZEOF(xGenericReply));
-    }
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
-        return BadValue;
-
-    rep.dotclock = dotClock;
-    rep.hdisplay = VidModeGetModeValue(mode, VIDMODE_H_DISPLAY);
-    rep.hsyncstart = VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART);
-    rep.hsyncend = VidModeGetModeValue(mode, VIDMODE_H_SYNCEND);
-    rep.htotal = VidModeGetModeValue(mode, VIDMODE_H_TOTAL);
-    rep.hskew = VidModeGetModeValue(mode, VIDMODE_H_SKEW);
-    rep.vdisplay = VidModeGetModeValue(mode, VIDMODE_V_DISPLAY);
-    rep.vsyncstart = VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART);
-    rep.vsyncend = VidModeGetModeValue(mode, VIDMODE_V_SYNCEND);
-    rep.vtotal = VidModeGetModeValue(mode, VIDMODE_V_TOTAL);
-    rep.flags = VidModeGetModeValue(mode, VIDMODE_FLAGS);
-
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-        ErrorF("GetModeLine - scrn: %d clock: %ld\n",
-               stuff->screen, (unsigned long) rep.dotclock);
-        ErrorF("GetModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n",
-               rep.hdisplay, rep.hsyncstart, rep.hsyncend, rep.htotal);
-        ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
-               rep.vdisplay, rep.vsyncstart, rep.vsyncend,
-               rep.vtotal, (unsigned long) rep.flags);
-    }
-
-    /*
-     * Older servers sometimes had server privates that the VidMode 
-     * extention made available. So to be compatiable pretend that
-     * there are no server privates to pass to the client
-     */
-    rep.privsize = 0;
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.dotclock);
-        swaps(&rep.hdisplay);
-        swaps(&rep.hsyncstart);
-        swaps(&rep.hsyncend);
-        swaps(&rep.htotal);
-        swaps(&rep.hskew);
-        swaps(&rep.vdisplay);
-        swaps(&rep.vsyncstart);
-        swaps(&rep.vsyncend);
-        swaps(&rep.vtotal);
-        swapl(&rep.flags);
-        swapl(&rep.privsize);
-    }
-    if (ver < 2) {
-        xXF86OldVidModeGetModeLineReply oldrep = {
-            .type = rep.type,
-            .sequenceNumber = rep.sequenceNumber,
-            .length = rep.length,
-            .dotclock = rep.dotclock,
-            .hdisplay = rep.hdisplay,
-            .hsyncstart = rep.hsyncstart,
-            .hsyncend = rep.hsyncend,
-            .htotal = rep.htotal,
-            .vdisplay = rep.vdisplay,
-            .vsyncstart = rep.vsyncstart,
-            .vsyncend = rep.vsyncend,
-            .vtotal = rep.vtotal,
-            .flags = rep.flags,
-            .privsize = rep.privsize
-        };
-        WriteToClient(client, sizeof(xXF86OldVidModeGetModeLineReply), &oldrep);
-    }
-    else {
-        WriteToClient(client, sizeof(xXF86VidModeGetModeLineReply), &rep);
-    }
-    return Success;
-}
-
-static int
-ProcXF86VidModeGetAllModeLines(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetAllModeLinesReq);
-    xXF86VidModeGetAllModeLinesReply rep;
-    pointer mode;
-    int modecount, dotClock;
-    int ver;
-
-    DEBUG_P("XF86VidModeGetAllModelines");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    ver = ClientMajorVersion(client);
-
-    modecount = VidModeGetNumOfModes(stuff->screen);
-    if (modecount < 1)
-        return VidModeErrorBase + XF86VidModeExtensionDisabled;
-
-    if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
-        return BadValue;
-
-    rep = (xXF86VidModeGetAllModeLinesReply) {
-        .type = X_Reply,
-        .length = SIZEOF(xXF86VidModeGetAllModeLinesReply) -
-            SIZEOF(xGenericReply),
-        .sequenceNumber = client->sequence,
-        .modecount = modecount
-    };
-    if (ver < 2)
-        rep.length += modecount * sizeof(xXF86OldVidModeModeInfo);
-    else
-        rep.length += modecount * sizeof(xXF86VidModeModeInfo);
-    rep.length >>= 2;
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.modecount);
-    }
-    WriteToClient(client, sizeof(xXF86VidModeGetAllModeLinesReply), &rep);
-
-    do {
-        xXF86VidModeModeInfo mdinf = {
-            .dotclock = dotClock,
-            .hdisplay = VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
-            .hsyncstart = VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
-            .hsyncend = VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
-            .htotal = VidModeGetModeValue(mode, VIDMODE_H_TOTAL),
-            .hskew = VidModeGetModeValue(mode, VIDMODE_H_SKEW),
-            .vdisplay = VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
-            .vsyncstart = VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
-            .vsyncend = VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
-            .vtotal = VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
-            .flags = VidModeGetModeValue(mode, VIDMODE_FLAGS),
-            .privsize = 0
-        };
-        if (client->swapped) {
-            swapl(&mdinf.dotclock);
-            swaps(&mdinf.hdisplay);
-            swaps(&mdinf.hsyncstart);
-            swaps(&mdinf.hsyncend);
-            swaps(&mdinf.htotal);
-            swapl(&mdinf.hskew);
-            swaps(&mdinf.vdisplay);
-            swaps(&mdinf.vsyncstart);
-            swaps(&mdinf.vsyncend);
-            swaps(&mdinf.vtotal);
-            swapl(&mdinf.flags);
-            swapl(&mdinf.privsize);
-        }
-        if (ver < 2) {
-            xXF86OldVidModeModeInfo oldmdinf = {
-                .dotclock = mdinf.dotclock,
-                .hdisplay = mdinf.hdisplay,
-                .hsyncstart = mdinf.hsyncstart,
-                .hsyncend = mdinf.hsyncend,
-                .htotal = mdinf.htotal,
-                .vdisplay = mdinf.vdisplay,
-                .vsyncstart = mdinf.vsyncstart,
-                .vsyncend = mdinf.vsyncend,
-                .vtotal = mdinf.vtotal,
-                .flags = mdinf.flags,
-                .privsize = mdinf.privsize
-            };
-            WriteToClient(client, sizeof(xXF86OldVidModeModeInfo), &oldmdinf);
-        }
-        else {
-            WriteToClient(client, sizeof(xXF86VidModeModeInfo), &mdinf);
-        }
-
-    } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
-
-    return Success;
-}
-
-#define MODEMATCH(mode,stuff)	  \
-     (VidModeGetModeValue(mode, VIDMODE_H_DISPLAY)  == stuff->hdisplay \
-     && VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART)  == stuff->hsyncstart \
-     && VidModeGetModeValue(mode, VIDMODE_H_SYNCEND)  == stuff->hsyncend \
-     && VidModeGetModeValue(mode, VIDMODE_H_TOTAL)  == stuff->htotal \
-     && VidModeGetModeValue(mode, VIDMODE_V_DISPLAY)  == stuff->vdisplay \
-     && VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART)  == stuff->vsyncstart \
-     && VidModeGetModeValue(mode, VIDMODE_V_SYNCEND)  == stuff->vsyncend \
-     && VidModeGetModeValue(mode, VIDMODE_V_TOTAL)  == stuff->vtotal \
-     && VidModeGetModeValue(mode, VIDMODE_FLAGS)  == stuff->flags )
-
-static int
-ProcXF86VidModeAddModeLine(ClientPtr client)
-{
-    REQUEST(xXF86VidModeAddModeLineReq);
-    xXF86OldVidModeAddModeLineReq *oldstuff =
-        (xXF86OldVidModeAddModeLineReq *) client->requestBuffer;
-    xXF86VidModeAddModeLineReq newstuff;
-    pointer mode;
-    int len;
-    int dotClock;
-    int ver;
-
-    DEBUG_P("XF86VidModeAddModeline");
-
-    ver = ClientMajorVersion(client);
-    if (ver < 2) {
-        /* convert from old format */
-        stuff = &newstuff;
-        stuff->length = oldstuff->length;
-        stuff->screen = oldstuff->screen;
-        stuff->dotclock = oldstuff->dotclock;
-        stuff->hdisplay = oldstuff->hdisplay;
-        stuff->hsyncstart = oldstuff->hsyncstart;
-        stuff->hsyncend = oldstuff->hsyncend;
-        stuff->htotal = oldstuff->htotal;
-        stuff->hskew = 0;
-        stuff->vdisplay = oldstuff->vdisplay;
-        stuff->vsyncstart = oldstuff->vsyncstart;
-        stuff->vsyncend = oldstuff->vsyncend;
-        stuff->vtotal = oldstuff->vtotal;
-        stuff->flags = oldstuff->flags;
-        stuff->privsize = oldstuff->privsize;
-        stuff->after_dotclock = oldstuff->after_dotclock;
-        stuff->after_hdisplay = oldstuff->after_hdisplay;
-        stuff->after_hsyncstart = oldstuff->after_hsyncstart;
-        stuff->after_hsyncend = oldstuff->after_hsyncend;
-        stuff->after_htotal = oldstuff->after_htotal;
-        stuff->after_hskew = 0;
-        stuff->after_vdisplay = oldstuff->after_vdisplay;
-        stuff->after_vsyncstart = oldstuff->after_vsyncstart;
-        stuff->after_vsyncend = oldstuff->after_vsyncend;
-        stuff->after_vtotal = oldstuff->after_vtotal;
-        stuff->after_flags = oldstuff->after_flags;
-    }
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-        ErrorF("AddModeLine - scrn: %d clock: %ld\n",
-               (int) stuff->screen, (unsigned long) stuff->dotclock);
-        ErrorF("AddModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n",
-               stuff->hdisplay, stuff->hsyncstart,
-               stuff->hsyncend, stuff->htotal);
-        ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
-               stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
-               stuff->vtotal, (unsigned long) stuff->flags);
-        ErrorF("      after - scrn: %d clock: %ld\n",
-               (int) stuff->screen, (unsigned long) stuff->after_dotclock);
-        ErrorF("              hdsp: %d hbeg: %d hend: %d httl: %d\n",
-               stuff->after_hdisplay, stuff->after_hsyncstart,
-               stuff->after_hsyncend, stuff->after_htotal);
-        ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
-               stuff->after_vdisplay, stuff->after_vsyncstart,
-               stuff->after_vsyncend, stuff->after_vtotal,
-               (unsigned long) stuff->after_flags);
-    }
-
-    if (ver < 2) {
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeAddModeLineReq);
-        len =
-            client->req_len -
-            bytes_to_int32(sizeof(xXF86OldVidModeAddModeLineReq));
-    }
-    else {
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
-        len =
-            client->req_len -
-            bytes_to_int32(sizeof(xXF86VidModeAddModeLineReq));
-    }
-    if (len != stuff->privsize)
-        return BadLength;
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (stuff->hsyncstart < stuff->hdisplay ||
-        stuff->hsyncend < stuff->hsyncstart ||
-        stuff->htotal < stuff->hsyncend ||
-        stuff->vsyncstart < stuff->vdisplay ||
-        stuff->vsyncend < stuff->vsyncstart || stuff->vtotal < stuff->vsyncend)
-        return BadValue;
-
-    if (stuff->after_hsyncstart < stuff->after_hdisplay ||
-        stuff->after_hsyncend < stuff->after_hsyncstart ||
-        stuff->after_htotal < stuff->after_hsyncend ||
-        stuff->after_vsyncstart < stuff->after_vdisplay ||
-        stuff->after_vsyncend < stuff->after_vsyncstart ||
-        stuff->after_vtotal < stuff->after_vsyncend)
-        return BadValue;
-
-    if (stuff->after_htotal != 0 || stuff->after_vtotal != 0) {
-        Bool found = FALSE;
-
-        if (VidModeGetFirstModeline(stuff->screen, &mode, &dotClock)) {
-            do {
-                if ((VidModeGetDotClock(stuff->screen, stuff->dotclock)
-                     == dotClock) && MODEMATCH(mode, stuff)) {
-                    found = TRUE;
-                    break;
-                }
-            } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
-        }
-        if (!found)
-            return BadValue;
-    }
-
-    mode = VidModeCreateMode();
-    if (mode == NULL)
-        return BadValue;
-
-    VidModeSetModeValue(mode, VIDMODE_CLOCK, stuff->dotclock);
-    VidModeSetModeValue(mode, VIDMODE_H_DISPLAY, stuff->hdisplay);
-    VidModeSetModeValue(mode, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
-    VidModeSetModeValue(mode, VIDMODE_H_SYNCEND, stuff->hsyncend);
-    VidModeSetModeValue(mode, VIDMODE_H_TOTAL, stuff->htotal);
-    VidModeSetModeValue(mode, VIDMODE_H_SKEW, stuff->hskew);
-    VidModeSetModeValue(mode, VIDMODE_V_DISPLAY, stuff->vdisplay);
-    VidModeSetModeValue(mode, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
-    VidModeSetModeValue(mode, VIDMODE_V_SYNCEND, stuff->vsyncend);
-    VidModeSetModeValue(mode, VIDMODE_V_TOTAL, stuff->vtotal);
-    VidModeSetModeValue(mode, VIDMODE_FLAGS, stuff->flags);
-
-    if (stuff->privsize)
-        ErrorF("AddModeLine - Privates in request have been ignored\n");
-
-    /* Check that the mode is consistent with the monitor specs */
-    switch (VidModeCheckModeForMonitor(stuff->screen, mode)) {
-    case MODE_OK:
-        break;
-    case MODE_HSYNC:
-    case MODE_H_ILLEGAL:
-        free(mode);
-        return VidModeErrorBase + XF86VidModeBadHTimings;
-    case MODE_VSYNC:
-    case MODE_V_ILLEGAL:
-        free(mode);
-        return VidModeErrorBase + XF86VidModeBadVTimings;
-    default:
-        free(mode);
-        return VidModeErrorBase + XF86VidModeModeUnsuitable;
-    }
-
-    /* Check that the driver is happy with the mode */
-    if (VidModeCheckModeForDriver(stuff->screen, mode) != MODE_OK) {
-        free(mode);
-        return VidModeErrorBase + XF86VidModeModeUnsuitable;
-    }
-
-    VidModeSetCrtcForMode(stuff->screen, mode);
-
-    VidModeAddModeline(stuff->screen, mode);
-
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
-        ErrorF("AddModeLine - Succeeded\n");
-    return Success;
-}
-
-static int
-ProcXF86VidModeDeleteModeLine(ClientPtr client)
-{
-    REQUEST(xXF86VidModeDeleteModeLineReq);
-    xXF86OldVidModeDeleteModeLineReq *oldstuff =
-        (xXF86OldVidModeDeleteModeLineReq *) client->requestBuffer;
-    xXF86VidModeDeleteModeLineReq newstuff;
-    pointer mode;
-    int len, dotClock;
-    int ver;
-
-    DEBUG_P("XF86VidModeDeleteModeline");
-
-    ver = ClientMajorVersion(client);
-    if (ver < 2) {
-        /* convert from old format */
-        stuff = &newstuff;
-        stuff->length = oldstuff->length;
-        stuff->screen = oldstuff->screen;
-        stuff->dotclock = oldstuff->dotclock;
-        stuff->hdisplay = oldstuff->hdisplay;
-        stuff->hsyncstart = oldstuff->hsyncstart;
-        stuff->hsyncend = oldstuff->hsyncend;
-        stuff->htotal = oldstuff->htotal;
-        stuff->hskew = 0;
-        stuff->vdisplay = oldstuff->vdisplay;
-        stuff->vsyncstart = oldstuff->vsyncstart;
-        stuff->vsyncend = oldstuff->vsyncend;
-        stuff->vtotal = oldstuff->vtotal;
-        stuff->flags = oldstuff->flags;
-        stuff->privsize = oldstuff->privsize;
-    }
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-        ErrorF("DeleteModeLine - scrn: %d clock: %ld\n",
-               (int) stuff->screen, (unsigned long) stuff->dotclock);
-        ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
-               stuff->hdisplay, stuff->hsyncstart,
-               stuff->hsyncend, stuff->htotal);
-        ErrorF
-            ("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
-             stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
-             (unsigned long) stuff->flags);
-    }
-
-    if (ver < 2) {
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeDeleteModeLineReq);
-        len =
-            client->req_len -
-            bytes_to_int32(sizeof(xXF86OldVidModeDeleteModeLineReq));
-    }
-    else {
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
-        len =
-            client->req_len -
-            bytes_to_int32(sizeof(xXF86VidModeDeleteModeLineReq));
-    }
-    if (len != stuff->privsize) {
-        if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-            ErrorF("req_len = %ld, sizeof(Req) = %d, privsize = %ld, "
-                   "len = %d, length = %d\n",
-                   (unsigned long) client->req_len,
-                   (int) sizeof(xXF86VidModeDeleteModeLineReq) >> 2,
-                   (unsigned long) stuff->privsize, len, stuff->length);
-        }
-        return BadLength;
-    }
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
-        return BadValue;
-
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-        ErrorF("Checking against clock: %d (%d)\n",
-               VidModeGetModeValue(mode, VIDMODE_CLOCK), dotClock);
-        ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
-               VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
-               VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
-               VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
-               VidModeGetModeValue(mode, VIDMODE_H_TOTAL));
-        ErrorF
-            ("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
-             VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
-             VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
-             VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
-             VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
-             VidModeGetModeValue(mode, VIDMODE_FLAGS));
-    }
-    if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock) &&
-        MODEMATCH(mode, stuff))
-        return BadValue;
-
-    if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
-        return BadValue;
-
-    do {
-        if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-            ErrorF("Checking against clock: %d (%d)\n",
-                   VidModeGetModeValue(mode, VIDMODE_CLOCK), dotClock);
-            ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
-                   VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
-                   VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
-                   VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
-                   VidModeGetModeValue(mode, VIDMODE_H_TOTAL));
-            ErrorF
-                ("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
-                 VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
-                 VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
-                 VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
-                 VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
-                 VidModeGetModeValue(mode, VIDMODE_FLAGS));
-        }
-        if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock) &&
-            MODEMATCH(mode, stuff)) {
-            VidModeDeleteModeline(stuff->screen, mode);
-            if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
-                ErrorF("DeleteModeLine - Succeeded\n");
-            return Success;
-        }
-    } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
-
-    return BadValue;
-}
-
-static int
-ProcXF86VidModeModModeLine(ClientPtr client)
-{
-    REQUEST(xXF86VidModeModModeLineReq);
-    xXF86OldVidModeModModeLineReq *oldstuff =
-        (xXF86OldVidModeModModeLineReq *) client->requestBuffer;
-    xXF86VidModeModModeLineReq newstuff;
-    pointer mode, modetmp;
-    int len, dotClock;
-    int ver;
-
-    DEBUG_P("XF86VidModeModModeline");
-
-    ver = ClientMajorVersion(client);
-    if (ver < 2) {
-        /* convert from old format */
-        stuff = &newstuff;
-        stuff->length = oldstuff->length;
-        stuff->screen = oldstuff->screen;
-        stuff->hdisplay = oldstuff->hdisplay;
-        stuff->hsyncstart = oldstuff->hsyncstart;
-        stuff->hsyncend = oldstuff->hsyncend;
-        stuff->htotal = oldstuff->htotal;
-        stuff->hskew = 0;
-        stuff->vdisplay = oldstuff->vdisplay;
-        stuff->vsyncstart = oldstuff->vsyncstart;
-        stuff->vsyncend = oldstuff->vsyncend;
-        stuff->vtotal = oldstuff->vtotal;
-        stuff->flags = oldstuff->flags;
-        stuff->privsize = oldstuff->privsize;
-    }
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-        ErrorF("ModModeLine - scrn: %d hdsp: %d hbeg: %d hend: %d httl: %d\n",
-               (int) stuff->screen, stuff->hdisplay, stuff->hsyncstart,
-               stuff->hsyncend, stuff->htotal);
-        ErrorF("              vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
-               stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
-               stuff->vtotal, (unsigned long) stuff->flags);
-    }
-
-    if (ver < 2) {
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeModModeLineReq);
-        len =
-            client->req_len -
-            bytes_to_int32(sizeof(xXF86OldVidModeModModeLineReq));
-    }
-    else {
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
-        len =
-            client->req_len -
-            bytes_to_int32(sizeof(xXF86VidModeModModeLineReq));
-    }
-    if (len != stuff->privsize)
-        return BadLength;
-
-    if (stuff->hsyncstart < stuff->hdisplay ||
-        stuff->hsyncend < stuff->hsyncstart ||
-        stuff->htotal < stuff->hsyncend ||
-        stuff->vsyncstart < stuff->vdisplay ||
-        stuff->vsyncend < stuff->vsyncstart || stuff->vtotal < stuff->vsyncend)
-        return BadValue;
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
-        return BadValue;
-
-    modetmp = VidModeCreateMode();
-    VidModeCopyMode(mode, modetmp);
-
-    VidModeSetModeValue(modetmp, VIDMODE_H_DISPLAY, stuff->hdisplay);
-    VidModeSetModeValue(modetmp, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
-    VidModeSetModeValue(modetmp, VIDMODE_H_SYNCEND, stuff->hsyncend);
-    VidModeSetModeValue(modetmp, VIDMODE_H_TOTAL, stuff->htotal);
-    VidModeSetModeValue(modetmp, VIDMODE_H_SKEW, stuff->hskew);
-    VidModeSetModeValue(modetmp, VIDMODE_V_DISPLAY, stuff->vdisplay);
-    VidModeSetModeValue(modetmp, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
-    VidModeSetModeValue(modetmp, VIDMODE_V_SYNCEND, stuff->vsyncend);
-    VidModeSetModeValue(modetmp, VIDMODE_V_TOTAL, stuff->vtotal);
-    VidModeSetModeValue(modetmp, VIDMODE_FLAGS, stuff->flags);
-
-    if (stuff->privsize)
-        ErrorF("ModModeLine - Privates in request have been ignored\n");
-
-    /* Check that the mode is consistent with the monitor specs */
-    switch (VidModeCheckModeForMonitor(stuff->screen, modetmp)) {
-    case MODE_OK:
-        break;
-    case MODE_HSYNC:
-    case MODE_H_ILLEGAL:
-        free(modetmp);
-        return VidModeErrorBase + XF86VidModeBadHTimings;
-    case MODE_VSYNC:
-    case MODE_V_ILLEGAL:
-        free(modetmp);
-        return VidModeErrorBase + XF86VidModeBadVTimings;
-    default:
-        free(modetmp);
-        return VidModeErrorBase + XF86VidModeModeUnsuitable;
-    }
-
-    /* Check that the driver is happy with the mode */
-    if (VidModeCheckModeForDriver(stuff->screen, modetmp) != MODE_OK) {
-        free(modetmp);
-        return VidModeErrorBase + XF86VidModeModeUnsuitable;
-    }
-    free(modetmp);
-
-    VidModeSetModeValue(mode, VIDMODE_H_DISPLAY, stuff->hdisplay);
-    VidModeSetModeValue(mode, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
-    VidModeSetModeValue(mode, VIDMODE_H_SYNCEND, stuff->hsyncend);
-    VidModeSetModeValue(mode, VIDMODE_H_TOTAL, stuff->htotal);
-    VidModeSetModeValue(mode, VIDMODE_H_SKEW, stuff->hskew);
-    VidModeSetModeValue(mode, VIDMODE_V_DISPLAY, stuff->vdisplay);
-    VidModeSetModeValue(mode, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
-    VidModeSetModeValue(mode, VIDMODE_V_SYNCEND, stuff->vsyncend);
-    VidModeSetModeValue(mode, VIDMODE_V_TOTAL, stuff->vtotal);
-    VidModeSetModeValue(mode, VIDMODE_FLAGS, stuff->flags);
-
-    VidModeSetCrtcForMode(stuff->screen, mode);
-    VidModeSwitchMode(stuff->screen, mode);
-
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
-        ErrorF("ModModeLine - Succeeded\n");
-    return Success;
-}
-
-static int
-ProcXF86VidModeValidateModeLine(ClientPtr client)
-{
-    REQUEST(xXF86VidModeValidateModeLineReq);
-    xXF86OldVidModeValidateModeLineReq *oldstuff =
-        (xXF86OldVidModeValidateModeLineReq *) client->requestBuffer;
-    xXF86VidModeValidateModeLineReq newstuff;
-    xXF86VidModeValidateModeLineReply rep;
-    pointer mode, modetmp = NULL;
-    int len, status, dotClock;
-    int ver;
-
-    DEBUG_P("XF86VidModeValidateModeline");
-
-    ver = ClientMajorVersion(client);
-    if (ver < 2) {
-        /* convert from old format */
-        stuff = &newstuff;
-        stuff->length = oldstuff->length;
-        stuff->screen = oldstuff->screen;
-        stuff->dotclock = oldstuff->dotclock;
-        stuff->hdisplay = oldstuff->hdisplay;
-        stuff->hsyncstart = oldstuff->hsyncstart;
-        stuff->hsyncend = oldstuff->hsyncend;
-        stuff->htotal = oldstuff->htotal;
-        stuff->hskew = 0;
-        stuff->vdisplay = oldstuff->vdisplay;
-        stuff->vsyncstart = oldstuff->vsyncstart;
-        stuff->vsyncend = oldstuff->vsyncend;
-        stuff->vtotal = oldstuff->vtotal;
-        stuff->flags = oldstuff->flags;
-        stuff->privsize = oldstuff->privsize;
-    }
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-        ErrorF("ValidateModeLine - scrn: %d clock: %ld\n",
-               (int) stuff->screen, (unsigned long) stuff->dotclock);
-        ErrorF("                   hdsp: %d hbeg: %d hend: %d httl: %d\n",
-               stuff->hdisplay, stuff->hsyncstart,
-               stuff->hsyncend, stuff->htotal);
-        ErrorF
-            ("                   vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
-             stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
-             (unsigned long) stuff->flags);
-    }
-
-    if (ver < 2) {
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeValidateModeLineReq);
-        len = client->req_len -
-            bytes_to_int32(sizeof(xXF86OldVidModeValidateModeLineReq));
-    }
-    else {
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
-        len =
-            client->req_len -
-            bytes_to_int32(sizeof(xXF86VidModeValidateModeLineReq));
-    }
-    if (len != stuff->privsize)
-        return BadLength;
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    status = MODE_OK;
-
-    if (stuff->hsyncstart < stuff->hdisplay ||
-        stuff->hsyncend < stuff->hsyncstart ||
-        stuff->htotal < stuff->hsyncend ||
-        stuff->vsyncstart < stuff->vdisplay ||
-        stuff->vsyncend < stuff->vsyncstart ||
-        stuff->vtotal < stuff->vsyncend) {
-        status = MODE_BAD;
-        goto status_reply;
-    }
-
-    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
-        return BadValue;
-
-    modetmp = VidModeCreateMode();
-    VidModeCopyMode(mode, modetmp);
-
-    VidModeSetModeValue(modetmp, VIDMODE_H_DISPLAY, stuff->hdisplay);
-    VidModeSetModeValue(modetmp, VIDMODE_H_SYNCSTART, stuff->hsyncstart);
-    VidModeSetModeValue(modetmp, VIDMODE_H_SYNCEND, stuff->hsyncend);
-    VidModeSetModeValue(modetmp, VIDMODE_H_TOTAL, stuff->htotal);
-    VidModeSetModeValue(modetmp, VIDMODE_H_SKEW, stuff->hskew);
-    VidModeSetModeValue(modetmp, VIDMODE_V_DISPLAY, stuff->vdisplay);
-    VidModeSetModeValue(modetmp, VIDMODE_V_SYNCSTART, stuff->vsyncstart);
-    VidModeSetModeValue(modetmp, VIDMODE_V_SYNCEND, stuff->vsyncend);
-    VidModeSetModeValue(modetmp, VIDMODE_V_TOTAL, stuff->vtotal);
-    VidModeSetModeValue(modetmp, VIDMODE_FLAGS, stuff->flags);
-    if (stuff->privsize)
-        ErrorF("ValidateModeLine - Privates in request have been ignored\n");
-
-    /* Check that the mode is consistent with the monitor specs */
-    if ((status =
-         VidModeCheckModeForMonitor(stuff->screen, modetmp)) != MODE_OK)
-        goto status_reply;
-
-    /* Check that the driver is happy with the mode */
-    status = VidModeCheckModeForDriver(stuff->screen, modetmp);
-
- status_reply:
-    free(modetmp);
-
-    rep = (xXF86VidModeValidateModeLineReply) {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = bytes_to_int32(SIZEOF(xXF86VidModeValidateModeLineReply)
-                                 - SIZEOF(xGenericReply)),
-        .status = status
-    };
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.status);
-    }
-    WriteToClient(client, sizeof(xXF86VidModeValidateModeLineReply), &rep);
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
-        ErrorF("ValidateModeLine - Succeeded (status = %d)\n", status);
-    return Success;
-}
-
-static int
-ProcXF86VidModeSwitchMode(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSwitchModeReq);
-
-    DEBUG_P("XF86VidModeSwitchMode");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    VidModeZoomViewport(stuff->screen, (short) stuff->zoom);
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeSwitchToMode(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSwitchToModeReq);
-    xXF86OldVidModeSwitchToModeReq *oldstuff =
-        (xXF86OldVidModeSwitchToModeReq *) client->requestBuffer;
-    xXF86VidModeSwitchToModeReq newstuff;
-    pointer mode;
-    int len, dotClock;
-    int ver;
-
-    DEBUG_P("XF86VidModeSwitchToMode");
-
-    ver = ClientMajorVersion(client);
-    if (ver < 2) {
-        /* convert from old format */
-        stuff = &newstuff;
-        stuff->length = oldstuff->length;
-        stuff->screen = oldstuff->screen;
-        stuff->dotclock = oldstuff->dotclock;
-        stuff->hdisplay = oldstuff->hdisplay;
-        stuff->hsyncstart = oldstuff->hsyncstart;
-        stuff->hsyncend = oldstuff->hsyncend;
-        stuff->htotal = oldstuff->htotal;
-        stuff->hskew = 0;
-        stuff->vdisplay = oldstuff->vdisplay;
-        stuff->vsyncstart = oldstuff->vsyncstart;
-        stuff->vsyncend = oldstuff->vsyncend;
-        stuff->vtotal = oldstuff->vtotal;
-        stuff->flags = oldstuff->flags;
-        stuff->privsize = oldstuff->privsize;
-    }
-    if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-        ErrorF("SwitchToMode - scrn: %d clock: %ld\n",
-               (int) stuff->screen, (unsigned long) stuff->dotclock);
-        ErrorF("               hdsp: %d hbeg: %d hend: %d httl: %d\n",
-               stuff->hdisplay, stuff->hsyncstart,
-               stuff->hsyncend, stuff->htotal);
-        ErrorF
-            ("               vdsp: %d vbeg: %d vend: %d vttl: %d flags: %ld\n",
-             stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
-             (unsigned long) stuff->flags);
-    }
-
-    if (ver < 2) {
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeSwitchToModeReq);
-        len =
-            client->req_len -
-            bytes_to_int32(sizeof(xXF86OldVidModeSwitchToModeReq));
-    }
-    else {
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeSwitchToModeReq);
-        len =
-            client->req_len -
-            bytes_to_int32(sizeof(xXF86VidModeSwitchToModeReq));
-    }
-    if (len != stuff->privsize)
-        return BadLength;
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!VidModeGetCurrentModeline(stuff->screen, &mode, &dotClock))
-        return BadValue;
-
-    if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock)
-        && MODEMATCH(mode, stuff))
-        return Success;
-
-    if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
-        return BadValue;
-
-    do {
-        if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY) {
-            ErrorF("Checking against clock: %d (%d)\n",
-                   VidModeGetModeValue(mode, VIDMODE_CLOCK), dotClock);
-            ErrorF("                 hdsp: %d hbeg: %d hend: %d httl: %d\n",
-                   VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
-                   VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
-                   VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
-                   VidModeGetModeValue(mode, VIDMODE_H_TOTAL));
-            ErrorF
-                ("                 vdsp: %d vbeg: %d vend: %d vttl: %d flags: %d\n",
-                 VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
-                 VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
-                 VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
-                 VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
-                 VidModeGetModeValue(mode, VIDMODE_FLAGS));
-        }
-        if ((VidModeGetDotClock(stuff->screen, stuff->dotclock) == dotClock) &&
-            MODEMATCH(mode, stuff)) {
-
-            if (!VidModeSwitchMode(stuff->screen, mode))
-                return BadValue;
-
-            if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
-                ErrorF("SwitchToMode - Succeeded\n");
-            return Success;
-        }
-    } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
-
-    return BadValue;
-}
-
-static int
-ProcXF86VidModeLockModeSwitch(ClientPtr client)
-{
-    REQUEST(xXF86VidModeLockModeSwitchReq);
-
-    REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
-
-    DEBUG_P("XF86VidModeLockModeSwitch");
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!VidModeLockZoom(stuff->screen, (short) stuff->lock))
-        return VidModeErrorBase + XF86VidModeZoomLocked;
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeGetMonitor(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetMonitorReq);
-    xXF86VidModeGetMonitorReply rep = {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence
-    };
-    CARD32 *hsyncdata, *vsyncdata;
-    int i, nHsync, nVrefresh;
-    pointer monitor;
-
-    DEBUG_P("XF86VidModeGetMonitor");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!VidModeGetMonitor(stuff->screen, &monitor))
-        return BadValue;
-
-    nHsync = VidModeGetMonitorValue(monitor, VIDMODE_MON_NHSYNC, 0).i;
-    nVrefresh = VidModeGetMonitorValue(monitor, VIDMODE_MON_NVREFRESH, 0).i;
-
-    if ((char *) (VidModeGetMonitorValue(monitor, VIDMODE_MON_VENDOR, 0)).ptr)
-        rep.vendorLength = strlen((char *) (VidModeGetMonitorValue(monitor,
-                                                                   VIDMODE_MON_VENDOR,
-                                                                   0)).ptr);
-    else
-        rep.vendorLength = 0;
-    if ((char *) (VidModeGetMonitorValue(monitor, VIDMODE_MON_MODEL, 0)).ptr)
-        rep.modelLength = strlen((char *) (VidModeGetMonitorValue(monitor,
-                                                                  VIDMODE_MON_MODEL,
-                                                                  0)).ptr);
-    else
-        rep.modelLength = 0;
-    rep.length =
-        bytes_to_int32(SIZEOF(xXF86VidModeGetMonitorReply) -
-                       SIZEOF(xGenericReply) + (nHsync +
-                                                nVrefresh) * sizeof(CARD32) +
-                       pad_to_int32(rep.vendorLength) +
-                       pad_to_int32(rep.modelLength));
-    rep.nhsync = nHsync;
-    rep.nvsync = nVrefresh;
-    hsyncdata = malloc(nHsync * sizeof(CARD32));
-    if (!hsyncdata) {
-        return BadAlloc;
-    }
-    vsyncdata = malloc(nVrefresh * sizeof(CARD32));
-
-    if (!vsyncdata) {
-        free(hsyncdata);
-        return BadAlloc;
-    }
-
-    for (i = 0; i < nHsync; i++) {
-        hsyncdata[i] = (unsigned short) (VidModeGetMonitorValue(monitor,
-                                                                VIDMODE_MON_HSYNC_LO,
-                                                                i)).f |
-            (unsigned
-             short) (VidModeGetMonitorValue(monitor, VIDMODE_MON_HSYNC_HI,
-                                            i)).f << 16;
-    }
-    for (i = 0; i < nVrefresh; i++) {
-        vsyncdata[i] = (unsigned short) (VidModeGetMonitorValue(monitor,
-                                                                VIDMODE_MON_VREFRESH_LO,
-                                                                i)).f |
-            (unsigned
-             short) (VidModeGetMonitorValue(monitor, VIDMODE_MON_VREFRESH_HI,
-                                            i)).f << 16;
-    }
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-    }
-    WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), &rep);
-    client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
-    WriteSwappedDataToClient(client, nHsync * sizeof(CARD32), hsyncdata);
-    WriteSwappedDataToClient(client, nVrefresh * sizeof(CARD32), vsyncdata);
-    if (rep.vendorLength)
-        WriteToClient(client, rep.vendorLength,
-                 (VidModeGetMonitorValue(monitor, VIDMODE_MON_VENDOR, 0)).ptr);
-    if (rep.modelLength)
-        WriteToClient(client, rep.modelLength,
-                 (VidModeGetMonitorValue(monitor, VIDMODE_MON_MODEL, 0)).ptr);
-
-    free(hsyncdata);
-    free(vsyncdata);
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeGetViewPort(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetViewPortReq);
-    xXF86VidModeGetViewPortReply rep;
-    int x, y;
-
-    DEBUG_P("XF86VidModeGetViewPort");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    VidModeGetViewPort(stuff->screen, &x, &y);
-
-    rep = (xXF86VidModeGetViewPortReply) {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = 0,
-        .x = x,
-        .y = y
-    };
-
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.x);
-        swapl(&rep.y);
-    }
-    WriteToClient(client, SIZEOF(xXF86VidModeGetViewPortReply), &rep);
-    return Success;
-}
-
-static int
-ProcXF86VidModeSetViewPort(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSetViewPortReq);
-
-    DEBUG_P("XF86VidModeSetViewPort");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!VidModeSetViewPort(stuff->screen, stuff->x, stuff->y))
-        return BadValue;
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeGetDotClocks(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetDotClocksReq);
-    xXF86VidModeGetDotClocksReply rep;
-    int n;
-    int numClocks;
-    CARD32 dotclock;
-    int *Clocks = NULL;
-    Bool ClockProg;
-
-    DEBUG_P("XF86VidModeGetDotClocks");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeGetDotClocksReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    numClocks = VidModeGetNumOfClocks(stuff->screen, &ClockProg);
-
-    rep = (xXF86VidModeGetDotClocksReply) {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = bytes_to_int32(SIZEOF(xXF86VidModeGetDotClocksReply)
-                                 - SIZEOF(xGenericReply) + numClocks),
-        .clocks = numClocks,
-        .maxclocks = MAXCLOCKS,
-        .flags = 0
-    };
-
-    if (!ClockProg) {
-        Clocks = calloc(numClocks, sizeof(int));
-        if (!Clocks)
-            return BadValue;
-        if (!VidModeGetClocks(stuff->screen, Clocks)) {
-            free(Clocks);
-            return BadValue;
-        }
-    }
-    if (ClockProg) {
-        rep.flags |= CLKFLAG_PROGRAMABLE;
-    }
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.clocks);
-        swapl(&rep.maxclocks);
-        swapl(&rep.flags);
-    }
-    WriteToClient(client, sizeof(xXF86VidModeGetDotClocksReply), &rep);
-    if (!ClockProg) {
-        for (n = 0; n < numClocks; n++) {
-            dotclock = *Clocks++;
-            if (client->swapped) {
-                WriteSwappedDataToClient(client, 4, (char *) &dotclock);
-            }
-            else {
-                WriteToClient(client, 4, &dotclock);
-            }
-        }
-    }
-
-    free(Clocks);
-    return Success;
-}
-
-static int
-ProcXF86VidModeSetGamma(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSetGammaReq);
-
-    DEBUG_P("XF86VidModeSetGamma");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeSetGammaReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!VidModeSetGamma(stuff->screen, ((float) stuff->red) / 10000.,
-                         ((float) stuff->green) / 10000.,
-                         ((float) stuff->blue) / 10000.))
-        return BadValue;
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeGetGamma(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetGammaReq);
-    xXF86VidModeGetGammaReply rep;
-    float red, green, blue;
-
-    DEBUG_P("XF86VidModeGetGamma");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!VidModeGetGamma(stuff->screen, &red, &green, &blue))
-        return BadValue;
-    rep = (xXF86VidModeGetGammaReply) {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = 0,
-        .red = (CARD32) (red * 10000.),
-        .green = (CARD32) (green * 10000.),
-        .blue = (CARD32) (blue * 10000.)
-    };
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.red);
-        swapl(&rep.green);
-        swapl(&rep.blue);
-    }
-    WriteToClient(client, sizeof(xXF86VidModeGetGammaReply), &rep);
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeSetGammaRamp(ClientPtr client)
-{
-    CARD16 *r, *g, *b;
-    int length;
-
-    REQUEST(xXF86VidModeSetGammaRampReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (stuff->size != VidModeGetGammaRampSize(stuff->screen))
-        return BadValue;
-
-    length = (stuff->size + 1) & ~1;
-
-    REQUEST_FIXED_SIZE(xXF86VidModeSetGammaRampReq, length * 6);
-
-    r = (CARD16 *) &stuff[1];
-    g = r + length;
-    b = g + length;
-
-    if (!VidModeSetGammaRamp(stuff->screen, stuff->size, r, g, b))
-        return BadValue;
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeGetGammaRamp(ClientPtr client)
-{
-    CARD16 *ramp = NULL;
-    int length;
-    size_t ramplen = 0;
-    xXF86VidModeGetGammaRampReply rep;
-
-    REQUEST(xXF86VidModeGetGammaRampReq);
-
-    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (stuff->size != VidModeGetGammaRampSize(stuff->screen))
-        return BadValue;
-
-    length = (stuff->size + 1) & ~1;
-
-    if (stuff->size) {
-        ramplen = length * 3 * sizeof(CARD16);
-        if (!(ramp = malloc(ramplen)))
-            return BadAlloc;
-
-        if (!VidModeGetGammaRamp(stuff->screen, stuff->size,
-                                 ramp, ramp + length, ramp + (length * 2))) {
-            free(ramp);
-            return BadValue;
-        }
-    }
-    rep = (xXF86VidModeGetGammaRampReply) {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = (length >> 1) * 3,
-        .size = stuff->size
-    };
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swaps(&rep.size);
-        SwapShorts((short *) ramp, length * 3);
-    }
-    WriteToClient(client, sizeof(xXF86VidModeGetGammaRampReply), &rep);
-
-    if (stuff->size) {
-        WriteToClient(client, ramplen, ramp);
-        free(ramp);
-    }
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeGetGammaRampSize(ClientPtr client)
-{
-    xXF86VidModeGetGammaRampSizeReply rep;
-
-    REQUEST(xXF86VidModeGetGammaRampSizeReq);
-
-    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampSizeReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    rep = (xXF86VidModeGetGammaRampSizeReply) {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = 0,
-        .size = VidModeGetGammaRampSize(stuff->screen)
-    };
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swaps(&rep.size);
-    }
-    WriteToClient(client, sizeof(xXF86VidModeGetGammaRampSizeReply), &rep);
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeGetPermissions(ClientPtr client)
-{
-    xXF86VidModeGetPermissionsReply rep =  {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = 0,
-        .permissions = XF86VM_READ_PERMISSION
-    };
-
-    REQUEST(xXF86VidModeGetPermissionsReq);
-
-    REQUEST_SIZE_MATCH(xXF86VidModeGetPermissionsReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (xf86GetVidModeEnabled() &&
-        (xf86GetVidModeAllowNonLocal() || LocalClient(client))) {
-        rep.permissions |= XF86VM_WRITE_PERMISSION;
-    }
-    if (client->swapped) {
-        swaps(&rep.sequenceNumber);
-        swapl(&rep.length);
-        swapl(&rep.permissions);
-    }
-    WriteToClient(client, sizeof(xXF86VidModeGetPermissionsReply), &rep);
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeSetClientVersion(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSetClientVersionReq);
-
-    VidModePrivPtr pPriv;
-
-    DEBUG_P("XF86VidModeSetClientVersion");
-
-    REQUEST_SIZE_MATCH(xXF86VidModeSetClientVersionReq);
-
-    if ((pPriv = VM_GETPRIV(client)) == NULL) {
-        pPriv = malloc(sizeof(VidModePrivRec));
-        if (!pPriv)
-            return BadAlloc;
-        VM_SETPRIV(client, pPriv);
-    }
-    pPriv->major = stuff->major;
-
-    pPriv->minor = stuff->minor;
-
-    return Success;
-}
-
-static int
-ProcXF86VidModeDispatch(ClientPtr client)
-{
-    REQUEST(xReq);
-    switch (stuff->data) {
-    case X_XF86VidModeQueryVersion:
-        return ProcXF86VidModeQueryVersion(client);
-    case X_XF86VidModeGetModeLine:
-        return ProcXF86VidModeGetModeLine(client);
-    case X_XF86VidModeGetMonitor:
-        return ProcXF86VidModeGetMonitor(client);
-    case X_XF86VidModeGetAllModeLines:
-        return ProcXF86VidModeGetAllModeLines(client);
-    case X_XF86VidModeValidateModeLine:
-        return ProcXF86VidModeValidateModeLine(client);
-    case X_XF86VidModeGetViewPort:
-        return ProcXF86VidModeGetViewPort(client);
-    case X_XF86VidModeGetDotClocks:
-        return ProcXF86VidModeGetDotClocks(client);
-    case X_XF86VidModeSetClientVersion:
-        return ProcXF86VidModeSetClientVersion(client);
-    case X_XF86VidModeGetGamma:
-        return ProcXF86VidModeGetGamma(client);
-    case X_XF86VidModeGetGammaRamp:
-        return ProcXF86VidModeGetGammaRamp(client);
-    case X_XF86VidModeGetGammaRampSize:
-        return ProcXF86VidModeGetGammaRampSize(client);
-    case X_XF86VidModeGetPermissions:
-        return ProcXF86VidModeGetPermissions(client);
-    default:
-        if (!xf86GetVidModeEnabled())
-            return VidModeErrorBase + XF86VidModeExtensionDisabled;
-        if (xf86GetVidModeAllowNonLocal() || LocalClient(client)) {
-            switch (stuff->data) {
-            case X_XF86VidModeAddModeLine:
-                return ProcXF86VidModeAddModeLine(client);
-            case X_XF86VidModeDeleteModeLine:
-                return ProcXF86VidModeDeleteModeLine(client);
-            case X_XF86VidModeModModeLine:
-                return ProcXF86VidModeModModeLine(client);
-            case X_XF86VidModeSwitchMode:
-                return ProcXF86VidModeSwitchMode(client);
-            case X_XF86VidModeSwitchToMode:
-                return ProcXF86VidModeSwitchToMode(client);
-            case X_XF86VidModeLockModeSwitch:
-                return ProcXF86VidModeLockModeSwitch(client);
-            case X_XF86VidModeSetViewPort:
-                return ProcXF86VidModeSetViewPort(client);
-            case X_XF86VidModeSetGamma:
-                return ProcXF86VidModeSetGamma(client);
-            case X_XF86VidModeSetGammaRamp:
-                return ProcXF86VidModeSetGammaRamp(client);
-            default:
-                return BadRequest;
-            }
-        }
-        else
-            return VidModeErrorBase + XF86VidModeClientNotLocal;
-    }
-}
-
-static int
-SProcXF86VidModeQueryVersion(ClientPtr client)
-{
-    REQUEST(xXF86VidModeQueryVersionReq);
-    swaps(&stuff->length);
-    return ProcXF86VidModeQueryVersion(client);
-}
-
-static int
-SProcXF86VidModeGetModeLine(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetModeLineReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
-    swaps(&stuff->screen);
-    return ProcXF86VidModeGetModeLine(client);
-}
-
-static int
-SProcXF86VidModeGetAllModeLines(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetAllModeLinesReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetAllModeLinesReq);
-    swaps(&stuff->screen);
-    return ProcXF86VidModeGetAllModeLines(client);
-}
-
-static int
-SProcXF86VidModeAddModeLine(ClientPtr client)
-{
-    xXF86OldVidModeAddModeLineReq *oldstuff =
-        (xXF86OldVidModeAddModeLineReq *) client->requestBuffer;
-    int ver;
-
-    REQUEST(xXF86VidModeAddModeLineReq);
-    ver = ClientMajorVersion(client);
-    if (ver < 2) {
-        swaps(&oldstuff->length);
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeAddModeLineReq);
-        swapl(&oldstuff->screen);
-        swaps(&oldstuff->hdisplay);
-        swaps(&oldstuff->hsyncstart);
-        swaps(&oldstuff->hsyncend);
-        swaps(&oldstuff->htotal);
-        swaps(&oldstuff->vdisplay);
-        swaps(&oldstuff->vsyncstart);
-        swaps(&oldstuff->vsyncend);
-        swaps(&oldstuff->vtotal);
-        swapl(&oldstuff->flags);
-        swapl(&oldstuff->privsize);
-        SwapRestL(oldstuff);
-    }
-    else {
-        swaps(&stuff->length);
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
-        swapl(&stuff->screen);
-        swaps(&stuff->hdisplay);
-        swaps(&stuff->hsyncstart);
-        swaps(&stuff->hsyncend);
-        swaps(&stuff->htotal);
-        swaps(&stuff->hskew);
-        swaps(&stuff->vdisplay);
-        swaps(&stuff->vsyncstart);
-        swaps(&stuff->vsyncend);
-        swaps(&stuff->vtotal);
-        swapl(&stuff->flags);
-        swapl(&stuff->privsize);
-        SwapRestL(stuff);
-    }
-    return ProcXF86VidModeAddModeLine(client);
-}
-
-static int
-SProcXF86VidModeDeleteModeLine(ClientPtr client)
-{
-    xXF86OldVidModeDeleteModeLineReq *oldstuff =
-        (xXF86OldVidModeDeleteModeLineReq *) client->requestBuffer;
-    int ver;
-
-    REQUEST(xXF86VidModeDeleteModeLineReq);
-    ver = ClientMajorVersion(client);
-    if (ver < 2) {
-        swaps(&oldstuff->length);
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeDeleteModeLineReq);
-        swapl(&oldstuff->screen);
-        swaps(&oldstuff->hdisplay);
-        swaps(&oldstuff->hsyncstart);
-        swaps(&oldstuff->hsyncend);
-        swaps(&oldstuff->htotal);
-        swaps(&oldstuff->vdisplay);
-        swaps(&oldstuff->vsyncstart);
-        swaps(&oldstuff->vsyncend);
-        swaps(&oldstuff->vtotal);
-        swapl(&oldstuff->flags);
-        swapl(&oldstuff->privsize);
-        SwapRestL(oldstuff);
-    }
-    else {
-        swaps(&stuff->length);
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
-        swapl(&stuff->screen);
-        swaps(&stuff->hdisplay);
-        swaps(&stuff->hsyncstart);
-        swaps(&stuff->hsyncend);
-        swaps(&stuff->htotal);
-        swaps(&stuff->hskew);
-        swaps(&stuff->vdisplay);
-        swaps(&stuff->vsyncstart);
-        swaps(&stuff->vsyncend);
-        swaps(&stuff->vtotal);
-        swapl(&stuff->flags);
-        swapl(&stuff->privsize);
-        SwapRestL(stuff);
-    }
-    return ProcXF86VidModeDeleteModeLine(client);
-}
-
-static int
-SProcXF86VidModeModModeLine(ClientPtr client)
-{
-    xXF86OldVidModeModModeLineReq *oldstuff =
-        (xXF86OldVidModeModModeLineReq *) client->requestBuffer;
-    int ver;
-
-    REQUEST(xXF86VidModeModModeLineReq);
-    ver = ClientMajorVersion(client);
-    if (ver < 2) {
-        swaps(&oldstuff->length);
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeModModeLineReq);
-        swapl(&oldstuff->screen);
-        swaps(&oldstuff->hdisplay);
-        swaps(&oldstuff->hsyncstart);
-        swaps(&oldstuff->hsyncend);
-        swaps(&oldstuff->htotal);
-        swaps(&oldstuff->vdisplay);
-        swaps(&oldstuff->vsyncstart);
-        swaps(&oldstuff->vsyncend);
-        swaps(&oldstuff->vtotal);
-        swapl(&oldstuff->flags);
-        swapl(&oldstuff->privsize);
-        SwapRestL(oldstuff);
-    }
-    else {
-        swaps(&stuff->length);
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
-        swapl(&stuff->screen);
-        swaps(&stuff->hdisplay);
-        swaps(&stuff->hsyncstart);
-        swaps(&stuff->hsyncend);
-        swaps(&stuff->htotal);
-        swaps(&stuff->hskew);
-        swaps(&stuff->vdisplay);
-        swaps(&stuff->vsyncstart);
-        swaps(&stuff->vsyncend);
-        swaps(&stuff->vtotal);
-        swapl(&stuff->flags);
-        swapl(&stuff->privsize);
-        SwapRestL(stuff);
-    }
-    return ProcXF86VidModeModModeLine(client);
-}
-
-static int
-SProcXF86VidModeValidateModeLine(ClientPtr client)
-{
-    xXF86OldVidModeValidateModeLineReq *oldstuff =
-        (xXF86OldVidModeValidateModeLineReq *) client->requestBuffer;
-    int ver;
-
-    REQUEST(xXF86VidModeValidateModeLineReq);
-    ver = ClientMajorVersion(client);
-    if (ver < 2) {
-        swaps(&oldstuff->length);
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeValidateModeLineReq);
-        swapl(&oldstuff->screen);
-        swaps(&oldstuff->hdisplay);
-        swaps(&oldstuff->hsyncstart);
-        swaps(&oldstuff->hsyncend);
-        swaps(&oldstuff->htotal);
-        swaps(&oldstuff->vdisplay);
-        swaps(&oldstuff->vsyncstart);
-        swaps(&oldstuff->vsyncend);
-        swaps(&oldstuff->vtotal);
-        swapl(&oldstuff->flags);
-        swapl(&oldstuff->privsize);
-        SwapRestL(oldstuff);
-    }
-    else {
-        swaps(&stuff->length);
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
-        swapl(&stuff->screen);
-        swaps(&stuff->hdisplay);
-        swaps(&stuff->hsyncstart);
-        swaps(&stuff->hsyncend);
-        swaps(&stuff->htotal);
-        swaps(&stuff->hskew);
-        swaps(&stuff->vdisplay);
-        swaps(&stuff->vsyncstart);
-        swaps(&stuff->vsyncend);
-        swaps(&stuff->vtotal);
-        swapl(&stuff->flags);
-        swapl(&stuff->privsize);
-        SwapRestL(stuff);
-    }
-    return ProcXF86VidModeValidateModeLine(client);
-}
-
-static int
-SProcXF86VidModeSwitchMode(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSwitchModeReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeSwitchModeReq);
-    swaps(&stuff->screen);
-    swaps(&stuff->zoom);
-    return ProcXF86VidModeSwitchMode(client);
-}
-
-static int
-SProcXF86VidModeSwitchToMode(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSwitchToModeReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeSwitchToModeReq);
-    swapl(&stuff->screen);
-    return ProcXF86VidModeSwitchToMode(client);
-}
-
-static int
-SProcXF86VidModeLockModeSwitch(ClientPtr client)
-{
-    REQUEST(xXF86VidModeLockModeSwitchReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeLockModeSwitchReq);
-    swaps(&stuff->screen);
-    swaps(&stuff->lock);
-    return ProcXF86VidModeLockModeSwitch(client);
-}
-
-static int
-SProcXF86VidModeGetMonitor(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetMonitorReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetMonitorReq);
-    swaps(&stuff->screen);
-    return ProcXF86VidModeGetMonitor(client);
-}
-
-static int
-SProcXF86VidModeGetViewPort(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetViewPortReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetViewPortReq);
-    swaps(&stuff->screen);
-    return ProcXF86VidModeGetViewPort(client);
-}
-
-static int
-SProcXF86VidModeSetViewPort(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSetViewPortReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeSetViewPortReq);
-    swaps(&stuff->screen);
-    swapl(&stuff->x);
-    swapl(&stuff->y);
-    return ProcXF86VidModeSetViewPort(client);
-}
-
-static int
-SProcXF86VidModeGetDotClocks(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetDotClocksReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetDotClocksReq);
-    swaps(&stuff->screen);
-    return ProcXF86VidModeGetDotClocks(client);
-}
-
-static int
-SProcXF86VidModeSetClientVersion(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSetClientVersionReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeSetClientVersionReq);
-    swaps(&stuff->major);
-    swaps(&stuff->minor);
-    return ProcXF86VidModeSetClientVersion(client);
-}
-
-static int
-SProcXF86VidModeSetGamma(ClientPtr client)
-{
-    REQUEST(xXF86VidModeSetGammaReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeSetGammaReq);
-    swaps(&stuff->screen);
-    swapl(&stuff->red);
-    swapl(&stuff->green);
-    swapl(&stuff->blue);
-    return ProcXF86VidModeSetGamma(client);
-}
-
-static int
-SProcXF86VidModeGetGamma(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetGammaReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaReq);
-    swaps(&stuff->screen);
-    return ProcXF86VidModeGetGamma(client);
-}
-
-static int
-SProcXF86VidModeSetGammaRamp(ClientPtr client)
-{
-    int length;
-
-    REQUEST(xXF86VidModeSetGammaRampReq);
-    swaps(&stuff->length);
-    REQUEST_AT_LEAST_SIZE(xXF86VidModeSetGammaRampReq);
-    swaps(&stuff->size);
-    swaps(&stuff->screen);
-    length = ((stuff->size + 1) & ~1) * 6;
-    REQUEST_FIXED_SIZE(xXF86VidModeSetGammaRampReq, length);
-    SwapRestS(stuff);
-    return ProcXF86VidModeSetGammaRamp(client);
-}
-
-static int
-SProcXF86VidModeGetGammaRamp(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetGammaRampReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampReq);
-    swaps(&stuff->size);
-    swaps(&stuff->screen);
-    return ProcXF86VidModeGetGammaRamp(client);
-}
-
-static int
-SProcXF86VidModeGetGammaRampSize(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetGammaRampSizeReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampSizeReq);
-    swaps(&stuff->screen);
-    return ProcXF86VidModeGetGammaRampSize(client);
-}
-
-static int
-SProcXF86VidModeGetPermissions(ClientPtr client)
-{
-    REQUEST(xXF86VidModeGetPermissionsReq);
-    swaps(&stuff->length);
-    REQUEST_SIZE_MATCH(xXF86VidModeGetPermissionsReq);
-    swaps(&stuff->screen);
-    return ProcXF86VidModeGetPermissions(client);
-}
-
-static int
-SProcXF86VidModeDispatch(ClientPtr client)
-{
-    REQUEST(xReq);
-    switch (stuff->data) {
-    case X_XF86VidModeQueryVersion:
-        return SProcXF86VidModeQueryVersion(client);
-    case X_XF86VidModeGetModeLine:
-        return SProcXF86VidModeGetModeLine(client);
-    case X_XF86VidModeGetMonitor:
-        return SProcXF86VidModeGetMonitor(client);
-    case X_XF86VidModeGetAllModeLines:
-        return SProcXF86VidModeGetAllModeLines(client);
-    case X_XF86VidModeGetViewPort:
-        return SProcXF86VidModeGetViewPort(client);
-    case X_XF86VidModeValidateModeLine:
-        return SProcXF86VidModeValidateModeLine(client);
-    case X_XF86VidModeGetDotClocks:
-        return SProcXF86VidModeGetDotClocks(client);
-    case X_XF86VidModeSetClientVersion:
-        return SProcXF86VidModeSetClientVersion(client);
-    case X_XF86VidModeGetGamma:
-        return SProcXF86VidModeGetGamma(client);
-    case X_XF86VidModeGetGammaRamp:
-        return SProcXF86VidModeGetGammaRamp(client);
-    case X_XF86VidModeGetGammaRampSize:
-        return SProcXF86VidModeGetGammaRampSize(client);
-    case X_XF86VidModeGetPermissions:
-        return SProcXF86VidModeGetPermissions(client);
-    default:
-        if (!xf86GetVidModeEnabled())
-            return VidModeErrorBase + XF86VidModeExtensionDisabled;
-        if (xf86GetVidModeAllowNonLocal() || LocalClient(client)) {
-            switch (stuff->data) {
-            case X_XF86VidModeAddModeLine:
-                return SProcXF86VidModeAddModeLine(client);
-            case X_XF86VidModeDeleteModeLine:
-                return SProcXF86VidModeDeleteModeLine(client);
-            case X_XF86VidModeModModeLine:
-                return SProcXF86VidModeModModeLine(client);
-            case X_XF86VidModeSwitchMode:
-                return SProcXF86VidModeSwitchMode(client);
-            case X_XF86VidModeSwitchToMode:
-                return SProcXF86VidModeSwitchToMode(client);
-            case X_XF86VidModeLockModeSwitch:
-                return SProcXF86VidModeLockModeSwitch(client);
-            case X_XF86VidModeSetViewPort:
-                return SProcXF86VidModeSetViewPort(client);
-            case X_XF86VidModeSetGamma:
-                return SProcXF86VidModeSetGamma(client);
-            case X_XF86VidModeSetGammaRamp:
-                return SProcXF86VidModeSetGammaRamp(client);
-            default:
-                return BadRequest;
-            }
-        }
-        else
-            return VidModeErrorBase + XF86VidModeClientNotLocal;
-    }
-}
-
-void
-XFree86VidModeExtensionInit(void)
-{
-    ExtensionEntry *extEntry;
-    ScreenPtr pScreen;
-    int i;
-    Bool enabled = FALSE;
-
-    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
-
-    for (i = 0; i < screenInfo.numScreens; i++) {
-        pScreen = screenInfo.screens[i];
-        if (VidModeExtensionInit(pScreen))
-            enabled = TRUE;
-    }
-    /* This means that the DDX doesn't want the vidmode extension enabled */
-    if (!enabled)
-        return;
-
-    if (
-#ifdef XF86VIDMODE_EVENTS
-           EventType &&
-#endif
-           (extEntry = AddExtension(XF86VIDMODENAME,
-                                    XF86VidModeNumberEvents,
-                                    XF86VidModeNumberErrors,
-                                    ProcXF86VidModeDispatch,
-                                    SProcXF86VidModeDispatch,
-                                    NULL, StandardMinorOpcode))) {
-#if 0
-        XF86VidModeReqCode = (unsigned char) extEntry->base;
-#endif
-        VidModeErrorBase = extEntry->errorBase;
-#ifdef XF86VIDMODE_EVENTS
-        XF86VidModeEventBase = extEntry->eventBase;
-        EventSwapVector[XF86VidModeEventBase] =
-            (EventSwapPtr) SXF86VidModeNotifyEvent;
-#endif
-    }
-}
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index e06bf64..f3d7640 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -133,12 +133,9 @@ cat > sdksyms.c << EOF
 # include "xf86xvmc.h"
 # include "xf86xvpriv.h"
 #endif
-/* XF86VidMode code is in libextmod module */
-/*
 #if XF86VIDMODE
 # include "vidmodeproc.h"
 #endif
- */
 #include "xorgVersion.h"
 #if defined(__sparc__) || defined(__sparc)
 # include "xf86sbusBus.h"
commit 60f53e3012be795eee741ecd4be858552c5e86c8
Author: Tomas Carnecky <tom at dbservice.com>
Date:   Tue Jul 10 02:03:11 2012 +0100

    DGA: Remove excessive module-induced indirection
    
    The DGA event base used to have to be passed through a function pointer,
    as the code was cleaved in two with half in a module, and half in the
    core server.  Now that's not the case, just access DGAEventBase
    directly.
    
    v2: Deal with Alan's event initialization cleanups
    
    Signed-off-by: Tomas Carnecky <tom at dbservice.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/dgaproc.h b/hw/xfree86/common/dgaproc.h
index 2c2fae0..e824d30 100644
--- a/hw/xfree86/common/dgaproc.h
+++ b/hw/xfree86/common/dgaproc.h
@@ -107,9 +107,4 @@ extern _X_EXPORT Bool DGAChangePixmapMode(int Index, int *x, int *y, int mode);
 extern _X_EXPORT int DGACreateColormap(int Index, ClientPtr client, int id,
                                        int mode, int alloc);
 
-extern _X_EXPORT unsigned char DGAReqCode;
-extern _X_EXPORT int DGAErrorBase;
-extern _X_EXPORT int DGAEventBase;
-extern _X_EXPORT int *XDGAEventBase;
-
 #endif                          /* __DGAPROC_H */
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index 00b9022..a441dee 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -93,7 +93,9 @@ static void DGAHandleEvent(int screen_num, InternalEvent *event,
 static void
  DGACopyModeInfo(DGAModePtr mode, XDGAModePtr xmode);
 
-int *XDGAEventBase = NULL;
+static unsigned char DGAReqCode = 0;
+static int DGAErrorBase;
+static int DGAEventBase;
 
 #define DGA_GET_SCREEN_PRIV(pScreen) ((DGAScreenPtr) \
     dixLookupPrivate(&(pScreen)->devPrivates, &DGAScreenKeyRec))
@@ -1042,7 +1044,7 @@ DGAProcessKeyboardEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr keybd)
             .u.event.screen = pScreen->myNum,
             .u.event.state = ev.corestate
         };
-        de.u.u.type = *XDGAEventBase + GetCoreType(ev.type);
+        de.u.u.type = DGAEventBase + GetCoreType(ev.type);
         de.u.u.detail = event->detail;
 
         /* If the DGA client has selected input, then deliver based on the usual filter */
@@ -1093,7 +1095,7 @@ DGAProcessPointerEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr mouse)
             .u.event.screen = pScreen->myNum,
             .u.event.state = ev.corestate
         };
-        de.u.u.type = *XDGAEventBase + coreEquiv;
+        de.u.u.type = DGAEventBase + coreEquiv;
         de.u.u.detail = event->detail;
 
         /* If the DGA client has selected input, then deliver based on the usual filter */
@@ -1180,8 +1182,8 @@ DGAHandleEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
     DGAScreenPtr pScreenPriv;
 
     /* no DGA */
-    if (!DGAScreenKeyRegistered || XDGAEventBase == 0)
-        return;
+    if (!DGAScreenKeyRegistered || noXFree86DGAExtension)
+	return;
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
     /* DGA not initialized on this screen */
@@ -1210,10 +1212,6 @@ static void XDGAResetProc(ExtensionEntry * extEntry);
 
 static void DGAClientStateChange(CallbackListPtr *, pointer, pointer);
 
-unsigned char DGAReqCode = 0;
-int DGAErrorBase;
-int DGAEventBase;
-
 static DevPrivateKeyRec DGAScreenPrivateKeyRec;
 
 #define DGAScreenPrivateKey (&DGAScreenPrivateKeyRec)
@@ -2170,12 +2168,6 @@ ProcXDGADispatch(ClientPtr client)
 }
 
 void
-XFree86DGARegister(void)
-{
-    XDGAEventBase = &DGAEventBase;
-}
-
-void
 XFree86DGAExtensionInit(void)
 {
     ExtensionEntry *extEntry;
diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c
index 7a84988..5ee6be8 100644
--- a/hw/xfree86/common/xf86Extensions.c
+++ b/hw/xfree86/common/xf86Extensions.c
@@ -54,7 +54,7 @@ static ExtensionModule extensionModules[] = {
 	XFree86DGAExtensionInit,
 	XF86DGANAME,
 	&noXFree86DGAExtension,
-	XFree86DGARegister,
+	NULL,
 	NULL
     },
 #endif
commit 7a5880bc3b47e1f90a638f056ad4d40be6931977
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:10 2012 +0100

    Move DGA from extmod to built-in
    
    Rather than leave DGA languishing in extmod, move it to be a built-in
    extension.  As it's quite specific to the Xorg DDX, just move it
    sideways to the rest of the DGA code in hw/xfree86/common, and
    initialise it from xf86ExtensionInit, rather than miinitext.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Acked-by:  Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index 556b9cc..ea98449 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -20,6 +20,7 @@ endif
 
 if DGA
 DGASOURCES = xf86DGA.c
+DGA_SDK = dgaproc.h
 endif
 
 if XORG_BUS_PLATFORM
@@ -60,7 +61,7 @@ INCLUDES = $(XORG_INCS) -I$(srcdir)/../ddc -I$(srcdir)/../i2c \
 sdk_HEADERS = compiler.h fourcc.h xf86.h xf86Module.h xf86Opt.h \
               xf86PciInfo.h xf86Priv.h xf86Privstr.h \
               xf86cmap.h xf86fbman.h xf86str.h xf86Xinput.h xisb.h \
-              $(XVSDKINCS) $(XF86VMODE_SDK) xorgVersion.h \
+              $(XVSDKINCS) $(XF86VMODE_SDK) $(DGA_SDK) xorgVersion.h \
               xf86sbusBus.h xf86VGAarbiter.h xf86Optionstr.h xf86platformBus.h
 
 DISTCLEANFILES = xf86Build.h
diff --git a/hw/xfree86/common/dgaproc.h b/hw/xfree86/common/dgaproc.h
new file mode 100644
index 0000000..2c2fae0
--- /dev/null
+++ b/hw/xfree86/common/dgaproc.h
@@ -0,0 +1,115 @@
+
+#ifndef __DGAPROC_H
+#define __DGAPROC_H
+
+#include <X11/Xproto.h>
+#include "pixmap.h"
+
+#define DGA_CONCURRENT_ACCESS	0x00000001
+#define DGA_FILL_RECT		0x00000002
+#define DGA_BLIT_RECT		0x00000004
+#define DGA_BLIT_RECT_TRANS	0x00000008
+#define DGA_PIXMAP_AVAILABLE	0x00000010
+
+#define DGA_INTERLACED		0x00010000
+#define DGA_DOUBLESCAN		0x00020000
+
+#define DGA_FLIP_IMMEDIATE	0x00000001
+#define DGA_FLIP_RETRACE	0x00000002
+
+#define DGA_COMPLETED		0x00000000
+#define DGA_PENDING		0x00000001
+
+#define DGA_NEED_ROOT		0x00000001
+
+typedef struct {
+    int num;                    /* A unique identifier for the mode (num > 0) */
+    char *name;                 /* name of mode given in the XF86Config */
+    int VSync_num;
+    int VSync_den;
+    int flags;                  /* DGA_CONCURRENT_ACCESS, etc... */
+    int imageWidth;             /* linear accessible portion (pixels) */
+    int imageHeight;
+    int pixmapWidth;            /* Xlib accessible portion (pixels) */
+    int pixmapHeight;           /* both fields ignored if no concurrent access */
+    int bytesPerScanline;
+    int byteOrder;              /* MSBFirst, LSBFirst */
+    int depth;
+    int bitsPerPixel;
+    unsigned long red_mask;
+    unsigned long green_mask;
+    unsigned long blue_mask;
+    short visualClass;
+    int viewportWidth;
+    int viewportHeight;
+    int xViewportStep;          /* viewport position granularity */
+    int yViewportStep;
+    int maxViewportX;           /* max viewport origin */
+    int maxViewportY;
+    int viewportFlags;          /* types of page flipping possible */
+    int offset;
+    int reserved1;
+    int reserved2;
+} XDGAModeRec, *XDGAModePtr;
+
+/* DDX interface */
+
+extern _X_EXPORT int
+ DGASetMode(int Index, int num, XDGAModePtr mode, PixmapPtr *pPix);
+
+extern _X_EXPORT void
+ DGASetInputMode(int Index, Bool keyboard, Bool mouse);
+
+extern _X_EXPORT void
+ DGASelectInput(int Index, ClientPtr client, long mask);
+
+extern _X_EXPORT Bool DGAAvailable(int Index);
+extern _X_EXPORT Bool DGAScreenAvailable(ScreenPtr pScreen);
+extern _X_EXPORT Bool DGAActive(int Index);
+extern _X_EXPORT void DGAShutdown(void);
+extern _X_EXPORT void DGAInstallCmap(ColormapPtr cmap);
+extern _X_EXPORT int DGAGetViewportStatus(int Index);
+extern _X_EXPORT int DGASync(int Index);
+
+extern _X_EXPORT int
+ DGAFillRect(int Index, int x, int y, int w, int h, unsigned long color);
+
+extern _X_EXPORT int
+ DGABlitRect(int Index, int srcx, int srcy, int w, int h, int dstx, int dsty);
+
+extern _X_EXPORT int
+
+DGABlitTransRect(int Index,
+                 int srcx, int srcy,
+                 int w, int h, int dstx, int dsty, unsigned long color);
+
+extern _X_EXPORT int
+ DGASetViewport(int Index, int x, int y, int mode);
+
+extern _X_EXPORT int DGAGetModes(int Index);
+extern _X_EXPORT int DGAGetOldDGAMode(int Index);
+
+extern _X_EXPORT int DGAGetModeInfo(int Index, XDGAModePtr mode, int num);
+
+extern _X_EXPORT Bool DGAVTSwitch(void);
+extern _X_EXPORT Bool DGAStealButtonEvent(DeviceIntPtr dev, int Index,
+                                          int button, int is_down);
+extern _X_EXPORT Bool DGAStealMotionEvent(DeviceIntPtr dev, int Index, int dx,
+                                          int dy);
+extern _X_EXPORT Bool DGAStealKeyEvent(DeviceIntPtr dev, int Index,
+                                       int key_code, int is_down);
+
+extern _X_EXPORT Bool DGAOpenFramebuffer(int Index, char **name,
+                                         unsigned char **mem, int *size,
+                                         int *offset, int *flags);
+extern _X_EXPORT void DGACloseFramebuffer(int Index);
+extern _X_EXPORT Bool DGAChangePixmapMode(int Index, int *x, int *y, int mode);
+extern _X_EXPORT int DGACreateColormap(int Index, ClientPtr client, int id,
+                                       int mode, int alloc);
+
+extern _X_EXPORT unsigned char DGAReqCode;
+extern _X_EXPORT int DGAErrorBase;
+extern _X_EXPORT int DGAEventBase;
+extern _X_EXPORT int *XDGAEventBase;
+
+#endif                          /* __DGAPROC_H */
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index ab172a8..00b9022 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -1,4 +1,6 @@
 /*
+ * Copyright (c) 1995  Jon Tombs
+ * Copyright (c) 1995, 1996, 1999  XFree86 Inc
  * Copyright (c) 1998-2002 by The XFree86 Project, Inc.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -27,10 +29,20 @@
  * Written by Mark Vojkovich
  */
 
+/*
+ * This is quite literally just two files glued together:
+ * hw/xfree86/common/xf86DGA.c is the first part, and
+ * hw/xfree86/dixmods/extmod/xf86dga2.c is the second part.  One day, if
+ * someone actually cares about DGA, it'd be nice to clean this up.  But trust
+ * me, I am not that person.
+ */
+
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
 
+#include <X11/X.h>
+#include <X11/Xproto.h>
 #include "xf86.h"
 #include "xf86str.h"
 #include "xf86Priv.h"
@@ -48,9 +60,24 @@
 #include "exevents.h"
 #include "eventstr.h"
 #include "eventconvert.h"
+#include "xf86Extensions.h"
 
 #include "mi.h"
 
+#include "misc.h"
+#include "dixstruct.h"
+#include "dixevents.h"
+#include "extnsionst.h"
+#include "cursorstr.h"
+#include "scrnintstr.h"
+#include "swaprep.h"
+#include "dgaproc.h"
+#include "protocol-versions.h"
+
+#include <string.h>
+
+#define DGA_PROTOCOL_OLD_SUPPORT 1
+
 static DevPrivateKeyRec DGAScreenKeyRec;
 
 #define DGAScreenKeyRegistered dixPrivateKeyRegistered(&DGAScreenKeyRec)
@@ -1178,3 +1205,999 @@ DGAHandleEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device)
         break;
     }
 }
+
+static void XDGAResetProc(ExtensionEntry * extEntry);
+
+static void DGAClientStateChange(CallbackListPtr *, pointer, pointer);
+
+unsigned char DGAReqCode = 0;
+int DGAErrorBase;
+int DGAEventBase;
+
+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 */
+typedef struct {
+    int major;
+    int minor;
+} DGAPrivRec, *DGAPrivPtr;
+
+#define DGA_GETCLIENT(idx) ((ClientPtr) \
+    dixLookupPrivate(&screenInfo.screens[idx]->devPrivates, DGAScreenPrivateKey))
+#define DGA_SETCLIENT(idx,p) \
+    dixSetPrivate(&screenInfo.screens[idx]->devPrivates, DGAScreenPrivateKey, p)
+
+#define DGA_GETPRIV(c) ((DGAPrivPtr) \
+    dixLookupPrivate(&(c)->devPrivates, DGAClientPrivateKey))
+#define DGA_SETPRIV(c,p) \
+    dixSetPrivate(&(c)->devPrivates, DGAClientPrivateKey, p)
+
+static void
+XDGAResetProc(ExtensionEntry * extEntry)
+{
+    DeleteCallback(&ClientStateCallback, DGAClientStateChange, NULL);
+    DGACallbackRefCount = 0;
+}
+
+static int
+ProcXDGAQueryVersion(ClientPtr client)
+{
+    xXDGAQueryVersionReply rep;
+
+    REQUEST_SIZE_MATCH(xXDGAQueryVersionReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.majorVersion = SERVER_XDGA_MAJOR_VERSION;
+    rep.minorVersion = SERVER_XDGA_MINOR_VERSION;
+
+    WriteToClient(client, sizeof(xXDGAQueryVersionReply), (char *) &rep);
+    return Success;
+}
+
+static int
+ProcXDGAOpenFramebuffer(ClientPtr client)
+{
+    REQUEST(xXDGAOpenFramebufferReq);
+    xXDGAOpenFramebufferReply rep;
+    char *deviceName;
+    int nameSize;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!DGAAvailable(stuff->screen))
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    REQUEST_SIZE_MATCH(xXDGAOpenFramebufferReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    if (!DGAOpenFramebuffer(stuff->screen, &deviceName,
+                            (unsigned char **) (&rep.mem1),
+                            (int *) &rep.size, (int *) &rep.offset,
+                            (int *) &rep.extra)) {
+        return BadAlloc;
+    }
+
+    nameSize = deviceName ? (strlen(deviceName) + 1) : 0;
+    rep.length = bytes_to_int32(nameSize);
+
+    WriteToClient(client, sizeof(xXDGAOpenFramebufferReply), (char *) &rep);
+    if (rep.length)
+        WriteToClient(client, nameSize, deviceName);
+
+    return Success;
+}
+
+static int
+ProcXDGACloseFramebuffer(ClientPtr client)
+{
+    REQUEST(xXDGACloseFramebufferReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (!DGAAvailable(stuff->screen))
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    REQUEST_SIZE_MATCH(xXDGACloseFramebufferReq);
+
+    DGACloseFramebuffer(stuff->screen);
+
+    return Success;
+}
+
+static int
+ProcXDGAQueryModes(ClientPtr client)
+{
+    int i, num, size;
+
+    REQUEST(xXDGAQueryModesReq);
+    xXDGAQueryModesReply rep;
+    xXDGAModeInfo info;
+    XDGAModePtr mode;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    REQUEST_SIZE_MATCH(xXDGAQueryModesReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.number = 0;
+    rep.sequenceNumber = client->sequence;
+
+    if (!DGAAvailable(stuff->screen)) {
+        rep.number = 0;
+        rep.length = 0;
+        WriteToClient(client, sz_xXDGAQueryModesReply, (char *) &rep);
+        return Success;
+    }
+
+    if (!(num = DGAGetModes(stuff->screen))) {
+        WriteToClient(client, sz_xXDGAQueryModesReply, (char *) &rep);
+        return Success;
+    }
+
+    if (!(mode = (XDGAModePtr) malloc(num * sizeof(XDGAModeRec))))
+        return BadAlloc;
+
+    for (i = 0; i < num; i++)
+        DGAGetModeInfo(stuff->screen, mode + i, i + 1);
+
+    size = num * sz_xXDGAModeInfo;
+    for (i = 0; i < num; i++)
+        size += pad_to_int32(strlen(mode[i].name) + 1); /* plus NULL */
+
+    rep.number = num;
+    rep.length = bytes_to_int32(size);
+
+    WriteToClient(client, sz_xXDGAQueryModesReply, (char *) &rep);
+
+    for (i = 0; i < num; i++) {
+        size = strlen(mode[i].name) + 1;
+
+        info.byte_order = mode[i].byteOrder;
+        info.depth = mode[i].depth;
+        info.num = mode[i].num;
+        info.bpp = mode[i].bitsPerPixel;
+        info.name_size = (size + 3) & ~3L;
+        info.vsync_num = mode[i].VSync_num;
+        info.vsync_den = mode[i].VSync_den;
+        info.flags = mode[i].flags;
+        info.image_width = mode[i].imageWidth;
+        info.image_height = mode[i].imageHeight;
+        info.pixmap_width = mode[i].pixmapWidth;
+        info.pixmap_height = mode[i].pixmapHeight;
+        info.bytes_per_scanline = mode[i].bytesPerScanline;
+        info.red_mask = mode[i].red_mask;
+        info.green_mask = mode[i].green_mask;
+        info.blue_mask = mode[i].blue_mask;
+        info.visual_class = mode[i].visualClass;
+        info.viewport_width = mode[i].viewportWidth;
+        info.viewport_height = mode[i].viewportHeight;
+        info.viewport_xstep = mode[i].xViewportStep;
+        info.viewport_ystep = mode[i].yViewportStep;
+        info.viewport_xmax = mode[i].maxViewportX;
+        info.viewport_ymax = mode[i].maxViewportY;
+        info.viewport_flags = mode[i].viewportFlags;
+        info.reserved1 = mode[i].reserved1;
+        info.reserved2 = mode[i].reserved2;
+
+        WriteToClient(client, sz_xXDGAModeInfo, (char *) (&info));
+        WriteToClient(client, size, mode[i].name);
+    }
+
+    free(mode);
+
+    return Success;
+}
+
+static void
+DGAClientStateChange(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
+{
+    NewClientInfoRec *pci = (NewClientInfoRec *) calldata;
+    ClientPtr client = NULL;
+    int i;
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+        if (DGA_GETCLIENT(i) == pci->client) {
+            client = pci->client;
+            break;
+        }
+    }
+
+    if (client &&
+        ((client->clientState == ClientStateGone) ||
+         (client->clientState == ClientStateRetained))) {
+        XDGAModeRec mode;
+        PixmapPtr pPix;
+
+        DGA_SETCLIENT(i, NULL);
+        DGASelectInput(i, NULL, 0);
+        DGASetMode(i, 0, &mode, &pPix);
+
+        if (--DGACallbackRefCount == 0)
+            DeleteCallback(&ClientStateCallback, DGAClientStateChange, NULL);
+    }
+}
+
+static int
+ProcXDGASetMode(ClientPtr client)
+{
+    REQUEST(xXDGASetModeReq);
+    xXDGASetModeReply rep;
+    XDGAModeRec mode;
+    xXDGAModeInfo info;
+    PixmapPtr pPix;
+    ClientPtr owner;
+    int size;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+    owner = DGA_GETCLIENT(stuff->screen);
+
+    REQUEST_SIZE_MATCH(xXDGASetModeReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.offset = 0;
+    rep.flags = 0;
+    rep.sequenceNumber = client->sequence;
+
+    if (!DGAAvailable(stuff->screen))
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    if (owner && owner != client)
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    if (!stuff->mode) {
+        if (owner) {
+            if (--DGACallbackRefCount == 0)
+                DeleteCallback(&ClientStateCallback, DGAClientStateChange,
+                               NULL);
+        }
+        DGA_SETCLIENT(stuff->screen, NULL);
+        DGASelectInput(stuff->screen, NULL, 0);
+        DGASetMode(stuff->screen, 0, &mode, &pPix);
+        WriteToClient(client, sz_xXDGASetModeReply, (char *) &rep);
+        return Success;
+    }
+
+    if (Success != DGASetMode(stuff->screen, stuff->mode, &mode, &pPix))
+        return BadValue;
+
+    if (!owner) {
+        if (DGACallbackRefCount++ == 0)
+            AddCallback(&ClientStateCallback, DGAClientStateChange, NULL);
+    }
+
+    DGA_SETCLIENT(stuff->screen, client);
+
+    if (pPix) {
+        if (AddResource(stuff->pid, RT_PIXMAP, (pointer) (pPix))) {
+            pPix->drawable.id = (int) stuff->pid;
+            rep.flags = DGA_PIXMAP_AVAILABLE;
+        }
+    }
+
+    size = strlen(mode.name) + 1;
+
+    info.byte_order = mode.byteOrder;
+    info.depth = mode.depth;
+    info.num = mode.num;
+    info.bpp = mode.bitsPerPixel;
+    info.name_size = (size + 3) & ~3L;
+    info.vsync_num = mode.VSync_num;
+    info.vsync_den = mode.VSync_den;
+    info.flags = mode.flags;
+    info.image_width = mode.imageWidth;
+    info.image_height = mode.imageHeight;
+    info.pixmap_width = mode.pixmapWidth;
+    info.pixmap_height = mode.pixmapHeight;
+    info.bytes_per_scanline = mode.bytesPerScanline;
+    info.red_mask = mode.red_mask;
+    info.green_mask = mode.green_mask;
+    info.blue_mask = mode.blue_mask;
+    info.visual_class = mode.visualClass;
+    info.viewport_width = mode.viewportWidth;
+    info.viewport_height = mode.viewportHeight;
+    info.viewport_xstep = mode.xViewportStep;
+    info.viewport_ystep = mode.yViewportStep;
+    info.viewport_xmax = mode.maxViewportX;
+    info.viewport_ymax = mode.maxViewportY;
+    info.viewport_flags = mode.viewportFlags;
+    info.reserved1 = mode.reserved1;
+    info.reserved2 = mode.reserved2;
+
+    rep.length = bytes_to_int32(sz_xXDGAModeInfo + info.name_size);
+
+    WriteToClient(client, sz_xXDGASetModeReply, (char *) &rep);
+    WriteToClient(client, sz_xXDGAModeInfo, (char *) (&info));
+    WriteToClient(client, size, mode.name);
+
+    return Success;
+}
+
+static int
+ProcXDGASetViewport(ClientPtr client)
+{
+    REQUEST(xXDGASetViewportReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGASetViewportReq);
+
+    DGASetViewport(stuff->screen, stuff->x, stuff->y, stuff->flags);
+
+    return Success;
+}
+
+static int
+ProcXDGAInstallColormap(ClientPtr client)
+{
+    ColormapPtr cmap;
+    int rc;
+
+    REQUEST(xXDGAInstallColormapReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGAInstallColormapReq);
+
+    rc = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, RT_COLORMAP,
+                                 client, DixInstallAccess);
+    if (rc != Success)
+        return rc;
+    DGAInstallCmap(cmap);
+    return Success;
+}
+
+static int
+ProcXDGASelectInput(ClientPtr client)
+{
+    REQUEST(xXDGASelectInputReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGASelectInputReq);
+
+    if (DGA_GETCLIENT(stuff->screen) == client)
+        DGASelectInput(stuff->screen, client, stuff->mask);
+
+    return Success;
+}
+
+static int
+ProcXDGAFillRectangle(ClientPtr client)
+{
+    REQUEST(xXDGAFillRectangleReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGAFillRectangleReq);
+
+    if (Success != DGAFillRect(stuff->screen, stuff->x, stuff->y,
+                               stuff->width, stuff->height, stuff->color))
+        return BadMatch;
+
+    return Success;
+}
+
+static int
+ProcXDGACopyArea(ClientPtr client)
+{
+    REQUEST(xXDGACopyAreaReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGACopyAreaReq);
+
+    if (Success != DGABlitRect(stuff->screen, stuff->srcx, stuff->srcy,
+                               stuff->width, stuff->height, stuff->dstx,
+                               stuff->dsty))
+        return BadMatch;
+
+    return Success;
+}
+
+static int
+ProcXDGACopyTransparentArea(ClientPtr client)
+{
+    REQUEST(xXDGACopyTransparentAreaReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGACopyTransparentAreaReq);
+
+    if (Success != DGABlitTransRect(stuff->screen, stuff->srcx, stuff->srcy,
+                                    stuff->width, stuff->height, stuff->dstx,
+                                    stuff->dsty, stuff->key))
+        return BadMatch;
+
+    return Success;
+}
+
+static int
+ProcXDGAGetViewportStatus(ClientPtr client)
+{
+    REQUEST(xXDGAGetViewportStatusReq);
+    xXDGAGetViewportStatusReply rep;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGAGetViewportStatusReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    rep.status = DGAGetViewportStatus(stuff->screen);
+
+    WriteToClient(client, sizeof(xXDGAGetViewportStatusReply), (char *) &rep);
+    return Success;
+}
+
+static int
+ProcXDGASync(ClientPtr client)
+{
+    REQUEST(xXDGASyncReq);
+    xXDGASyncReply rep;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGASyncReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    DGASync(stuff->screen);
+
+    WriteToClient(client, sizeof(xXDGASyncReply), (char *) &rep);
+    return Success;
+}
+
+static int
+ProcXDGASetClientVersion(ClientPtr client)
+{
+    REQUEST(xXDGASetClientVersionReq);
+
+    DGAPrivPtr pPriv;
+
+    REQUEST_SIZE_MATCH(xXDGASetClientVersionReq);
+    if ((pPriv = DGA_GETPRIV(client)) == NULL) {
+        pPriv = malloc(sizeof(DGAPrivRec));
+        /* XXX Need to look into freeing this */
+        if (!pPriv)
+            return BadAlloc;
+        DGA_SETPRIV(client, pPriv);
+    }
+    pPriv->major = stuff->major;
+    pPriv->minor = stuff->minor;
+
+    return Success;
+}
+
+static int
+ProcXDGAChangePixmapMode(ClientPtr client)
+{
+    REQUEST(xXDGAChangePixmapModeReq);
+    xXDGAChangePixmapModeReply rep;
+    int x, y;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGAChangePixmapModeReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    x = stuff->x;
+    y = stuff->y;
+
+    if (!DGAChangePixmapMode(stuff->screen, &x, &y, stuff->flags))
+        return BadMatch;
+
+    rep.x = x;
+    rep.y = y;
+    WriteToClient(client, sizeof(xXDGAChangePixmapModeReply), (char *) &rep);
+
+    return Success;
+}
+
+static int
+ProcXDGACreateColormap(ClientPtr client)
+{
+    REQUEST(xXDGACreateColormapReq);
+    int result;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXDGACreateColormapReq);
+
+    if (!stuff->mode)
+        return BadValue;
+
+    result = DGACreateColormap(stuff->screen, client, stuff->id,
+                               stuff->mode, stuff->alloc);
+    if (result != Success)
+        return result;
+
+    return Success;
+}
+
+/*
+ *
+ * Support for the old DGA protocol, used to live in xf86dga.c
+ *
+ */
+
+#ifdef DGA_PROTOCOL_OLD_SUPPORT
+
+static int
+ProcXF86DGAGetVideoLL(ClientPtr client)
+{
+    REQUEST(xXF86DGAGetVideoLLReq);
+    xXF86DGAGetVideoLLReply rep;
+    XDGAModeRec mode;
+    int num, offset, flags;
+    char *name;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    if (!DGAAvailable(stuff->screen))
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    if (!(num = DGAGetOldDGAMode(stuff->screen)))
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    /* get the parameters for the mode that best matches */
+    DGAGetModeInfo(stuff->screen, &mode, num);
+
+    if (!DGAOpenFramebuffer(stuff->screen, &name,
+                            (unsigned char **) (&rep.offset),
+                            (int *) (&rep.bank_size), &offset, &flags))
+        return BadAlloc;
+
+    rep.offset += mode.offset;
+    rep.width = mode.bytesPerScanline / (mode.bitsPerPixel >> 3);
+    rep.ram_size = rep.bank_size >> 10;
+
+    WriteToClient(client, SIZEOF(xXF86DGAGetVideoLLReply), (char *) &rep);
+    return Success;
+}
+
+static int
+ProcXF86DGADirectVideo(ClientPtr client)
+{
+    int num;
+    PixmapPtr pix;
+    XDGAModeRec mode;
+    ClientPtr owner;
+
+    REQUEST(xXF86DGADirectVideoReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+    REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
+
+    if (!DGAAvailable(stuff->screen))
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    owner = DGA_GETCLIENT(stuff->screen);
+
+    if (owner && owner != client)
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    if (stuff->enable & XF86DGADirectGraphics) {
+        if (!(num = DGAGetOldDGAMode(stuff->screen)))
+            return DGAErrorBase + XF86DGANoDirectVideoMode;
+    }
+    else
+        num = 0;
+
+    if (Success != DGASetMode(stuff->screen, num, &mode, &pix))
+        return DGAErrorBase + XF86DGAScreenNotActive;
+
+    DGASetInputMode(stuff->screen,
+                    (stuff->enable & XF86DGADirectKeyb) != 0,
+                    (stuff->enable & XF86DGADirectMouse) != 0);
+
+    /* We need to track the client and attach the teardown callback */
+    if (stuff->enable &
+        (XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse)) {
+        if (!owner) {
+            if (DGACallbackRefCount++ == 0)
+                AddCallback(&ClientStateCallback, DGAClientStateChange, NULL);
+        }
+
+        DGA_SETCLIENT(stuff->screen, client);
+    }
+    else {
+        if (owner) {
+            if (--DGACallbackRefCount == 0)
+                DeleteCallback(&ClientStateCallback, DGAClientStateChange,
+                               NULL);
+        }
+
+        DGA_SETCLIENT(stuff->screen, NULL);
+    }
+
+    return Success;
+}
+
+static int
+ProcXF86DGAGetViewPortSize(ClientPtr client)
+{
+    int num;
+    XDGAModeRec mode;
+
+    REQUEST(xXF86DGAGetViewPortSizeReq);
+    xXF86DGAGetViewPortSizeReply rep;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+
+    if (!DGAAvailable(stuff->screen))
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    if (!(num = DGAGetOldDGAMode(stuff->screen)))
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    DGAGetModeInfo(stuff->screen, &mode, num);
+
+    rep.width = mode.viewportWidth;
+    rep.height = mode.viewportHeight;
+
+    WriteToClient(client, SIZEOF(xXF86DGAGetViewPortSizeReply), (char *) &rep);
+    return Success;
+}
+
+static int
+ProcXF86DGASetViewPort(ClientPtr client)
+{
+    REQUEST(xXF86DGASetViewPortReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq);
+
+    if (!DGAAvailable(stuff->screen))
+        return DGAErrorBase + XF86DGANoDirectVideoMode;
+
+    if (!DGAActive(stuff->screen))
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    if (DGASetViewport(stuff->screen, stuff->x, stuff->y, DGA_FLIP_RETRACE)
+        != Success)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    return Success;
+}
+
+static int
+ProcXF86DGAGetVidPage(ClientPtr client)
+{
+    REQUEST(xXF86DGAGetVidPageReq);
+    xXF86DGAGetVidPageReply rep;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.vpage = 0;              /* silently fail */
+
+    WriteToClient(client, SIZEOF(xXF86DGAGetVidPageReply), (char *) &rep);
+    return Success;
+}
+
+static int
+ProcXF86DGASetVidPage(ClientPtr client)
+{
+    REQUEST(xXF86DGASetVidPageReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq);
+
+    /* silently fail */
+
+    return Success;
+}
+
+static int
+ProcXF86DGAInstallColormap(ClientPtr client)
+{
+    ColormapPtr pcmp;
+    int rc;
+
+    REQUEST(xXF86DGAInstallColormapReq);
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq);
+
+    if (!DGAActive(stuff->screen))
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    rc = dixLookupResourceByType((pointer *) &pcmp, stuff->id, RT_COLORMAP,
+                                 client, DixInstallAccess);
+    if (rc == Success) {
+        DGAInstallCmap(pcmp);
+        return Success;
+    }
+    else {
+        return rc;
+    }
+}
+
+static int
+ProcXF86DGAQueryDirectVideo(ClientPtr client)
+{
+    REQUEST(xXF86DGAQueryDirectVideoReq);
+    xXF86DGAQueryDirectVideoReply rep;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.flags = 0;
+
+    if (DGAAvailable(stuff->screen))
+        rep.flags = XF86DGADirectPresent;
+
+    WriteToClient(client, SIZEOF(xXF86DGAQueryDirectVideoReply), (char *) &rep);
+    return Success;
+}
+
+static int
+ProcXF86DGAViewPortChanged(ClientPtr client)
+{
+    REQUEST(xXF86DGAViewPortChangedReq);
+    xXF86DGAViewPortChangedReply rep;
+
+    if (stuff->screen >= screenInfo.numScreens)
+        return BadValue;
+
+    if (DGA_GETCLIENT(stuff->screen) != client)
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
+
+    if (!DGAActive(stuff->screen))
+        return DGAErrorBase + XF86DGADirectNotActivated;
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.result = 1;
+
+    WriteToClient(client, SIZEOF(xXF86DGAViewPortChangedReply), (char *) &rep);
+    return Success;
+}
+
+#endif                          /* DGA_PROTOCOL_OLD_SUPPORT */
+
+static int
+SProcXDGADispatch(ClientPtr client)
+{
+    return DGAErrorBase + XF86DGAClientNotLocal;
+}
+
+#if 0
+#define DGA_REQ_DEBUG
+#endif
+
+#ifdef DGA_REQ_DEBUG
+static char *dgaMinor[] = {
+    "QueryVersion",
+    "GetVideoLL",
+    "DirectVideo",
+    "GetViewPortSize",
+    "SetViewPort",
+    "GetVidPage",
+    "SetVidPage",
+    "InstallColormap",
+    "QueryDirectVideo",
+    "ViewPortChanged",
+    "10",
+    "11",
+    "QueryModes",
+    "SetMode",
+    "SetViewport",
+    "InstallColormap",
+    "SelectInput",
+    "FillRectangle",
+    "CopyArea",
+    "CopyTransparentArea",
+    "GetViewportStatus",
+    "Sync",
+    "OpenFramebuffer",
+    "CloseFramebuffer",
+    "SetClientVersion",
+    "ChangePixmapMode",
+    "CreateColormap",
+};
+#endif
+
+static int
+ProcXDGADispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+
+    if (!LocalClient(client))
+        return DGAErrorBase + XF86DGAClientNotLocal;
+
+#ifdef DGA_REQ_DEBUG
+    if (stuff->data <= X_XDGACreateColormap)
+        fprintf(stderr, "    DGA %s\n", dgaMinor[stuff->data]);
+#endif
+
+    switch (stuff->data) {
+        /*
+         * DGA2 Protocol
+         */
+    case X_XDGAQueryVersion:
+        return ProcXDGAQueryVersion(client);
+    case X_XDGAQueryModes:
+        return ProcXDGAQueryModes(client);
+    case X_XDGASetMode:
+        return ProcXDGASetMode(client);
+    case X_XDGAOpenFramebuffer:
+        return ProcXDGAOpenFramebuffer(client);
+    case X_XDGACloseFramebuffer:
+        return ProcXDGACloseFramebuffer(client);
+    case X_XDGASetViewport:
+        return ProcXDGASetViewport(client);
+    case X_XDGAInstallColormap:
+        return ProcXDGAInstallColormap(client);
+    case X_XDGASelectInput:
+        return ProcXDGASelectInput(client);
+    case X_XDGAFillRectangle:
+        return ProcXDGAFillRectangle(client);
+    case X_XDGACopyArea:
+        return ProcXDGACopyArea(client);
+    case X_XDGACopyTransparentArea:
+        return ProcXDGACopyTransparentArea(client);
+    case X_XDGAGetViewportStatus:
+        return ProcXDGAGetViewportStatus(client);
+    case X_XDGASync:
+        return ProcXDGASync(client);
+    case X_XDGASetClientVersion:
+        return ProcXDGASetClientVersion(client);
+    case X_XDGAChangePixmapMode:
+        return ProcXDGAChangePixmapMode(client);
+    case X_XDGACreateColormap:
+        return ProcXDGACreateColormap(client);
+        /*
+         * Old DGA Protocol
+         */
+#ifdef DGA_PROTOCOL_OLD_SUPPORT
+    case X_XF86DGAGetVideoLL:
+        return ProcXF86DGAGetVideoLL(client);
+    case X_XF86DGADirectVideo:
+        return ProcXF86DGADirectVideo(client);
+    case X_XF86DGAGetViewPortSize:
+        return ProcXF86DGAGetViewPortSize(client);
+    case X_XF86DGASetViewPort:
+        return ProcXF86DGASetViewPort(client);
+    case X_XF86DGAGetVidPage:
+        return ProcXF86DGAGetVidPage(client);
+    case X_XF86DGASetVidPage:
+        return ProcXF86DGASetVidPage(client);
+    case X_XF86DGAInstallColormap:
+        return ProcXF86DGAInstallColormap(client);
+    case X_XF86DGAQueryDirectVideo:
+        return ProcXF86DGAQueryDirectVideo(client);
+    case X_XF86DGAViewPortChanged:
+        return ProcXF86DGAViewPortChanged(client);
+#endif                          /* DGA_PROTOCOL_OLD_SUPPORT */
+    default:
+        return BadRequest;
+    }
+}
+
+void
+XFree86DGARegister(void)
+{
+    XDGAEventBase = &DGAEventBase;
+}
+
+void
+XFree86DGAExtensionInit(void)
+{
+    ExtensionEntry *extEntry;
+
+    if (!dixRegisterPrivateKey(&DGAClientPrivateKeyRec, PRIVATE_CLIENT, 0))
+        return;
+
+    if (!dixRegisterPrivateKey(&DGAScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
+        return;
+
+    if ((extEntry = AddExtension(XF86DGANAME,
+                                 XF86DGANumberEvents,
+                                 XF86DGANumberErrors,
+                                 ProcXDGADispatch,
+                                 SProcXDGADispatch,
+                                 XDGAResetProc, StandardMinorOpcode))) {
+        int i;
+
+        DGAReqCode = (unsigned char) extEntry->base;
+        DGAErrorBase = extEntry->errorBase;
+        DGAEventBase = extEntry->eventBase;
+        for (i = KeyPress; i <= MotionNotify; i++)
+            SetCriticalEvent(DGAEventBase + i);
+    }
+}
diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c
index aed0635..7a84988 100644
--- a/hw/xfree86/common/xf86Extensions.c
+++ b/hw/xfree86/common/xf86Extensions.c
@@ -41,10 +41,23 @@
 #include "xselinux.h"
 #endif
 
+#ifdef XFreeXDGA
+#include <X11/extensions/xf86dgaproto.h>
+#endif
+
 /*
  * DDX-specific extensions.
  */
 static ExtensionModule extensionModules[] = {
+#ifdef XFreeXDGA
+    {
+	XFree86DGAExtensionInit,
+	XF86DGANAME,
+	&noXFree86DGAExtension,
+	XFree86DGARegister,
+	NULL
+    },
+#endif
 };
 
 static void
@@ -52,6 +65,7 @@ load_extension_config(void)
 {
     XF86ConfModulePtr mod_con = xf86configptr->conf_modules;
     XF86LoadPtr modp;
+    int i;
 
     /* Only the best. */
     if (!mod_con)
diff --git a/hw/xfree86/dixmods/extmod/Makefile.am b/hw/xfree86/dixmods/extmod/Makefile.am
index 8436cb3..d3a9fc8 100644
--- a/hw/xfree86/dixmods/extmod/Makefile.am
+++ b/hw/xfree86/dixmods/extmod/Makefile.am
@@ -1,12 +1,6 @@
-sdk_HEADERS = dgaproc.h
-
 extsmoduledir = $(moduledir)/extensions
 extsmodule_LTLIBRARIES = libextmod.la
 
-if DGA
-DGA_SRCS = xf86dga2.c dgaproc.h
-endif
-
 if XF86VIDMODE
 XF86VMODE_SRCS = xf86vmode.c
 endif
@@ -19,6 +13,5 @@ INCLUDES = @XORG_INCS@ \
 
 libextmod_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
 libextmod_la_SOURCES = modinit.c \
-                       $(DGA_SRCS) \
                        $(XF86VMODE_SRCS)
 libextmod_la_LIBADD = $(top_builddir)/Xext/libXextmodule.la
diff --git a/hw/xfree86/dixmods/extmod/dgaproc.h b/hw/xfree86/dixmods/extmod/dgaproc.h
deleted file mode 100644
index 2c2fae0..0000000
--- a/hw/xfree86/dixmods/extmod/dgaproc.h
+++ /dev/null
@@ -1,115 +0,0 @@
-
-#ifndef __DGAPROC_H
-#define __DGAPROC_H
-
-#include <X11/Xproto.h>
-#include "pixmap.h"
-
-#define DGA_CONCURRENT_ACCESS	0x00000001
-#define DGA_FILL_RECT		0x00000002
-#define DGA_BLIT_RECT		0x00000004
-#define DGA_BLIT_RECT_TRANS	0x00000008
-#define DGA_PIXMAP_AVAILABLE	0x00000010
-
-#define DGA_INTERLACED		0x00010000
-#define DGA_DOUBLESCAN		0x00020000
-
-#define DGA_FLIP_IMMEDIATE	0x00000001
-#define DGA_FLIP_RETRACE	0x00000002
-
-#define DGA_COMPLETED		0x00000000
-#define DGA_PENDING		0x00000001
-
-#define DGA_NEED_ROOT		0x00000001
-
-typedef struct {
-    int num;                    /* A unique identifier for the mode (num > 0) */
-    char *name;                 /* name of mode given in the XF86Config */
-    int VSync_num;
-    int VSync_den;
-    int flags;                  /* DGA_CONCURRENT_ACCESS, etc... */
-    int imageWidth;             /* linear accessible portion (pixels) */
-    int imageHeight;
-    int pixmapWidth;            /* Xlib accessible portion (pixels) */
-    int pixmapHeight;           /* both fields ignored if no concurrent access */
-    int bytesPerScanline;
-    int byteOrder;              /* MSBFirst, LSBFirst */
-    int depth;
-    int bitsPerPixel;
-    unsigned long red_mask;
-    unsigned long green_mask;
-    unsigned long blue_mask;
-    short visualClass;
-    int viewportWidth;
-    int viewportHeight;
-    int xViewportStep;          /* viewport position granularity */
-    int yViewportStep;
-    int maxViewportX;           /* max viewport origin */
-    int maxViewportY;
-    int viewportFlags;          /* types of page flipping possible */
-    int offset;
-    int reserved1;
-    int reserved2;
-} XDGAModeRec, *XDGAModePtr;
-
-/* DDX interface */
-
-extern _X_EXPORT int
- DGASetMode(int Index, int num, XDGAModePtr mode, PixmapPtr *pPix);
-
-extern _X_EXPORT void
- DGASetInputMode(int Index, Bool keyboard, Bool mouse);
-
-extern _X_EXPORT void
- DGASelectInput(int Index, ClientPtr client, long mask);
-
-extern _X_EXPORT Bool DGAAvailable(int Index);
-extern _X_EXPORT Bool DGAScreenAvailable(ScreenPtr pScreen);
-extern _X_EXPORT Bool DGAActive(int Index);
-extern _X_EXPORT void DGAShutdown(void);
-extern _X_EXPORT void DGAInstallCmap(ColormapPtr cmap);
-extern _X_EXPORT int DGAGetViewportStatus(int Index);
-extern _X_EXPORT int DGASync(int Index);
-
-extern _X_EXPORT int
- DGAFillRect(int Index, int x, int y, int w, int h, unsigned long color);
-
-extern _X_EXPORT int
- DGABlitRect(int Index, int srcx, int srcy, int w, int h, int dstx, int dsty);
-
-extern _X_EXPORT int
-
-DGABlitTransRect(int Index,
-                 int srcx, int srcy,
-                 int w, int h, int dstx, int dsty, unsigned long color);
-
-extern _X_EXPORT int
- DGASetViewport(int Index, int x, int y, int mode);
-
-extern _X_EXPORT int DGAGetModes(int Index);
-extern _X_EXPORT int DGAGetOldDGAMode(int Index);
-
-extern _X_EXPORT int DGAGetModeInfo(int Index, XDGAModePtr mode, int num);
-
-extern _X_EXPORT Bool DGAVTSwitch(void);
-extern _X_EXPORT Bool DGAStealButtonEvent(DeviceIntPtr dev, int Index,
-                                          int button, int is_down);
-extern _X_EXPORT Bool DGAStealMotionEvent(DeviceIntPtr dev, int Index, int dx,
-                                          int dy);
-extern _X_EXPORT Bool DGAStealKeyEvent(DeviceIntPtr dev, int Index,
-                                       int key_code, int is_down);
-
-extern _X_EXPORT Bool DGAOpenFramebuffer(int Index, char **name,
-                                         unsigned char **mem, int *size,
-                                         int *offset, int *flags);
-extern _X_EXPORT void DGACloseFramebuffer(int Index);
-extern _X_EXPORT Bool DGAChangePixmapMode(int Index, int *x, int *y, int mode);
-extern _X_EXPORT int DGACreateColormap(int Index, ClientPtr client, int id,
-                                       int mode, int alloc);
-
-extern _X_EXPORT unsigned char DGAReqCode;
-extern _X_EXPORT int DGAErrorBase;
-extern _X_EXPORT int DGAEventBase;
-extern _X_EXPORT int *XDGAEventBase;
-
-#endif                          /* __DGAPROC_H */
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index e64d41a..f05a570 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -47,14 +47,6 @@ static ExtensionModule extensionModules[] = {
      NULL,
      NULL},
 #endif
-#ifdef XFreeXDGA
-    {
-     XFree86DGAExtensionInit,
-     XF86DGANAME,
-     &noXFree86DGAExtension,
-     XFree86DGARegister,
-     NULL},
-#endif
 };
 
 static XF86ModuleVersionInfo VersRec = {
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
deleted file mode 100644
index 808aa69..0000000
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ /dev/null
@@ -1,1044 +0,0 @@
-/*
- * Copyright (c) 1995  Jon Tombs
- * Copyright (c) 1995, 1996, 1999  XFree86 Inc
- * Copyright (c) 1999 - The XFree86 Project Inc.
- *
- * Written by Mark Vojkovich
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "dixstruct.h"
-#include "dixevents.h"
-#include "pixmapstr.h"
-#include "extnsionst.h"
-#include "xf86Extensions.h"
-#include "colormapst.h"
-#include "cursorstr.h"
-#include "scrnintstr.h"
-#include "servermd.h"
-#include <X11/extensions/xf86dgaproto.h>
-#include "swaprep.h"
-#include "dgaproc.h"
-#include "protocol-versions.h"
-
-#include <string.h>
-
-#include "extinit.h"
-
-#define DGA_PROTOCOL_OLD_SUPPORT 1
-
-static void XDGAResetProc(ExtensionEntry * extEntry);
-
-static void DGAClientStateChange(CallbackListPtr *, pointer, pointer);
-
-unsigned char DGAReqCode = 0;
-int DGAErrorBase;
-int DGAEventBase;
-
-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 */
-typedef struct {
-    int major;
-    int minor;
-} DGAPrivRec, *DGAPrivPtr;
-
-#define DGA_GETCLIENT(idx) ((ClientPtr) \
-    dixLookupPrivate(&screenInfo.screens[idx]->devPrivates, DGAScreenPrivateKey))
-#define DGA_SETCLIENT(idx,p) \
-    dixSetPrivate(&screenInfo.screens[idx]->devPrivates, DGAScreenPrivateKey, p)
-
-#define DGA_GETPRIV(c) ((DGAPrivPtr) \
-    dixLookupPrivate(&(c)->devPrivates, DGAClientPrivateKey))
-#define DGA_SETPRIV(c,p) \
-    dixSetPrivate(&(c)->devPrivates, DGAClientPrivateKey, p)
-
-static void
-XDGAResetProc(ExtensionEntry * extEntry)
-{
-    DeleteCallback(&ClientStateCallback, DGAClientStateChange, NULL);
-    DGACallbackRefCount = 0;
-}
-
-static int
-ProcXDGAQueryVersion(ClientPtr client)
-{
-    xXDGAQueryVersionReply rep = {
-        .type = X_Reply,
-        .sequenceNumber = client->sequence,
-        .length = 0,
-        .majorVersion = SERVER_XDGA_MAJOR_VERSION,
-        .minorVersion = SERVER_XDGA_MINOR_VERSION
-    };
-
-    REQUEST_SIZE_MATCH(xXDGAQueryVersionReq);
-
-    WriteToClient(client, sizeof(xXDGAQueryVersionReply), &rep);
-    return Success;
-}
-
-static int
-ProcXDGAOpenFramebuffer(ClientPtr client)
-{
-    REQUEST(xXDGAOpenFramebufferReq);
-    xXDGAOpenFramebufferReply rep = {
-        .type = X_Reply,
-        .length = 0,
-        .sequenceNumber = client->sequence
-    };
-    char *deviceName;
-    int nameSize;
-
-    REQUEST_SIZE_MATCH(xXDGAOpenFramebufferReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!DGAAvailable(stuff->screen))
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    if (!DGAOpenFramebuffer(stuff->screen, &deviceName,
-                            (unsigned char **) (&rep.mem1),
-                            (int *) &rep.size, (int *) &rep.offset,
-                            (int *) &rep.extra)) {
-        return BadAlloc;
-    }
-
-    nameSize = deviceName ? (strlen(deviceName) + 1) : 0;
-    rep.length = bytes_to_int32(nameSize);
-
-    WriteToClient(client, sizeof(xXDGAOpenFramebufferReply), &rep);
-    if (rep.length)
-        WriteToClient(client, nameSize, deviceName);
-
-    return Success;
-}
-
-static int
-ProcXDGACloseFramebuffer(ClientPtr client)
-{
-    REQUEST(xXDGACloseFramebufferReq);
-
-    REQUEST_SIZE_MATCH(xXDGACloseFramebufferReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!DGAAvailable(stuff->screen))
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    DGACloseFramebuffer(stuff->screen);
-
-    return Success;
-}
-
-static int
-ProcXDGAQueryModes(ClientPtr client)
-{
-    int i, num, size;
-
-    REQUEST(xXDGAQueryModesReq);
-    xXDGAQueryModesReply rep = {
-        .type = X_Reply,
-        .length = 0,
-        .number = 0,
-        .sequenceNumber = client->sequence
-    };
-    xXDGAModeInfo info;
-    XDGAModePtr mode;
-
-    REQUEST_SIZE_MATCH(xXDGAQueryModesReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!DGAAvailable(stuff->screen)) {
-        rep.number = 0;
-        rep.length = 0;
-        WriteToClient(client, sz_xXDGAQueryModesReply, &rep);
-        return Success;
-    }
-
-    if (!(num = DGAGetModes(stuff->screen))) {
-        WriteToClient(client, sz_xXDGAQueryModesReply, &rep);
-        return Success;
-    }
-
-    if (!(mode = (XDGAModePtr) malloc(num * sizeof(XDGAModeRec))))
-        return BadAlloc;
-
-    for (i = 0; i < num; i++)
-        DGAGetModeInfo(stuff->screen, mode + i, i + 1);
-
-    size = num * sz_xXDGAModeInfo;
-    for (i = 0; i < num; i++)
-        size += pad_to_int32(strlen(mode[i].name) + 1); /* plus NULL */
-
-    rep.number = num;
-    rep.length = bytes_to_int32(size);
-
-    WriteToClient(client, sz_xXDGAQueryModesReply, &rep);
-
-    for (i = 0; i < num; i++) {
-        size = strlen(mode[i].name) + 1;
-
-        info.byte_order = mode[i].byteOrder;
-        info.depth = mode[i].depth;
-        info.num = mode[i].num;
-        info.bpp = mode[i].bitsPerPixel;
-        info.name_size = (size + 3) & ~3L;
-        info.vsync_num = mode[i].VSync_num;
-        info.vsync_den = mode[i].VSync_den;
-        info.flags = mode[i].flags;
-        info.image_width = mode[i].imageWidth;
-        info.image_height = mode[i].imageHeight;
-        info.pixmap_width = mode[i].pixmapWidth;
-        info.pixmap_height = mode[i].pixmapHeight;
-        info.bytes_per_scanline = mode[i].bytesPerScanline;
-        info.red_mask = mode[i].red_mask;
-        info.green_mask = mode[i].green_mask;
-        info.blue_mask = mode[i].blue_mask;
-        info.visual_class = mode[i].visualClass;
-        info.viewport_width = mode[i].viewportWidth;
-        info.viewport_height = mode[i].viewportHeight;
-        info.viewport_xstep = mode[i].xViewportStep;
-        info.viewport_ystep = mode[i].yViewportStep;
-        info.viewport_xmax = mode[i].maxViewportX;
-        info.viewport_ymax = mode[i].maxViewportY;
-        info.viewport_flags = mode[i].viewportFlags;
-        info.reserved1 = mode[i].reserved1;
-        info.reserved2 = mode[i].reserved2;
-
-        WriteToClient(client, sz_xXDGAModeInfo, (&info));
-        WriteToClient(client, size, mode[i].name);
-    }
-
-    free(mode);
-
-    return Success;
-}
-
-static void
-DGAClientStateChange(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
-{
-    NewClientInfoRec *pci = (NewClientInfoRec *) calldata;
-    ClientPtr client = NULL;
-    int i;
-
-    for (i = 0; i < screenInfo.numScreens; i++) {
-        if (DGA_GETCLIENT(i) == pci->client) {
-            client = pci->client;
-            break;
-        }
-    }
-
-    if (client &&
-        ((client->clientState == ClientStateGone) ||
-         (client->clientState == ClientStateRetained))) {
-        XDGAModeRec mode;
-        PixmapPtr pPix;
-
-        DGA_SETCLIENT(i, NULL);
-        DGASelectInput(i, NULL, 0);
-        DGASetMode(i, 0, &mode, &pPix);
-
-        if (--DGACallbackRefCount == 0)
-            DeleteCallback(&ClientStateCallback, DGAClientStateChange, NULL);
-    }
-}
-
-static int
-ProcXDGASetMode(ClientPtr client)
-{
-    REQUEST(xXDGASetModeReq);
-    xXDGASetModeReply rep = {
-        .type = X_Reply,
-        .length = 0,
-        .offset = 0,
-        .flags = 0,
-        .sequenceNumber = client->sequence
-    };
-    XDGAModeRec mode;
-    xXDGAModeInfo info;
-    PixmapPtr pPix;
-    ClientPtr owner;
-    int size;
-
-    REQUEST_SIZE_MATCH(xXDGASetModeReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-    owner = DGA_GETCLIENT(stuff->screen);
-
-    if (!DGAAvailable(stuff->screen))
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    if (owner && owner != client)
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    if (!stuff->mode) {
-        if (owner) {
-            if (--DGACallbackRefCount == 0)
-                DeleteCallback(&ClientStateCallback, DGAClientStateChange,
-                               NULL);
-        }
-        DGA_SETCLIENT(stuff->screen, NULL);
-        DGASelectInput(stuff->screen, NULL, 0);
-        DGASetMode(stuff->screen, 0, &mode, &pPix);
-        WriteToClient(client, sz_xXDGASetModeReply, &rep);
-        return Success;
-    }
-
-    if (Success != DGASetMode(stuff->screen, stuff->mode, &mode, &pPix))
-        return BadValue;
-
-    if (!owner) {
-        if (DGACallbackRefCount++ == 0)
-            AddCallback(&ClientStateCallback, DGAClientStateChange, NULL);
-    }
-
-    DGA_SETCLIENT(stuff->screen, client);
-
-    if (pPix) {
-        if (AddResource(stuff->pid, RT_PIXMAP, (pointer) (pPix))) {
-            pPix->drawable.id = (int) stuff->pid;
-            rep.flags = DGA_PIXMAP_AVAILABLE;
-        }
-    }
-
-    size = strlen(mode.name) + 1;
-
-    info.byte_order = mode.byteOrder;
-    info.depth = mode.depth;
-    info.num = mode.num;
-    info.bpp = mode.bitsPerPixel;
-    info.name_size = (size + 3) & ~3L;
-    info.vsync_num = mode.VSync_num;
-    info.vsync_den = mode.VSync_den;
-    info.flags = mode.flags;
-    info.image_width = mode.imageWidth;
-    info.image_height = mode.imageHeight;
-    info.pixmap_width = mode.pixmapWidth;
-    info.pixmap_height = mode.pixmapHeight;
-    info.bytes_per_scanline = mode.bytesPerScanline;
-    info.red_mask = mode.red_mask;
-    info.green_mask = mode.green_mask;
-    info.blue_mask = mode.blue_mask;
-    info.visual_class = mode.visualClass;
-    info.viewport_width = mode.viewportWidth;
-    info.viewport_height = mode.viewportHeight;
-    info.viewport_xstep = mode.xViewportStep;
-    info.viewport_ystep = mode.yViewportStep;
-    info.viewport_xmax = mode.maxViewportX;
-    info.viewport_ymax = mode.maxViewportY;
-    info.viewport_flags = mode.viewportFlags;
-    info.reserved1 = mode.reserved1;
-    info.reserved2 = mode.reserved2;
-
-    rep.length = bytes_to_int32(sz_xXDGAModeInfo + info.name_size);
-
-    WriteToClient(client, sz_xXDGASetModeReply, &rep);
-    WriteToClient(client, sz_xXDGAModeInfo, (&info));
-    WriteToClient(client, size, mode.name);
-
-    return Success;
-}
-
-static int
-ProcXDGASetViewport(ClientPtr client)
-{
-    REQUEST(xXDGASetViewportReq);
-
-    REQUEST_SIZE_MATCH(xXDGASetViewportReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    DGASetViewport(stuff->screen, stuff->x, stuff->y, stuff->flags);
-
-    return Success;
-}
-
-static int
-ProcXDGAInstallColormap(ClientPtr client)
-{
-    ColormapPtr cmap;
-    int rc;
-
-    REQUEST(xXDGAInstallColormapReq);
-
-    REQUEST_SIZE_MATCH(xXDGAInstallColormapReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    rc = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, RT_COLORMAP,
-                                 client, DixInstallAccess);
-    if (rc != Success)
-        return rc;
-    DGAInstallCmap(cmap);
-    return Success;
-}
-
-static int
-ProcXDGASelectInput(ClientPtr client)
-{
-    REQUEST(xXDGASelectInputReq);
-
-    REQUEST_SIZE_MATCH(xXDGASelectInputReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    if (DGA_GETCLIENT(stuff->screen) == client)
-        DGASelectInput(stuff->screen, client, stuff->mask);
-
-    return Success;
-}
-
-static int
-ProcXDGAFillRectangle(ClientPtr client)
-{
-    REQUEST(xXDGAFillRectangleReq);
-
-    REQUEST_SIZE_MATCH(xXDGAFillRectangleReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    if (Success != DGAFillRect(stuff->screen, stuff->x, stuff->y,
-                               stuff->width, stuff->height, stuff->color))
-        return BadMatch;
-
-    return Success;
-}
-
-static int
-ProcXDGACopyArea(ClientPtr client)
-{
-    REQUEST(xXDGACopyAreaReq);
-
-    REQUEST_SIZE_MATCH(xXDGACopyAreaReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    if (Success != DGABlitRect(stuff->screen, stuff->srcx, stuff->srcy,
-                               stuff->width, stuff->height, stuff->dstx,
-                               stuff->dsty))
-        return BadMatch;
-
-    return Success;
-}
-
-static int
-ProcXDGACopyTransparentArea(ClientPtr client)
-{
-    REQUEST(xXDGACopyTransparentAreaReq);
-
-    REQUEST_SIZE_MATCH(xXDGACopyTransparentAreaReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    if (Success != DGABlitTransRect(stuff->screen, stuff->srcx, stuff->srcy,
-                                    stuff->width, stuff->height, stuff->dstx,
-                                    stuff->dsty, stuff->key))
-        return BadMatch;
-
-    return Success;
-}
-
-static int
-ProcXDGAGetViewportStatus(ClientPtr client)
-{
-    REQUEST(xXDGAGetViewportStatusReq);
-    xXDGAGetViewportStatusReply rep = {
-        .type = X_Reply,
-        .length = 0,
-        .sequenceNumber = client->sequence
-    };
-
-    REQUEST_SIZE_MATCH(xXDGAGetViewportStatusReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    rep.status = DGAGetViewportStatus(stuff->screen);
-
-    WriteToClient(client, sizeof(xXDGAGetViewportStatusReply), &rep);
-    return Success;
-}
-
-static int
-ProcXDGASync(ClientPtr client)
-{
-    REQUEST(xXDGASyncReq);
-    xXDGASyncReply rep = {
-        .type = X_Reply,
-        .length = 0,
-        .sequenceNumber = client->sequence
-    };
-
-    REQUEST_SIZE_MATCH(xXDGASyncReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    DGASync(stuff->screen);
-
-    WriteToClient(client, sizeof(xXDGASyncReply), &rep);
-    return Success;
-}
-
-static int
-ProcXDGASetClientVersion(ClientPtr client)
-{
-    REQUEST(xXDGASetClientVersionReq);
-
-    DGAPrivPtr pPriv;
-
-    REQUEST_SIZE_MATCH(xXDGASetClientVersionReq);
-    if ((pPriv = DGA_GETPRIV(client)) == NULL) {
-        pPriv = malloc(sizeof(DGAPrivRec));
-        /* XXX Need to look into freeing this */
-        if (!pPriv)
-            return BadAlloc;
-        DGA_SETPRIV(client, pPriv);
-    }
-    pPriv->major = stuff->major;
-    pPriv->minor = stuff->minor;
-
-    return Success;
-}
-
-static int
-ProcXDGAChangePixmapMode(ClientPtr client)
-{
-    REQUEST(xXDGAChangePixmapModeReq);
-    xXDGAChangePixmapModeReply rep;
-    int x, y;
-
-    REQUEST_SIZE_MATCH(xXDGAChangePixmapModeReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    x = stuff->x;
-    y = stuff->y;
-
-    if (!DGAChangePixmapMode(stuff->screen, &x, &y, stuff->flags))
-        return BadMatch;
-
-    rep = (xXDGAChangePixmapModeReply) {
-        .type = X_Reply,
-        .length = 0,
-        .sequenceNumber = client->sequence,
-        .x = x,
-        .y = y
-    };
-    WriteToClient(client, sizeof(xXDGAChangePixmapModeReply), &rep);
-
-    return Success;
-}
-
-static int
-ProcXDGACreateColormap(ClientPtr client)
-{
-    REQUEST(xXDGACreateColormapReq);
-    int result;
-
-    REQUEST_SIZE_MATCH(xXDGACreateColormapReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    if (!stuff->mode)
-        return BadValue;
-
-    result = DGACreateColormap(stuff->screen, client, stuff->id,
-                               stuff->mode, stuff->alloc);
-    if (result != Success)
-        return result;
-
-    return Success;
-}
-
-/*
- *
- * Support for the old DGA protocol, used to live in xf86dga.c
- *
- */
-
-#ifdef DGA_PROTOCOL_OLD_SUPPORT
-
-static int
-ProcXF86DGAGetVideoLL(ClientPtr client)
-{
-    REQUEST(xXF86DGAGetVideoLLReq);
-    xXF86DGAGetVideoLLReply rep = {
-        .type = X_Reply,
-        .length = 0,
-        .sequenceNumber = client->sequence
-    };
-    XDGAModeRec mode;
-    int num, offset, flags;
-    char *name;
-
-    REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!DGAAvailable(stuff->screen))
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    if (!(num = DGAGetOldDGAMode(stuff->screen)))
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    /* get the parameters for the mode that best matches */
-    DGAGetModeInfo(stuff->screen, &mode, num);
-
-    if (!DGAOpenFramebuffer(stuff->screen, &name,
-                            (unsigned char **) (&rep.offset),
-                            (int *) (&rep.bank_size), &offset, &flags))
-        return BadAlloc;
-
-    rep.offset += mode.offset;
-    rep.width = mode.bytesPerScanline / (mode.bitsPerPixel >> 3);
-    rep.ram_size = rep.bank_size >> 10;
-
-    WriteToClient(client, SIZEOF(xXF86DGAGetVideoLLReply), &rep);
-    return Success;
-}
-
-static int
-ProcXF86DGADirectVideo(ClientPtr client)
-{
-    int num;
-    PixmapPtr pix;
-    XDGAModeRec mode;
-    ClientPtr owner;
-
-    REQUEST(xXF86DGADirectVideoReq);
-
-    REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!DGAAvailable(stuff->screen))
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    owner = DGA_GETCLIENT(stuff->screen);
-
-    if (owner && owner != client)
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    if (stuff->enable & XF86DGADirectGraphics) {
-        if (!(num = DGAGetOldDGAMode(stuff->screen)))
-            return DGAErrorBase + XF86DGANoDirectVideoMode;
-    }
-    else
-        num = 0;
-
-    if (Success != DGASetMode(stuff->screen, num, &mode, &pix))
-        return DGAErrorBase + XF86DGAScreenNotActive;
-
-    DGASetInputMode(stuff->screen,
-                    (stuff->enable & XF86DGADirectKeyb) != 0,
-                    (stuff->enable & XF86DGADirectMouse) != 0);
-
-    /* We need to track the client and attach the teardown callback */
-    if (stuff->enable &
-        (XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse)) {
-        if (!owner) {
-            if (DGACallbackRefCount++ == 0)
-                AddCallback(&ClientStateCallback, DGAClientStateChange, NULL);
-        }
-
-        DGA_SETCLIENT(stuff->screen, client);
-    }
-    else {
-        if (owner) {
-            if (--DGACallbackRefCount == 0)
-                DeleteCallback(&ClientStateCallback, DGAClientStateChange,
-                               NULL);
-        }
-
-        DGA_SETCLIENT(stuff->screen, NULL);
-    }
-
-    return Success;
-}
-
-static int
-ProcXF86DGAGetViewPortSize(ClientPtr client)
-{
-    int num;
-    XDGAModeRec mode;
-
-    REQUEST(xXF86DGAGetViewPortSizeReq);
-    xXF86DGAGetViewPortSizeReply rep;
-
-    REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (!DGAAvailable(stuff->screen))
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    if (!(num = DGAGetOldDGAMode(stuff->screen)))
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    DGAGetModeInfo(stuff->screen, &mode, num);
-
-    rep = (xXF86DGAGetViewPortSizeReply) {
-        .type = X_Reply,
-        .length = 0,
-        .sequenceNumber = client->sequence,
-        .width = mode.viewportWidth,
-        .height = mode.viewportHeight
-    };
-
-    WriteToClient(client, SIZEOF(xXF86DGAGetViewPortSizeReply), &rep);
-    return Success;
-}
-
-static int
-ProcXF86DGASetViewPort(ClientPtr client)
-{
-    REQUEST(xXF86DGASetViewPortReq);
-
-    REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    if (!DGAAvailable(stuff->screen))
-        return DGAErrorBase + XF86DGANoDirectVideoMode;
-
-    if (!DGAActive(stuff->screen))
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    if (DGASetViewport(stuff->screen, stuff->x, stuff->y, DGA_FLIP_RETRACE)
-        != Success)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    return Success;
-}
-
-static int
-ProcXF86DGAGetVidPage(ClientPtr client)
-{
-    REQUEST(xXF86DGAGetVidPageReq);
-    xXF86DGAGetVidPageReply rep = {
-        .type = X_Reply,
-        .length = 0,
-        .sequenceNumber = client->sequence,
-        .vpage = 0               /* silently fail */
-    };
-
-    REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    WriteToClient(client, SIZEOF(xXF86DGAGetVidPageReply), &rep);
-    return Success;
-}
-
-static int
-ProcXF86DGASetVidPage(ClientPtr client)
-{
-    REQUEST(xXF86DGASetVidPageReq);
-
-    REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    /* silently fail */
-
-    return Success;
-}
-
-static int
-ProcXF86DGAInstallColormap(ClientPtr client)
-{
-    ColormapPtr pcmp;
-    int rc;
-
-    REQUEST(xXF86DGAInstallColormapReq);
-
-    REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    if (!DGAActive(stuff->screen))
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    rc = dixLookupResourceByType((pointer *) &pcmp, stuff->id, RT_COLORMAP,
-                                 client, DixInstallAccess);
-    if (rc == Success) {
-        DGAInstallCmap(pcmp);
-        return Success;
-    }
-    else {
-        return rc;
-    }
-}
-
-static int
-ProcXF86DGAQueryDirectVideo(ClientPtr client)
-{
-    REQUEST(xXF86DGAQueryDirectVideoReq);
-    xXF86DGAQueryDirectVideoReply rep = {
-        .type = X_Reply,
-        .length = 0,
-        .sequenceNumber = client->sequence,
-        .flags = 0
-    };
-
-    REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGAAvailable(stuff->screen))
-        rep.flags = XF86DGADirectPresent;
-
-    WriteToClient(client, SIZEOF(xXF86DGAQueryDirectVideoReply), &rep);
-    return Success;
-}
-
-static int
-ProcXF86DGAViewPortChanged(ClientPtr client)
-{
-    REQUEST(xXF86DGAViewPortChangedReq);
-    xXF86DGAViewPortChangedReply rep = {
-        .type = X_Reply,
-        .length = 0,
-        .sequenceNumber = client->sequence,
-        .result = 1
-    };
-
-    REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
-
-    if (stuff->screen >= screenInfo.numScreens)
-        return BadValue;
-
-    if (DGA_GETCLIENT(stuff->screen) != client)
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    if (!DGAActive(stuff->screen))
-        return DGAErrorBase + XF86DGADirectNotActivated;
-
-    WriteToClient(client, SIZEOF(xXF86DGAViewPortChangedReply), &rep);
-    return Success;
-}
-
-#endif                          /* DGA_PROTOCOL_OLD_SUPPORT */
-
-static int
-SProcXDGADispatch(ClientPtr client)
-{
-    return DGAErrorBase + XF86DGAClientNotLocal;
-}
-
-#if 0
-#define DGA_REQ_DEBUG
-#endif
-
-#ifdef DGA_REQ_DEBUG
-static char *dgaMinor[] = {
-    "QueryVersion",
-    "GetVideoLL",
-    "DirectVideo",
-    "GetViewPortSize",
-    "SetViewPort",
-    "GetVidPage",
-    "SetVidPage",
-    "InstallColormap",
-    "QueryDirectVideo",
-    "ViewPortChanged",
-    "10",
-    "11",
-    "QueryModes",
-    "SetMode",
-    "SetViewport",
-    "InstallColormap",
-    "SelectInput",
-    "FillRectangle",
-    "CopyArea",
-    "CopyTransparentArea",
-    "GetViewportStatus",
-    "Sync",
-    "OpenFramebuffer",
-    "CloseFramebuffer",
-    "SetClientVersion",
-    "ChangePixmapMode",
-    "CreateColormap",
-};
-#endif
-
-static int
-ProcXDGADispatch(ClientPtr client)
-{
-    REQUEST(xReq);
-
-    if (!LocalClient(client))
-        return DGAErrorBase + XF86DGAClientNotLocal;
-
-#ifdef DGA_REQ_DEBUG
-    if (stuff->data <= X_XDGACreateColormap)
-        fprintf(stderr, "    DGA %s\n", dgaMinor[stuff->data]);
-#endif
-
-    switch (stuff->data) {
-        /*
-         * DGA2 Protocol
-         */
-    case X_XDGAQueryVersion:
-        return ProcXDGAQueryVersion(client);
-    case X_XDGAQueryModes:
-        return ProcXDGAQueryModes(client);
-    case X_XDGASetMode:
-        return ProcXDGASetMode(client);
-    case X_XDGAOpenFramebuffer:
-        return ProcXDGAOpenFramebuffer(client);
-    case X_XDGACloseFramebuffer:
-        return ProcXDGACloseFramebuffer(client);
-    case X_XDGASetViewport:
-        return ProcXDGASetViewport(client);
-    case X_XDGAInstallColormap:
-        return ProcXDGAInstallColormap(client);
-    case X_XDGASelectInput:
-        return ProcXDGASelectInput(client);
-    case X_XDGAFillRectangle:
-        return ProcXDGAFillRectangle(client);
-    case X_XDGACopyArea:
-        return ProcXDGACopyArea(client);
-    case X_XDGACopyTransparentArea:
-        return ProcXDGACopyTransparentArea(client);
-    case X_XDGAGetViewportStatus:
-        return ProcXDGAGetViewportStatus(client);
-    case X_XDGASync:
-        return ProcXDGASync(client);
-    case X_XDGASetClientVersion:
-        return ProcXDGASetClientVersion(client);
-    case X_XDGAChangePixmapMode:
-        return ProcXDGAChangePixmapMode(client);
-    case X_XDGACreateColormap:
-        return ProcXDGACreateColormap(client);
-        /*
-         * Old DGA Protocol
-         */
-#ifdef DGA_PROTOCOL_OLD_SUPPORT
-    case X_XF86DGAGetVideoLL:
-        return ProcXF86DGAGetVideoLL(client);
-    case X_XF86DGADirectVideo:
-        return ProcXF86DGADirectVideo(client);
-    case X_XF86DGAGetViewPortSize:
-        return ProcXF86DGAGetViewPortSize(client);
-    case X_XF86DGASetViewPort:
-        return ProcXF86DGASetViewPort(client);
-    case X_XF86DGAGetVidPage:
-        return ProcXF86DGAGetVidPage(client);
-    case X_XF86DGASetVidPage:
-        return ProcXF86DGASetVidPage(client);
-    case X_XF86DGAInstallColormap:
-        return ProcXF86DGAInstallColormap(client);
-    case X_XF86DGAQueryDirectVideo:
-        return ProcXF86DGAQueryDirectVideo(client);
-    case X_XF86DGAViewPortChanged:
-        return ProcXF86DGAViewPortChanged(client);
-#endif                          /* DGA_PROTOCOL_OLD_SUPPORT */
-    default:
-        return BadRequest;
-    }
-}
-
-void
-XFree86DGARegister(void)
-{
-    XDGAEventBase = &DGAEventBase;
-}
-
-void
-XFree86DGAExtensionInit(void)
-{
-    ExtensionEntry *extEntry;
-
-    if (!dixRegisterPrivateKey(&DGAClientPrivateKeyRec, PRIVATE_CLIENT, 0))
-        return;
-
-    if (!dixRegisterPrivateKey(&DGAScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
-        return;
-
-    if ((extEntry = AddExtension(XF86DGANAME,
-                                 XF86DGANumberEvents,
-                                 XF86DGANumberErrors,
-                                 ProcXDGADispatch,
-                                 SProcXDGADispatch,
-                                 XDGAResetProc, StandardMinorOpcode))) {
-        int i;
-
-        DGAReqCode = (unsigned char) extEntry->base;
-        DGAErrorBase = extEntry->errorBase;
-        DGAEventBase = extEntry->eventBase;
-        for (i = KeyPress; i <= MotionNotify; i++)
-            SetCriticalEvent(DGAEventBase + i);
-    }
-}
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index 2959457..e06bf64 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -188,9 +188,9 @@ cat > sdksyms.c << EOF
 
 
 /* hw/xfree86/dixmods/extmod/Makefile.am -- module */
-/*
+#ifdef XFreeXDGA
 #include "dgaproc.h"
- */
+#endif
 
 
 /* hw/xfree86/parser/Makefile.am */
commit 6fb481d1251626456914d0012d6ca5a342bfdf71
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:09 2012 +0100

    Move SELinux from extmod to built-in
    
    Instead of letting it languish in extmod just because we want to
    configure bits of it from xf86, move XSELinux to the builtin part of
    Xext, and do its configuration from xf86ExtensionInit.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 98e9917..957fa67 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -30,6 +30,7 @@ BUILTIN_SRCS =			\
 	syncsrv.h		\
 	xcmisc.c		\
 	xtest.c
+BUILTIN_LIBS =
 
 # Sources always included in libXextmodule.la & libXext.la. That's right, zero.
 MODULE_SRCS =
@@ -84,8 +85,8 @@ endif
 # requires X-ACE extension
 XSELINUX_SRCS = xselinux_ext.c xselinux_hooks.c xselinux_label.c xselinux.h xselinuxint.h
 if XSELINUX
-MODULE_SRCS += $(XSELINUX_SRCS)
-MODULE_LIBS += $(SELINUX_LIBS)
+BUILTIN_SRCS += $(XSELINUX_SRCS)
+BUILTIN_LIBS += $(SELINUX_LIBS)
 endif
 
 # Security extension: multi-level security to protect clients from each other
@@ -109,10 +110,11 @@ endif
 # Now take all of the above, mix well, bake for 10 minutes and get libXext*.la
 
 libXext_la_SOURCES =		$(BUILTIN_SRCS) $(MODULE_SRCS)
-libXext_la_LIBADD =		$(MODULE_LIBS)
+libXext_la_LIBADD =		$(BUILTIN_LIBS) $(MODULE_LIBS)
 
 if XORG
 libXextbuiltin_la_SOURCES =	$(BUILTIN_SRCS)
+libXextbuiltin_la_LIBADD = 	$(BUILTIN_LIBS)
 
 libXextmodule_la_SOURCES =	$(MODULE_SRCS)
 libXextmodule_la_LIBADD =	$(MODULE_LIBS)
diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c
index 15c96b4..aed0635 100644
--- a/hw/xfree86/common/xf86Extensions.c
+++ b/hw/xfree86/common/xf86Extensions.c
@@ -37,6 +37,10 @@
 #include "xf86Opt.h"
 #include "optionstr.h"
 
+#ifdef XSELINUX
+#include "xselinux.h"
+#endif
+
 /*
  * DDX-specific extensions.
  */
@@ -67,6 +71,24 @@ load_extension_config(void)
             if (EnableDisableExtension(key + 4, FALSE))
                 xf86MarkOptionUsed(opt);
         }
+
+#ifdef XSELINUX
+        if ((opt = xf86FindOption(modp->load_opt,
+                                  "SELinux mode disabled"))) {
+            xf86MarkOptionUsed(opt);
+            selinuxEnforcingState = SELINUX_MODE_DISABLED;
+        }
+        if ((opt = xf86FindOption(modp->load_opt,
+                                  "SELinux mode permissive"))) {
+            xf86MarkOptionUsed(opt);
+            selinuxEnforcingState = SELINUX_MODE_PERMISSIVE;
+        }
+        if ((opt = xf86FindOption(modp->load_opt,
+                                  "SELinux mode enforcing"))) {
+            xf86MarkOptionUsed(opt);
+            selinuxEnforcingState = SELINUX_MODE_ENFORCING;
+        }
+#endif
     }
 }
 
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index f8832fd..e64d41a 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -39,14 +39,6 @@ static MODULESETUPPROTO(extmodSetup);
  * Array describing extensions to be initialized
  */
 static ExtensionModule extensionModules[] = {
-#ifdef XSELINUX
-    {
-     SELinuxExtensionInit,
-     SELINUX_EXTENSION_NAME,
-     &noSELinuxExtension,
-     NULL,
-     NULL},
-#endif
 #ifdef XF86VIDMODE
     {
      XFree86VidModeExtensionInit,
@@ -88,32 +80,9 @@ extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin)
 {
     int i;
 
-    /* XXX the option stuff here is largely a sample/test case */
-
-    for (i = 0; i < ARRAY_SIZE(extensionModules); i++) {
-#ifdef XSELINUX
-        if (!strcmp(SELINUX_EXTENSION_NAME, extensionModules[i].name)) {
-            pointer o;
-
-            selinuxEnforcingState = SELINUX_MODE_DEFAULT;
-
-            if ((o = xf86FindOption(opts, "SELinux mode disabled"))) {
-                xf86MarkOptionUsed(o);
-                selinuxEnforcingState = SELINUX_MODE_DISABLED;
-            }
-            if ((o = xf86FindOption(opts, "SELinux mode permissive"))) {
-                xf86MarkOptionUsed(o);
-                selinuxEnforcingState = SELINUX_MODE_PERMISSIVE;
-            }
-            if ((o = xf86FindOption(opts, "SELinux mode enforcing"))) {
-                xf86MarkOptionUsed(o);
-                selinuxEnforcingState = SELINUX_MODE_ENFORCING;
-            }
-        }
-#endif
+    for (i = 0; i < ARRAY_SIZE(extensionModules); i++)
+	LoadExtension(&extensionModules[i], FALSE);
 
-        LoadExtension(&extensionModules[i], FALSE);
-    }
     /* Need a non-NULL return */
     return (pointer) 1;
 }
diff --git a/include/extinit.h b/include/extinit.h
index ea41eba..0a24db0 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -158,7 +158,7 @@ extern _X_EXPORT void AssignTypeAndName(DeviceIntPtr dev,
 #include <X11/extensions/XKB.h>
 extern void XkbExtensionInit(void);
 
-#if defined(XSELINUX) && !defined(XorgLoader)
+#if defined(XSELINUX)
 #include "xselinux.h"
 extern Bool noSELinuxExtension;
 extern void SELinuxExtensionInit(void);
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 74fb223..a8644db 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -416,6 +416,9 @@ static ExtensionModule staticExtensions[] = {
     {XvExtensionInit, XvName, &noXvExtension, NULL},
     {XvMCExtensionInit, XvMCName, &noXvExtension, NULL},
 #endif
+#ifdef XSELINUX
+    {SELinuxExtensionInit, SELINUX_EXTENSION_NAME, &noSELinuxExtension, NULL},
+#endif
 };
 
  /*ARGSUSED*/ void
commit 5d92ee4081a23a6b4d1f9ba2a98985f539f99312
Author: Tomas Carnecky <tom at dbservice.com>
Date:   Tue Jul 10 02:03:08 2012 +0100

    Xv: Remove excessive module-induced indirection
    
    Xv used to call XvScreenInit and co. through function pointers, as
    XvScreenInit may have been sitting on the other side of a module
    boundary from xf86XvScreenInit.  Why this was so is a mystery, but make
    it not so any more.
    
    Signed-off-by: Tomas Carnecky <tom at dbservice.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Acked-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index fc8eb0f..9c6160c 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -70,10 +70,6 @@ extern _X_EXPORT RESTYPE XvRTVideoNotify;
 extern _X_EXPORT RESTYPE XvRTVideoNotifyList;
 extern _X_EXPORT RESTYPE XvRTPortNotify;
 
-extern DevPrivateKey (*XvGetScreenKeyProc)(void);
-extern unsigned long (*XvGetRTPortProc)(void);
-extern int (*XvScreenInitProc)(ScreenPtr);
-
 typedef struct {
     int numerator;
     int denominator;
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 77c4156..c2860b8 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -194,18 +194,6 @@ XvExtensionInit(void)
     }
 }
 
-DevPrivateKey (*XvGetScreenKeyProc)(void) = NULL;
-unsigned long (*XvGetRTPortProc)(void) = NULL;
-int (*XvScreenInitProc)(ScreenPtr) = NULL;
-
-void
-XvRegister(void)
-{
-    XvScreenInitProc = XvScreenInit;
-    XvGetScreenKeyProc = XvGetScreenKey;
-    XvGetRTPortProc = XvGetRTPort;
-}
-
 static Bool
 CreateResourceTypes(void)
 {
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 910adf4..ad7956b 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -764,12 +764,6 @@ XvMCScreenInit(ScreenPtr pScreen, int num, XvMCAdaptorPtr pAdapt)
     return Success;
 }
 
-void
-XvMCRegister(void)
-{
-    XvMCScreenInitProc = XvMCScreenInit;
-}
-
 XvImagePtr
 XvMCFindXvImage(XvPortPtr pPort, CARD32 id)
 {
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index b7afb2e..cf65636 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -182,17 +182,17 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr * adaptors, int num)
     if (KdXVGeneration != serverGeneration)
         KdXVGeneration = serverGeneration;
 
-    if (!XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc)
+    if (noXvExtension)
         return FALSE;
 
     if (!dixRegisterPrivateKey(&KdXVWindowKeyRec, PRIVATE_WINDOW, 0))
         return FALSE;
 
-    if (Success != (*XvScreenInitProc) (pScreen))
+    if (Success != XvScreenInit(pScreen))
         return FALSE;
 
-    KdXvScreenKey = (*XvGetScreenKeyProc) ();
-    PortResource = (*XvGetRTPortProc) ();
+    KdXvScreenKey = XvGetScreenKey();
+    PortResource = XvGetRTPort();
 
     pxvs = GET_XV_SCREEN(pScreen);
 
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 0e50f37..92d0f6d 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -234,19 +234,18 @@ xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num)
     XF86XVScreenPtr ScreenPriv;
     XvScreenPtr pxvs;
 
-    if (num <= 0 ||
-        !XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc)
+    if (num <= 0 || noXvExtension)
         return FALSE;
 
-    if (Success != (*XvScreenInitProc) (pScreen))
+    if (Success != XvScreenInit(pScreen))
         return FALSE;
 
     if (!dixRegisterPrivateKey(&XF86XVWindowKeyRec, PRIVATE_WINDOW, 0))
         return FALSE;
 
-    XF86XvScreenKey = (*XvGetScreenKeyProc) ();
+    XF86XvScreenKey = XvGetScreenKey();
 
-    PortResource = (*XvGetRTPortProc) ();
+    PortResource = XvGetRTPort();
 
     pxvs = GET_XV_SCREEN(pScreen);
 
diff --git a/hw/xfree86/common/xf86xvmc.c b/hw/xfree86/common/xf86xvmc.c
index dc6b395..78a32bf 100644
--- a/hw/xfree86/common/xf86xvmc.c
+++ b/hw/xfree86/common/xf86xvmc.c
@@ -152,7 +152,7 @@ xf86XvMCScreenInit(ScreenPtr pScreen,
                                                       XF86XvScreenKey);
     int i, j;
 
-    if (!XvMCScreenInitProc)
+    if (noXvExtension)
         return FALSE;
 
     if (!(pAdapt = malloc(sizeof(XvMCAdaptorRec) * num_adaptors)))
@@ -201,7 +201,7 @@ xf86XvMCScreenInit(ScreenPtr pScreen,
         adaptors++;
     }
 
-    if (Success != (*XvMCScreenInitProc) (pScreen, num_adaptors, pAdapt))
+    if (Success != XvMCScreenInit(pScreen, num_adaptors, pAdapt))
         return FALSE;
 
     return TRUE;
diff --git a/hw/xfree86/common/xf86xvmc.h b/hw/xfree86/common/xf86xvmc.h
index ff32379..2478fe3 100644
--- a/hw/xfree86/common/xf86xvmc.h
+++ b/hw/xfree86/common/xf86xvmc.h
@@ -138,7 +138,4 @@ extern _X_EXPORT Bool xf86XvMCScreenInit(ScreenPtr pScreen,
 extern _X_EXPORT XF86MCAdaptorPtr xf86XvMCCreateAdaptorRec(void);
 extern _X_EXPORT void xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor);
 
-typedef int (*XvMCScreenInitProcPtr) (ScreenPtr, int, XvMCAdaptorPtr);
-extern _X_EXPORT XvMCScreenInitProcPtr XvMCScreenInitProc;
-
 #endif                          /* _XF86XVMC_H */
diff --git a/include/extinit.h b/include/extinit.h
index a8c2539..ea41eba 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -181,8 +181,6 @@ extern void PseudoramiXExtensionInit(void);
 extern Bool noXvExtension;
 extern void XvExtensionInit(void);
 extern void XvMCExtensionInit(void);
-extern void XvRegister(void);
-extern void XvMCRegister(void);
 #endif
 
 #endif
diff --git a/mi/miinitext.c b/mi/miinitext.c
index a83df60..74fb223 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -413,8 +413,8 @@ static ExtensionModule staticExtensions[] = {
     {ResExtensionInit, XRES_NAME, &noResExtension, NULL},
 #endif
 #ifdef XV
-    {XvExtensionInit, XvName, &noXvExtension, XvRegister},
-    {XvMCExtensionInit, XvMCName, &noXvExtension, XvMCRegister},
+    {XvExtensionInit, XvName, &noXvExtension, NULL},
+    {XvMCExtensionInit, XvMCName, &noXvExtension, NULL},
 #endif
 };
 
commit 2e6c5f959153cdcea4bcf719621ebec408250f54
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:07 2012 +0100

    XFree86: sdksyms: Remove unused -DXorgLoader
    
    We no longer have anything in the tree that checks for XorgLoader.  This
    was a fairly monumental hack: xvdi.h used to hide all its functions
    behind #ifndef XorgLoader, solely to avoid sdksyms.sh picking up its
    symbols, as it was previously a module rather than built-in.
    
    This is no longer the case, so we can remove the define.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index 6d8a4d3..2959457 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -324,8 +324,8 @@ topdir=$1
 shift
 LC_ALL=C
 export LC_ALL
-${CPP:-cpp} "$@" -DXorgLoader sdksyms.c > /dev/null || exit $?
-${CPP:-cpp} "$@" -DXorgLoader sdksyms.c | ${AWK:-awk} -v topdir=$topdir '
+${CPP:-cpp} "$@" sdksyms.c > /dev/null || exit $?
+${CPP:-cpp} "$@" sdksyms.c | ${AWK:-awk} -v topdir=$topdir '
 BEGIN {
     sdk = 0;
     print("/*");
commit 7a11b817e770cd2196814f1ac6264c6d87b76c6a
Author: Tomas Carnecky <tom at dbservice.com>
Date:   Tue Jul 10 02:03:06 2012 +0100

    Move Xv and XvMC from extmod to built-in
    
    Always build these extensions into the core server, rather than letting
    them languish in extmod.
    
    Signed-off-by: Tomas Carnecky <tom at dbservice.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 5837be0..98e9917 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -46,7 +46,7 @@ endif
 # XVideo extension
 XV_SRCS = xvmain.c xvdisp.c xvmc.c xvdix.h xvmcext.h xvdisp.h
 if XV
-MODULE_SRCS  += $(XV_SRCS)
+BUILTIN_SRCS  += $(XV_SRCS)
 endif
 
 # XResource extension: lets clients get data about per-client resource usage
diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index fdf33d3..fc8eb0f 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -55,7 +55,6 @@ SOFTWARE.
 #include "scrnintstr.h"
 #include <X11/extensions/Xvproto.h>
 
-#ifndef XorgLoader
 extern _X_EXPORT unsigned long XvExtensionGeneration;
 extern _X_EXPORT unsigned long XvScreenGeneration;
 extern _X_EXPORT unsigned long XvResourceGeneration;
@@ -70,7 +69,10 @@ extern _X_EXPORT RESTYPE XvRTGrab;
 extern _X_EXPORT RESTYPE XvRTVideoNotify;
 extern _X_EXPORT RESTYPE XvRTVideoNotifyList;
 extern _X_EXPORT RESTYPE XvRTPortNotify;
-#endif
+
+extern DevPrivateKey (*XvGetScreenKeyProc)(void);
+extern unsigned long (*XvGetRTPortProc)(void);
+extern int (*XvScreenInitProc)(ScreenPtr);
 
 typedef struct {
     int numerator;
@@ -231,7 +233,6 @@ typedef struct {
 #define _XvBadPort (XvBadPort+XvErrorBase)
 #define _XvBadEncoding (XvBadEncoding+XvErrorBase)
 
-#ifndef XorgLoader
 extern _X_EXPORT int ProcXvDispatch(ClientPtr);
 extern _X_EXPORT int SProcXvDispatch(ClientPtr);
 
@@ -267,6 +268,4 @@ extern _X_EXPORT int XvdiPreemptVideo(ClientPtr, XvPortPtr, DrawablePtr);
 extern _X_EXPORT int XvdiMatchPort(XvPortPtr, DrawablePtr);
 extern _X_EXPORT int XvdiGrabPort(ClientPtr, XvPortPtr, Time, int *);
 extern _X_EXPORT int XvdiUngrabPort(ClientPtr, XvPortPtr, Time);
-#endif                          /* XorgLoader */
-
 #endif                          /* XVDIX_H */
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index c2860b8..77c4156 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -194,6 +194,18 @@ XvExtensionInit(void)
     }
 }
 
+DevPrivateKey (*XvGetScreenKeyProc)(void) = NULL;
+unsigned long (*XvGetRTPortProc)(void) = NULL;
+int (*XvScreenInitProc)(ScreenPtr) = NULL;
+
+void
+XvRegister(void)
+{
+    XvScreenInitProc = XvScreenInit;
+    XvGetScreenKeyProc = XvGetScreenKey;
+    XvGetRTPortProc = XvGetRTPort;
+}
+
 static Bool
 CreateResourceTypes(void)
 {
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 808691c..910adf4 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -46,6 +46,8 @@ static RESTYPE XvMCRTContext;
 static RESTYPE XvMCRTSurface;
 static RESTYPE XvMCRTSubpicture;
 
+int (*XvMCScreenInitProc)(ScreenPtr, int, XvMCAdaptorPtr) = NULL;
+
 typedef struct {
     int num_adaptors;
     XvMCAdaptorPtr adaptors;
@@ -762,6 +764,12 @@ XvMCScreenInit(ScreenPtr pScreen, int num, XvMCAdaptorPtr pAdapt)
     return Success;
 }
 
+void
+XvMCRegister(void)
+{
+    XvMCScreenInitProc = XvMCScreenInit;
+}
+
 XvImagePtr
 XvMCFindXvImage(XvPortPtr pPort, CARD32 id)
 {
diff --git a/Xext/xvmcext.h b/Xext/xvmcext.h
index d78171d..2201d7b 100644
--- a/Xext/xvmcext.h
+++ b/Xext/xvmcext.h
@@ -84,7 +84,8 @@ typedef struct {
     XvMCDestroySubpictureProcPtr DestroySubpicture;
 } XvMCAdaptorRec, *XvMCAdaptorPtr;
 
-#ifndef XorgLoader
+extern int (*XvMCScreenInitProc)(ScreenPtr, int, XvMCAdaptorPtr);
+
 extern _X_EXPORT int XvMCScreenInit(ScreenPtr pScreen,
                                     int num, XvMCAdaptorPtr adapt);
 
@@ -93,6 +94,5 @@ extern _X_EXPORT XvImagePtr XvMCFindXvImage(XvPortPtr pPort, CARD32 id);
 extern _X_EXPORT int xf86XvMCRegisterDRInfo(ScreenPtr pScreen, char *name,
                                             char *busID, int major, int minor,
                                             int patchLevel);
-#endif
 
 #endif                          /* _XVMC_H */
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index b02dd88..b7afb2e 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -107,10 +107,6 @@ static DevPrivateKey KdXvScreenKey;
 static unsigned long KdXVGeneration = 0;
 static unsigned long PortResource = 0;
 
-DevPrivateKey (*XvGetScreenKeyProc) (void) = XvGetScreenKey;
-unsigned long (*XvGetRTPortProc) (void) = XvGetRTPort;
-int (*XvScreenInitProc) (ScreenPtr) = XvScreenInit;
-
 #define GET_XV_SCREEN(pScreen) ((XvScreenPtr) \
     dixLookupPrivate(&(pScreen)->devPrivates, KdXvScreenKey))
 
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 1a964d2..0e50f37 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -117,10 +117,6 @@ DevPrivateKey XF86XvScreenKey;
 
 static unsigned long PortResource = 0;
 
-DevPrivateKey (*XvGetScreenKeyProc) (void) = NULL;
-unsigned long (*XvGetRTPortProc) (void) = NULL;
-int (*XvScreenInitProc) (ScreenPtr) = NULL;
-
 #define GET_XV_SCREEN(pScreen) \
     ((XvScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XF86XvScreenKey))
 
diff --git a/hw/xfree86/common/xf86xv.h b/hw/xfree86/common/xf86xv.h
index 2db00a8..091efca 100644
--- a/hw/xfree86/common/xf86xv.h
+++ b/hw/xfree86/common/xf86xv.h
@@ -263,8 +263,4 @@ extern _X_EXPORT void
 xf86XVCopyPacked(const void *src,
                  void *dst, int srcPitch, int dstPitch, int h, int w);
 
-extern _X_EXPORT DevPrivateKey (*XvGetScreenKeyProc) (void);
-extern _X_EXPORT unsigned long (*XvGetRTPortProc) (void);
-extern _X_EXPORT int (*XvScreenInitProc) (ScreenPtr);
-
 #endif                          /* _XF86XV_H_ */
diff --git a/hw/xfree86/common/xf86xvmc.c b/hw/xfree86/common/xf86xvmc.c
index 2e529dd..dc6b395 100644
--- a/hw/xfree86/common/xf86xvmc.c
+++ b/hw/xfree86/common/xf86xvmc.c
@@ -43,8 +43,6 @@
 #include "xf86xvpriv.h"
 #include "xf86xvmc.h"
 
-XvMCScreenInitProcPtr XvMCScreenInitProc = NULL;
-
 typedef struct {
     CloseScreenProcPtr CloseScreen;
     int num_adaptors;
diff --git a/hw/xfree86/dixmods/extmod/Makefile.am b/hw/xfree86/dixmods/extmod/Makefile.am
index cdbd82e..8436cb3 100644
--- a/hw/xfree86/dixmods/extmod/Makefile.am
+++ b/hw/xfree86/dixmods/extmod/Makefile.am
@@ -7,10 +7,6 @@ if DGA
 DGA_SRCS = xf86dga2.c dgaproc.h
 endif
 
-if XV
-XV_SRCS = xvmod.c xvmodproc.h
-endif
-
 if XF86VIDMODE
 XF86VMODE_SRCS = xf86vmode.c
 endif
@@ -24,6 +20,5 @@ INCLUDES = @XORG_INCS@ \
 libextmod_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
 libextmod_la_SOURCES = modinit.c \
                        $(DGA_SRCS) \
-                       $(XF86VMODE_SRCS) \
-                       $(XV_SRCS)
+                       $(XF86VMODE_SRCS)
 libextmod_la_LIBADD = $(top_builddir)/Xext/libXextmodule.la
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index 3c69332..f8832fd 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -63,20 +63,6 @@ static ExtensionModule extensionModules[] = {
      XFree86DGARegister,
      NULL},
 #endif
-#ifdef XV
-    {
-     XvExtensionInit,
-     XvName,
-     &noXvExtension,
-     XvRegister,
-     NULL},
-    {
-     XvMCExtensionInit,
-     XvMCName,
-     &noXvExtension,
-     NULL,
-     NULL},
-#endif
 };
 
 static XF86ModuleVersionInfo VersRec = {
diff --git a/hw/xfree86/dixmods/extmod/xvmod.c b/hw/xfree86/dixmods/extmod/xvmod.c
deleted file mode 100644
index 97616c7..0000000
--- a/hw/xfree86/dixmods/extmod/xvmod.c
+++ /dev/null
@@ -1,22 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include "misc.h"
-#include "scrnintstr.h"
-#include "gc.h"
-#include <X11/extensions/Xv.h>
-#include <X11/extensions/Xvproto.h>
-#include "xvdix.h"
-#include "xvmodproc.h"
-
-void
-XvRegister(void)
-{
-    XvScreenInitProc = XvScreenInit;
-    XvGetScreenKeyProc = XvGetScreenKey;
-    XvGetRTPortProc = XvGetRTPort;
-    XvMCScreenInitProc = XvMCScreenInit;
-}
diff --git a/hw/xfree86/dixmods/extmod/xvmodproc.h b/hw/xfree86/dixmods/extmod/xvmodproc.h
deleted file mode 100644
index 0090547..0000000
--- a/hw/xfree86/dixmods/extmod/xvmodproc.h
+++ /dev/null
@@ -1,17 +0,0 @@
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef XVMODPROC_H
-#define XVMODPROC_H
-#include "xvmcext.h"
-
-extern DevPrivateKey (*XvGetScreenKeyProc) (void);
-extern unsigned long (*XvGetRTPortProc) (void);
-extern int (*XvScreenInitProc) (ScreenPtr);
-extern int (*XvMCScreenInitProc) (ScreenPtr, int, XvMCAdaptorPtr);
-
-extern void XvRegister(void);
-
-#endif /* XVMODPROC_H */
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index ab48fcf..6d8a4d3 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -46,10 +46,8 @@ cat > sdksyms.c << EOF
 #include "misyncstr.h"
 
 /* Xext/Makefile.am -- half is module, half is builtin */
-/*
 #include "xvdix.h"
 #include "xvmcext.h"
- */
 #include "geext.h"
 #include "geint.h"
 #ifdef MITSHM
diff --git a/include/extinit.h b/include/extinit.h
index 589db1f..a8c2539 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -175,13 +175,14 @@ extern Bool noPseudoramiXExtension;
 extern void PseudoramiXExtensionInit(void);
 #endif
 
-#if defined(XV) && !defined(XorgLoader)
+#if defined(XV)
 #include <X11/extensions/Xv.h>
 #include <X11/extensions/XvMC.h>
 extern Bool noXvExtension;
 extern void XvExtensionInit(void);
 extern void XvMCExtensionInit(void);
 extern void XvRegister(void);
+extern void XvMCRegister(void);
 #endif
 
 #endif
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 53e5dda..a83df60 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -412,6 +412,10 @@ static ExtensionModule staticExtensions[] = {
 #ifdef RES
     {ResExtensionInit, XRES_NAME, &noResExtension, NULL},
 #endif
+#ifdef XV
+    {XvExtensionInit, XvName, &noXvExtension, XvRegister},
+    {XvMCExtensionInit, XvMCName, &noXvExtension, XvMCRegister},
+#endif
 };
 
  /*ARGSUSED*/ void
commit 7d859bd87834dd79c7fa3792075496ece698c082
Author: Tomas Carnecky <tom at dbservice.com>
Date:   Tue Jul 10 02:03:05 2012 +0100

    Move XRes from extmod to built-in
    
    Always build XRes support into the core server, rather than letting it
    languish in extmod.
    
    Signed-off-by: Tomas Carnecky <tom at dbservice.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 15cbdab..5837be0 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -52,7 +52,7 @@ endif
 # XResource extension: lets clients get data about per-client resource usage
 RES_SRCS = hashtable.c hashtable.h xres.c
 if RES
-MODULE_SRCS  += $(RES_SRCS)
+BUILTIN_SRCS  += $(RES_SRCS)
 endif
 
 # MIT ScreenSaver extension
diff --git a/Xext/xres.c b/Xext/xres.c
index 445abca..7d21ad7 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -190,6 +190,8 @@ DestroyConstructResourceBytesCtx(ConstructResourceBytesCtx *ctx)
     ht_destroy(ctx->visitedResources);
 }
 
+extern void ResExtensionInit(void);
+
 static int
 ProcXResQueryVersion(ClientPtr client)
 {
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index bb120a2..3c69332 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -77,14 +77,6 @@ static ExtensionModule extensionModules[] = {
      NULL,
      NULL},
 #endif
-#ifdef RES
-    {
-     ResExtensionInit,
-     XRES_NAME,
-     &noResExtension,
-     NULL,
-     NULL},
-#endif
 };
 
 static XF86ModuleVersionInfo VersRec = {
diff --git a/include/extinit.h b/include/extinit.h
index 4d8aef5..589db1f 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -104,7 +104,7 @@ extern void RecordExtensionInit(void);
 extern Bool noRenderExtension;
 extern void RenderExtensionInit(void);
 
-#if defined(RES) && !defined(XorgLoader)
+#if defined(RES)
 #include <X11/extensions/XResproto.h>
 extern Bool noResExtension;
 extern void ResExtensionInit(void);
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 6aee7c1..53e5dda 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -409,6 +409,9 @@ static ExtensionModule staticExtensions[] = {
 #ifdef DPMSExtension
     {DPMSExtensionInit, DPMSExtensionName, &noDPMSExtension, NULL},
 #endif
+#ifdef RES
+    {ResExtensionInit, XRES_NAME, &noResExtension, NULL},
+#endif
 };
 
  /*ARGSUSED*/ void
commit ba21fc29587e4f11320b88a70433beb1fe22cdf3
Author: Tomas Carnecky <tom at dbservice.com>
Date:   Tue Jul 10 02:03:04 2012 +0100

    Move DPMS from extmod to built-in
    
    Always build DPMS support into the core server, rather than letting it
    languish in extmod.
    
    Signed-off-by: Tomas Carnecky <tom at dbservice.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 4f91254..15cbdab 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -103,7 +103,7 @@ endif
 # DPMS extension
 DPMS_SRCS = dpms.c dpmsproc.h
 if DPMSExtension
-MODULE_SRCS += $(DPMS_SRCS)
+BUILTIN_SRCS += $(DPMS_SRCS)
 endif
 
 # Now take all of the above, mix well, bake for 10 minutes and get libXext*.la
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index 660b1cd..bb120a2 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -63,14 +63,6 @@ static ExtensionModule extensionModules[] = {
      XFree86DGARegister,
      NULL},
 #endif
-#ifdef DPMSExtension
-    {
-     DPMSExtensionInit,
-     DPMSExtensionName,
-     &noDPMSExtension,
-     NULL,
-     NULL},
-#endif
 #ifdef XV
     {
      XvExtensionInit,
diff --git a/include/extinit.h b/include/extinit.h
index 61768b0..4d8aef5 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -72,7 +72,7 @@ extern void DbeExtensionInit(void);
 extern void DMXExtensionInit(void);
 #endif
 
-#if defined(DPMSExtension) && !defined(XorgLoader)
+#if defined(DPMSExtension)
 #include <X11/extensions/dpmsconst.h>
 extern Bool noDPMSExtension;
 extern void DPMSExtensionInit(void);
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 0b4a4cf..6aee7c1 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -406,6 +406,9 @@ static ExtensionModule staticExtensions[] = {
 #ifdef XRECORD
     {RecordExtensionInit, "RECORD", &noTestExtensions, NULL},
 #endif
+#ifdef DPMSExtension
+    {DPMSExtensionInit, DPMSExtensionName, &noDPMSExtension, NULL},
+#endif
 };
 
  /*ARGSUSED*/ void
commit 3ed2c6e11298c4299042cfe4578f6cc02e441d58
Author: Tomas Carnecky <tom at dbservice.com>
Date:   Tue Jul 10 02:03:03 2012 +0100

    Move MIT-SCREEN-SAVER from extmod to built-in
    
    If we've built MIT-SCREEN-SAVER support, then just build it into the
    main binary, rather than leaving it in extmod.
    
    Signed-off-by: Tomas Carnecky <tom at dbservice.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 4082de7..4f91254 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -58,7 +58,7 @@ endif
 # MIT ScreenSaver extension
 SCREENSAVER_SRCS = saver.c
 if SCREENSAVER
-MODULE_SRCS  += $(SCREENSAVER_SRCS)
+BUILTIN_SRCS  += $(SCREENSAVER_SRCS)
 endif
 
 # Xinerama extension: making multiple video devices act as one virtual screen
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index 009852c..660b1cd 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -47,14 +47,6 @@ static ExtensionModule extensionModules[] = {
      NULL,
      NULL},
 #endif
-#ifdef SCREENSAVER
-    {
-     ScreenSaverExtensionInit,
-     ScreenSaverName,
-     &noScreenSaverExtension,
-     NULL,
-     NULL},
-#endif
 #ifdef XF86VIDMODE
     {
      XFree86VidModeExtensionInit,
diff --git a/include/extinit.h b/include/extinit.h
index 2755e30..61768b0 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -110,7 +110,7 @@ extern Bool noResExtension;
 extern void ResExtensionInit(void);
 #endif
 
-#if defined(SCREENSAVER) && !defined(XorgLoader)
+#if defined(SCREENSAVER)
 #include <X11/extensions/saver.h>
 extern Bool noScreenSaverExtension;
 extern void ScreenSaverExtensionInit(void);
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 9c93fc5..0b4a4cf 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -397,6 +397,9 @@ static ExtensionModule staticExtensions[] = {
 #ifdef DAMAGE
     {DamageExtensionInit, "DAMAGE", &noDamageExtension, NULL},
 #endif
+#ifdef SCREENSAVER
+    {ScreenSaverExtensionInit, ScreenSaverName, &noScreenSaverExtension, NULL},
+#endif
 #ifdef DBE
     {DbeExtensionInit, "DOUBLE-BUFFER", &noDbeExtension, NULL},
 #endif
commit b8c9ab0fea0be299d9f48ac0c4ed0474104a7556
Author: Tomas Carnecky <tom at dbservice.com>
Date:   Tue Jul 10 02:03:02 2012 +0100

    Move RECORD from external module to built-in
    
    Rather than languishing in its own special module, move RECORD into the
    core server.
    
    Signed-off-by: Tomas Carnecky <tom at dbservice.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 13628f5..fc5e2d9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1605,7 +1605,7 @@ if test "x$XORG" = xyes; then
 	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
 	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
 	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
-	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $DBE_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $XI_LIB $XKB_LIB"
+	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $XI_LIB $XKB_LIB"
 
 	dnl ==================================================================
 	dnl symbol visibility
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index ce2c10a..7b68e35 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -113,9 +113,6 @@ static ModuleDefault ModuleDefaults[] = {
 #ifdef GLXEXT
     {.name = "glx",.toLoad = TRUE,.load_opt = NULL},
 #endif
-#ifdef XRECORD
-    {.name = "record",.toLoad = TRUE,.load_opt = NULL},
-#endif
 #ifdef XF86DRI
     {.name = "dri",.toLoad = TRUE,.load_opt = NULL},
 #endif
diff --git a/hw/xfree86/dixmods/Makefile.am b/hw/xfree86/dixmods/Makefile.am
index 827b952..3aa7d27 100644
--- a/hw/xfree86/dixmods/Makefile.am
+++ b/hw/xfree86/dixmods/Makefile.am
@@ -6,17 +6,12 @@ if GLX
 GLXMODS = libglx.la
 endif
 
-if RECORD
-RECORDMOD = librecord.la
-endif
-
 module_LTLIBRARIES = libfb.la \
                      libwfb.la \
                      libshadow.la
 
 extsmoduledir = $(moduledir)/extensions
-extsmodule_LTLIBRARIES = $(RECORDMOD) \
-                         $(GLXMODS)
+extsmodule_LTLIBRARIES = $(GLXMODS)
 
 AM_CFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
 INCLUDES = @XORG_INCS@ \
@@ -44,10 +39,6 @@ endif
 endif
 libglx_la_SOURCES = glxmodule.c
 
-librecord_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-librecord_la_LIBADD = $(top_builddir)/record/librecord.la
-librecord_la_SOURCES = recordmod.c
-
 libshadow_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
 libshadow_la_LIBADD = $(top_builddir)/miext/shadow/libshadow.la
 if NO_UNDEFINED
diff --git a/hw/xfree86/dixmods/recordmod.c b/hw/xfree86/dixmods/recordmod.c
deleted file mode 100644
index 4f8eb97..0000000
--- a/hw/xfree86/dixmods/recordmod.c
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-#include "extinit.h"
-
-extern Bool noTestExtensions;
-
-static MODULESETUPPROTO(recordSetup);
-
-static ExtensionModule recordExt = {
-    RecordExtensionInit,
-    "RECORD",
-    &noTestExtensions,
-    NULL,
-    NULL
-};
-
-static XF86ModuleVersionInfo VersRec = {
-    "record",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 13, 0,
-    ABI_CLASS_EXTENSION,
-    ABI_EXTENSION_VERSION,
-    MOD_CLASS_EXTENSION,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData recordModuleData = { &VersRec, recordSetup, NULL };
-
-static pointer
-recordSetup(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    LoadExtension(&recordExt, FALSE);
-
-    /* Need a non-NULL return value to indicate success */
-    return (pointer) 1;
-}
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 99f06c2..9ce5813 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -834,6 +834,7 @@ static const char *compiled_in_modules[] = {
     "i2c",
     "ramdac",
     "dbe",
+    "record",
     NULL
 };
 
diff --git a/include/extinit.h b/include/extinit.h
index 539e28d..2755e30 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -97,7 +97,7 @@ extern Bool noRRExtension;
 extern void RRExtensionInit(void);
 #endif
 
-#if defined(XRECORD) && !defined(XorgLoader)
+#if defined(XRECORD)
 extern void RecordExtensionInit(void);
 #endif
 
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 6c1a055..9c93fc5 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -400,6 +400,9 @@ static ExtensionModule staticExtensions[] = {
 #ifdef DBE
     {DbeExtensionInit, "DOUBLE-BUFFER", &noDbeExtension, NULL},
 #endif
+#ifdef XRECORD
+    {RecordExtensionInit, "RECORD", &noTestExtensions, NULL},
+#endif
 };
 
  /*ARGSUSED*/ void
commit bf61bf69b2b4f9e9993ca771de100079c7696bea
Author: Tomas Carnecky <tom at dbservice.com>
Date:   Tue Jul 10 02:03:01 2012 +0100

    Move DBE from an external module to built-in
    
    If DBE support is compiled in the server, just man up and build it into
    the server, rather than having it as an external module.
    
    Signed-off-by: Tomas Carnecky <tom at dbservice.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 74e7e9a..13628f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1173,6 +1173,7 @@ AM_CONDITIONAL(DBE, [test "x$DBE" = xyes])
 if test "x$DBE" = xyes; then
 	AC_DEFINE(DBE, 1, [Support DBE extension])
 	DBE_LIB='$(top_builddir)/dbe/libdbe.la'
+	DBE_INC='-I$(top_srcdir)/dbe'
 fi
 
 AM_CONDITIONAL(XF86BIGFONT, [test "x$XF86BIGFONT" = xyes])
@@ -1545,7 +1546,7 @@ AC_EGREP_CPP([I_AM_SVR4],[
 AC_DEFINE([SVR4],1,[Define to 1 on systems derived from System V Release 4])
 AC_MSG_RESULT([yes])], AC_MSG_RESULT([no]))
 
-XSERVER_CFLAGS="$XSERVER_CFLAGS $CORE_INCS $XEXT_INC $COMPOSITE_INC $DAMAGE_INC $FIXES_INC $XI_INC $MI_INC $MIEXT_SYNC_INC $MIEXT_SHADOW_INC $MIEXT_LAYER_INC $MIEXT_DAMAGE_INC $RENDER_INC $RANDR_INC $FB_INC"
+XSERVER_CFLAGS="$XSERVER_CFLAGS $CORE_INCS $XEXT_INC $COMPOSITE_INC $DAMAGE_INC $FIXES_INC $XI_INC $MI_INC $MIEXT_SYNC_INC $MIEXT_SHADOW_INC $MIEXT_LAYER_INC $MIEXT_DAMAGE_INC $RENDER_INC $RANDR_INC $FB_INC $DBE_INC"
 
 dnl ---------------------------------------------------------------------------
 dnl DDX section.
@@ -1604,7 +1605,7 @@ if test "x$XORG" = xyes; then
 	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
 	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
 	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
-	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $XI_LIB $XKB_LIB"
+	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $DBE_LIB $GLX_LIBS $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $XI_LIB $XKB_LIB"
 
 	dnl ==================================================================
 	dnl symbol visibility
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 6b806a3..ce2c10a 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -110,9 +110,6 @@
 
 static ModuleDefault ModuleDefaults[] = {
     {.name = "extmod",.toLoad = TRUE,.load_opt = NULL},
-#ifdef DBE
-    {.name = "dbe",.toLoad = TRUE,.load_opt = NULL},
-#endif
 #ifdef GLXEXT
     {.name = "glx",.toLoad = TRUE,.load_opt = NULL},
 #endif
diff --git a/hw/xfree86/dixmods/Makefile.am b/hw/xfree86/dixmods/Makefile.am
index 6f4af6c..827b952 100644
--- a/hw/xfree86/dixmods/Makefile.am
+++ b/hw/xfree86/dixmods/Makefile.am
@@ -6,10 +6,6 @@ if GLX
 GLXMODS = libglx.la
 endif
 
-if DBE
-DBEMOD = libdbe.la
-endif
-
 if RECORD
 RECORDMOD = librecord.la
 endif
@@ -20,20 +16,14 @@ module_LTLIBRARIES = libfb.la \
 
 extsmoduledir = $(moduledir)/extensions
 extsmodule_LTLIBRARIES = $(RECORDMOD) \
-			 $(DBEMOD) \
                          $(GLXMODS)
 
 AM_CFLAGS = @XORG_CFLAGS@ @DIX_CFLAGS@
 INCLUDES = @XORG_INCS@ \
-           -I$(top_srcdir)/dbe \
            -I$(top_srcdir)/hw/xfree86/loader \
            -I$(top_srcdir)/miext/shadow \
            -I$(top_srcdir)/glx
 
-libdbe_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-libdbe_la_LIBADD = $(top_builddir)/dbe/libdbe.la
-libdbe_la_SOURCES = dbemodule.c
-
 libfb_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
 libfb_la_LIBADD = $(top_builddir)/fb/libfb.la
 libfb_la_SOURCES = $(top_builddir)/fb/fbcmap_mi.c fbmodule.c
diff --git a/hw/xfree86/dixmods/dbemodule.c b/hw/xfree86/dixmods/dbemodule.c
deleted file mode 100644
index fb37053..0000000
--- a/hw/xfree86/dixmods/dbemodule.c
+++ /dev/null
@@ -1,44 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-#include "globals.h"
-#include "extinit.h"
-
-static MODULESETUPPROTO(dbeSetup);
-
-static ExtensionModule dbeExt = {
-    DbeExtensionInit,
-    "DOUBLE-BUFFER",
-    &noDbeExtension,
-    NULL,
-    NULL
-};
-
-static XF86ModuleVersionInfo VersRec = {
-    "dbe",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_EXTENSION,
-    ABI_EXTENSION_VERSION,
-    MOD_CLASS_EXTENSION,
-    {0, 0, 0, 0}
-};
-
-/*
- * Data for the loader
- */
-_X_EXPORT XF86ModuleData dbeModuleData = { &VersRec, dbeSetup, NULL };
-
-static pointer
-dbeSetup(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    LoadExtension(&dbeExt, FALSE);
-
-    /* Need a non-NULL return value to indicate success */
-    return (pointer) 1;
-}
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index e7e60dd..99f06c2 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -833,6 +833,7 @@ static const char *compiled_in_modules[] = {
     "ddc",
     "i2c",
     "ramdac",
+    "dbe",
     NULL
 };
 
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index 81dbbe2..ab48fcf 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -241,9 +241,9 @@ cat > sdksyms.c << EOF
 
 
 /* dbe/Makefile.am -- module */
-/*
+#ifdef DBE
 #include "dbestruct.h"
- */
+#endif
 
 
 /* exa/Makefile.am -- module */
diff --git a/include/extinit.h b/include/extinit.h
index 5e01128..539e28d 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -63,7 +63,7 @@ extern Bool noDamageExtension;
 extern void DamageExtensionInit(void);
 #endif
 
-#if defined(DBE) && !defined(XorgLoader)
+#if defined(DBE)
 extern Bool noDbeExtension;
 extern void DbeExtensionInit(void);
 #endif
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 7b5eef6..6c1a055 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -397,6 +397,9 @@ static ExtensionModule staticExtensions[] = {
 #ifdef DAMAGE
     {DamageExtensionInit, "DAMAGE", &noDamageExtension, NULL},
 #endif
+#ifdef DBE
+    {DbeExtensionInit, "DOUBLE-BUFFER", &noDbeExtension, NULL},
+#endif
 };
 
  /*ARGSUSED*/ void
commit d785368e0e171080fea5447c87e81c93f515ff21
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:03:00 2012 +0100

    miinitext: Use ARRAY_SIZE rather than sentinel
    
    NULL sentinels are totally lame.
    
    v2: numExtensionModules isn't public, so keep using the provided
        sentinal - Keith Packard <keithp at keithp.com>
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Stéphane Marchesin <stephane.marchesin at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/mi/miinitext.c b/mi/miinitext.c
index ef20a11..7b5eef6 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -172,15 +172,16 @@ static ExtensionToggle ExtensionToggleList[] = {
 #ifdef XV
     {"XVideo", &noXvExtension},
 #endif
-    {NULL, NULL}
 };
 
 Bool
 EnableDisableExtension(const char *name, Bool enable)
 {
-    ExtensionToggle *ext = &ExtensionToggleList[0];
+    ExtensionToggle *ext;
+    int i;
 
-    for (ext = &ExtensionToggleList[0]; ext->name != NULL; ext++) {
+    for (i = 0; i < ARRAY_SIZE(ExtensionToggleList); i++) {
+        ext = &ExtensionToggleList[i];
         if (strcmp(name, ext->name) == 0) {
             if (ext->disablePtr != NULL) {
                 *ext->disablePtr = !enable;
@@ -396,7 +397,6 @@ static ExtensionModule staticExtensions[] = {
 #ifdef DAMAGE
     {DamageExtensionInit, "DAMAGE", &noDamageExtension, NULL},
 #endif
-    {NULL, NULL, NULL, NULL, NULL}
 };
 
  /*ARGSUSED*/ void
@@ -408,7 +408,7 @@ InitExtensions(int argc, char *argv[])
 
     if (!listInitialised) {
         /* Add built-in extensions to the list. */
-        for (i = 0; staticExtensions[i].name; i++)
+        for (i = 0; i < ARRAY_SIZE(staticExtensions); i++)
             LoadExtension(&staticExtensions[i], TRUE);
 
         /* Sort the extensions according the init dependencies. */
commit f48d8f58b39af0036365368d6ac35319d6d856d5
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:59 2012 +0100

    extmod: Use ARRAY_SIZE rather than sentinel
    
    When the array gets down to size zero (which it does in later patches),
    gcc complains that the index is out of bounds.  Avoid this by using
    ARRAY_SIZE on extensionModules instead.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Stéphane Marchesin <stephane.marchesin at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index afee27a..009852c 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -101,12 +101,6 @@ static ExtensionModule extensionModules[] = {
      NULL,
      NULL},
 #endif
-    {                           /* DON'T delete this entry ! */
-     NULL,
-     NULL,
-     NULL,
-     NULL,
-     NULL}
 };
 
 static XF86ModuleVersionInfo VersRec = {
@@ -134,7 +128,7 @@ extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin)
 
     /* XXX the option stuff here is largely a sample/test case */
 
-    for (i = 0; extensionModules[i].name != NULL; i++) {
+    for (i = 0; i < ARRAY_SIZE(extensionModules); i++) {
 #ifdef XSELINUX
         if (!strcmp(SELINUX_EXTENSION_NAME, extensionModules[i].name)) {
             pointer o;
commit d35884da2f5a250ff6dd5131dc23ac629eccdd0c
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:58 2012 +0100

    Add xf86ExtensionInit for DDX extension configuration
    
    xf86ExtensionInit is called after configuration file parsing, so it can
    perform the two parts of extension initialisation currently done by
    extmod: enabling and disabling of extensions through an 'omit' option,
    and SELinux configuration.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index 5fbb890..556b9cc 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -46,6 +46,7 @@ libcommon_la_SOURCES = xf86Configure.c xf86Bus.c xf86Config.c \
                       xf86VidMode.c xf86fbman.c xf86cmap.c \
                       xf86Helper.c xf86PM.c xf86Xinput.c xisb.c \
                       xf86Mode.c xorgHelper.c xf86Extensions.h \
+		      xf86Extensions.c \
                       $(XVSOURCES) $(BUSSOURCES) $(RANDRSOURCES)
 nodist_libcommon_la_SOURCES = xf86DefModeSet.c xf86Build.h
 libcommon_la_LIBADD = $(top_builddir)/config/libconfig.la
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 1e122cf..8dc7dcc 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -449,6 +449,9 @@ xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen,
                                     Bool resetMode);
 #endif
 
+/* xf86Extensions.c */
+extern void xf86ExtensionInit(void);
+
 /* convert ScreenPtr to ScrnInfoPtr */
 extern _X_EXPORT ScrnInfoPtr xf86ScreenToScrn(ScreenPtr pScreen);
 /* convert ScrnInfoPtr to ScreenPtr */
diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c
new file mode 100644
index 0000000..15c96b4
--- /dev/null
+++ b/hw/xfree86/common/xf86Extensions.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright © 2011 Daniel Stone
+ *
+ * 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, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Author: Daniel Stone <daniel at fooishbar.org>
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#include "extension.h"
+#include "globals.h"
+
+#include "xf86.h"
+#include "xf86Config.h"
+#include "xf86Module.h"
+#include "xf86Extensions.h"
+#include "xf86Opt.h"
+#include "optionstr.h"
+
+/*
+ * DDX-specific extensions.
+ */
+static ExtensionModule extensionModules[] = {
+};
+
+static void
+load_extension_config(void)
+{
+    XF86ConfModulePtr mod_con = xf86configptr->conf_modules;
+    XF86LoadPtr modp;
+
+    /* Only the best. */
+    if (!mod_con)
+        return;
+
+    nt_list_for_each_entry(modp, mod_con->mod_load_lst, list.next) {
+        InputOption *opt;
+
+        if (strcasecmp(modp->load_name, "extmod") != 0)
+            continue;
+
+        /* extmod options are of the form "omit <extension-name>" */
+        nt_list_for_each_entry(opt, modp->load_opt, list.next) {
+            const char *key = input_option_get_key(opt);
+            if (strncasecmp(key, "omit", 4) != 0 || strlen(key) < 5)
+                continue;
+            if (EnableDisableExtension(key + 4, FALSE))
+                xf86MarkOptionUsed(opt);
+        }
+    }
+}
+
+void
+xf86ExtensionInit(void)
+{
+    int i;
+
+    load_extension_config();
+
+    for (i = 0; i < ARRAY_SIZE(extensionModules); i++)
+	LoadExtension(&extensionModules[i], TRUE);
+}
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 058d09f..16991b3 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -471,6 +471,8 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
         xf86OSPMClose = xf86OSPMOpen();
 #endif
 
+        xf86ExtensionInit();
+
         /* Load all modules specified explicitly in the config file */
         if ((modulelist = xf86ModulelistFromConfig(&optionlist))) {
             xf86LoadModules(modulelist, optionlist);
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index 6477127..afee27a 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -135,21 +135,6 @@ extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin)
     /* XXX the option stuff here is largely a sample/test case */
 
     for (i = 0; extensionModules[i].name != NULL; i++) {
-        if (opts) {
-            char *s;
-
-            if (asprintf(&s, "omit%s", extensionModules[i].name) != -1) {
-                pointer o;
-
-                o = xf86FindOption(opts, s);
-                free(s);
-                if (o) {
-                    xf86MarkOptionUsed(o);
-                    continue;
-                }
-            }
-        }
-
 #ifdef XSELINUX
         if (!strcmp(SELINUX_EXTENSION_NAME, extensionModules[i].name)) {
             pointer o;
commit 4170e4e1f8e879394c896c490d9f08a38ecfdefd
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:57 2012 +0100

    Loader: Drop EXTERN_MODULE flag
    
    EXTERN_MODULE was used to specify that we shouldn't worry about modules
    lacking a ModuleData object.  It was also completely unused.  *shrug*
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 9ba874c..c48f041 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -55,9 +55,6 @@ typedef enum {
 
 #define DEFAULT_LIST ((char *)-1)
 
-/* This indicates a special module that doesn't have the usual entry point */
-#define EXTERN_MODULE ((pointer)-1)
-
 /* Built-in ABI classes.  These definitions must not be changed. */
 #define ABI_CLASS_NONE		NULL
 #define ABI_CLASS_ANSIC		"X.Org ANSI C Emulation"
diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml
index 24b0c03..118b58f 100644
--- a/hw/xfree86/doc/ddxDesign.xml
+++ b/hw/xfree86/doc/ddxDesign.xml
@@ -5363,15 +5363,6 @@ XFree86 common layer.
 		  way by modules loaded directly by the XFree86 common
 		  layer.  However, it may be used for application-specific
 		  parameter passing in other situations.
-		    </para>
-
-		    <para>
-		  When loading <quote>external</quote> modules (modules that don't
-		  have the standard entry point, for example a
-		  special shared library) the options parameter can be
-		  set to <constant>EXTERN_MODULE</constant> to tell the
-		  loader not to reject the module when it doesn't find
-		  the standard entry point.
 		    </para></listitem></varlistentry>
 
 
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index dd20573..e7e60dd 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -992,10 +992,6 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
         ret->VersionInfo = vers;
     }
     else {
-        /* No initdata is OK for external modules */
-        if (options == EXTERN_MODULE)
-            goto LoadModule_exit;
-
         /* no initdata, fail the load */
         xf86Msg(X_ERROR, "LoadModule: Module %s does not have a %s "
                 "data object.\n", module, p);
commit a1d41e311c21eb6627caa0d168e070ceaf90806f
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:56 2012 +0100

    Move extension initialisation prototypes into extinit.h
    
    Create extinit.h (and xf86Extensions.h, for Xorg-specific extensions) to
    hold all our extension initialisation prototypes, rather than
    duplicating them everywhere.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/bigreq.c b/Xext/bigreq.c
index 886b761..c78a1e4 100644
--- a/Xext/bigreq.c
+++ b/Xext/bigreq.c
@@ -38,9 +38,7 @@ from The Open Group.
 #include "extnsionst.h"
 #include <X11/extensions/bigreqsproto.h>
 #include "opaque.h"
-#include "modinit.h"
-
-void BigReqExtensionInit(void);
+#include "extinit.h"
 
 static int
 ProcBigReqDispatch(ClientPtr client)
diff --git a/Xext/dpms.c b/Xext/dpms.c
index 8cff8bd..5f1a35d 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -39,7 +39,7 @@ Equipment Corporation.
 #include "opaque.h"
 #include <X11/extensions/dpmsproto.h>
 #include "dpmsproc.h"
-#include "modinit.h"
+#include "extinit.h"
 
 static int
 ProcDPMSGetVersion(ClientPtr client)
diff --git a/Xext/geext.c b/Xext/geext.c
index fc16b8a..ad7f963 100644
--- a/Xext/geext.c
+++ b/Xext/geext.c
@@ -32,6 +32,7 @@
 #include "geint.h"
 #include "geext.h"
 #include "protocol-versions.h"
+#include "extinit.h"
 
 DevPrivateKeyRec GEClientPrivateKeyRec;
 
diff --git a/Xext/geext.h b/Xext/geext.h
index d2a15dc..f468979 100644
--- a/Xext/geext.h
+++ b/Xext/geext.h
@@ -78,6 +78,4 @@ extern _X_EXPORT void GERegisterExtension(int extension,
 
 extern _X_EXPORT void GEInitEvent(xGenericEvent *ev, int extension);
 
-extern _X_EXPORT void GEExtensionInit(void);
-
 #endif                          /* _GEEXT_H_ */
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index df67c00..3398a8d 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -59,7 +59,7 @@ Equipment Corporation.
 #ifdef COMPOSITE
 #include "compint.h"
 #endif
-#include "modinit.h"
+#include "extinit.h"
 #include "protocol-versions.h"
 
 #ifdef GLXPROXY
diff --git a/Xext/saver.c b/Xext/saver.c
index eefb497..ac4a633 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -58,7 +58,7 @@ in this Software without prior written authorization from the X Consortium.
 
 #include <stdio.h>
 
-#include "modinit.h"
+#include "extinit.h"
 
 static int ScreenSaverEventBase = 0;
 
diff --git a/Xext/security.c b/Xext/security.c
index c101b7d..6cc9aa0 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -38,7 +38,7 @@ in this Software without prior written authorization from The Open Group.
 #include "xacestr.h"
 #include "securitysrv.h"
 #include <X11/extensions/securproto.h>
-#include "modinit.h"
+#include "extinit.h"
 #include "protocol-versions.h"
 
 /* Extension stuff */
diff --git a/Xext/shape.c b/Xext/shape.c
index 68cbef2..d36867c 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -44,7 +44,7 @@ in this Software without prior written authorization from The Open Group.
 #include <X11/extensions/shapeproto.h>
 #include "regionstr.h"
 #include "gcstruct.h"
-#include "modinit.h"
+#include "extinit.h"
 #include "protocol-versions.h"
 
 typedef RegionPtr (*CreateDftPtr) (WindowPtr    /* pWin */
diff --git a/Xext/shm.c b/Xext/shm.c
index fd0c41f..3fa04b9 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -87,7 +87,7 @@ in this Software without prior written authorization from The Open Group.
 #include "panoramiXsrv.h"
 #endif
 
-#include "modinit.h"
+#include "extinit.h"
 
 typedef struct _ShmDesc {
     struct _ShmDesc *next;
diff --git a/Xext/sync.c b/Xext/sync.c
index b203c5e..8a333dd 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -76,7 +76,7 @@ PERFORMANCE OF THIS SOFTWARE.
 #include <sys/time.h>
 #endif
 
-#include "modinit.h"
+#include "extinit.h"
 
 /*
  * Local Global Variables
diff --git a/Xext/syncsrv.h b/Xext/syncsrv.h
index dbed476..c68229f 100644
--- a/Xext/syncsrv.h
+++ b/Xext/syncsrv.h
@@ -134,8 +134,6 @@ extern void SyncChangeCounter(SyncCounter *pCounter,
 
 extern void SyncDestroySystemCounter(pointer pCounter);
 
-extern void SyncExtensionInit(void);
-
 extern SyncCounter *SyncInitDeviceIdleTime(DeviceIntPtr dev);
 extern void SyncRemoveDeviceIdleTime(SyncCounter *counter);
 #endif                          /* _SYNCSRV_H_ */
diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index cfde3b3..034bfb6 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -38,7 +38,7 @@ from The Open Group.
 #include "extnsionst.h"
 #include "swaprep.h"
 #include <X11/extensions/xcmiscproto.h>
-#include "modinit.h"
+#include "extinit.h"
 
 #include <stdint.h>
 
diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index d91ff95..b4ef5e4 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -71,6 +71,7 @@
 #include "gcstruct.h"
 #include "dixfontstr.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "protocol-versions.h"
 
 #include <X11/extensions/xf86bigfproto.h>
diff --git a/Xext/xf86bigfontsrv.h b/Xext/xf86bigfontsrv.h
index 2c78dc4..eab5287 100644
--- a/Xext/xf86bigfontsrv.h
+++ b/Xext/xf86bigfontsrv.h
@@ -27,7 +27,6 @@
 
 #include <X11/fonts/font.h>
 
-extern void XFree86BigfontExtensionInit(void);
 extern void XF86BigfontFreeFontShm(FontPtr);
 extern void XF86BigfontCleanup(void);
 
diff --git a/Xext/xres.c b/Xext/xres.c
index acc5b8c..445abca 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -21,7 +21,7 @@
 #include "pixmapstr.h"
 #include "windowstr.h"
 #include "gcstruct.h"
-#include "modinit.h"
+#include "extinit.h"
 #include "protocol-versions.h"
 #include "client.h"
 #include "list.h"
diff --git a/Xext/xselinux_ext.c b/Xext/xselinux_ext.c
index 220e876..3115f03 100644
--- a/Xext/xselinux_ext.c
+++ b/Xext/xselinux_ext.c
@@ -26,7 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "windowstr.h"
 #include "propertyst.h"
 #include "extnsionst.h"
-#include "modinit.h"
+#include "extinit.h"
 #include "xselinuxint.h"
 
 #define CTX_DEV offsetof(SELinuxSubjectRec, dev_create_sid)
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 4938e3b..c593372 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -55,7 +55,7 @@
 #include "eventstr.h"
 #include "inpututils.h"
 
-#include "modinit.h"
+#include "extinit.h"
 
 extern int DeviceValuator;
 
diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index 59fc1ff..fdf33d3 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -235,7 +235,6 @@ typedef struct {
 extern _X_EXPORT int ProcXvDispatch(ClientPtr);
 extern _X_EXPORT int SProcXvDispatch(ClientPtr);
 
-extern _X_EXPORT void XvExtensionInit(void);
 extern _X_EXPORT int XvScreenInit(ScreenPtr);
 extern _X_EXPORT DevPrivateKey XvGetScreenKey(void);
 extern _X_EXPORT unsigned long XvGetRTPort(void);
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 74872fc..c2860b8 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -88,6 +88,7 @@ SOFTWARE.
 #include "pixmapstr.h"
 #include "gc.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "dixstruct.h"
 #include "resource.h"
 #include "opaque.h"
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index d74302b..808691c 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -13,6 +13,7 @@
 #include "resource.h"
 #include "scrnintstr.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "servermd.h"
 #include <X11/Xfuncproto.h>
 #include "xvdix.h"
diff --git a/Xext/xvmcext.h b/Xext/xvmcext.h
index 5a4261b..d78171d 100644
--- a/Xext/xvmcext.h
+++ b/Xext/xvmcext.h
@@ -85,8 +85,6 @@ typedef struct {
 } XvMCAdaptorRec, *XvMCAdaptorPtr;
 
 #ifndef XorgLoader
-extern _X_EXPORT void XvMCExtensionInit(void);
-
 extern _X_EXPORT int XvMCScreenInit(ScreenPtr pScreen,
                                     int num, XvMCAdaptorPtr adapt);
 
diff --git a/composite/compext.c b/composite/compext.c
index eea1a58..8641eff 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -48,6 +48,7 @@
 #include "compint.h"
 #include "xace.h"
 #include "protocol-versions.h"
+#include "extinit.h"
 
 static CARD8 CompositeReqCode;
 static DevPrivateKeyRec CompositeClientPrivateKeyRec;
diff --git a/composite/compint.h b/composite/compint.h
index 30b724e..45b5824 100644
--- a/composite/compint.h
+++ b/composite/compint.h
@@ -229,13 +229,6 @@ compReallocPixmap(WindowPtr pWin, int x, int y,
                   unsigned int w, unsigned int h, int bw);
 
 /*
- * compext.c
- */
-
-void
- CompositeExtensionInit(void);
-
-/*
  * compinit.c
  */
 
diff --git a/damageext/Makefile.am b/damageext/Makefile.am
index 35f7620..4d4cf44 100644
--- a/damageext/Makefile.am
+++ b/damageext/Makefile.am
@@ -4,5 +4,4 @@ AM_CFLAGS = $(DIX_CFLAGS)
 
 libdamageext_la_SOURCES = 	\
 	damageext.c		\
-	damageext.h		\
 	damageextint.h
diff --git a/damageext/damageext.c b/damageext/damageext.c
index 222643c..a942ffa 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -26,6 +26,7 @@
 
 #include "damageextint.h"
 #include "protocol-versions.h"
+#include "extinit.h"
 
 static unsigned char DamageReqCode;
 static int DamageEventBase;
diff --git a/damageext/damageextint.h b/damageext/damageextint.h
index b7e63e0..2723379 100644
--- a/damageext/damageextint.h
+++ b/damageext/damageextint.h
@@ -37,7 +37,6 @@
 #include "windowstr.h"
 #include "selection.h"
 #include "scrnintstr.h"
-#include "damageext.h"
 #include "damage.h"
 #include "xfixes.h"
 
diff --git a/dbe/dbe.c b/dbe/dbe.c
index 8f3d1b0..9039d80 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -42,6 +42,7 @@
 #include <X11/Xproto.h>
 #include "scrnintstr.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "gcstruct.h"
 #include "dixstruct.h"
 #define NEED_DBE_PROTOCOL
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index 9ea9eb6..f9d938a 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -83,8 +83,6 @@ typedef struct {
 /* Marker for free elements in the buffer ID array. */
 #define DBE_FREE_ID_ELEMENT	0
 
-extern _X_EXPORT void DbeExtensionInit(void);
-
 /* TYPEDEFS */
 
 /* Record used to pass swap information between DIX and DDX swapping
diff --git a/glx/glxext.c b/glx/glxext.c
index e506aec..a1f9d42 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -39,6 +39,7 @@
 #include <registry.h>
 #include "privates.h"
 #include <os.h>
+#include "extinit.h"
 #include "unpack.h"
 #include "glxutil.h"
 #include "glxext.h"
@@ -338,6 +339,9 @@ GlxExtensionInit(void)
     if (!__glXContextRes || !__glXDrawableRes)
         return;
 
+    if (serverGeneration == 1)
+        GlxPushProvider(&__glXDRISWRastProvider);
+
     if (!dixRegisterPrivateKey
         (&glxClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(__GLXclientState)))
         return;
diff --git a/glx/glxserver.h b/glx/glxserver.h
index 61c45c5..d9b106b 100644
--- a/glx/glxserver.h
+++ b/glx/glxserver.h
@@ -76,8 +76,6 @@ extern __GLXclientState *glxGetClient(ClientPtr pClient);
 
 /************************************************************************/
 
-void GlxExtensionInit(void);
-
 void GlxSetVisualConfigs(int nconfigs, void *configs, void **privates);
 
 void __glXScreenInitVisuals(__GLXscreen * screen);
diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c
index 9df94a4..0f7cb5c 100644
--- a/hw/dmx/dmx.c
+++ b/hw/dmx/dmx.c
@@ -52,6 +52,7 @@
 #include "os.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "opaque.h"
 
 #include "dmxextension.h"
@@ -65,8 +66,6 @@ extern unsigned long XRT_WINDOW;
 extern int PanoramiXNumScreens;
 #endif
 
-extern void DMXExtensionInit(void);
-
 static unsigned char DMXCode;
 
 static int
diff --git a/hw/dmx/glxProxy/glxext.c b/hw/dmx/glxProxy/glxext.c
index 9532837..8122221 100644
--- a/hw/dmx/glxProxy/glxext.c
+++ b/hw/dmx/glxProxy/glxext.c
@@ -44,6 +44,7 @@
 #include "glxvisuals.h"
 #include "micmap.h"
 #include "glxswap.h"
+#include "extinit.h"
 
 /*
 ** Forward declarations.
diff --git a/hw/dmx/glxProxy/glxext.h b/hw/dmx/glxProxy/glxext.h
index 881152d..47cec15 100644
--- a/hw/dmx/glxProxy/glxext.h
+++ b/hw/dmx/glxProxy/glxext.h
@@ -64,8 +64,6 @@ extern void __glXResetLargeCommandStatus(__GLXclientState *);
 extern int __glXQueryContextInfoEXT(__GLXclientState * cl, GLbyte * pc);
 extern int __glXSwapQueryContextInfoEXT(__GLXclientState * cl, char *pc);
 
-extern void GlxExtensionInit(void);
-
 extern Bool __glXCoreType(void);
 
 #endif                          /* _glxext_h_ */
diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index 65d98e6..5fbb890 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -45,7 +45,7 @@ libcommon_la_SOURCES = xf86Configure.c xf86Bus.c xf86Config.c \
                       xf86Option.c xf86Init.c \
                       xf86VidMode.c xf86fbman.c xf86cmap.c \
                       xf86Helper.c xf86PM.c xf86Xinput.c xisb.c \
-                      xf86Mode.c xorgHelper.c \
+                      xf86Mode.c xorgHelper.c xf86Extensions.h \
                       $(XVSOURCES) $(BUSSOURCES) $(RANDRSOURCES)
 nodist_libcommon_la_SOURCES = xf86DefModeSet.c xf86Build.h
 libcommon_la_LIBADD = $(top_builddir)/config/libconfig.la
diff --git a/hw/xfree86/common/vidmodeproc.h b/hw/xfree86/common/vidmodeproc.h
index aa43237..311d35c 100644
--- a/hw/xfree86/common/vidmodeproc.h
+++ b/hw/xfree86/common/vidmodeproc.h
@@ -39,7 +39,7 @@ typedef union {
     float f;
 } vidMonitorValue;
 
-extern _X_EXPORT void XFree86VidModeExtensionInit(void);
+extern Bool VidModeExtensionInit(ScreenPtr pScreen);
 
 extern _X_EXPORT Bool VidModeAvailable(int scrnIndex);
 extern _X_EXPORT Bool VidModeGetCurrentModeline(int scrnIndex, pointer *mode,
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 6116985..1e122cf 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -449,11 +449,6 @@ xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen,
                                     Bool resetMode);
 #endif
 
-/* xf86VidModeExtentionInit.c */
-
-extern _X_EXPORT Bool
-VidModeExtensionInit(ScreenPtr pScreen);
-
 /* convert ScreenPtr to ScrnInfoPtr */
 extern _X_EXPORT ScrnInfoPtr xf86ScreenToScrn(ScreenPtr pScreen);
 /* convert ScrnInfoPtr to ScreenPtr */
diff --git a/hw/xfree86/common/xf86Extensions.h b/hw/xfree86/common/xf86Extensions.h
new file mode 100644
index 0000000..f86a421
--- /dev/null
+++ b/hw/xfree86/common/xf86Extensions.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright © 2011 Daniel Stone
+ *
+ * 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, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Author: Daniel Stone <daniel at fooishbar.org>
+ */
+
+#ifndef XF86EXTENSIONS_H
+#define XF86EXTENSIONS_H
+
+#include "extnsionst.h"
+
+#ifdef XF86DRI
+extern Bool noXFree86DRIExtension;
+extern void XFree86DRIExtensionInit(void);
+#endif
+
+#ifdef DRI2
+#include <X11/extensions/dri2proto.h>
+extern void DRI2ExtensionInit(void);
+#endif
+
+#ifdef XF86VIDMODE
+#include <X11/extensions/xf86vmproto.h>
+extern Bool noXFree86VidModeExtension;
+extern void XFree86VidModeExtensionInit(void);
+#endif
+
+#ifdef XFreeXDGA
+#include <X11/extensions/xf86dgaproto.h>
+extern Bool noXFree86DGAExtension;
+extern void XFree86DGAExtensionInit(void);
+extern void XFree86DGARegister(void);
+#endif
+
+#endif
diff --git a/hw/xfree86/dixmods/dbemodule.c b/hw/xfree86/dixmods/dbemodule.c
index fea3d9f..fb37053 100644
--- a/hw/xfree86/dixmods/dbemodule.c
+++ b/hw/xfree86/dixmods/dbemodule.c
@@ -4,11 +4,10 @@
 
 #include "xf86Module.h"
 #include "globals.h"
+#include "extinit.h"
 
 static MODULESETUPPROTO(dbeSetup);
 
-extern void DbeExtensionInit(void);
-
 static ExtensionModule dbeExt = {
     DbeExtensionInit,
     "DOUBLE-BUFFER",
diff --git a/hw/xfree86/dixmods/extmod/Makefile.am b/hw/xfree86/dixmods/extmod/Makefile.am
index d08e9ad..cdbd82e 100644
--- a/hw/xfree86/dixmods/extmod/Makefile.am
+++ b/hw/xfree86/dixmods/extmod/Makefile.am
@@ -23,7 +23,6 @@ INCLUDES = @XORG_INCS@ \
 
 libextmod_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
 libextmod_la_SOURCES = modinit.c \
-                       modinit.h \
                        $(DGA_SRCS) \
                        $(XF86VMODE_SRCS) \
                        $(XV_SRCS)
diff --git a/hw/xfree86/dixmods/extmod/modinit.c b/hw/xfree86/dixmods/extmod/modinit.c
index ca15ee0..6477127 100644
--- a/hw/xfree86/dixmods/extmod/modinit.c
+++ b/hw/xfree86/dixmods/extmod/modinit.c
@@ -29,7 +29,8 @@
 
 #include <X11/Xproto.h>
 
-#include "modinit.h"
+#include "extinit.h"
+#include "xf86Extensions.h"
 #include "globals.h"
 
 static MODULESETUPPROTO(extmodSetup);
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 4cae949..808aa69 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -17,6 +17,7 @@
 #include "dixevents.h"
 #include "pixmapstr.h"
 #include "extnsionst.h"
+#include "xf86Extensions.h"
 #include "colormapst.h"
 #include "cursorstr.h"
 #include "scrnintstr.h"
@@ -28,7 +29,7 @@
 
 #include <string.h>
 
-#include "modinit.h"
+#include "extinit.h"
 
 #define DGA_PROTOCOL_OLD_SUPPORT 1
 
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 3d66852..7cd2eed 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -39,6 +39,7 @@ from Kaleb S. KEITHLEY
 #include "misc.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
+#include "xf86Extensions.h"
 #include "scrnintstr.h"
 #include "servermd.h"
 #include <X11/extensions/xf86vmproto.h>
diff --git a/hw/xfree86/dixmods/glxmodule.c b/hw/xfree86/dixmods/glxmodule.c
index 4482cbc..f263324 100644
--- a/hw/xfree86/dixmods/glxmodule.c
+++ b/hw/xfree86/dixmods/glxmodule.c
@@ -42,6 +42,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "micmap.h"
 #include "globals.h"
 #include "glxserver.h"
+#include "extinit.h"
 
 static MODULESETUPPROTO(glxSetup);
 
diff --git a/hw/xfree86/dixmods/recordmod.c b/hw/xfree86/dixmods/recordmod.c
index fe52fa8..4f8eb97 100644
--- a/hw/xfree86/dixmods/recordmod.c
+++ b/hw/xfree86/dixmods/recordmod.c
@@ -3,13 +3,12 @@
 #endif
 
 #include "xf86Module.h"
+#include "extinit.h"
 
 extern Bool noTestExtensions;
 
 static MODULESETUPPROTO(recordSetup);
 
-extern void RecordExtensionInit(void);
-
 static ExtensionModule recordExt = {
     RecordExtensionInit,
     "RECORD",
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index 46a9ae4..a3e7870 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -51,6 +51,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "misc.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "colormapst.h"
 #include "cursorstr.h"
 #include "scrnintstr.h"
@@ -68,6 +69,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86_OSproc.h"
 #include "inputstr.h"
 #include "xf86VGAarbiter.h"
+#include "xf86Extensions.h"
 
 static int DRIEntPrivIndex = -1;
 static DevPrivateKeyRec DRIScreenPrivKeyRec;
diff --git a/hw/xfree86/dri/drimodule.c b/hw/xfree86/dri/drimodule.c
index eb42ef6..6cb3bfb 100644
--- a/hw/xfree86/dri/drimodule.c
+++ b/hw/xfree86/dri/drimodule.c
@@ -37,6 +37,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 #include "xf86Module.h"
+#include "xf86Extensions.h"
 #include "globals.h"
 
 #include "xf86drm.h"
@@ -57,7 +58,6 @@ static XF86ModuleVersionInfo VersRec = {
     {0, 0, 0, 0}
 };
 
-extern void XFree86DRIExtensionInit(void);
 #define _XF86DRI_SERVER_
 #include <X11/dri/xf86driproto.h>
 
diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
index 310bb5e..ba74bb0 100644
--- a/hw/xfree86/dri/xf86dri.c
+++ b/hw/xfree86/dri/xf86dri.c
@@ -47,6 +47,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "misc.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "colormapst.h"
 #include "cursorstr.h"
 #include "scrnintstr.h"
@@ -60,17 +61,17 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "dristruct.h"
 #include "xf86drm.h"
 #include "protocol-versions.h"
+#include "xf86Extensions.h"
 
 static int DRIErrorBase;
 
-static void XF86DRIResetProc(ExtensionEntry * extEntry);
+static void XF86DRIResetProc(ExtensionEntry *extEntry);
 
 static unsigned char DRIReqCode = 0;
 
-extern void XFree86DRIExtensionInit(void);
-
- /*ARGSUSED*/ static void
-XF86DRIResetProc(ExtensionEntry * extEntry)
+/*ARGSUSED*/
+static void
+XF86DRIResetProc(ExtensionEntry *extEntry)
 {
     DRIReset();
 }
diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index f6c3f22..81dbbe2 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -279,7 +279,6 @@ cat > sdksyms.c << EOF
 #include "dixstruct.h"
 #include "exevents.h"
 #include "extension.h"
-#include "extinit.h"
 #include "extnsionst.h"
 #include "gc.h"
 #include "gcstruct.h"
diff --git a/hw/xquartz/pseudoramiX.c b/hw/xquartz/pseudoramiX.c
index c146687..3e10500 100644
--- a/hw/xquartz/pseudoramiX.c
+++ b/hw/xquartz/pseudoramiX.c
@@ -40,6 +40,7 @@
 #include "darwin.h"
 #include "pseudoramiX.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "dixstruct.h"
 #include "window.h"
 #include <X11/extensions/panoramiXproto.h>
diff --git a/hw/xquartz/pseudoramiX.h b/hw/xquartz/pseudoramiX.h
index f41b5cb..f063919 100644
--- a/hw/xquartz/pseudoramiX.h
+++ b/hw/xquartz/pseudoramiX.h
@@ -6,6 +6,5 @@ extern int noPseudoramiXExtension;
 
 void
 PseudoramiXAddScreen(int x, int y, int w, int h);
-void PseudoramiXExtensionInit(int argc, char *argv[]);
 void
 PseudoramiXResetScreens(void);
diff --git a/hw/xquartz/xpr/dri.c b/hw/xquartz/xpr/dri.c
index 002ec94..663d61d 100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@ -55,6 +55,7 @@
 #include "misc.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "colormapst.h"
 #include "cursorstr.h"
 #include "scrnintstr.h"
diff --git a/hw/xquartz/xpr/dri.h b/hw/xquartz/xpr/dri.h
index 8717a51..7d1c4f2 100644
--- a/hw/xquartz/xpr/dri.h
+++ b/hw/xquartz/xpr/dri.h
@@ -72,9 +72,6 @@ DRIFinishScreenInit(ScreenPtr pScreen);
 extern void
 DRICloseScreen(ScreenPtr pScreen);
 
-extern Bool
-DRIExtensionInit(void);
-
 extern void
 DRIReset(void);
 
diff --git a/include/extinit.h b/include/extinit.h
index a048b72..5e01128 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -23,8 +23,29 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 ********************************************************/
 
-/********************************************************************
- * Interface of extinit.c
+/*
+ * Copyright (C) 1994-2003 The XFree86 Project, Inc.  All Rights Reserved.
+ *
+ * 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, and to permit persons to whom the Software is furnished to do
+ * so, subject to the following conditions:
+ *
+ * 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, FIT-
+ * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ * XFREE86 PROJECT 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 XFree86 Project 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 XFree86 Project.
  */
 
 #ifndef EXTINIT_H
@@ -32,14 +53,135 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 #include "extnsionst.h"
 
-extern void
- XInputExtensionInit(void
-    );
+#ifdef COMPOSITE
+extern Bool noCompositeExtension;
+extern void CompositeExtensionInit(void);
+#endif
 
-extern _X_EXPORT void
- AssignTypeAndName(DeviceIntPtr /* dev */ ,
-                   Atom /* type */ ,
-                   const char * /* name */
-    );
+#ifdef DAMAGE
+extern Bool noDamageExtension;
+extern void DamageExtensionInit(void);
+#endif
 
-#endif                          /* EXTINIT_H */
+#if defined(DBE) && !defined(XorgLoader)
+extern Bool noDbeExtension;
+extern void DbeExtensionInit(void);
+#endif
+
+#ifdef DMXEXT
+extern void DMXExtensionInit(void);
+#endif
+
+#if defined(DPMSExtension) && !defined(XorgLoader)
+#include <X11/extensions/dpmsconst.h>
+extern Bool noDPMSExtension;
+extern void DPMSExtensionInit(void);
+#endif
+
+extern Bool noGEExtension;
+extern void GEExtensionInit(void);
+
+#ifdef GLXEXT
+extern _X_EXPORT Bool noGlxExtension;
+extern void GlxExtensionInit(void);
+#endif
+
+#ifdef PANORAMIX
+#include <X11/extensions/panoramiXproto.h>
+extern Bool noPanoramiXExtension;
+extern void PanoramiXExtensionInit(void);
+#endif
+
+#ifdef RANDR
+extern Bool noRRExtension;
+extern void RRExtensionInit(void);
+#endif
+
+#if defined(XRECORD) && !defined(XorgLoader)
+extern void RecordExtensionInit(void);
+#endif
+
+extern Bool noRenderExtension;
+extern void RenderExtensionInit(void);
+
+#if defined(RES) && !defined(XorgLoader)
+#include <X11/extensions/XResproto.h>
+extern Bool noResExtension;
+extern void ResExtensionInit(void);
+#endif
+
+#if defined(SCREENSAVER) && !defined(XorgLoader)
+#include <X11/extensions/saver.h>
+extern Bool noScreenSaverExtension;
+extern void ScreenSaverExtensionInit(void);
+#endif
+
+#include <X11/extensions/shapeproto.h>
+extern void ShapeExtensionInit(void);
+
+#ifdef MITSHM
+#include <X11/extensions/shm.h>
+#include <X11/extensions/shmproto.h>
+extern Bool noMITShmExtension;
+extern void ShmExtensionInit(void);
+#endif
+
+extern void SyncExtensionInit(void);
+
+extern void XCMiscExtensionInit(void);
+
+#ifdef XCSECURITY
+#include <X11/extensions/secur.h>
+#include "securitysrv.h"
+extern Bool noSecurityExtension;
+extern void SecurityExtensionInit(void);
+#endif
+
+#ifdef XF86BIGFONT
+#include <X11/extensions/xf86bigfproto.h>
+extern Bool noXFree86BigfontExtension;
+extern void XFree86BigfontExtensionInit(void);
+#endif
+
+extern void BigReqExtensionInit(void);
+
+#ifdef XFIXES
+extern Bool noXFixesExtension;
+extern void XFixesExtensionInit(void);
+#endif
+
+extern void XInputExtensionInit(void);
+extern _X_EXPORT void AssignTypeAndName(DeviceIntPtr dev,
+                                        Atom type,
+                                        const char *name);
+
+#include <X11/extensions/XKB.h>
+extern void XkbExtensionInit(void);
+
+#if defined(XSELINUX) && !defined(XorgLoader)
+#include "xselinux.h"
+extern Bool noSELinuxExtension;
+extern void SELinuxExtensionInit(void);
+#endif
+
+#ifdef XTEST
+#include <X11/extensions/xtestconst.h>
+#include <X11/extensions/xtestproto.h>
+extern void XTestExtensionInit(void);
+#endif
+
+#ifdef INXQUARTZ
+extern Bool noPseudoramiXExtension;
+extern void PseudoramiXExtensionInit(void);
+#endif
+
+#if defined(XV) && !defined(XorgLoader)
+#include <X11/extensions/Xv.h>
+#include <X11/extensions/XvMC.h>
+extern Bool noXvExtension;
+extern void XvExtensionInit(void);
+extern void XvMCExtensionInit(void);
+extern void XvRegister(void);
+#endif
+
+#endif
diff --git a/include/globals.h b/include/globals.h
index 6d3f3d7..7786987 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -5,6 +5,7 @@
 #include <signal.h>
 
 #include "window.h"             /* for WindowPtr */
+#include "extinit.h"
 
 /* Global X server variables that are visible to mi, dix, os, and ddx */
 
@@ -41,79 +42,7 @@ extern _X_EXPORT Bool DPMSCapableFlag;
 extern _X_EXPORT Bool PanoramiXExtensionDisabledHack;
 #endif
 
-#ifdef COMPOSITE
-extern _X_EXPORT Bool noCompositeExtension;
-#endif
-
-#ifdef DAMAGE
-extern _X_EXPORT Bool noDamageExtension;
-#endif
-
-#ifdef DBE
-extern _X_EXPORT Bool noDbeExtension;
-#endif
-
-#ifdef DPMSExtension
-extern _X_EXPORT Bool noDPMSExtension;
-#endif
-
-#ifdef GLXEXT
-extern _X_EXPORT Bool noGlxExtension;
-#endif
-
-#ifdef SCREENSAVER
-extern _X_EXPORT Bool noScreenSaverExtension;
-#endif
-
-#ifdef MITSHM
-extern _X_EXPORT Bool noMITShmExtension;
-#endif
-
-#ifdef RANDR
-extern _X_EXPORT Bool noRRExtension;
-#endif
-
-extern _X_EXPORT Bool noRenderExtension;
-
-#ifdef XCSECURITY
-extern _X_EXPORT Bool noSecurityExtension;
-#endif
-
-#ifdef RES
-extern _X_EXPORT Bool noResExtension;
-#endif
-
-#ifdef XF86BIGFONT
-extern _X_EXPORT Bool noXFree86BigfontExtension;
-#endif
-
-#ifdef XFreeXDGA
-extern _X_EXPORT Bool noXFree86DGAExtension;
-#endif
-
-#ifdef XF86DRI
-extern _X_EXPORT Bool noXFree86DRIExtension;
-#endif
-
-#ifdef XF86VIDMODE
-extern _X_EXPORT Bool noXFree86VidModeExtension;
-#endif
-
-#ifdef XFIXES
-extern _X_EXPORT Bool noXFixesExtension;
-#endif
-
-#ifdef PANORAMIX
-extern _X_EXPORT Bool noPanoramiXExtension;
-#endif
-
-#ifdef INXQUARTZ
-extern _X_EXPORT Bool noPseudoramiXExtension;
-#endif
-
 #ifdef XSELINUX
-extern _X_EXPORT Bool noSELinuxExtension;
-
 #define SELINUX_MODE_DEFAULT    0
 #define SELINUX_MODE_DISABLED   1
 #define SELINUX_MODE_PERMISSIVE 2
@@ -121,12 +50,4 @@ extern _X_EXPORT Bool noSELinuxExtension;
 extern _X_EXPORT int selinuxEnforcingState;
 #endif
 
-#ifdef XV
-extern _X_EXPORT Bool noXvExtension;
-#endif
-
-#ifdef DRI2
-extern _X_EXPORT Bool noDRI2Extension;
-#endif
-
 #endif                          /* !_XSERV_GLOBAL_H_ */
diff --git a/include/window.h b/include/window.h
index 7842b4d..f8fc2a5 100644
--- a/include/window.h
+++ b/include/window.h
@@ -214,10 +214,8 @@ extern _X_EXPORT void ResizeChildrenWinSize(WindowPtr /*pWin */ ,
                                             int /*dw */ ,
                                             int /*dh */ );
 
-extern _X_EXPORT void ShapeExtensionInit(void);
-
 extern _X_EXPORT void SendShapeNotify(WindowPtr /* pWin */ ,
-                                      int /* which */ );
+                                      int /* which */);
 
 extern _X_EXPORT RegionPtr CreateBoundingShape(WindowPtr /* pWin */ );
 
diff --git a/mi/miinitext.c b/mi/miinitext.c
index e60cc3f..ef20a11 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -90,114 +90,15 @@ SOFTWARE.
 
 #include "misc.h"
 #include "extension.h"
+#include "extinit.h"
 #include "micmap.h"
 #include "globals.h"
 
-extern Bool noGEExtension;
-
 #ifndef XFree86LOADER
 typedef void (*InitExtension) (void);
 #else                           /* XFree86Loader */
 #include "loaderProcs.h"
-#endif
-
-#ifdef MITSHM
-#include <X11/extensions/shm.h>
-#endif
-#ifdef XTEST
-#include <X11/extensions/xtestconst.h>
-#endif
-#include <X11/extensions/XKB.h>
-#ifdef XCSECURITY
-#include "securitysrv.h"
-#include <X11/extensions/secur.h>
-#endif
-#ifdef XSELINUX
-#include "xselinux.h"
-#endif
-#ifdef PANORAMIX
-#include <X11/extensions/panoramiXproto.h>
-#endif
-#ifdef XF86BIGFONT
-#include <X11/extensions/xf86bigfproto.h>
-#endif
-#ifdef RES
-#include <X11/extensions/XResproto.h>
-#endif
-
-/* FIXME: this whole block of externs should be from the appropriate headers */
-#ifdef MITSHM
-extern void ShmExtensionInit(void);
-#endif
-#ifdef PANORAMIX
-extern void PanoramiXExtensionInit(void);
-#endif
-#ifdef INXQUARTZ
-extern void PseudoramiXExtensionInit(void);
-#endif
-extern void XInputExtensionInit(void);
-#ifdef XTEST
-extern void XTestExtensionInit(void);
-#endif
-extern void BigReqExtensionInit(void);
-#ifdef SCREENSAVER
-extern void ScreenSaverExtensionInit(void);
-#endif
-#ifdef XV
-extern void XvExtensionInit(void);
-extern void XvMCExtensionInit(void);
-#endif
-extern void SyncExtensionInit(void);
-extern void XkbExtensionInit(void);
-extern void XCMiscExtensionInit(void);
-#ifdef XRECORD
-extern void RecordExtensionInit(void);
-#endif
-#ifdef DBE
-extern void DbeExtensionInit(void);
-#endif
-#ifdef XCSECURITY
-extern void SecurityExtensionInit(void);
-#endif
-#ifdef XSELINUX
-extern void SELinuxExtensionInit(void);
-#endif
-#ifdef XF86BIGFONT
-extern void XFree86BigfontExtensionInit(void);
-#endif
-#ifdef XF86VIDMODE
-extern void XFree86VidModeExtensionInit(void);
-#endif
-#ifdef XFreeXDGA
-extern void XFree86DGAExtensionInit(void);
-#endif
-#ifdef GLXEXT
-extern void GlxExtensionInit(void);
-#endif
-#ifdef XF86DRI
-extern void XFree86DRIExtensionInit(void);
-#endif
-#ifdef DPMSExtension
-extern void DPMSExtensionInit(void);
-#endif
-extern void RenderExtensionInit(void);
-#ifdef RANDR
-extern void RRExtensionInit(void);
-#endif
-#ifdef RES
-extern void ResExtensionInit(void);
-#endif
-#ifdef DMXEXT
-extern void DMXExtensionInit(void);
-#endif
-#ifdef XFIXES
-extern void XFixesExtensionInit(void);
-#endif
-#ifdef DAMAGE
-extern void DamageExtensionInit(void);
-#endif
-#ifdef COMPOSITE
-extern void CompositeExtensionInit(void);
+#include "xf86Extensions.h"
 #endif
 
 /* The following is only a small first step towards run-time
@@ -245,6 +146,7 @@ static ExtensionToggle ExtensionToggleList[] = {
 #ifdef XF86BIGFONT
     {"XFree86-Bigfont", &noXFree86BigfontExtension},
 #endif
+#ifndef NO_HW_ONLY_EXTS
 #ifdef XFreeXDGA
     {"XFree86-DGA", &noXFree86DGAExtension},
 #endif
@@ -254,6 +156,7 @@ static ExtensionToggle ExtensionToggleList[] = {
 #ifdef XF86VIDMODE
     {"XFree86-VidModeExtension", &noXFree86VidModeExtension},
 #endif
+#endif
 #ifdef XFIXES
     {"XFIXES", &noXFixesExtension},
 #endif
diff --git a/randr/randr.c b/randr/randr.c
index 3050c54..da48c3f 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -30,6 +30,7 @@
 #endif
 
 #include "randrstr.h"
+#include "extinit.h"
 
 /* From render.h */
 #ifndef SubPixelUnknown
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 62b9050..212b0a9 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -418,10 +418,6 @@ extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType, RRProviderType;
 #define GetRRClient(pClient)    ((RRClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RRClientPrivateKey))
 #define rrClientPriv(pClient)	RRClientPtr pRRClient = GetRRClient(pClient)
 
-/* Initialize the extension */
-extern _X_EXPORT void
- RRExtensionInit(void);
-
 #ifdef RANDR_12_INTERFACE
 /*
  * Set the range of sizes for the screen
diff --git a/record/record.c b/record/record.c
index 67569d9..f3a26a7 100644
--- a/record/record.c
+++ b/record/record.c
@@ -38,6 +38,7 @@ and Jim Haggerty of Metheus.
 
 #include "dixstruct.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include <X11/extensions/recordproto.h>
 #include "set.h"
 #include "swaprep.h"
@@ -139,8 +140,6 @@ static int RecordDeleteContext(pointer /*value */ ,
                                XID      /*id */
     );
 
-void RecordExtensionInit(void);
-
 /***************************************************************************/
 
 /* client private stuff */
diff --git a/render/picturestr.h b/render/picturestr.h
index 1cda88a..dc00f41 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -547,8 +547,6 @@ CompositeTriFan(CARD8 op,
                 PictFormatPtr maskFormat,
                 INT16 xSrc, INT16 ySrc, int npoints, xPointFixed * points);
 
-extern _X_EXPORT void RenderExtensionInit(void);
-
 Bool
  AnimCurInit(ScreenPtr pScreen);
 
diff --git a/render/render.c b/render/render.c
index 5301811..51f75ae 100644
--- a/render/render.c
+++ b/render/render.c
@@ -37,6 +37,7 @@
 #include "pixmapstr.h"
 #include "colormapst.h"
 #include "extnsionst.h"
+#include "extinit.h"
 #include "servermd.h"
 #include <X11/extensions/render.h>
 #include <X11/extensions/renderproto.h>
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index c6dd19e..52c57df 100644
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -48,6 +48,7 @@
 
 #include "xfixesint.h"
 #include "protocol-versions.h"
+#include "extinit.h"
 
 static unsigned char XFixesReqCode;
 int XFixesEventBase;
diff --git a/xfixes/xfixesint.h b/xfixes/xfixesint.h
index 71f88a9..334c71f 100644
--- a/xfixes/xfixesint.h
+++ b/xfixes/xfixesint.h
@@ -71,11 +71,6 @@ typedef struct _XFixesClient {
 
 extern int (*ProcXFixesVector[XFixesNumberRequests]) (ClientPtr);
 
-/* Initialize extension at server startup time */
-
-void
- XFixesExtensionInit(void);
-
 /* Save set */
 int
  ProcXFixesChangeSaveSet(ClientPtr client);
diff --git a/xkb/xkb.c b/xkb/xkb.c
index ad837c8..4440a98 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -36,6 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #define	XKBSRV_NEED_FILE_FUNCS
 #include <xkbsrv.h>
 #include "extnsionst.h"
+#include "extinit.h"
 #include "xace.h"
 #include "xkb.h"
 #include "protocol-versions.h"
diff --git a/xkb/xkb.h b/xkb/xkb.h
index a526356..f3a60af 100644
--- a/xkb/xkb.h
+++ b/xkb/xkb.h
@@ -27,6 +27,4 @@ extern int ProcXkbGetKbdByName(ClientPtr client);
 extern int ProcXkbGetDeviceInfo(ClientPtr client);
 extern int ProcXkbSetDeviceInfo(ClientPtr client);
 extern int ProcXkbSetDebuggingFlags(ClientPtr client);
-
-extern void XkbExtensionInit(void);
 #endif
commit b86aa74cafddf9bca5addfeb458a23f46ddcf132
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:55 2012 +0100

    GLX: Insert swrast provider from GlxExtensionInit
    
    Rather than making poor old miinitext.c do it, including making DMX
    have fake symbols just to keep it happy.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Stéphane Marchesin <stephane.marchesin at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxext.c b/glx/glxext.c
index 8d168d8..e506aec 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -322,9 +322,15 @@ GlxExtensionInit(void)
     ExtensionEntry *extEntry;
     ScreenPtr pScreen;
     int i;
-    __GLXprovider *p;
+    __GLXprovider *p, **stack;
     Bool glx_provided = False;
 
+    if (serverGeneration == 1) {
+        for (stack = &__glXProviderStack; *stack; stack = &(*stack)->next)
+            ;
+        *stack = &__glXDRISWRastProvider;
+    }
+
     __glXContextRes = CreateNewResourceType((DeleteType) ContextGone,
                                             "GLXContext");
     __glXDrawableRes = CreateNewResourceType((DeleteType) DrawableGone,
diff --git a/glx/glxserver.h b/glx/glxserver.h
index 24e3d62..61c45c5 100644
--- a/glx/glxserver.h
+++ b/glx/glxserver.h
@@ -99,6 +99,7 @@ struct __GLXprovider {
     const char *name;
     __GLXprovider *next;
 };
+__GLXprovider __glXDRISWRastProvider;
 
 void GlxPushProvider(__GLXprovider * provider);
 
diff --git a/hw/dmx/glxProxy/glxext.c b/hw/dmx/glxProxy/glxext.c
index b0710cc..9532837 100644
--- a/hw/dmx/glxProxy/glxext.c
+++ b/hw/dmx/glxProxy/glxext.c
@@ -46,16 +46,6 @@
 #include "glxswap.h"
 
 /*
-** Stubs to satisfy miinitext.c references.
-*/
-typedef int __GLXprovider;
-__GLXprovider __glXDRISWRastProvider;
-void
-GlxPushProvider(__GLXprovider * provider)
-{
-}
-
-/*
 ** Forward declarations.
 */
 static int __glXSwapDispatch(ClientPtr);
diff --git a/hw/xfree86/dixmods/glxmodule.c b/hw/xfree86/dixmods/glxmodule.c
index e72f382..4482cbc 100644
--- a/hw/xfree86/dixmods/glxmodule.c
+++ b/hw/xfree86/dixmods/glxmodule.c
@@ -84,11 +84,6 @@ glxSetup(pointer module, pointer opts, int *errmaj, int *errmin)
 
     setupDone = TRUE;
 
-    provider = LoaderSymbol("__glXDRISWRastProvider");
-    if (provider == NULL)
-        return NULL;
-    GlxPushProvider(provider);
-
     xf86Msg(xf86Info.aiglxFrom, "AIGLX %s\n",
             xf86Info.aiglx ? "enabled" : "disabled");
     if (xf86Info.aiglx) {
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 13f554a..e60cc3f 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -172,9 +172,6 @@ extern void XFree86VidModeExtensionInit(void);
 extern void XFree86DGAExtensionInit(void);
 #endif
 #ifdef GLXEXT
-typedef struct __GLXprovider __GLXprovider;
-extern __GLXprovider __glXDRISWRastProvider;
-extern void GlxPushProvider(__GLXprovider *impl);
 extern void GlxExtensionInit(void);
 #endif
 #ifdef XF86DRI
@@ -449,8 +446,6 @@ InitExtensions(int argc, char *argv[])
 #endif
 
 #ifdef GLXEXT
-    if (serverGeneration == 1)
-        GlxPushProvider(&__glXDRISWRastProvider);
     if (!noGlxExtension)
         GlxExtensionInit();
 #endif
commit 13552a5c4701097a1507a99ed8366ab1438844b6
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:54 2012 +0100

    Reorder extension initialisation for non-Xorg
    
    Reorder static extension initialisation in miinitext for non-Xorg
    servers to match Xorg's order.
    
    Tested with Xephyr; checked that the extension list was identical before
    and after.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/mi/miinitext.c b/mi/miinitext.c
index 13e1b68..13f554a 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -329,62 +329,79 @@ InitExtensions(int argc, char *argv[])
     if (!noGEExtension)
         GEExtensionInit();
 
-#ifdef PANORAMIX
-    if (!noPanoramiXExtension)
-        PanoramiXExtensionInit();
-#endif
-#ifdef INXQUARTZ
-    if (!noPseudoramiXExtension)
-        PseudoramiXExtensionInit();
-#endif
     ShapeExtensionInit();
+
 #ifdef MITSHM
     if (!noMITShmExtension)
         ShmExtensionInit();
 #endif
+
     XInputExtensionInit();
+
 #ifdef XTEST
     if (!noTestExtensions)
         XTestExtensionInit();
 #endif
+
     BigReqExtensionInit();
-#if defined(SCREENSAVER)
-    if (!noScreenSaverExtension)
-        ScreenSaverExtensionInit();
-#endif
-#ifdef XV
-    if (!noXvExtension) {
-        XvExtensionInit();
-        XvMCExtensionInit();
-    }
-#endif
     SyncExtensionInit();
     XkbExtensionInit();
     XCMiscExtensionInit();
-#ifdef XRECORD
-    if (!noTestExtensions)
-        RecordExtensionInit();
-#endif
-#ifdef DBE
-    if (!noDbeExtension)
-        DbeExtensionInit();
-#endif
+
 #ifdef XCSECURITY
     if (!noSecurityExtension)
         SecurityExtensionInit();
 #endif
-#ifdef XSELINUX
-    if (!noSELinuxExtension)
-        SELinuxExtensionInit();
+
+#ifdef PANORAMIX
+    if (!noPanoramiXExtension)
+        PanoramiXExtensionInit();
 #endif
-#if defined(DPMSExtension) && !defined(NO_HW_ONLY_EXTS)
-    if (!noDPMSExtension)
-        DPMSExtensionInit();
+
+#ifdef INXQUARTZ
+    if (!noPseudoramiXExtension)
+        PseudoramiXExtensionInit();
 #endif
+
+#ifdef XFIXES
+    /* must be before Render to layer DisplayCursor correctly */
+    if (!noXFixesExtension)
+        XFixesExtensionInit();
+#endif
+
 #ifdef XF86BIGFONT
     if (!noXFree86BigfontExtension)
         XFree86BigfontExtensionInit();
 #endif
+
+    if (!noRenderExtension)
+        RenderExtensionInit();
+
+#ifdef RANDR
+    if (!noRRExtension)
+        RRExtensionInit();
+#endif
+
+#ifdef COMPOSITE
+    if (!noCompositeExtension)
+        CompositeExtensionInit();
+#endif
+
+#ifdef DAMAGE
+    if (!noDamageExtension)
+        DamageExtensionInit();
+#endif
+
+#ifdef XSELINUX
+    if (!noSELinuxExtension)
+        SELinuxExtensionInit();
+#endif
+
+#if defined(SCREENSAVER)
+    if (!noScreenSaverExtension)
+        ScreenSaverExtensionInit();
+#endif
+
 #if !defined(NO_HW_ONLY_EXTS)
 #if defined(XF86VIDMODE)
     if (!noXFree86VidModeExtension)
@@ -394,36 +411,41 @@ InitExtensions(int argc, char *argv[])
     if (!noXFree86DGAExtension)
         XFree86DGAExtensionInit();
 #endif
-#ifdef XF86DRI
-    if (!noXFree86DRIExtension)
-        XFree86DRIExtensionInit();
-#endif
+#ifdef DPMSExtension
+    if (!noDPMSExtension)
+        DPMSExtensionInit();
 #endif
-#ifdef XFIXES
-    /* must be before Render to layer DisplayCursor correctly */
-    if (!noXFixesExtension)
-        XFixesExtensionInit();
 #endif
-    if (!noRenderExtension)
-        RenderExtensionInit();
-#ifdef RANDR
-    if (!noRRExtension)
-        RRExtensionInit();
+
+#ifdef XV
+    if (!noXvExtension) {
+        XvExtensionInit();
+        XvMCExtensionInit();
+    }
 #endif
+
 #ifdef RES
     if (!noResExtension)
         ResExtensionInit();
 #endif
-#ifdef DMXEXT
-    DMXExtensionInit();         /* server-specific extension, cannot be disabled */
+
+#ifdef XRECORD
+    if (!noTestExtensions)
+        RecordExtensionInit();
 #endif
-#ifdef COMPOSITE
-    if (!noCompositeExtension)
-        CompositeExtensionInit();
+
+#ifdef DBE
+    if (!noDbeExtension)
+        DbeExtensionInit();
 #endif
-#ifdef DAMAGE
-    if (!noDamageExtension)
-        DamageExtensionInit();
+
+#if !defined(NO_HW_ONLY_EXTS) && defined(XF86DRI)
+    if (!noXFree86DRIExtension)
+        XFree86DRIExtensionInit();
+#endif
+
+#ifdef DMXEXT
+    DMXExtensionInit();         /* server-specific extension, cannot be disabled */
 #endif
 
 #ifdef GLXEXT
commit 5079db78aea8fa42e781dd876c1ee1c31571b3ae
Author: Tomas Carnecky <tom at dbservice.com>
Date:   Tue Jul 10 02:02:53 2012 +0100

    Replace INITARGS with void
    
    INITARGS was a hardcoded define to void.  Since knowing the function
    signature for your extensions is kinda useful, just replace it with a
    hardcoded void, but leave the define there for API compatibility.
    
    Signed-off-by: Tomas Carnecky <tom at dbservice.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/bigreq.c b/Xext/bigreq.c
index d61ff3c..886b761 100644
--- a/Xext/bigreq.c
+++ b/Xext/bigreq.c
@@ -40,7 +40,7 @@ from The Open Group.
 #include "opaque.h"
 #include "modinit.h"
 
-void BigReqExtensionInit(INITARGS);
+void BigReqExtensionInit(void);
 
 static int
 ProcBigReqDispatch(ClientPtr client)
@@ -70,7 +70,7 @@ ProcBigReqDispatch(ClientPtr client)
 }
 
 void
-BigReqExtensionInit(INITARGS)
+BigReqExtensionInit(void)
 {
     AddExtension(XBigReqExtensionName, 0, 0,
                  ProcBigReqDispatch, ProcBigReqDispatch,
diff --git a/Xext/dpms.c b/Xext/dpms.c
index 8ec32ea..8cff8bd 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -355,7 +355,7 @@ SProcDPMSDispatch(ClientPtr client)
 }
 
 void
-DPMSExtensionInit(INITARGS)
+DPMSExtensionInit(void)
 {
     AddExtension(DPMSExtensionName, 0, 0,
                  ProcDPMSDispatch, SProcDPMSDispatch,
diff --git a/Xext/saver.c b/Xext/saver.c
index 7f70bc0..eefb497 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -1389,7 +1389,7 @@ SProcScreenSaverDispatch(ClientPtr client)
 }
 
 void
-ScreenSaverExtensionInit(INITARGS)
+ScreenSaverExtensionInit(void)
 {
     ExtensionEntry *extEntry;
     int i;
diff --git a/Xext/security.c b/Xext/security.c
index 50041de..c101b7d 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1027,7 +1027,7 @@ SecurityResetProc(ExtensionEntry * extEntry)
  */
 
 void
-SecurityExtensionInit(INITARGS)
+SecurityExtensionInit(void)
 {
     ExtensionEntry *extEntry;
     int ret = TRUE;
diff --git a/Xext/shm.c b/Xext/shm.c
index be10a49..fd0c41f 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -1248,7 +1248,7 @@ SProcShmDispatch(ClientPtr client)
 }
 
 void
-ShmExtensionInit(INITARGS)
+ShmExtensionInit(void)
 {
     ExtensionEntry *extEntry;
     int i;
diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index 9e4ea89..cfde3b3 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -190,7 +190,7 @@ SProcXCMiscDispatch(ClientPtr client)
 }
 
 void
-XCMiscExtensionInit(INITARGS)
+XCMiscExtensionInit(void)
 {
     AddExtension(XCMiscExtensionName, 0, 0,
                  ProcXCMiscDispatch, SProcXCMiscDispatch,
diff --git a/Xext/xres.c b/Xext/xres.c
index 25d4417..acc5b8c 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -1184,7 +1184,7 @@ SProcResDispatch (ClientPtr client)
 }
 
 void
-ResExtensionInit(INITARGS)
+ResExtensionInit(void)
 {
     (void) AddExtension(XRES_NAME, 0, 0,
                         ProcResDispatch, SProcResDispatch,
diff --git a/Xext/xselinux_ext.c b/Xext/xselinux_ext.c
index d22c2f1..220e876 100644
--- a/Xext/xselinux_ext.c
+++ b/Xext/xselinux_ext.c
@@ -687,7 +687,7 @@ SELinuxResetProc(ExtensionEntry * extEntry)
 }
 
 void
-SELinuxExtensionInit(INITARGS)
+SELinuxExtensionInit(void)
 {
     ExtensionEntry *extEntry;
 
diff --git a/Xext/xtest.c b/Xext/xtest.c
index c7b087b..4938e3b 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -679,7 +679,7 @@ XTestExtensionTearDown(ExtensionEntry * e)
 }
 
 void
-XTestExtensionInit(INITARGS)
+XTestExtensionInit(void)
 {
     AddExtension(XTestExtensionName, 0, 0,
                  ProcXTestDispatch, SProcXTestDispatch,
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 7671cea..9ba874c 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -171,7 +171,7 @@ typedef struct {
 
 #define INITARGS void
 
-typedef void (*InitExtension) (INITARGS);
+typedef void (*InitExtension) (void);
 
 typedef struct {
     InitExtension initFunc;
diff --git a/hw/xfree86/dixmods/dbemodule.c b/hw/xfree86/dixmods/dbemodule.c
index 5541eac..fea3d9f 100644
--- a/hw/xfree86/dixmods/dbemodule.c
+++ b/hw/xfree86/dixmods/dbemodule.c
@@ -7,7 +7,7 @@
 
 static MODULESETUPPROTO(dbeSetup);
 
-extern void DbeExtensionInit(INITARGS);
+extern void DbeExtensionInit(void);
 
 static ExtensionModule dbeExt = {
     DbeExtensionInit,
diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
index e7c7448..4c9b6e3 100644
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ b/hw/xfree86/dixmods/extmod/modinit.h
@@ -3,91 +3,78 @@
 #include <dix-config.h>
 #endif
 
-#ifndef INITARGS
-#define INITARGS void
-#endif
-
 #include <X11/extensions/shapeproto.h>
 
 #ifdef XTEST
-extern void XTestExtensionInit(INITARGS);
-
+extern void XTestExtensionInit(void);
 #include <X11/extensions/xtestproto.h>
 #endif
 
 #if 1
-extern void XTestExtension1Init(INITARGS);
+extern void XTestExtension1Init(void);
 #endif
 
 #if 1
-extern void XCMiscExtensionInit(INITARGS);
+extern void XCMiscExtensionInit(void);
 #endif
 
 #ifdef SCREENSAVER
-extern void ScreenSaverExtensionInit(INITARGS);
-
+extern void ScreenSaverExtensionInit(void);
 #include <X11/extensions/saver.h>
 #endif
 
 #ifdef XF86VIDMODE
-extern void XFree86VidModeExtensionInit(INITARGS);
-
+extern void XFree86VidModeExtensionInit(void);
 #include <X11/extensions/xf86vmproto.h>
 #endif
 
 #ifdef XFreeXDGA
-extern void XFree86DGAExtensionInit(INITARGS);
-extern void XFree86DGARegister(INITARGS);
-
+extern void XFree86DGAExtensionInit(void);
+extern void XFree86DGARegister(void);
 #include <X11/extensions/xf86dgaproto.h>
 #endif
 
 #ifdef DPMSExtension
-extern void DPMSExtensionInit(INITARGS);
-
+extern void DPMSExtensionInit(void);
 #include <X11/extensions/dpmsconst.h>
 #endif
 
 #ifdef XV
-extern void XvExtensionInit(INITARGS);
-extern void XvMCExtensionInit(INITARGS);
-extern void XvRegister(INITARGS);
-
+extern void XvExtensionInit(void);
+extern void XvMCExtensionInit(void);
+extern void XvRegister(void);
 #include <X11/extensions/Xv.h>
 #include <X11/extensions/XvMC.h>
 #endif
 
 #ifdef RES
-extern void ResExtensionInit(INITARGS);
-
+extern void ResExtensionInit(void);
 #include <X11/extensions/XResproto.h>
 #endif
 
 #ifdef SHM
-extern void ShmExtensionInit(INITARGS);
-
 #include <X11/extensions/shmproto.h>
+extern void ShmExtensionInit(void);
 extern void ShmRegisterFuncs(ScreenPtr pScreen, ShmFuncsPtr funcs);
 #endif
 
 #ifdef XSELINUX
-extern void SELinuxExtensionInit(INITARGS);
-
+extern void SELinuxExtensionInit(void);
 #include "xselinux.h"
 #endif
 
 #ifdef XEVIE
-extern void XevieExtensionInit(INITARGS);
+extern void XevieExtensionInit(void);
 #endif
 
 #if 1
-extern void SecurityExtensionInit(INITARGS);
+extern void SecurityExtensionInit(void);
 #endif
 
 #if 1
-extern void PanoramiXExtensionInit(INITARGS);
+extern void PanoramiXExtensionInit(void);
 #endif
 
 #if 1
-extern void XkbExtensionInit(INITARGS);
+extern void XkbExtensionInit(void);
 #endif
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 9b7ec14..4cae949 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -1010,13 +1010,13 @@ ProcXDGADispatch(ClientPtr client)
 }
 
 void
-XFree86DGARegister(INITARGS)
+XFree86DGARegister(void)
 {
     XDGAEventBase = &DGAEventBase;
 }
 
 void
-XFree86DGAExtensionInit(INITARGS)
+XFree86DGAExtensionInit(void)
 {
     ExtensionEntry *extEntry;
 
diff --git a/hw/xfree86/dixmods/recordmod.c b/hw/xfree86/dixmods/recordmod.c
index b75cc3f..fe52fa8 100644
--- a/hw/xfree86/dixmods/recordmod.c
+++ b/hw/xfree86/dixmods/recordmod.c
@@ -8,7 +8,7 @@ extern Bool noTestExtensions;
 
 static MODULESETUPPROTO(recordSetup);
 
-extern void RecordExtensionInit(INITARGS);
+extern void RecordExtensionInit(void);
 
 static ExtensionModule recordExt = {
     RecordExtensionInit,
diff --git a/hw/xfree86/dri/drimodule.c b/hw/xfree86/dri/drimodule.c
index 83eca4e..eb42ef6 100644
--- a/hw/xfree86/dri/drimodule.c
+++ b/hw/xfree86/dri/drimodule.c
@@ -57,8 +57,7 @@ static XF86ModuleVersionInfo VersRec = {
     {0, 0, 0, 0}
 };
 
-extern void XFree86DRIExtensionInit(INITARGS);
-
+extern void XFree86DRIExtensionInit(void);
 #define _XF86DRI_SERVER_
 #include <X11/dri/xf86driproto.h>
 
diff --git a/mi/miinitext.c b/mi/miinitext.c
index ca21b6f..13e1b68 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -96,8 +96,7 @@ SOFTWARE.
 extern Bool noGEExtension;
 
 #ifndef XFree86LOADER
-#define INITARGS void
-typedef void (*InitExtension) (INITARGS);
+typedef void (*InitExtension) (void);
 #else                           /* XFree86Loader */
 #include "loaderProcs.h"
 #endif
@@ -128,84 +127,80 @@ typedef void (*InitExtension) (INITARGS);
 
 /* FIXME: this whole block of externs should be from the appropriate headers */
 #ifdef MITSHM
-extern void ShmExtensionInit(INITARGS);
+extern void ShmExtensionInit(void);
 #endif
 #ifdef PANORAMIX
-extern void PanoramiXExtensionInit(INITARGS);
+extern void PanoramiXExtensionInit(void);
 #endif
 #ifdef INXQUARTZ
-extern void PseudoramiXExtensionInit(INITARGS);
+extern void PseudoramiXExtensionInit(void);
 #endif
-extern void XInputExtensionInit(INITARGS);
-
+extern void XInputExtensionInit(void);
 #ifdef XTEST
-extern void XTestExtensionInit(INITARGS);
+extern void XTestExtensionInit(void);
 #endif
-extern void BigReqExtensionInit(INITARGS);
-
+extern void BigReqExtensionInit(void);
 #ifdef SCREENSAVER
-extern void ScreenSaverExtensionInit(INITARGS);
+extern void ScreenSaverExtensionInit(void);
 #endif
 #ifdef XV
-extern void XvExtensionInit(INITARGS);
-extern void XvMCExtensionInit(INITARGS);
+extern void XvExtensionInit(void);
+extern void XvMCExtensionInit(void);
 #endif
-extern void SyncExtensionInit(INITARGS);
-extern void XkbExtensionInit(INITARGS);
-extern void XCMiscExtensionInit(INITARGS);
-
+extern void SyncExtensionInit(void);
+extern void XkbExtensionInit(void);
+extern void XCMiscExtensionInit(void);
 #ifdef XRECORD
-extern void RecordExtensionInit(INITARGS);
+extern void RecordExtensionInit(void);
 #endif
 #ifdef DBE
-extern void DbeExtensionInit(INITARGS);
+extern void DbeExtensionInit(void);
 #endif
 #ifdef XCSECURITY
-extern void SecurityExtensionInit(INITARGS);
+extern void SecurityExtensionInit(void);
 #endif
 #ifdef XSELINUX
-extern void SELinuxExtensionInit(INITARGS);
+extern void SELinuxExtensionInit(void);
 #endif
 #ifdef XF86BIGFONT
-extern void XFree86BigfontExtensionInit(INITARGS);
+extern void XFree86BigfontExtensionInit(void);
 #endif
 #ifdef XF86VIDMODE
-extern void XFree86VidModeExtensionInit(INITARGS);
+extern void XFree86VidModeExtensionInit(void);
 #endif
 #ifdef XFreeXDGA
-extern void XFree86DGAExtensionInit(INITARGS);
+extern void XFree86DGAExtensionInit(void);
 #endif
 #ifdef GLXEXT
 typedef struct __GLXprovider __GLXprovider;
 extern __GLXprovider __glXDRISWRastProvider;
-extern void GlxPushProvider(__GLXprovider * impl);
-extern void GlxExtensionInit(INITARGS);
+extern void GlxPushProvider(__GLXprovider *impl);
+extern void GlxExtensionInit(void);
 #endif
 #ifdef XF86DRI
-extern void XFree86DRIExtensionInit(INITARGS);
+extern void XFree86DRIExtensionInit(void);
 #endif
 #ifdef DPMSExtension
-extern void DPMSExtensionInit(INITARGS);
+extern void DPMSExtensionInit(void);
 #endif
-extern void RenderExtensionInit(INITARGS);
-
+extern void RenderExtensionInit(void);
 #ifdef RANDR
-extern void RRExtensionInit(INITARGS);
+extern void RRExtensionInit(void);
 #endif
 #ifdef RES
-extern void ResExtensionInit(INITARGS);
+extern void ResExtensionInit(void);
 #endif
 #ifdef DMXEXT
-extern void DMXExtensionInit(INITARGS);
+extern void DMXExtensionInit(void);
 #endif
 #ifdef XFIXES
-extern void XFixesExtensionInit(INITARGS);
+extern void XFixesExtensionInit(void);
 #endif
 #ifdef DAMAGE
-extern void DamageExtensionInit(INITARGS);
+extern void DamageExtensionInit(void);
 #endif
 #ifdef COMPOSITE
-extern void CompositeExtensionInit(INITARGS);
+extern void CompositeExtensionInit(void);
 #endif
 
 /* The following is only a small first step towards run-time
commit bddb8c6cbe52ba9923b1d36d01f5ac9391b0ec0e
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:52 2012 +0100

    Xinerama: Fix ExtensionInit prototype
    
    Huh, so I guess INITARGS used to be int argc, char *argv then.  Either
    way, it's now void, so fix that ...
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index bb253c3..df67c00 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -434,7 +434,7 @@ XineramaReinitData(void)
  */
 
 void
-PanoramiXExtensionInit(int argc, char *argv[])
+PanoramiXExtensionInit(void)
 {
     int i;
     Bool success = FALSE;
diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
index 9753fe0..e7c7448 100644
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ b/hw/xfree86/dixmods/extmod/modinit.h
@@ -85,7 +85,7 @@ extern void SecurityExtensionInit(INITARGS);
 #endif
 
 #if 1
-extern void PanoramiXExtensionInit(int argc, char *argv[]);
+extern void PanoramiXExtensionInit(INITARGS);
 #endif
 
 #if 1
commit eb9661fef9f59587f898371f97a0952ac14d125f
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:51 2012 +0100

    Make extension.h self-contained, remove C++ externs
    
    externsion.h required bits from Xfuncproto.h and dixstruct.h, but
    included neither; fix that.
    
    It also had _XFUNCPROTOBEGIN and _XFUNCPROTOEND wrappers, which is a bit
    pointless for a server-only library, as it's only needed for C++.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/extension.h b/include/extension.h
index c7f51b9..f0560d7 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -47,7 +47,9 @@ SOFTWARE.
 #ifndef EXTENSION_H
 #define EXTENSION_H
 
-_XFUNCPROTOBEGIN
+#include <X11/Xfuncproto.h>
+
+#include "dixstruct.h"
 
 extern _X_EXPORT unsigned short StandardMinorOpcode(ClientPtr /*client */ );
 
@@ -60,5 +62,4 @@ extern _X_EXPORT void InitExtensions(int argc, char **argv);
 
 extern _X_EXPORT void CloseDownExtensions(void);
 
-_XFUNCPROTOEND
 #endif                          /* EXTENSION_H */
commit 854c1fa4a1e90288d1e2f3777fac3e1a9acb1235
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:50 2012 +0100

    Add a common ARRAY_SIZE macro to dix.h
    
    Does what it says on the box, replacing those from Xi/ and glx/.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Cyril Brulebois <kibi at debian.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xi/extinit.c b/Xi/extinit.c
index bcea410..52d248b 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -49,8 +49,6 @@ SOFTWARE.
  *  Dispatch routines and initialization routines for the X input extension.
  *
  */
-#define ARRAY_SIZE(_a)        (sizeof((_a)) / sizeof((_a)[0]))
-
 #define	 NUMTYPES 15
 
 #ifdef HAVE_DIX_CONFIG_H
diff --git a/glx/glxdricommon.c b/glx/glxdricommon.c
index 44d5a3e..c90f380 100644
--- a/glx/glxdricommon.c
+++ b/glx/glxdricommon.c
@@ -107,8 +107,6 @@ __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits),
         __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture),
         __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),};
 
-#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
-
 static void
 setScalar(__GLXconfig * config, unsigned int attrib, unsigned int value)
 {
diff --git a/include/dix.h b/include/dix.h
index 5bc1daa..74123b5 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -64,6 +64,8 @@ SOFTWARE.
 #define REQUEST(type) \
 	type *stuff = (type *)client->requestBuffer
 
+#define ARRAY_SIZE(a)  (sizeof((a)) / sizeof((a)[0]))
+
 #define REQUEST_SIZE_MATCH(req)\
     if ((sizeof(req) >> 2) != client->req_len)\
          return(BadLength)
commit 67953d6975ef2ee573b95e7641aaf3d72e9f8379
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:49 2012 +0100

    Xorg: Link XKB DDX library after core server libs
    
    libxorgxkb.a contains a number of libraries which are used by XKB action
    code to call back into the DDX, e.g. for VT switching, termination, grab
    breaking, et al.  Make sure libxkb.a comes first in the link order, so
    it can mark XkbDDX* as used in order for the linker to not discard them.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index 4d5d576..f74691b 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -54,8 +54,8 @@ LOCAL_LIBS = \
             ramdac/libramdac.la \
             ddc/libddc.la \
             i2c/libi2c.la \
-            dixmods/libxorgxkb.la \
             $(XORG_LIBS) \
+            dixmods/libxorgxkb.la \
             $(top_builddir)/mi/libmi.la \
             $(top_builddir)/os/libos.la
 Xorg_LDADD = \
commit 656af2c7e73d948338683675e14cd827b46a97c4
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:46 2012 +0100

    Don't make failure to -nolisten fatal
    
    If failing to disable a protocol specified by -nolisten failed, we'd
    throw a FatalError and bomb startup entirely.  From poking at xtrans, it
    looks like the only way we can get a failure here is because we've
    specified a protocol name which doesn't exist, which probably doesn't
    constitute a security risk.
    
    And it makes it possible to start gdm even though you've built with
    --disable-tcp-transport.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/os/utils.c b/os/utils.c
index 2537934..b00d38b 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -757,8 +757,8 @@ ProcessCommandLine(int argc, char *argv[])
         else if (strcmp(argv[i], "-nolisten") == 0) {
             if (++i < argc) {
                 if (_XSERVTransNoListen(argv[i]))
-                    FatalError("Failed to disable listen for %s transport",
-                               argv[i]);
+                    ErrorF("Failed to disable listen for %s transport",
+                           argv[i]);
             }
             else
                 UseMsg();
commit dc0c2dd92d5eb314582ea10830678753824375d9
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Tue Jul 10 02:02:45 2012 +0100

    Xext: Add hashtable.h to sources to fix distcheck
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 5929a3e..4082de7 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -50,7 +50,7 @@ MODULE_SRCS  += $(XV_SRCS)
 endif
 
 # XResource extension: lets clients get data about per-client resource usage
-RES_SRCS = hashtable.c xres.c
+RES_SRCS = hashtable.c hashtable.h xres.c
 if RES
 MODULE_SRCS  += $(RES_SRCS)
 endif
commit ad4092cf7d59a89b1b2922440eef65be5c0c5ebd
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:44 2012 -0700

    Replace padlength tables with inline functions from misc.h
    
    Adds new function padding_for_int32() and uses existing pad_to_int32()
    depending on required results.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index d916f34..3c6a591 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -466,8 +466,6 @@ Dispatch(void)
 static int VendorRelease = VENDOR_RELEASE;
 static char *VendorString = VENDOR_NAME;
 
-static const int padlength[4] = { 0, 3, 2, 1 };
-
 void
 SetVendorRelease(int release)
 {
@@ -528,7 +526,7 @@ CreateConnectionBlock(void)
     memmove(pBuf, VendorString, (int) setup.nbytesVendor);
     sizesofar += setup.nbytesVendor;
     pBuf += setup.nbytesVendor;
-    i = padlength[setup.nbytesVendor & 3];
+    i = padding_for_int32(setup.nbytesVendor);
     sizesofar += i;
     while (--i >= 0)
         *pBuf++ = 0;
diff --git a/include/misc.h b/include/misc.h
index 6bea82f..7f7f221 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -232,6 +232,20 @@ pad_to_int32(const int bytes)
     return (((bytes) + 3) & ~3);
 }
 
+/**
+ * Calculate padding needed to bring the number of bytes to an even
+ * multiple of 4.
+ * @param bytes The minimum number of bytes needed.
+ * @return The bytes of padding needed to arrive at the closest multiple of 4
+ * that is equal or higher than bytes.
+ */
+static inline int
+padding_for_int32(const int bytes)
+{
+    return ((-bytes) & 3);
+}
+
+
 extern char **xstrtokenize(const char *str, const char *separators);
 extern void FormatUInt64(uint64_t num, char *string);
 extern void FormatUInt64Hex(uint64_t num, char *string);
diff --git a/os/io.c b/os/io.c
index 8d0e5cc..e44db39 100644
--- a/os/io.c
+++ b/os/io.c
@@ -578,8 +578,6 @@ ResetCurrentRequest(ClientPtr client)
     }
 }
 
-static const int padlength[4] = { 0, 3, 2, 1 };
-
  /********************
  * FlushAllOutput()
  *    Flush all clients with output.  However, if some client still
@@ -757,7 +755,7 @@ WriteToClient(ClientPtr who, int count, const void *__buf)
         oc->output = oco;
     }
 
-    padBytes = padlength[count & 3];
+    padBytes = padding_for_int32(count);
 
     if (ReplyCallback) {
         ReplyInfoRec replyinfo;
@@ -850,7 +848,7 @@ FlushClient(ClientPtr who, OsCommPtr oc, const void *__extraBuf, int extraCount)
     if (!oco)
         return 0;
     written = 0;
-    padsize = padlength[extraCount & 3];
+    padsize = padding_for_int32(extraCount);
     notWritten = oco->count + extraCount + padsize;
     todo = notWritten;
     while (notWritten) {
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index a427725..6a7a089 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -22,8 +22,6 @@
 
 #include "randrstr.h"
 
-static const int padlength[4] = { 0, 3, 2, 1 };
-
 static CARD16
  RR10CurrentSizeID(ScreenPtr pScreen);
 
@@ -46,8 +44,7 @@ RREditConnectionInfo(ScreenPtr pScreen)
     connSetup = (xConnSetup *) ConnectionInfo;
     vendor = (char *) connSetup + sizeof(xConnSetup);
     formats = (xPixmapFormat *) ((char *) vendor +
-                                 connSetup->nbytesVendor +
-                                 padlength[connSetup->nbytesVendor & 3]);
+                                 pad_to_int32(connSetup->nbytesVendor));
     root = (xWindowRoot *) ((char *) formats +
                             sizeof(xPixmapFormat) *
                             screenInfo.numPixmapFormats);
diff --git a/test/input.c b/test/input.c
index 90ab9ae..191c817 100644
--- a/test/input.c
+++ b/test/input.c
@@ -965,6 +965,19 @@ test_pad_to_int32(int i)
 }
 
 static void
+test_padding_for_int32(int i)
+{
+    static const int padlength[4] = { 0, 3, 2, 1 };
+    int expected_bytes = (((i + 3) / 4) * 4) - i;
+
+    assert(padding_for_int32(i) >= 0);
+    assert(padding_for_int32(i) <= 3);
+    assert(padding_for_int32(i) == expected_bytes);
+    assert(padding_for_int32(i) == padlength[i & 3]);
+    assert((padding_for_int32(i) + i) == pad_to_int32(i));
+}
+
+static void
 include_byte_padding_macros(void)
 {
     printf("Testing bits_to_bytes()\n");
@@ -996,12 +1009,12 @@ include_byte_padding_macros(void)
     test_bytes_to_int32(INT_MAX - 4);
     test_bytes_to_int32(INT_MAX - 3);
 
-    printf("Testing pad_to_int32\n");
+    printf("Testing pad_to_int32()\n");
 
     test_pad_to_int32(0);
-    test_pad_to_int32(0);
     test_pad_to_int32(1);
     test_pad_to_int32(2);
+    test_pad_to_int32(3);
     test_pad_to_int32(7);
     test_pad_to_int32(8);
     test_pad_to_int32(0xFF);
@@ -1012,6 +1025,23 @@ include_byte_padding_macros(void)
     test_pad_to_int32(0x1000000);
     test_pad_to_int32(INT_MAX - 4);
     test_pad_to_int32(INT_MAX - 3);
+
+    printf("Testing padding_for_int32()\n");
+
+    test_padding_for_int32(0);
+    test_padding_for_int32(1);
+    test_padding_for_int32(2);
+    test_padding_for_int32(3);
+    test_padding_for_int32(7);
+    test_padding_for_int32(8);
+    test_padding_for_int32(0xFF);
+    test_padding_for_int32(0x100);
+    test_padding_for_int32(0xFFFF);
+    test_padding_for_int32(0x10000);
+    test_padding_for_int32(0xFFFFFF);
+    test_padding_for_int32(0x1000000);
+    test_padding_for_int32(INT_MAX - 4);
+    test_padding_for_int32(INT_MAX - 3);
 }
 
 static void
commit 2b1c1300cc23912ee1c59f8dde938dd4d7287f4a
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:44 2012 -0700

    ephyrGLXQueryServerString: Stop making an unused copy of server_string
    
    ephyrGLXQueryServerString() carefully allocated a buffer padded to the
    word-aligned string length for sending to the client, copied the string
    to it, and then forgot to use it, potentially reading a few bytes of
    garbage past the end of the server_string buffer.
    
    Since WriteToClient already handles the necessary padding, just send
    it the actual length of the original server_string, and don't bother
    making a padded copy.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/kdrive/ephyr/ephyrglxext.c b/hw/kdrive/ephyr/ephyrglxext.c
index dae22fc..df285cf 100644
--- a/hw/kdrive/ephyr/ephyrglxext.c
+++ b/hw/kdrive/ephyr/ephyrglxext.c
@@ -357,7 +357,7 @@ ephyrGLXQueryServerString(__GLXclientState * a_cl, GLbyte * a_pc)
     ClientPtr client = a_cl->client;
     xGLXQueryServerStringReq *req = (xGLXQueryServerStringReq *) a_pc;
     xGLXQueryServerStringReply reply;
-    char *server_string = NULL, *buf = NULL;
+    char *server_string = NULL;
     int length = 0;
 
     EPHYR_LOG("enter\n");
@@ -377,13 +377,6 @@ ephyrGLXQueryServerString(__GLXclientState * a_cl, GLbyte * a_pc)
         .n = length
     };
 
-    buf = calloc(reply.length << 2, 1);
-    if (!buf) {
-        EPHYR_LOG_ERROR("failed to allocate string\n;");
-        return BadAlloc;
-    }
-    memcpy(buf, server_string, length);
-
     WriteToClient(client, sz_xGLXQueryServerStringReply, &reply);
     WriteToClient(client, (int) (reply.length << 2), server_string);
 
@@ -394,9 +387,6 @@ ephyrGLXQueryServerString(__GLXclientState * a_cl, GLbyte * a_pc)
     free(server_string);
     server_string = NULL;
 
-    free(buf);
-    buf = NULL;
-
     return res;
 }
 
commit 7a29f6878284e2d65e69fcd157aa9ec01d21b3c0
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:44 2012 -0700

    Initialize padding bits to 0 in ErrorConnMax()
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/os/connection.c b/os/connection.c
index 3441472..721ad65 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -892,7 +892,7 @@ ErrorConnMax(XtransConnInfo trans_conn)
 {
     int fd = _XSERVTransGetConnectionNumber(trans_conn);
     xConnSetupPrefix csp;
-    char pad[3];
+    char pad[3] = { 0, 0, 0 };
     struct iovec iov[3];
     char byteOrder = 0;
     int whichbyte = 1;
commit bed610fcae41ddfe21fa9acde599b17d1d15f5d1
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:44 2012 -0700

    Set padding bytes to 0 in WriteToClient
    
    Clear them out when needed instead of leaving whatever values were
    present in previously sent messages.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/os/io.c b/os/io.c
index b67a5f3..8d0e5cc 100644
--- a/os/io.c
+++ b/os/io.c
@@ -815,7 +815,11 @@ WriteToClient(ClientPtr who, int count, const void *__buf)
     NewOutputPending = TRUE;
     FD_SET(oc->fd, &OutputPending);
     memmove((char *) oco->buf + oco->count, buf, count);
-    oco->count += count + padBytes;
+    oco->count += count;
+    if (padBytes) {
+        memset(oco->buf + oco->count, '\0', padBytes);
+        oco->count += padBytes;
+    }
     return count;
 }
 
commit 1622dd8ab24d2fe7b9908110eb237774d4e03568
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:44 2012 -0700

    Use C99 designated initializers in dix registry
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/registry.c b/dix/registry.c
index e9c19b0..5bad0fd 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -286,7 +286,7 @@ LookupResourceName(RESTYPE resource)
 void
 dixResetRegistry(void)
 {
-    ExtensionEntry extEntry;
+    ExtensionEntry extEntry = { .name = CORE };
 
     /* Free all memory */
     while (nmajor--) {
@@ -336,8 +336,6 @@ dixResetRegistry(void)
     RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
 
     /* Add the core protocol */
-    memset(&extEntry, 0, sizeof(extEntry));
-    extEntry.name = CORE;
     RegisterExtensionNames(&extEntry);
 }
 
commit 9805cedf7b0f76d3b75f94e956c4cc2dcf0d8b64
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:44 2012 -0700

    Use C99 designated initializers in extension Events
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xext/saver.c b/Xext/saver.c
index e1e86c0..7f70bc0 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -406,7 +406,6 @@ SendScreenSaverNotify(ScreenPtr pScreen, int state, Bool forced)
     ScreenSaverScreenPrivatePtr pPriv;
     ScreenSaverEventPtr pEv;
     unsigned long mask;
-    xScreenSaverNotifyEvent ev;
     int kind;
 
     UpdateCurrentTimeIf();
@@ -424,16 +423,18 @@ SendScreenSaverNotify(ScreenPtr pScreen, int state, Bool forced)
     else
         kind = ScreenSaverInternal;
     for (pEv = pPriv->events; pEv; pEv = pEv->next) {
-        if (!(pEv->mask & mask))
-            continue;
-        ev.type = ScreenSaverNotify + ScreenSaverEventBase;
-        ev.state = state;
-        ev.timestamp = currentTime.milliseconds;
-        ev.root = pScreen->root->drawable.id;
-        ev.window = pScreen->screensaver.wid;
-        ev.kind = kind;
-        ev.forced = forced;
-        WriteEventsToClient(pEv->client, 1, (xEvent *) &ev);
+        if (pEv->mask & mask) {
+            xScreenSaverNotifyEvent ev = {
+                .type = ScreenSaverNotify + ScreenSaverEventBase,
+                .state = state,
+                .timestamp = currentTime.milliseconds,
+                .root = pScreen->root->drawable.id,
+                .window = pScreen->screensaver.wid,
+                .kind = kind,
+                .forced = forced
+            };
+            WriteEventsToClient(pEv->client, 1, (xEvent *) &ev);
+        }
     }
 }
 
diff --git a/Xext/security.c b/Xext/security.c
index 4144d85..50041de 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -192,10 +192,10 @@ SecurityDeleteAuthorization(pointer value, XID id)
 
     while ((pEventClient = pAuth->eventClients)) {
         /* send revocation event event */
-        xSecurityAuthorizationRevokedEvent are;
-
-        are.type = SecurityEventBase + XSecurityAuthorizationRevoked;
-        are.authId = pAuth->id;
+        xSecurityAuthorizationRevokedEvent are = {
+            .type = SecurityEventBase + XSecurityAuthorizationRevoked,
+            .authId = pAuth->id
+        };
         WriteEventsToClient(rClient(pEventClient), 1, (xEvent *) &are);
         FreeResource(pEventClient->resource, RT_NONE);
     }
diff --git a/Xext/shape.c b/Xext/shape.c
index ecc6c88..68cbef2 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -826,7 +826,6 @@ void
 SendShapeNotify(WindowPtr pWin, int which)
 {
     ShapeEventPtr *pHead, pShapeEvent;
-    xShapeNotifyEvent se;
     BoxRec extents;
     RegionPtr region;
     BYTE shaped;
@@ -883,15 +882,17 @@ SendShapeNotify(WindowPtr pWin, int which)
         return;
     }
     for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) {
-        se.type = ShapeNotify + ShapeEventBase;
-        se.kind = which;
-        se.window = pWin->drawable.id;
-        se.x = extents.x1;
-        se.y = extents.y1;
-        se.width = extents.x2 - extents.x1;
-        se.height = extents.y2 - extents.y1;
-        se.time = currentTime.milliseconds;
-        se.shaped = shaped;
+        xShapeNotifyEvent se = {
+            .type = ShapeNotify + ShapeEventBase,
+            .kind = which,
+            .window = pWin->drawable.id,
+            .x = extents.x1,
+            .y = extents.y1,
+            .width = extents.x2 - extents.x1,
+            .height = extents.y2 - extents.y1,
+            .time = currentTime.milliseconds,
+            .shaped = shaped
+        };
         WriteEventsToClient(pShapeEvent->client, 1, (xEvent *) &se);
     }
 }
diff --git a/Xext/shm.c b/Xext/shm.c
index 6c9b16d..be10a49 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -595,14 +595,14 @@ ProcShmPutImage(ClientPtr client)
                       stuff->dstX, stuff->dstY, shmdesc->addr + stuff->offset);
 
     if (stuff->sendEvent) {
-        xShmCompletionEvent ev;
-
-        ev.type = ShmCompletionCode;
-        ev.drawable = stuff->drawable;
-        ev.minorEvent = X_ShmPutImage;
-        ev.majorEvent = ShmReqCode;
-        ev.shmseg = stuff->shmseg;
-        ev.offset = stuff->offset;
+        xShmCompletionEvent ev = {
+            .type = ShmCompletionCode,
+            .drawable = stuff->drawable,
+            .minorEvent = X_ShmPutImage,
+            .majorEvent = ShmReqCode,
+            .shmseg = stuff->shmseg,
+            .offset = stuff->offset
+        };
         WriteEventsToClient(client, 1, (xEvent *) &ev);
     }
 
diff --git a/Xext/sync.c b/Xext/sync.c
index 3ad2b1b..b203c5e 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -437,9 +437,16 @@ SyncSendAlarmNotifyEvents(SyncAlarm * pAlarm)
 
     UpdateCurrentTime();
 
-    ane.type = SyncEventBase + XSyncAlarmNotify;
-    ane.kind = XSyncAlarmNotify;
-    ane.alarm = pAlarm->alarm_id;
+    ane = (xSyncAlarmNotifyEvent) {
+        .type = SyncEventBase + XSyncAlarmNotify,
+        .kind = XSyncAlarmNotify,
+        .alarm = pAlarm->alarm_id,
+        .alarm_value_hi = XSyncValueHigh32(pTrigger->test_value),
+        .alarm_value_lo = XSyncValueLow32(pTrigger->test_value),
+        .time = currentTime.milliseconds,
+        .state = pAlarm->state
+    };
+
     if (pTrigger->pSync && SYNC_COUNTER == pTrigger->pSync->type) {
         ane.counter_value_hi = XSyncValueHigh32(pCounter->value);
         ane.counter_value_lo = XSyncValueLow32(pCounter->value);
@@ -449,11 +456,6 @@ SyncSendAlarmNotifyEvents(SyncAlarm * pAlarm)
         ane.counter_value_hi = ane.counter_value_lo = 0;
     }
 
-    ane.alarm_value_hi = XSyncValueHigh32(pTrigger->test_value);
-    ane.alarm_value_lo = XSyncValueLow32(pTrigger->test_value);
-    ane.time = currentTime.milliseconds;
-    ane.state = pAlarm->state;
-
     /* send to owner */
     if (pAlarm->events)
         WriteEventsToClient(pAlarm->client, 1, (xEvent *) &ane);
diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index dae9772..31b7783 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -1029,14 +1029,14 @@ ProcXvShmPutImage(ClientPtr client)
                           stuff->send_event, stuff->width, stuff->height);
 
     if ((status == Success) && stuff->send_event) {
-        xShmCompletionEvent ev;
-
-        ev.type = ShmCompletionCode;
-        ev.drawable = stuff->drawable;
-        ev.minorEvent = xv_ShmPutImage;
-        ev.majorEvent = XvReqCode;
-        ev.shmseg = stuff->shmseg;
-        ev.offset = stuff->offset;
+        xShmCompletionEvent ev = {
+            .type = ShmCompletionCode,
+            .drawable = stuff->drawable,
+            .minorEvent = xv_ShmPutImage,
+            .majorEvent = XvReqCode,
+            .shmseg = stuff->shmseg,
+            .offset = stuff->offset
+        };
         WriteEventsToClient(client, 1, (xEvent *) &ev);
     }
 
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 736114b..74872fc 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -507,19 +507,20 @@ XvdiDestroyEncoding(pointer value, XID id)
 static int
 XvdiSendVideoNotify(XvPortPtr pPort, DrawablePtr pDraw, int reason)
 {
-    xvEvent event;
     XvVideoNotifyPtr pn;
 
     dixLookupResourceByType((pointer *) &pn, pDraw->id, XvRTVideoNotifyList,
                             serverClient, DixReadAccess);
 
     while (pn) {
+        xvEvent event = {
+            .u.videoNotify.reason = reason,
+            .u.videoNotify.time = currentTime.milliseconds,
+            .u.videoNotify.drawable = pDraw->id,
+            .u.videoNotify.port = pPort->id
+        };
         event.u.u.type = XvEventBase + XvVideoNotify;
-        event.u.videoNotify.time = currentTime.milliseconds;
-        event.u.videoNotify.drawable = pDraw->id;
-        event.u.videoNotify.port = pPort->id;
-        event.u.videoNotify.reason = reason;
-        WriteEventsToClient(pn->client, 1, (xEventPtr) & event);
+        WriteEventsToClient(pn->client, 1, (xEventPtr) &event);
         pn = pn->next;
     }
 
@@ -530,18 +531,19 @@ XvdiSendVideoNotify(XvPortPtr pPort, DrawablePtr pDraw, int reason)
 int
 XvdiSendPortNotify(XvPortPtr pPort, Atom attribute, INT32 value)
 {
-    xvEvent event;
     XvPortNotifyPtr pn;
 
     pn = pPort->pNotify;
 
     while (pn) {
+        xvEvent event = {
+            .u.portNotify.time = currentTime.milliseconds,
+            .u.portNotify.port = pPort->id,
+            .u.portNotify.attribute = attribute,
+            .u.portNotify.value = value
+        };
         event.u.u.type = XvEventBase + XvPortNotify;
-        event.u.portNotify.time = currentTime.milliseconds;
-        event.u.portNotify.port = pPort->id;
-        event.u.portNotify.attribute = attribute;
-        event.u.portNotify.value = value;
-        WriteEventsToClient(pn->client, 1, (xEventPtr) & event);
+        WriteEventsToClient(pn->client, 1, (xEventPtr) &event);
         pn = pn->next;
     }
 
diff --git a/Xi/chgdctl.c b/Xi/chgdctl.c
index caef0bf..9fe69a5 100644
--- a/Xi/chgdctl.c
+++ b/Xi/chgdctl.c
@@ -113,7 +113,6 @@ ProcXChangeDeviceControl(ClientPtr client)
     AxisInfoPtr a;
     CARD32 *resolution;
     xDeviceEnableCtl *e;
-    devicePresenceNotify dpn;
 
     REQUEST(xChangeDeviceControlReq);
     REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq);
@@ -211,11 +210,13 @@ ProcXChangeDeviceControl(ClientPtr client)
 
  out:
     if (ret == Success) {
-        dpn.type = DevicePresenceNotify;
-        dpn.time = currentTime.milliseconds;
-        dpn.devchange = DeviceControlChanged;
-        dpn.deviceid = dev->id;
-        dpn.control = stuff->control;
+        devicePresenceNotify dpn = {
+            .type = DevicePresenceNotify,
+            .time = currentTime.milliseconds,
+            .devchange = DeviceControlChanged,
+            .deviceid = dev->id,
+            .control = stuff->control
+        };
         SendEventToAllWindows(dev, DevicePresenceNotifyMask,
                               (xEvent *) &dpn, 1);
 
diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
index 0f0e975..8b4ae69 100644
--- a/Xi/grabdevb.c
+++ b/Xi/grabdevb.c
@@ -137,13 +137,14 @@ ProcXGrabDeviceButton(ClientPtr client)
                                   X_GrabDeviceButton)) != Success)
         return ret;
 
-    memset(&param, 0, sizeof(param));
-    param.grabtype = XI;
-    param.ownerEvents = stuff->ownerEvents;
-    param.this_device_mode = stuff->this_device_mode;
-    param.other_devices_mode = stuff->other_devices_mode;
-    param.grabWindow = stuff->grabWindow;
-    param.modifiers = stuff->modifiers;
+    param = (GrabParameters) {
+        .grabtype = XI,
+        .ownerEvents = stuff->ownerEvents,
+        .this_device_mode = stuff->this_device_mode,
+        .other_devices_mode = stuff->other_devices_mode,
+        .grabWindow = stuff->grabWindow,
+        .modifiers = stuff->modifiers
+    };
     mask.xi = tmp[stuff->grabbed_device].mask;
 
     ret = GrabButton(client, dev, mdev, stuff->button, &param, XI, &mask);
diff --git a/Xi/grabdevk.c b/Xi/grabdevk.c
index b755182..8694f9e 100644
--- a/Xi/grabdevk.c
+++ b/Xi/grabdevk.c
@@ -135,13 +135,14 @@ ProcXGrabDeviceKey(ClientPtr client)
                                   X_GrabDeviceKey)) != Success)
         return ret;
 
-    memset(&param, 0, sizeof(param));
-    param.grabtype = XI;
-    param.ownerEvents = stuff->ownerEvents;
-    param.this_device_mode = stuff->this_device_mode;
-    param.other_devices_mode = stuff->other_devices_mode;
-    param.grabWindow = stuff->grabWindow;
-    param.modifiers = stuff->modifiers;
+    param = (GrabParameters) {
+        .grabtype = XI,
+        .ownerEvents = stuff->ownerEvents,
+        .this_device_mode = stuff->this_device_mode,
+        .other_devices_mode = stuff->other_devices_mode,
+        .grabWindow = stuff->grabWindow,
+        .modifiers = stuff->modifiers
+    };
     mask.xi = tmp[stuff->grabbed_device].mask;
 
     ret = GrabKey(client, dev, mdev, stuff->key, &param, XI, &mask);
diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index 51a36d4..ca73104 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -182,30 +182,27 @@ static long XIPropHandlerID = 1;
 static void
 send_property_event(DeviceIntPtr dev, Atom property, int what)
 {
-    devicePropertyNotify event;
-    xXIPropertyEvent xi2;
-    int state;
-
-    if (what == XIPropertyDeleted)
-        state = PropertyDelete;
-    else
-        state = PropertyNewValue;
+    int state = (what == XIPropertyDeleted) ? PropertyDelete : PropertyNewValue;
+    devicePropertyNotify event = {
+        .type = DevicePropertyNotify,
+        .deviceid = dev->id,
+        .state = state,
+        .atom = property,
+        .time = currentTime.milliseconds
+    };
+    xXIPropertyEvent xi2 = {
+        .type = GenericEvent,
+        .extension = IReqCode,
+        .length = 0,
+        .evtype = XI_PropertyEvent,
+        .deviceid = dev->id,
+        .time = currentTime.milliseconds,
+        .property = property,
+        .what = what
+    };
 
-    event.type = DevicePropertyNotify;
-    event.deviceid = dev->id;
-    event.state = state;
-    event.atom = property;
-    event.time = currentTime.milliseconds;
     SendEventToAllWindows(dev, DevicePropertyNotifyMask, (xEvent *) &event, 1);
 
-    xi2.type = GenericEvent;
-    xi2.extension = IReqCode;
-    xi2.length = 0;
-    xi2.evtype = XI_PropertyEvent;
-    xi2.deviceid = dev->id;
-    xi2.time = currentTime.milliseconds;
-    xi2.property = property;
-    xi2.what = what;
     SendEventToAllWindows(dev, GetEventFilter(dev, (xEvent *) &xi2),
                           (xEvent *) &xi2, 1);
 }
diff --git a/damageext/damageext.c b/damageext/damageext.c
index 2eddfb3..222643c 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -46,15 +46,17 @@ DamageExtNotify(DamageExtPtr pDamageExt, BoxPtr pBoxes, int nBoxes)
     int i;
 
     UpdateCurrentTimeIf();
-    ev.type = DamageEventBase + XDamageNotify;
-    ev.level = pDamageExt->level;
-    ev.drawable = pDamageExt->drawable;
-    ev.damage = pDamageExt->id;
-    ev.timestamp = currentTime.milliseconds;
-    ev.geometry.x = pDrawable->x;
-    ev.geometry.y = pDrawable->y;
-    ev.geometry.width = pDrawable->width;
-    ev.geometry.height = pDrawable->height;
+    ev = (xDamageNotifyEvent) {
+        .type = DamageEventBase + XDamageNotify,
+        .level = pDamageExt->level,
+        .drawable = pDamageExt->drawable,
+        .damage = pDamageExt->id,
+        .timestamp = currentTime.milliseconds,
+        .geometry.x = pDrawable->x,
+        .geometry.y = pDrawable->y,
+        .geometry.width = pDrawable->width,
+        .geometry.height = pDrawable->height
+    };
     if (pBoxes) {
         for (i = 0; i < nBoxes; i++) {
             ev.level = pDamageExt->level;
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index e0f4cf7..909de70 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -178,12 +178,13 @@ __glXdriSwapEvent(ClientPtr client, void *data, int type, CARD64 ust,
                   CARD64 msc, CARD32 sbc)
 {
     __GLXdrawable *drawable = data;
-    xGLXBufferSwapComplete2 wire;
+    xGLXBufferSwapComplete2 wire =  {
+        .type = __glXEventBase + GLX_BufferSwapComplete
+    };
 
     if (!(drawable->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
         return;
 
-    wire.type = __glXEventBase + GLX_BufferSwapComplete;
     switch (type) {
     case DRI2_EXCHANGE_COMPLETE:
         wire.event_type = GLX_EXCHANGE_COMPLETE_INTEL;
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index 61612c3..ab172a8 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -900,15 +900,16 @@ DGAStealKeyEvent(DeviceIntPtr dev, int index, int key_code, int is_down)
     if (!pScreenPriv || !pScreenPriv->grabKeyboard)     /* no direct mode */
         return FALSE;
 
-    memset(&event, 0, sizeof(event));
-    event.header = ET_Internal;
-    event.type = ET_DGAEvent;
-    event.length = sizeof(event);
-    event.time = GetTimeInMillis();
-    event.subtype = (is_down ? ET_KeyPress : ET_KeyRelease);
-    event.detail = key_code;
-    event.dx = 0;
-    event.dy = 0;
+    event = (DGAEvent) {
+        .header = ET_Internal,
+        .type = ET_DGAEvent,
+        .length = sizeof(event),
+        .time = GetTimeInMillis(),
+        .subtype = (is_down ? ET_KeyPress : ET_KeyRelease),
+        .detail = key_code,
+        .dx = 0,
+        .dy = 0
+    };
     mieqEnqueue(dev, (InternalEvent *) &event);
 
     return TRUE;
@@ -928,15 +929,16 @@ DGAStealMotionEvent(DeviceIntPtr dev, int index, int dx, int dy)
     if (!pScreenPriv || !pScreenPriv->grabMouse)        /* no direct mode */
         return FALSE;
 
-    memset(&event, 0, sizeof(event));
-    event.header = ET_Internal;
-    event.type = ET_DGAEvent;
-    event.length = sizeof(event);
-    event.time = GetTimeInMillis();
-    event.subtype = ET_Motion;
-    event.detail = 0;
-    event.dx = dx;
-    event.dy = dy;
+    event = (DGAEvent) {
+        .header = ET_Internal,
+        .type = ET_DGAEvent,
+        .length = sizeof(event),
+        .time = GetTimeInMillis(),
+        .subtype = ET_Motion,
+        .detail = 0,
+        .dx = dx,
+        .dy = dy
+    };
     mieqEnqueue(dev, (InternalEvent *) &event);
     return TRUE;
 }
@@ -955,15 +957,16 @@ DGAStealButtonEvent(DeviceIntPtr dev, int index, int button, int is_down)
     if (!pScreenPriv || !pScreenPriv->grabMouse)
         return FALSE;
 
-    memset(&event, 0, sizeof(event));
-    event.header = ET_Internal;
-    event.type = ET_DGAEvent;
-    event.length = sizeof(event);
-    event.time = GetTimeInMillis();
-    event.subtype = (is_down ? ET_ButtonPress : ET_ButtonRelease);
-    event.detail = button;
-    event.dx = 0;
-    event.dy = 0;
+    event = (DGAEvent) {
+        .header = ET_Internal,
+        .type = ET_DGAEvent,
+        .length = sizeof(event),
+        .time = GetTimeInMillis(),
+        .subtype = (is_down ? ET_ButtonPress : ET_ButtonRelease),
+        .detail = button,
+        .dx = 0,
+        .dy = 0
+    };
     mieqEnqueue(dev, (InternalEvent *) &event);
 
     return TRUE;
@@ -988,16 +991,15 @@ DGAProcessKeyboardEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr keybd)
     KeyClassPtr keyc = keybd->key;
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
     DeviceIntPtr pointer = GetMaster(keybd, POINTER_OR_FLOAT);
-    DeviceEvent ev;
-
-    memset(&ev, 0, sizeof(ev));
-    ev.header = ET_Internal;
-    ev.length = sizeof(ev);
-    ev.detail.key = event->detail;
-    ev.type = event->subtype;
-    ev.root_x = 0;
-    ev.root_y = 0;
-    ev.corestate = XkbStateFieldFromRec(&keyc->xkbInfo->state);
+    DeviceEvent ev = {
+        .header = ET_Internal,
+        .length = sizeof(ev),
+        .detail.key = event->detail,
+        .type = event->subtype,
+        .root_x = 0,
+        .root_y = 0,
+        .corestate = XkbStateFieldFromRec(&keyc->xkbInfo->state)
+    };
     ev.corestate |= pointer->button->state;
 
     UpdateDeviceState(keybd, &ev);
@@ -1006,15 +1008,15 @@ DGAProcessKeyboardEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr keybd)
      * Deliver the DGA event
      */
     if (pScreenPriv->client) {
-        dgaEvent de;
-
+        dgaEvent de = {
+            .u.event.time = event->time,
+            .u.event.dx = event->dx,
+            .u.event.dy = event->dy,
+            .u.event.screen = pScreen->myNum,
+            .u.event.state = ev.corestate
+        };
         de.u.u.type = *XDGAEventBase + GetCoreType(ev.type);
         de.u.u.detail = event->detail;
-        de.u.event.time = event->time;
-        de.u.event.dx = event->dx;
-        de.u.event.dy = event->dy;
-        de.u.event.screen = pScreen->myNum;
-        de.u.event.state = ev.corestate;
 
         /* If the DGA client has selected input, then deliver based on the usual filter */
         TryClientEvents(pScreenPriv->client, keybd, (xEvent *) &de, 1,
@@ -1039,14 +1041,14 @@ DGAProcessPointerEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr mouse)
 {
     ButtonClassPtr butc = mouse->button;
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
-    DeviceEvent ev;
     DeviceIntPtr master = GetMaster(mouse, MASTER_KEYBOARD);
+    DeviceEvent ev = {
+        .header = ET_Internal,
+        .length = sizeof(ev),
+        .type = event->subtype,
+        .corestate = butc ? butc->state : 0
+    };
 
-    memset(&ev, 0, sizeof(ev));
-    ev.header = ET_Internal;
-    ev.length = sizeof(ev);
-    ev.type = event->subtype;
-    ev.corestate = butc ? butc->state : 0;
     if (master && master->key)
         ev.corestate |= XkbStateFieldFromRec(&master->key->xkbInfo->state);
 
@@ -1056,18 +1058,16 @@ DGAProcessPointerEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr mouse)
      * Deliver the DGA event
      */
     if (pScreenPriv->client) {
-        dgaEvent de;
-        int coreEquiv;
-
-        coreEquiv = GetCoreType(ev.type);
-
+        int coreEquiv = GetCoreType(ev.type);
+        dgaEvent de = {
+            .u.event.time = event->time,
+            .u.event.dx = event->dx,
+            .u.event.dy = event->dy,
+            .u.event.screen = pScreen->myNum,
+            .u.event.state = ev.corestate
+        };
         de.u.u.type = *XDGAEventBase + coreEquiv;
         de.u.u.detail = event->detail;
-        de.u.event.time = event->time;
-        de.u.event.dx = event->dx;
-        de.u.event.dy = event->dy;
-        de.u.event.screen = pScreen->myNum;
-        de.u.event.state = ev.corestate;
 
         /* If the DGA client has selected input, then deliver based on the usual filter */
         TryClientEvents(pScreenPriv->client, mouse, (xEvent *) &de, 1,
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 455ff34..3d66852 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -240,7 +240,6 @@ static void
 SendXF86VidModeNotify(ScreenPtr pScreen, int state, Bool forced)
 {
     XF86VidModeScreenPrivatePtr pPriv;
-    XF86VidModeEventPtr pEv;
     unsigned long mask;
     xXF86VidModeNotifyEvent ev;
     int kind;
@@ -253,15 +252,17 @@ SendXF86VidModeNotify(ScreenPtr pScreen, int state, Bool forced)
         return;
     kind = XF86VidModeModeChange;
     for (pEv = pPriv->events; pEv; pEv = pEv->next) {
-        if (!(pEv->mask & mask))
-            continue;
-        ev.type = XF86VidModeNotify + XF86VidModeEventBase;
-        ev.state = state;
-        ev.timestamp = currentTime.milliseconds;
-        ev.root = pScreen->root->drawable.id;
-        ev.kind = kind;
-        ev.forced = forced;
-        WriteEventsToClient(pEv->client, 1, (xEvent *) &ev);
+        if (pEv->mask & mask) {
+            XF86VidModeEventPtr pEv = {
+                .type = XF86VidModeNotify + XF86VidModeEventBase,
+                .state = state,
+                .timestamp = currentTime.milliseconds,
+                .root = pScreen->root->drawable.id,
+                .kind = kind,
+                .forced = forced
+            };
+            WriteEventsToClient(pEv->client, 1, (xEvent *) &ev);
+        }
     }
 }
 
diff --git a/hw/xfree86/dri2/dri2ext.c b/hw/xfree86/dri2/dri2ext.c
index a6be4c2..c73fe9d 100644
--- a/hw/xfree86/dri2/dri2ext.c
+++ b/hw/xfree86/dri2/dri2ext.c
@@ -161,11 +161,11 @@ ProcDRI2Authenticate(ClientPtr client)
 static void
 DRI2InvalidateBuffersEvent(DrawablePtr pDraw, void *priv, XID id)
 {
-    xDRI2InvalidateBuffers event;
     ClientPtr client = priv;
-
-    event.type = DRI2EventBase + DRI2_InvalidateBuffers;
-    event.drawable = id;
+    xDRI2InvalidateBuffers event = {
+        .type = DRI2EventBase + DRI2_InvalidateBuffers,
+        .drawable = id
+    };
 
     WriteEventsToClient(client, 1, (xEvent *) &event);
 }
@@ -363,17 +363,17 @@ static void
 DRI2SwapEvent(ClientPtr client, void *data, int type, CARD64 ust, CARD64 msc,
               CARD32 sbc)
 {
-    xDRI2BufferSwapComplete2 event;
     DrawablePtr pDrawable = data;
-
-    event.type = DRI2EventBase + DRI2_BufferSwapComplete;
-    event.event_type = type;
-    event.drawable = pDrawable->id;
-    event.ust_hi = (CARD64) ust >> 32;
-    event.ust_lo = ust & 0xffffffff;
-    event.msc_hi = (CARD64) msc >> 32;
-    event.msc_lo = msc & 0xffffffff;
-    event.sbc = sbc;
+    xDRI2BufferSwapComplete2 event = {
+        .type = DRI2EventBase + DRI2_BufferSwapComplete,
+        .event_type = type,
+        .drawable = pDrawable->id,
+        .ust_hi = (CARD64) ust >> 32,
+        .ust_lo = ust & 0xffffffff,
+        .msc_hi = (CARD64) msc >> 32,
+        .msc_lo = msc & 0xffffffff,
+        .sbc = sbc
+    };
 
     WriteEventsToClient(client, 1, (xEvent *) &event);
 }
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 138fbe1..e82d050 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -236,29 +236,21 @@ RRDeliverCrtcEvent(ClientPtr client, WindowPtr pWin, RRCrtcPtr crtc)
     ScreenPtr pScreen = pWin->drawable.pScreen;
 
     rrScrPriv(pScreen);
-    xRRCrtcChangeNotifyEvent ce;
     RRModePtr mode = crtc->mode;
 
-    ce.type = RRNotify + RREventBase;
-    ce.subCode = RRNotify_CrtcChange;
-    ce.timestamp = pScrPriv->lastSetTime.milliseconds;
-    ce.window = pWin->drawable.id;
-    ce.crtc = crtc->id;
-    ce.rotation = crtc->rotation;
-    if (mode) {
-        ce.mode = mode->mode.id;
-        ce.x = crtc->x;
-        ce.y = crtc->y;
-        ce.width = mode->mode.width;
-        ce.height = mode->mode.height;
-    }
-    else {
-        ce.mode = None;
-        ce.x = 0;
-        ce.y = 0;
-        ce.width = 0;
-        ce.height = 0;
-    }
+    xRRCrtcChangeNotifyEvent ce = {
+        .type = RRNotify + RREventBase,
+        .subCode = RRNotify_CrtcChange,
+        .timestamp = pScrPriv->lastSetTime.milliseconds,
+        .window = pWin->drawable.id,
+        .crtc = crtc->id,
+        .mode = mode ? mode->mode.id : None,
+        .rotation = crtc->rotation,
+        .x = mode ? crtc->x : 0,
+        .y = mode ? crtc->y : 0,
+        .width = mode ? mode->mode.width : 0,
+        .height = mode ? mode->mode.height : 0
+    };
     WriteEventsToClient(client, 1, (xEvent *) &ce);
 }
 
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 0932508..88781ba 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -305,28 +305,22 @@ RRDeliverOutputEvent(ClientPtr client, WindowPtr pWin, RROutputPtr output)
     ScreenPtr pScreen = pWin->drawable.pScreen;
 
     rrScrPriv(pScreen);
-    xRROutputChangeNotifyEvent oe;
     RRCrtcPtr crtc = output->crtc;
-    RRModePtr mode = crtc ? crtc->mode : 0;
-
-    oe.type = RRNotify + RREventBase;
-    oe.subCode = RRNotify_OutputChange;
-    oe.timestamp = pScrPriv->lastSetTime.milliseconds;
-    oe.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
-    oe.window = pWin->drawable.id;
-    oe.output = output->id;
-    if (crtc) {
-        oe.crtc = crtc->id;
-        oe.mode = mode ? mode->mode.id : None;
-        oe.rotation = crtc->rotation;
-    }
-    else {
-        oe.crtc = None;
-        oe.mode = None;
-        oe.rotation = RR_Rotate_0;
-    }
-    oe.connection = output->connection;
-    oe.subpixelOrder = output->subpixelOrder;
+    RRModePtr mode = crtc ? crtc->mode : NULL;
+
+    xRROutputChangeNotifyEvent oe = {
+        .type = RRNotify + RREventBase,
+        .subCode = RRNotify_OutputChange,
+        .timestamp = pScrPriv->lastSetTime.milliseconds,
+        .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
+        .window = pWin->drawable.id,
+        .output = output->id,
+        .crtc = crtc ? crtc->id : None,
+        .mode = mode ? mode->mode.id : None,
+        .rotation = crtc ? crtc->rotation : RR_Rotate_0,
+        .connection = output->connection,
+        .subpixelOrder = output->subpixelOrder
+    };
     WriteEventsToClient(client, 1, (xEvent *) &oe);
 }
 
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index 7ce085c..7f09092 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -65,14 +65,14 @@ RRDestroyOutputProperty(RRPropertyPtr 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;
+    xRROutputPropertyNotifyEvent event = {
+        .type = RREventBase + RRNotify,
+        .subCode = RRNotify_OutputProperty,
+        .output = output->id,
+        .state = PropertyDelete,
+        .atom = prop->propertyName,
+        .timestamp = currentTime.milliseconds
+    };
 
     RRDeliverPropertyEvent(output->pScreen, (xEvent *) &event);
 
@@ -138,7 +138,6 @@ RRChangeOutputProperty(RROutputPtr output, Atom property, Atom type,
                        pointer value, Bool sendevent, Bool pending)
 {
     RRPropertyPtr prop;
-    xRROutputPropertyNotifyEvent event;
     rrScrPrivPtr pScrPriv = rrGetScrPriv(output->pScreen);
     int size_in_bytes;
     int total_size;
@@ -237,12 +236,14 @@ RRChangeOutputProperty(RROutputPtr output, Atom property, Atom type,
         output->pendingProperties = TRUE;
 
     if (sendevent) {
-        event.type = RREventBase + RRNotify;
-        event.subCode = RRNotify_OutputProperty;
-        event.output = output->id;
-        event.state = PropertyNewValue;
-        event.atom = prop->propertyName;
-        event.timestamp = currentTime.milliseconds;
+        xRROutputPropertyNotifyEvent event = {
+            .type = RREventBase + RRNotify,
+            .subCode = RRNotify_OutputProperty,
+            .output = output->id,
+            .state = PropertyNewValue,
+            .atom = prop->propertyName,
+            .timestamp = currentTime.milliseconds
+        };
         RRDeliverPropertyEvent(output->pScreen, (xEvent *) &event);
     }
     return Success;
@@ -682,14 +683,14 @@ ProcRRGetOutputProperty(ClientPtr client)
     reply.propertyType = prop_value->type;
 
     if (stuff->delete && (reply.bytesAfter == 0)) {
-        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;
+        xRROutputPropertyNotifyEvent event = {
+            .type = RREventBase + RRNotify,
+            .subCode = RRNotify_OutputProperty,
+            .output = output->id,
+            .state = PropertyDelete,
+            .atom = prop->propertyName,
+            .timestamp = currentTime.milliseconds
+        };
         RRDeliverPropertyEvent(output->pScreen, (xEvent *) &event);
     }
 
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 774f8be..a427725 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -71,20 +71,20 @@ void
 RRSendConfigNotify(ScreenPtr pScreen)
 {
     WindowPtr pWin = pScreen->root;
-    xEvent event;
-
-    event.u.u.type = ConfigureNotify;
-    event.u.configureNotify.window = pWin->drawable.id;
-    event.u.configureNotify.aboveSibling = None;
-    event.u.configureNotify.x = 0;
-    event.u.configureNotify.y = 0;
+    xEvent event = {
+        .u.configureNotify.window = pWin->drawable.id,
+        .u.configureNotify.aboveSibling = None,
+        .u.configureNotify.x = 0,
+        .u.configureNotify.y = 0,
 
     /* XXX xinerama stuff ? */
 
-    event.u.configureNotify.width = pWin->drawable.width;
-    event.u.configureNotify.height = pWin->drawable.height;
-    event.u.configureNotify.borderWidth = wBorderWidth(pWin);
-    event.u.configureNotify.override = pWin->overrideRedirect;
+        .u.configureNotify.width = pWin->drawable.width,
+        .u.configureNotify.height = pWin->drawable.height,
+        .u.configureNotify.borderWidth = wBorderWidth(pWin),
+        .u.configureNotify.override = pWin->overrideRedirect
+    };
+    event.u.u.type = ConfigureNotify;
     DeliverEvents(pWin, &event, 1, NullWindow);
 }
 
@@ -92,19 +92,20 @@ void
 RRDeliverScreenEvent(ClientPtr client, WindowPtr pWin, ScreenPtr pScreen)
 {
     rrScrPriv(pScreen);
-    xRRScreenChangeNotifyEvent se;
     RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL;
     WindowPtr pRoot = pScreen->root;
 
-    se.type = RRScreenChangeNotify + RREventBase;
-    se.rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0);
-    se.timestamp = pScrPriv->lastSetTime.milliseconds;
-    se.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
-    se.root = pRoot->drawable.id;
-    se.window = pWin->drawable.id;
-    se.subpixelOrder = PictureGetSubpixelOrder(pScreen);
+    xRRScreenChangeNotifyEvent se = {
+        .type = RRScreenChangeNotify + RREventBase,
+        .rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0),
+        .timestamp = pScrPriv->lastSetTime.milliseconds,
+        .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
+        .root = pRoot->drawable.id,
+        .window = pWin->drawable.id,
+        .subpixelOrder = PictureGetSubpixelOrder(pScreen),
 
-    se.sizeID = RR10CurrentSizeID(pScreen);
+        .sizeID = RR10CurrentSizeID(pScreen)
+    };
 
     if (se.rotation & (RR_Rotate_90 | RR_Rotate_270)) {
         se.widthInPixels = pScreen->height;
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 68f7b74..4eee592 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -172,14 +172,14 @@ CursorDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
         CursorCurrent[pDev->id] = pCursor;
         for (e = cursorEvents; e; e = e->next) {
             if ((e->eventMask & XFixesDisplayCursorNotifyMask)) {
-                xXFixesCursorNotifyEvent ev;
-
-                ev.type = XFixesEventBase + XFixesCursorNotify;
-                ev.subtype = XFixesDisplayCursorNotify;
-                ev.window = e->pWindow->drawable.id;
-                ev.cursorSerial = pCursor ? pCursor->serialNumber : 0;
-                ev.timestamp = currentTime.milliseconds;
-                ev.name = pCursor ? pCursor->name : None;
+                xXFixesCursorNotifyEvent ev = {
+                    .type = XFixesEventBase + XFixesCursorNotify,
+                    .subtype = XFixesDisplayCursorNotify,
+                    .window = e->pWindow->drawable.id,
+                    .cursorSerial = pCursor ? pCursor->serialNumber : 0,
+                    .timestamp = currentTime.milliseconds,
+                    .name = pCursor ? pCursor->name : None
+                };
                 WriteEventsToClient(e->pClient, 1, (xEvent *) &ev);
             }
         }
diff --git a/xfixes/select.c b/xfixes/select.c
index a896846..ee8ed6f 100644
--- a/xfixes/select.c
+++ b/xfixes/select.c
@@ -77,19 +77,16 @@ XFixesSelectionCallback(CallbackListPtr *callbacks, pointer data, pointer args)
     }
     for (e = selectionEvents; e; e = e->next) {
         if (e->selection == selection->selection && (e->eventMask & eventMask)) {
-            xXFixesSelectionNotifyEvent ev;
-
-            memset(&ev, 0, sizeof(xXFixesSelectionNotifyEvent));
-            ev.type = XFixesEventBase + XFixesSelectionNotify;
-            ev.subtype = subtype;
-            ev.window = e->pWindow->drawable.id;
-            if (subtype == XFixesSetSelectionOwnerNotify)
-                ev.owner = selection->window;
-            else
-                ev.owner = 0;
-            ev.selection = e->selection;
-            ev.timestamp = currentTime.milliseconds;
-            ev.selectionTimestamp = selection->lastTimeChanged.milliseconds;
+            xXFixesSelectionNotifyEvent ev = {
+                .type = XFixesEventBase + XFixesSelectionNotify,
+                .subtype = subtype,
+                .window = e->pWindow->drawable.id,
+                .owner = (subtype == XFixesSetSelectionOwnerNotify) ?
+                            selection->window : 0,
+                .selection = e->selection,
+                .timestamp = currentTime.milliseconds,
+                .selectionTimestamp = selection->lastTimeChanged.milliseconds
+            };
             WriteEventsToClient(e->pClient, 1, (xEvent *) &ev);
         }
     }
diff --git a/xkb/xkbEvents.c b/xkb/xkbEvents.c
index beb09cf..87a4485 100644
--- a/xkb/xkbEvents.c
+++ b/xkb/xkbEvents.c
@@ -59,8 +59,6 @@ XkbSendLegacyMapNotify(DeviceIntPtr kbd, CARD16 xkb_event, CARD16 changed,
     int i;
     int keymap_changed = 0;
     int modmap_changed = 0;
-    xEvent core_mn;
-    deviceMappingNotify xi_mn;
     CARD32 time = GetTimeInMillis();
 
     if (xkb_event == XkbNewKeyboardNotify) {
@@ -78,11 +76,6 @@ XkbSendLegacyMapNotify(DeviceIntPtr kbd, CARD16 xkb_event, CARD16 changed,
     if (!keymap_changed && !modmap_changed)
         return;
 
-    core_mn.u.u.type = MappingNotify;
-    xi_mn.type = DeviceMappingNotify;
-    xi_mn.deviceid = kbd->id;
-    xi_mn.time = time;
-
     /* 0 is serverClient. */
     for (i = 1; i < currentMaxClients; i++) {
         if (!clients[i] || clients[i]->clientState != ClientStateRunning)
@@ -106,6 +99,7 @@ XkbSendLegacyMapNotify(DeviceIntPtr kbd, CARD16 xkb_event, CARD16 changed,
             continue;
 
         if (keymap_changed) {
+            xEvent core_mn = { .u.u.type = MappingNotify };
             core_mn.u.mappingNotify.request = MappingKeyboard;
 
             /* Clip the keycode range to what the client knows about, so it
@@ -123,9 +117,12 @@ XkbSendLegacyMapNotify(DeviceIntPtr kbd, CARD16 xkb_event, CARD16 changed,
             WriteEventsToClient(clients[i], 1, &core_mn);
         }
         if (modmap_changed) {
-            core_mn.u.mappingNotify.request = MappingModifier;
-            core_mn.u.mappingNotify.firstKeyCode = 0;
-            core_mn.u.mappingNotify.count = 0;
+            xEvent core_mn = {
+                .u.mappingNotify.request = MappingModifier,
+                .u.mappingNotify.firstKeyCode = 0,
+                .u.mappingNotify.count = 0
+            };
+            core_mn.u.u.type = MappingNotify;
             WriteEventsToClient(clients[i], 1, &core_mn);
         }
     }
@@ -134,16 +131,26 @@ XkbSendLegacyMapNotify(DeviceIntPtr kbd, CARD16 xkb_event, CARD16 changed,
      * here? Clients might be upset, but that seems better than the
      * alternative of stale keymaps. -ds */
     if (keymap_changed) {
-        xi_mn.request = MappingKeyboard;
-        xi_mn.firstKeyCode = first_key;
-        xi_mn.count = num_keys;
+        deviceMappingNotify xi_mn = {
+            .type = DeviceMappingNotify,
+            .deviceid = kbd->id,
+            .request = MappingKeyboard,
+            .firstKeyCode = first_key,
+            .count = num_keys,
+            .time = time
+        };
         SendEventToAllWindows(kbd, DeviceMappingNotifyMask, (xEvent *) &xi_mn,
                               1);
     }
     if (modmap_changed) {
-        xi_mn.request = MappingModifier;
-        xi_mn.firstKeyCode = 0;
-        xi_mn.count = 0;
+        deviceMappingNotify xi_mn = {
+            .type = DeviceMappingNotify,
+            .deviceid = kbd->id,
+            .request = MappingModifier,
+            .firstKeyCode = 0,
+            .count = 0,
+            .time = time
+        };
         SendEventToAllWindows(kbd, DeviceMappingNotifyMask, (xEvent *) &xi_mn,
                               1);
     }
commit 0af79b124e1317c36d1613d28755c5a8ce612e2a
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:44 2012 -0700

    Use C99 designated initializers in dix Events
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/colormap.c b/dix/colormap.c
index 36526b8..a43e279 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -450,15 +450,15 @@ FreeColormap(pointer value, XID mid)
 static int
 TellNoMap(WindowPtr pwin, Colormap * pmid)
 {
-    xEvent xE;
-
     if (wColormap(pwin) == *pmid) {
         /* This should be call to DeliverEvent */
+        xEvent xE = {
+            .u.colormap.window = pwin->drawable.id,
+            .u.colormap.colormap = None,
+            .u.colormap.new = TRUE,
+            .u.colormap.state = ColormapUninstalled
+        };
         xE.u.u.type = ColormapNotify;
-        xE.u.colormap.window = pwin->drawable.id;
-        xE.u.colormap.colormap = None;
-        xE.u.colormap.new = TRUE;
-        xE.u.colormap.state = ColormapUninstalled;
 #ifdef PANORAMIX
         if (noPanoramiXExtension || !pwin->drawable.pScreen->myNum)
 #endif
@@ -477,7 +477,6 @@ int
 TellLostMap(WindowPtr pwin, pointer value)
 {
     Colormap *pmid = (Colormap *) value;
-    xEvent xE;
 
 #ifdef PANORAMIX
     if (!noPanoramiXExtension && pwin->drawable.pScreen->myNum)
@@ -485,11 +484,13 @@ TellLostMap(WindowPtr pwin, pointer value)
 #endif
     if (wColormap(pwin) == *pmid) {
         /* This should be call to DeliverEvent */
+        xEvent xE = {
+            .u.colormap.window = pwin->drawable.id,
+            .u.colormap.colormap = *pmid,
+            .u.colormap.new = FALSE,
+            .u.colormap.state = ColormapUninstalled
+        };
         xE.u.u.type = ColormapNotify;
-        xE.u.colormap.window = pwin->drawable.id;
-        xE.u.colormap.colormap = *pmid;
-        xE.u.colormap.new = FALSE;
-        xE.u.colormap.state = ColormapUninstalled;
         DeliverEvents(pwin, &xE, 1, (WindowPtr) NULL);
     }
 
@@ -501,7 +502,6 @@ int
 TellGainedMap(WindowPtr pwin, pointer value)
 {
     Colormap *pmid = (Colormap *) value;
-    xEvent xE;
 
 #ifdef PANORAMIX
     if (!noPanoramiXExtension && pwin->drawable.pScreen->myNum)
@@ -509,11 +509,13 @@ TellGainedMap(WindowPtr pwin, pointer value)
 #endif
     if (wColormap(pwin) == *pmid) {
         /* This should be call to DeliverEvent */
+        xEvent xE = {
+            .u.colormap.window = pwin->drawable.id,
+            .u.colormap.colormap = *pmid,
+            .u.colormap.new = FALSE,
+            .u.colormap.state = ColormapInstalled
+        };
         xE.u.u.type = ColormapNotify;
-        xE.u.colormap.window = pwin->drawable.id;
-        xE.u.colormap.colormap = *pmid;
-        xE.u.colormap.new = FALSE;
-        xE.u.colormap.state = ColormapInstalled;
         DeliverEvents(pwin, &xE, 1, (WindowPtr) NULL);
     }
 
diff --git a/dix/devices.c b/dix/devices.c
index 77583f7..839de35 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -321,15 +321,14 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
 void
 SendDevicePresenceEvent(int deviceid, int type)
 {
-    DeviceIntRec dummyDev;
-    devicePresenceNotify ev;
-
-    memset(&dummyDev, 0, sizeof(DeviceIntRec));
-    ev.type = DevicePresenceNotify;
-    ev.time = currentTime.milliseconds;
-    ev.devchange = type;
-    ev.deviceid = deviceid;
-    dummyDev.id = XIAllDevices;
+    DeviceIntRec dummyDev = { .id =  XIAllDevices };
+    devicePresenceNotify ev = {
+        .type = DevicePresenceNotify,
+        .time = currentTime.milliseconds,
+        .devchange = type,
+        .deviceid = deviceid
+    };
+
     SendEventToAllWindows(&dummyDev, DevicePresenceNotifyMask,
                           (xEvent *) &ev, 1);
 }
@@ -2450,18 +2449,17 @@ RecalculateMasterButtons(DeviceIntPtr slave)
 
     if (master->button && master->button->numButtons != maxbuttons) {
         int i;
-        DeviceChangedEvent event;
-
-        memset(&event, 0, sizeof(event));
+        DeviceChangedEvent event = {
+            .header = ET_Internal,
+            .type = ET_DeviceChanged,
+            .time = GetTimeInMillis(),
+            .deviceid = master->id,
+            .flags = DEVCHANGE_POINTER_EVENT | DEVCHANGE_DEVICE_CHANGE,
+            .buttons.num_buttons = maxbuttons
+        };
 
         master->button->numButtons = maxbuttons;
 
-        event.header = ET_Internal;
-        event.type = ET_DeviceChanged;
-        event.time = GetTimeInMillis();
-        event.deviceid = master->id;
-        event.flags = DEVCHANGE_POINTER_EVENT | DEVCHANGE_DEVICE_CHANGE;
-        event.buttons.num_buttons = maxbuttons;
         memcpy(&event.buttons.names, master->button->labels, maxbuttons *
                sizeof(Atom));
 
diff --git a/dix/enterleave.c b/dix/enterleave.c
index 00083e9..431566f 100644
--- a/dix/enterleave.c
+++ b/dix/enterleave.c
@@ -827,12 +827,14 @@ DeviceFocusEvent(DeviceIntPtr dev, int type, int mode, int detail,
     free(xi2event);
 
     /* XI 1.x event */
-    event.deviceid = dev->id;
-    event.mode = mode;
-    event.type = (type == XI_FocusIn) ? DeviceFocusIn : DeviceFocusOut;
-    event.detail = detail;
-    event.window = pWin->drawable.id;
-    event.time = currentTime.milliseconds;
+    event = (deviceFocus) {
+        .deviceid = dev->id,
+        .mode = mode,
+        .type = (type == XI_FocusIn) ? DeviceFocusIn : DeviceFocusOut,
+        .detail = detail,
+        .window = pWin->drawable.id,
+        .time = currentTime.milliseconds
+    };
 
     DeliverEventsToWindow(dev, pWin, (xEvent *) &event, 1,
                           DeviceFocusChangeMask, NullGrab);
diff --git a/dix/events.c b/dix/events.c
index 1708710..3b40446 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2834,14 +2834,15 @@ ActivateFocusInGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
     if (win == NoneWin || win == PointerRootWin)
         return FALSE;
 
-    memset(&event, 0, sizeof(DeviceEvent));
-    event.header = ET_Internal;
-    event.type = ET_FocusIn;
-    event.length = sizeof(DeviceEvent);
-    event.time = GetTimeInMillis();
-    event.deviceid = dev->id;
-    event.sourceid = dev->id;
-    event.detail.button = 0;
+    event = (DeviceEvent) {
+        .header = ET_Internal,
+        .type = ET_FocusIn,
+        .length = sizeof(DeviceEvent),
+        .time = GetTimeInMillis(),
+        .deviceid = dev->id,
+        .sourceid = dev->id,
+        .detail.button = 0
+    };
     rc = (CheckPassiveGrabsOnWindow(win, dev, (InternalEvent *) &event, FALSE,
                                     TRUE) != NULL);
     if (rc)
@@ -2871,14 +2872,15 @@ ActivateEnterGrab(DeviceIntPtr dev, WindowPtr old, WindowPtr win)
         (*dev->deviceGrab.DeactivateGrab) (dev);
     }
 
-    memset(&event, 0, sizeof(DeviceEvent));
-    event.header = ET_Internal;
-    event.type = ET_Enter;
-    event.length = sizeof(DeviceEvent);
-    event.time = GetTimeInMillis();
-    event.deviceid = dev->id;
-    event.sourceid = dev->id;
-    event.detail.button = 0;
+    event = (DeviceEvent) {
+        .header = ET_Internal,
+        .type = ET_Enter,
+        .length = sizeof(DeviceEvent),
+        .time = GetTimeInMillis(),
+        .deviceid = dev->id,
+        .sourceid = dev->id,
+        .detail.button = 0
+    };
     rc = (CheckPassiveGrabsOnWindow(win, dev, (InternalEvent *) &event, FALSE,
                                     TRUE) != NULL);
     if (rc)
@@ -4457,7 +4459,10 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
                     int type,
                     int mode, int detail, WindowPtr pWin, Window child)
 {
-    xEvent event;
+    xEvent event = {
+        .u.u.type = type,
+        .u.u.detail = detail
+    };
     WindowPtr focus;
     DeviceIntPtr keybd;
     GrabPtr grab = mouse->deviceGrab.grab;
@@ -4477,9 +4482,6 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
         mask = pWin->eventMask | wOtherEventMasks(pWin);
     }
 
-    memset(&event, 0, sizeof(xEvent));
-    event.u.u.type = type;
-    event.u.u.detail = detail;
     event.u.enterLeave.time = currentTime.milliseconds;
     event.u.enterLeave.rootX = mouse->spriteInfo->sprite->hot.x;
     event.u.enterLeave.rootY = mouse->spriteInfo->sprite->hot.y;
@@ -4510,16 +4512,16 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
     }
 
     if ((type == EnterNotify) && (mask & KeymapStateMask)) {
-        xKeymapEvent ke;
+        xKeymapEvent ke = {
+            .type = KeymapNotify
+        };
         ClientPtr client = grab ? rClient(grab) : wClient(pWin);
         int rc;
 
-        memset((char *) &ke.map[0], 0, 31);
         rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess);
         if (rc == Success)
             memcpy((char *) &ke.map[0], (char *) &keybd->key->down[1], 31);
 
-        ke.type = KeymapNotify;
         if (grab)
             TryClientEvents(rClient(grab), keybd, (xEvent *) &ke, 1,
                             mask, KeymapStateMask, grab);
@@ -4604,28 +4606,27 @@ DeviceEnterLeaveEvent(DeviceIntPtr mouse,
 void
 CoreFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin)
 {
-    xEvent event;
-
-    memset(&event, 0, sizeof(xEvent));
+    xEvent event = {
+        .u.u.type = type,
+        .u.u.detail = detail
+    };
     event.u.focus.mode = mode;
-    event.u.u.type = type;
-    event.u.u.detail = detail;
     event.u.focus.window = pWin->drawable.id;
 
     DeliverEventsToWindow(dev, pWin, &event, 1,
                           GetEventFilter(dev, &event), NullGrab);
     if ((type == FocusIn) &&
         ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask)) {
-        xKeymapEvent ke;
+        xKeymapEvent ke = {
+            .type = KeymapNotify
+        };
         ClientPtr client = wClient(pWin);
         int rc;
 
-        memset((char *) &ke.map[0], 0, 31);
         rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess);
         if (rc == Success)
             memcpy((char *) &ke.map[0], (char *) &dev->key->down[1], 31);
 
-        ke.type = KeymapNotify;
         DeliverEventsToWindow(dev, pWin, (xEvent *) &ke, 1,
                               KeymapStateMask, NullGrab);
     }
@@ -5429,12 +5430,13 @@ ProcGrabKey(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xGrabKeyReq);
 
-    memset(&param, 0, sizeof(param));
-    param.grabtype = CORE;
-    param.ownerEvents = stuff->ownerEvents;
-    param.this_device_mode = stuff->keyboardMode;
-    param.other_devices_mode = stuff->pointerMode;
-    param.modifiers = stuff->modifiers;
+    param = (GrabParameters) {
+        .grabtype = CORE,
+        .ownerEvents = stuff->ownerEvents,
+        .this_device_mode = stuff->keyboardMode,
+        .other_devices_mode = stuff->pointerMode,
+        .modifiers = stuff->modifiers
+    };
 
     rc = CheckGrabValues(client, &param);
     if (rc != Success)
@@ -5535,12 +5537,13 @@ ProcGrabButton(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    memset(&param, 0, sizeof(param));
-    param.grabtype = CORE;
-    param.ownerEvents = stuff->ownerEvents;
-    param.this_device_mode = stuff->keyboardMode;
-    param.other_devices_mode = stuff->pointerMode;
-    param.modifiers = stuff->modifiers;
+    param = (GrabParameters) {
+        .grabtype = CORE,
+        .ownerEvents = stuff->ownerEvents,
+        .this_device_mode = stuff->keyboardMode,
+        .other_devices_mode = stuff->pointerMode,
+        .modifiers = stuff->modifiers
+    };
 
     mask.core = stuff->eventMask;
 
diff --git a/dix/inpututils.c b/dix/inpututils.c
index 223d547..f01e9a7 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -71,14 +71,13 @@ static void
 do_butmap_change(DeviceIntPtr dev, CARD8 *map, int len, ClientPtr client)
 {
     int i;
-    xEvent core_mn;
+    xEvent core_mn = { .u.u.type = MappingNotify };
     deviceMappingNotify xi_mn;
 
     /* The map in ButtonClassRec refers to button numbers, whereas the
      * protocol is zero-indexed.  Sigh. */
     memcpy(&(dev->button->map[1]), map, len);
 
-    core_mn.u.u.type = MappingNotify;
     core_mn.u.mappingNotify.request = MappingPointer;
 
     /* 0 is the server client. */
@@ -93,10 +92,12 @@ do_butmap_change(DeviceIntPtr dev, CARD8 *map, int len, ClientPtr client)
         WriteEventsToClient(clients[i], 1, &core_mn);
     }
 
-    xi_mn.type = DeviceMappingNotify;
-    xi_mn.request = MappingPointer;
-    xi_mn.deviceid = dev->id;
-    xi_mn.time = GetTimeInMillis();
+    xi_mn = (deviceMappingNotify) {
+        .type = DeviceMappingNotify,
+        .request = MappingPointer,
+        .deviceid = dev->id,
+        .time = GetTimeInMillis()
+    };
 
     SendEventToAllWindows(dev, DeviceMappingNotifyMask, (xEvent *) &xi_mn, 1);
 }
diff --git a/dix/property.c b/dix/property.c
index 5aa6f4a..dec4090 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -108,14 +108,13 @@ dixLookupProperty(PropertyPtr *result, WindowPtr pWin, Atom propertyName,
 static void
 deliverPropertyNotifyEvent(WindowPtr pWin, int state, Atom atom)
 {
-    xEvent event;
-
-    memset(&event, 0, sizeof(xEvent));
+    xEvent event = {
+        .u.property.window = pWin->drawable.id,
+        .u.property.state = state,
+        .u.property.atom = atom,
+        .u.property.time = currentTime.milliseconds
+    };
     event.u.u.type = PropertyNotify;
-    event.u.property.window = pWin->drawable.id;
-    event.u.property.state = state;
-    event.u.property.atom = atom;
-    event.u.property.time = currentTime.milliseconds;
     DeliverEvents(pWin, &event, 1, (WindowPtr) NULL);
 }
 
diff --git a/dix/selection.c b/dix/selection.c
index 80b5893..e905b1e 100644
--- a/dix/selection.c
+++ b/dix/selection.c
@@ -174,8 +174,6 @@ ProcSetSelectionOwner(ClientPtr client)
     rc = dixLookupSelection(&pSel, stuff->selection, client, DixSetAttrAccess);
 
     if (rc == Success) {
-        xEvent event;
-
         /* If the timestamp in client's request is in the past relative
            to the time stamp indicating the last time the owner of the
            selection was set, do not set the selection, just return 
@@ -183,10 +181,12 @@ ProcSetSelectionOwner(ClientPtr client)
         if (CompareTimeStamps(time, pSel->lastTimeChanged) == EARLIER)
             return Success;
         if (pSel->client && (!pWin || (pSel->client != client))) {
+            xEvent event = {
+                .u.selectionClear.time = time.milliseconds,
+                .u.selectionClear.window = pSel->window,
+                .u.selectionClear.atom = pSel->selection
+            };
             event.u.u.type = SelectionClear;
-            event.u.selectionClear.time = time.milliseconds;
-            event.u.selectionClear.window = pSel->window;
-            event.u.selectionClear.atom = pSel->selection;
             WriteEventsToClient(pSel->client, 1, &event);
         }
     }
diff --git a/dix/swapreq.c b/dix/swapreq.c
index a896b4b..0f6d49e 100644
--- a/dix/swapreq.c
+++ b/dix/swapreq.c
@@ -283,7 +283,7 @@ SProcConvertSelection(ClientPtr client)
 int
 SProcSendEvent(ClientPtr client)
 {
-    xEvent eventT;
+    xEvent eventT = { .u.u.type = 0 };
     EventSwapPtr proc;
 
     REQUEST(xSendEventReq);
diff --git a/dix/window.c b/dix/window.c
index b660808..cdd12dc 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -641,7 +641,6 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
     WindowPtr pWin;
     WindowPtr pHead;
     ScreenPtr pScreen;
-    xEvent event;
     int idepth, ivisual;
     Bool fOK;
     DepthPtr pDepth;
@@ -828,16 +827,17 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
     }
 
     if (SubSend(pParent)) {
-        memset(&event, 0, sizeof(xEvent));
+        xEvent event = {
+            .u.createNotify.window = wid,
+            .u.createNotify.parent = pParent->drawable.id,
+            .u.createNotify.x = x,
+            .u.createNotify.y = y,
+            .u.createNotify.width = w,
+            .u.createNotify.height = h,
+            .u.createNotify.borderWidth = bw,
+            .u.createNotify.override = pWin->overrideRedirect
+        };
         event.u.u.type = CreateNotify;
-        event.u.createNotify.window = wid;
-        event.u.createNotify.parent = pParent->drawable.id;
-        event.u.createNotify.x = x;
-        event.u.createNotify.y = y;
-        event.u.createNotify.width = w;
-        event.u.createNotify.height = h;
-        event.u.createNotify.borderWidth = bw;
-        event.u.createNotify.override = pWin->overrideRedirect;
         DeliverEvents(pParent, &event, 1, NullWindow);
     }
     return pWin;
@@ -912,7 +912,6 @@ CrushTree(WindowPtr pWin)
 {
     WindowPtr pChild, pSib, pParent;
     UnrealizeWindowProcPtr UnrealizeWindow;
-    xEvent event;
 
     if (!(pChild = pWin->firstChild))
         return;
@@ -925,8 +924,7 @@ CrushTree(WindowPtr pWin)
         while (1) {
             pParent = pChild->parent;
             if (SubStrSend(pChild, pParent)) {
-                memset(&event, 0, sizeof(xEvent));
-                event.u.u.type = DestroyNotify;
+                xEvent event = { .u.u.type = DestroyNotify };
                 event.u.destroyNotify.window = pChild->drawable.id;
                 DeliverEvents(pChild, &event, 1, NullWindow);
             }
@@ -961,7 +959,6 @@ DeleteWindow(pointer value, XID wid)
 {
     WindowPtr pParent;
     WindowPtr pWin = (WindowPtr) value;
-    xEvent event;
 
     UnmapWindow(pWin, FALSE);
 
@@ -969,8 +966,7 @@ DeleteWindow(pointer value, XID wid)
 
     pParent = pWin->parent;
     if (wid && pParent && SubStrSend(pWin, pParent)) {
-        memset(&event, 0, sizeof(xEvent));
-        event.u.u.type = DestroyNotify;
+        xEvent event = { .u.u.type = DestroyNotify };
         event.u.destroyNotify.window = pWin->drawable.id;
         DeliverEvents(pWin, &event, 1, NullWindow);
     }
@@ -1355,11 +1351,13 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
                         CheckWindowOptionalNeed(pChild);
                 }
 
+                xE = (xEvent) {
+                    .u.colormap.window = pWin->drawable.id,
+                    .u.colormap.colormap = cmap,
+                    .u.colormap.new = xTrue,
+                    .u.colormap.state = IsMapInstalled(cmap, pWin)
+                };
                 xE.u.u.type = ColormapNotify;
-                xE.u.colormap.window = pWin->drawable.id;
-                xE.u.colormap.colormap = cmap;
-                xE.u.colormap.new = xTrue;
-                xE.u.colormap.state = IsMapInstalled(cmap, pWin);
                 DeliverEvents(pWin, &xE, 1, NullWindow);
             }
             break;
@@ -1746,12 +1744,12 @@ ResizeChildrenWinSize(WindowPtr pWin, int dx, int dy, int dw, int dh)
             GravityTranslate(cwsx, cwsy, cwsx - dx, cwsy - dy, dw, dh,
                              pSib->winGravity, &cwsx, &cwsy);
             if (cwsx != pSib->origin.x || cwsy != pSib->origin.y) {
-                xEvent event;
-
+                xEvent event = {
+                    .u.gravity.window = pSib->drawable.id,
+                    .u.gravity.x = cwsx - wBorderWidth(pSib),
+                    .u.gravity.y = cwsy - wBorderWidth(pSib)
+                };
                 event.u.u.type = GravityNotify;
-                event.u.gravity.window = pSib->drawable.id;
-                event.u.gravity.x = cwsx - wBorderWidth(pSib);
-                event.u.gravity.y = cwsy - wBorderWidth(pSib);
                 DeliverEvents(pSib, &event, 1, NullWindow);
                 pSib->origin.x = cwsx;
                 pSib->origin.y = cwsy;
@@ -2090,7 +2088,6 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
     unsigned short w = pWin->drawable.width,
         h = pWin->drawable.height, bw = pWin->borderWidth;
     int rc, action, smode = Above;
-    xEvent event;
 
     if ((pWin->drawable.class == InputOnly) &&
         (mask & IllegalInputOnlyConfigureMask))
@@ -2179,30 +2176,25 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
 
     if ((!pWin->overrideRedirect) && (RedirectSend(pParent)
         )) {
-        memset(&event, 0, sizeof(xEvent));
+        xEvent event = {
+            .u.configureRequest.window = pWin->drawable.id,
+            .u.configureRequest.sibling = (mask & CWSibling) ? sibwid : None,
+            .u.configureRequest.x = x,
+            .u.configureRequest.y = y,
+            .u.configureRequest.width = w,
+            .u.configureRequest.height = h,
+            .u.configureRequest.borderWidth = bw,
+            .u.configureRequest.valueMask = mask,
+            .u.configureRequest.parent = pParent->drawable.id
+        };
         event.u.u.type = ConfigureRequest;
-        event.u.configureRequest.window = pWin->drawable.id;
-        if (mask & CWSibling)
-            event.u.configureRequest.sibling = sibwid;
-        else
-            event.u.configureRequest.sibling = None;
-        if (mask & CWStackMode)
-            event.u.u.detail = smode;
-        else
-            event.u.u.detail = Above;
-        event.u.configureRequest.x = x;
-        event.u.configureRequest.y = y;
+        event.u.u.detail = (mask & CWStackMode) ? smode : Above;
 #ifdef PANORAMIX
         if (!noPanoramiXExtension && (!pParent || !pParent->parent)) {
             event.u.configureRequest.x += screenInfo.screens[0]->x;
             event.u.configureRequest.y += screenInfo.screens[0]->y;
         }
 #endif
-        event.u.configureRequest.width = w;
-        event.u.configureRequest.height = h;
-        event.u.configureRequest.borderWidth = bw;
-        event.u.configureRequest.valueMask = mask;
-        event.u.configureRequest.parent = pParent->drawable.id;
         if (MaybeDeliverEventsToClient(pParent, &event, 1,
                                        SubstructureRedirectMask, client) == 1)
             return Success;
@@ -2213,13 +2205,12 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
 
         if (size_change &&
             ((pWin->eventMask | wOtherEventMasks(pWin)) & ResizeRedirectMask)) {
-            xEvent eventT;
-
-            memset(&eventT, 0, sizeof(xEvent));
+            xEvent eventT = {
+                .u.resizeRequest.window = pWin->drawable.id,
+                .u.resizeRequest.width = w,
+                .u.resizeRequest.height = h
+            };
             eventT.u.u.type = ResizeRequest;
-            eventT.u.resizeRequest.window = pWin->drawable.id;
-            eventT.u.resizeRequest.width = w;
-            eventT.u.resizeRequest.height = h;
             if (MaybeDeliverEventsToClient(pWin, &eventT, 1,
                                            ResizeRedirectMask, client) == 1) {
                 /* if event is delivered, leave the actual size alone. */
@@ -2270,25 +2261,23 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
     }
 
     if (SubStrSend(pWin, pParent)) {
-        memset(&event, 0, sizeof(xEvent));
+        xEvent event = {
+            .u.configureNotify.window = pWin->drawable.id,
+            .u.configureNotify.aboveSibling = pSib ? pSib->drawable.id : None,
+            .u.configureNotify.x = x,
+            .u.configureNotify.y = y,
+            .u.configureNotify.width = w,
+            .u.configureNotify.height = h,
+            .u.configureNotify.borderWidth = bw,
+            .u.configureNotify.override = pWin->overrideRedirect
+        };
         event.u.u.type = ConfigureNotify;
-        event.u.configureNotify.window = pWin->drawable.id;
-        if (pSib)
-            event.u.configureNotify.aboveSibling = pSib->drawable.id;
-        else
-            event.u.configureNotify.aboveSibling = None;
-        event.u.configureNotify.x = x;
-        event.u.configureNotify.y = y;
 #ifdef PANORAMIX
         if (!noPanoramiXExtension && (!pParent || !pParent->parent)) {
             event.u.configureNotify.x += screenInfo.screens[0]->x;
             event.u.configureNotify.y += screenInfo.screens[0]->y;
         }
 #endif
-        event.u.configureNotify.width = w;
-        event.u.configureNotify.height = h;
-        event.u.configureNotify.borderWidth = bw;
-        event.u.configureNotify.override = pWin->overrideRedirect;
         DeliverEvents(pWin, &event, 1, NullWindow);
     }
     if (mask & CWBorderWidth) {
@@ -2361,13 +2350,13 @@ CirculateWindow(WindowPtr pParent, int direction, ClientPtr client)
             return Success;
     }
 
-    event.u.circulate.window = pWin->drawable.id;
-    event.u.circulate.parent = pParent->drawable.id;
-    event.u.circulate.event = pParent->drawable.id;
-    if (direction == RaiseLowest)
-        event.u.circulate.place = PlaceOnTop;
-    else
-        event.u.circulate.place = PlaceOnBottom;
+    event = (xEvent) {
+        .u.circulate.window = pWin->drawable.id,
+        .u.circulate.parent = pParent->drawable.id,
+        .u.circulate.event = pParent->drawable.id,
+        .u.circulate.place = (direction == RaiseLowest) ?
+                              PlaceOnTop : PlaceOnBottom,
+    };
 
     if (RedirectSend(pParent)) {
         event.u.u.type = CirculateRequest;
@@ -2420,19 +2409,20 @@ ReparentWindow(WindowPtr pWin, WindowPtr pParent,
     if (WasMapped)
         UnmapWindow(pWin, FALSE);
 
-    memset(&event, 0, sizeof(xEvent));
+    event = (xEvent) {
+        .u.reparent.window = pWin->drawable.id,
+        .u.reparent.parent = pParent->drawable.id,
+        .u.reparent.x = x,
+        .u.reparent.y = y,
+        .u.reparent.override = pWin->overrideRedirect
+    };
     event.u.u.type = ReparentNotify;
-    event.u.reparent.window = pWin->drawable.id;
-    event.u.reparent.parent = pParent->drawable.id;
-    event.u.reparent.x = x;
-    event.u.reparent.y = y;
 #ifdef PANORAMIX
     if (!noPanoramiXExtension && !pParent->parent) {
         event.u.reparent.x += screenInfo.screens[0]->x;
         event.u.reparent.y += screenInfo.screens[0]->y;
     }
 #endif
-    event.u.reparent.override = pWin->overrideRedirect;
     DeliverEvents(pWin, &event, 1, pParent);
 
     /* take out of sibling chain */
@@ -2568,15 +2558,15 @@ MapWindow(WindowPtr pWin, ClientPtr client)
 
     pScreen = pWin->drawable.pScreen;
     if ((pParent = pWin->parent)) {
-        xEvent event;
         Bool anyMarked;
 
         if ((!pWin->overrideRedirect) && (RedirectSend(pParent)
             )) {
-            memset(&event, 0, sizeof(xEvent));
+            xEvent event = {
+                .u.mapRequest.window = pWin->drawable.id,
+                .u.mapRequest.parent = pParent->drawable.id
+            };
             event.u.u.type = MapRequest;
-            event.u.mapRequest.window = pWin->drawable.id;
-            event.u.mapRequest.parent = pParent->drawable.id;
 
             if (MaybeDeliverEventsToClient(pParent, &event, 1,
                                            SubstructureRedirectMask,
@@ -2586,10 +2576,11 @@ MapWindow(WindowPtr pWin, ClientPtr client)
 
         pWin->mapped = TRUE;
         if (SubStrSend(pWin, pParent) && MapUnmapEventsEnabled(pWin)) {
-            memset(&event, 0, sizeof(xEvent));
+            xEvent event = {
+                .u.mapNotify.window = pWin->drawable.id,
+                .u.mapNotify.override = pWin->overrideRedirect,
+            };
             event.u.u.type = MapNotify;
-            event.u.mapNotify.window = pWin->drawable.id;
-            event.u.mapNotify.override = pWin->overrideRedirect;
             DeliverEvents(pWin, &event, 1, NullWindow);
         }
 
@@ -2644,7 +2635,6 @@ MapSubwindows(WindowPtr pParent, ClientPtr client)
     ScreenPtr pScreen;
     Mask parentRedirect;
     Mask parentNotify;
-    xEvent event;
     Bool anyMarked;
     WindowPtr pLayerWin;
 
@@ -2655,10 +2645,11 @@ MapSubwindows(WindowPtr pParent, ClientPtr client)
     for (pWin = pParent->firstChild; pWin; pWin = pWin->nextSib) {
         if (!pWin->mapped) {
             if (parentRedirect && !pWin->overrideRedirect) {
-                memset(&event, 0, sizeof(xEvent));
+                xEvent event = {
+                    .u.mapRequest.window = pWin->drawable.id,
+                    .u.mapRequest.parent = pParent->drawable.id
+                };
                 event.u.u.type = MapRequest;
-                event.u.mapRequest.window = pWin->drawable.id;
-                event.u.mapRequest.parent = pParent->drawable.id;
 
                 if (MaybeDeliverEventsToClient(pParent, &event, 1,
                                                SubstructureRedirectMask,
@@ -2668,10 +2659,11 @@ MapSubwindows(WindowPtr pParent, ClientPtr client)
 
             pWin->mapped = TRUE;
             if (parentNotify || StrSend(pWin)) {
-                memset(&event, 0, sizeof(xEvent));
+                xEvent event = {
+                    .u.mapNotify.window = pWin->drawable.id,
+                    .u.mapNotify.override = pWin->overrideRedirect
+                };
                 event.u.u.type = MapNotify;
-                event.u.mapNotify.window = pWin->drawable.id;
-                event.u.mapNotify.override = pWin->overrideRedirect;
                 DeliverEvents(pWin, &event, 1, NullWindow);
             }
 
@@ -2765,7 +2757,6 @@ int
 UnmapWindow(WindowPtr pWin, Bool fromConfigure)
 {
     WindowPtr pParent;
-    xEvent event;
     Bool wasRealized = (Bool) pWin->realized;
     Bool wasViewable = (Bool) pWin->viewable;
     ScreenPtr pScreen = pWin->drawable.pScreen;
@@ -2774,10 +2765,11 @@ UnmapWindow(WindowPtr pWin, Bool fromConfigure)
     if ((!pWin->mapped) || (!(pParent = pWin->parent)))
         return Success;
     if (SubStrSend(pWin, pParent) && MapUnmapEventsEnabled(pWin)) {
-        memset(&event, 0, sizeof(xEvent));
+        xEvent event = {
+            .u.unmapNotify.window = pWin->drawable.id,
+            .u.unmapNotify.fromConfigure = fromConfigure
+        };
         event.u.u.type = UnmapNotify;
-        event.u.unmapNotify.window = pWin->drawable.id;
-        event.u.unmapNotify.fromConfigure = fromConfigure;
         DeliverEvents(pWin, &event, 1, NullWindow);
     }
     if (wasViewable && !fromConfigure) {
@@ -2813,7 +2805,6 @@ void
 UnmapSubwindows(WindowPtr pWin)
 {
     WindowPtr pChild, pHead;
-    xEvent event;
     Bool wasRealized = (Bool) pWin->realized;
     Bool wasViewable = (Bool) pWin->viewable;
     Bool anyMarked = FALSE;
@@ -2832,9 +2823,11 @@ UnmapSubwindows(WindowPtr pWin)
     for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib) {
         if (pChild->mapped) {
             if (parentNotify || StrSend(pChild)) {
+                xEvent event = {
+                    .u.unmapNotify.window = pChild->drawable.id,
+                    .u.unmapNotify.fromConfigure = xFalse
+                };
                 event.u.u.type = UnmapNotify;
-                event.u.unmapNotify.window = pChild->drawable.id;
-                event.u.unmapNotify.fromConfigure = xFalse;
                 DeliverEvents(pChild, &event, 1, NullWindow);
             }
             if (pChild->viewable) {
@@ -3028,10 +3021,11 @@ SendVisibilityNotify(WindowPtr pWin)
     }
 #endif
 
-    memset(&event, 0, sizeof(xEvent));
+    event = (xEvent) {
+        .u.visibility.window = pWin->drawable.id,
+        .u.visibility.state = visibility
+    };
     event.u.u.type = VisibilityNotify;
-    event.u.visibility.window = pWin->drawable.id;
-    event.u.visibility.state = visibility;
     DeliverEvents(pWin, &event, 1, NullWindow);
 }
 
diff --git a/mi/miexpose.c b/mi/miexpose.c
index 2dc465d..8b7c93f 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -349,13 +349,12 @@ miSendGraphicsExpose(ClientPtr client, RegionPtr pRgn, XID drawable,
         free(pEvent);
     }
     else {
-        xEvent event;
-
-        memset(&event, 0, sizeof(xEvent));
+        xEvent event = {
+            .u.noExposure.drawable = drawable,
+            .u.noExposure.majorEvent = major,
+            .u.noExposure.minorEvent = minor
+        };
         event.u.u.type = NoExpose;
-        event.u.noExposure.drawable = drawable;
-        event.u.noExposure.majorEvent = major;
-        event.u.noExposure.minorEvent = minor;
         WriteEventsToClient(client, 1, &event);
     }
 }
commit 483266a583b0fd8a552303f318a71502ce3ff1d2
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in xf86 extension Replies
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 347282c..9b7ec14 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -75,14 +75,15 @@ XDGAResetProc(ExtensionEntry * extEntry)
 static int
 ProcXDGAQueryVersion(ClientPtr client)
 {
-    xXDGAQueryVersionReply rep;
+    xXDGAQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_XDGA_MAJOR_VERSION,
+        .minorVersion = SERVER_XDGA_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xXDGAQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_XDGA_MAJOR_VERSION;
-    rep.minorVersion = SERVER_XDGA_MINOR_VERSION;
 
     WriteToClient(client, sizeof(xXDGAQueryVersionReply), &rep);
     return Success;
@@ -92,7 +93,11 @@ static int
 ProcXDGAOpenFramebuffer(ClientPtr client)
 {
     REQUEST(xXDGAOpenFramebufferReq);
-    xXDGAOpenFramebufferReply rep;
+    xXDGAOpenFramebufferReply rep = {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence
+    };
     char *deviceName;
     int nameSize;
 
@@ -104,10 +109,6 @@ ProcXDGAOpenFramebuffer(ClientPtr client)
     if (!DGAAvailable(stuff->screen))
         return DGAErrorBase + XF86DGANoDirectVideoMode;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     if (!DGAOpenFramebuffer(stuff->screen, &deviceName,
                             (unsigned char **) (&rep.mem1),
                             (int *) &rep.size, (int *) &rep.offset,
@@ -149,7 +150,12 @@ ProcXDGAQueryModes(ClientPtr client)
     int i, num, size;
 
     REQUEST(xXDGAQueryModesReq);
-    xXDGAQueryModesReply rep;
+    xXDGAQueryModesReply rep = {
+        .type = X_Reply,
+        .length = 0,
+        .number = 0,
+        .sequenceNumber = client->sequence
+    };
     xXDGAModeInfo info;
     XDGAModePtr mode;
 
@@ -158,11 +164,6 @@ ProcXDGAQueryModes(ClientPtr client)
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.number = 0;
-    rep.sequenceNumber = client->sequence;
-
     if (!DGAAvailable(stuff->screen)) {
         rep.number = 0;
         rep.length = 0;
@@ -262,7 +263,13 @@ static int
 ProcXDGASetMode(ClientPtr client)
 {
     REQUEST(xXDGASetModeReq);
-    xXDGASetModeReply rep;
+    xXDGASetModeReply rep = {
+        .type = X_Reply,
+        .length = 0,
+        .offset = 0,
+        .flags = 0,
+        .sequenceNumber = client->sequence
+    };
     XDGAModeRec mode;
     xXDGAModeInfo info;
     PixmapPtr pPix;
@@ -275,12 +282,6 @@ ProcXDGASetMode(ClientPtr client)
         return BadValue;
     owner = DGA_GETCLIENT(stuff->screen);
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.offset = 0;
-    rep.flags = 0;
-    rep.sequenceNumber = client->sequence;
-
     if (!DGAAvailable(stuff->screen))
         return DGAErrorBase + XF86DGANoDirectVideoMode;
 
@@ -482,7 +483,11 @@ static int
 ProcXDGAGetViewportStatus(ClientPtr client)
 {
     REQUEST(xXDGAGetViewportStatusReq);
-    xXDGAGetViewportStatusReply rep;
+    xXDGAGetViewportStatusReply rep = {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence
+    };
 
     REQUEST_SIZE_MATCH(xXDGAGetViewportStatusReq);
 
@@ -492,10 +497,6 @@ ProcXDGAGetViewportStatus(ClientPtr client)
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     rep.status = DGAGetViewportStatus(stuff->screen);
 
     WriteToClient(client, sizeof(xXDGAGetViewportStatusReply), &rep);
@@ -506,7 +507,11 @@ static int
 ProcXDGASync(ClientPtr client)
 {
     REQUEST(xXDGASyncReq);
-    xXDGASyncReply rep;
+    xXDGASyncReply rep = {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence
+    };
 
     REQUEST_SIZE_MATCH(xXDGASyncReq);
 
@@ -516,10 +521,6 @@ ProcXDGASync(ClientPtr client)
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     DGASync(stuff->screen);
 
     WriteToClient(client, sizeof(xXDGASyncReply), &rep);
@@ -562,18 +563,19 @@ ProcXDGAChangePixmapMode(ClientPtr client)
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     x = stuff->x;
     y = stuff->y;
 
     if (!DGAChangePixmapMode(stuff->screen, &x, &y, stuff->flags))
         return BadMatch;
 
-    rep.x = x;
-    rep.y = y;
+    rep = (xXDGAChangePixmapModeReply) {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence,
+        .x = x,
+        .y = y
+    };
     WriteToClient(client, sizeof(xXDGAChangePixmapModeReply), &rep);
 
     return Success;
@@ -616,7 +618,11 @@ static int
 ProcXF86DGAGetVideoLL(ClientPtr client)
 {
     REQUEST(xXF86DGAGetVideoLLReq);
-    xXF86DGAGetVideoLLReply rep;
+    xXF86DGAGetVideoLLReply rep = {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence
+    };
     XDGAModeRec mode;
     int num, offset, flags;
     char *name;
@@ -626,10 +632,6 @@ ProcXF86DGAGetVideoLL(ClientPtr client)
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     if (!DGAAvailable(stuff->screen))
         return DGAErrorBase + XF86DGANoDirectVideoMode;
 
@@ -726,10 +728,6 @@ ProcXF86DGAGetViewPortSize(ClientPtr client)
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     if (!DGAAvailable(stuff->screen))
         return DGAErrorBase + XF86DGANoDirectVideoMode;
 
@@ -738,8 +736,13 @@ ProcXF86DGAGetViewPortSize(ClientPtr client)
 
     DGAGetModeInfo(stuff->screen, &mode, num);
 
-    rep.width = mode.viewportWidth;
-    rep.height = mode.viewportHeight;
+    rep = (xXF86DGAGetViewPortSizeReply) {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence,
+        .width = mode.viewportWidth,
+        .height = mode.viewportHeight
+    };
 
     WriteToClient(client, SIZEOF(xXF86DGAGetViewPortSizeReply), &rep);
     return Success;
@@ -775,18 +778,18 @@ static int
 ProcXF86DGAGetVidPage(ClientPtr client)
 {
     REQUEST(xXF86DGAGetVidPageReq);
-    xXF86DGAGetVidPageReply rep;
+    xXF86DGAGetVidPageReply rep = {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence,
+        .vpage = 0               /* silently fail */
+    };
 
     REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
 
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.vpage = 0;              /* silently fail */
-
     WriteToClient(client, SIZEOF(xXF86DGAGetVidPageReply), &rep);
     return Success;
 }
@@ -840,18 +843,18 @@ static int
 ProcXF86DGAQueryDirectVideo(ClientPtr client)
 {
     REQUEST(xXF86DGAQueryDirectVideoReq);
-    xXF86DGAQueryDirectVideoReply rep;
+    xXF86DGAQueryDirectVideoReply rep = {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence,
+        .flags = 0
+    };
 
     REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
 
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.flags = 0;
-
     if (DGAAvailable(stuff->screen))
         rep.flags = XF86DGADirectPresent;
 
@@ -863,7 +866,12 @@ static int
 ProcXF86DGAViewPortChanged(ClientPtr client)
 {
     REQUEST(xXF86DGAViewPortChangedReq);
-    xXF86DGAViewPortChangedReply rep;
+    xXF86DGAViewPortChangedReply rep = {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence,
+        .result = 1
+    };
 
     REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
 
@@ -876,11 +884,6 @@ ProcXF86DGAViewPortChanged(ClientPtr client)
     if (!DGAActive(stuff->screen))
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.result = 1;
-
     WriteToClient(client, SIZEOF(xXF86DGAViewPortChangedReply), &rep);
     return Success;
 }
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 0435cb6..455ff34 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -282,16 +282,18 @@ SXF86VidModeNotifyEvent(xXF86VidModeNotifyEvent * from,
 static int
 ProcXF86VidModeQueryVersion(ClientPtr client)
 {
-    xXF86VidModeQueryVersionReply rep;
+    xXF86VidModeQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_XF86VIDMODE_MAJOR_VERSION,
+        .minorVersion = SERVER_XF86VIDMODE_MINOR_VERSION
+    };
 
     DEBUG_P("XF86VidModeQueryVersion");
 
     REQUEST_SIZE_MATCH(xXF86VidModeQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_XF86VIDMODE_MAJOR_VERSION;
-    rep.minorVersion = SERVER_XF86VIDMODE_MINOR_VERSION;
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -306,8 +308,10 @@ static int
 ProcXF86VidModeGetModeLine(ClientPtr client)
 {
     REQUEST(xXF86VidModeGetModeLineReq);
-    xXF86VidModeGetModeLineReply rep;
-    xXF86OldVidModeGetModeLineReply oldrep;
+    xXF86VidModeGetModeLineReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence
+    };
     pointer mode;
     int dotClock;
     int ver;
@@ -316,7 +320,7 @@ ProcXF86VidModeGetModeLine(ClientPtr client)
 
     ver = ClientMajorVersion(client);
     REQUEST_SIZE_MATCH(xXF86VidModeGetModeLineReq);
-    rep.type = X_Reply;
+
     if (ver < 2) {
         rep.length = bytes_to_int32(SIZEOF(xXF86OldVidModeGetModeLineReply) -
                                     SIZEOF(xGenericReply));
@@ -325,7 +329,6 @@ ProcXF86VidModeGetModeLine(ClientPtr client)
         rep.length = bytes_to_int32(SIZEOF(xXF86VidModeGetModeLineReply) -
                                     SIZEOF(xGenericReply));
     }
-    rep.sequenceNumber = client->sequence;
 
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
@@ -379,20 +382,22 @@ ProcXF86VidModeGetModeLine(ClientPtr client)
         swapl(&rep.privsize);
     }
     if (ver < 2) {
-        oldrep.type = rep.type;
-        oldrep.sequenceNumber = rep.sequenceNumber;
-        oldrep.length = rep.length;
-        oldrep.dotclock = rep.dotclock;
-        oldrep.hdisplay = rep.hdisplay;
-        oldrep.hsyncstart = rep.hsyncstart;
-        oldrep.hsyncend = rep.hsyncend;
-        oldrep.htotal = rep.htotal;
-        oldrep.vdisplay = rep.vdisplay;
-        oldrep.vsyncstart = rep.vsyncstart;
-        oldrep.vsyncend = rep.vsyncend;
-        oldrep.vtotal = rep.vtotal;
-        oldrep.flags = rep.flags;
-        oldrep.privsize = rep.privsize;
+        xXF86OldVidModeGetModeLineReply oldrep = {
+            .type = rep.type,
+            .sequenceNumber = rep.sequenceNumber,
+            .length = rep.length,
+            .dotclock = rep.dotclock,
+            .hdisplay = rep.hdisplay,
+            .hsyncstart = rep.hsyncstart,
+            .hsyncend = rep.hsyncend,
+            .htotal = rep.htotal,
+            .vdisplay = rep.vdisplay,
+            .vsyncstart = rep.vsyncstart,
+            .vsyncend = rep.vsyncend,
+            .vtotal = rep.vtotal,
+            .flags = rep.flags,
+            .privsize = rep.privsize
+        };
         WriteToClient(client, sizeof(xXF86OldVidModeGetModeLineReply), &oldrep);
     }
     else {
@@ -406,8 +411,6 @@ ProcXF86VidModeGetAllModeLines(ClientPtr client)
 {
     REQUEST(xXF86VidModeGetAllModeLinesReq);
     xXF86VidModeGetAllModeLinesReply rep;
-    xXF86VidModeModeInfo mdinf;
-    xXF86OldVidModeModeInfo oldmdinf;
     pointer mode;
     int modecount, dotClock;
     int ver;
@@ -428,16 +431,18 @@ ProcXF86VidModeGetAllModeLines(ClientPtr client)
     if (!VidModeGetFirstModeline(stuff->screen, &mode, &dotClock))
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = SIZEOF(xXF86VidModeGetAllModeLinesReply) -
-        SIZEOF(xGenericReply);
+    rep = (xXF86VidModeGetAllModeLinesReply) {
+        .type = X_Reply,
+        .length = SIZEOF(xXF86VidModeGetAllModeLinesReply) -
+            SIZEOF(xGenericReply),
+        .sequenceNumber = client->sequence,
+        .modecount = modecount
+    };
     if (ver < 2)
         rep.length += modecount * sizeof(xXF86OldVidModeModeInfo);
     else
         rep.length += modecount * sizeof(xXF86VidModeModeInfo);
     rep.length >>= 2;
-    rep.sequenceNumber = client->sequence;
-    rep.modecount = modecount;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -446,18 +451,20 @@ ProcXF86VidModeGetAllModeLines(ClientPtr client)
     WriteToClient(client, sizeof(xXF86VidModeGetAllModeLinesReply), &rep);
 
     do {
-        mdinf.dotclock = dotClock;
-        mdinf.hdisplay = VidModeGetModeValue(mode, VIDMODE_H_DISPLAY);
-        mdinf.hsyncstart = VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART);
-        mdinf.hsyncend = VidModeGetModeValue(mode, VIDMODE_H_SYNCEND);
-        mdinf.htotal = VidModeGetModeValue(mode, VIDMODE_H_TOTAL);
-        mdinf.hskew = VidModeGetModeValue(mode, VIDMODE_H_SKEW);
-        mdinf.vdisplay = VidModeGetModeValue(mode, VIDMODE_V_DISPLAY);
-        mdinf.vsyncstart = VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART);
-        mdinf.vsyncend = VidModeGetModeValue(mode, VIDMODE_V_SYNCEND);
-        mdinf.vtotal = VidModeGetModeValue(mode, VIDMODE_V_TOTAL);
-        mdinf.flags = VidModeGetModeValue(mode, VIDMODE_FLAGS);
-        mdinf.privsize = 0;
+        xXF86VidModeModeInfo mdinf = {
+            .dotclock = dotClock,
+            .hdisplay = VidModeGetModeValue(mode, VIDMODE_H_DISPLAY),
+            .hsyncstart = VidModeGetModeValue(mode, VIDMODE_H_SYNCSTART),
+            .hsyncend = VidModeGetModeValue(mode, VIDMODE_H_SYNCEND),
+            .htotal = VidModeGetModeValue(mode, VIDMODE_H_TOTAL),
+            .hskew = VidModeGetModeValue(mode, VIDMODE_H_SKEW),
+            .vdisplay = VidModeGetModeValue(mode, VIDMODE_V_DISPLAY),
+            .vsyncstart = VidModeGetModeValue(mode, VIDMODE_V_SYNCSTART),
+            .vsyncend = VidModeGetModeValue(mode, VIDMODE_V_SYNCEND),
+            .vtotal = VidModeGetModeValue(mode, VIDMODE_V_TOTAL),
+            .flags = VidModeGetModeValue(mode, VIDMODE_FLAGS),
+            .privsize = 0
+        };
         if (client->swapped) {
             swapl(&mdinf.dotclock);
             swaps(&mdinf.hdisplay);
@@ -473,17 +480,19 @@ ProcXF86VidModeGetAllModeLines(ClientPtr client)
             swapl(&mdinf.privsize);
         }
         if (ver < 2) {
-            oldmdinf.dotclock = mdinf.dotclock;
-            oldmdinf.hdisplay = mdinf.hdisplay;
-            oldmdinf.hsyncstart = mdinf.hsyncstart;
-            oldmdinf.hsyncend = mdinf.hsyncend;
-            oldmdinf.htotal = mdinf.htotal;
-            oldmdinf.vdisplay = mdinf.vdisplay;
-            oldmdinf.vsyncstart = mdinf.vsyncstart;
-            oldmdinf.vsyncend = mdinf.vsyncend;
-            oldmdinf.vtotal = mdinf.vtotal;
-            oldmdinf.flags = mdinf.flags;
-            oldmdinf.privsize = mdinf.privsize;
+            xXF86OldVidModeModeInfo oldmdinf = {
+                .dotclock = mdinf.dotclock,
+                .hdisplay = mdinf.hdisplay,
+                .hsyncstart = mdinf.hsyncstart,
+                .hsyncend = mdinf.hsyncend,
+                .htotal = mdinf.htotal,
+                .vdisplay = mdinf.vdisplay,
+                .vsyncstart = mdinf.vsyncstart,
+                .vsyncend = mdinf.vsyncend,
+                .vtotal = mdinf.vtotal,
+                .flags = mdinf.flags,
+                .privsize = mdinf.privsize
+            };
             WriteToClient(client, sizeof(xXF86OldVidModeModeInfo), &oldmdinf);
         }
         else {
@@ -1027,11 +1036,13 @@ ProcXF86VidModeValidateModeLine(ClientPtr client)
  status_reply:
     free(modetmp);
 
-    rep.type = X_Reply;
-    rep.length = bytes_to_int32(SIZEOF(xXF86VidModeValidateModeLineReply)
-                                - SIZEOF(xGenericReply));
-    rep.sequenceNumber = client->sequence;
-    rep.status = status;
+    rep = (xXF86VidModeValidateModeLineReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(SIZEOF(xXF86VidModeValidateModeLineReply)
+                                 - SIZEOF(xGenericReply)),
+        .status = status
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -1186,7 +1197,10 @@ static int
 ProcXF86VidModeGetMonitor(ClientPtr client)
 {
     REQUEST(xXF86VidModeGetMonitorReq);
-    xXF86VidModeGetMonitorReply rep;
+    xXF86VidModeGetMonitorReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence
+    };
     CARD32 *hsyncdata, *vsyncdata;
     int i, nHsync, nVrefresh;
     pointer monitor;
@@ -1204,7 +1218,6 @@ ProcXF86VidModeGetMonitor(ClientPtr client)
     nHsync = VidModeGetMonitorValue(monitor, VIDMODE_MON_NHSYNC, 0).i;
     nVrefresh = VidModeGetMonitorValue(monitor, VIDMODE_MON_NVREFRESH, 0).i;
 
-    rep.type = X_Reply;
     if ((char *) (VidModeGetMonitorValue(monitor, VIDMODE_MON_VENDOR, 0)).ptr)
         rep.vendorLength = strlen((char *) (VidModeGetMonitorValue(monitor,
                                                                    VIDMODE_MON_VENDOR,
@@ -1223,7 +1236,6 @@ ProcXF86VidModeGetMonitor(ClientPtr client)
                                                 nVrefresh) * sizeof(CARD32) +
                        pad_to_int32(rep.vendorLength) +
                        pad_to_int32(rep.modelLength));
-    rep.sequenceNumber = client->sequence;
     rep.nhsync = nHsync;
     rep.nvsync = nVrefresh;
     hsyncdata = malloc(nHsync * sizeof(CARD32));
@@ -1289,13 +1301,15 @@ ProcXF86VidModeGetViewPort(ClientPtr client)
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     VidModeGetViewPort(stuff->screen, &x, &y);
-    rep.x = x;
-    rep.y = y;
+
+    rep = (xXF86VidModeGetViewPortReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .x = x,
+        .y = y
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -1345,13 +1359,15 @@ ProcXF86VidModeGetDotClocks(ClientPtr client)
 
     numClocks = VidModeGetNumOfClocks(stuff->screen, &ClockProg);
 
-    rep.type = X_Reply;
-    rep.length = bytes_to_int32(SIZEOF(xXF86VidModeGetDotClocksReply)
-                                - SIZEOF(xGenericReply) + numClocks);
-    rep.sequenceNumber = client->sequence;
-    rep.clocks = numClocks;
-    rep.maxclocks = MAXCLOCKS;
-    rep.flags = 0;
+    rep = (xXF86VidModeGetDotClocksReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(SIZEOF(xXF86VidModeGetDotClocksReply)
+                                 - SIZEOF(xGenericReply) + numClocks),
+        .clocks = numClocks,
+        .maxclocks = MAXCLOCKS,
+        .flags = 0
+    };
 
     if (!ClockProg) {
         Clocks = calloc(numClocks, sizeof(int));
@@ -1423,14 +1439,16 @@ ProcXF86VidModeGetGamma(ClientPtr client)
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
     if (!VidModeGetGamma(stuff->screen, &red, &green, &blue))
         return BadValue;
-    rep.red = (CARD32) (red * 10000.);
-    rep.green = (CARD32) (green * 10000.);
-    rep.blue = (CARD32) (blue * 10000.);
+    rep = (xXF86VidModeGetGammaReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .red = (CARD32) (red * 10000.),
+        .green = (CARD32) (green * 10000.),
+        .blue = (CARD32) (blue * 10000.)
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -1502,10 +1520,12 @@ ProcXF86VidModeGetGammaRamp(ClientPtr client)
             return BadValue;
         }
     }
-    rep.type = X_Reply;
-    rep.length = (length >> 1) * 3;
-    rep.sequenceNumber = client->sequence;
-    rep.size = stuff->size;
+    rep = (xXF86VidModeGetGammaRampReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = (length >> 1) * 3,
+        .size = stuff->size
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -1534,10 +1554,12 @@ ProcXF86VidModeGetGammaRampSize(ClientPtr client)
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.size = VidModeGetGammaRampSize(stuff->screen);
+    rep = (xXF86VidModeGetGammaRampSizeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .size = VidModeGetGammaRampSize(stuff->screen)
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -1551,7 +1573,12 @@ ProcXF86VidModeGetGammaRampSize(ClientPtr client)
 static int
 ProcXF86VidModeGetPermissions(ClientPtr client)
 {
-    xXF86VidModeGetPermissionsReply rep;
+    xXF86VidModeGetPermissionsReply rep =  {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .permissions = XF86VM_READ_PERMISSION
+    };
 
     REQUEST(xXF86VidModeGetPermissionsReq);
 
@@ -1560,10 +1587,6 @@ ProcXF86VidModeGetPermissions(ClientPtr client)
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.permissions = XF86VM_READ_PERMISSION;
     if (xf86GetVidModeEnabled() &&
         (xf86GetVidModeAllowNonLocal() || LocalClient(client))) {
         rep.permissions |= XF86VM_WRITE_PERMISSION;
diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
index 43504b7..310bb5e 100644
--- a/hw/xfree86/dri/xf86dri.c
+++ b/hw/xfree86/dri/xf86dri.c
@@ -78,15 +78,16 @@ XF86DRIResetProc(ExtensionEntry * extEntry)
 static int
 ProcXF86DRIQueryVersion(register ClientPtr client)
 {
-    xXF86DRIQueryVersionReply rep;
+    xXF86DRIQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_XF86DRI_MAJOR_VERSION,
+        .minorVersion = SERVER_XF86DRI_MINOR_VERSION,
+        .patchVersion = SERVER_XF86DRI_PATCH_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xXF86DRIQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_XF86DRI_MAJOR_VERSION;
-    rep.minorVersion = SERVER_XF86DRI_MINOR_VERSION;
-    rep.patchVersion = SERVER_XF86DRI_PATCH_VERSION;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -111,18 +112,20 @@ ProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     if (!DRIQueryDirectRenderingCapable(screenInfo.screens[stuff->screen],
                                         &isCapable)) {
         return BadValue;
     }
-    rep.isCapable = isCapable;
 
     if (!LocalClient(client) || client->swapped)
-        rep.isCapable = 0;
+        isCapable = 0;
+
+    rep = (xXF86DRIQueryDirectRenderingCapableReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .isCapable = isCapable
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -158,20 +161,21 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
     if (busIdString)
         busIdStringLength = strlen(busIdString);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.busIdStringLength = busIdStringLength;
-    rep.length =
-        bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) -
-                       SIZEOF(xGenericReply) +
-                       pad_to_int32(rep.busIdStringLength));
+    rep = (xXF86DRIOpenConnectionReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) -
+                                 SIZEOF(xGenericReply) +
+                                 pad_to_int32(busIdStringLength)),
+        .busIdStringLength = busIdStringLength,
 
-    rep.hSAREALow = (CARD32) (hSAREA & 0xffffffff);
+        .hSAREALow = (CARD32) (hSAREA & 0xffffffff),
 #if defined(LONG64) && !defined(__linux__)
-    rep.hSAREAHigh = (CARD32) (hSAREA >> 32);
+        .hSAREAHigh = (CARD32) (hSAREA >> 32),
 #else
-    rep.hSAREAHigh = 0;
+        .hSAREAHigh = 0
 #endif
+    };
 
     WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), &rep);
     if (busIdStringLength)
@@ -182,7 +186,12 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
 static int
 ProcXF86DRIAuthConnection(register ClientPtr client)
 {
-    xXF86DRIAuthConnectionReply rep;
+    xXF86DRIAuthConnectionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .authenticated = 1
+    };
 
     REQUEST(xXF86DRIAuthConnectionReq);
     REQUEST_SIZE_MATCH(xXF86DRIAuthConnectionReq);
@@ -191,11 +200,6 @@ ProcXF86DRIAuthConnection(register ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.authenticated = 1;
-
     if (!DRIAuthConnection(screenInfo.screens[stuff->screen], stuff->magic)) {
         ErrorF("Failed to authenticate %lu\n", (unsigned long) stuff->magic);
         rep.authenticated = 0;
@@ -222,7 +226,11 @@ ProcXF86DRICloseConnection(register ClientPtr client)
 static int
 ProcXF86DRIGetClientDriverName(register ClientPtr client)
 {
-    xXF86DRIGetClientDriverNameReply rep;
+    xXF86DRIGetClientDriverNameReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .clientDriverNameLength = 0
+    };
     char *clientDriverName;
 
     REQUEST(xXF86DRIGetClientDriverNameReq);
@@ -238,9 +246,6 @@ ProcXF86DRIGetClientDriverName(register ClientPtr client)
                            (int *) &rep.ddxDriverPatchVersion,
                            &clientDriverName);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.clientDriverNameLength = 0;
     if (clientDriverName)
         rep.clientDriverNameLength = strlen(clientDriverName);
     rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetClientDriverNameReply) -
@@ -256,7 +261,11 @@ ProcXF86DRIGetClientDriverName(register ClientPtr client)
 static int
 ProcXF86DRICreateContext(register ClientPtr client)
 {
-    xXF86DRICreateContextReply rep;
+    xXF86DRICreateContextReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     ScreenPtr pScreen;
 
     REQUEST(xXF86DRICreateContextReq);
@@ -266,10 +275,6 @@ ProcXF86DRICreateContext(register ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     pScreen = screenInfo.screens[stuff->screen];
 
     if (!DRICreateContext(pScreen,
@@ -302,7 +307,11 @@ ProcXF86DRIDestroyContext(register ClientPtr client)
 static int
 ProcXF86DRICreateDrawable(ClientPtr client)
 {
-    xXF86DRICreateDrawableReply rep;
+    xXF86DRICreateDrawableReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     DrawablePtr pDrawable;
     int rc;
 
@@ -313,10 +322,6 @@ ProcXF86DRICreateDrawable(ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
                            DixReadAccess);
     if (rc != Success)
@@ -361,7 +366,11 @@ ProcXF86DRIDestroyDrawable(register ClientPtr client)
 static int
 ProcXF86DRIGetDrawableInfo(register ClientPtr client)
 {
-    xXF86DRIGetDrawableInfoReply rep;
+    xXF86DRIGetDrawableInfoReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     DrawablePtr pDrawable;
     int X, Y, W, H;
     drm_clip_rect_t *pClipRects, *pClippedRects;
@@ -375,10 +384,6 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
                            DixReadAccess);
     if (rc != Success)
@@ -466,7 +471,11 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client)
 static int
 ProcXF86DRIGetDeviceInfo(register ClientPtr client)
 {
-    xXF86DRIGetDeviceInfoReply rep;
+    xXF86DRIGetDeviceInfoReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     drm_handle_t hFrameBuffer;
     void *pDevPrivate;
 
@@ -477,10 +486,6 @@ ProcXF86DRIGetDeviceInfo(register ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     if (!DRIGetDeviceInfo(screenInfo.screens[stuff->screen],
                           &hFrameBuffer,
                           (int *) &rep.framebufferOrigin,
@@ -497,7 +502,6 @@ ProcXF86DRIGetDeviceInfo(register ClientPtr client)
     rep.hFrameBufferHigh = 0;
 #endif
 
-    rep.length = 0;
     if (rep.devPrivateSize) {
         rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetDeviceInfoReply) -
                                     SIZEOF(xGenericReply) +
diff --git a/hw/xfree86/dri2/dri2ext.c b/hw/xfree86/dri2/dri2ext.c
index 3bc3ea7..a6be4c2 100644
--- a/hw/xfree86/dri2/dri2ext.c
+++ b/hw/xfree86/dri2/dri2ext.c
@@ -71,17 +71,18 @@ static int
 ProcDRI2QueryVersion(ClientPtr client)
 {
     REQUEST(xDRI2QueryVersionReq);
-    xDRI2QueryVersionReply rep;
+    xDRI2QueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = dri2_major,
+        .minorVersion = dri2_minor
+    };
 
     if (client->swapped)
         swaps(&stuff->length);
 
     REQUEST_SIZE_MATCH(xDRI2QueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = dri2_major;
-    rep.minorVersion = dri2_minor;
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -99,7 +100,13 @@ static int
 ProcDRI2Connect(ClientPtr client)
 {
     REQUEST(xDRI2ConnectReq);
-    xDRI2ConnectReply rep;
+    xDRI2ConnectReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .driverNameLength = 0,
+        .deviceNameLength = 0
+    };
     DrawablePtr pDraw;
     int fd, status;
     const char *driverName;
@@ -110,12 +117,6 @@ ProcDRI2Connect(ClientPtr client)
                        &pDraw, &status))
         return status;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.driverNameLength = 0;
-    rep.deviceNameLength = 0;
-
     if (!DRI2Connect(client, pDraw->pScreen,
                      stuff->driverType, &fd, &driverName, &deviceName))
         goto fail;
@@ -146,10 +147,12 @@ ProcDRI2Authenticate(ClientPtr client)
                        &pDraw, &status))
         return status;
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.authenticated = DRI2Authenticate(client, pDraw->pScreen, stuff->magic);
+    rep = (xDRI2AuthenticateReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .authenticated = DRI2Authenticate(client, pDraw->pScreen, stuff->magic)
+    };
     WriteToClient(client, sizeof(xDRI2AuthenticateReply), &rep);
 
     return Success;
@@ -225,12 +228,14 @@ send_buffers_reply(ClientPtr client, DrawablePtr pDrawable,
         }
     }
 
-    rep.type = X_Reply;
-    rep.length = (count - skip) * sizeof(xDRI2Buffer) / 4;
-    rep.sequenceNumber = client->sequence;
-    rep.width = width;
-    rep.height = height;
-    rep.count = count - skip;
+    rep = (xDRI2GetBuffersReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = (count - skip) * sizeof(xDRI2Buffer) / 4,
+        .width = width,
+        .height = height,
+        .count = count - skip
+    };
     WriteToClient(client, sizeof(xDRI2GetBuffersReply), &rep);
 
     for (i = 0; i < count; i++) {
@@ -330,9 +335,11 @@ ProcDRI2CopyRegion(ClientPtr client)
      * that yet.
      */
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xDRI2CopyRegionReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     WriteToClient(client, sizeof(xDRI2CopyRegionReply), &rep);
 
@@ -375,7 +382,11 @@ static int
 ProcDRI2SwapBuffers(ClientPtr client)
 {
     REQUEST(xDRI2SwapBuffersReq);
-    xDRI2SwapBuffersReply rep;
+    xDRI2SwapBuffersReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     DrawablePtr pDrawable;
     CARD64 target_msc, divisor, remainder, swap_target;
     int status;
@@ -402,9 +413,6 @@ ProcDRI2SwapBuffers(ClientPtr client)
     if (status != Success)
         return BadDrawable;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
     load_swap_reply(&rep, swap_target);
 
     WriteToClient(client, sizeof(xDRI2SwapBuffersReply), &rep);
@@ -427,7 +435,11 @@ static int
 ProcDRI2GetMSC(ClientPtr client)
 {
     REQUEST(xDRI2GetMSCReq);
-    xDRI2MSCReply rep;
+    xDRI2MSCReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     DrawablePtr pDrawable;
     CARD64 ust, msc, sbc;
     int status;
@@ -442,9 +454,6 @@ ProcDRI2GetMSC(ClientPtr client)
     if (status != Success)
         return status;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
     load_msc_reply(&rep, ust, msc, sbc);
 
     WriteToClient(client, sizeof(xDRI2MSCReply), &rep);
@@ -482,11 +491,12 @@ ProcDRI2WaitMSC(ClientPtr client)
 int
 ProcDRI2WaitMSCReply(ClientPtr client, CARD64 ust, CARD64 msc, CARD64 sbc)
 {
-    xDRI2MSCReply rep;
+    xDRI2MSCReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
     load_msc_reply(&rep, ust, msc, sbc);
 
     WriteToClient(client, sizeof(xDRI2MSCReply), &rep);
@@ -614,7 +624,13 @@ static int
 SProcDRI2Connect(ClientPtr client)
 {
     REQUEST(xDRI2ConnectReq);
-    xDRI2ConnectReply rep;
+    xDRI2ConnectReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .driverNameLength = 0,
+        .deviceNameLength = 0
+    };
 
     /* If the client is swapped, it's not local.  Talk to the hand. */
 
@@ -622,12 +638,7 @@ SProcDRI2Connect(ClientPtr client)
     if (sizeof(*stuff) / 4 != client->req_len)
         return BadLength;
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
     swaps(&rep.sequenceNumber);
-    rep.length = 0;
-    rep.driverNameLength = 0;
-    rep.deviceNameLength = 0;
 
     WriteToClient(client, sizeof(xDRI2ConnectReply), &rep);
 
commit 14501fd33ee89acf9fc1d908003ed62f383d8bae
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in Xephyr Replies
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 65e0ff8..a42be07 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -517,18 +517,19 @@ EphyrMirrorHostVisuals(ScreenPtr a_screen)
 static int
 ProcXF86DRIQueryVersion(register ClientPtr client)
 {
-    xXF86DRIQueryVersionReply rep;
+    xXF86DRIQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_XF86DRI_MAJOR_VERSION,
+        .minorVersion = SERVER_XF86DRI_MINOR_VERSION,
+        .patchVersion = SERVER_XF86DRI_PATCH_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xXF86DRIQueryVersionReq);
 
     EPHYR_LOG("enter\n");
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_XF86DRI_MAJOR_VERSION;
-    rep.minorVersion = SERVER_XF86DRI_MINOR_VERSION;
-    rep.patchVersion = SERVER_XF86DRI_PATCH_VERSION;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -556,17 +557,19 @@ ProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     if (!ephyrDRIQueryDirectRenderingCapable(stuff->screen, &isCapable)) {
         return BadValue;
     }
-    rep.isCapable = isCapable;
 
     if (!LocalClient(client) || client->swapped)
-        rep.isCapable = 0;
+        isCapable = 0;
+
+    rep = (xXF86DRIQueryDirectRenderingCapableReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .isCapable = isCapable
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -604,20 +607,20 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
     if (busIdString)
         busIdStringLength = strlen(busIdString);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.busIdStringLength = busIdStringLength;
-    rep.length =
-        bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) -
-                       SIZEOF(xGenericReply) +
-                       pad_to_int32(busIdStringLength));
-
-    rep.hSAREALow = (CARD32) (hSAREA & 0xffffffff);
+    rep = (xXF86DRIOpenConnectionReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) -
+                                 SIZEOF(xGenericReply) +
+                                 pad_to_int32(busIdStringLength)),
+        .hSAREALow = (CARD32) (hSAREA & 0xffffffff),
 #if defined(LONG64) && !defined(__linux__)
-    rep.hSAREAHigh = (CARD32) (hSAREA >> 32);
+        .hSAREAHigh = (CARD32) (hSAREA >> 32),
 #else
-    rep.hSAREAHigh = 0;
+        .hSAREAHigh = 0,
 #endif
+        .busIdStringLength = busIdStringLength
+    };
 
     WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), &rep);
     if (busIdStringLength)
@@ -641,10 +644,12 @@ ProcXF86DRIAuthConnection(register ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.authenticated = 1;
+    rep = (xXF86DRIAuthConnectionReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .authenticated = 1
+    };
 
     if (!ephyrDRIAuthConnection(stuff->screen, stuff->magic)) {
         ErrorF("Failed to authenticate %lu\n", (unsigned long) stuff->magic);
@@ -677,7 +682,11 @@ ProcXF86DRICloseConnection(register ClientPtr client)
 static int
 ProcXF86DRIGetClientDriverName(register ClientPtr client)
 {
-    xXF86DRIGetClientDriverNameReply rep;
+    xXF86DRIGetClientDriverNameReply rep =  {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .clientDriverNameLength = 0
+    };
     char *clientDriverName;
 
     REQUEST(xXF86DRIGetClientDriverNameReq);
@@ -694,10 +703,6 @@ ProcXF86DRIGetClientDriverName(register ClientPtr client)
                                 (int *) &rep.ddxDriverMinorVersion,
                                 (int *) &rep.ddxDriverPatchVersion,
                                 &clientDriverName);
-
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.clientDriverNameLength = 0;
     if (clientDriverName)
         rep.clientDriverNameLength = strlen(clientDriverName);
     rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetClientDriverNameReply) -
@@ -714,7 +719,11 @@ ProcXF86DRIGetClientDriverName(register ClientPtr client)
 static int
 ProcXF86DRICreateContext(register ClientPtr client)
 {
-    xXF86DRICreateContextReply rep;
+    xXF86DRICreateContextReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     ScreenPtr pScreen;
     VisualPtr visual;
     int i = 0;
@@ -729,10 +738,6 @@ ProcXF86DRICreateContext(register ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     pScreen = screenInfo.screens[stuff->screen];
     visual = pScreen->visuals;
 
@@ -917,7 +922,11 @@ destroyHostPeerWindow(const WindowPtr a_win)
 static int
 ProcXF86DRICreateDrawable(ClientPtr client)
 {
-    xXF86DRICreateDrawableReply rep;
+    xXF86DRICreateDrawableReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     DrawablePtr drawable = NULL;
     WindowPtr window = NULL;
     EphyrWindowPair *pair = NULL;
@@ -933,10 +942,6 @@ ProcXF86DRICreateDrawable(ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     rc = dixLookupDrawable(&drawable, stuff->drawable, client, 0,
                            DixReadAccess);
     if (rc != Success)
@@ -1025,7 +1030,11 @@ ProcXF86DRIDestroyDrawable(register ClientPtr client)
 static int
 ProcXF86DRIGetDrawableInfo(register ClientPtr client)
 {
-    xXF86DRIGetDrawableInfoReply rep;
+    xXF86DRIGetDrawableInfoReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     DrawablePtr drawable;
     WindowPtr window = NULL;
     EphyrWindowPair *pair = NULL;
@@ -1037,16 +1046,11 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client)
     REQUEST_SIZE_MATCH(xXF86DRIGetDrawableInfoReq);
 
     EPHYR_LOG("enter\n");
-    memset(&rep, 0, sizeof(rep));
     if (stuff->screen >= screenInfo.numScreens) {
         client->errorValue = stuff->screen;
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     rc = dixLookupDrawable(&drawable, stuff->drawable, client, 0,
                            DixReadAccess);
     if (rc != Success || !drawable) {
@@ -1161,7 +1165,11 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client)
 static int
 ProcXF86DRIGetDeviceInfo(register ClientPtr client)
 {
-    xXF86DRIGetDeviceInfoReply rep;
+    xXF86DRIGetDeviceInfoReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     drm_handle_t hFrameBuffer;
     void *pDevPrivate;
 
@@ -1174,10 +1182,6 @@ ProcXF86DRIGetDeviceInfo(register ClientPtr client)
         return BadValue;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     if (!ephyrDRIGetDeviceInfo(stuff->screen,
                                &hFrameBuffer,
                                (int *) &rep.framebufferOrigin,
@@ -1194,7 +1198,6 @@ ProcXF86DRIGetDeviceInfo(register ClientPtr client)
     rep.hFrameBufferHigh = 0;
 #endif
 
-    rep.length = 0;
     if (rep.devPrivateSize) {
         rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetDeviceInfoReply) -
                                     SIZEOF(xGenericReply) +
diff --git a/hw/kdrive/ephyr/ephyrglxext.c b/hw/kdrive/ephyr/ephyrglxext.c
index f5c4c18..dae22fc 100644
--- a/hw/kdrive/ephyr/ephyrglxext.c
+++ b/hw/kdrive/ephyr/ephyrglxext.c
@@ -159,11 +159,13 @@ ephyrGLXQueryVersion(__GLXclientState * a_cl, GLbyte * a_pc)
         goto out;
     }
     EPHYR_LOG("major:%d, minor:%d\n", major, minor);
-    reply.majorVersion = major;
-    reply.minorVersion = minor;
-    reply.length = 0;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXQueryVersionReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = major,
+        .minorVersion = minor
+    };
 
     if (client->swapped) {
         __glXSwapQueryVersionReply(client, &reply);
@@ -215,11 +217,13 @@ ephyrGLXGetVisualConfigsReal(__GLXclientState * a_cl,
     }
     EPHYR_LOG("num_visuals:%d, num_props:%d\n", num_visuals, num_props);
 
-    reply.numVisuals = num_visuals;
-    reply.numProps = num_props;
-    reply.length = (num_visuals * __GLX_SIZE_CARD32 * num_props) >> 2;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXGetVisualConfigsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = (num_visuals * __GLX_SIZE_CARD32 * num_props) >> 2,
+        .numVisuals = num_visuals,
+        .numProps = num_props
+    };
 
     if (a_do_swap) {
         __GLX_SWAP_SHORT(&reply.sequenceNumber);
@@ -269,11 +273,13 @@ ephyrGLXGetFBConfigsSGIXReal(__GLXclientState * a_cl,
     }
     EPHYR_LOG("num_visuals:%d, num_props:%d\n", num_visuals, num_props);
 
-    reply.numVisuals = num_visuals;
-    reply.numProps = num_props;
-    reply.length = props_buf_size >> 2;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXGetVisualConfigsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = props_buf_size >> 2,
+        .numVisuals = num_visuals,
+        .numProps = num_props
+    };
 
     if (a_do_swap) {
         __GLX_SWAP_SHORT(&reply.sequenceNumber);
@@ -364,10 +370,13 @@ ephyrGLXQueryServerString(__GLXclientState * a_cl, GLbyte * a_pc)
     }
     EPHYR_LOG("string: %s\n", server_string);
     length = strlen(server_string) + 1;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = __GLX_PAD(length) >> 2;
-    reply.n = length;
+    reply = (xGLXQueryServerStringReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = __GLX_PAD(length) >> 2,
+        .n = length
+    };
+
     buf = calloc(reply.length << 2, 1);
     if (!buf) {
         EPHYR_LOG_ERROR("failed to allocate string\n;");
@@ -522,7 +531,6 @@ ephyrGLXMakeCurrentReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
     EPHYR_RETURN_VAL_IF_FAIL(drawable->pScreen, BadValue);
     EPHYR_LOG("screen nummber requested:%d\n", drawable->pScreen->myNum);
 
-    memset(&reply, 0, sizeof(reply));
     if (!ephyrHostGLXMakeCurrent(hostx_get_window(drawable->pScreen->myNum),
                                  req->context,
                                  req->oldContextTag,
@@ -530,10 +538,12 @@ ephyrGLXMakeCurrentReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
         EPHYR_LOG_ERROR("ephyrHostGLXMakeCurrent() failed\n");
         goto out;
     }
-    reply.length = 0;
-    reply.type = X_Reply;
-    reply.sequenceNumber = a_cl->client->sequence;
-    reply.contextTag = contextTag;
+    reply = (xGLXMakeCurrentReply) {
+        .type = X_Reply,
+        .sequenceNumber = a_cl->client->sequence,
+        .length = 0,
+        .contextTag = contextTag
+    };
     if (a_do_swap) {
         __GLX_DECLARE_SWAP_VARIABLES;
         __GLX_SWAP_SHORT(&reply.sequenceNumber);
@@ -683,15 +693,17 @@ ephyrGLXIsDirectReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
 
     EPHYR_LOG("enter\n");
 
-    memset(&reply, 0, sizeof(reply));
     if (!ephyrHostIsContextDirect(req->context, (int *) &is_direct)) {
         EPHYR_LOG_ERROR("ephyrHostIsContextDirect() failed\n");
         goto out;
     }
-    reply.isDirect = is_direct;
-    reply.length = 0;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXIsDirectReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .isDirect = is_direct
+    };
+
     WriteToClient(client, sz_xGLXIsDirectReply, &reply);
     res = Success;
 
commit e4e827ec36fd20b7aea608db09790f76fb87e519
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in dmx Replies
    
    v2: fix in __glXGetVisualConfigs to not re-declare local 'reply' variable
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>
    
    Fixup for Use C99 designated initializeres in dmx Replies
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c
index 5ea133e..9df94a4 100644
--- a/hw/dmx/dmx.c
+++ b/hw/dmx/dmx.c
@@ -208,16 +208,17 @@ dmxFetchInputAttributes(unsigned int mask,
 static int
 ProcDMXQueryVersion(ClientPtr client)
 {
-    xDMXQueryVersionReply rep;
+    xDMXQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_DMX_MAJOR_VERSION,
+        .minorVersion = SERVER_DMX_MINOR_VERSION,
+        .patchVersion = SERVER_DMX_PATCH_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xDMXQueryVersionReq);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.majorVersion = SERVER_DMX_MAJOR_VERSION;
-    rep.minorVersion = SERVER_DMX_MINOR_VERSION;
-    rep.patchVersion = SERVER_DMX_PATCH_VERSION;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -238,10 +239,12 @@ ProcDMXSync(ClientPtr client)
 
     dmxFlushPendingSyncs();
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.status = 0;
+    rep = (xDMXSyncReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = 0
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -288,10 +291,12 @@ ProcDMXForceWindowCreation(ClientPtr client)
     dmxForceWindowCreation(pWin);
  doreply:
     dmxFlushPendingSyncs();
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.status = 0;
+    rep = (xDMXForceWindowCreationReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = 0
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -308,10 +313,12 @@ ProcDMXGetScreenCount(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xDMXGetScreenCountReq);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.screenCount = dmxGetNumScreens();
+    rep = (xDMXGetScreenCountReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .screenCount = dmxGetNumScreens()
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -339,27 +346,29 @@ ProcDMXGetScreenAttributes(ClientPtr client)
     if (!dmxGetScreenAttributes(stuff->physicalScreen, &attr))
         return BadValue;
 
-    rep.logicalScreen = attr.logicalScreen;
-    rep.screenWindowWidth = attr.screenWindowWidth;
-    rep.screenWindowHeight = attr.screenWindowHeight;
-    rep.screenWindowXoffset = attr.screenWindowXoffset;
-    rep.screenWindowYoffset = attr.screenWindowYoffset;
-    rep.rootWindowWidth = attr.rootWindowWidth;
-    rep.rootWindowHeight = attr.rootWindowHeight;
-    rep.rootWindowXoffset = attr.rootWindowXoffset;
-    rep.rootWindowYoffset = attr.rootWindowYoffset;
-    rep.rootWindowXorigin = attr.rootWindowXorigin;
-    rep.rootWindowYorigin = attr.rootWindowYorigin;
-
     length = attr.displayName ? strlen(attr.displayName) : 0;
     paddedLength = pad_to_int32(length);
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length =
-        bytes_to_int32((sizeof(xDMXGetScreenAttributesReply) -
-                        sizeof(xGenericReply))
-                       + paddedLength);
-    rep.displayNameLength = length;
+
+    rep = (xDMXGetScreenAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length =
+            bytes_to_int32((sizeof(xDMXGetScreenAttributesReply) -
+                            sizeof(xGenericReply))
+                           + paddedLength),
+        .displayNameLength = length,
+        .logicalScreen = attr.logicalScreen,
+        .screenWindowWidth = attr.screenWindowWidth,
+        .screenWindowHeight = attr.screenWindowHeight,
+        .screenWindowXoffset = attr.screenWindowXoffset,
+        .screenWindowYoffset = attr.screenWindowYoffset,
+        .rootWindowWidth = attr.rootWindowWidth,
+        .rootWindowHeight = attr.rootWindowHeight,
+        .rootWindowXoffset = attr.rootWindowXoffset,
+        .rootWindowYoffset = attr.rootWindowYoffset,
+        .rootWindowXorigin = attr.rootWindowXorigin,
+        .rootWindowYorigin = attr.rootWindowYorigin
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -442,11 +451,13 @@ ProcDMXChangeScreensAttributes(ClientPtr client)
         return status;
 
  noxinerama:
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.status = status;
-    rep.errorScreen = errorScreen;
+    rep = (xDMXChangeScreensAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = status,
+        .errorScreen = errorScreen
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -491,11 +502,13 @@ ProcDMXAddScreen(ClientPtr client)
 
     free(name);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.status = status;
-    rep.physicalScreen = stuff->physicalScreen;
+    rep = (xDMXAddScreenReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = status,
+        .physicalScreen = stuff->physicalScreen
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -517,10 +530,12 @@ ProcDMXRemoveScreen(ClientPtr client)
 
     status = dmxDetachScreen(stuff->physicalScreen);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.status = status;
+    rep = (xDMXRemoveScreenReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = status
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -636,10 +651,12 @@ ProcDMXGetWindowAttributes(ClientPtr client)
         return BadWindow;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = count * 6;
-    rep.screenCount = count;
+    rep = (xDMXGetWindowAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = count * 6,
+        .screenCount = count
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -688,14 +705,15 @@ ProcDMXGetDesktopAttributes(ClientPtr client)
 
     dmxGetDesktopAttributes(&attr);
 
-    rep.width = attr.width;
-    rep.height = attr.height;
-    rep.shiftX = attr.shiftX;
-    rep.shiftY = attr.shiftY;
-
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
+    rep = (xDMXGetDesktopAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .width = attr.width,
+        .height = attr.height,
+        .shiftX = attr.shiftX,
+        .shiftY = attr.shiftY
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -739,10 +757,12 @@ ProcDMXChangeDesktopAttributes(ClientPtr client)
         return status;
 
  noxinerama:
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.status = status;
+    rep = (xDMXChangeDesktopAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = status
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -759,10 +779,12 @@ ProcDMXGetInputCount(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xDMXGetInputCountReq);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.inputCount = dmxGetInputCount();
+    rep = (xDMXGetInputCountReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .inputCount = dmxGetInputCount()
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -785,19 +807,24 @@ ProcDMXGetInputAttributes(ClientPtr client)
 
     if (dmxGetInputAttributes(stuff->deviceId, &attr))
         return BadValue;
-    rep.inputType = attr.inputType;
-    rep.physicalScreen = attr.physicalScreen;
-    rep.physicalId = attr.physicalId;
-    rep.isCore = attr.isCore;
-    rep.sendsCore = attr.sendsCore;
-    rep.detached = attr.detached;
 
     length = attr.name ? strlen(attr.name) : 0;
     paddedLength = pad_to_int32(length);
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = bytes_to_int32(paddedLength);
-    rep.nameLength = length;
+
+    rep = (xDMXGetInputAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(paddedLength),
+
+        .inputType = attr.inputType,
+        .physicalScreen = attr.physicalScreen,
+        .physicalId = attr.physicalId,
+        .nameLength = length,
+        .isCore = attr.isCore,
+        .sendsCore = attr.sendsCore,
+        .detached = attr.detached
+    };
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -849,11 +876,13 @@ ProcDMXAddInput(ClientPtr client)
     if (status)
         return status;
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.status = status;
-    rep.physicalId = id;
+    rep = (xDMXAddInputReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = status,
+        .physicalId = id
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -878,10 +907,12 @@ ProcDMXRemoveInput(ClientPtr client)
     if (status)
         return status;
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.status = status;
+    rep = (xDMXRemoveInputReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = status
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index 32684fa..91011d1 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -454,12 +454,12 @@ __glXQueryMaxSwapBarriersSGIX(__GLXclientState * cl, GLbyte * pc)
     ClientPtr client = cl->client;
     xGLXQueryMaxSwapBarriersSGIXReq *req =
         (xGLXQueryMaxSwapBarriersSGIXReq *) pc;
-    xGLXQueryMaxSwapBarriersSGIXReply reply;
-
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = 0;
-    reply.max = QueryMaxSwapBarriersSGIX(req->screen);
+    xGLXQueryMaxSwapBarriersSGIXReply reply = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .max = QueryMaxSwapBarriersSGIX(req->screen)
+    };
 
     if (client->swapped) {
         __glXSwapQueryMaxSwapBarriersSGIXReply(client, &reply);
@@ -793,7 +793,11 @@ MakeCurrent(__GLXclientState * cl,
     ClientPtr client = cl->client;
     DrawablePtr pDraw = NULL;
     DrawablePtr pReadDraw = NULL;
-    xGLXMakeCurrentReadSGIReply new_reply;
+    xGLXMakeCurrentReadSGIReply new_reply = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     xGLXMakeCurrentReq *be_req;
     xGLXMakeCurrentReply be_reply;
     xGLXMakeContextCurrentReq *be_new_req;
@@ -1197,9 +1201,6 @@ MakeCurrent(__GLXclientState * cl,
     else {
         new_reply.contextTag = 0;
     }
-    new_reply.length = 0;
-    new_reply.type = X_Reply;
-    new_reply.sequenceNumber = client->sequence;
 
 #ifdef PANORAMIX
     if (!noPanoramiXExtension) {
@@ -1438,10 +1439,12 @@ __glXIsDirect(__GLXclientState * cl, GLbyte * pc)
         return __glXBadContext;
     }
 
-    reply.isDirect = 0;
-    reply.length = 0;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXIsDirectReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .isDirect = 0
+    };
 
     if (client->swapped) {
         __glXSwapIsDirectReply(client, &reply);
@@ -1459,18 +1462,19 @@ __glXQueryVersion(__GLXclientState * cl, GLbyte * pc)
     ClientPtr client = cl->client;
 
 /*    xGLXQueryVersionReq *req = (xGLXQueryVersionReq *) pc; */
-    xGLXQueryVersionReply reply;
 
+    xGLXQueryVersionReply reply = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
     /*
      ** Server should take into consideration the version numbers sent by the
      ** client if it wants to work with older clients; however, in this
      ** implementation the server just returns its version number.
      */
-    reply.majorVersion = __glXVersionMajor;
-    reply.minorVersion = __glXVersionMinor;
-    reply.length = 0;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+        .majorVersion = __glXVersionMajor,
+        .minorVersion = __glXVersionMinor
+    };
 
     if (client->swapped) {
         __glXSwapQueryVersionReply(client, &reply);
@@ -1680,12 +1684,14 @@ __glXGetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
     }
     pGlxScreen = &__glXActiveScreens[screen];
 
-    reply.numVisuals = pGlxScreen->numGLXVisuals;
-    reply.numProps = __GLX_TOTAL_CONFIG;
-    reply.length = (pGlxScreen->numGLXVisuals * __GLX_SIZE_CARD32 *
-                    __GLX_TOTAL_CONFIG) >> 2;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXGetVisualConfigsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .numVisuals = pGlxScreen->numGLXVisuals,
+        .numProps = __GLX_TOTAL_CONFIG,
+        .length = (pGlxScreen->numGLXVisuals * __GLX_SIZE_CARD32 *
+                    __GLX_TOTAL_CONFIG) >> 2
+    };
 
     WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply);
 
@@ -2625,10 +2631,12 @@ __glXQueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
 #endif
 
     length = len;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = len;
-    reply.n = numbytes;
+    reply = (xGLXQueryExtensionsStringReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = len,
+        .n = numbytes
+    };
 
     if (client->swapped) {
         glxSwapQueryExtensionsStringReply(client, &reply, be_buf);
@@ -2706,10 +2714,12 @@ __glXQueryServerString(__GLXclientState * cl, GLbyte * pc)
 #endif
 
     length = len;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = length;
-    reply.n = numbytes;
+    reply = (xGLXQueryServerStringReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = length,
+        .n = numbytes
+    };
 
     if (client->swapped) {
         glxSwapQueryServerStringReply(client, &reply, be_buf);
@@ -2863,11 +2873,13 @@ __glXGetFBConfigs(__GLXclientState * cl, GLbyte * pc)
     pGlxScreen = &__glXActiveScreens[screen];
     numFBConfigs = __glXNumFBConfigs;
 
-    reply.numFBConfigs = numFBConfigs;
-    reply.numAttribs = numAttribs;
-    reply.length = (numFBConfigs * 2 * numAttribs * __GLX_SIZE_CARD32) >> 2;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXGetFBConfigsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = (numFBConfigs * 2 * numAttribs * __GLX_SIZE_CARD32) >> 2,
+        .numFBConfigs = numFBConfigs,
+        .numAttribs = numAttribs
+    };
 
     if (client->swapped) {
         __GLX_DECLARE_SWAP_VARIABLES;
@@ -3195,10 +3207,12 @@ __glXQueryContext(__GLXclientState * cl, GLbyte * pc)
 
     nProps = 3;
 
-    reply.length = nProps << 1;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.n = nProps;
+    reply = (xGLXQueryContextReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = nProps << 1,
+        .n = nProps
+    };
 
     nReplyBytes = reply.length << 2;
     sendBuf = (int *) malloc(nReplyBytes);
@@ -3245,10 +3259,12 @@ __glXQueryContextInfoEXT(__GLXclientState * cl, GLbyte * pc)
 
     nProps = 4;
 
-    reply.length = nProps << 1;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.n = nProps;
+    reply = (xGLXQueryContextInfoEXTReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = nProps << 1,
+        .n = nProps
+    };
 
     nReplyBytes = reply.length << 2;
     sendBuf = (int *) malloc(nReplyBytes);
diff --git a/hw/dmx/glxProxy/glxcmdsswap.c b/hw/dmx/glxProxy/glxcmdsswap.c
index a11c919..ac79cda 100644
--- a/hw/dmx/glxProxy/glxcmdsswap.c
+++ b/hw/dmx/glxProxy/glxcmdsswap.c
@@ -293,12 +293,14 @@ __glXSwapGetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
     }
     pGlxScreen = &__glXActiveScreens[screen];
 
-    reply.numVisuals = pGlxScreen->numGLXVisuals;
-    reply.numProps = __GLX_TOTAL_CONFIG;
-    reply.length = (pGlxScreen->numGLXVisuals * __GLX_SIZE_CARD32 *
-                    __GLX_TOTAL_CONFIG) >> 2;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXGetVisualConfigsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = (pGlxScreen->numGLXVisuals * __GLX_SIZE_CARD32 *
+                   __GLX_TOTAL_CONFIG) >> 2,
+        .numVisuals = pGlxScreen->numGLXVisuals,
+        .numProps = __GLX_TOTAL_CONFIG
+    };
 
     __GLX_SWAP_SHORT(&reply.sequenceNumber);
     __GLX_SWAP_INT(&reply.length);
diff --git a/hw/dmx/glxProxy/glxsingle.c b/hw/dmx/glxProxy/glxsingle.c
index 2253060..8784200 100644
--- a/hw/dmx/glxProxy/glxsingle.c
+++ b/hw/dmx/glxProxy/glxsingle.c
@@ -269,13 +269,15 @@ __glXForwardPipe0WithReply(__GLXclientState * cl, GLbyte * pc)
     /*
      * send the reply to the client
      */
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = be_reply.length;
-    reply.retval = be_reply.retval;
-    reply.size = be_reply.size;
-    reply.pad3 = be_reply.pad3;
-    reply.pad4 = be_reply.pad4;
+    reply = (xGLXSingleReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = be_reply.length,
+        .retval = be_reply.retval,
+        .size = be_reply.size,
+        .pad3 = be_reply.pad3,
+        .pad4 = be_reply.pad4
+    };
 
     if (client->swapped) {
         SendSwappedReply(client, &reply, be_buf, be_buf_size);
@@ -371,13 +373,15 @@ __glXForwardAllWithReply(__GLXclientState * cl, GLbyte * pc)
     /*
      * send the reply to the client
      */
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = be_reply.length;
-    reply.retval = be_reply.retval;
-    reply.size = be_reply.size;
-    reply.pad3 = be_reply.pad3;
-    reply.pad4 = be_reply.pad4;
+    reply = (xGLXSingleReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = be_reply.length,
+        .retval = be_reply.retval,
+        .size = be_reply.size,
+        .pad3 = be_reply.pad3,
+        .pad4 = be_reply.pad4
+    };
 
     if (client->swapped) {
         SendSwappedReply(client, &reply, be_buf, be_buf_size);
@@ -1004,9 +1008,11 @@ __glXDisp_ReadPixels(__GLXclientState * cl, GLbyte * pc)
 
     }                           /* of if buf_size > 0 */
 
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = buf_size >> 2;
+    reply = (xGLXReadPixelsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = buf_size >> 2
+    };
 
     if (client->swapped) {
         __GLX_SWAP_SHORT(&reply.sequenceNumber);
commit bd6f948c41865c2c9d3fba1000bf5f7458d3afc1
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in randr Replies
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index c91c7fd..138fbe1 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -900,11 +900,13 @@ ProcRRGetCrtcInfo(ClientPtr client)
 
     mode = crtc->mode;
 
-    rep.type = X_Reply;
-    rep.status = RRSetConfigSuccess;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.timestamp = pScrPriv->lastSetTime.milliseconds;
+    rep = (xRRGetCrtcInfoReply) {
+        .type = X_Reply,
+        .status = RRSetConfigSuccess,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .timestamp = pScrPriv->lastSetTime.milliseconds
+    };
     if (pScrPriv->rrGetPanning &&
         pScrPriv->rrGetPanning(pScreen, crtc, &panned_area, NULL, NULL) &&
         (panned_area.x2 > panned_area.x1) && (panned_area.y2 > panned_area.y1))
@@ -1171,11 +1173,13 @@ ProcRRSetCrtcConfig(ClientPtr client)
  sendReply:
     free(outputs);
 
-    rep.type = X_Reply;
-    rep.status = status;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
+    rep = (xRRSetCrtcConfigReply) {
+        .type = X_Reply,
+        .status = status,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .newTimestamp = pScrPriv->lastSetTime.milliseconds
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -1211,12 +1215,13 @@ ProcRRGetPanning(ClientPtr client)
     if (!pScrPriv)
         return RRErrorBase + BadRRCrtc;
 
-    memset(&rep, 0, sizeof(rep));
-    rep.type = X_Reply;
-    rep.status = RRSetConfigSuccess;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 1;
-    rep.timestamp = pScrPriv->lastSetTime.milliseconds;
+    rep = (xRRGetPanningReply) {
+        .type = X_Reply,
+        .status = RRSetConfigSuccess,
+        .sequenceNumber = client->sequence,
+        .length = 1,
+        .timestamp = pScrPriv->lastSetTime.milliseconds
+    };
 
     if (pScrPriv->rrGetPanning &&
         pScrPriv->rrGetPanning(pScreen, crtc, &total, &tracking, border)) {
@@ -1310,11 +1315,13 @@ ProcRRSetPanning(ClientPtr client)
     status = RRSetConfigSuccess;
 
  sendReply:
-    rep.type = X_Reply;
-    rep.status = status;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
+    rep = (xRRSetPanningReply) {
+        .type = X_Reply,
+        .status = status,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .newTimestamp = pScrPriv->lastSetTime.milliseconds
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -1339,10 +1346,12 @@ ProcRRGetCrtcGammaSize(ClientPtr client)
     if (!RRCrtcGammaGet(crtc))
         return RRErrorBase + BadRRCrtc;
 
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = 0;
-    reply.size = crtc->gammaSize;
+    reply = (xRRGetCrtcGammaSizeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .size = crtc->gammaSize
+    };
     if (client->swapped) {
         swaps(&reply.sequenceNumber);
         swapl(&reply.length);
@@ -1376,10 +1385,12 @@ ProcRRGetCrtcGamma(ClientPtr client)
             return BadAlloc;
     }
 
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = bytes_to_int32(len);
-    reply.size = crtc->gammaSize;
+    reply = (xRRGetCrtcGammaReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(len),
+        .size = crtc->gammaSize
+    };
     if (client->swapped) {
         swaps(&reply.sequenceNumber);
         swapl(&reply.length);
diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index d071787..7fbc9f0 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -35,16 +35,17 @@ RRClientKnowsRates(ClientPtr pClient)
 static int
 ProcRRQueryVersion(ClientPtr client)
 {
-    xRRQueryVersionReply rep = { 0 };
+    xRRQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     REQUEST(xRRQueryVersionReq);
     rrClientPriv(client);
 
     REQUEST_SIZE_MATCH(xRRQueryVersionReq);
     pRRClient->major_version = stuff->majorVersion;
     pRRClient->minor_version = stuff->minorVersion;
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
 
     if (version_compare(stuff->majorVersion, stuff->minorVersion,
                         SERVER_RANDR_MAJOR_VERSION,
diff --git a/randr/rrmode.c b/randr/rrmode.c
index 7e17d7d..56e5977 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -282,7 +282,7 @@ int
 ProcRRCreateMode(ClientPtr client)
 {
     REQUEST(xRRCreateModeReq);
-    xRRCreateModeReply rep = { 0 };
+    xRRCreateModeReply rep;
     WindowPtr pWin;
     ScreenPtr pScreen;
     xRRModeInfo *modeInfo;
@@ -310,11 +310,12 @@ ProcRRCreateMode(ClientPtr client)
     if (!mode)
         return error;
 
-    rep.type = X_Reply;
-    rep.pad0 = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.mode = mode->mode.id;
+    rep = (xRRCreateModeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .mode = mode->mode.id
+	};
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 3662a5a..0932508 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -425,22 +425,23 @@ ProcRRGetOutputInfo(ClientPtr client)
     pScreen = output->pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
 
-    rep.type = X_Reply;
-    rep.status = RRSetConfigSuccess;
-    rep.sequenceNumber = client->sequence;
-    rep.length = bytes_to_int32(OutputInfoExtra);
-    rep.timestamp = pScrPriv->lastSetTime.milliseconds;
-    rep.crtc = output->crtc ? output->crtc->id : None;
-    rep.mmWidth = output->mmWidth;
-    rep.mmHeight = output->mmHeight;
-    rep.connection = output->connection;
-    rep.subpixelOrder = output->subpixelOrder;
-    rep.nCrtcs = output->numCrtcs;
-    rep.nModes = output->numModes + output->numUserModes;
-    rep.nPreferred = output->numPreferred;
-    rep.nClones = output->numClones;
-    rep.nameLength = output->nameLength;
-
+    rep = (xRRGetOutputInfoReply) {
+        .type = X_Reply,
+        .status = RRSetConfigSuccess,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(OutputInfoExtra),
+        .timestamp = pScrPriv->lastSetTime.milliseconds,
+        .crtc = output->crtc ? output->crtc->id : None,
+        .mmWidth = output->mmWidth,
+        .mmHeight = output->mmHeight,
+        .connection = output->connection,
+        .subpixelOrder = output->subpixelOrder,
+        .nCrtcs = output->numCrtcs,
+        .nModes = output->numModes + output->numUserModes,
+        .nPreferred = output->numPreferred,
+        .nClones = output->numClones,
+        .nameLength = output->nameLength
+    };
     extraLen = ((output->numCrtcs +
                  output->numModes + output->numUserModes +
                  output->numClones + bytes_to_int32(rep.nameLength)) << 2);
@@ -573,10 +574,11 @@ ProcRRGetOutputPrimary(ClientPtr client)
     if (pScrPriv)
         primary = pScrPriv->primaryOutput;
 
-    memset(&rep, 0, sizeof(rep));
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.output = primary ? primary->id : None;
+    rep = (xRRGetOutputPrimaryReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .output = primary ? primary->id : None
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index b0a1cf9..7ce085c 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -394,10 +394,12 @@ ProcRRListOutputProperties(ClientPtr client)
         if (!(pAtoms = (Atom *) malloc(numProps * sizeof(Atom))))
             return BadAlloc;
 
-    rep.type = X_Reply;
-    rep.length = bytes_to_int32(numProps * sizeof(Atom));
-    rep.sequenceNumber = client->sequence;
-    rep.nAtoms = numProps;
+    rep = (xRRListOutputPropertiesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(numProps * sizeof(Atom)),
+        .nAtoms = numProps
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -440,12 +442,16 @@ ProcRRQueryOutputProperty(ClientPtr client)
         if (!extra)
             return BadAlloc;
     }
-    rep.type = X_Reply;
-    rep.length = prop->num_valid;
-    rep.sequenceNumber = client->sequence;
-    rep.pending = prop->is_pending;
-    rep.range = prop->range;
-    rep.immutable = prop->immutable;
+
+    rep = (xRRQueryOutputPropertyReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = prop->num_valid,
+        .pending = prop->is_pending,
+        .range = prop->range,
+        .immutable = prop->immutable
+    };
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -596,8 +602,10 @@ ProcRRGetOutputProperty(ClientPtr client)
         if (prop->propertyName == stuff->property)
             break;
 
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xRRGetOutputPropertyReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence
+    };
     if (!prop) {
         reply.nItems = 0;
         reply.length = 0;
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 6fd24e0..774f8be 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -203,10 +203,12 @@ ProcRRGetScreenSizeRange(ClientPtr client)
     pScreen = pWin->drawable.pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
 
-    rep.type = X_Reply;
-    rep.pad = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
+    rep = (xRRGetScreenSizeRangeReply) {
+        .type = X_Reply,
+        .pad = 0,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     if (pScrPriv) {
         if (!RRGetInfo(pScreen, FALSE))
@@ -481,7 +483,6 @@ rrGetScreenResources(ClientPtr client, Bool query)
 
     pScreen = pWin->drawable.pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
-    rep.pad = 0;
 
     if (query && pScrPriv)
         if (!RRGetInfo(pScreen, query))
@@ -491,15 +492,17 @@ rrGetScreenResources(ClientPtr client, Bool query)
         return rrGetMultiScreenResources(client, query, pScreen);
 
     if (!pScrPriv) {
-        rep.type = X_Reply;
-        rep.sequenceNumber = client->sequence;
-        rep.length = 0;
-        rep.timestamp = currentTime.milliseconds;
-        rep.configTimestamp = currentTime.milliseconds;
-        rep.nCrtcs = 0;
-        rep.nOutputs = 0;
-        rep.nModes = 0;
-        rep.nbytesNames = 0;
+        rep = (xRRGetScreenResourcesReply) {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .timestamp = currentTime.milliseconds,
+            .configTimestamp = currentTime.milliseconds,
+            .nCrtcs = 0,
+            .nOutputs = 0,
+            .nModes = 0,
+            .nbytesNames = 0
+        };
         extra = NULL;
         extraLen = 0;
     }
@@ -511,15 +514,18 @@ rrGetScreenResources(ClientPtr client, Bool query)
         if (!modes)
             return BadAlloc;
 
-        rep.type = X_Reply;
-        rep.sequenceNumber = client->sequence;
-        rep.length = 0;
-        rep.timestamp = pScrPriv->lastSetTime.milliseconds;
-        rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
-        rep.nCrtcs = pScrPriv->numCrtcs;
-        rep.nOutputs = pScrPriv->numOutputs;
-        rep.nModes = num_modes;
-        rep.nbytesNames = 0;
+        rep = (xRRGetScreenResourcesReply) {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .timestamp = pScrPriv->lastSetTime.milliseconds,
+            .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
+            .nCrtcs = pScrPriv->numCrtcs,
+            .nOutputs = pScrPriv->numOutputs,
+            .nModes = num_modes,
+            .nbytesNames = 0
+        };
+
 
         for (i = 0; i < num_modes; i++)
             rep.nbytesNames += modes[i]->mode.nameLength;
@@ -744,7 +750,6 @@ ProcRRGetScreenInfo(ClientPtr client)
 
     pScreen = pWin->drawable.pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
-    rep.pad = 0;
 
     if (pScrPriv)
         if (!RRGetInfo(pScreen, TRUE))
@@ -753,18 +758,20 @@ ProcRRGetScreenInfo(ClientPtr client)
     output = RRFirstOutput(pScreen);
 
     if (!pScrPriv || !output) {
-        rep.type = X_Reply;
-        rep.setOfRotations = RR_Rotate_0;
-        rep.sequenceNumber = client->sequence;
-        rep.length = 0;
-        rep.root = pWin->drawable.pScreen->root->drawable.id;
-        rep.timestamp = currentTime.milliseconds;
-        rep.configTimestamp = currentTime.milliseconds;
-        rep.nSizes = 0;
-        rep.sizeID = 0;
-        rep.rotation = RR_Rotate_0;
-        rep.rate = 0;
-        rep.nrateEnts = 0;
+        rep = (xRRGetScreenInfoReply) {
+            .type = X_Reply,
+            .setOfRotations = RR_Rotate_0,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .root = pWin->drawable.pScreen->root->drawable.id,
+            .timestamp = currentTime.milliseconds,
+            .configTimestamp = currentTime.milliseconds,
+            .nSizes = 0,
+            .sizeID = 0,
+            .rotation = RR_Rotate_0,
+            .rate = 0,
+            .nrateEnts = 0
+        };
         extra = 0;
         extraLen = 0;
     }
@@ -781,18 +788,20 @@ ProcRRGetScreenInfo(ClientPtr client)
         if (!pData)
             return BadAlloc;
 
-        rep.type = X_Reply;
-        rep.setOfRotations = output->crtc->rotations;
-        rep.sequenceNumber = client->sequence;
-        rep.length = 0;
-        rep.root = pWin->drawable.pScreen->root->drawable.id;
-        rep.timestamp = pScrPriv->lastSetTime.milliseconds;
-        rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
-        rep.rotation = output->crtc->rotation;
-        rep.nSizes = pData->nsize;
-        rep.nrateEnts = pData->nrefresh + pData->nsize;
-        rep.sizeID = pData->size;
-        rep.rate = pData->refresh;
+        rep = (xRRGetScreenInfoReply) {
+            .type = X_Reply,
+            .setOfRotations = output->crtc->rotations,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .root = pWin->drawable.pScreen->root->drawable.id,
+            .timestamp = pScrPriv->lastSetTime.milliseconds,
+            .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
+            .rotation = output->crtc->rotation,
+            .nSizes = pData->nsize,
+            .nrateEnts = pData->nrefresh + pData->nsize,
+            .sizeID = pData->size,
+            .rate = pData->refresh
+        };
 
         extraLen = rep.nSizes * sizeof(xScreenSizes);
         if (has_rate)
@@ -1078,14 +1087,17 @@ ProcRRSetScreenConfig(ClientPtr client)
 
     free(pData);
 
-    rep.type = X_Reply;
-    rep.status = status;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
-    rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
-    rep.newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds;
-    rep.root = pDraw->pScreen->root->drawable.id;
+    rep = (xRRSetScreenConfigReply) {
+        .type = X_Reply,
+        .status = status,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+
+        .newTimestamp = pScrPriv->lastSetTime.milliseconds,
+        .newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds,
+        .root = pDraw->pScreen->root->drawable.id,
+        /* .subpixelOrder = ?? */
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
diff --git a/randr/rrxinerama.c b/randr/rrxinerama.c
index da3942f..87d6a73 100644
--- a/randr/rrxinerama.c
+++ b/randr/rrxinerama.c
@@ -89,14 +89,15 @@ static int SProcRRXineramaDispatch(ClientPtr client);
 int
 ProcRRXineramaQueryVersion(ClientPtr client)
 {
-    xPanoramiXQueryVersionReply rep;
+    xPanoramiXQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_RRXINERAMA_MAJOR_VERSION,
+        .minorVersion = SERVER_RRXINERAMA_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_RRXINERAMA_MAJOR_VERSION;
-    rep.minorVersion = SERVER_RRXINERAMA_MINOR_VERSION;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -130,11 +131,13 @@ ProcRRXineramaGetState(ClientPtr client)
         active = TRUE;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.state = active;
-    rep.window = stuff->window;
+    rep = (xPanoramiXGetStateReply) {
+        .type = X_Reply,
+        .state = active,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .window = stuff->window
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -184,11 +187,13 @@ ProcRRXineramaGetScreenCount(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.ScreenCount = RRXineramaScreenCount(pWin->drawable.pScreen);
-    rep.window = stuff->window;
+    rep = (xPanoramiXGetScreenCountReply)  {
+        .type = X_Reply,
+        .ScreenCount = RRXineramaScreenCount(pWin->drawable.pScreen),
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .window = stuff->window
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -215,13 +220,15 @@ ProcRRXineramaGetScreenSize(ClientPtr client)
     pScreen = pWin->drawable.pScreen;
     pRoot = pScreen->root;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.width = pRoot->drawable.width;
-    rep.height = pRoot->drawable.height;
-    rep.window = stuff->window;
-    rep.screen = stuff->screen;
+    rep = (xPanoramiXGetScreenSizeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .width = pRoot->drawable.width,
+        .height = pRoot->drawable.height,
+        .window = stuff->window,
+        .screen = stuff->screen
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -241,11 +248,12 @@ ProcRRXineramaIsActive(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xXineramaIsActiveReq);
 
-    memset(&rep, 0, sizeof(xXineramaIsActiveReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.state = RRXineramaScreenActive(screenInfo.screens[RR_XINERAMA_SCREEN]);
+    rep = (xXineramaIsActiveReply) {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence,
+        .state = RRXineramaScreenActive(screenInfo.screens[RR_XINERAMA_SCREEN])
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -308,10 +316,12 @@ ProcRRXineramaQueryScreens(ClientPtr client)
         n = RRXineramaScreenCount(pScreen);
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.number = n;
-    rep.length = bytes_to_int32(n * sz_XineramaScreenInfo);
+    rep = (xXineramaQueryScreensReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(n * sz_XineramaScreenInfo),
+        .number = n
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
commit a406bd07593edb69285cf2fd91a6af4a5d956817
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in xkb Replies
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/xkb/xkb.c b/xkb/xkb.c
index b21815c..ad837c8 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -181,13 +181,14 @@ ProcXkbUseExtension(ClientPtr client)
              stuff->wantedMinor, SERVER_XKB_MAJOR_VERSION,
              SERVER_XKB_MINOR_VERSION);
     }
-    memset(&rep, 0, sizeof(xkbUseExtensionReply));
-    rep.type = X_Reply;
-    rep.supported = supported;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.serverMajor = SERVER_XKB_MAJOR_VERSION;
-    rep.serverMinor = SERVER_XKB_MINOR_VERSION;
+    rep = (xkbUseExtensionReply) {
+        .type = X_Reply,
+        .supported = supported,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .serverMajor = SERVER_XKB_MAJOR_VERSION,
+        .serverMinor = SERVER_XKB_MINOR_VERSION
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.serverMajor);
@@ -577,21 +578,22 @@ ProcXkbGetState(ClientPtr client)
     CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
 
     xkb = &dev->key->xkbInfo->state;
-    memset(&rep, 0, sizeof(xkbGetStateReply));
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.deviceID = dev->id;
-    rep.mods = XkbStateFieldFromRec(xkb) & 0xff;
-    rep.baseMods = xkb->base_mods;
-    rep.lockedMods = xkb->locked_mods;
-    rep.latchedMods = xkb->latched_mods;
-    rep.group = xkb->group;
-    rep.baseGroup = xkb->base_group;
-    rep.latchedGroup = xkb->latched_group;
-    rep.lockedGroup = xkb->locked_group;
-    rep.compatState = xkb->compat_state;
-    rep.ptrBtnState = xkb->ptr_buttons;
+    rep = (xkbGetStateReply) {
+        .type = X_Reply,
+        .deviceID = dev->id,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .mods = XkbStateFieldFromRec(xkb) & 0xff,
+        .baseMods = xkb->base_mods,
+        .latchedMods = xkb->latched_mods,
+        .lockedMods = xkb->locked_mods,
+        .group = xkb->group,
+        .lockedGroup = xkb->locked_group,
+        .baseGroup = xkb->base_group,
+        .latchedGroup = xkb->latched_group,
+        .compatState = xkb->compat_state,
+        .ptrBtnState = xkb->ptr_buttons
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.ptrBtnState);
@@ -688,36 +690,38 @@ ProcXkbGetControls(ClientPtr client)
     CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
 
     xkb = dev->key->xkbInfo->desc->ctrls;
-    rep.type = X_Reply;
-    rep.length = bytes_to_int32(SIZEOF(xkbGetControlsReply) -
-                                SIZEOF(xGenericReply));
-    rep.sequenceNumber = client->sequence;
-    rep.deviceID = ((DeviceIntPtr) dev)->id;
-    rep.numGroups = xkb->num_groups;
-    rep.groupsWrap = xkb->groups_wrap;
-    rep.internalMods = xkb->internal.mask;
-    rep.ignoreLockMods = xkb->ignore_lock.mask;
-    rep.internalRealMods = xkb->internal.real_mods;
-    rep.ignoreLockRealMods = xkb->ignore_lock.real_mods;
-    rep.internalVMods = xkb->internal.vmods;
-    rep.ignoreLockVMods = xkb->ignore_lock.vmods;
-    rep.enabledCtrls = xkb->enabled_ctrls;
-    rep.repeatDelay = xkb->repeat_delay;
-    rep.repeatInterval = xkb->repeat_interval;
-    rep.slowKeysDelay = xkb->slow_keys_delay;
-    rep.debounceDelay = xkb->debounce_delay;
-    rep.mkDelay = xkb->mk_delay;
-    rep.mkInterval = xkb->mk_interval;
-    rep.mkTimeToMax = xkb->mk_time_to_max;
-    rep.mkMaxSpeed = xkb->mk_max_speed;
-    rep.mkCurve = xkb->mk_curve;
-    rep.mkDfltBtn = xkb->mk_dflt_btn;
-    rep.axTimeout = xkb->ax_timeout;
-    rep.axtCtrlsMask = xkb->axt_ctrls_mask;
-    rep.axtCtrlsValues = xkb->axt_ctrls_values;
-    rep.axtOptsMask = xkb->axt_opts_mask;
-    rep.axtOptsValues = xkb->axt_opts_values;
-    rep.axOptions = xkb->ax_options;
+    rep = (xkbGetControlsReply) {
+        .type = X_Reply,
+        .deviceID = ((DeviceIntPtr) dev)->id,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(SIZEOF(xkbGetControlsReply) -
+                                 SIZEOF(xGenericReply)),
+        .mkDfltBtn = xkb->mk_dflt_btn,
+        .numGroups = xkb->num_groups,
+        .groupsWrap = xkb->groups_wrap,
+        .internalMods = xkb->internal.mask,
+        .ignoreLockMods = xkb->ignore_lock.mask,
+        .internalRealMods = xkb->internal.real_mods,
+        .ignoreLockRealMods = xkb->ignore_lock.real_mods,
+        .internalVMods = xkb->internal.vmods,
+        .ignoreLockVMods = xkb->ignore_lock.vmods,
+        .repeatDelay = xkb->repeat_delay,
+        .repeatInterval = xkb->repeat_interval,
+        .slowKeysDelay = xkb->slow_keys_delay,
+        .debounceDelay = xkb->debounce_delay,
+        .mkDelay = xkb->mk_delay,
+        .mkInterval = xkb->mk_interval,
+        .mkTimeToMax = xkb->mk_time_to_max,
+        .mkMaxSpeed = xkb->mk_max_speed,
+        .mkCurve = xkb->mk_curve,
+        .axOptions = xkb->ax_options,
+        .axTimeout = xkb->ax_timeout,
+        .axtOptsMask = xkb->axt_opts_mask,
+        .axtOptsValues = xkb->axt_opts_values,
+        .axtCtrlsMask = xkb->axt_ctrls_mask,
+        .axtCtrlsValues = xkb->axt_ctrls_values,
+        .enabledCtrls = xkb->enabled_ctrls,
+    };
     memcpy(rep.perKeyRepeat, xkb->per_key_repeat, XkbPerKeyBitArraySize);
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -1459,14 +1463,16 @@ ProcXkbGetMap(ClientPtr client)
     CHK_MASK_LEGAL(0x03, stuff->partial, XkbAllMapComponentsMask);
 
     xkb = dev->key->xkbInfo->desc;
-    memset(&rep, 0, sizeof(xkbGetMapReply));
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = (SIZEOF(xkbGetMapReply) - SIZEOF(xGenericReply)) >> 2;
-    rep.deviceID = dev->id;
-    rep.present = stuff->partial | stuff->full;
-    rep.minKeyCode = xkb->min_key_code;
-    rep.maxKeyCode = xkb->max_key_code;
+    rep = (xkbGetMapReply) {
+        .type = X_Reply,
+        .deviceID = dev->id,
+        .sequenceNumber = client->sequence,
+        .length = (SIZEOF(xkbGetMapReply) - SIZEOF(xGenericReply)) >> 2,
+        .present = stuff->partial | stuff->full,
+        .minKeyCode = xkb->min_key_code,
+        .maxKeyCode = xkb->max_key_code
+    };
+
     if (stuff->full & XkbKeyTypesMask) {
         rep.firstType = 0;
         rep.nTypes = xkb->map->num_types;
@@ -2771,12 +2777,14 @@ ProcXkbGetCompatMap(ClientPtr client)
     xkb = dev->key->xkbInfo->desc;
     compat = xkb->compat;
 
-    rep.type = X_Reply;
-    rep.deviceID = dev->id;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.firstSI = stuff->firstSI;
-    rep.nSI = stuff->nSI;
+    rep = (xkbGetCompatMapReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .deviceID = dev->id,
+        .firstSI = stuff->firstSI,
+        .nSI = stuff->nSI
+    };
     if (stuff->getAllSI) {
         rep.firstSI = 0;
         rep.nSI = compat->num_si;
@@ -3034,11 +3042,13 @@ ProcXkbGetIndicatorState(ClientPtr client)
     if (!sli)
         return BadAlloc;
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.deviceID = dev->id;
-    rep.state = sli->effectiveState;
+    rep = (xkbGetIndicatorStateReply) {
+        .type = X_Reply,
+        .deviceID = dev->id,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .state = sli->effectiveState
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -3145,11 +3155,13 @@ ProcXkbGetIndicatorMap(ClientPtr client)
     xkb = dev->key->xkbInfo->desc;
     leds = xkb->indicators;
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.deviceID = dev->id;
-    rep.which = stuff->which;
+    rep = (xkbGetIndicatorMapReply) {
+        .type = X_Reply,
+        .deviceID = dev->id,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .which = stuff->which
+    };
     XkbComputeGetIndicatorMapReplySize(leds, &rep);
     return XkbSendIndicatorMap(client, leds, &rep);
 }
@@ -3300,11 +3312,13 @@ ProcXkbGetNamedIndicator(ClientPtr client)
         }
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.deviceID = dev->id;
-    rep.indicator = stuff->indicator;
+    rep = (xkbGetNamedIndicatorReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .deviceID = dev->id,
+        .indicator = stuff->indicator
+    };
     if (map != NULL) {
         rep.found = TRUE;
         rep.on = ((sli->effectiveState & (1 << i)) != 0);
@@ -3880,22 +3894,18 @@ ProcXkbGetNames(ClientPtr client)
     CHK_MASK_LEGAL(0x01, stuff->which, XkbAllNamesMask);
 
     xkb = dev->key->xkbInfo->desc;
-    memset(&rep, 0, sizeof(xkbGetNamesReply));
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.deviceID = dev->id;
-    rep.which = stuff->which;
-    rep.nTypes = xkb->map->num_types;
-    rep.firstKey = xkb->min_key_code;
-    rep.nKeys = XkbNumKeys(xkb);
-    if (xkb->names != NULL) {
-        rep.nKeyAliases = xkb->names->num_key_aliases;
-        rep.nRadioGroups = xkb->names->num_rg;
-    }
-    else {
-        rep.nKeyAliases = rep.nRadioGroups = 0;
-    }
+    rep = (xkbGetNamesReply) {
+        .type = X_Reply,
+        .deviceID = dev->id,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .which = stuff->which,
+        .nTypes = xkb->map->num_types,
+        .firstKey = xkb->min_key_code,
+        .nKeys = XkbNumKeys(xkb),
+        .nKeyAliases = xkb->names ? xkb->names->num_key_aliases : 0,
+        .nRadioGroups = xkb->names ? xkb->names->num_rg : 0
+    };
     XkbComputeGetNamesReplySize(xkb, &rep);
     return XkbSendNames(client, xkb, &rep);
 }
@@ -4933,10 +4943,12 @@ ProcXkbGetGeometry(ClientPtr client)
     CHK_ATOM_OR_NONE(stuff->name);
 
     geom = XkbLookupNamedGeometry(dev, stuff->name, &shouldFree);
-    rep.type = X_Reply;
-    rep.deviceID = dev->id;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
+    rep = (xkbGetGeometryReply) {
+        .type = X_Reply,
+        .deviceID = dev->id,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     status = XkbComputeGetGeometryReplySize(geom, &rep, stuff->name);
     if (status != Success)
         return status;
@@ -5483,10 +5495,6 @@ ProcXkbPerClientFlags(ClientPtr client)
     CHK_MASK_MATCH(0x02, stuff->change, stuff->value);
 
     interest = XkbFindClientResource((DevicePtr) dev, client);
-    memset(&rep, 0, sizeof(xkbPerClientFlagsReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
     if (stuff->change) {
         client->xkbClientFlags &= ~stuff->change;
         client->xkbClientFlags |= stuff->value;
@@ -5522,15 +5530,16 @@ ProcXkbPerClientFlags(ClientPtr client)
             interest->autoCtrlValues |= stuff->autoCtrlValues & affect;
         }
     }
-    rep.supported = XkbPCF_AllFlagsMask;
-    rep.value = client->xkbClientFlags & XkbPCF_AllFlagsMask;
-    if (interest) {
-        rep.autoCtrls = interest->autoCtrls;
-        rep.autoCtrlValues = interest->autoCtrlValues;
-    }
-    else {
-        rep.autoCtrls = rep.autoCtrlValues = 0;
-    }
+
+    rep = (xkbPerClientFlagsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .supported = XkbPCF_AllFlagsMask,
+        .value = client->xkbClientFlags & XkbPCF_AllFlagsMask,
+        .autoCtrls = interest ? interest->autoCtrls : 0,
+        .autoCtrlValues =  interest ? interest->autoCtrlValues : 0,
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.supported);
@@ -5642,18 +5651,19 @@ ProcXkbListComponents(ClientPtr client)
         list.pool = NULL;
         return status;
     }
-    memset(&rep, 0, sizeof(xkbListComponentsReply));
-    rep.type = X_Reply;
-    rep.deviceID = dev->id;
-    rep.sequenceNumber = client->sequence;
-    rep.length = XkbPaddedSize(list.nPool) / 4;
-    rep.nKeymaps = 0;
-    rep.nKeycodes = list.nFound[_XkbListKeycodes];
-    rep.nTypes = list.nFound[_XkbListTypes];
-    rep.nCompatMaps = list.nFound[_XkbListCompat];
-    rep.nSymbols = list.nFound[_XkbListSymbols];
-    rep.nGeometries = list.nFound[_XkbListGeometry];
-    rep.extra = 0;
+    rep = (xkbListComponentsReply) {
+        .type = X_Reply,
+        .deviceID = dev->id,
+        .sequenceNumber = client->sequence,
+        .length = XkbPaddedSize(list.nPool) / 4,
+        .nKeymaps = 0,
+        .nKeycodes = list.nFound[_XkbListKeycodes],
+        .nTypes = list.nFound[_XkbListTypes],
+        .nCompatMaps = list.nFound[_XkbListCompat],
+        .nSymbols = list.nFound[_XkbListSymbols],
+        .nGeometries = list.nFound[_XkbListGeometry],
+        .extra = 0
+    };
     if (list.nTotal > list.maxRtrn)
         rep.extra = (list.nTotal - list.maxRtrn);
     if (client->swapped) {
@@ -6254,37 +6264,29 @@ ProcXkbGetDeviceInfo(ClientPtr client)
         wanted &= ~XkbXI_IndicatorsMask;
 
     nameLen = XkbSizeCountedString(dev->name);
-    memset((char *) &rep, 0, SIZEOF(xkbGetDeviceInfoReply));
-    rep.type = X_Reply;
-    rep.deviceID = dev->id;
-    rep.sequenceNumber = client->sequence;
-    rep.length = nameLen / 4;
-    rep.present = wanted;
-    rep.supported = XkbXI_AllDeviceFeaturesMask;
-    rep.unsupported = 0;
-    rep.firstBtnWanted = rep.nBtnsWanted = 0;
-    rep.firstBtnRtrn = rep.nBtnsRtrn = 0;
-    if (dev->button)
-        rep.totalBtns = dev->button->numButtons;
-    else
-        rep.totalBtns = 0;
-    rep.devType = dev->xinput_type;
-    rep.hasOwnState = (dev->key && dev->key->xkbInfo);
-    rep.nDeviceLedFBs = 0;
-    if (dev->kbdfeed)
-        rep.dfltKbdFB = dev->kbdfeed->ctrl.id;
-    else
-        rep.dfltKbdFB = XkbXINone;
-    if (dev->leds)
-        rep.dfltLedFB = dev->leds->ctrl.id;
-    else
-        rep.dfltLedFB = XkbXINone;
+    rep = (xkbGetDeviceInfoReply) {
+        .type = X_Reply,
+        .deviceID = dev->id,
+        .sequenceNumber = client->sequence,
+        .length = nameLen / 4,
+        .present = wanted,
+        .supported = XkbXI_AllDeviceFeaturesMask,
+        .unsupported = 0,
+        .nDeviceLedFBs = 0,
+        .firstBtnWanted = 0,
+        .nBtnsWanted = 0,
+        .firstBtnRtrn = 0,
+        .nBtnsRtrn = 0,
+        .totalBtns = dev->button ? dev->button->numButtons : 0,
+        .hasOwnState = (dev->key && dev->key->xkbInfo),
+        .dfltKbdFB = dev->kbdfeed ? dev->kbdfeed->ctrl.id : XkbXINone,
+        .dfltLedFB = dev->leds ? dev->leds->ctrl.id : XkbXINone,
+        .devType = dev->xinput_type
+    };
 
     ledClass = stuff->ledClass;
     ledID = stuff->ledID;
 
-    rep.firstBtnWanted = rep.nBtnsWanted = 0;
-    rep.firstBtnRtrn = rep.nBtnsRtrn = 0;
     if (wanted & XkbXI_ButtonActionsMask) {
         if (stuff->allBtns) {
             stuff->firstBtn = 0;
@@ -6746,13 +6748,15 @@ ProcXkbSetDebuggingFlags(ClientPtr client)
     xkbDebugFlags = newFlags;
     xkbDebugCtrls = newCtrls;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.currentFlags = newFlags;
-    rep.currentCtrls = newCtrls;
-    rep.supportedFlags = ~0;
-    rep.supportedCtrls = ~0;
+    rep = (xkbSetDebuggingFlagsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .currentFlags = newFlags,
+        .currentCtrls = newCtrls,
+        .supportedFlags = ~0,
+        .supportedCtrls = ~0
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.currentFlags);
commit 26efa09d0c7ee2f6a18547205c84be75376e688b
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in glx Replies
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index c1c836f..c1f4e22 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -651,17 +651,17 @@ DoMakeCurrent(__GLXclientState * cl,
 
     StopUsingContext(prevglxc);
 
+    reply = (xGLXMakeCurrentReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .contextTag = 0
+    };
+
     if (glxc) {
         StartUsingContext(cl, glxc);
         reply.contextTag = glxc->id;
     }
-    else {
-        reply.contextTag = 0;
-    }
-
-    reply.length = 0;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
 
     if (client->swapped) {
         __glXSwapMakeCurrentReply(client, &reply);
@@ -722,10 +722,12 @@ __glXDisp_IsDirect(__GLXclientState * cl, GLbyte * pc)
     if (!validGlxContext(cl->client, req->context, DixReadAccess, &glxc, &err))
         return err;
 
-    reply.isDirect = glxc->isDirect;
-    reply.length = 0;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXIsDirectReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .isDirect = glxc->isDirect
+    };
 
     if (client->swapped) {
         __glXSwapIsDirectReply(client, &reply);
@@ -757,11 +759,13 @@ __glXDisp_QueryVersion(__GLXclientState * cl, GLbyte * pc)
      ** client if it wants to work with older clients; however, in this
      ** implementation the server just returns its version number.
      */
-    reply.majorVersion = glxMajorVersion;
-    reply.minorVersion = glxMinorVersion;
-    reply.length = 0;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXQueryVersionReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = glxMajorVersion,
+        .minorVersion = glxMinorVersion
+    };
 
     if (client->swapped) {
         __glXSwapQueryVersionReply(client, &reply);
@@ -935,12 +939,14 @@ __glXDisp_GetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
     if (!validGlxScreen(cl->client, req->screen, &pGlxScreen, &err))
         return err;
 
-    reply.numVisuals = pGlxScreen->numVisuals;
-    reply.numProps = GLX_VIS_CONFIG_TOTAL;
-    reply.length =
-        (reply.numVisuals * __GLX_SIZE_CARD32 * GLX_VIS_CONFIG_TOTAL) >> 2;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXGetVisualConfigsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = (pGlxScreen->numVisuals *
+                   __GLX_SIZE_CARD32 * GLX_VIS_CONFIG_TOTAL) >> 2,
+        .numVisuals = pGlxScreen->numVisuals,
+        .numProps = GLX_VIS_CONFIG_TOTAL
+    };
 
     if (client->swapped) {
         __GLX_SWAP_SHORT(&reply.sequenceNumber);
@@ -1039,11 +1045,13 @@ DoGetFBConfigs(__GLXclientState * cl, unsigned screen)
     if (!validGlxScreen(cl->client, screen, &pGlxScreen, &err))
         return err;
 
-    reply.numFBConfigs = pGlxScreen->numFBConfigs;
-    reply.numAttribs = __GLX_TOTAL_FBCONFIG_ATTRIBS;
-    reply.length = (__GLX_FBCONFIG_ATTRIBS_LENGTH * reply.numFBConfigs);
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGLXGetFBConfigsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = __GLX_FBCONFIG_ATTRIBS_LENGTH * pGlxScreen->numFBConfigs,
+        .numFBConfigs = pGlxScreen->numFBConfigs,
+        .numAttribs = __GLX_TOTAL_FBCONFIG_ATTRIBS
+    };
 
     if (client->swapped) {
         __GLX_SWAP_SHORT(&reply.sequenceNumber);
@@ -1663,10 +1671,12 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId)
         return err;
 
     nProps = 3;
-    reply.length = nProps << 1;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.n = nProps;
+    reply = (xGLXQueryContextInfoEXTReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = nProps << 1,
+        .n = nProps
+    };
 
     nReplyBytes = reply.length << 2;
     sendBuf = (int *) malloc((size_t) nReplyBytes);
@@ -1870,10 +1880,12 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
         return error;
 
     numAttribs = 3;
-    reply.length = numAttribs << 1;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.numAttribs = numAttribs;
+    reply = (xGLXGetDrawableAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = numAttribs << 1,
+        .numAttribs = numAttribs
+    };
 
     attributes[0] = GLX_TEXTURE_TARGET_EXT;
     attributes[1] = pGlxDraw->target == GL_TEXTURE_2D ? GLX_TEXTURE_2D_EXT :
@@ -2309,10 +2321,12 @@ __glXDisp_QueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
 
     n = strlen(pGlxScreen->GLXextensions) + 1;
     length = __GLX_PAD(n) >> 2;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = length;
-    reply.n = n;
+    reply = (xGLXQueryExtensionsStringReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = length,
+        .n = n
+    };
 
     /* Allocate buffer to make sure it's a multiple of 4 bytes big. */
     buf = calloc(length, 4);
@@ -2370,10 +2384,12 @@ __glXDisp_QueryServerString(__GLXclientState * cl, GLbyte * pc)
 
     n = strlen(ptr) + 1;
     length = __GLX_PAD(n) >> 2;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = length;
-    reply.n = n;
+    reply = (xGLXQueryServerStringReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = length,
+        .n = n
+    };
 
     buf = calloc(length, 4);
     if (buf == NULL) {
diff --git a/glx/single2.c b/glx/single2.c
index 4d8ea4e..9597d29 100644
--- a/glx/single2.c
+++ b/glx/single2.c
@@ -193,12 +193,14 @@ __glXDisp_RenderMode(__GLXclientState * cl, GLbyte * pc)
      */
  noChangeAllowed:;
     client = cl->client;
-    reply.length = nitems;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.retval = retval;
-    reply.size = nitems;
-    reply.newMode = newMode;
+    reply = (xGLXRenderModeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = nitems,
+        .retval = retval,
+        .size = nitems,
+        .newMode = newMode
+    };
     WriteToClient(client, sz_xGLXRenderModeReply, &reply);
     if (retBytes) {
         WriteToClient(client, retBytes, retBuffer);
diff --git a/glx/single2swap.c b/glx/single2swap.c
index 9da2afd..1ca5328 100644
--- a/glx/single2swap.c
+++ b/glx/single2swap.c
@@ -205,12 +205,14 @@ __glXDispSwap_RenderMode(__GLXclientState * cl, GLbyte * pc)
      */
  noChangeAllowed:;
     client = cl->client;
-    reply.length = nitems;
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.retval = retval;
-    reply.size = nitems;
-    reply.newMode = newMode;
+    reply = (xGLXRenderModeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = nitems,
+        .retval = retval,
+        .size = nitems,
+        .newMode = newMode
+    };
     __GLX_SWAP_SHORT(&reply.sequenceNumber);
     __GLX_SWAP_INT(&reply.length);
     __GLX_SWAP_INT(&reply.retval);
commit cc5f09c86f7bea23b7546c3491b2c52ce8100a71
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in various extension Replies
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/composite/compext.c b/composite/compext.c
index be25b27..eea1a58 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -107,14 +107,15 @@ static int
 ProcCompositeQueryVersion(ClientPtr client)
 {
     CompositeClientPtr pCompositeClient = GetCompositeClient(client);
-    xCompositeQueryVersionReply rep;
+    xCompositeQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     REQUEST(xCompositeQueryVersionReq);
 
     REQUEST_SIZE_MATCH(xCompositeQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
     if (stuff->majorVersion < SERVER_COMPOSITE_MAJOR_VERSION) {
         rep.majorVersion = stuff->majorVersion;
         rep.minorVersion = stuff->minorVersion;
@@ -311,10 +312,12 @@ ProcCompositeGetOverlayWindow(ClientPtr client)
         return rc;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.overlayWin = cs->pOverlayWin->drawable.id;
+    rep = (xCompositeGetOverlayWindowReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .overlayWin = cs->pOverlayWin->drawable.id
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -842,10 +845,12 @@ PanoramiXCompositeGetOverlayWindow(ClientPtr client)
 
     cs = GetCompScreen(screenInfo.screens[0]);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.overlayWin = cs->pOverlayWin->drawable.id;
+    rep = (xCompositeGetOverlayWindowReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .overlayWin = cs->pOverlayWin->drawable.id
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
diff --git a/damageext/damageext.c b/damageext/damageext.c
index 70d2eee..2eddfb3 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -126,14 +126,16 @@ static int
 ProcDamageQueryVersion(ClientPtr client)
 {
     DamageClientPtr pDamageClient = GetDamageClient(client);
-    xDamageQueryVersionReply rep;
+    xDamageQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     REQUEST(xDamageQueryVersionReq);
 
     REQUEST_SIZE_MATCH(xDamageQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+
     if (stuff->majorVersion < SERVER_DAMAGE_MAJOR_VERSION) {
         rep.majorVersion = stuff->majorVersion;
         rep.minorVersion = stuff->minorVersion;
diff --git a/dbe/dbe.c b/dbe/dbe.c
index d8010ff..8f3d1b0 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -118,16 +118,16 @@ static int
 ProcDbeGetVersion(ClientPtr client)
 {
     /* REQUEST(xDbeGetVersionReq); */
-    xDbeGetVersionReply rep;
+    xDbeGetVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = DBE_MAJOR_VERSION,
+        .minorVersion = DBE_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xDbeGetVersionReq);
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = DBE_MAJOR_VERSION;
-    rep.minorVersion = DBE_MINOR_VERSION;
-
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
     }
@@ -667,10 +667,12 @@ ProcDbeGetVisualInfo(ClientPtr client)
         length += pScrVisInfo[i].count * sizeof(xDbeVisInfo);
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = bytes_to_int32(length);
-    rep.m = count;
+    rep = (xDbeGetVisualInfoReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(length),
+        .m = count
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -755,7 +757,11 @@ static int
 ProcDbeGetBackBufferAttributes(ClientPtr client)
 {
     REQUEST(xDbeGetBackBufferAttributesReq);
-    xDbeGetBackBufferAttributesReply rep;
+    xDbeGetBackBufferAttributesReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     DbeWindowPrivPtr pDbeWindowPriv;
     int rc;
 
@@ -771,10 +777,6 @@ ProcDbeGetBackBufferAttributes(ClientPtr client)
         rep.attributes = None;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
diff --git a/record/record.c b/record/record.c
index 54a0e68..67569d9 100644
--- a/record/record.c
+++ b/record/record.c
@@ -1816,14 +1816,15 @@ static int
 ProcRecordQueryVersion(ClientPtr client)
 {
     /* REQUEST(xRecordQueryVersionReq); */
-    xRecordQueryVersionReply rep;
+    xRecordQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_RECORD_MAJOR_VERSION,
+        .minorVersion = SERVER_RECORD_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xRecordQueryVersionReq);
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.majorVersion = SERVER_RECORD_MAJOR_VERSION;
-    rep.minorVersion = SERVER_RECORD_MINOR_VERSION;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.majorVersion);
@@ -2231,12 +2232,14 @@ ProcRecordGetContext(ClientPtr client)
 
     /* write the reply header */
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = length;
-    rep.enabled = pContext->pRecordingClient != NULL;
-    rep.elementHeader = pContext->elemHeaders;
-    rep.nClients = nClients;
+    rep = (xRecordGetContextReply) {
+        .type = X_Reply,
+        .enabled = pContext->pRecordingClient != NULL,
+        .sequenceNumber = client->sequence,
+        .length = length,
+        .elementHeader = pContext->elemHeaders,
+        .nClients = nClients
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
diff --git a/render/render.c b/render/render.c
index 3bf0702..5301811 100644
--- a/render/render.c
+++ b/render/render.c
@@ -267,7 +267,11 @@ static int
 ProcRenderQueryVersion(ClientPtr client)
 {
     RenderClientPtr pRenderClient = GetRenderClient(client);
-    xRenderQueryVersionReply rep;
+    xRenderQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     REQUEST(xRenderQueryVersionReq);
 
@@ -275,10 +279,6 @@ ProcRenderQueryVersion(ClientPtr client)
     pRenderClient->minor_version = stuff->minorVersion;
 
     REQUEST_SIZE_MATCH(xRenderQueryVersionReq);
-    memset(&rep, 0, sizeof(xRenderQueryVersionReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
 
     if ((stuff->majorVersion * 1000 + stuff->minorVersion) <
         (SERVER_RENDER_MAJOR_VERSION * 1000 + SERVER_RENDER_MINOR_VERSION)) {
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 402456d..68f7b74 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -474,11 +474,13 @@ ProcXFixesGetCursorName(ClientPtr client)
         str = "";
     len = strlen(str);
 
-    reply.type = X_Reply;
-    reply.length = bytes_to_int32(len);
-    reply.sequenceNumber = client->sequence;
-    reply.atom = pCursor->name;
-    reply.nbytes = len;
+    reply = (xXFixesGetCursorNameReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(len),
+        .atom = pCursor->name,
+        .nbytes = len
+    };
     if (client->swapped) {
         swaps(&reply.sequenceNumber);
         swapl(&reply.length);
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index 54f84f4..c6dd19e 100644
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -61,15 +61,15 @@ static int
 ProcXFixesQueryVersion(ClientPtr client)
 {
     XFixesClientPtr pXFixesClient = GetXFixesClient(client);
-    xXFixesQueryVersionReply rep;
+    xXFixesQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     REQUEST(xXFixesQueryVersionReq);
 
     REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
-    memset(&rep, 0, sizeof(xXFixesQueryVersionReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
 
     if (version_compare(stuff->majorVersion, stuff->minorVersion,
                         SERVER_XFIXES_MAJOR_VERSION,
commit 2f5caeaddb3616dc9ff57d784f7feba589c536e7
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in Xinput Replies
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xi/chgdctl.c b/Xi/chgdctl.c
index 0de5f2b..caef0bf 100644
--- a/Xi/chgdctl.c
+++ b/Xi/chgdctl.c
@@ -123,10 +123,12 @@ ProcXChangeDeviceControl(ClientPtr client)
     if (ret != Success)
         goto out;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_ChangeDeviceControl;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xChangeDeviceControlReply) {
+        .repType = X_Reply,
+        .RepType = X_ChangeDeviceControl,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     switch (stuff->control) {
     case DEVICE_RESOLUTION:
diff --git a/Xi/getbmap.c b/Xi/getbmap.c
index 2712fcd..49b8688 100644
--- a/Xi/getbmap.c
+++ b/Xi/getbmap.c
@@ -92,11 +92,13 @@ ProcXGetDeviceButtonMapping(ClientPtr client)
     REQUEST(xGetDeviceButtonMappingReq);
     REQUEST_SIZE_MATCH(xGetDeviceButtonMappingReq);
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GetDeviceButtonMapping;
-    rep.nElts = 0;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xGetDeviceButtonMappingReply) {
+        .repType = X_Reply,
+        .RepType = X_GetDeviceButtonMapping,
+        .sequenceNumber = client->sequence,
+        .nElts = 0,
+        .length = 0
+    };
 
     rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
     if (rc != Success)
diff --git a/Xi/getdctl.c b/Xi/getdctl.c
index 27775e2..6f73e09 100644
--- a/Xi/getdctl.c
+++ b/Xi/getdctl.c
@@ -182,10 +182,12 @@ ProcXGetDeviceControl(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GetDeviceControl;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xGetDeviceControlReply) {
+        .repType = X_Reply,
+        .RepType = X_GetDeviceControl,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     switch (stuff->control) {
     case DEVICE_RESOLUTION:
diff --git a/Xi/getfctl.c b/Xi/getfctl.c
index 5f97cc3..599b2ef 100644
--- a/Xi/getfctl.c
+++ b/Xi/getfctl.c
@@ -295,11 +295,13 @@ ProcXGetFeedbackControl(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GetFeedbackControl;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.num_feedbacks = 0;
+    rep = (xGetFeedbackControlReply) {
+        .repType = X_Reply,
+        .RepType = X_GetFeedbackControl,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .num_feedbacks = 0
+    };
 
     for (k = dev->kbdfeed; k; k = k->next) {
         rep.num_feedbacks++;
diff --git a/Xi/getfocus.c b/Xi/getfocus.c
index 54c176f..40546cb 100644
--- a/Xi/getfocus.c
+++ b/Xi/getfocus.c
@@ -99,10 +99,12 @@ ProcXGetDeviceFocus(ClientPtr client)
     if (!dev->focus)
         return BadDevice;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GetDeviceFocus;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xGetDeviceFocusReply) {
+        .repType = X_Reply,
+        .RepType = X_GetDeviceFocus,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     focus = dev->focus;
 
diff --git a/Xi/getkmap.c b/Xi/getkmap.c
index 3536879..87c1977 100644
--- a/Xi/getkmap.c
+++ b/Xi/getkmap.c
@@ -119,11 +119,13 @@ ProcXGetDeviceKeyMapping(ClientPtr client)
     if (!syms)
         return BadAlloc;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GetDeviceKeyMapping;
-    rep.sequenceNumber = client->sequence;
-    rep.keySymsPerKeyCode = syms->mapWidth;
-    rep.length = (syms->mapWidth * stuff->count);       /* KeySyms are 4 bytes */
+    rep = (xGetDeviceKeyMappingReply) {
+        .repType = X_Reply,
+        .RepType = X_GetDeviceKeyMapping,
+        .sequenceNumber = client->sequence,
+        .keySymsPerKeyCode = syms->mapWidth,
+        .length = (syms->mapWidth * stuff->count) /* KeySyms are 4 bytes */
+    };
     WriteReplyToClient(client, sizeof(xGetDeviceKeyMappingReply), &rep);
 
     client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
diff --git a/Xi/getmmap.c b/Xi/getmmap.c
index 97d4c0d..f07f2bb 100644
--- a/Xi/getmmap.c
+++ b/Xi/getmmap.c
@@ -101,12 +101,14 @@ ProcXGetDeviceModifierMapping(ClientPtr client)
     if (ret != Success)
         return ret;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GetDeviceModifierMapping;
-    rep.numKeyPerModifier = max_keys_per_mod;
-    rep.sequenceNumber = client->sequence;
+    rep = (xGetDeviceModifierMappingReply) {
+        .repType = X_Reply,
+        .RepType = X_GetDeviceModifierMapping,
+        .sequenceNumber = client->sequence,
+        .numKeyPerModifier = max_keys_per_mod,
     /* length counts 4 byte quantities - there are 8 modifiers 1 byte big */
-    rep.length = max_keys_per_mod << 1;
+        .length = max_keys_per_mod << 1
+    };
 
     WriteReplyToClient(client, sizeof(xGetDeviceModifierMappingReply), &rep);
     WriteToClient(client, max_keys_per_mod * 8, modkeymap);
diff --git a/Xi/getprop.c b/Xi/getprop.c
index b5af13a..4d6ce63 100644
--- a/Xi/getprop.c
+++ b/Xi/getprop.c
@@ -101,11 +101,13 @@ ProcXGetDeviceDontPropagateList(ClientPtr client)
     REQUEST(xGetDeviceDontPropagateListReq);
     REQUEST_SIZE_MATCH(xGetDeviceDontPropagateListReq);
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GetDeviceDontPropagateList;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.count = 0;
+    rep = (xGetDeviceDontPropagateListReply) {
+        .repType = X_Reply,
+        .RepType = X_GetDeviceDontPropagateList,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .count = 0
+    };
 
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
diff --git a/Xi/getselev.c b/Xi/getselev.c
index 4fcc902..60a46c2 100644
--- a/Xi/getselev.c
+++ b/Xi/getselev.c
@@ -102,12 +102,14 @@ ProcXGetSelectedExtensionEvents(ClientPtr client)
     REQUEST(xGetSelectedExtensionEventsReq);
     REQUEST_SIZE_MATCH(xGetSelectedExtensionEventsReq);
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GetSelectedExtensionEvents;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.this_client_count = 0;
-    rep.all_clients_count = 0;
+    rep = (xGetSelectedExtensionEventsReply) {
+        .repType = X_Reply,
+        .RepType = X_GetSelectedExtensionEvents,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .this_client_count = 0,
+        .all_clients_count = 0
+    };
 
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
diff --git a/Xi/getvers.c b/Xi/getvers.c
index b380344..829e695 100644
--- a/Xi/getvers.c
+++ b/Xi/getvers.c
@@ -98,14 +98,15 @@ ProcXGetExtensionVersion(ClientPtr client)
                                         stuff->nbytes))
         return BadLength;
 
-    memset(&rep, 0, sizeof(xGetExtensionVersionReply));
-    rep.repType = X_Reply;
-    rep.RepType = X_GetExtensionVersion;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.present = TRUE;
-    rep.major_version = XIVersion.major_version;
-    rep.minor_version = XIVersion.minor_version;
+    rep = (xGetExtensionVersionReply) {
+        .repType = X_Reply,
+        .RepType = X_GetExtensionVersion,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .major_version = XIVersion.major_version,
+        .minor_version = XIVersion.minor_version,
+        .present = TRUE
+    };
 
     WriteReplyToClient(client, sizeof(xGetExtensionVersionReply), &rep);
 
diff --git a/Xi/grabdev.c b/Xi/grabdev.c
index bdc0c4b..443ef56 100644
--- a/Xi/grabdev.c
+++ b/Xi/grabdev.c
@@ -113,10 +113,12 @@ ProcXGrabDevice(ClientPtr client)
         bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count)
         return BadLength;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GrabDevice;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
+    rep = (xGrabDeviceReply) {
+        .repType = X_Reply,
+        .RepType = X_GrabDevice,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+    };
 
     rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
     if (rc != Success)
diff --git a/Xi/gtmotion.c b/Xi/gtmotion.c
index 2249b86..4642b19 100644
--- a/Xi/gtmotion.c
+++ b/Xi/gtmotion.c
@@ -110,13 +110,15 @@ ProcXGetDeviceMotionEvents(ClientPtr client)
     if (dev->valuator->motionHintWindow)
         MaybeStopDeviceHint(dev, client);
     axes = v->numAxes;
-    rep.repType = X_Reply;
-    rep.RepType = X_GetDeviceMotionEvents;
-    rep.sequenceNumber = client->sequence;
-    rep.nEvents = 0;
-    rep.axes = axes;
-    rep.mode = Absolute;        /* XXX we don't do relative at the moment */
-    rep.length = 0;
+    rep = (xGetDeviceMotionEventsReply) {
+        .repType = X_Reply,
+        .RepType = X_GetDeviceMotionEvents,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .nEvents = 0,
+        .axes = axes,
+        .mode = Absolute        /* XXX we don't do relative at the moment */
+    };
     start = ClientTimeToServerTime(stuff->start);
     stop = ClientTimeToServerTime(stuff->stop);
     if (CompareTimeStamps(start, stop) == LATER ||
diff --git a/Xi/listdev.c b/Xi/listdev.c
index 1fff738..014c61d 100644
--- a/Xi/listdev.c
+++ b/Xi/listdev.c
@@ -342,11 +342,12 @@ ProcXListInputDevices(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xListInputDevicesReq);
 
-    memset(&rep, 0, sizeof(xListInputDevicesReply));
-    rep.repType = X_Reply;
-    rep.RepType = X_ListInputDevices;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xListInputDevicesReply) {
+        .repType = X_Reply,
+        .RepType = X_ListInputDevices,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     /* allocate space for saving skip value */
     skip = calloc(sizeof(Bool), inputInfo.numDevices);
diff --git a/Xi/opendev.c b/Xi/opendev.c
index 486ac14..6708bad 100644
--- a/Xi/opendev.c
+++ b/Xi/opendev.c
@@ -117,10 +117,6 @@ ProcXOpenDevice(ClientPtr client)
     if (status != Success)
         return status;
 
-    memset(&rep, 0, sizeof(xOpenDeviceReply));
-    rep.repType = X_Reply;
-    rep.RepType = X_OpenDevice;
-    rep.sequenceNumber = client->sequence;
     if (dev->key != NULL) {
         evbase[j].class = KeyClass;
         evbase[j++].event_type_base = event_base[KeyClass];
@@ -148,8 +144,13 @@ ProcXOpenDevice(ClientPtr client)
     }
     evbase[j].class = OtherClass;
     evbase[j++].event_type_base = event_base[OtherClass];
-    rep.length = bytes_to_int32(j * sizeof(xInputClassInfo));
-    rep.num_classes = j;
+    rep = (xOpenDeviceReply) {
+        .repType = X_Reply,
+        .RepType = X_OpenDevice,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(j * sizeof(xInputClassInfo)),
+        .num_classes = j
+    };
     WriteReplyToClient(client, sizeof(xOpenDeviceReply), &rep);
     WriteToClient(client, j * sizeof(xInputClassInfo), evbase);
     return Success;
diff --git a/Xi/queryst.c b/Xi/queryst.c
index de19974..04a652b 100644
--- a/Xi/queryst.c
+++ b/Xi/queryst.c
@@ -87,11 +87,6 @@ ProcXQueryDeviceState(ClientPtr client)
     REQUEST(xQueryDeviceStateReq);
     REQUEST_SIZE_MATCH(xQueryDeviceStateReq);
 
-    rep.repType = X_Reply;
-    rep.RepType = X_QueryDeviceState;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     rc = dixLookupDevice(&dev, stuff->deviceid, client, DixReadAccess);
     if (rc != Success && rc != BadAccess)
         return rc;
@@ -163,8 +158,13 @@ ProcXQueryDeviceState(ClientPtr client)
         }
     }
 
-    rep.num_classes = num_classes;
-    rep.length = bytes_to_int32(total_length);
+    rep = (xQueryDeviceStateReply) {
+        .repType = X_Reply,
+        .RepType = X_QueryDeviceState,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(total_length),
+        .num_classes = num_classes
+    };
     WriteReplyToClient(client, sizeof(xQueryDeviceStateReply), &rep);
     if (total_length > 0)
         WriteToClient(client, total_length, savbuf);
diff --git a/Xi/setbmap.c b/Xi/setbmap.c
index 296b439..9479655 100644
--- a/Xi/setbmap.c
+++ b/Xi/setbmap.c
@@ -100,11 +100,13 @@ ProcXSetDeviceButtonMapping(ClientPtr client)
     if (ret != Success)
         return ret;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_SetDeviceButtonMapping;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.status = MappingSuccess;
+    rep = (xSetDeviceButtonMappingReply) {
+        .repType = X_Reply,
+        .RepType = X_SetDeviceButtonMapping,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = MappingSuccess
+    };
 
     ret =
         ApplyPointerMapping(dev, (CARD8 *) &stuff[1], stuff->map_length,
diff --git a/Xi/setdval.c b/Xi/setdval.c
index 8c3816d..4c9c99f 100644
--- a/Xi/setdval.c
+++ b/Xi/setdval.c
@@ -92,11 +92,13 @@ ProcXSetDeviceValuators(ClientPtr client)
     REQUEST(xSetDeviceValuatorsReq);
     REQUEST_AT_LEAST_SIZE(xSetDeviceValuatorsReq);
 
-    rep.repType = X_Reply;
-    rep.RepType = X_SetDeviceValuators;
-    rep.length = 0;
-    rep.status = Success;
-    rep.sequenceNumber = client->sequence;
+    rep = (xSetDeviceValuatorsReply) {
+        .repType = X_Reply,
+        .RepType = X_SetDeviceValuators,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = Success
+    };
 
     if (stuff->length != bytes_to_int32(sizeof(xSetDeviceValuatorsReq)) +
         stuff->num_valuators)
diff --git a/Xi/setmmap.c b/Xi/setmmap.c
index e70038e..1320cfe 100644
--- a/Xi/setmmap.c
+++ b/Xi/setmmap.c
@@ -98,10 +98,12 @@ ProcXSetDeviceModifierMapping(ClientPtr client)
         (stuff->numKeyPerModifier << 1))
         return BadLength;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_SetDeviceModifierMapping;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xSetDeviceModifierMappingReply) {
+        .repType = X_Reply,
+        .RepType = X_SetDeviceModifierMapping,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess);
     if (ret != Success)
diff --git a/Xi/setmode.c b/Xi/setmode.c
index f212d83..5356552 100644
--- a/Xi/setmode.c
+++ b/Xi/setmode.c
@@ -92,10 +92,12 @@ ProcXSetDeviceMode(ClientPtr client)
     REQUEST(xSetDeviceModeReq);
     REQUEST_SIZE_MATCH(xSetDeviceModeReq);
 
-    rep.repType = X_Reply;
-    rep.RepType = X_SetDeviceMode;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xSetDeviceModeReply) {
+        .repType = X_Reply,
+        .RepType = X_SetDeviceMode,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
     if (rc != Success)
diff --git a/Xi/xigetclientpointer.c b/Xi/xigetclientpointer.c
index 8a5f54f..3c90d58 100644
--- a/Xi/xigetclientpointer.c
+++ b/Xi/xigetclientpointer.c
@@ -75,12 +75,14 @@ ProcXIGetClientPointer(ClientPtr client)
     else
         winclient = client;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_XIGetClientPointer;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.set = (winclient->clientPtr != NULL);
-    rep.deviceid = (winclient->clientPtr) ? winclient->clientPtr->id : 0;
+    rep = (xXIGetClientPointerReply) {
+        .repType = X_Reply,
+        .RepType = X_XIGetClientPointer,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .set = (winclient->clientPtr != NULL),
+        .deviceid = (winclient->clientPtr) ? winclient->clientPtr->id : 0
+    };
 
     WriteReplyToClient(client, sizeof(xXIGetClientPointerReply), &rep);
     return Success;
diff --git a/Xi/xigrabdev.c b/Xi/xigrabdev.c
index 095fcfa..09186e8 100644
--- a/Xi/xigrabdev.c
+++ b/Xi/xigrabdev.c
@@ -104,11 +104,13 @@ ProcXIGrabDevice(ClientPtr client)
     if (ret != Success)
         return ret;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_XIGrabDevice;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.status = status;
+    rep = (xXIGrabDeviceReply) {
+        .repType = X_Reply,
+        .RepType = X_XIGrabDevice,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .status = status
+    };
 
     WriteReplyToClient(client, sizeof(rep), &rep);
     return ret;
diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 5e4fa4e..ddab53d 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -78,7 +78,13 @@ int
 ProcXIPassiveGrabDevice(ClientPtr client)
 {
     DeviceIntPtr dev, mod_dev;
-    xXIPassiveGrabDeviceReply rep;
+    xXIPassiveGrabDeviceReply rep = {
+        .repType = X_Reply,
+        .RepType = X_XIPassiveGrabDevice,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .num_modifiers = 0
+    };
     int i, ret = Success;
     uint32_t *modifiers;
     xXIGrabModifierInfo *modifiers_failed;
@@ -137,12 +143,6 @@ ProcXIPassiveGrabDevice(ClientPtr client)
     xi2mask_set_one_mask(mask.xi2mask, stuff->deviceid,
                          (unsigned char *) &stuff[1], mask_len * 4);
 
-    rep.repType = X_Reply;
-    rep.RepType = X_XIPassiveGrabDevice;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.num_modifiers = 0;
-
     memset(&param, 0, sizeof(param));
     param.grabtype = XI2;
     param.ownerEvents = stuff->owner_events;
diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index ab86963..51a36d4 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -864,11 +864,13 @@ ProcXListDeviceProperties(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_ListDeviceProperties;
-    rep.length = natoms;
-    rep.sequenceNumber = client->sequence;
-    rep.nAtoms = natoms;
+    rep = (xListDevicePropertiesReply) {
+        .repType = X_Reply,
+        .RepType = X_ListDeviceProperties,
+        .sequenceNumber = client->sequence,
+        .length = natoms,
+        .nAtoms = natoms
+    };
 
     WriteReplyToClient(client, sizeof(xListDevicePropertiesReply), &rep);
     if (natoms) {
@@ -958,15 +960,17 @@ ProcXGetDeviceProperty(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    reply.repType = X_Reply;
-    reply.RepType = X_GetDeviceProperty;
-    reply.sequenceNumber = client->sequence;
-    reply.deviceid = dev->id;
-    reply.nItems = nitems;
-    reply.format = format;
-    reply.bytesAfter = bytes_after;
-    reply.propertyType = type;
-    reply.length = bytes_to_int32(length);
+    reply = (xGetDevicePropertyReply) {
+        .repType = X_Reply,
+        .RepType = X_GetDeviceProperty,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(length),
+        .propertyType = type,
+        .bytesAfter = bytes_after,
+        .nItems = nitems,
+        .format = format,
+        .deviceid = dev->id
+    };
 
     if (stuff->delete && (reply.bytesAfter == 0))
         send_property_event(dev, stuff->property, XIPropertyDeleted);
@@ -1100,11 +1104,13 @@ ProcXIListProperties(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_XIListProperties;
-    rep.length = natoms;
-    rep.sequenceNumber = client->sequence;
-    rep.num_properties = natoms;
+    rep = (xXIListPropertiesReply) {
+        .repType = X_Reply,
+        .RepType = X_XIListProperties,
+        .sequenceNumber = client->sequence,
+        .length = natoms,
+        .num_properties = natoms
+    };
 
     WriteReplyToClient(client, sizeof(xXIListPropertiesReply), &rep);
     if (natoms) {
@@ -1194,14 +1200,16 @@ ProcXIGetProperty(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    reply.repType = X_Reply;
-    reply.RepType = X_XIGetProperty;
-    reply.sequenceNumber = client->sequence;
-    reply.num_items = nitems;
-    reply.format = format;
-    reply.bytes_after = bytes_after;
-    reply.type = type;
-    reply.length = bytes_to_int32(length);
+    reply = (xXIGetPropertyReply) {
+        .repType = X_Reply,
+        .RepType = X_XIGetProperty,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(length),
+        .type = type,
+        .bytes_after = bytes_after,
+        .num_items = nitems,
+        .format = format
+    };
 
     if (length && stuff->delete && (reply.bytes_after == 0))
         send_property_event(dev, stuff->property, XIPropertyDeleted);
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index af7ea53..85c1dd8 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -107,12 +107,13 @@ ProcXIQueryDevice(ClientPtr client)
         return BadAlloc;
     }
 
-    memset(&rep, 0, sizeof(xXIQueryDeviceReply));
-    rep.repType = X_Reply;
-    rep.RepType = X_XIQueryDevice;
-    rep.sequenceNumber = client->sequence;
-    rep.length = len / 4;
-    rep.num_devices = 0;
+    rep = (xXIQueryDeviceReply) {
+        .repType = X_Reply,
+        .RepType = X_XIQueryDevice,
+        .sequenceNumber = client->sequence,
+        .length = len / 4,
+        .num_devices = 0
+    };
 
     ptr = info;
     if (dev) {
diff --git a/Xi/xiquerypointer.c b/Xi/xiquerypointer.c
index e09a1f6..7e6852d 100644
--- a/Xi/xiquerypointer.c
+++ b/Xi/xiquerypointer.c
@@ -121,15 +121,16 @@ ProcXIQueryPointer(ClientPtr client)
 
     pSprite = pDev->spriteInfo->sprite;
 
-    memset(&rep, 0, sizeof(rep));
-    rep.repType = X_Reply;
-    rep.RepType = X_XIQueryPointer;
-    rep.length = 6;
-    rep.sequenceNumber = client->sequence;
-    rep.root = (GetCurrentRootWindow(pDev))->drawable.id;
-    rep.root_x = FP1616(pSprite->hot.x, 0);
-    rep.root_y = FP1616(pSprite->hot.y, 0);
-    rep.child = None;
+    rep = (xXIQueryPointerReply) {
+        .repType = X_Reply,
+        .RepType = X_XIQueryPointer,
+        .sequenceNumber = client->sequence,
+        .length = 6,
+        .root = (GetCurrentRootWindow(pDev))->drawable.id,
+        .root_x = FP1616(pSprite->hot.x, 0),
+        .root_y = FP1616(pSprite->hot.y, 0),
+        .child = None
+    };
 
     if (kbd) {
         state = &kbd->key->xkbInfo->state;
diff --git a/Xi/xiqueryversion.c b/Xi/xiqueryversion.c
index 0d4962f..b807a53 100644
--- a/Xi/xiqueryversion.c
+++ b/Xi/xiqueryversion.c
@@ -93,13 +93,14 @@ ProcXIQueryVersion(ClientPtr client)
         pXIClient->minor_version = minor;
     }
 
-    memset(&rep, 0, sizeof(xXIQueryVersionReply));
-    rep.repType = X_Reply;
-    rep.RepType = X_XIQueryVersion;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.major_version = major;
-    rep.minor_version = minor;
+    rep = (xXIQueryVersionReply) {
+        .repType = X_Reply,
+        .RepType = X_XIQueryVersion,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .major_version = major,
+        .minor_version = minor
+    };
 
     WriteReplyToClient(client, sizeof(xXIQueryVersionReply), &rep);
 
diff --git a/Xi/xiselectev.c b/Xi/xiselectev.c
index 6dd2c1c..0e45cb8 100644
--- a/Xi/xiselectev.c
+++ b/Xi/xiselectev.c
@@ -260,11 +260,13 @@ ProcXIGetSelectedEvents(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    reply.repType = X_Reply;
-    reply.RepType = X_XIGetSelectedEvents;
-    reply.length = 0;
-    reply.sequenceNumber = client->sequence;
-    reply.num_masks = 0;
+    reply = (xXIGetSelectedEventsReply) {
+        .repType = X_Reply,
+        .RepType = X_XIGetSelectedEvents,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .num_masks = 0
+    };
 
     masks = wOtherInputMasks(win);
     if (masks) {
diff --git a/Xi/xisetdevfocus.c b/Xi/xisetdevfocus.c
index 55e5c35..372ec24 100644
--- a/Xi/xisetdevfocus.c
+++ b/Xi/xisetdevfocus.c
@@ -97,10 +97,12 @@ ProcXIGetFocus(ClientPtr client)
     if (!dev->focus)
         return BadDevice;
 
-    rep.repType = X_Reply;
-    rep.RepType = X_XIGetFocus;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xXIGetFocusReply) {
+        .repType = X_Reply,
+        .RepType = X_XIGetFocus,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     if (dev->focus->win == NoneWin)
         rep.focus = None;
commit 6a721e3af5e11bae1d59ca551a02470f35d9e844
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in Xext Replies
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xext/bigreq.c b/Xext/bigreq.c
index 9bb1c86..d61ff3c 100644
--- a/Xext/bigreq.c
+++ b/Xext/bigreq.c
@@ -55,11 +55,12 @@ ProcBigReqDispatch(ClientPtr client)
         return BadRequest;
     REQUEST_SIZE_MATCH(xBigReqEnableReq);
     client->big_requests = TRUE;
-    memset(&rep, 0, sizeof(xBigReqEnableReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.max_request_size = maxBigRequestSize;
+    rep = (xBigReqEnableReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .max_request_size = maxBigRequestSize
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.max_request_size);
diff --git a/Xext/dpms.c b/Xext/dpms.c
index 35be966..8ec32ea 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -45,15 +45,16 @@ static int
 ProcDPMSGetVersion(ClientPtr client)
 {
     /* REQUEST(xDPMSGetVersionReq); */
-    xDPMSGetVersionReply rep;
+    xDPMSGetVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = DPMSMajorVersion,
+        .minorVersion = DPMSMinorVersion
+    };
 
     REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = DPMSMajorVersion;
-    rep.minorVersion = DPMSMinorVersion;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.majorVersion);
@@ -67,15 +68,15 @@ static int
 ProcDPMSCapable(ClientPtr client)
 {
     /* REQUEST(xDPMSCapableReq); */
-    xDPMSCapableReply rep;
+    xDPMSCapableReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .capable = DPMSCapableFlag
+    };
 
     REQUEST_SIZE_MATCH(xDPMSCapableReq);
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.capable = DPMSCapableFlag;
-
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
     }
@@ -87,17 +88,17 @@ static int
 ProcDPMSGetTimeouts(ClientPtr client)
 {
     /* REQUEST(xDPMSGetTimeoutsReq); */
-    xDPMSGetTimeoutsReply rep;
+    xDPMSGetTimeoutsReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .standby = DPMSStandbyTime / MILLI_PER_SECOND,
+        .suspend = DPMSSuspendTime / MILLI_PER_SECOND,
+        .off = DPMSOffTime / MILLI_PER_SECOND
+    };
 
     REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.standby = DPMSStandbyTime / MILLI_PER_SECOND;
-    rep.suspend = DPMSSuspendTime / MILLI_PER_SECOND;
-    rep.off = DPMSOffTime / MILLI_PER_SECOND;
-
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.standby);
@@ -188,16 +189,16 @@ static int
 ProcDPMSInfo(ClientPtr client)
 {
     /* REQUEST(xDPMSInfoReq); */
-    xDPMSInfoReply rep;
+    xDPMSInfoReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .power_level = DPMSPowerLevel,
+        .state = DPMSEnabled
+    };
 
     REQUEST_SIZE_MATCH(xDPMSInfoReq);
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.power_level = DPMSPowerLevel;
-    rep.state = DPMSEnabled;
-
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.power_level);
diff --git a/Xext/geext.c b/Xext/geext.c
index 7bdd873..fc16b8a 100644
--- a/Xext/geext.c
+++ b/Xext/geext.c
@@ -65,14 +65,16 @@ ProcGEQueryVersion(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xGEQueryVersionReq);
 
-    rep.repType = X_Reply;
-    rep.RepType = X_GEQueryVersion;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
-    /* return the supported version by the server */
-    rep.majorVersion = SERVER_GE_MAJOR_VERSION;
-    rep.minorVersion = SERVER_GE_MINOR_VERSION;
+    rep = (xGEQueryVersionReply) {
+        .repType = X_Reply,
+        .RepType = X_GEQueryVersion,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+
+        /* return the supported version by the server */
+        .majorVersion = SERVER_GE_MAJOR_VERSION,
+        .minorVersion = SERVER_GE_MINOR_VERSION
+    };
 
     /* Remember version the client requested */
     pGEClient->major_version = stuff->majorVersion;
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 98c612a..bb253c3 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -904,14 +904,15 @@ int
 ProcPanoramiXQueryVersion(ClientPtr client)
 {
     /* REQUEST(xPanoramiXQueryVersionReq); */
-    xPanoramiXQueryVersionReply rep;
+    xPanoramiXQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_PANORAMIX_MAJOR_VERSION,
+        .minorVersion = SERVER_PANORAMIX_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_PANORAMIX_MAJOR_VERSION;
-    rep.minorVersion = SERVER_PANORAMIX_MINOR_VERSION;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -935,11 +936,13 @@ ProcPanoramiXGetState(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.state = !noPanoramiXExtension;
-    rep.window = stuff->window;
+    rep = (xPanoramiXGetStateReply) {
+        .type = X_Reply,
+        .state = !noPanoramiXExtension,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .window = stuff->window
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -963,11 +966,13 @@ ProcPanoramiXGetScreenCount(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.ScreenCount = PanoramiXNumScreens;
-    rep.window = stuff->window;
+    rep = (xPanoramiXGetScreenCountReply) {
+        .type = X_Reply,
+        .ScreenCount = PanoramiXNumScreens,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .window = stuff->window
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -993,14 +998,16 @@ ProcPanoramiXGetScreenSize(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xPanoramiXGetScreenSizeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
     /* screen dimensions */
-    rep.width = screenInfo.screens[stuff->screen]->width;
-    rep.height = screenInfo.screens[stuff->screen]->height;
-    rep.window = stuff->window;
-    rep.screen = stuff->screen;
+        .width = screenInfo.screens[stuff->screen]->width,
+        .height = screenInfo.screens[stuff->screen]->height,
+        .window = stuff->window,
+        .screen = stuff->screen
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -1021,18 +1028,18 @@ ProcXineramaIsActive(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xXineramaIsActiveReq);
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xXineramaIsActiveReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
 #if 1
-    {
         /* The following hack fools clients into thinking that Xinerama
          * is disabled even though it is not. */
-        rep.state = !noPanoramiXExtension && !PanoramiXExtensionDisabledHack;
-    }
+        .state = !noPanoramiXExtension && !PanoramiXExtensionDisabledHack
 #else
-    rep.state = !noPanoramiXExtension;
+        .state = !noPanoramiXExtension;
 #endif
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -1046,14 +1053,15 @@ int
 ProcXineramaQueryScreens(ClientPtr client)
 {
     /* REQUEST(xXineramaQueryScreensReq); */
-    xXineramaQueryScreensReply rep;
+    xXineramaQueryScreensReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(rep.number * sz_XineramaScreenInfo),
+        .number = (noPanoramiXExtension) ? 0 : PanoramiXNumScreens
+    };
 
     REQUEST_SIZE_MATCH(xXineramaQueryScreensReq);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.number = (noPanoramiXExtension) ? 0 : PanoramiXNumScreens;
-    rep.length = bytes_to_int32(rep.number * sz_XineramaScreenInfo);
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index bdabfbf..576844c 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -566,14 +566,18 @@ PanoramiXGetGeometry(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.root = screenInfo.screens[0]->root->drawable.id;
-    rep.depth = pDraw->depth;
-    rep.width = pDraw->width;
-    rep.height = pDraw->height;
-    rep.x = rep.y = rep.borderWidth = 0;
+    rep = (xGetGeometryReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .root = screenInfo.screens[0]->root->drawable.id,
+        .depth = pDraw->depth,
+        .width = pDraw->width,
+        .height = pDraw->height,
+        .x = 0,
+        .y = 0,
+        .borderWidth = 0
+    };
 
     if (stuff->id == rep.root) {
         xWindowRoot *root = (xWindowRoot *)
@@ -617,11 +621,13 @@ PanoramiXTranslateCoords(ClientPtr client)
     rc = dixLookupWindow(&pDst, stuff->dstWid, client, DixReadAccess);
     if (rc != Success)
         return rc;
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.sameScreen = xTrue;
-    rep.child = None;
+    rep = (xTranslateCoordsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .sameScreen = xTrue,
+        .child = None
+    };
 
     if ((pWin == screenInfo.screens[0]->root) ||
         (pWin->drawable.id == screenInfo.screens[0]->screensaver.wid)) {
@@ -1954,10 +1960,12 @@ PanoramiXGetImage(ClientPtr client)
             return rc;
     }
 
-    xgi.visual = wVisual(((WindowPtr) pDraw));
-    xgi.type = X_Reply;
-    xgi.sequenceNumber = client->sequence;
-    xgi.depth = pDraw->depth;
+    xgi = (xGetImageReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .visual = wVisual(((WindowPtr) pDraw)),
+        .depth = pDraw->depth
+    };
     if (format == ZPixmap) {
         widthBytesLine = PixmapBytePad(w, pDraw->depth);
         length = widthBytesLine * h;
diff --git a/Xext/saver.c b/Xext/saver.c
index 60c02ff..e1e86c0 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -634,14 +634,16 @@ ScreenSaverHandle(ScreenPtr pScreen, int xstate, Bool force)
 static int
 ProcScreenSaverQueryVersion(ClientPtr client)
 {
-    xScreenSaverQueryVersionReply rep;
+    xScreenSaverQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_SAVER_MAJOR_VERSION,
+        .minorVersion = SERVER_SAVER_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xScreenSaverQueryVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_SAVER_MAJOR_VERSION;
-    rep.minorVersion = SERVER_SAVER_MINOR_VERSION;
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -677,10 +679,12 @@ ProcScreenSaverQueryInfo(ClientPtr client)
     UpdateCurrentTime();
     lastInput = GetTimeInMillis() - lastDeviceEventTime[XIAllDevices].milliseconds;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.window = pSaver->wid;
+    rep = (xScreenSaverQueryInfoReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .window = pSaver->wid
+    };
     if (screenIsSaved != SCREEN_SAVER_OFF) {
         rep.state = ScreenSaverOn;
         if (ScreenSaverTime)
diff --git a/Xext/security.c b/Xext/security.c
index fd63571..4144d85 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -338,14 +338,16 @@ static int
 ProcSecurityQueryVersion(ClientPtr client)
 {
     /* REQUEST(xSecurityQueryVersionReq); */
-    xSecurityQueryVersionReply rep;
+    xSecurityQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_SECURITY_MAJOR_VERSION,
+        .minorVersion = SERVER_SECURITY_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xSecurityQueryVersionReq);
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.majorVersion = SERVER_SECURITY_MAJOR_VERSION;
-    rep.minorVersion = SERVER_SECURITY_MINOR_VERSION;
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.majorVersion);
@@ -527,11 +529,13 @@ ProcSecurityGenerateAuthorization(ClientPtr client)
 
     /* tell client the auth id and data */
 
-    rep.type = X_Reply;
-    rep.length = bytes_to_int32(authdata_len);
-    rep.sequenceNumber = client->sequence;
-    rep.authId = authId;
-    rep.dataLength = authdata_len;
+    rep = (xSecurityGenerateAuthorizationReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(authdata_len),
+        .authId = authId,
+        .dataLength = authdata_len
+    };
 
     if (client->swapped) {
         swapl(&rep.length);
diff --git a/Xext/shape.c b/Xext/shape.c
index 7724e7b..ecc6c88 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -204,15 +204,16 @@ CreateClipShape(WindowPtr pWin)
 static int
 ProcShapeQueryVersion(ClientPtr client)
 {
-    xShapeQueryVersionReply rep;
+    xShapeQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_SHAPE_MAJOR_VERSION,
+        .minorVersion = SERVER_SHAPE_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xShapeQueryVersionReq);
-    memset(&rep, 0, sizeof(xShapeQueryVersionReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_SHAPE_MAJOR_VERSION;
-    rep.minorVersion = SERVER_SHAPE_MINOR_VERSION;
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -631,12 +632,13 @@ ProcShapeQueryExtents(ClientPtr client)
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
-    memset(&rep, 0, sizeof(xShapeQueryExtentsReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.boundingShaped = (wBoundingShape(pWin) != 0);
-    rep.clipShaped = (wClipShape(pWin) != 0);
+    rep = (xShapeQueryExtentsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .boundingShaped = (wBoundingShape(pWin) != 0),
+        .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 = RegionExtents(region);
@@ -920,10 +922,12 @@ ProcShapeInputSelected(ClientPtr client)
             }
         }
     }
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.enabled = enabled;
+    rep = (xShapeInputSelectedReply) {
+        .type = X_Reply,
+        .enabled = enabled,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -1001,11 +1005,13 @@ ProcShapeGetRectangles(ClientPtr client)
             rects[i].height = box->y2 - box->y1;
         }
     }
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = bytes_to_int32(nrects * sizeof(xRectangle));
-    rep.ordering = YXBanded;
-    rep.nrects = nrects;
+    rep = (xShapeGetRectanglesReply) {
+        .type = X_Reply,
+        .ordering = YXBanded,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(nrects * sizeof(xRectangle)),
+        .nrects = nrects
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
diff --git a/Xext/shm.c b/Xext/shm.c
index a732170..6c9b16d 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -285,19 +285,20 @@ ShmRegisterFbFuncs(ScreenPtr pScreen)
 static int
 ProcShmQueryVersion(ClientPtr client)
 {
-    xShmQueryVersionReply rep;
+    xShmQueryVersionReply rep = {
+        .type = X_Reply,
+        .sharedPixmaps = sharedPixmaps,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_SHM_MAJOR_VERSION,
+        .minorVersion = SERVER_SHM_MINOR_VERSION,
+        .uid = geteuid(),
+        .gid = getegid(),
+        .pixmapFormat = sharedPixmaps ? ZPixmap : 0
+    };
 
     REQUEST_SIZE_MATCH(xShmQueryVersionReq);
-    memset(&rep, 0, sizeof(xShmQueryVersionReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.sharedPixmaps = sharedPixmaps;
-    rep.pixmapFormat = sharedPixmaps ? ZPixmap : 0;
-    rep.majorVersion = SERVER_SHM_MAJOR_VERSION;
-    rep.minorVersion = SERVER_SHM_MINOR_VERSION;
-    rep.uid = geteuid();
-    rep.gid = getegid();
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -656,11 +657,13 @@ ProcShmGetImage(ClientPtr client)
             return BadMatch;
         visual = None;
     }
-    xgi.type = X_Reply;
-    xgi.length = 0;
-    xgi.sequenceNumber = client->sequence;
-    xgi.visual = visual;
-    xgi.depth = pDraw->depth;
+    xgi = (xShmGetImageReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .visual = visual,
+        .depth = pDraw->depth
+    };
     if (stuff->format == ZPixmap) {
         length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height;
     }
@@ -832,11 +835,13 @@ ProcPanoramiXShmGetImage(ClientPtr client)
         }
     }
 
-    xgi.visual = wVisual(((WindowPtr) pDraw));
-    xgi.type = X_Reply;
-    xgi.length = 0;
-    xgi.sequenceNumber = client->sequence;
-    xgi.depth = pDraw->depth;
+    xgi = (xShmGetImageReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .visual = wVisual(((WindowPtr) pDraw)),
+        .depth = pDraw->depth
+    };
 
     if (format == ZPixmap) {
         widthBytesLine = PixmapBytePad(w, pDraw->depth);
diff --git a/Xext/sync.c b/Xext/sync.c
index fc712cd..3ad2b1b 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -1185,17 +1185,16 @@ FreeAlarmClient(void *value, XID id)
 static int
 ProcSyncInitialize(ClientPtr client)
 {
-    xSyncInitializeReply rep;
+    xSyncInitializeReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_SYNC_MAJOR_VERSION,
+        .minorVersion = SERVER_SYNC_MINOR_VERSION,
+    };
 
     REQUEST_SIZE_MATCH(xSyncInitializeReq);
 
-    memset(&rep, 0, sizeof(xSyncInitializeReply));
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = SERVER_SYNC_MAJOR_VERSION;
-    rep.minorVersion = SERVER_SYNC_MINOR_VERSION;
-    rep.length = 0;
-
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
     }
@@ -1209,17 +1208,17 @@ ProcSyncInitialize(ClientPtr client)
 static int
 ProcSyncListSystemCounters(ClientPtr client)
 {
-    xSyncListSystemCountersReply rep;
+    xSyncListSystemCountersReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .nCounters = 0,
+    };
     SysCounterInfo *psci;
     int len = 0;
     xSyncSystemCounter *list = NULL, *walklist = NULL;
 
     REQUEST_SIZE_MATCH(xSyncListSystemCountersReq);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.nCounters = 0;
-
     xorg_list_for_each_entry(psci, &SysCounterList, entry) {
         /* pad to 4 byte boundary */
         len += pad_to_int32(sz_xSyncSystemCounter + strlen(psci->name));
@@ -1329,10 +1328,12 @@ ProcSyncGetPriority(ClientPtr client)
             return rc;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.priority = priorityclient->priority;
+    rep = (xSyncGetPriorityReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .priority = priorityclient->priority
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -1606,19 +1607,20 @@ ProcSyncQueryCounter(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-
     /* if system counter, ask it what the current value is */
-
     if (IsSystemCounter(pCounter)) {
         (*pCounter->pSysCounterInfo->QueryValue) ((pointer) pCounter,
                                                   &pCounter->value);
     }
 
-    rep.value_hi = XSyncValueHigh32(pCounter->value);
-    rep.value_lo = XSyncValueLow32(pCounter->value);
+    rep = (xSyncQueryCounterReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .value_hi = XSyncValueHigh32(pCounter->value),
+        .value_lo = XSyncValueLow32(pCounter->value)
+    };
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -1772,32 +1774,33 @@ ProcSyncQueryAlarm(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length =
-        bytes_to_int32(sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply));
-    rep.sequenceNumber = client->sequence;
-
     pTrigger = &pAlarm->trigger;
-    rep.counter = (pTrigger->pSync) ? pTrigger->pSync->id : None;
+    rep = (xSyncQueryAlarmReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length =
+          bytes_to_int32(sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply)),
+        .counter = (pTrigger->pSync) ? pTrigger->pSync->id : None,
 
 #if 0  /* XXX unclear what to do, depends on whether relative value-types
         * are "consumed" immediately and are considered absolute from then
         * on.
         */
-    rep.value_type = pTrigger->value_type;
-    rep.wait_value_hi = XSyncValueHigh32(pTrigger->wait_value);
-    rep.wait_value_lo = XSyncValueLow32(pTrigger->wait_value);
+        .value_type = pTrigger->value_type,
+        .wait_value_hi = XSyncValueHigh32(pTrigger->wait_value),
+        .wait_value_lo = XSyncValueLow32(pTrigger->wait_value),
 #else
-    rep.value_type = XSyncAbsolute;
-    rep.wait_value_hi = XSyncValueHigh32(pTrigger->test_value);
-    rep.wait_value_lo = XSyncValueLow32(pTrigger->test_value);
+        .value_type = XSyncAbsolute,
+        .wait_value_hi = XSyncValueHigh32(pTrigger->test_value),
+        .wait_value_lo = XSyncValueLow32(pTrigger->test_value),
 #endif
 
-    rep.test_type = pTrigger->test_type;
-    rep.delta_hi = XSyncValueHigh32(pAlarm->delta);
-    rep.delta_lo = XSyncValueLow32(pAlarm->delta);
-    rep.events = pAlarm->events;
-    rep.state = pAlarm->state;
+        .test_type = pTrigger->test_type,
+        .delta_hi = XSyncValueHigh32(pAlarm->delta),
+        .delta_lo = XSyncValueLow32(pAlarm->delta),
+        .events = pAlarm->events,
+        .state = pAlarm->state
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
@@ -1956,11 +1959,13 @@ ProcSyncQueryFence(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xSyncQueryFenceReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
 
-    rep.triggered = pFence->funcs.CheckTriggered(pFence);
+        .triggered = pFence->funcs.CheckTriggered(pFence)
+    };
 
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index 943b424..9e4ea89 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -45,14 +45,16 @@ from The Open Group.
 static int
 ProcXCMiscGetVersion(ClientPtr client)
 {
-    xXCMiscGetVersionReply rep;
+    xXCMiscGetVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = XCMiscMajorVersion,
+        .minorVersion = XCMiscMinorVersion
+    };
 
     REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = XCMiscMajorVersion;
-    rep.minorVersion = XCMiscMinorVersion;
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.majorVersion);
@@ -70,11 +72,13 @@ ProcXCMiscGetXIDRange(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xXCMiscGetXIDRangeReq);
     GetXIDRange(client->index, FALSE, &min_id, &max_id);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.start_id = min_id;
-    rep.count = max_id - min_id + 1;
+    rep = (xXCMiscGetXIDRangeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .start_id = min_id,
+        .count = max_id - min_id + 1
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.start_id);
@@ -102,10 +106,12 @@ ProcXCMiscGetXIDList(ClientPtr client)
         return BadAlloc;
     }
     count = GetXIDList(client, stuff->count, pids);
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = count;
-    rep.count = count;
+    rep = (xXCMiscGetXIDListReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = count,
+        .count = count
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index a902861..d91ff95 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -277,25 +277,23 @@ ProcXF86BigfontQueryVersion(ClientPtr client)
     xXF86BigfontQueryVersionReply reply;
 
     REQUEST_SIZE_MATCH(xXF86BigfontQueryVersionReq);
-    reply.type = X_Reply;
-    reply.length = 0;
-    reply.sequenceNumber = client->sequence;
-    reply.majorVersion = SERVER_XF86BIGFONT_MAJOR_VERSION;
-    reply.minorVersion = SERVER_XF86BIGFONT_MINOR_VERSION;
-    reply.uid = geteuid();
-    reply.gid = getegid();
+    reply = (xXF86BigfontQueryVersionReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = SERVER_XF86BIGFONT_MAJOR_VERSION,
+        .minorVersion = SERVER_XF86BIGFONT_MINOR_VERSION,
+        .uid = geteuid(),
+        .gid = getegid(),
 #ifdef HAS_SHM
-    reply.signature = signature;
+        .signature = signature,
+        .capabilities = (LocalClient(client) && !client->swapped)
+                         ? XF86Bigfont_CAP_LocalShm : 0
 #else
-    reply.signature = 0;        /* This is redundant. Avoids uninitialized memory. */
+        .signature = 0,
+        .capabilities = 0
 #endif
-    reply.capabilities =
-#ifdef HAS_SHM
-        (LocalClient(client) && !client->swapped ? XF86Bigfont_CAP_LocalShm : 0)
-#else
-        0
-#endif
-        ;                       /* may add more bits here in future versions */
+    };
     if (client->swapped) {
         char tmp;
 
diff --git a/Xext/xres.c b/Xext/xres.c
index d207dce..25d4417 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -194,15 +194,16 @@ static int
 ProcXResQueryVersion(ClientPtr client)
 {
     REQUEST(xXResQueryVersionReq);
-    xXResQueryVersionReply rep;
+    xXResQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .server_major = SERVER_XRES_MAJOR_VERSION,
+        .server_minor = SERVER_XRES_MINOR_VERSION
+    };
 
     REQUEST_SIZE_MATCH(xXResQueryVersionReq);
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.server_major = SERVER_XRES_MAJOR_VERSION;
-    rep.server_minor = SERVER_XRES_MINOR_VERSION;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -233,10 +234,12 @@ ProcXResQueryClients(ClientPtr client)
         }
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.num_clients = num_clients;
-    rep.length = bytes_to_int32(rep.num_clients * sz_xXResClient);
+    rep = (xXResQueryClientsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(num_clients * sz_xXResClient),
+        .num_clients = num_clients
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -300,10 +303,12 @@ ProcXResQueryClientResources(ClientPtr client)
             num_types++;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.num_types = num_types;
-    rep.length = bytes_to_int32(rep.num_types * sz_xXResType);
+    rep = (xXResQueryClientResourcesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(num_types * sz_xXResType),
+        .num_types = num_types
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -470,15 +475,17 @@ ProcXResQueryClientPixmapBytes(ClientPtr client)
                               (pointer)(&bytes));
 #endif
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.bytes = bytes;
+    rep = (xXResQueryClientPixmapBytesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .bytes = bytes,
 #ifdef _XSERVER64
-    rep.bytes_overflow = bytes >> 32;
+        .bytes_overflow = bytes >> 32
 #else
-    rep.bytes_overflow = 0;
+        .bytes_overflow = 0
 #endif
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -650,7 +657,6 @@ ProcXResQueryClientIds (ClientPtr client)
 {
     REQUEST(xXResQueryClientIdsReq);
 
-    xXResQueryClientIdsReply  rep;
     xXResClientIdSpec        *specs = (void*) ((char*) stuff + sizeof(*stuff));
     int                       rc;
     ConstructClientIdCtx      ctx;
@@ -664,12 +670,14 @@ ProcXResQueryClientIds (ClientPtr client)
     rc = ConstructClientIds(client, stuff->numSpecs, specs, &ctx);
 
     if (rc == Success) {
-        rep.type = X_Reply;
-        rep.sequenceNumber = client->sequence;
+        xXResQueryClientIdsReply  rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(ctx.resultBytes),
+            .numIds = ctx.numIds
+        };
 
         assert((ctx.resultBytes & 3) == 0);
-        rep.length = bytes_to_int32(ctx.resultBytes);
-        rep.numIds = ctx.numIds;
 
         if (client->swapped) {
             swaps (&rep.sequenceNumber);
@@ -1028,7 +1036,6 @@ ProcXResQueryResourceBytes (ClientPtr client)
 {
     REQUEST(xXResQueryResourceBytesReq);
 
-    xXResQueryResourceBytesReply rep;
     int                          rc;
     ConstructResourceBytesCtx    ctx;
 
@@ -1046,10 +1053,12 @@ ProcXResQueryResourceBytes (ClientPtr client)
     rc = ConstructResourceBytes(stuff->client, &ctx);
 
     if (rc == Success) {
-        rep.type = X_Reply;
-        rep.sequenceNumber = client->sequence;
-        rep.numSizes = ctx.numSizes;
-        rep.length = bytes_to_int32(ctx.resultBytes);
+        xXResQueryResourceBytesReply rep = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(ctx.resultBytes),
+            .numSizes = ctx.numSizes
+        };
 
         if (client->swapped) {
             swaps (&rep.sequenceNumber);
diff --git a/Xext/xselinux_ext.c b/Xext/xselinux_ext.c
index 8817591..d22c2f1 100644
--- a/Xext/xselinux_ext.c
+++ b/Xext/xselinux_ext.c
@@ -63,13 +63,13 @@ SELinuxCopyContext(char *ptr, unsigned len)
 static int
 ProcSELinuxQueryVersion(ClientPtr client)
 {
-    SELinuxQueryVersionReply rep;
-
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.server_major = SELINUX_MAJOR_VERSION;
-    rep.server_minor = SELINUX_MINOR_VERSION;
+    SELinuxQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .server_major = SELINUX_MAJOR_VERSION,
+        .server_minor = SELINUX_MINOR_VERSION
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -93,10 +93,12 @@ SELinuxSendContextReply(ClientPtr client, security_id_t sid)
         len = strlen(ctx) + 1;
     }
 
-    rep.type = X_Reply;
-    rep.length = bytes_to_int32(len);
-    rep.sequenceNumber = client->sequence;
-    rep.context_len = len;
+    rep = (SELinuxGetContextReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(len),
+        .context_len = len
+    };
 
     if (client->swapped) {
         swapl(&rep.length);
@@ -372,10 +374,12 @@ SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items,
     }
 
     /* Send reply to client */
-    rep.type = X_Reply;
-    rep.length = size;
-    rep.sequenceNumber = client->sequence;
-    rep.count = count;
+    rep = (SELinuxListItemsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = size,
+        .count = count
+    };
 
     if (client->swapped) {
         swapl(&rep.length);
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 6112c0b..c7b087b 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -88,14 +88,16 @@ static int XTestSwapFakeInput(ClientPtr /* client */ ,
 static int
 ProcXTestGetVersion(ClientPtr client)
 {
-    xXTestGetVersionReply rep;
+    xXTestGetVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .majorVersion = XTestMajorVersion,
+        .minorVersion = XTestMinorVersion
+    };
 
     REQUEST_SIZE_MATCH(xXTestGetVersionReq);
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.majorVersion = XTestMajorVersion;
-    rep.minorVersion = XTestMinorVersion;
+
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swaps(&rep.minorVersion);
@@ -134,10 +136,12 @@ ProcXTestCompareCursor(ClientPtr client)
             return rc;
         }
     }
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.same = (wCursor(pWin) == pCursor);
+    rep = (xXTestCompareCursorReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .same = (wCursor(pWin) == pCursor)
+    };
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
     }
diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index 8730267..dae9772 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -302,17 +302,17 @@ SWriteListImageFormatsReply(ClientPtr client, xvListImageFormatsReply * rep)
 static int
 ProcXvQueryExtension(ClientPtr client)
 {
-    xvQueryExtensionReply rep;
+    xvQueryExtensionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .version = XvVersion,
+        .revision = XvRevision
+    };
 
     /* REQUEST(xvQueryExtensionReq); */
     REQUEST_SIZE_MATCH(xvQueryExtensionReq);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.version = XvVersion;
-    rep.revision = XvRevision;
-
     _WriteQueryExtensionReply(client, &rep);
 
     return Success;
@@ -343,10 +343,12 @@ ProcXvQueryAdaptors(ClientPtr client)
     pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
                                           XvGetScreenKey());
     if (!pxvs) {
-        rep.type = X_Reply;
-        rep.sequenceNumber = client->sequence;
-        rep.num_adaptors = 0;
-        rep.length = 0;
+        rep = (xvQueryAdaptorsReply) {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .num_adaptors = 0
+        };
 
         _WriteQueryAdaptorsReply(client, &rep);
 
@@ -355,9 +357,11 @@ ProcXvQueryAdaptors(ClientPtr client)
 
     (*pxvs->ddQueryAdaptors) (pScreen, &pxvs->pAdaptors, &pxvs->nAdaptors);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.num_adaptors = pxvs->nAdaptors;
+    rep = (xvQueryAdaptorsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .num_adaptors = pxvs->nAdaptors
+    };
 
     /* CALCULATE THE TOTAL SIZE OF THE REPLY IN BYTES */
 
@@ -429,9 +433,11 @@ ProcXvQueryEncodings(ClientPtr client)
         return status;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.num_encodings = pPort->pAdaptor->nEncodings;
+    rep = (xvQueryEncodingsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .num_encodings = pPort->pAdaptor->nEncodings
+    };
 
     /* FOR EACH ENCODING ADD UP THE BYTES FOR ENCODING NAMES */
 
@@ -662,11 +668,12 @@ ProcXvGrabPort(ClientPtr client)
     if (status != Success) {
         return status;
     }
-
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.result = result;
+    rep = (xvGrabPortReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .result = result
+    };
 
     _WriteGrabPortReply(client, &rep);
 
@@ -777,10 +784,12 @@ ProcXvGetPortAttribute(ClientPtr client)
         return status;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.value = value;
+    rep = (xvGetPortAttributeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .value = value
+    };
 
     _WriteGetPortAttributeReply(client, &rep);
 
@@ -805,17 +814,18 @@ ProcXvQueryBestSize(ClientPtr client)
         return status;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-
     (*pPort->pAdaptor->ddQueryBestSize) (client, pPort, stuff->motion,
                                          stuff->vid_w, stuff->vid_h,
                                          stuff->drw_w, stuff->drw_h,
                                          &actual_width, &actual_height);
 
-    rep.actual_width = actual_width;
-    rep.actual_height = actual_height;
+    rep = (xvQueryBestSizeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .actual_width = actual_width,
+        .actual_height = actual_height
+    };
 
     _WriteQueryBestSizeReply(client, &rep);
 
@@ -841,10 +851,12 @@ ProcXvQueryPortAttributes(ClientPtr client)
         return status;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.num_attributes = pPort->pAdaptor->nAttributes;
-    rep.text_size = 0;
+    rep = (xvQueryPortAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .num_attributes = pPort->pAdaptor->nAttributes,
+        .text_size = 0
+    };
 
     for (i = 0, pAtt = pPort->pAdaptor->pAttributes;
          i < pPort->pAdaptor->nAttributes; i++, pAtt++) {
@@ -1089,13 +1101,15 @@ ProcXvQueryImageAttributes(ClientPtr client)
                                                        &width, &height, offsets,
                                                        pitches);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = planeLength = num_planes << 1;
-    rep.num_planes = num_planes;
-    rep.width = width;
-    rep.height = height;
-    rep.data_size = size;
+    rep = (xvQueryImageAttributesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = planeLength = num_planes << 1,
+        .num_planes = num_planes,
+        .width = width,
+        .height = height,
+        .data_size = size
+    };
 
     _WriteQueryImageAttributesReply(client, &rep);
     if (client->swapped)
@@ -1122,11 +1136,13 @@ ProcXvListImageFormats(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.num_formats = pPort->pAdaptor->nImages;
-    rep.length =
-        bytes_to_int32(pPort->pAdaptor->nImages * sz_xvImageFormatInfo);
+    rep = (xvListImageFormatsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .num_formats = pPort->pAdaptor->nImages,
+        .length =
+            bytes_to_int32(pPort->pAdaptor->nImages * sz_xvImageFormatInfo)
+    };
 
     _WriteListImageFormatsReply(client, &rep);
 
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index b008bfe..d74302b 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -109,15 +109,17 @@ XvMCDestroySubpictureRes(pointer data, XID id)
 static int
 ProcXvMCQueryVersion(ClientPtr client)
 {
-    xvmcQueryVersionReply rep;
+    xvmcQueryVersionReply rep = {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .major = SERVER_XVMC_MAJOR_VERSION,
+        .minor = SERVER_XVMC_MINOR_VERSION
+    };
 
     /* REQUEST(xvmcQueryVersionReq); */
     REQUEST_SIZE_MATCH(xvmcQueryVersionReq);
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
-    rep.major = SERVER_XVMC_MAJOR_VERSION;
-    rep.minor = SERVER_XVMC_MINOR_VERSION;
+
     WriteToClient(client, sizeof(xvmcQueryVersionReply), &rep);
     return Success;
 }
@@ -151,10 +153,12 @@ ProcXvMCListSurfaceTypes(ClientPtr client)
         }
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.num = (adaptor) ? adaptor->num_surfaces : 0;
-    rep.length = bytes_to_int32(rep.num * sizeof(xvmcSurfaceInfo));
+    rep = (xvmcListSurfaceTypesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .num = (adaptor) ? adaptor->num_surfaces : 0,
+        .length = bytes_to_int32(rep.num * sizeof(xvmcSurfaceInfo)),
+    };
 
     WriteToClient(client, sizeof(xvmcListSurfaceTypesReply), &rep);
 
@@ -247,12 +251,14 @@ ProcXvMCCreateContext(ClientPtr client)
         return result;
     }
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.width_actual = pContext->width;
-    rep.height_actual = pContext->height;
-    rep.flags_return = pContext->flags;
-    rep.length = dwords;
+    rep = (xvmcCreateContextReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = dwords,
+        .width_actual = pContext->width,
+        .height_actual = pContext->height,
+        .flags_return = pContext->flags
+    };
 
     WriteToClient(client, sizeof(xvmcCreateContextReply), &rep);
     if (dwords)
@@ -320,10 +326,11 @@ ProcXvMCCreateSurface(ClientPtr client)
         free(pSurface);
         return result;
     }
-
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = dwords;
+    rep = (xvmcCreateSurfaceReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = dwords
+    };
 
     WriteToClient(client, sizeof(xvmcCreateSurfaceReply), &rep);
     if (dwords)
@@ -435,18 +442,19 @@ ProcXvMCCreateSubpicture(ClientPtr client)
         free(pSubpicture);
         return result;
     }
-
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.width_actual = pSubpicture->width;
-    rep.height_actual = pSubpicture->height;
-    rep.num_palette_entries = pSubpicture->num_palette_entries;
-    rep.entry_bytes = pSubpicture->entry_bytes;
-    rep.component_order[0] = pSubpicture->component_order[0];
-    rep.component_order[1] = pSubpicture->component_order[1];
-    rep.component_order[2] = pSubpicture->component_order[2];
-    rep.component_order[3] = pSubpicture->component_order[3];
-    rep.length = dwords;
+    rep = (xvmcCreateSubpictureReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = dwords,
+        .width_actual = pSubpicture->width,
+        .height_actual = pSubpicture->height,
+        .num_palette_entries = pSubpicture->num_palette_entries,
+        .entry_bytes = pSubpicture->entry_bytes,
+        .component_order[0] = pSubpicture->component_order[0],
+        .component_order[1] = pSubpicture->component_order[1],
+        .component_order[2] = pSubpicture->component_order[2],
+        .component_order[3] = pSubpicture->component_order[3]
+    };
 
     WriteToClient(client, sizeof(xvmcCreateSubpictureReply), &rep);
     if (dwords)
@@ -525,9 +533,11 @@ ProcXvMCListSubpictureTypes(ClientPtr client)
     if (!surface)
         return BadMatch;
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.num = 0;
+    rep = (xvmcListSubpictureTypesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .num = 0
+    };
     if (surface->compatible_subpictures)
         rep.num = surface->compatible_subpictures->num_xvimages;
 
@@ -595,13 +605,16 @@ ProcXvMCGetDRInfo(ClientPtr client)
     pScreen = pPort->pAdaptor->pScreen;
     pScreenPriv = XVMC_GET_PRIVATE(pScreen);
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.major = pScreenPriv->major;
-    rep.minor = pScreenPriv->minor;
-    rep.patchLevel = pScreenPriv->patchLevel;
-    rep.nameLen = bytes_to_int32(strlen(pScreenPriv->clientDriverName) + 1);
-    rep.busIDLen = bytes_to_int32(strlen(pScreenPriv->busID) + 1);
+    rep = (xvmcGetDRInfoReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .major = pScreenPriv->major,
+        .minor = pScreenPriv->minor,
+        .patchLevel = pScreenPriv->patchLevel,
+        .nameLen = bytes_to_int32(strlen(pScreenPriv->clientDriverName) + 1),
+        .busIDLen = bytes_to_int32(strlen(pScreenPriv->busID) + 1),
+        .isLocal = 1
+    };
 
     rep.length = rep.nameLen + rep.busIDLen;
     rep.nameLen <<= 2;
@@ -612,7 +625,6 @@ ProcXvMCGetDRInfo(ClientPtr client)
      * segment she prepared for us.
      */
 
-    rep.isLocal = 1;
 #ifdef HAS_XVMCSHM
     patternP = (CARD32 *) shmat(stuff->shmKey, NULL, SHM_RDONLY);
     if (-1 != (long) patternP) {
commit d792ac125a0462a04a930af543cbc732f8cdab7d
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in dix Replies
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/devices.c b/dix/devices.c
index 4d1086f..77583f7 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1666,9 +1666,11 @@ ProcSetModifierMapping(ClientPtr client)
                             bytes_to_int32(sizeof(xSetModifierMappingReq))))
         return BadLength;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xSetModifierMappingReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
 
     rc = change_modmap(client, PickKeyboard(client), (KeyCode *) &stuff[1],
                        stuff->numKeyPerModifier);
@@ -1696,12 +1698,13 @@ ProcGetModifierMapping(ClientPtr client)
     generate_modkeymap(client, PickKeyboard(client), &modkeymap,
                        &max_keys_per_mod);
 
-    memset(&rep, 0, sizeof(xGetModifierMappingReply));
-    rep.type = X_Reply;
-    rep.numKeyPerModifier = max_keys_per_mod;
-    rep.sequenceNumber = client->sequence;
+    rep = (xGetModifierMappingReply) {
+        .type = X_Reply,
+        .numKeyPerModifier = max_keys_per_mod,
+        .sequenceNumber = client->sequence,
     /* length counts 4 byte quantities - there are 8 modifiers 1 byte big */
-    rep.length = max_keys_per_mod << 1;
+        .length = max_keys_per_mod << 1
+    };
 
     WriteReplyToClient(client, sizeof(xGetModifierMappingReply), &rep);
     WriteToClient(client, max_keys_per_mod * 8, modkeymap);
@@ -1785,10 +1788,13 @@ ProcSetPointerMapping(ClientPtr client)
     if (client->req_len !=
         bytes_to_int32(sizeof(xSetPointerMappingReq) + stuff->nElts))
         return BadLength;
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.success = MappingSuccess;
+
+    rep = (xSetPointerMappingReply) {
+        .type = X_Reply,
+        .success = MappingSuccess,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     map = (BYTE *) &stuff[1];
 
     /* So we're bounded here by the number of core buttons.  This check
@@ -1857,12 +1863,13 @@ ProcGetKeyboardMapping(ClientPtr client)
     if (!syms)
         return BadAlloc;
 
-    memset(&rep, 0, sizeof(xGetKeyboardMappingReply));
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.keySymsPerKeyCode = syms->mapWidth;
-    /* length is a count of 4 byte quantities and KeySyms are 4 bytes */
-    rep.length = syms->mapWidth * stuff->count;
+    rep = (xGetKeyboardMappingReply) {
+        .type = X_Reply,
+        .keySymsPerKeyCode = syms->mapWidth,
+        .sequenceNumber = client->sequence,
+        /* length is a count of 4 byte quantities and KeySyms are 4 bytes */
+        .length = syms->mapWidth * stuff->count
+    };
     WriteReplyToClient(client, sizeof(xGetKeyboardMappingReply), &rep);
     client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
     WriteSwappedDataToClient(client,
@@ -1892,10 +1899,12 @@ ProcGetPointerMapping(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.nElts = (butc) ? butc->numButtons : 0;
-    rep.length = ((unsigned) rep.nElts + (4 - 1)) / 4;
+    rep = (xGetPointerMappingReply) {
+        .type = X_Reply,
+        .nElts = (butc) ? butc->numButtons : 0,
+        .sequenceNumber = client->sequence,
+        .length = ((unsigned) rep.nElts + (4 - 1)) / 4
+    };
     WriteReplyToClient(client, sizeof(xGetPointerMappingReply), &rep);
     if (butc)
         WriteToClient(client, (int) rep.nElts, &butc->map[1]);
@@ -2144,15 +2153,17 @@ ProcGetKeyboardControl(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length = 5;
-    rep.sequenceNumber = client->sequence;
-    rep.globalAutoRepeat = ctrl->autoRepeat;
-    rep.keyClickPercent = ctrl->click;
-    rep.bellPercent = ctrl->bell;
-    rep.bellPitch = ctrl->bell_pitch;
-    rep.bellDuration = ctrl->bell_duration;
-    rep.ledMask = ctrl->leds;
+    rep = (xGetKeyboardControlReply) {
+        .type = X_Reply,
+        .globalAutoRepeat = ctrl->autoRepeat,
+        .sequenceNumber = client->sequence,
+        .length = 5,
+        .ledMask = ctrl->leds,
+        .keyClickPercent = ctrl->click,
+        .bellPercent = ctrl->bell,
+        .bellPitch = ctrl->bell_pitch,
+        .bellDuration = ctrl->bell_duration
+    };
     for (i = 0; i < 32; i++)
         rep.map[i] = ctrl->autoRepeats[i];
     WriteReplyToClient(client, sizeof(xGetKeyboardControlReply), &rep);
@@ -2287,12 +2298,14 @@ ProcGetPointerControl(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.threshold = ctrl->threshold;
-    rep.accelNumerator = ctrl->num;
-    rep.accelDenominator = ctrl->den;
+    rep = (xGetPointerControlReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .accelNumerator = ctrl->num,
+        .accelDenominator = ctrl->den,
+        .threshold = ctrl->threshold
+    };
     WriteReplyToClient(client, sizeof(xGenericReply), &rep);
     return Success;
 }
@@ -2336,8 +2349,10 @@ ProcGetMotionEvents(ClientPtr client)
 
     if (mouse->valuator->motionHintWindow)
         MaybeStopHint(mouse, client);
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
+    rep = (xGetMotionEventsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence
+    };
     nEvents = 0;
     start = ClientTimeToServerTime(stuff->start);
     stop = ClientTimeToServerTime(stuff->stop);
@@ -2385,10 +2400,11 @@ ProcQueryKeymap(ClientPtr client)
     CARD8 *down = keybd->key->down;
 
     REQUEST_SIZE_MATCH(xReq);
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 2;
-    memset(rep.map, 0, 32);
+    rep = (xQueryKeymapReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 2
+    };
 
     rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess);
     /* If rc is Success, we're allowed to copy out the keymap.
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 5982a49..d916f34 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -926,10 +926,9 @@ GetGeometry(ClientPtr client, xGetGeometryReply * rep)
 int
 ProcGetGeometry(ClientPtr client)
 {
-    xGetGeometryReply rep;
+    xGetGeometryReply rep = { .type = X_Reply };
     int status;
 
-    memset(&rep, 0, sizeof(xGetGeometryReply));
     if ((status = GetGeometry(client, &rep)) != Success)
         return status;
 
@@ -951,14 +950,13 @@ ProcQueryTree(ClientPtr client)
     rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess);
     if (rc != Success)
         return rc;
-    memset(&reply, 0, sizeof(xQueryTreeReply));
-    reply.type = X_Reply;
-    reply.root = pWin->drawable.pScreen->root->drawable.id;
-    reply.sequenceNumber = client->sequence;
-    if (pWin->parent)
-        reply.parent = pWin->parent->drawable.id;
-    else
-        reply.parent = (Window) None;
+
+    reply = (xQueryTreeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .root = pWin->drawable.pScreen->root->drawable.id,
+        .parent = (pWin->parent) ? pWin->parent->drawable.id : (Window) None
+    };
     pHead = RealChildHead(pWin);
     for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
         numChildren++;
@@ -1003,13 +1001,12 @@ ProcInternAtom(ClientPtr client)
     tchar = (char *) &stuff[1];
     atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists);
     if (atom != BAD_RESOURCE) {
-        xInternAtomReply reply;
-
-        memset(&reply, 0, sizeof(xInternAtomReply));
-        reply.type = X_Reply;
-        reply.length = 0;
-        reply.sequenceNumber = client->sequence;
-        reply.atom = atom;
+        xInternAtomReply reply = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .atom = atom
+        };
         WriteReplyToClient(client, sizeof(xInternAtomReply), &reply);
         return Success;
     }
@@ -1021,19 +1018,19 @@ int
 ProcGetAtomName(ClientPtr client)
 {
     const char *str;
-    xGetAtomNameReply reply;
-    int len;
 
     REQUEST(xResourceReq);
 
     REQUEST_SIZE_MATCH(xResourceReq);
     if ((str = NameForAtom(stuff->id))) {
-        len = strlen(str);
-        memset(&reply, 0, sizeof(xGetAtomNameReply));
-        reply.type = X_Reply;
-        reply.length = bytes_to_int32(len);
-        reply.sequenceNumber = client->sequence;
-        reply.nameLength = len;
+        int len = strlen(str);
+        xGetAtomNameReply reply = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(len),
+            .nameLength = len
+        };
+
         WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
         WriteToClient(client, len, str);
         return Success;
@@ -1123,10 +1120,12 @@ ProcTranslateCoords(ClientPtr client)
     rc = dixLookupWindow(&pDst, stuff->dstWid, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
-    memset(&rep, 0, sizeof(xTranslateCoordsReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+
+    rep = (xTranslateCoordsReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     if (!SAME_SCREENS(pWin->drawable, pDst->drawable)) {
         rep.sameScreen = xFalse;
         rep.child = None;
@@ -1288,17 +1287,19 @@ ProcQueryTextExtents(ClientPtr client)
     }
     if (!QueryTextExtents(pFont, length, (unsigned char *) &stuff[1], &info))
         return BadAlloc;
-    reply.type = X_Reply;
-    reply.length = 0;
-    reply.sequenceNumber = client->sequence;
-    reply.drawDirection = info.drawDirection;
-    reply.fontAscent = info.fontAscent;
-    reply.fontDescent = info.fontDescent;
-    reply.overallAscent = info.overallAscent;
-    reply.overallDescent = info.overallDescent;
-    reply.overallWidth = info.overallWidth;
-    reply.overallLeft = info.overallLeft;
-    reply.overallRight = info.overallRight;
+    reply = (xQueryTextExtentsReply) {
+        .type = X_Reply,
+        .drawDirection = info.drawDirection,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .fontAscent = info.fontAscent,
+        .fontDescent = info.fontDescent,
+        .overallAscent = info.overallAscent,
+        .overallDescent = info.overallDescent,
+        .overallWidth = info.overallWidth,
+        .overallLeft = info.overallLeft,
+        .overallRight = info.overallRight
+    };
     WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply);
     return Success;
 }
@@ -2466,7 +2467,6 @@ ProcAllocColor(ClientPtr client)
 {
     ColormapPtr pmap;
     int rc;
-    xAllocColorReply acr;
 
     REQUEST(xAllocColorReq);
 
@@ -2474,13 +2474,15 @@ ProcAllocColor(ClientPtr client)
     rc = dixLookupResourceByType((pointer *) &pmap, stuff->cmap, RT_COLORMAP,
                                  client, DixAddAccess);
     if (rc == Success) {
-        acr.type = X_Reply;
-        acr.length = 0;
-        acr.sequenceNumber = client->sequence;
-        acr.red = stuff->red;
-        acr.green = stuff->green;
-        acr.blue = stuff->blue;
-        acr.pixel = 0;
+        xAllocColorReply acr = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0,
+            .red = stuff->red,
+            .green = stuff->green,
+            .blue = stuff->blue,
+            .pixel = 0
+        };
         if ((rc = AllocColor(pmap, &acr.red, &acr.green, &acr.blue,
                              &acr.pixel, client->index)))
             return rc;
@@ -2509,12 +2511,11 @@ ProcAllocNamedColor(ClientPtr client)
     rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP,
                                  client, DixAddAccess);
     if (rc == Success) {
-        xAllocNamedColorReply ancr;
-
-        ancr.type = X_Reply;
-        ancr.length = 0;
-        ancr.sequenceNumber = client->sequence;
-
+        xAllocNamedColorReply ancr = {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = 0
+        };
         if (OsLookupColor
             (pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes,
              &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue)) {
@@ -2555,7 +2556,6 @@ ProcAllocColorCells(ClientPtr client)
     rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP,
                                  client, DixAddAccess);
     if (rc == Success) {
-        xAllocColorCellsReply accr;
         int npixels, nmasks;
         long length;
         Pixel *ppixels, *pmasks;
@@ -2585,11 +2585,13 @@ ProcAllocColorCells(ClientPtr client)
         if (noPanoramiXExtension || !pcmp->pScreen->myNum)
 #endif
         {
-            accr.type = X_Reply;
-            accr.length = bytes_to_int32(length);
-            accr.sequenceNumber = client->sequence;
-            accr.nPixels = npixels;
-            accr.nMasks = nmasks;
+            xAllocColorCellsReply accr = {
+                .type = X_Reply,
+                .sequenceNumber = client->sequence,
+                .length = bytes_to_int32(length),
+                .nPixels = npixels,
+                .nMasks = nmasks
+            };
             WriteReplyToClient(client, sizeof(xAllocColorCellsReply), &accr);
             client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
             WriteSwappedDataToClient(client, length, ppixels);
@@ -2629,9 +2631,11 @@ ProcAllocColorPlanes(ClientPtr client)
             client->errorValue = stuff->contiguous;
             return BadValue;
         }
-        acpr.type = X_Reply;
-        acpr.sequenceNumber = client->sequence;
-        acpr.nPixels = npixels;
+        acpr = (xAllocColorPlanesReply) {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .nPixels = npixels
+        };
         length = (long) npixels *sizeof(Pixel);
 
         ppixels = malloc(length);
@@ -2769,11 +2773,12 @@ ProcQueryColors(ClientPtr client)
             free(prgbs);
             return rc;
         }
-        memset(&qcr, 0, sizeof(xQueryColorsReply));
-        qcr.type = X_Reply;
-        qcr.length = bytes_to_int32(count * sizeof(xrgb));
-        qcr.sequenceNumber = client->sequence;
-        qcr.nColors = count;
+        qcr = (xQueryColorsReply) {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .length = bytes_to_int32(count * sizeof(xrgb)),
+            .nColors = count
+        };
         WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr);
         if (count) {
             client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend;
@@ -2806,16 +2811,17 @@ ProcLookupColor(ClientPtr client)
         if (OsLookupColor
             (pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes,
              &exactRed, &exactGreen, &exactBlue)) {
-            xLookupColorReply lcr;
-            lcr.type = X_Reply;
-            lcr.length = 0;
-            lcr.sequenceNumber = client->sequence;
-            lcr.exactRed = exactRed;
-            lcr.exactGreen = exactGreen;
-            lcr.exactBlue = exactBlue;
-            lcr.screenRed = exactRed;
-            lcr.screenGreen = exactGreen;
-            lcr.screenBlue = exactBlue;
+            xLookupColorReply lcr = {
+                .type = X_Reply,
+                .sequenceNumber = client->sequence,
+                .length = 0,
+                .exactRed = exactRed,
+                .exactGreen = exactGreen,
+                .exactBlue = exactBlue,
+                .screenRed = exactRed,
+                .screenGreen = exactGreen,
+                .screenBlue = exactBlue
+            };
             (*pcmp->pScreen->ResolveColor) (&lcr.screenRed,
                                             &lcr.screenGreen,
                                             &lcr.screenBlue, pcmp->pVisual);
@@ -2995,12 +3001,13 @@ ProcQueryBestSize(ClientPtr client)
         return rc;
     (*pScreen->QueryBestSize) (stuff->class, &stuff->width,
                                &stuff->height, pScreen);
-    memset(&reply, 0, sizeof(xQueryBestSizeReply));
-    reply.type = X_Reply;
-    reply.length = 0;
-    reply.sequenceNumber = client->sequence;
-    reply.width = stuff->width;
-    reply.height = stuff->height;
+    reply = (xQueryBestSizeReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .width = stuff->width,
+        .height = stuff->height
+    };
     WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply);
     return Success;
 }
@@ -3080,13 +3087,15 @@ ProcGetScreenSaver(ClientPtr client)
             return rc;
     }
 
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
-    rep.timeout = ScreenSaverTime / MILLI_PER_SECOND;
-    rep.interval = ScreenSaverInterval / MILLI_PER_SECOND;
-    rep.preferBlanking = ScreenSaverBlanking;
-    rep.allowExposures = ScreenSaverAllowExposures;
+    rep = (xGetScreenSaverReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .timeout = ScreenSaverTime / MILLI_PER_SECOND,
+        .interval = ScreenSaverInterval / MILLI_PER_SECOND,
+        .preferBlanking = ScreenSaverBlanking,
+        .allowExposures = ScreenSaverAllowExposures
+    };
     WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep);
     return Success;
 }
@@ -3128,11 +3137,14 @@ ProcListHosts(ClientPtr client)
     result = GetHosts(&pdata, &nHosts, &len, &enabled);
     if (result != Success)
         return result;
-    reply.type = X_Reply;
-    reply.enabled = enabled;
-    reply.sequenceNumber = client->sequence;
-    reply.nHosts = nHosts;
-    reply.length = bytes_to_int32(len);
+
+    reply = (xListHostsReply) {
+        .type = X_Reply,
+        .enabled = enabled,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(len),
+        .nHosts = nHosts
+    };
     WriteReplyToClient(client, sizeof(xListHostsReply), &reply);
     if (nHosts) {
         client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend;
@@ -3247,10 +3259,12 @@ ProcGetFontPath(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.length = bytes_to_int32(stringLens + numpaths);
-    reply.nPaths = numpaths;
+    reply = (xGetFontPathReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(stringLens + numpaths),
+        .nPaths = numpaths
+    };
 
     WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply);
     if (stringLens || numpaths)
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index d1f6326..ad21860 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -753,11 +753,12 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
     for (i = 0; i < nnames; i++)
         stringLens += (names->length[i] <= 255) ? names->length[i] : 0;
 
-    memset(&reply, 0, sizeof(xListFontsReply));
-    reply.type = X_Reply;
-    reply.length = bytes_to_int32(stringLens + nnames);
-    reply.nFonts = nnames;
-    reply.sequenceNumber = client->sequence;
+    reply = (xListFontsReply) {
+        .type = X_Reply,
+        .length = bytes_to_int32(stringLens + nnames),
+        .nFonts = nnames,
+        .sequenceNumber = client->sequence
+    };
 
     bufptr = bufferStart = malloc(reply.length << 2);
 
@@ -1030,11 +1031,12 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
     }
  finish:
     length = sizeof(xListFontsWithInfoReply);
-    memset((char *) &finalReply, 0, sizeof(xListFontsWithInfoReply));
-    finalReply.type = X_Reply;
-    finalReply.sequenceNumber = client->sequence;
-    finalReply.length = bytes_to_int32(sizeof(xListFontsWithInfoReply)
-                                       - sizeof(xGenericReply));
+    finalReply = (xListFontsWithInfoReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(sizeof(xListFontsWithInfoReply)
+                                 - sizeof(xGenericReply))
+    };
     WriteSwappedDataToClient(client, length, &finalReply);
  bail:
     ClientWakeup(client);
diff --git a/dix/events.c b/dix/events.c
index c5eceec..1708710 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4767,17 +4767,20 @@ ProcGetInputFocus(ClientPtr client)
     if (rc != Success)
         return rc;
 
-    memset(&rep, 0, sizeof(xGetInputFocusReply));
-    rep.type = X_Reply;
-    rep.length = 0;
-    rep.sequenceNumber = client->sequence;
+    rep = (xGetInputFocusReply) {
+        .type = X_Reply,
+        .length = 0,
+        .sequenceNumber = client->sequence,
+        .revertTo = focus->revert
+    };
+
     if (focus->win == NoneWin)
         rep.focus = None;
     else if (focus->win == PointerRootWin)
         rep.focus = PointerRoot;
     else
         rep.focus = focus->win->drawable.id;
-    rep.revertTo = focus->revert;
+
     WriteReplyToClient(client, sizeof(xGetInputFocusReply), &rep);
     return Success;
 }
@@ -4840,11 +4843,12 @@ ProcGrabPointer(ClientPtr client)
     if (oldCursor && status == GrabSuccess)
         FreeCursor(oldCursor, (Cursor) 0);
 
-    memset(&rep, 0, sizeof(xGrabPointerReply));
-    rep.type = X_Reply;
-    rep.status = status;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
+    rep = (xGrabPointerReply) {
+        .type = X_Reply,
+        .status = status,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep);
     return Success;
 }
@@ -5080,11 +5084,12 @@ ProcGrabKeyboard(ClientPtr client)
     if (result != Success)
         return result;
 
-    memset(&rep, 0, sizeof(xGrabKeyboardReply));
-    rep.type = X_Reply;
-    rep.status = status;
-    rep.sequenceNumber = client->sequence;
-    rep.length = 0;
+    rep = (xGrabKeyboardReply) {
+        .type = X_Reply,
+        .status = status,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     WriteReplyToClient(client, sizeof(xGrabKeyboardReply), &rep);
     return Success;
 }
@@ -5147,15 +5152,16 @@ ProcQueryPointer(ClientPtr client)
     pSprite = mouse->spriteInfo->sprite;
     if (mouse->valuator->motionHintWindow)
         MaybeStopHint(mouse, client);
-    memset(&rep, 0, sizeof(xQueryPointerReply));
-    rep.type = X_Reply;
-    rep.sequenceNumber = client->sequence;
-    rep.mask = event_get_corestate(mouse, keyboard);
-    rep.length = 0;
-    rep.root = (GetCurrentRootWindow(mouse))->drawable.id;
-    rep.rootX = pSprite->hot.x;
-    rep.rootY = pSprite->hot.y;
-    rep.child = None;
+    rep = (xQueryPointerReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .mask = event_get_corestate(mouse, keyboard),
+        .root = (GetCurrentRootWindow(mouse))->drawable.id,
+        .rootX = pSprite->hot.x,
+        .rootY = pSprite->hot.y,
+        .child = None
+    };
     if (pSprite->hot.pScreen == pWin->drawable.pScreen) {
         rep.sameScreen = xTrue;
         rep.winX = pSprite->hot.x - pWin->drawable.x;
diff --git a/dix/extension.c b/dix/extension.c
index 3cdfb51..6380db3 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -252,11 +252,12 @@ ProcQueryExtension(ClientPtr client)
 
     REQUEST_FIXED_SIZE(xQueryExtensionReq, stuff->nbytes);
 
-    memset(&reply, 0, sizeof(xQueryExtensionReply));
-    reply.type = X_Reply;
-    reply.length = 0;
-    reply.major_opcode = 0;
-    reply.sequenceNumber = client->sequence;
+    reply = (xQueryExtensionReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .major_opcode = 0
+    };
 
     if (!NumExtensions)
         reply.present = xFalse;
@@ -284,11 +285,12 @@ ProcListExtensions(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xReq);
 
-    memset(&reply, 0, sizeof(xListExtensionsReply));
-    reply.type = X_Reply;
-    reply.nExtensions = 0;
-    reply.length = 0;
-    reply.sequenceNumber = client->sequence;
+    reply = (xListExtensionsReply) {
+        .type = X_Reply,
+        .nExtensions = 0,
+        .sequenceNumber = client->sequence,
+        .length = 0
+    };
     buffer = NULL;
 
     if (NumExtensions) {
diff --git a/dix/property.c b/dix/property.c
index 5ef97ee..5aa6f4a 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -415,15 +415,15 @@ DeleteAllWindowProperties(WindowPtr pWin)
 static int
 NullPropertyReply(ClientPtr client, ATOM propertyType, int format)
 {
-    xGetPropertyReply reply;
-    memset(&reply, 0, sizeof(xGetPropertyReply));
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.nItems = 0;
-    reply.length = 0;
-    reply.bytesAfter = 0;
-    reply.propertyType = propertyType;
-    reply.format = format;
+    xGetPropertyReply reply = {
+        .type = X_Reply,
+        .format = format,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+        .propertyType = propertyType,
+        .bytesAfter = 0,
+        .nItems = 0
+    };
     WriteReplyToClient(client, sizeof(xGenericReply), &reply);
     return Success;
 }
@@ -484,14 +484,15 @@ ProcGetProperty(ClientPtr client)
 
     if (((stuff->type != pProp->type) && (stuff->type != AnyPropertyType))
         ) {
-        memset(&reply, 0, sizeof(xGetPropertyReply));
-        reply.type = X_Reply;
-        reply.sequenceNumber = client->sequence;
-        reply.bytesAfter = pProp->size;
-        reply.format = pProp->format;
-        reply.length = 0;
-        reply.nItems = 0;
-        reply.propertyType = pProp->type;
+        reply = (xGetPropertyReply) {
+            .type = X_Reply,
+            .sequenceNumber = client->sequence,
+            .bytesAfter = pProp->size,
+            .format = pProp->format,
+            .length = 0,
+            .nItems = 0,
+            .propertyType = pProp->type
+        };
         WriteReplyToClient(client, sizeof(xGenericReply), &reply);
         return Success;
     }
@@ -512,14 +513,15 @@ ProcGetProperty(ClientPtr client)
 
     len = min(n - ind, 4 * stuff->longLength);
 
-    memset(&reply, 0, sizeof(xGetPropertyReply));
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-    reply.bytesAfter = n - (ind + len);
-    reply.format = pProp->format;
-    reply.length = bytes_to_int32(len);
-    reply.nItems = len / (pProp->format / 8);
-    reply.propertyType = pProp->type;
+    reply = (xGetPropertyReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .bytesAfter = n - (ind + len),
+        .format = pProp->format,
+        .length = bytes_to_int32(len),
+        .nItems = len / (pProp->format / 8),
+        .propertyType = pProp->type
+    };
 
     if (stuff->delete && (reply.bytesAfter == 0))
         deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName);
@@ -594,10 +596,12 @@ ProcListProperties(ClientPtr client)
         }
     }
 
-    xlpr.type = X_Reply;
-    xlpr.nProperties = numProps;
-    xlpr.length = bytes_to_int32(numProps * sizeof(Atom));
-    xlpr.sequenceNumber = client->sequence;
+    xlpr = (xListPropertiesReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = bytes_to_int32(numProps * sizeof(Atom)),
+        .nProperties = numProps
+    };
     WriteReplyToClient(client, sizeof(xGenericReply), &xlpr);
     if (numProps) {
         client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
diff --git a/dix/selection.c b/dix/selection.c
index dfdcfdc..80b5893 100644
--- a/dix/selection.c
+++ b/dix/selection.c
@@ -238,10 +238,11 @@ ProcGetSelectionOwner(ClientPtr client)
         return BadAtom;
     }
 
-    memset(&reply, 0, sizeof(xGetSelectionOwnerReply));
-    reply.type = X_Reply;
-    reply.length = 0;
-    reply.sequenceNumber = client->sequence;
+    reply = (xGetSelectionOwnerReply) {
+        .type = X_Reply,
+        .sequenceNumber = client->sequence,
+        .length = 0,
+    };
 
     rc = dixLookupSelection(&pSel, stuff->id, client, DixGetAttrAccess);
     if (rc == Success)
commit 69fa5630b5902aaad267fc67d0da4ca93625886a
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:43 2012 -0700

    Use C99 designated initializers in SendErrorToClient
    
    Let the compiler worry about 0-filling the rest of the fields,
    instead of memsetting the whole struct and then going back to
    overwrite some of the fields.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 787f87f..5982a49 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3625,14 +3625,13 @@ void
 SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode,
                   XID resId, int errorCode)
 {
-    xError rep;
-
-    memset(&rep, 0, sizeof(xError));
-    rep.type = X_Error;
-    rep.errorCode = errorCode;
-    rep.majorCode = majorCode;
-    rep.minorCode = minorCode;
-    rep.resourceID = resId;
+    xError rep = {
+        .type = X_Error,
+        .errorCode = errorCode,
+        .resourceID = resId,
+        .minorCode = minorCode,
+        .majorCode = majorCode
+    };
 
     WriteEventsToClient(client, 1, (xEvent *) &rep);
 }
commit cdf5bcd420e5bcf4a4a24a275d3133a4e16ce41e
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    Use calloc to zero fill buffers being allocated for replies & events
    
    Ensures padding bytes are zero-filled
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xext/sync.c b/Xext/sync.c
index 6dc4c5e..fc712cd 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -475,7 +475,7 @@ SyncSendCounterNotifyEvents(ClientPtr client, SyncAwait ** ppAwait,
 
     if (client->clientGone)
         return;
-    pev = pEvents = malloc(num_events * sizeof(xSyncCounterNotifyEvent));
+    pev = pEvents = calloc(num_events, sizeof(xSyncCounterNotifyEvent));
     if (!pEvents)
         return;
     UpdateCurrentTime();
diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index 3a1e1b2..a902861 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -554,7 +554,7 @@ ProcXF86BigfontQueryFont(ClientPtr client)
                ? nUniqCharInfos * sizeof(xCharInfo)
                + (nCharInfos + 1) / 2 * 2 * sizeof(CARD16)
                : 0);
-        xXF86BigfontQueryFontReply *reply = malloc(rlength);
+        xXF86BigfontQueryFontReply *reply = calloc(1, rlength);
         char *p;
 
         if (!reply) {
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 9cb9e73..c1c836f 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2315,7 +2315,7 @@ __glXDisp_QueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
     reply.n = n;
 
     /* Allocate buffer to make sure it's a multiple of 4 bytes big. */
-    buf = (char *) malloc(length << 2);
+    buf = calloc(length, 4);
     if (buf == NULL)
         return BadAlloc;
     memcpy(buf, pGlxScreen->GLXextensions, n);
@@ -2375,7 +2375,7 @@ __glXDisp_QueryServerString(__GLXclientState * cl, GLbyte * pc)
     reply.length = length;
     reply.n = n;
 
-    buf = (char *) malloc(length << 2);
+    buf = calloc(length, 4);
     if (buf == NULL) {
         return BadAlloc;
     }
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 2fdf9e9..0435cb6 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -1354,7 +1354,7 @@ ProcXF86VidModeGetDotClocks(ClientPtr client)
     rep.flags = 0;
 
     if (!ClockProg) {
-        Clocks = malloc(numClocks * sizeof(int));
+        Clocks = calloc(numClocks, sizeof(int));
         if (!Clocks)
             return BadValue;
         if (!VidModeGetClocks(stuff->screen, Clocks)) {
diff --git a/mi/miexpose.c b/mi/miexpose.c
index dbb29ca..2dc465d 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -327,7 +327,7 @@ miSendGraphicsExpose(ClientPtr client, RegionPtr pRgn, XID drawable,
 
         numRects = RegionNumRects(pRgn);
         pBox = RegionRects(pRgn);
-        if (!(pEvent = malloc(numRects * sizeof(xEvent))))
+        if (!(pEvent = calloc(numRects, sizeof(xEvent))))
             return;
         pe = pEvent;
 
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index ee29f37..c91c7fd 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1526,7 +1526,7 @@ ProcRRGetCrtcTransform(ClientPtr client)
     nextra = (transform_filter_length(pending) +
               transform_filter_length(current));
 
-    reply = malloc(sizeof(xRRGetCrtcTransformReply) + nextra);
+    reply = calloc(1, sizeof(xRRGetCrtcTransformReply) + nextra);
     if (!reply)
         return BadAlloc;
 
diff --git a/render/render.c b/render/render.c
index be7d21e..3bf0702 100644
--- a/render/render.c
+++ b/render/render.c
@@ -531,7 +531,7 @@ ProcRenderQueryPictIndexValues(ClientPtr client)
     num = pFormat->index.nvalues;
     rlength = (sizeof(xRenderQueryPictIndexValuesReply) +
                num * sizeof(xIndexValue));
-    reply = (xRenderQueryPictIndexValuesReply *) malloc(rlength);
+    reply = (xRenderQueryPictIndexValuesReply *) calloc(1, rlength);
     if (!reply)
         return BadAlloc;
 
@@ -1688,7 +1688,7 @@ ProcRenderQueryFilters(ClientPtr client)
     }
     len = ((nnames + 1) >> 1) + bytes_to_int32(nbytesName);
     total_bytes = sizeof(xRenderQueryFiltersReply) + (len << 2);
-    reply = (xRenderQueryFiltersReply *) malloc(total_bytes);
+    reply = (xRenderQueryFiltersReply *) calloc(1, total_bytes);
     if (!reply)
         return BadAlloc;
     aliases = (INT16 *) (reply + 1);
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 79530f9..402456d 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -380,7 +380,8 @@ ProcXFixesGetCursorImage(ClientPtr client)
     width = pCursor->bits->width;
     height = pCursor->bits->height;
     npixels = width * height;
-    rep = malloc(sizeof(xXFixesGetCursorImageReply) + npixels * sizeof(CARD32));
+    rep = calloc(sizeof(xXFixesGetCursorImageReply) + npixels * sizeof(CARD32),
+                 1);
     if (!rep)
         return BadAlloc;
 
@@ -529,8 +530,8 @@ ProcXFixesGetCursorImageAndName(ClientPtr client)
     name = pCursor->name ? NameForAtom(pCursor->name) : "";
     nbytes = strlen(name);
     nbytesRound = pad_to_int32(nbytes);
-    rep = malloc(sizeof(xXFixesGetCursorImageAndNameReply) +
-                 npixels * sizeof(CARD32) + nbytesRound);
+    rep = calloc(sizeof(xXFixesGetCursorImageAndNameReply) +
+                 npixels * sizeof(CARD32) + nbytesRound, 1);
     if (!rep)
         return BadAlloc;
 
diff --git a/xfixes/region.c b/xfixes/region.c
index 89675e5..0e9ca44 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -557,7 +557,8 @@ ProcXFixesFetchRegion(ClientPtr client)
     pBox = RegionRects(pRegion);
     nBox = RegionNumRects(pRegion);
 
-    reply = malloc(sizeof(xXFixesFetchRegionReply) + nBox * sizeof(xRectangle));
+    reply = calloc(sizeof(xXFixesFetchRegionReply) + nBox * sizeof(xRectangle),
+                   1);
     if (!reply)
         return BadAlloc;
     reply->type = X_Reply;
commit ef0f701c9245b0373eb0c7a84dd804af4738bb29
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    xf86dga2.c & xf86vmode.c: Move REQUEST_SIZE_MATCH checks before using stuff
    
    Seems silly waiting to check if the client failed to send us enough bytes
    until after we've already tried using them.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 1ed6a50..347282c 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -96,13 +96,14 @@ ProcXDGAOpenFramebuffer(ClientPtr client)
     char *deviceName;
     int nameSize;
 
+    REQUEST_SIZE_MATCH(xXDGAOpenFramebufferReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (!DGAAvailable(stuff->screen))
         return DGAErrorBase + XF86DGANoDirectVideoMode;
 
-    REQUEST_SIZE_MATCH(xXDGAOpenFramebufferReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -129,14 +130,14 @@ ProcXDGACloseFramebuffer(ClientPtr client)
 {
     REQUEST(xXDGACloseFramebufferReq);
 
+    REQUEST_SIZE_MATCH(xXDGACloseFramebufferReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (!DGAAvailable(stuff->screen))
         return DGAErrorBase + XF86DGANoDirectVideoMode;
 
-    REQUEST_SIZE_MATCH(xXDGACloseFramebufferReq);
-
     DGACloseFramebuffer(stuff->screen);
 
     return Success;
@@ -152,10 +153,11 @@ ProcXDGAQueryModes(ClientPtr client)
     xXDGAModeInfo info;
     XDGAModePtr mode;
 
+    REQUEST_SIZE_MATCH(xXDGAQueryModesReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    REQUEST_SIZE_MATCH(xXDGAQueryModesReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.number = 0;
@@ -267,11 +269,12 @@ ProcXDGASetMode(ClientPtr client)
     ClientPtr owner;
     int size;
 
+    REQUEST_SIZE_MATCH(xXDGASetModeReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
     owner = DGA_GETCLIENT(stuff->screen);
 
-    REQUEST_SIZE_MATCH(xXDGASetModeReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.offset = 0;
@@ -357,14 +360,14 @@ ProcXDGASetViewport(ClientPtr client)
 {
     REQUEST(xXDGASetViewportReq);
 
+    REQUEST_SIZE_MATCH(xXDGASetViewportReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGASetViewportReq);
-
     DGASetViewport(stuff->screen, stuff->x, stuff->y, stuff->flags);
 
     return Success;
@@ -378,14 +381,14 @@ ProcXDGAInstallColormap(ClientPtr client)
 
     REQUEST(xXDGAInstallColormapReq);
 
+    REQUEST_SIZE_MATCH(xXDGAInstallColormapReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGAInstallColormapReq);
-
     rc = dixLookupResourceByType((pointer *) &cmap, stuff->cmap, RT_COLORMAP,
                                  client, DixInstallAccess);
     if (rc != Success)
@@ -399,14 +402,14 @@ ProcXDGASelectInput(ClientPtr client)
 {
     REQUEST(xXDGASelectInputReq);
 
+    REQUEST_SIZE_MATCH(xXDGASelectInputReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGASelectInputReq);
-
     if (DGA_GETCLIENT(stuff->screen) == client)
         DGASelectInput(stuff->screen, client, stuff->mask);
 
@@ -418,14 +421,14 @@ ProcXDGAFillRectangle(ClientPtr client)
 {
     REQUEST(xXDGAFillRectangleReq);
 
+    REQUEST_SIZE_MATCH(xXDGAFillRectangleReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGAFillRectangleReq);
-
     if (Success != DGAFillRect(stuff->screen, stuff->x, stuff->y,
                                stuff->width, stuff->height, stuff->color))
         return BadMatch;
@@ -438,14 +441,14 @@ ProcXDGACopyArea(ClientPtr client)
 {
     REQUEST(xXDGACopyAreaReq);
 
+    REQUEST_SIZE_MATCH(xXDGACopyAreaReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGACopyAreaReq);
-
     if (Success != DGABlitRect(stuff->screen, stuff->srcx, stuff->srcy,
                                stuff->width, stuff->height, stuff->dstx,
                                stuff->dsty))
@@ -459,14 +462,14 @@ ProcXDGACopyTransparentArea(ClientPtr client)
 {
     REQUEST(xXDGACopyTransparentAreaReq);
 
+    REQUEST_SIZE_MATCH(xXDGACopyTransparentAreaReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGACopyTransparentAreaReq);
-
     if (Success != DGABlitTransRect(stuff->screen, stuff->srcx, stuff->srcy,
                                     stuff->width, stuff->height, stuff->dstx,
                                     stuff->dsty, stuff->key))
@@ -481,13 +484,14 @@ ProcXDGAGetViewportStatus(ClientPtr client)
     REQUEST(xXDGAGetViewportStatusReq);
     xXDGAGetViewportStatusReply rep;
 
+    REQUEST_SIZE_MATCH(xXDGAGetViewportStatusReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGAGetViewportStatusReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -504,13 +508,14 @@ ProcXDGASync(ClientPtr client)
     REQUEST(xXDGASyncReq);
     xXDGASyncReply rep;
 
+    REQUEST_SIZE_MATCH(xXDGASyncReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGASyncReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -549,13 +554,14 @@ ProcXDGAChangePixmapMode(ClientPtr client)
     xXDGAChangePixmapModeReply rep;
     int x, y;
 
+    REQUEST_SIZE_MATCH(xXDGAChangePixmapModeReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGAChangePixmapModeReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -579,14 +585,14 @@ ProcXDGACreateColormap(ClientPtr client)
     REQUEST(xXDGACreateColormapReq);
     int result;
 
+    REQUEST_SIZE_MATCH(xXDGACreateColormapReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXDGACreateColormapReq);
-
     if (!stuff->mode)
         return BadValue;
 
@@ -615,10 +621,11 @@ ProcXF86DGAGetVideoLL(ClientPtr client)
     int num, offset, flags;
     char *name;
 
+    REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -655,9 +662,10 @@ ProcXF86DGADirectVideo(ClientPtr client)
 
     REQUEST(xXF86DGADirectVideoReq);
 
+    REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
-    REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
 
     if (!DGAAvailable(stuff->screen))
         return DGAErrorBase + XF86DGANoDirectVideoMode;
@@ -713,10 +721,11 @@ ProcXF86DGAGetViewPortSize(ClientPtr client)
     REQUEST(xXF86DGAGetViewPortSizeReq);
     xXF86DGAGetViewPortSizeReply rep;
 
+    REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -741,14 +750,14 @@ ProcXF86DGASetViewPort(ClientPtr client)
 {
     REQUEST(xXF86DGASetViewPortReq);
 
+    REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq);
-
     if (!DGAAvailable(stuff->screen))
         return DGAErrorBase + XF86DGANoDirectVideoMode;
 
@@ -768,10 +777,11 @@ ProcXF86DGAGetVidPage(ClientPtr client)
     REQUEST(xXF86DGAGetVidPageReq);
     xXF86DGAGetVidPageReply rep;
 
+    REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -786,11 +796,11 @@ ProcXF86DGASetVidPage(ClientPtr client)
 {
     REQUEST(xXF86DGASetVidPageReq);
 
+    REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq);
-
     /* silently fail */
 
     return Success;
@@ -804,14 +814,14 @@ ProcXF86DGAInstallColormap(ClientPtr client)
 
     REQUEST(xXF86DGAInstallColormapReq);
 
+    REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq);
-
     if (!DGAActive(stuff->screen))
         return DGAErrorBase + XF86DGADirectNotActivated;
 
@@ -832,10 +842,11 @@ ProcXF86DGAQueryDirectVideo(ClientPtr client)
     REQUEST(xXF86DGAQueryDirectVideoReq);
     xXF86DGAQueryDirectVideoReply rep;
 
+    REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -854,14 +865,14 @@ ProcXF86DGAViewPortChanged(ClientPtr client)
     REQUEST(xXF86DGAViewPortChangedReq);
     xXF86DGAViewPortChangedReply rep;
 
+    REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (DGA_GETCLIENT(stuff->screen) != client)
         return DGAErrorBase + XF86DGADirectNotActivated;
 
-    REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
-
     if (!DGAActive(stuff->screen))
         return DGAErrorBase + XF86DGADirectNotActivated;
 
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index bac5f11..2fdf9e9 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -1481,14 +1481,14 @@ ProcXF86VidModeGetGammaRamp(ClientPtr client)
 
     REQUEST(xXF86VidModeGetGammaRampReq);
 
+    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
     if (stuff->size != VidModeGetGammaRampSize(stuff->screen))
         return BadValue;
 
-    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampReq);
-
     length = (stuff->size + 1) & ~1;
 
     if (stuff->size) {
@@ -1529,11 +1529,11 @@ ProcXF86VidModeGetGammaRampSize(ClientPtr client)
 
     REQUEST(xXF86VidModeGetGammaRampSizeReq);
 
+    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampSizeReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    REQUEST_SIZE_MATCH(xXF86VidModeGetGammaRampSizeReq);
-
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -1555,11 +1555,11 @@ ProcXF86VidModeGetPermissions(ClientPtr client)
 
     REQUEST(xXF86VidModeGetPermissionsReq);
 
+    REQUEST_SIZE_MATCH(xXF86VidModeGetPermissionsReq);
+
     if (stuff->screen >= screenInfo.numScreens)
         return BadValue;
 
-    REQUEST_SIZE_MATCH(xXF86VidModeGetPermissionsReq);
-
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
commit 2e739a8870d91fbac7f536ffa8f6d2cee0f66cec
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    ProcRRListOutputProperties: skip atom walk if the list is empty
    
    pAtoms is only allocated if numProps was non-zero, so move the walk
    through the property list to copy atoms to it inside the if (numProps)
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index e8f0578..b0a1cf9 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -378,7 +378,7 @@ int
 ProcRRListOutputProperties(ClientPtr client)
 {
     REQUEST(xRRListOutputPropertiesReq);
-    Atom *pAtoms = NULL, *temppAtoms;
+    Atom *pAtoms = NULL;
     xRRListOutputPropertiesReply rep;
     int numProps = 0;
     RROutputPtr output;
@@ -403,12 +403,14 @@ ProcRRListOutputProperties(ClientPtr client)
         swapl(&rep.length);
         swaps(&rep.nAtoms);
     }
-    temppAtoms = pAtoms;
-    for (prop = output->properties; prop; prop = prop->next)
-        *temppAtoms++ = prop->propertyName;
-
     WriteToClient(client, sizeof(xRRListOutputPropertiesReply), &rep);
+
     if (numProps) {
+        /* Copy property name atoms to reply buffer */
+        Atom *temppAtoms = pAtoms;
+        for (prop = output->properties; prop; prop = prop->next)
+            *temppAtoms++ = prop->propertyName;
+
         client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
         WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms);
         free(pAtoms);
commit 15bc13c8d088e05f14c7262348e0066929c29251
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    ProcRRGetScreenInfo: swap configTimestamp as well
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 236794a..6fd24e0 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -854,6 +854,7 @@ ProcRRGetScreenInfo(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
         swapl(&rep.timestamp);
+        swapl(&rep.configTimestamp);
         swaps(&rep.rotation);
         swaps(&rep.nSizes);
         swaps(&rep.sizeID);
commit 3a013b8816bc0bb765c99e8a2bf2ea536dc62c3b
Author: Jaroslav Šmíd <jardasmid at gmail.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    Bug 51375: Xorg doesn't set status for RRGetOutputInfo
    
    https://bugs.freedesktop.org/show_bug.cgi?id=51375
    https://bugs.freedesktop.org/attachment.cgi?id=63397
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/randr/rroutput.c b/randr/rroutput.c
index fd03aab..3662a5a 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -426,6 +426,7 @@ ProcRRGetOutputInfo(ClientPtr client)
     pScrPriv = rrGetScrPriv(pScreen);
 
     rep.type = X_Reply;
+    rep.status = RRSetConfigSuccess;
     rep.sequenceNumber = client->sequence;
     rep.length = bytes_to_int32(OutputInfoExtra);
     rep.timestamp = pScrPriv->lastSetTime.milliseconds;
commit 5b86c072d1d586ce040d8831a05cf97ff8b17821
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    Use temporary variables instead of parts of reply structures
    
    When passing variable pointers to functions or otherwise doing long
    sequences to compute values for replies, create & use some new
    temporary variables, to allow for simpler initialization of reply
    structures in the following patches.
    
    Move memsets & other initializations to group with the rest of the
    filling in of the reply structure, now that they're not needed so
    early in the code path.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xext/shm.c b/Xext/shm.c
index aa3feae..a732170 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -616,6 +616,7 @@ ProcShmGetImage(ClientPtr client)
     Mask plane = 0;
     xShmGetImageReply xgi;
     ShmDescPtr shmdesc;
+    VisualID visual = None;
     int rc;
 
     REQUEST(xShmGetImageReq);
@@ -646,18 +647,19 @@ ProcShmGetImage(ClientPtr client)
                stuff->y + (int) stuff->height >
                wBorderWidth((WindowPtr) pDraw) + (int) pDraw->height)
             return BadMatch;
-        xgi.visual = wVisual(((WindowPtr) pDraw));
+        visual = wVisual(((WindowPtr) pDraw));
     }
     else {
         if (stuff->x < 0 ||
             stuff->x + (int) stuff->width > pDraw->width ||
             stuff->y < 0 || stuff->y + (int) stuff->height > pDraw->height)
             return BadMatch;
-        xgi.visual = None;
+        visual = None;
     }
     xgi.type = X_Reply;
     xgi.length = 0;
     xgi.sequenceNumber = client->sequence;
+    xgi.visual = visual;
     xgi.depth = pDraw->depth;
     if (stuff->format == ZPixmap) {
         length = PixmapBytePad(stuff->width, pDraw->depth) * stuff->height;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 4231cb0..787f87f 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -2801,17 +2801,21 @@ ProcLookupColor(ClientPtr client)
     rc = dixLookupResourceByType((pointer *) &pcmp, stuff->cmap, RT_COLORMAP,
                                  client, DixReadAccess);
     if (rc == Success) {
-        xLookupColorReply lcr;
+        CARD16 exactRed, exactGreen, exactBlue;
 
         if (OsLookupColor
             (pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes,
-             &lcr.exactRed, &lcr.exactGreen, &lcr.exactBlue)) {
+             &exactRed, &exactGreen, &exactBlue)) {
+            xLookupColorReply lcr;
             lcr.type = X_Reply;
             lcr.length = 0;
             lcr.sequenceNumber = client->sequence;
-            lcr.screenRed = lcr.exactRed;
-            lcr.screenGreen = lcr.exactGreen;
-            lcr.screenBlue = lcr.exactBlue;
+            lcr.exactRed = exactRed;
+            lcr.exactGreen = exactGreen;
+            lcr.exactBlue = exactBlue;
+            lcr.screenRed = exactRed;
+            lcr.screenGreen = exactGreen;
+            lcr.screenBlue = exactBlue;
             (*pcmp->pScreen->ResolveColor) (&lcr.screenRed,
                                             &lcr.screenGreen,
                                             &lcr.screenBlue, pcmp->pVisual);
@@ -3109,6 +3113,7 @@ ProcListHosts(ClientPtr client)
 {
     xListHostsReply reply;
     int len, nHosts, result;
+    BOOL enabled;
     pointer pdata;
 
     /* REQUEST(xListHostsReq); */
@@ -3120,10 +3125,11 @@ ProcListHosts(ClientPtr client)
     if (result != Success)
         return result;
 
-    result = GetHosts(&pdata, &nHosts, &len, &reply.enabled);
+    result = GetHosts(&pdata, &nHosts, &len, &enabled);
     if (result != Success)
         return result;
     reply.type = X_Reply;
+    reply.enabled = enabled;
     reply.sequenceNumber = client->sequence;
     reply.nHosts = nHosts;
     reply.length = bytes_to_int32(len);
diff --git a/dix/events.c b/dix/events.c
index 6e4385a..c5eceec 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4797,6 +4797,7 @@ ProcGrabPointer(ClientPtr client)
     GrabMask mask;
     WindowPtr confineTo;
     CursorPtr oldCursor;
+    BYTE status;
 
     REQUEST(xGrabPointerReq);
     int rc;
@@ -4818,7 +4819,6 @@ ProcGrabPointer(ClientPtr client)
             return rc;
     }
 
-    memset(&rep, 0, sizeof(xGrabPointerReply));
     oldCursor = NullCursor;
     grab = device->deviceGrab.grab;
 
@@ -4833,14 +4833,16 @@ ProcGrabPointer(ClientPtr client)
 
     rc = GrabDevice(client, device, stuff->pointerMode, stuff->keyboardMode,
                     stuff->grabWindow, stuff->ownerEvents, stuff->time,
-                    &mask, CORE, stuff->cursor, stuff->confineTo, &rep.status);
+                    &mask, CORE, stuff->cursor, stuff->confineTo, &status);
     if (rc != Success)
         return rc;
 
-    if (oldCursor && rep.status == GrabSuccess)
+    if (oldCursor && status == GrabSuccess)
         FreeCursor(oldCursor, (Cursor) 0);
 
+    memset(&rep, 0, sizeof(xGrabPointerReply));
     rep.type = X_Reply;
+    rep.status = status;
     rep.sequenceNumber = client->sequence;
     rep.length = 0;
     WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep);
@@ -5059,6 +5061,7 @@ int
 ProcGrabKeyboard(ClientPtr client)
 {
     xGrabKeyboardReply rep;
+    BYTE status;
 
     REQUEST(xGrabKeyboardReq);
     int result;
@@ -5067,17 +5070,19 @@ ProcGrabKeyboard(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xGrabKeyboardReq);
 
-    memset(&rep, 0, sizeof(xGrabKeyboardReply));
     mask.core = KeyPressMask | KeyReleaseMask;
 
     result = GrabDevice(client, keyboard, stuff->pointerMode,
                         stuff->keyboardMode, stuff->grabWindow,
                         stuff->ownerEvents, stuff->time, &mask, CORE, None,
-                        None, &rep.status);
+                        None, &status);
 
     if (result != Success)
         return result;
+
+    memset(&rep, 0, sizeof(xGrabKeyboardReply));
     rep.type = X_Reply;
+    rep.status = status;
     rep.sequenceNumber = client->sequence;
     rep.length = 0;
     WriteReplyToClient(client, sizeof(xGrabKeyboardReply), &rep);
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index aefbcfb..65e0ff8 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -586,6 +586,7 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
     xXF86DRIOpenConnectionReply rep;
     drm_handle_t hSAREA;
     char *busIdString = NULL;
+    CARD32 busIdStringLength = 0;
 
     REQUEST(xXF86DRIOpenConnectionReq);
     REQUEST_SIZE_MATCH(xXF86DRIOpenConnectionReq);
@@ -600,15 +601,16 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
         return BadValue;
     }
 
+    if (busIdString)
+        busIdStringLength = strlen(busIdString);
+
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
-    rep.busIdStringLength = 0;
-    if (busIdString)
-        rep.busIdStringLength = strlen(busIdString);
+    rep.busIdStringLength = busIdStringLength;
     rep.length =
         bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) -
                        SIZEOF(xGenericReply) +
-                       pad_to_int32(rep.busIdStringLength));
+                       pad_to_int32(busIdStringLength));
 
     rep.hSAREALow = (CARD32) (hSAREA & 0xffffffff);
 #if defined(LONG64) && !defined(__linux__)
@@ -618,8 +620,8 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
 #endif
 
     WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), &rep);
-    if (rep.busIdStringLength)
-        WriteToClient(client, rep.busIdStringLength, busIdString);
+    if (busIdStringLength)
+        WriteToClient(client, busIdStringLength, busIdString);
     free(busIdString);
     EPHYR_LOG("leave\n");
     return Success;
diff --git a/hw/kdrive/ephyr/ephyrglxext.c b/hw/kdrive/ephyr/ephyrglxext.c
index 1287e04..f5c4c18 100644
--- a/hw/kdrive/ephyr/ephyrglxext.c
+++ b/hw/kdrive/ephyr/ephyrglxext.c
@@ -512,6 +512,7 @@ ephyrGLXMakeCurrentReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
     xGLXMakeCurrentReq *req = (xGLXMakeCurrentReq *) a_pc;
     xGLXMakeCurrentReply reply;
     DrawablePtr drawable = NULL;
+    GLXContextTag contextTag = 0;
     int rc = 0;
 
     EPHYR_LOG("enter\n");
@@ -525,13 +526,14 @@ ephyrGLXMakeCurrentReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
     if (!ephyrHostGLXMakeCurrent(hostx_get_window(drawable->pScreen->myNum),
                                  req->context,
                                  req->oldContextTag,
-                                 (int *) &reply.contextTag)) {
+                                 (int *) &contextTag)) {
         EPHYR_LOG_ERROR("ephyrHostGLXMakeCurrent() failed\n");
         goto out;
     }
     reply.length = 0;
     reply.type = X_Reply;
     reply.sequenceNumber = a_cl->client->sequence;
+    reply.contextTag = contextTag;
     if (a_do_swap) {
         __GLX_DECLARE_SWAP_VARIABLES;
         __GLX_SWAP_SHORT(&reply.sequenceNumber);
diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
index ee7b213..43504b7 100644
--- a/hw/xfree86/dri/xf86dri.c
+++ b/hw/xfree86/dri/xf86dri.c
@@ -141,6 +141,7 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
     xXF86DRIOpenConnectionReply rep;
     drm_handle_t hSAREA;
     char *busIdString;
+    CARD32 busIdStringLength = 0;
 
     REQUEST(xXF86DRIOpenConnectionReq);
     REQUEST_SIZE_MATCH(xXF86DRIOpenConnectionReq);
@@ -154,11 +155,12 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
         return BadValue;
     }
 
+    if (busIdString)
+        busIdStringLength = strlen(busIdString);
+
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
-    rep.busIdStringLength = 0;
-    if (busIdString)
-        rep.busIdStringLength = strlen(busIdString);
+    rep.busIdStringLength = busIdStringLength;
     rep.length =
         bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) -
                        SIZEOF(xGenericReply) +
@@ -172,8 +174,8 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
 #endif
 
     WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), &rep);
-    if (rep.busIdStringLength)
-        WriteToClient(client, rep.busIdStringLength, busIdString);
+    if (busIdStringLength)
+        WriteToClient(client, busIdStringLength, busIdString);
     return Success;
 }
 
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 7616e7c..ee29f37 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -999,6 +999,7 @@ ProcRRSetCrtcConfig(ClientPtr client)
     TimeStamp time;
     Rotation rotation;
     int ret, i, j;
+    CARD8 status;
 
     REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigReq);
     numOutputs = (stuff->length - bytes_to_int32(SIZEOF(xRRSetCrtcConfigReq)));
@@ -1077,7 +1078,7 @@ ProcRRSetCrtcConfig(ClientPtr client)
 
     if (!pScrPriv) {
         time = currentTime;
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
         goto sendReply;
     }
 
@@ -1161,17 +1162,17 @@ ProcRRSetCrtcConfig(ClientPtr client)
 
     if (!RRCrtcSet(crtc, mode, stuff->x, stuff->y,
                    rotation, numOutputs, outputs)) {
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
         goto sendReply;
     }
-    rep.status = RRSetConfigSuccess;
+    status = RRSetConfigSuccess;
     pScrPriv->lastSetTime = time;
 
  sendReply:
     free(outputs);
 
     rep.type = X_Reply;
-    /* rep.status has already been filled in */
+    rep.status = status;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
     rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
@@ -1266,6 +1267,7 @@ ProcRRSetPanning(ClientPtr client)
     BoxRec total;
     BoxRec tracking;
     INT16 border[4];
+    CARD8 status;
 
     REQUEST_SIZE_MATCH(xRRSetPanningReq);
     VERIFY_RR_CRTC(stuff->crtc, crtc, DixReadAccess);
@@ -1278,7 +1280,7 @@ ProcRRSetPanning(ClientPtr client)
 
     if (!pScrPriv) {
         time = currentTime;
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
         goto sendReply;
     }
 
@@ -1305,10 +1307,11 @@ ProcRRSetPanning(ClientPtr client)
 
     pScrPriv->lastSetTime = time;
 
-    rep.status = RRSetConfigSuccess;
+    status = RRSetConfigSuccess;
 
  sendReply:
     rep.type = X_Reply;
+    rep.status = status;
     rep.sequenceNumber = client->sequence;
     rep.length = 0;
     rep.newTimestamp = pScrPriv->lastSetTime.milliseconds;
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index ec07bb1..236794a 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -882,6 +882,7 @@ ProcRRSetScreenConfig(ClientPtr client)
     Rotation rotation;
     int rate;
     Bool has_rate;
+    CARD8 status;
     RROutputPtr output;
     RRCrtcPtr crtc;
     RRModePtr mode;
@@ -912,7 +913,7 @@ ProcRRSetScreenConfig(ClientPtr client)
 
     if (!pScrPriv) {
         time = currentTime;
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
         goto sendReply;
     }
     if (!RRGetInfo(pScreen, FALSE))
@@ -921,7 +922,7 @@ ProcRRSetScreenConfig(ClientPtr client)
     output = RRFirstOutput(pScreen);
     if (!output) {
         time = currentTime;
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
         goto sendReply;
     }
 
@@ -937,7 +938,7 @@ ProcRRSetScreenConfig(ClientPtr client)
      * stop working after several hours have passed (freedesktop bug #6502).
      */
     if (stuff->configTimestamp != pScrPriv->lastConfigTime.milliseconds) {
-        rep.status = RRSetConfigInvalidConfigTime;
+        status = RRSetConfigInvalidConfigTime;
         goto sendReply;
     }
 
@@ -1016,7 +1017,7 @@ ProcRRSetScreenConfig(ClientPtr client)
      * the last set-time
      */
     if (CompareTimeStamps(time, pScrPriv->lastSetTime) < 0) {
-        rep.status = RRSetConfigInvalidTime;
+        status = RRSetConfigInvalidTime;
         goto sendReply;
     }
 
@@ -1048,24 +1049,24 @@ ProcRRSetScreenConfig(ClientPtr client)
         for (c = 0; c < pScrPriv->numCrtcs; c++) {
             if (!RRCrtcSet(pScrPriv->crtcs[c], NULL, 0, 0, RR_Rotate_0,
                            0, NULL)) {
-                rep.status = RRSetConfigFailed;
+                status = RRSetConfigFailed;
                 /* XXX recover from failure */
                 goto sendReply;
             }
         }
         if (!RRScreenSizeSet(pScreen, width, height,
                              pScreen->mmWidth, pScreen->mmHeight)) {
-            rep.status = RRSetConfigFailed;
+            status = RRSetConfigFailed;
             /* XXX recover from failure */
             goto sendReply;
         }
     }
 
     if (!RRCrtcSet(crtc, mode, 0, 0, stuff->rotation, 1, &output))
-        rep.status = RRSetConfigFailed;
+        status = RRSetConfigFailed;
     else {
         pScrPriv->lastSetTime = time;
-        rep.status = RRSetConfigSuccess;
+        status = RRSetConfigSuccess;
     }
 
     /*
@@ -1077,7 +1078,7 @@ ProcRRSetScreenConfig(ClientPtr client)
     free(pData);
 
     rep.type = X_Reply;
-    /* rep.status has already been filled in */
+    rep.status = status;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
 
diff --git a/randr/rrxinerama.c b/randr/rrxinerama.c
index 269a63f..da3942f 100644
--- a/randr/rrxinerama.c
+++ b/randr/rrxinerama.c
@@ -299,16 +299,19 @@ ProcRRXineramaQueryScreens(ClientPtr client)
 {
     xXineramaQueryScreensReply rep;
     ScreenPtr pScreen = screenInfo.screens[RR_XINERAMA_SCREEN];
+    int n = 0;
 
     REQUEST_SIZE_MATCH(xXineramaQueryScreensReq);
 
-    if (RRXineramaScreenActive(pScreen))
+    if (RRXineramaScreenActive(pScreen)) {
         RRGetInfo(pScreen, FALSE);
+        n = RRXineramaScreenCount(pScreen);
+    }
 
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
-    rep.number = RRXineramaScreenCount(pScreen);
-    rep.length = bytes_to_int32(rep.number * sz_XineramaScreenInfo);
+    rep.number = n;
+    rep.length = bytes_to_int32(n * sz_XineramaScreenInfo);
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
@@ -316,7 +319,7 @@ ProcRRXineramaQueryScreens(ClientPtr client)
     }
     WriteToClient(client, sizeof(xXineramaQueryScreensReply), &rep);
 
-    if (rep.number) {
+    if (n) {
         rrScrPriv(pScreen);
         int i;
         int has_primary = 0;
diff --git a/record/record.c b/record/record.c
index a3ee4dd..54a0e68 100644
--- a/record/record.c
+++ b/record/record.c
@@ -2135,6 +2135,7 @@ ProcRecordGetContext(ClientPtr client)
     GetContextRangeInfoPtr pri;
     int i;
     int err;
+    CARD32 nClients, length;
 
     REQUEST_SIZE_MATCH(xRecordGetContextReq);
     VERIFY_CONTEXT(pContext, stuff->context, client);
@@ -2218,12 +2219,12 @@ ProcRecordGetContext(ClientPtr client)
 
     /* calculate number of clients and reply length */
 
-    rep.nClients = 0;
-    rep.length = 0;
+    nClients = 0;
+    length = 0;
     for (pRCAP = pContext->pListOfRCAP, pri = pRangeInfo;
          pRCAP; pRCAP = pRCAP->pNextRCAP, pri++) {
-        rep.nClients += pRCAP->numClients;
-        rep.length += pRCAP->numClients *
+        nClients += pRCAP->numClients;
+        length += pRCAP->numClients *
             (bytes_to_int32(sizeof(xRecordClientInfo)) +
              pri->nRanges * bytes_to_int32(sizeof(xRecordRange)));
     }
@@ -2232,8 +2233,10 @@ ProcRecordGetContext(ClientPtr client)
 
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
+    rep.length = length;
     rep.enabled = pContext->pRecordingClient != NULL;
     rep.elementHeader = pContext->elemHeaders;
+    rep.nClients = nClients;
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
commit c2fb1a7b2ab58d70b38ee03ab2fdeb4e7183a356
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    ProcQueryKeymap: rework logic around permission to copy key states
    
    Always initialize to zero, and then if permission is granted, copy
    the current key state maps, instead of always copying and then
    zeroing out if permission was denied.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/devices.c b/dix/devices.c
index c042681..4d1086f 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2388,17 +2388,19 @@ ProcQueryKeymap(ClientPtr client)
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
     rep.length = 2;
+    memset(rep.map, 0, 32);
 
     rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess);
-    if (rc != Success && rc != BadAccess)
+    /* If rc is Success, we're allowed to copy out the keymap.
+     * If it's BadAccess, we leave it empty & lie to the client.
+     */
+    if (rc == Success) {
+        for (i = 0; i < 32; i++)
+            rep.map[i] = down[i];
+    }
+    else if (rc != BadAccess)
         return rc;
 
-    for (i = 0; i < 32; i++)
-        rep.map[i] = down[i];
-
-    if (rc == BadAccess)
-        memset(rep.map, 0, 32);
-
     WriteReplyToClient(client, sizeof(xQueryKeymapReply), &rep);
 
     return Success;
commit dccb0858d71341e1258800b37d1bb78c0115838d
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    Core events: invert check for permission to copy key states
    
    Always initialize to zero, and then if permission is granted, copy
    the current key state maps.   Use memcpy instead of memmove for the
    copy, since we're always copying to a newly allocated event on the
    stack, so guaranteed not to overlap with the device map structure.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/events.c b/dix/events.c
index 7933749..6e4385a 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4512,11 +4512,12 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
     if ((type == EnterNotify) && (mask & KeymapStateMask)) {
         xKeymapEvent ke;
         ClientPtr client = grab ? rClient(grab) : wClient(pWin);
+        int rc;
 
-        if (XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess))
-            memset((char *) &ke.map[0], 0, 31);
-        else
-            memmove((char *) &ke.map[0], (char *) &keybd->key->down[1], 31);
+        memset((char *) &ke.map[0], 0, 31);
+        rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess);
+        if (rc == Success)
+            memcpy((char *) &ke.map[0], (char *) &keybd->key->down[1], 31);
 
         ke.type = KeymapNotify;
         if (grab)
@@ -4617,11 +4618,12 @@ CoreFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin)
         ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask)) {
         xKeymapEvent ke;
         ClientPtr client = wClient(pWin);
+        int rc;
 
-        if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess))
-            memset((char *) &ke.map[0], 0, 31);
-        else
-            memmove((char *) &ke.map[0], (char *) &dev->key->down[1], 31);
+        memset((char *) &ke.map[0], 0, 31);
+        rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess);
+        if (rc == Success)
+            memcpy((char *) &ke.map[0], (char *) &dev->key->down[1], 31);
 
         ke.type = KeymapNotify;
         DeliverEventsToWindow(dev, pWin, (xEvent *) &ke, 1,
commit db69212df8a0bf09140368356d2d430c54afe346
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    Rework reply initialization in ProcGetProperty & NullPropertyReply
    
    Don't need to pass an empty reply to NullPropertyReply, let it make
    it's own.   Move reply initialization code in remaining replies in
    ProcGetProperty to group with the rest of the fields.   (Prepares
    for coming C99 designated initializer conversion.)
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/dix/property.c b/dix/property.c
index b1b8312..5ef97ee 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -413,15 +413,18 @@ DeleteAllWindowProperties(WindowPtr pWin)
 }
 
 static int
-NullPropertyReply(ClientPtr client,
-                  ATOM propertyType, int format, xGetPropertyReply * reply)
+NullPropertyReply(ClientPtr client, ATOM propertyType, int format)
 {
-    reply->nItems = 0;
-    reply->length = 0;
-    reply->bytesAfter = 0;
-    reply->propertyType = propertyType;
-    reply->format = format;
-    WriteReplyToClient(client, sizeof(xGenericReply), reply);
+    xGetPropertyReply reply;
+    memset(&reply, 0, sizeof(xGetPropertyReply));
+    reply.type = X_Reply;
+    reply.sequenceNumber = client->sequence;
+    reply.nItems = 0;
+    reply.length = 0;
+    reply.bytesAfter = 0;
+    reply.propertyType = propertyType;
+    reply.format = format;
+    WriteReplyToClient(client, sizeof(xGenericReply), &reply);
     return Success;
 }
 
@@ -470,13 +473,9 @@ ProcGetProperty(ClientPtr client)
         return BadAtom;
     }
 
-    memset(&reply, 0, sizeof(xGetPropertyReply));
-    reply.type = X_Reply;
-    reply.sequenceNumber = client->sequence;
-
     rc = dixLookupProperty(&pProp, pWin, stuff->property, client, prop_mode);
     if (rc == BadMatch)
-        return NullPropertyReply(client, None, 0, &reply);
+        return NullPropertyReply(client, None, 0);
     else if (rc != Success)
         return rc;
 
@@ -485,6 +484,9 @@ ProcGetProperty(ClientPtr client)
 
     if (((stuff->type != pProp->type) && (stuff->type != AnyPropertyType))
         ) {
+        memset(&reply, 0, sizeof(xGetPropertyReply));
+        reply.type = X_Reply;
+        reply.sequenceNumber = client->sequence;
         reply.bytesAfter = pProp->size;
         reply.format = pProp->format;
         reply.length = 0;
@@ -510,6 +512,9 @@ ProcGetProperty(ClientPtr client)
 
     len = min(n - ind, 4 * stuff->longLength);
 
+    memset(&reply, 0, sizeof(xGetPropertyReply));
+    reply.type = X_Reply;
+    reply.sequenceNumber = client->sequence;
     reply.bytesAfter = n - (ind + len);
     reply.format = pProp->format;
     reply.length = bytes_to_int32(len);
commit 6be74a9080e30fc502421cd438cd0c73fb8eb0b0
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Mon Jul 9 19:12:42 2012 -0700

    Fix more poorly indented/wrapped comments & code
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xext/shm.c b/Xext/shm.c
index 1cdb401..aa3feae 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -630,7 +630,7 @@ ProcShmGetImage(ClientPtr client)
         return rc;
     VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
     if (pDraw->type == DRAWABLE_WINDOW) {
-        if (                    /* check for being viewable */
+        if (   /* check for being viewable */
                !((WindowPtr) pDraw)->realized ||
                /* check for being on screen */
                pDraw->x + stuff->x < 0 ||
diff --git a/Xext/sync.c b/Xext/sync.c
index 532bbf9..6dc4c5e 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -444,7 +444,8 @@ SyncSendAlarmNotifyEvents(SyncAlarm * pAlarm)
         ane.counter_value_hi = XSyncValueHigh32(pCounter->value);
         ane.counter_value_lo = XSyncValueLow32(pCounter->value);
     }
-    else {                      /* XXX what else can we do if there's no counter? */
+    else {
+        /* XXX what else can we do if there's no counter? */
         ane.counter_value_hi = ane.counter_value_lo = 0;
     }
 
@@ -1779,10 +1780,10 @@ ProcSyncQueryAlarm(ClientPtr client)
     pTrigger = &pAlarm->trigger;
     rep.counter = (pTrigger->pSync) ? pTrigger->pSync->id : None;
 
-#if 0                           /* XXX unclear what to do, depends on whether relative value-types
-                                 * are "consumed" immediately and are considered absolute from then
-                                 * on.
-                                 */
+#if 0  /* XXX unclear what to do, depends on whether relative value-types
+        * are "consumed" immediately and are considered absolute from then
+        * on.
+        */
     rep.value_type = pTrigger->value_type;
     rep.wait_value_hi = XSyncValueHigh32(pTrigger->wait_value);
     rep.wait_value_lo = XSyncValueLow32(pTrigger->wait_value);
diff --git a/Xi/exevents.c b/Xi/exevents.c
index e99bf6c..9f6ec84 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1266,7 +1266,7 @@ ProcessTouchOwnershipEvent(DeviceIntPtr dev, TouchPointInfoPtr ti,
         else
             ti->listeners[0].state = LISTENER_HAS_ACCEPTED;
     }
-    else {                      /* this is the very first ownership event for a grab */
+    else {  /* this is the very first ownership event for a grab */
         DeliverTouchEvents(dev, ti, (InternalEvent *) ev, ev->resource);
     }
 }
@@ -2312,12 +2312,11 @@ SelectForWindow(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client,
 
     check = (mask & exclusivemasks);
     if (wOtherInputMasks(pWin)) {
-        if (check & wOtherInputMasks(pWin)->inputEvents[mskidx]) {      /* It is illegal for two different
-                                                                         * clients to select on any of the
-                                                                         * events for maskcheck. However,
-                                                                         * it is OK, for some client to
-                                                                         * continue selecting on one of those
-                                                                         * events.  */
+        if (check & wOtherInputMasks(pWin)->inputEvents[mskidx]) {
+            /* It is illegal for two different clients to select on any of
+             * the events for maskcheck. However, it is OK, for some client
+             * to continue selecting on one of those events.
+             */
             for (others = wOtherInputMasks(pWin)->inputClients; others;
                  others = others->next) {
                 if (!SameClient(others, client) && (check &
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 94f46f7..bcea410 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -438,8 +438,9 @@ SProcIDispatch(ClientPtr client)
 
 static void
 SReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
-                                        /* All we look at is the type field */
-{                               /* This is common to all replies    */
+{
+    /* All we look at is the type field */
+    /* This is common to all replies    */
     if (rep->RepType == X_GetExtensionVersion)
         SRepXGetExtensionVersion(client, len,
                                  (xGetExtensionVersionReply *) rep);
diff --git a/composite/compwindow.c b/composite/compwindow.c
index d0bcd18..0be7a1b 100644
--- a/composite/compwindow.c
+++ b/composite/compwindow.c
@@ -208,7 +208,8 @@ updateOverlayWindow(ScreenPtr pScreen)
         return ConfigureWindow(pWin, CWWidth | CWHeight, vlist, wClient(pWin));
     }
 
-    /* Let's be on the safe side and not assume an overlay window is always allocated. */
+    /* Let's be on the safe side and not assume an overlay window is
+       always allocated. */
     return Success;
 }
 
@@ -678,7 +679,8 @@ compWindowUpdateAutomatic(WindowPtr pWin)
     /*
      * And paint
      */
-    CompositePicture(PictOpSrc, pSrcPicture, 0, pDstPicture, 0, 0,      /* src_x, src_y */
+    CompositePicture(PictOpSrc, pSrcPicture, 0, pDstPicture,
+                     0, 0,      /* src_x, src_y */
                      0, 0,      /* msk_x, msk_y */
                      pSrcPixmap->screen_x - pParent->drawable.x,
                      pSrcPixmap->screen_y - pParent->drawable.y,
diff --git a/config/udev.c b/config/udev.c
index 5297b90..03aca28 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -331,9 +331,11 @@ config_udev_pre_init(void)
 
     udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input",
                                                     NULL);
-    udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL); /* For Wacom serial devices */
+    /* For Wacom serial devices */
+    udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL);
 #ifdef CONFIG_UDEV_KMS
-    udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "drm", NULL); /* For output GPU devices */
+    /* For output GPU devices */
+    udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "drm", NULL);
 #endif
 
 #ifdef HAVE_UDEV_MONITOR_FILTER_ADD_MATCH_TAG
diff --git a/dix/colormap.c b/dix/colormap.c
index 1030628..36526b8 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -576,7 +576,7 @@ CopyFree(int channel, int client, ColormapPtr pmapSrc, ColormapPtr pmapDst)
     int nalloc;
 
     switch (channel) {
-    default:                   /* so compiler can see that everything gets initialized */
+    default:         /* so compiler can see that everything gets initialized */
     case REDMAP:
         ppix = (pmapSrc->clientPixelsRed)[client];
         npix = (pmapSrc->numPixelsRed)[client];
@@ -653,7 +653,7 @@ FreeCell(ColormapPtr pmap, Pixel i, int channel)
     int *pCount;
 
     switch (channel) {
-    default:                   /* so compiler can see that everything gets initialized */
+    default:         /* so compiler can see that everything gets initialized */
     case PSEUDOMAP:
     case REDMAP:
         pent = (EntryPtr) & pmap->red[i];
@@ -2146,7 +2146,7 @@ FreeCo(ColormapPtr pmap, int client, int color, int npixIn, Pixel * ppixIn,
         ppixClient = pmap->clientPixelsBlue[client];
         npixClient = pmap->numPixelsBlue[client];
         break;
-    default:                   /* so compiler can see that everything gets initialized */
+    default:        /* so compiler can see that everything gets initialized */
     case PSEUDOMAP:
         cmask = ~((Pixel) 0);
         rgbbad = 0;
diff --git a/dix/enterleave.c b/dix/enterleave.c
index 761ab3b..00083e9 100644
--- a/dix/enterleave.c
+++ b/dix/enterleave.c
@@ -1246,7 +1246,8 @@ HasOtherPointer(WindowPtr win, DeviceIntPtr exclude)
  * Assumption: Neither A nor B are valid windows.
  */
 static void
-CoreFocusPointerRootNoneSwitch(DeviceIntPtr dev, WindowPtr A,   /* PointerRootWin or NoneWin */
+CoreFocusPointerRootNoneSwitch(DeviceIntPtr dev,
+                               WindowPtr A,     /* PointerRootWin or NoneWin */
                                WindowPtr B,     /* NoneWin or PointerRootWin */
                                int mode)
 {
@@ -1290,7 +1291,8 @@ CoreFocusPointerRootNoneSwitch(DeviceIntPtr dev, WindowPtr A,   /* PointerRootWi
  * Assumption: A is a valid window and not PointerRoot or None.
  */
 static void
-CoreFocusToPointerRootOrNone(DeviceIntPtr dev, WindowPtr A, WindowPtr B,        /* PointerRootWin or NoneWin */
+CoreFocusToPointerRootOrNone(DeviceIntPtr dev, WindowPtr A,
+                             WindowPtr B,        /* PointerRootWin or NoneWin */
                              int mode)
 {
     WindowPtr root;
@@ -1336,7 +1338,8 @@ CoreFocusToPointerRootOrNone(DeviceIntPtr dev, WindowPtr A, WindowPtr B,
  * Assumption: B is a valid window and not PointerRoot or None.
  */
 static void
-CoreFocusFromPointerRootOrNone(DeviceIntPtr dev, WindowPtr A,   /* PointerRootWin or NoneWin */
+CoreFocusFromPointerRootOrNone(DeviceIntPtr dev,
+                               WindowPtr A,   /* PointerRootWin or NoneWin */
                                WindowPtr B, int mode)
 {
     WindowPtr root;
diff --git a/dix/events.c b/dix/events.c
index dbfe9d9..7933749 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -698,9 +698,10 @@ ConfineToShape(DeviceIntPtr pDev, RegionPtr shape, int *px, int *py)
 }
 
 static void
-CheckPhysLimits(DeviceIntPtr pDev, CursorPtr cursor, Bool generateEvents, Bool confineToScreen, /* unused if PanoramiX on */
-                ScreenPtr pScreen)
-{                               /* unused if PanoramiX on */
+CheckPhysLimits(DeviceIntPtr pDev, CursorPtr cursor, Bool generateEvents,
+                Bool confineToScreen, /* unused if PanoramiX on */
+                ScreenPtr pScreen)    /* unused if PanoramiX on */
+{
     HotSpot new;
     SpritePtr pSprite = pDev->spriteInfo->sprite;
 
diff --git a/dix/grabs.c b/dix/grabs.c
index 2f05f57..55bf64f 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -205,7 +205,10 @@ AllocGrab(void)
 }
 
 GrabPtr
-CreateGrab(int client, DeviceIntPtr device, DeviceIntPtr modDevice, WindowPtr window, enum InputLevel grabtype, GrabMask *mask, GrabParameters *param, int type, KeyCode keybut,        /* key or button */
+CreateGrab(int client, DeviceIntPtr device, DeviceIntPtr modDevice,
+           WindowPtr window, enum InputLevel grabtype, GrabMask *mask,
+           GrabParameters *param, int type,
+           KeyCode keybut,        /* key or button */
            WindowPtr confineTo, CursorPtr cursor)
 {
     GrabPtr grab;
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index bd23dc2..bac5f11 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -262,8 +262,10 @@ SendXF86VidModeNotify(ScreenPtr pScreen, int state, Bool forced)
         ev.kind = kind;
         ev.forced = forced;
         WriteEventsToClient(pEv->client, 1, (xEvent *) &ev);
-}} static void
+    }
+}
 
+static void
 SXF86VidModeNotifyEvent(xXF86VidModeNotifyEvent * from,
                         xXF86VidModeNotifyEvent * to)
 {
commit 789d64e19a3b3d98b88bc80f677e0c37bfb5c631
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun May 13 00:03:35 2012 -0700

    Remove unneccesary casts from WriteToClient calls
    
    Casting return to (void) was used to tell lint that you intended
    to ignore the return value, so it didn't warn you about it.
    
    Casting the third argument to (char *) was used as the most generic
    pointer type in the days before compilers supported C89 (void *)
    (except for a couple places it's used for byte-sized pointer math).
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Tested-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xext/bigreq.c b/Xext/bigreq.c
index 49355c4..9bb1c86 100644
--- a/Xext/bigreq.c
+++ b/Xext/bigreq.c
@@ -64,7 +64,7 @@ ProcBigReqDispatch(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swapl(&rep.max_request_size);
     }
-    WriteToClient(client, sizeof(xBigReqEnableReply), (char *) &rep);
+    WriteToClient(client, sizeof(xBigReqEnableReply), &rep);
     return Success;
 }
 
diff --git a/Xext/dpms.c b/Xext/dpms.c
index 348c872..35be966 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -59,7 +59,7 @@ ProcDPMSGetVersion(ClientPtr client)
         swaps(&rep.majorVersion);
         swaps(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xDPMSGetVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDPMSGetVersionReply), &rep);
     return Success;
 }
 
@@ -79,7 +79,7 @@ ProcDPMSCapable(ClientPtr client)
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
     }
-    WriteToClient(client, sizeof(xDPMSCapableReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDPMSCapableReply), &rep);
     return Success;
 }
 
@@ -104,7 +104,7 @@ ProcDPMSGetTimeouts(ClientPtr client)
         swaps(&rep.suspend);
         swaps(&rep.off);
     }
-    WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), &rep);
     return Success;
 }
 
@@ -202,7 +202,7 @@ ProcDPMSInfo(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swaps(&rep.power_level);
     }
-    WriteToClient(client, sizeof(xDPMSInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDPMSInfoReply), &rep);
     return Success;
 }
 
diff --git a/Xext/geext.c b/Xext/geext.c
index 0702823..7bdd873 100644
--- a/Xext/geext.c
+++ b/Xext/geext.c
@@ -85,7 +85,7 @@ ProcGEQueryVersion(ClientPtr client)
         swaps(&rep.minorVersion);
     }
 
-    WriteToClient(client, sizeof(xGEQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xGEQueryVersionReply), &rep);
     return Success;
 }
 
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index de62a35..98c612a 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -918,7 +918,7 @@ ProcPanoramiXQueryVersion(ClientPtr client)
         swaps(&rep.majorVersion);
         swaps(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xPanoramiXQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xPanoramiXQueryVersionReply), &rep);
     return Success;
 }
 
@@ -945,7 +945,7 @@ ProcPanoramiXGetState(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.window);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetStateReply), (char *) &rep);
+    WriteToClient(client, sizeof(xPanoramiXGetStateReply), &rep);
     return Success;
 
 }
@@ -973,7 +973,7 @@ ProcPanoramiXGetScreenCount(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.window);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), (char *) &rep);
+    WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), &rep);
     return Success;
 }
 
@@ -1009,7 +1009,7 @@ ProcPanoramiXGetScreenSize(ClientPtr client)
         swapl(&rep.window);
         swapl(&rep.screen);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), (char *) &rep);
+    WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), &rep);
     return Success;
 }
 
@@ -1038,7 +1038,7 @@ ProcXineramaIsActive(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.state);
     }
-    WriteToClient(client, sizeof(xXineramaIsActiveReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXineramaIsActiveReply), &rep);
     return Success;
 }
 
@@ -1059,7 +1059,7 @@ ProcXineramaQueryScreens(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.number);
     }
-    WriteToClient(client, sizeof(xXineramaQueryScreensReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXineramaQueryScreensReply), &rep);
 
     if (!noPanoramiXExtension) {
         xXineramaScreenInfo scratch;
@@ -1077,7 +1077,7 @@ ProcXineramaQueryScreens(ClientPtr client)
                 swaps(&scratch.width);
                 swaps(&scratch.height);
             }
-            WriteToClient(client, sz_XineramaScreenInfo, (char *) &scratch);
+            WriteToClient(client, sz_XineramaScreenInfo, &scratch);
         }
     }
 
diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 12d6163..bdabfbf 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -2003,7 +2003,7 @@ PanoramiXGetImage(ClientPtr client)
                                  format, planemask, pBuf, widthBytesLine,
                                  isRoot);
 
-            (void) WriteToClient(client, (int) (nlines * widthBytesLine), pBuf);
+            WriteToClient(client, (int) (nlines * widthBytesLine), pBuf);
             linesDone += nlines;
         }
     }
@@ -2020,8 +2020,7 @@ PanoramiXGetImage(ClientPtr client)
                                          nlines, format, plane, pBuf,
                                          widthBytesLine, isRoot);
 
-                    (void) WriteToClient(client,
-                                         (int) (nlines * widthBytesLine), pBuf);
+                    WriteToClient(client, (int)(nlines * widthBytesLine), pBuf);
 
                     linesDone += nlines;
                 }
diff --git a/Xext/saver.c b/Xext/saver.c
index 61fc044..60c02ff 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -646,7 +646,7 @@ ProcScreenSaverQueryVersion(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
     }
-    WriteToClient(client, sizeof(xScreenSaverQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xScreenSaverQueryVersionReply), &rep);
     return Success;
 }
 
@@ -717,7 +717,7 @@ ProcScreenSaverQueryInfo(ClientPtr client)
         swapl(&rep.idle);
         swapl(&rep.eventMask);
     }
-    WriteToClient(client, sizeof(xScreenSaverQueryInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xScreenSaverQueryInfoReply), &rep);
     return Success;
 }
 
diff --git a/Xext/security.c b/Xext/security.c
index 3699510..fd63571 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -351,8 +351,7 @@ ProcSecurityQueryVersion(ClientPtr client)
         swaps(&rep.majorVersion);
         swaps(&rep.minorVersion);
     }
-    (void) WriteToClient(client, SIZEOF(xSecurityQueryVersionReply),
-                         (char *) &rep);
+    WriteToClient(client, SIZEOF(xSecurityQueryVersionReply), &rep);
     return Success;
 }                               /* ProcSecurityQueryVersion */
 
@@ -541,8 +540,7 @@ ProcSecurityGenerateAuthorization(ClientPtr client)
         swaps(&rep.dataLength);
     }
 
-    WriteToClient(client, SIZEOF(xSecurityGenerateAuthorizationReply),
-                  (char *) &rep);
+    WriteToClient(client, SIZEOF(xSecurityGenerateAuthorizationReply), &rep);
     WriteToClient(client, authdata_len, pAuthdata);
 
     SecurityAudit
diff --git a/Xext/shape.c b/Xext/shape.c
index cc5214a..7724e7b 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -219,7 +219,7 @@ ProcShapeQueryVersion(ClientPtr client)
         swaps(&rep.majorVersion);
         swaps(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xShapeQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xShapeQueryVersionReply), &rep);
     return Success;
 }
 
@@ -679,7 +679,7 @@ ProcShapeQueryExtents(ClientPtr client)
         swaps(&rep.widthClipShape);
         swaps(&rep.heightClipShape);
     }
-    WriteToClient(client, sizeof(xShapeQueryExtentsReply), (char *) &rep);
+    WriteToClient(client, sizeof(xShapeQueryExtentsReply), &rep);
     return Success;
 }
 
@@ -928,7 +928,7 @@ ProcShapeInputSelected(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
     }
-    WriteToClient(client, sizeof(xShapeInputSelectedReply), (char *) &rep);
+    WriteToClient(client, sizeof(xShapeInputSelectedReply), &rep);
     return Success;
 }
 
@@ -1012,8 +1012,8 @@ ProcShapeGetRectangles(ClientPtr client)
         swapl(&rep.nrects);
         SwapShorts((short *) rects, (unsigned long) nrects * 4);
     }
-    WriteToClient(client, sizeof(rep), (char *) &rep);
-    WriteToClient(client, nrects * sizeof(xRectangle), (char *) rects);
+    WriteToClient(client, sizeof(rep), &rep);
+    WriteToClient(client, nrects * sizeof(xRectangle), rects);
     free(rects);
     return Success;
 }
diff --git a/Xext/shm.c b/Xext/shm.c
index e9c4a4e..1cdb401 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -306,7 +306,7 @@ ProcShmQueryVersion(ClientPtr client)
         swaps(&rep.uid);
         swaps(&rep.gid);
     }
-    WriteToClient(client, sizeof(xShmQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xShmQueryVersionReply), &rep);
     return Success;
 }
 
@@ -702,7 +702,7 @@ ProcShmGetImage(ClientPtr client)
         swapl(&xgi.visual);
         swapl(&xgi.size);
     }
-    WriteToClient(client, sizeof(xShmGetImageReply), (char *) &xgi);
+    WriteToClient(client, sizeof(xShmGetImageReply), &xgi);
 
     return Success;
 }
@@ -877,7 +877,7 @@ ProcPanoramiXShmGetImage(ClientPtr client)
         swapl(&xgi.visual);
         swapl(&xgi.size);
     }
-    WriteToClient(client, sizeof(xShmGetImageReply), (char *) &xgi);
+    WriteToClient(client, sizeof(xShmGetImageReply), &xgi);
 
     return Success;
 }
diff --git a/Xext/sync.c b/Xext/sync.c
index 91968e4..532bbf9 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -1198,7 +1198,7 @@ ProcSyncInitialize(ClientPtr client)
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
     }
-    WriteToClient(client, sizeof(rep), (char *) &rep);
+    WriteToClient(client, sizeof(rep), &rep);
     return Success;
 }
 
@@ -1263,9 +1263,9 @@ ProcSyncListSystemCounters(ClientPtr client)
                                                         namelen));
     }
 
-    WriteToClient(client, sizeof(rep), (char *) &rep);
+    WriteToClient(client, sizeof(rep), &rep);
     if (len) {
-        WriteToClient(client, len, (char *) list);
+        WriteToClient(client, len, list);
         free(list);
     }
 
@@ -1338,7 +1338,7 @@ ProcSyncGetPriority(ClientPtr client)
         swapl(&rep.priority);
     }
 
-    WriteToClient(client, sizeof(xSyncGetPriorityReply), (char *) &rep);
+    WriteToClient(client, sizeof(xSyncGetPriorityReply), &rep);
 
     return Success;
 }
@@ -1624,7 +1624,7 @@ ProcSyncQueryCounter(ClientPtr client)
         swapl(&rep.value_hi);
         swapl(&rep.value_lo);
     }
-    WriteToClient(client, sizeof(xSyncQueryCounterReply), (char *) &rep);
+    WriteToClient(client, sizeof(xSyncQueryCounterReply), &rep);
     return Success;
 }
 
@@ -1809,7 +1809,7 @@ ProcSyncQueryAlarm(ClientPtr client)
         swapl(&rep.delta_lo);
     }
 
-    WriteToClient(client, sizeof(xSyncQueryAlarmReply), (char *) &rep);
+    WriteToClient(client, sizeof(xSyncQueryAlarmReply), &rep);
     return Success;
 }
 
@@ -1966,7 +1966,7 @@ ProcSyncQueryFence(ClientPtr client)
         swapl(&rep.length);
     }
 
-    WriteToClient(client, sizeof(xSyncQueryFenceReply), (char *) &rep);
+    WriteToClient(client, sizeof(xSyncQueryFenceReply), &rep);
     return client->noClientException;
 }
 
diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index 99a6ece..943b424 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -58,7 +58,7 @@ ProcXCMiscGetVersion(ClientPtr client)
         swaps(&rep.majorVersion);
         swaps(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xXCMiscGetVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXCMiscGetVersionReply), &rep);
     return Success;
 }
 
@@ -80,7 +80,7 @@ ProcXCMiscGetXIDRange(ClientPtr client)
         swapl(&rep.start_id);
         swapl(&rep.count);
     }
-    WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), &rep);
     return Success;
 }
 
@@ -111,7 +111,7 @@ ProcXCMiscGetXIDList(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.count);
     }
-    WriteToClient(client, sizeof(xXCMiscGetXIDListReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXCMiscGetXIDListReply), &rep);
     if (count) {
         client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
         WriteSwappedDataToClient(client, count * sizeof(XID), pids);
diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index 9de7856..3a1e1b2 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -307,8 +307,7 @@ ProcXF86BigfontQueryVersion(ClientPtr client)
         swapl(&reply.gid);
         swapl(&reply.signature);
     }
-    WriteToClient(client,
-                  sizeof(xXF86BigfontQueryVersionReply), (char *) &reply);
+    WriteToClient(client, sizeof(xXF86BigfontQueryVersionReply), &reply);
     return Success;
 }
 
@@ -644,7 +643,7 @@ ProcXF86BigfontQueryFont(ClientPtr client)
                 }
             }
         }
-        WriteToClient(client, rlength, (char *) reply);
+        WriteToClient(client, rlength, reply);
         free(reply);
         if (nCharInfos > 0) {
             if (shmid == -1)
diff --git a/Xext/xres.c b/Xext/xres.c
index dbefeeb..d207dce 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -209,7 +209,7 @@ ProcXResQueryVersion(ClientPtr client)
         swaps(&rep.server_major);
         swaps(&rep.server_minor);
     }
-    WriteToClient(client, sizeof(xXResQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXResQueryVersionReply), &rep);
     return Success;
 }
 
@@ -242,7 +242,7 @@ ProcXResQueryClients(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.num_clients);
     }
-    WriteToClient(client, sizeof(xXResQueryClientsReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXResQueryClientsReply), &rep);
 
     if (num_clients) {
         xXResClient scratch;
@@ -255,7 +255,7 @@ ProcXResQueryClients(ClientPtr client)
                 swapl(&scratch.resource_base);
                 swapl(&scratch.resource_mask);
             }
-            WriteToClient(client, sz_xXResClient, (char *) &scratch);
+            WriteToClient(client, sz_xXResClient, &scratch);
         }
     }
 
@@ -310,8 +310,7 @@ ProcXResQueryClientResources(ClientPtr client)
         swapl(&rep.num_types);
     }
 
-    WriteToClient(client, sizeof(xXResQueryClientResourcesReply),
-                  (char *) &rep);
+    WriteToClient(client, sizeof(xXResQueryClientResourcesReply), &rep);
 
     if (num_types) {
         xXResType scratch;
@@ -337,7 +336,7 @@ ProcXResQueryClientResources(ClientPtr client)
                 swapl(&scratch.resource_type);
                 swapl(&scratch.count);
             }
-            WriteToClient(client, sz_xXResType, (char *) &scratch);
+            WriteToClient(client, sz_xXResType, &scratch);
         }
     }
 
@@ -486,8 +485,7 @@ ProcXResQueryClientPixmapBytes(ClientPtr client)
         swapl(&rep.bytes);
         swapl(&rep.bytes_overflow);
     }
-    WriteToClient(client, sizeof(xXResQueryClientPixmapBytesReply),
-                  (char *) &rep);
+    WriteToClient(client, sizeof(xXResQueryClientPixmapBytesReply), &rep);
 
     return Success;
 }
@@ -679,7 +677,7 @@ ProcXResQueryClientIds (ClientPtr client)
             swapl (&rep.numIds);
         }
 
-        WriteToClient(client,sizeof(rep),(char*)&rep);
+        WriteToClient(client, sizeof(rep), &rep);
         WriteFragmentsToClient(client, &ctx.response);
     }
 
@@ -1061,7 +1059,7 @@ ProcXResQueryResourceBytes (ClientPtr client)
             SwapXResQueryResourceBytes(&ctx.response);
         }
 
-        WriteToClient(client,sizeof(rep),(char*)&rep);
+        WriteToClient(client, sizeof(rep), &rep);
         WriteFragmentsToClient(client, &ctx.response);
     }
 
diff --git a/Xext/xselinux_ext.c b/Xext/xselinux_ext.c
index 342abb1..8817591 100644
--- a/Xext/xselinux_ext.c
+++ b/Xext/xselinux_ext.c
@@ -76,7 +76,7 @@ ProcSELinuxQueryVersion(ClientPtr client)
         swaps(&rep.server_major);
         swaps(&rep.server_minor);
     }
-    WriteToClient(client, sizeof(rep), (char *) &rep);
+    WriteToClient(client, sizeof(rep), &rep);
     return Success;
 }
 
@@ -104,7 +104,7 @@ SELinuxSendContextReply(ClientPtr client, security_id_t sid)
         swapl(&rep.context_len);
     }
 
-    WriteToClient(client, sizeof(SELinuxGetContextReply), (char *) &rep);
+    WriteToClient(client, sizeof(SELinuxGetContextReply), &rep);
     WriteToClient(client, len, ctx);
     freecon(ctx);
     return Success;
@@ -383,8 +383,8 @@ SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items,
         swapl(&rep.count);
     }
 
-    WriteToClient(client, sizeof(SELinuxListItemsReply), (char *) &rep);
-    WriteToClient(client, size * 4, (char *) buf);
+    WriteToClient(client, sizeof(SELinuxListItemsReply), &rep);
+    WriteToClient(client, size * 4, buf);
 
     /* Free stuff and return */
     rc = Success;
diff --git a/Xext/xtest.c b/Xext/xtest.c
index e659b41..6112c0b 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -100,7 +100,7 @@ ProcXTestGetVersion(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swaps(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xXTestGetVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXTestGetVersionReply), &rep);
     return Success;
 }
 
@@ -141,7 +141,7 @@ ProcXTestCompareCursor(ClientPtr client)
     if (client->swapped) {
         swaps(&rep.sequenceNumber);
     }
-    WriteToClient(client, sizeof(xXTestCompareCursorReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXTestCompareCursorReply), &rep);
     return Success;
 }
 
diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index 8abd51c..8730267 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -62,7 +62,7 @@ SWriteQueryExtensionReply(ClientPtr client, xvQueryExtensionReply * rep)
     swaps(&rep->version);
     swaps(&rep->revision);
 
-    (void) WriteToClient(client, sz_xvQueryExtensionReply, (char *) rep);
+    WriteToClient(client, sz_xvQueryExtensionReply, rep);
 
     return Success;
 }
@@ -74,7 +74,7 @@ SWriteQueryAdaptorsReply(ClientPtr client, xvQueryAdaptorsReply * rep)
     swapl(&rep->length);
     swaps(&rep->num_adaptors);
 
-    (void) WriteToClient(client, sz_xvQueryAdaptorsReply, (char *) rep);
+    WriteToClient(client, sz_xvQueryAdaptorsReply, rep);
 
     return Success;
 }
@@ -86,7 +86,7 @@ SWriteQueryEncodingsReply(ClientPtr client, xvQueryEncodingsReply * rep)
     swapl(&rep->length);
     swaps(&rep->num_encodings);
 
-    (void) WriteToClient(client, sz_xvQueryEncodingsReply, (char *) rep);
+    WriteToClient(client, sz_xvQueryEncodingsReply, rep);
 
     return Success;
 }
@@ -99,7 +99,7 @@ SWriteAdaptorInfo(ClientPtr client, xvAdaptorInfo * pAdaptor)
     swaps(&pAdaptor->num_ports);
     swaps(&pAdaptor->num_formats);
 
-    (void) WriteToClient(client, sz_xvAdaptorInfo, (char *) pAdaptor);
+    WriteToClient(client, sz_xvAdaptorInfo, pAdaptor);
 
     return Success;
 }
@@ -114,7 +114,7 @@ SWriteEncodingInfo(ClientPtr client, xvEncodingInfo * pEncoding)
     swaps(&pEncoding->height);
     swapl(&pEncoding->rate.numerator);
     swapl(&pEncoding->rate.denominator);
-    (void) WriteToClient(client, sz_xvEncodingInfo, (char *) pEncoding);
+    WriteToClient(client, sz_xvEncodingInfo, pEncoding);
 
     return Success;
 }
@@ -123,7 +123,7 @@ static int
 SWriteFormat(ClientPtr client, xvFormat * pFormat)
 {
     swapl(&pFormat->visual);
-    (void) WriteToClient(client, sz_xvFormat, (char *) pFormat);
+    WriteToClient(client, sz_xvFormat, pFormat);
 
     return Success;
 }
@@ -135,7 +135,7 @@ SWriteAttributeInfo(ClientPtr client, xvAttributeInfo * pAtt)
     swapl(&pAtt->size);
     swapl(&pAtt->min);
     swapl(&pAtt->max);
-    (void) WriteToClient(client, sz_xvAttributeInfo, (char *) pAtt);
+    WriteToClient(client, sz_xvAttributeInfo, pAtt);
 
     return Success;
 }
@@ -157,7 +157,7 @@ SWriteImageFormatInfo(ClientPtr client, xvImageFormatInfo * pImage)
     swapl(&pImage->vert_u_period);
     swapl(&pImage->vert_v_period);
 
-    (void) WriteToClient(client, sz_xvImageFormatInfo, (char *) pImage);
+    WriteToClient(client, sz_xvImageFormatInfo, pImage);
 
     return Success;
 }
@@ -168,7 +168,7 @@ SWriteGrabPortReply(ClientPtr client, xvGrabPortReply * rep)
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
 
-    (void) WriteToClient(client, sz_xvGrabPortReply, (char *) rep);
+    WriteToClient(client, sz_xvGrabPortReply, rep);
 
     return Success;
 }
@@ -180,7 +180,7 @@ SWriteGetPortAttributeReply(ClientPtr client, xvGetPortAttributeReply * rep)
     swapl(&rep->length);
     swapl(&rep->value);
 
-    (void) WriteToClient(client, sz_xvGetPortAttributeReply, (char *) rep);
+    WriteToClient(client, sz_xvGetPortAttributeReply, rep);
 
     return Success;
 }
@@ -193,7 +193,7 @@ SWriteQueryBestSizeReply(ClientPtr client, xvQueryBestSizeReply * rep)
     swaps(&rep->actual_width);
     swaps(&rep->actual_height);
 
-    (void) WriteToClient(client, sz_xvQueryBestSizeReply, (char *) rep);
+    WriteToClient(client, sz_xvQueryBestSizeReply, rep);
 
     return Success;
 }
@@ -207,7 +207,7 @@ SWriteQueryPortAttributesReply(ClientPtr client,
     swapl(&rep->num_attributes);
     swapl(&rep->text_size);
 
-    (void) WriteToClient(client, sz_xvQueryPortAttributesReply, (char *) rep);
+    WriteToClient(client, sz_xvQueryPortAttributesReply, rep);
 
     return Success;
 }
@@ -223,7 +223,7 @@ SWriteQueryImageAttributesReply(ClientPtr client,
     swaps(&rep->width);
     swaps(&rep->height);
 
-    (void) WriteToClient(client, sz_xvQueryImageAttributesReply, (char *) rep);
+    WriteToClient(client, sz_xvQueryImageAttributesReply, rep);
 
     return Success;
 }
@@ -235,66 +235,66 @@ SWriteListImageFormatsReply(ClientPtr client, xvListImageFormatsReply * rep)
     swapl(&rep->length);
     swapl(&rep->num_formats);
 
-    (void) WriteToClient(client, sz_xvListImageFormatsReply, (char *) rep);
+    WriteToClient(client, sz_xvListImageFormatsReply, rep);
 
     return Success;
 }
 
 #define _WriteQueryAdaptorsReply(_c,_d) \
   if ((_c)->swapped) SWriteQueryAdaptorsReply(_c, _d); \
-  else WriteToClient(_c, sz_xvQueryAdaptorsReply, (char*)_d)
+  else WriteToClient(_c, sz_xvQueryAdaptorsReply, _d)
 
 #define _WriteQueryExtensionReply(_c,_d) \
   if ((_c)->swapped) SWriteQueryExtensionReply(_c, _d); \
-  else WriteToClient(_c, sz_xvQueryExtensionReply, (char*)_d)
+  else WriteToClient(_c, sz_xvQueryExtensionReply, _d)
 
 #define _WriteQueryEncodingsReply(_c,_d) \
   if ((_c)->swapped) SWriteQueryEncodingsReply(_c, _d); \
-  else WriteToClient(_c, sz_xvQueryEncodingsReply, (char*)_d)
+  else WriteToClient(_c, sz_xvQueryEncodingsReply, _d)
 
 #define _WriteAdaptorInfo(_c,_d) \
   if ((_c)->swapped) SWriteAdaptorInfo(_c, _d); \
-  else WriteToClient(_c, sz_xvAdaptorInfo, (char*)_d)
+  else WriteToClient(_c, sz_xvAdaptorInfo, _d)
 
 #define _WriteAttributeInfo(_c,_d) \
   if ((_c)->swapped) SWriteAttributeInfo(_c, _d); \
-  else WriteToClient(_c, sz_xvAttributeInfo, (char*)_d)
+  else WriteToClient(_c, sz_xvAttributeInfo, _d)
 
 #define _WriteEncodingInfo(_c,_d) \
   if ((_c)->swapped) SWriteEncodingInfo(_c, _d); \
-  else WriteToClient(_c, sz_xvEncodingInfo, (char*)_d)
+  else WriteToClient(_c, sz_xvEncodingInfo, _d)
 
 #define _WriteFormat(_c,_d) \
   if ((_c)->swapped) SWriteFormat(_c, _d); \
-  else WriteToClient(_c, sz_xvFormat, (char*)_d)
+  else WriteToClient(_c, sz_xvFormat, _d)
 
 #define _WriteGrabPortReply(_c,_d) \
   if ((_c)->swapped) SWriteGrabPortReply(_c, _d); \
-  else WriteToClient(_c, sz_xvGrabPortReply, (char*)_d)
+  else WriteToClient(_c, sz_xvGrabPortReply, _d)
 
 #define _WriteGetPortAttributeReply(_c,_d) \
   if ((_c)->swapped) SWriteGetPortAttributeReply(_c, _d); \
-  else WriteToClient(_c, sz_xvGetPortAttributeReply, (char*)_d)
+  else WriteToClient(_c, sz_xvGetPortAttributeReply, _d)
 
 #define _WriteQueryBestSizeReply(_c,_d) \
   if ((_c)->swapped) SWriteQueryBestSizeReply(_c, _d); \
-  else WriteToClient(_c, sz_xvQueryBestSizeReply,(char*) _d)
+  else WriteToClient(_c, sz_xvQueryBestSizeReply, _d)
 
 #define _WriteQueryPortAttributesReply(_c,_d) \
   if ((_c)->swapped) SWriteQueryPortAttributesReply(_c, _d); \
-  else WriteToClient(_c, sz_xvQueryPortAttributesReply,(char*) _d)
+  else WriteToClient(_c, sz_xvQueryPortAttributesReply, _d)
 
 #define _WriteQueryImageAttributesReply(_c,_d) \
   if ((_c)->swapped) SWriteQueryImageAttributesReply(_c, _d); \
-  else WriteToClient(_c, sz_xvQueryImageAttributesReply,(char*) _d)
+  else WriteToClient(_c, sz_xvQueryImageAttributesReply, _d)
 
 #define _WriteListImageFormatsReply(_c,_d) \
   if ((_c)->swapped) SWriteListImageFormatsReply(_c, _d); \
-  else WriteToClient(_c, sz_xvListImageFormatsReply,(char*) _d)
+  else WriteToClient(_c, sz_xvListImageFormatsReply, _d)
 
 #define _WriteImageFormatInfo(_c,_d) \
   if ((_c)->swapped) SWriteImageFormatInfo(_c, _d); \
-  else WriteToClient(_c, sz_xvImageFormatInfo, (char*)_d)
+  else WriteToClient(_c, sz_xvImageFormatInfo, _d)
 
 #define _AllocatePort(_i,_p) \
   ((_p)->id != _i) ? (* (_p)->pAdaptor->ddAllocatePort)(_i,_p,&_p) : Success
@@ -1100,7 +1100,7 @@ ProcXvQueryImageAttributes(ClientPtr client)
     _WriteQueryImageAttributesReply(client, &rep);
     if (client->swapped)
         SwapLongs((CARD32 *) offsets, planeLength);
-    WriteToClient(client, planeLength << 2, (char *) offsets);
+    WriteToClient(client, planeLength << 2, offsets);
 
     free(offsets);
 
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 4aaff4d..b008bfe 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -118,7 +118,7 @@ ProcXvMCQueryVersion(ClientPtr client)
     rep.length = 0;
     rep.major = SERVER_XVMC_MAJOR_VERSION;
     rep.minor = SERVER_XVMC_MINOR_VERSION;
-    WriteToClient(client, sizeof(xvmcQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xvmcQueryVersionReply), &rep);
     return Success;
 }
 
@@ -156,7 +156,7 @@ ProcXvMCListSurfaceTypes(ClientPtr client)
     rep.num = (adaptor) ? adaptor->num_surfaces : 0;
     rep.length = bytes_to_int32(rep.num * sizeof(xvmcSurfaceInfo));
 
-    WriteToClient(client, sizeof(xvmcListSurfaceTypesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xvmcListSurfaceTypesReply), &rep);
 
     for (i = 0; i < rep.num; i++) {
         surface = adaptor->surfaces[i];
@@ -168,7 +168,7 @@ ProcXvMCListSurfaceTypes(ClientPtr client)
         info.subpicture_max_height = surface->subpicture_max_height;
         info.mc_type = surface->mc_type;
         info.flags = surface->flags;
-        WriteToClient(client, sizeof(xvmcSurfaceInfo), (char *) &info);
+        WriteToClient(client, sizeof(xvmcSurfaceInfo), &info);
     }
 
     return Success;
@@ -254,9 +254,9 @@ ProcXvMCCreateContext(ClientPtr client)
     rep.flags_return = pContext->flags;
     rep.length = dwords;
 
-    WriteToClient(client, sizeof(xvmcCreateContextReply), (char *) &rep);
+    WriteToClient(client, sizeof(xvmcCreateContextReply), &rep);
     if (dwords)
-        WriteToClient(client, dwords << 2, (char *) data);
+        WriteToClient(client, dwords << 2, data);
     AddResource(pContext->context_id, XvMCRTContext, pContext);
 
     free(data);
@@ -325,9 +325,9 @@ ProcXvMCCreateSurface(ClientPtr client)
     rep.sequenceNumber = client->sequence;
     rep.length = dwords;
 
-    WriteToClient(client, sizeof(xvmcCreateSurfaceReply), (char *) &rep);
+    WriteToClient(client, sizeof(xvmcCreateSurfaceReply), &rep);
     if (dwords)
-        WriteToClient(client, dwords << 2, (char *) data);
+        WriteToClient(client, dwords << 2, data);
     AddResource(pSurface->surface_id, XvMCRTSurface, pSurface);
 
     free(data);
@@ -448,9 +448,9 @@ ProcXvMCCreateSubpicture(ClientPtr client)
     rep.component_order[3] = pSubpicture->component_order[3];
     rep.length = dwords;
 
-    WriteToClient(client, sizeof(xvmcCreateSubpictureReply), (char *) &rep);
+    WriteToClient(client, sizeof(xvmcCreateSubpictureReply), &rep);
     if (dwords)
-        WriteToClient(client, dwords << 2, (char *) data);
+        WriteToClient(client, dwords << 2, data);
     AddResource(pSubpicture->subpicture_id, XvMCRTSubpicture, pSubpicture);
 
     free(data);
@@ -533,7 +533,7 @@ ProcXvMCListSubpictureTypes(ClientPtr client)
 
     rep.length = bytes_to_int32(rep.num * sizeof(xvImageFormatInfo));
 
-    WriteToClient(client, sizeof(xvmcListSubpictureTypesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xvmcListSubpictureTypesReply), &rep);
 
     for (i = 0; i < rep.num; i++) {
         pImage = NULL;
@@ -569,7 +569,7 @@ ProcXvMCListSubpictureTypes(ClientPtr client)
         info.vert_v_period = pImage->vert_v_period;
         memcpy(&info.comp_order, pImage->component_order, 32);
         info.scanline_order = pImage->scanline_order;
-        WriteToClient(client, sizeof(xvImageFormatInfo), (char *) &info);
+        WriteToClient(client, sizeof(xvImageFormatInfo), &info);
     }
 
     return Success;
@@ -634,7 +634,7 @@ ProcXvMCGetDRInfo(ClientPtr client)
     }
 #endif                          /* HAS_XVMCSHM */
 
-    WriteToClient(client, sizeof(xvmcGetDRInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xvmcGetDRInfoReply), &rep);
     if (rep.length) {
         WriteToClient(client, rep.nameLen, pScreenPriv->clientDriverName);
         WriteToClient(client, rep.busIDLen, pScreenPriv->busID);
diff --git a/Xi/chgdctl.c b/Xi/chgdctl.c
index ff5d69a..0de5f2b 100644
--- a/Xi/chgdctl.c
+++ b/Xi/chgdctl.c
@@ -236,5 +236,5 @@ SRepXChangeDeviceControl(ClientPtr client, int size,
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/getbmap.c b/Xi/getbmap.c
index a0ec1a6..2712fcd 100644
--- a/Xi/getbmap.c
+++ b/Xi/getbmap.c
@@ -109,7 +109,7 @@ ProcXGetDeviceButtonMapping(ClientPtr client)
     rep.nElts = b->numButtons;
     rep.length = bytes_to_int32(rep.nElts);
     WriteReplyToClient(client, sizeof(xGetDeviceButtonMappingReply), &rep);
-    (void) WriteToClient(client, rep.nElts, (char *) &b->map[1]);
+    WriteToClient(client, rep.nElts, &b->map[1]);
     return Success;
 }
 
@@ -126,5 +126,5 @@ SRepXGetDeviceButtonMapping(ClientPtr client, int size,
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/getdctl.c b/Xi/getdctl.c
index 4d66a4d..27775e2 100644
--- a/Xi/getdctl.c
+++ b/Xi/getdctl.c
@@ -158,7 +158,7 @@ SRepXGetDeviceControl(ClientPtr client, int size, xGetDeviceControlReply * rep)
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
 
 /***********************************************************************
diff --git a/Xi/getfctl.c b/Xi/getfctl.c
index 2772c0c..5f97cc3 100644
--- a/Xi/getfctl.c
+++ b/Xi/getfctl.c
@@ -265,7 +265,7 @@ SRepXGetFeedbackControl(ClientPtr client, int size,
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
     swaps(&rep->num_feedbacks);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
 
 /***********************************************************************
diff --git a/Xi/getfocus.c b/Xi/getfocus.c
index ba36e37..54c176f 100644
--- a/Xi/getfocus.c
+++ b/Xi/getfocus.c
@@ -135,5 +135,5 @@ SRepXGetDeviceFocus(ClientPtr client, int size, xGetDeviceFocusReply * rep)
     swapl(&rep->length);
     swapl(&rep->focus);
     swapl(&rep->time);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/getkmap.c b/Xi/getkmap.c
index 006be62..3536879 100644
--- a/Xi/getkmap.c
+++ b/Xi/getkmap.c
@@ -150,5 +150,5 @@ SRepXGetDeviceKeyMapping(ClientPtr client, int size,
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/getmmap.c b/Xi/getmmap.c
index 3f84243..97d4c0d 100644
--- a/Xi/getmmap.c
+++ b/Xi/getmmap.c
@@ -109,7 +109,7 @@ ProcXGetDeviceModifierMapping(ClientPtr client)
     rep.length = max_keys_per_mod << 1;
 
     WriteReplyToClient(client, sizeof(xGetDeviceModifierMappingReply), &rep);
-    WriteToClient(client, max_keys_per_mod * 8, (char *) modkeymap);
+    WriteToClient(client, max_keys_per_mod * 8, modkeymap);
 
     free(modkeymap);
 
@@ -129,5 +129,5 @@ SRepXGetDeviceModifierMapping(ClientPtr client, int size,
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/getprop.c b/Xi/getprop.c
index b7b9e6b..b5af13a 100644
--- a/Xi/getprop.c
+++ b/Xi/getprop.c
@@ -178,5 +178,5 @@ SRepXGetDeviceDontPropagateList(ClientPtr client, int size,
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
     swaps(&rep->count);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/getselev.c b/Xi/getselev.c
index 253c87f..4fcc902 100644
--- a/Xi/getselev.c
+++ b/Xi/getselev.c
@@ -170,5 +170,5 @@ SRepXGetSelectedExtensionEvents(ClientPtr client, int size,
     swapl(&rep->length);
     swaps(&rep->this_client_count);
     swaps(&rep->all_clients_count);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/getvers.c b/Xi/getvers.c
index eb52c5b..b380344 100644
--- a/Xi/getvers.c
+++ b/Xi/getvers.c
@@ -127,5 +127,5 @@ SRepXGetExtensionVersion(ClientPtr client, int size,
     swapl(&rep->length);
     swaps(&rep->major_version);
     swaps(&rep->minor_version);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/grabdev.c b/Xi/grabdev.c
index c904a97..bdc0c4b 100644
--- a/Xi/grabdev.c
+++ b/Xi/grabdev.c
@@ -211,5 +211,5 @@ SRepXGrabDevice(ClientPtr client, int size, xGrabDeviceReply * rep)
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/gtmotion.c b/Xi/gtmotion.c
index 48bc79a..2249b86 100644
--- a/Xi/gtmotion.c
+++ b/Xi/gtmotion.c
@@ -147,7 +147,7 @@ ProcXGetDeviceMotionEvents(ClientPtr client)
                 bufptr++;
             }
         }
-        WriteToClient(client, length * 4, (char *) coords);
+        WriteToClient(client, length * 4, coords);
     }
     free(coords);
     return Success;
@@ -167,5 +167,5 @@ SRepXGetDeviceMotionEvents(ClientPtr client, int size,
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
     swapl(&rep->nEvents);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/listdev.c b/Xi/listdev.c
index a02112f..1fff738 100644
--- a/Xi/listdev.c
+++ b/Xi/listdev.c
@@ -417,5 +417,5 @@ SRepXListInputDevices(ClientPtr client, int size, xListInputDevicesReply * rep)
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/opendev.c b/Xi/opendev.c
index e7c00a2..486ac14 100644
--- a/Xi/opendev.c
+++ b/Xi/opendev.c
@@ -151,7 +151,7 @@ ProcXOpenDevice(ClientPtr client)
     rep.length = bytes_to_int32(j * sizeof(xInputClassInfo));
     rep.num_classes = j;
     WriteReplyToClient(client, sizeof(xOpenDeviceReply), &rep);
-    WriteToClient(client, j * sizeof(xInputClassInfo), (char *) evbase);
+    WriteToClient(client, j * sizeof(xInputClassInfo), evbase);
     return Success;
 }
 
@@ -167,5 +167,5 @@ SRepXOpenDevice(ClientPtr client, int size, xOpenDeviceReply * rep)
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/queryst.c b/Xi/queryst.c
index ffb6de0..de19974 100644
--- a/Xi/queryst.c
+++ b/Xi/queryst.c
@@ -184,5 +184,5 @@ SRepXQueryDeviceState(ClientPtr client, int size, xQueryDeviceStateReply * rep)
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/setbmap.c b/Xi/setbmap.c
index 110f5e9..296b439 100644
--- a/Xi/setbmap.c
+++ b/Xi/setbmap.c
@@ -134,5 +134,5 @@ SRepXSetDeviceButtonMapping(ClientPtr client, int size,
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/setdval.c b/Xi/setdval.c
index 542f20d..8c3816d 100644
--- a/Xi/setdval.c
+++ b/Xi/setdval.c
@@ -138,5 +138,5 @@ SRepXSetDeviceValuators(ClientPtr client, int size,
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/setmmap.c b/Xi/setmmap.c
index 36845d7..e70038e 100644
--- a/Xi/setmmap.c
+++ b/Xi/setmmap.c
@@ -140,5 +140,5 @@ SRepXSetDeviceModifierMapping(ClientPtr client, int size,
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/setmode.c b/Xi/setmode.c
index a7bf1ea..f212d83 100644
--- a/Xi/setmode.c
+++ b/Xi/setmode.c
@@ -137,5 +137,5 @@ SRepXSetDeviceMode(ClientPtr client, int size, xSetDeviceModeReply * rep)
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/xigetclientpointer.c b/Xi/xigetclientpointer.c
index 07dbf18..8a5f54f 100644
--- a/Xi/xigetclientpointer.c
+++ b/Xi/xigetclientpointer.c
@@ -100,5 +100,5 @@ SRepXIGetClientPointer(ClientPtr client, int size,
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
     swaps(&rep->deviceid);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/xigrabdev.c b/Xi/xigrabdev.c
index 8d2cf0b..095fcfa 100644
--- a/Xi/xigrabdev.c
+++ b/Xi/xigrabdev.c
@@ -156,5 +156,5 @@ SRepXIGrabDevice(ClientPtr client, int size, xXIGrabDeviceReply * rep)
 {
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 7130328..5e4fa4e 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -224,7 +224,7 @@ ProcXIPassiveGrabDevice(ClientPtr client)
 
     WriteReplyToClient(client, sizeof(rep), &rep);
     if (rep.num_modifiers)
-        WriteToClient(client, rep.length * 4, (char *) modifiers_failed);
+        WriteToClient(client, rep.length * 4, modifiers_failed);
 
     free(modifiers_failed);
  out:
@@ -240,7 +240,7 @@ SRepXIPassiveGrabDevice(ClientPtr client, int size,
     swapl(&rep->length);
     swaps(&rep->num_modifiers);
 
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
 
 int
diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index 5f46b54..ab86963 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -1063,7 +1063,7 @@ SRepXListDeviceProperties(ClientPtr client, int size,
     swapl(&rep->length);
     swaps(&rep->nAtoms);
     /* properties will be swapped later, see ProcXListDeviceProperties */
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
 
 void
@@ -1076,7 +1076,7 @@ SRepXGetDeviceProperty(ClientPtr client, int size,
     swapl(&rep->bytesAfter);
     swapl(&rep->nItems);
     /* data will be swapped, see ProcXGetDeviceProperty */
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
 
 /* XI2 Request/reply handling */
@@ -1300,7 +1300,7 @@ SRepXIListProperties(ClientPtr client, int size, xXIListPropertiesReply * rep)
     swapl(&rep->length);
     swaps(&rep->num_properties);
     /* properties will be swapped later, see ProcXIListProperties */
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
 
 void
@@ -1312,5 +1312,5 @@ SRepXIGetProperty(ClientPtr client, int size, xXIGetPropertyReply * rep)
     swapl(&rep->bytes_after);
     swapl(&rep->num_items);
     /* data will be swapped, see ProcXIGetProperty */
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
index 15c8b2a..af7ea53 100644
--- a/Xi/xiquerydevice.c
+++ b/Xi/xiquerydevice.c
@@ -162,7 +162,7 @@ SRepXIQueryDevice(ClientPtr client, int size, xXIQueryDeviceReply * rep)
 
     /* Device info is already swapped, see ProcXIQueryDevice */
 
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
 
 /**
diff --git a/Xi/xiquerypointer.c b/Xi/xiquerypointer.c
index 169436e..e09a1f6 100644
--- a/Xi/xiquerypointer.c
+++ b/Xi/xiquerypointer.c
@@ -219,5 +219,5 @@ SRepXIQueryPointer(ClientPtr client, int size, xXIQueryPointerReply * rep)
     swapl(&rep->win_y);
     swaps(&rep->buttons_len);
 
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/xiqueryversion.c b/Xi/xiqueryversion.c
index 6081c41..0d4962f 100644
--- a/Xi/xiqueryversion.c
+++ b/Xi/xiqueryversion.c
@@ -126,5 +126,5 @@ SRepXIQueryVersion(ClientPtr client, int size, xXIQueryVersionReply * rep)
     swapl(&rep->length);
     swaps(&rep->major_version);
     swaps(&rep->minor_version);
-    WriteToClient(client, size, (char *) rep);
+    WriteToClient(client, size, rep);
 }
diff --git a/Xi/xiselectev.c b/Xi/xiselectev.c
index e7e719d..6dd2c1c 100644
--- a/Xi/xiselectev.c
+++ b/Xi/xiselectev.c
@@ -335,5 +335,5 @@ SRepXIGetSelectedEvents(ClientPtr client,
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
     swaps(&rep->num_masks);
-    WriteToClient(client, len, (char *) rep);
+    WriteToClient(client, len, rep);
 }
diff --git a/Xi/xisetdevfocus.c b/Xi/xisetdevfocus.c
index b52c9cc..55e5c35 100644
--- a/Xi/xisetdevfocus.c
+++ b/Xi/xisetdevfocus.c
@@ -121,5 +121,5 @@ SRepXIGetFocus(ClientPtr client, int len, xXIGetFocusReply * rep)
     swaps(&rep->sequenceNumber);
     swapl(&rep->length);
     swapl(&rep->focus);
-    WriteToClient(client, len, (char *) rep);
+    WriteToClient(client, len, rep);
 }
diff --git a/composite/compext.c b/composite/compext.c
index 1d4d8bf..be25b27 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -131,7 +131,7 @@ ProcCompositeQueryVersion(ClientPtr client)
         swapl(&rep.majorVersion);
         swapl(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xCompositeQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xCompositeQueryVersionReply), &rep);
     return Success;
 }
 
@@ -321,8 +321,7 @@ ProcCompositeGetOverlayWindow(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.overlayWin);
     }
-    (void) WriteToClient(client, sz_xCompositeGetOverlayWindowReply,
-                         (char *) &rep);
+    WriteToClient(client, sz_xCompositeGetOverlayWindowReply, &rep);
 
     return Success;
 }
@@ -853,8 +852,7 @@ PanoramiXCompositeGetOverlayWindow(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.overlayWin);
     }
-    (void) WriteToClient(client, sz_xCompositeGetOverlayWindowReply,
-                         (char *) &rep);
+    WriteToClient(client, sz_xCompositeGetOverlayWindowReply, &rep);
 
     return Success;
 }
diff --git a/damageext/damageext.c b/damageext/damageext.c
index f21f71c..70d2eee 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -154,7 +154,7 @@ ProcDamageQueryVersion(ClientPtr client)
         swapl(&rep.majorVersion);
         swapl(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xDamageQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDamageQueryVersionReply), &rep);
     return Success;
 }
 
diff --git a/dbe/dbe.c b/dbe/dbe.c
index ca7f3e2..d8010ff 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -132,7 +132,7 @@ ProcDbeGetVersion(ClientPtr client)
         swaps(&rep.sequenceNumber);
     }
 
-    WriteToClient(client, sizeof(xDbeGetVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDbeGetVersionReply), &rep);
 
     return Success;
 
@@ -679,7 +679,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
     }
 
     /* Send off reply. */
-    WriteToClient(client, sizeof(xDbeGetVisualInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDbeGetVisualInfoReply), &rep);
 
     for (i = 0; i < count; i++) {
         CARD32 data32;
@@ -693,7 +693,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
             swapl(&data32);
         }
 
-        WriteToClient(client, sizeof(CARD32), (char *) &data32);
+        WriteToClient(client, sizeof(CARD32), &data32);
 
         /* Now send off visual info items. */
         for (j = 0; j < pScrVisInfo[i].count; j++) {
@@ -717,8 +717,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
             }
 
             /* Write visualID(32), depth(8), perfLevel(8), and pad(16). */
-            WriteToClient(client, 2 * sizeof(CARD32),
-                          (char *) &visInfo.visualID);
+            WriteToClient(client, 2 * sizeof(CARD32), &visInfo.visualID);
         }
     }
 
@@ -782,8 +781,7 @@ ProcDbeGetBackBufferAttributes(ClientPtr client)
         swapl(&rep.attributes);
     }
 
-    WriteToClient(client, sizeof(xDbeGetBackBufferAttributesReply),
-                  (char *) &rep);
+    WriteToClient(client, sizeof(xDbeGetBackBufferAttributesReply), &rep);
     return Success;
 
 }                               /* ProcDbeGetbackBufferAttributes() */
diff --git a/dix/devices.c b/dix/devices.c
index 70fb273..c042681 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1704,7 +1704,7 @@ ProcGetModifierMapping(ClientPtr client)
     rep.length = max_keys_per_mod << 1;
 
     WriteReplyToClient(client, sizeof(xGetModifierMappingReply), &rep);
-    (void) WriteToClient(client, max_keys_per_mod * 8, (char *) modkeymap);
+    WriteToClient(client, max_keys_per_mod * 8, modkeymap);
 
     free(modkeymap);
 
@@ -1898,7 +1898,7 @@ ProcGetPointerMapping(ClientPtr client)
     rep.length = ((unsigned) rep.nElts + (4 - 1)) / 4;
     WriteReplyToClient(client, sizeof(xGetPointerMappingReply), &rep);
     if (butc)
-        WriteToClient(client, (int) rep.nElts, (char *) &butc->map[1]);
+        WriteToClient(client, (int) rep.nElts, &butc->map[1]);
     return Success;
 }
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index bcce22f..4231cb0 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1035,7 +1035,7 @@ ProcGetAtomName(ClientPtr client)
         reply.sequenceNumber = client->sequence;
         reply.nameLength = len;
         WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply);
-        (void) WriteToClient(client, len, str);
+        WriteToClient(client, len, str);
         return Success;
     }
     else {
@@ -2143,8 +2143,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
                               BitsPerPixel(pDraw->depth), ClientOrder(client));
 
 /* Don't split me, gcc pukes when you do */
-                (void) WriteToClient(client,
-                                     (int) (nlines * widthBytesLine), pBuf);
+                WriteToClient(client, (int) (nlines * widthBytesLine), pBuf);
             }
             linesDone += nlines;
         }
@@ -2179,9 +2178,8 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
                                       1, ClientOrder(client));
 
 /* Don't split me, gcc pukes when you do */
-                        (void) WriteToClient(client,
-                                             (int) (nlines * widthBytesLine),
-                                             pBuf);
+                        WriteToClient(client, (int) (nlines * widthBytesLine),
+				      pBuf);
                     }
                     linesDone += nlines;
                 }
@@ -3250,8 +3248,7 @@ ProcGetFontPath(ClientPtr client)
 
     WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply);
     if (stringLens || numpaths)
-        (void) WriteToClient(client, stringLens + numpaths,
-                             (char *) bufferStart);
+        WriteToClient(client, stringLens + numpaths, bufferStart);
     return Success;
 }
 
@@ -3523,8 +3520,8 @@ SendConnSetup(ClientPtr client, const char *reason)
         if (client->swapped)
             WriteSConnSetupPrefix(client, &csp);
         else
-            (void) WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp);
-        (void) WriteToClient(client, (int) csp.lengthReason, reason);
+            WriteToClient(client, sz_xConnSetupPrefix, &csp);
+        WriteToClient(client, (int) csp.lengthReason, reason);
         return client->noClientException = -1;
     }
 
@@ -3577,10 +3574,9 @@ SendConnSetup(ClientPtr client, const char *reason)
                              lConnectionInfo);
     }
     else {
-        (void) WriteToClient(client, sizeof(xConnSetupPrefix),
-                             (char *) lconnSetupPrefix);
-        (void) WriteToClient(client, (int) (lconnSetupPrefix->length << 2),
-                             lConnectionInfo);
+        WriteToClient(client, sizeof(xConnSetupPrefix), lconnSetupPrefix);
+        WriteToClient(client, (int) (lconnSetupPrefix->length << 2),
+		      lConnectionInfo);
     }
     client->clientState = ClientStateRunning;
     if (ClientStateCallback) {
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index dd93311..d1f6326 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -782,7 +782,7 @@ doListFontsAndAliases(ClientPtr client, LFclosurePtr c)
     reply.length = bytes_to_int32(stringLens + nnames);
     client->pSwapReplyFunc = ReplySwapVector[X_ListFonts];
     WriteSwappedDataToClient(client, sizeof(xListFontsReply), &reply);
-    (void) WriteToClient(client, stringLens + nnames, bufferStart);
+    WriteToClient(client, stringLens + nnames, bufferStart);
     free(bufferStart);
 
  bail:
@@ -1020,7 +1020,7 @@ doListFontsWithInfo(ClientPtr client, LFWIclosurePtr c)
                 pFP++;
             }
             WriteSwappedDataToClient(client, length, reply);
-            (void) WriteToClient(client, namelen, name);
+            WriteToClient(client, namelen, name);
             if (pFontInfo == &fontInfo) {
                 free(fontInfo.props);
                 free(fontInfo.isStringProp);
diff --git a/dix/events.c b/dix/events.c
index 89877a1..dbfe9d9 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -5898,14 +5898,14 @@ WriteEventsToClient(ClientPtr pClient, int count, xEvent *events)
             (*EventSwapVector[eventFrom->u.u.type & 0177])
                 (eventFrom, eventTo);
 
-            WriteToClient(pClient, eventlength, (char *) eventTo);
+            WriteToClient(pClient, eventlength, eventTo);
         }
     }
     else {
         /* only one GenericEvent, remember? that means either count is 1 and
          * eventlength is arbitrary or eventlength is 32 and count doesn't
          * matter. And we're all set. Woohoo. */
-        WriteToClient(pClient, count * eventlength, (char *) events);
+        WriteToClient(pClient, count * eventlength, events);
     }
 }
 
diff --git a/dix/swaprep.c b/dix/swaprep.c
index 9440c4e..559fe27 100644
--- a/dix/swaprep.c
+++ b/dix/swaprep.c
@@ -80,7 +80,7 @@ Swap32Write(ClientPtr pClient, int size, CARD32 *pbuf)
     {
         swapl(&pbuf[i]);
     }
-    (void) WriteToClient(pClient, size << 2, (char *) pbuf);
+    WriteToClient(pClient, size << 2, pbuf);
 }
 
 /**
@@ -123,7 +123,7 @@ CopySwap32Write(ClientPtr pClient, int size, CARD32 *pbuf)
             from++;
             to++;
         }
-        (void) WriteToClient(pClient, nbytes, (char *) pbufT);
+        WriteToClient(pClient, nbytes, pbufT);
     }
 
     if (pbufT != tmpbuf)
@@ -170,7 +170,7 @@ CopySwap16Write(ClientPtr pClient, int size, short *pbuf)
             from++;
             to++;
         }
-        (void) WriteToClient(pClient, nbytes, (char *) pbufT);
+        WriteToClient(pClient, nbytes, pbufT);
     }
 
     if (pbufT != tmpbuf)
@@ -182,7 +182,7 @@ void
 SGenericReply(ClientPtr pClient, int size, xGenericReply * pRep)
 {
     swaps(&pRep->sequenceNumber);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 /* Extra-large reply */
@@ -200,7 +200,7 @@ SGetWindowAttributesReply(ClientPtr pClient, int size,
     swapl(&pRep->allEventMasks);
     swapl(&pRep->yourEventMask);
     swaps(&pRep->doNotPropagateMask);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -213,7 +213,7 @@ SGetGeometryReply(ClientPtr pClient, int size, xGetGeometryReply * pRep)
     swaps(&pRep->width);
     swaps(&pRep->height);
     swaps(&pRep->borderWidth);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -224,7 +224,7 @@ SQueryTreeReply(ClientPtr pClient, int size, xQueryTreeReply * pRep)
     swapl(&pRep->root);
     swapl(&pRep->parent);
     swaps(&pRep->nChildren);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -232,7 +232,7 @@ SInternAtomReply(ClientPtr pClient, int size, xInternAtomReply * pRep)
 {
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->atom);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -241,7 +241,7 @@ SGetAtomNameReply(ClientPtr pClient, int size, xGetAtomNameReply * pRep)
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
     swaps(&pRep->nameLength);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -252,7 +252,7 @@ SGetPropertyReply(ClientPtr pClient, int size, xGetPropertyReply * pRep)
     swapl(&pRep->propertyType);
     swapl(&pRep->bytesAfter);
     swapl(&pRep->nItems);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -261,7 +261,7 @@ SListPropertiesReply(ClientPtr pClient, int size, xListPropertiesReply * pRep)
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
     swaps(&pRep->nProperties);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -270,7 +270,7 @@ SGetSelectionOwnerReply(ClientPtr pClient, int size,
 {
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->owner);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -284,7 +284,7 @@ SQueryPointerReply(ClientPtr pClient, int size, xQueryPointerReply * pRep)
     swaps(&pRep->winX);
     swaps(&pRep->winY);
     swaps(&pRep->mask);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 static void
@@ -307,7 +307,7 @@ SwapTimeCoordWrite(ClientPtr pClient, int size, xTimecoord * pRep)
         SwapTimecoord(pRepT);
         pRepT++;
     }
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 
 }
 
@@ -317,7 +317,7 @@ SGetMotionEventsReply(ClientPtr pClient, int size, xGetMotionEventsReply * pRep)
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
     swapl(&pRep->nEvents);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -327,7 +327,7 @@ STranslateCoordsReply(ClientPtr pClient, int size, xTranslateCoordsReply * pRep)
     swapl(&pRep->child);
     swaps(&pRep->dstX);
     swaps(&pRep->dstY);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -335,7 +335,7 @@ SGetInputFocusReply(ClientPtr pClient, int size, xGetInputFocusReply * pRep)
 {
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->focus);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 /* extra long reply */
@@ -344,7 +344,7 @@ SQueryKeymapReply(ClientPtr pClient, int size, xQueryKeymapReply * pRep)
 {
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 static void
@@ -405,7 +405,7 @@ void
 SQueryFontReply(ClientPtr pClient, int size, xQueryFontReply * pRep)
 {
     SwapFont(pRep, TRUE);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -420,7 +420,7 @@ SQueryTextExtentsReply(ClientPtr pClient, int size,
     swapl(&pRep->overallWidth);
     swapl(&pRep->overallLeft);
     swapl(&pRep->overallRight);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -429,7 +429,7 @@ SListFontsReply(ClientPtr pClient, int size, xListFontsReply * pRep)
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
     swaps(&pRep->nFonts);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -437,7 +437,7 @@ SListFontsWithInfoReply(ClientPtr pClient, int size,
                         xListFontsWithInfoReply * pRep)
 {
     SwapFont((xQueryFontReply *) pRep, FALSE);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -446,7 +446,7 @@ SGetFontPathReply(ClientPtr pClient, int size, xGetFontPathReply * pRep)
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
     swaps(&pRep->nPaths);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -455,7 +455,7 @@ SGetImageReply(ClientPtr pClient, int size, xGetImageReply * pRep)
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
     swapl(&pRep->visual);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
     /* Fortunately, image doesn't need swapping */
 }
 
@@ -466,7 +466,7 @@ SListInstalledColormapsReply(ClientPtr pClient, int size,
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
     swaps(&pRep->nColormaps);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -477,7 +477,7 @@ SAllocColorReply(ClientPtr pClient, int size, xAllocColorReply * pRep)
     swaps(&pRep->green);
     swaps(&pRep->blue);
     swapl(&pRep->pixel);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -491,7 +491,7 @@ SAllocNamedColorReply(ClientPtr pClient, int size, xAllocNamedColorReply * pRep)
     swaps(&pRep->screenRed);
     swaps(&pRep->screenGreen);
     swaps(&pRep->screenBlue);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -501,7 +501,7 @@ SAllocColorCellsReply(ClientPtr pClient, int size, xAllocColorCellsReply * pRep)
     swapl(&pRep->length);
     swaps(&pRep->nPixels);
     swaps(&pRep->nMasks);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -514,7 +514,7 @@ SAllocColorPlanesReply(ClientPtr pClient, int size,
     swapl(&pRep->redMask);
     swapl(&pRep->greenMask);
     swapl(&pRep->blueMask);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 static void
@@ -537,7 +537,7 @@ SQColorsExtend(ClientPtr pClient, int size, xrgb * prgb)
         SwapRGB(prgbT);
         prgbT++;
     }
-    (void) WriteToClient(pClient, size, (char *) prgb);
+    WriteToClient(pClient, size, prgb);
 }
 
 void
@@ -546,7 +546,7 @@ SQueryColorsReply(ClientPtr pClient, int size, xQueryColorsReply * pRep)
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
     swaps(&pRep->nColors);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -559,7 +559,7 @@ SLookupColorReply(ClientPtr pClient, int size, xLookupColorReply * pRep)
     swaps(&pRep->screenRed);
     swaps(&pRep->screenGreen);
     swaps(&pRep->screenBlue);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -568,7 +568,7 @@ SQueryBestSizeReply(ClientPtr pClient, int size, xQueryBestSizeReply * pRep)
     swaps(&pRep->sequenceNumber);
     swaps(&pRep->width);
     swaps(&pRep->height);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -576,7 +576,7 @@ SListExtensionsReply(ClientPtr pClient, int size, xListExtensionsReply * pRep)
 {
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -585,7 +585,7 @@ SGetKeyboardMappingReply(ClientPtr pClient, int size,
 {
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -594,7 +594,7 @@ SGetPointerMappingReply(ClientPtr pClient, int size,
 {
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -603,7 +603,7 @@ SGetModifierMappingReply(ClientPtr pClient, int size,
 {
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -615,7 +615,7 @@ SGetKeyboardControlReply(ClientPtr pClient, int size,
     swapl(&pRep->ledMask);
     swaps(&pRep->bellPitch);
     swaps(&pRep->bellDuration);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -626,7 +626,7 @@ SGetPointerControlReply(ClientPtr pClient, int size,
     swaps(&pRep->accelNumerator);
     swaps(&pRep->accelDenominator);
     swaps(&pRep->threshold);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -635,7 +635,7 @@ SGetScreenSaverReply(ClientPtr pClient, int size, xGetScreenSaverReply * pRep)
     swaps(&pRep->sequenceNumber);
     swaps(&pRep->timeout);
     swaps(&pRep->interval);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -651,7 +651,7 @@ SLHostsExtend(ClientPtr pClient, int size, char *buf)
         swaps(&host->length);
         bufT += sizeof(xHostEntry) + pad_to_int32(len);
     }
-    (void) WriteToClient(pClient, size, buf);
+    WriteToClient(pClient, size, buf);
 }
 
 void
@@ -660,7 +660,7 @@ SListHostsReply(ClientPtr pClient, int size, xListHostsReply * pRep)
     swaps(&pRep->sequenceNumber);
     swapl(&pRep->length);
     swaps(&pRep->nHosts);
-    (void) WriteToClient(pClient, size, (char *) pRep);
+    WriteToClient(pClient, size, pRep);
 }
 
 void
@@ -1140,7 +1140,7 @@ WriteSConnectionInfo(ClientPtr pClient, unsigned long size, char *pInfo)
         return;
     }
     SwapConnSetupInfo(pInfo, pInfoTBase);
-    (void) WriteToClient(pClient, (int) size, (char *) pInfoTBase);
+    WriteToClient(pClient, (int) size, pInfoTBase);
     free(pInfoTBase);
 }
 
@@ -1160,7 +1160,7 @@ WriteSConnSetupPrefix(ClientPtr pClient, xConnSetupPrefix * pcsp)
     xConnSetupPrefix cspT;
 
     SwapConnSetupPrefix(pcsp, &cspT);
-    (void) WriteToClient(pClient, sizeof(cspT), (char *) &cspT);
+    WriteToClient(pClient, sizeof(cspT), &cspT);
 }
 
 /*
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index d054219..9cb9e73 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -667,7 +667,7 @@ DoMakeCurrent(__GLXclientState * cl,
         __glXSwapMakeCurrentReply(client, &reply);
     }
     else {
-        WriteToClient(client, sz_xGLXMakeCurrentReply, (char *) &reply);
+        WriteToClient(client, sz_xGLXMakeCurrentReply, &reply);
     }
     return Success;
 }
@@ -731,7 +731,7 @@ __glXDisp_IsDirect(__GLXclientState * cl, GLbyte * pc)
         __glXSwapIsDirectReply(client, &reply);
     }
     else {
-        WriteToClient(client, sz_xGLXIsDirectReply, (char *) &reply);
+        WriteToClient(client, sz_xGLXIsDirectReply, &reply);
     }
 
     return Success;
@@ -767,7 +767,7 @@ __glXDisp_QueryVersion(__GLXclientState * cl, GLbyte * pc)
         __glXSwapQueryVersionReply(client, &reply);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryVersionReply, (char *) &reply);
+        WriteToClient(client, sz_xGLXQueryVersionReply, &reply);
     }
     return Success;
 }
@@ -949,7 +949,7 @@ __glXDisp_GetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
         __GLX_SWAP_INT(&reply.numProps);
     }
 
-    WriteToClient(client, sz_xGLXGetVisualConfigsReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply);
 
     for (i = 0; i < pGlxScreen->numVisuals; i++) {
         modes = pGlxScreen->visuals[i];
@@ -1006,7 +1006,7 @@ __glXDisp_GetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
         if (client->swapped) {
             __GLX_SWAP_INT_ARRAY(buf, p);
         }
-        WriteToClient(client, __GLX_SIZE_CARD32 * p, (char *) buf);
+        WriteToClient(client, __GLX_SIZE_CARD32 * p, buf);
     }
     return Success;
 }
@@ -1052,7 +1052,7 @@ DoGetFBConfigs(__GLXclientState * cl, unsigned screen)
         __GLX_SWAP_INT(&reply.numAttribs);
     }
 
-    WriteToClient(client, sz_xGLXGetFBConfigsReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXGetFBConfigsReply, &reply);
 
     for (modes = pGlxScreen->fbconfigs; modes != NULL; modes = modes->next) {
         p = 0;
@@ -1685,8 +1685,8 @@ DoQueryContext(__GLXclientState * cl, GLXContextID gcId)
         __glXSwapQueryContextInfoEXTReply(client, &reply, sendBuf);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, (char *) &reply);
-        WriteToClient(client, nReplyBytes, (char *) sendBuf);
+        WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, &reply);
+        WriteToClient(client, nReplyBytes, sendBuf);
     }
     free((char *) sendBuf);
 
@@ -1887,10 +1887,8 @@ DoGetDrawableAttributes(__GLXclientState * cl, XID drawId)
         __glXSwapGetDrawableAttributesReply(client, &reply, attributes);
     }
     else {
-        WriteToClient(client, sz_xGLXGetDrawableAttributesReply,
-                      (char *) &reply);
-        WriteToClient(client, reply.length * sizeof(CARD32),
-                      (char *) attributes);
+        WriteToClient(client, sz_xGLXGetDrawableAttributesReply, &reply);
+        WriteToClient(client, reply.length * sizeof(CARD32), attributes);
     }
 
     return Success;
@@ -2326,9 +2324,8 @@ __glXDisp_QueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
         glxSwapQueryExtensionsStringReply(client, &reply, buf);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryExtensionsStringReply,
-                      (char *) &reply);
-        WriteToClient(client, (int) (length << 2), (char *) buf);
+        WriteToClient(client, sz_xGLXQueryExtensionsStringReply, &reply);
+        WriteToClient(client, (int) (length << 2), buf);
     }
 
     free(buf);
@@ -2388,7 +2385,7 @@ __glXDisp_QueryServerString(__GLXclientState * cl, GLbyte * pc)
         glxSwapQueryServerStringReply(client, &reply, buf);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryServerStringReply, (char *) &reply);
+        WriteToClient(client, sz_xGLXQueryServerStringReply, &reply);
         WriteToClient(client, (int) (length << 2), buf);
     }
 
diff --git a/glx/glxcmdsswap.c b/glx/glxcmdsswap.c
index e8520d6..43f88d3 100644
--- a/glx/glxcmdsswap.c
+++ b/glx/glxcmdsswap.c
@@ -840,7 +840,7 @@ __glXSwapMakeCurrentReply(ClientPtr client, xGLXMakeCurrentReply * reply)
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->contextTag);
-    WriteToClient(client, sz_xGLXMakeCurrentReply, (char *) reply);
+    WriteToClient(client, sz_xGLXMakeCurrentReply, reply);
 }
 
 void
@@ -849,7 +849,7 @@ __glXSwapIsDirectReply(ClientPtr client, xGLXIsDirectReply * reply)
     __GLX_DECLARE_SWAP_VARIABLES;
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
-    WriteToClient(client, sz_xGLXIsDirectReply, (char *) reply);
+    WriteToClient(client, sz_xGLXIsDirectReply, reply);
 }
 
 void
@@ -860,7 +860,7 @@ __glXSwapQueryVersionReply(ClientPtr client, xGLXQueryVersionReply * reply)
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->majorVersion);
     __GLX_SWAP_INT(&reply->minorVersion);
-    WriteToClient(client, sz_xGLXQueryVersionReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryVersionReply, reply);
 }
 
 void
@@ -875,7 +875,7 @@ glxSwapQueryExtensionsStringReply(ClientPtr client,
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
-    WriteToClient(client, sz_xGLXQueryExtensionsStringReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryExtensionsStringReply, reply);
     __GLX_SWAP_INT_ARRAY((int *) buf, length);
     WriteToClient(client, length << 2, buf);
 }
@@ -890,7 +890,7 @@ glxSwapQueryServerStringReply(ClientPtr client,
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
-    WriteToClient(client, sz_xGLXQueryServerStringReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryServerStringReply, reply);
     /** no swap is needed for an array of chars **/
     /* __GLX_SWAP_INT_ARRAY((int *)buf, length); */
     WriteToClient(client, length << 2, buf);
@@ -908,9 +908,9 @@ __glXSwapQueryContextInfoEXTReply(ClientPtr client,
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
-    WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, reply);
     __GLX_SWAP_INT_ARRAY((int *) buf, length);
-    WriteToClient(client, length << 2, (char *) buf);
+    WriteToClient(client, length << 2, buf);
 }
 
 void
@@ -925,9 +925,9 @@ __glXSwapGetDrawableAttributesReply(ClientPtr client,
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->numAttribs);
-    WriteToClient(client, sz_xGLXGetDrawableAttributesReply, (char *) reply);
+    WriteToClient(client, sz_xGLXGetDrawableAttributesReply, reply);
     __GLX_SWAP_INT_ARRAY((int *) buf, length);
-    WriteToClient(client, length << 2, (char *) buf);
+    WriteToClient(client, length << 2, buf);
 }
 
 /************************************************************************/
diff --git a/glx/indirect_util.c b/glx/indirect_util.c
index a54f70a..a30b1f8 100644
--- a/glx/indirect_util.c
+++ b/glx/indirect_util.c
@@ -138,10 +138,10 @@ __glXSendReply(ClientPtr client, const void *data, size_t elements,
      */
 
     (void) memcpy(&__glXReply.pad3, data, 8);
-    WriteToClient(client, sz_xGLXSingleReply, (char *) &__glXReply);
+    WriteToClient(client, sz_xGLXSingleReply, &__glXReply);
 
     if (reply_ints != 0) {
-        WriteToClient(client, reply_ints * 4, (char *) data);
+        WriteToClient(client, reply_ints * 4, data);
     }
 }
 
@@ -184,10 +184,10 @@ __glXSendReplySwap(ClientPtr client, const void *data, size_t elements,
      */
 
     (void) memcpy(&__glXReply.pad3, data, 8);
-    WriteToClient(client, sz_xGLXSingleReply, (char *) &__glXReply);
+    WriteToClient(client, sz_xGLXSingleReply, &__glXReply);
 
     if (reply_ints != 0) {
-        WriteToClient(client, reply_ints * 4, (char *) data);
+        WriteToClient(client, reply_ints * 4, data);
     }
 }
 
diff --git a/glx/single2.c b/glx/single2.c
index 42cccc1..4d8ea4e 100644
--- a/glx/single2.c
+++ b/glx/single2.c
@@ -199,9 +199,9 @@ __glXDisp_RenderMode(__GLXclientState * cl, GLbyte * pc)
     reply.retval = retval;
     reply.size = nitems;
     reply.newMode = newMode;
-    WriteToClient(client, sz_xGLXRenderModeReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXRenderModeReply, &reply);
     if (retBytes) {
-        WriteToClient(client, retBytes, (char *) retBuffer);
+        WriteToClient(client, retBytes, retBuffer);
     }
     return Success;
 }
@@ -384,7 +384,7 @@ DoGetString(__GLXclientState * cl, GLbyte * pc, GLboolean need_swap)
     }
 
     __GLX_SEND_HEADER();
-    WriteToClient(client, length, (char *) string);
+    WriteToClient(client, length, string);
     free(buf);
 
     return Success;
diff --git a/glx/single2swap.c b/glx/single2swap.c
index e6bb585..9da2afd 100644
--- a/glx/single2swap.c
+++ b/glx/single2swap.c
@@ -216,9 +216,9 @@ __glXDispSwap_RenderMode(__GLXclientState * cl, GLbyte * pc)
     __GLX_SWAP_INT(&reply.retval);
     __GLX_SWAP_INT(&reply.size);
     __GLX_SWAP_INT(&reply.newMode);
-    WriteToClient(client, sz_xGLXRenderModeReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXRenderModeReply, &reply);
     if (retBytes) {
-        WriteToClient(client, retBytes, (char *) retBuffer);
+        WriteToClient(client, retBytes, retBuffer);
     }
     return Success;
 }
diff --git a/glx/unpack.h b/glx/unpack.h
index 0a088fc..52fba74 100644
--- a/glx/unpack.h
+++ b/glx/unpack.h
@@ -63,7 +63,7 @@ extern xGLXSingleReply __glXReply;
   	__glXReply.sequenceNumber = client->sequence;
 
 #define __GLX_SEND_HEADER() \
-	WriteToClient( client, sz_xGLXSingleReply, (char *)&__glXReply);
+	WriteToClient (client, sz_xGLXSingleReply, &__glXReply);
 
 #define __GLX_PUT_RETVAL(a) \
   	__glXReply.retval = (a);
@@ -116,19 +116,19 @@ extern xGLXSingleReply __glXReply;
   	*(GLdouble *)&__glXReply.pad3 = *(GLdouble *)answer
 
 #define __GLX_SEND_BYTE_ARRAY(len) \
-	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), (char *)answer)
+	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), answer)
 
 #define __GLX_SEND_SHORT_ARRAY(len) \
-	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), (char *)answer)
+	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), answer)
 
 #define __GLX_SEND_INT_ARRAY(len) \
-	WriteToClient(client, (len)*__GLX_SIZE_INT32, (char *)answer)
+	WriteToClient(client, (len)*__GLX_SIZE_INT32, answer)
 
 #define __GLX_SEND_FLOAT_ARRAY(len) \
-	WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, (char *)answer)
+	WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, answer)
 
 #define __GLX_SEND_DOUBLE_ARRAY(len) \
-	WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, (char *)answer)
+	WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, answer)
 
 #define __GLX_SEND_VOID_ARRAY(len)  __GLX_SEND_BYTE_ARRAY(len)
 #define __GLX_SEND_UBYTE_ARRAY(len)  __GLX_SEND_BYTE_ARRAY(len)
diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c
index a226c5d..5ea133e 100644
--- a/hw/dmx/dmx.c
+++ b/hw/dmx/dmx.c
@@ -225,7 +225,7 @@ ProcDMXQueryVersion(ClientPtr client)
         swapl(&rep.minorVersion);
         swapl(&rep.patchVersion);
     }
-    WriteToClient(client, sizeof(xDMXQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXQueryVersionReply), &rep);
     return Success;
 }
 
@@ -247,7 +247,7 @@ ProcDMXSync(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.status);
     }
-    WriteToClient(client, sizeof(xDMXSyncReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXSyncReply), &rep);
     return Success;
 }
 
@@ -297,7 +297,7 @@ ProcDMXForceWindowCreation(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.status);
     }
-    WriteToClient(client, sizeof(xDMXForceWindowCreationReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXForceWindowCreationReply), &rep);
     return Success;
 }
 
@@ -317,7 +317,7 @@ ProcDMXGetScreenCount(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.screenCount);
     }
-    WriteToClient(client, sizeof(xDMXGetScreenCountReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXGetScreenCountReply), &rep);
     return Success;
 }
 
@@ -377,9 +377,9 @@ ProcDMXGetScreenAttributes(ClientPtr client)
         swaps(&rep.rootWindowXorigin);
         swaps(&rep.rootWindowYorigin);
     }
-    WriteToClient(client, sizeof(xDMXGetScreenAttributesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXGetScreenAttributesReply), &rep);
     if (length)
-        WriteToClient(client, length, (char *) attr.displayName);
+        WriteToClient(client, length, attr.displayName);
     return Success;
 }
 
@@ -453,8 +453,7 @@ ProcDMXChangeScreensAttributes(ClientPtr client)
         swapl(&rep.status);
         swapl(&rep.errorScreen);
     }
-    WriteToClient(client,
-                  sizeof(xDMXChangeScreensAttributesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXChangeScreensAttributesReply), &rep);
     return Success;
 }
 
@@ -503,7 +502,7 @@ ProcDMXAddScreen(ClientPtr client)
         swapl(&rep.status);
         swapl(&rep.physicalScreen);
     }
-    WriteToClient(client, sizeof(xDMXAddScreenReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXAddScreenReply), &rep);
     return Success;
 }
 
@@ -527,7 +526,7 @@ ProcDMXRemoveScreen(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.status);
     }
-    WriteToClient(client, sizeof(xDMXRemoveScreenReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXRemoveScreenReply), &rep);
     return Success;
 }
 
@@ -663,12 +662,12 @@ ProcDMXGetWindowAttributes(ClientPtr client)
 
     dmxFlushPendingSyncs();
 
-    WriteToClient(client, sizeof(xDMXGetWindowAttributesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXGetWindowAttributesReply), &rep);
     if (count) {
-        WriteToClient(client, count * sizeof(*screens), (char *) screens);
-        WriteToClient(client, count * sizeof(*windows), (char *) windows);
-        WriteToClient(client, count * sizeof(*pos), (char *) pos);
-        WriteToClient(client, count * sizeof(*vis), (char *) vis);
+        WriteToClient(client, count * sizeof(*screens), screens);
+        WriteToClient(client, count * sizeof(*windows), windows);
+        WriteToClient(client, count * sizeof(*pos), pos);
+        WriteToClient(client, count * sizeof(*vis), vis);
     }
 
     free(vis);
@@ -706,7 +705,7 @@ ProcDMXGetDesktopAttributes(ClientPtr client)
         swaps(&rep.shiftX);
         swaps(&rep.shiftY);
     }
-    WriteToClient(client, sizeof(xDMXGetDesktopAttributesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXGetDesktopAttributesReply), &rep);
     return Success;
 }
 
@@ -749,8 +748,7 @@ ProcDMXChangeDesktopAttributes(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.status);
     }
-    WriteToClient(client,
-                  sizeof(xDMXChangeDesktopAttributesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXChangeDesktopAttributesReply), &rep);
     return Success;
 }
 
@@ -770,7 +768,7 @@ ProcDMXGetInputCount(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.inputCount);
     }
-    WriteToClient(client, sizeof(xDMXGetInputCountReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXGetInputCountReply), &rep);
     return Success;
 }
 
@@ -808,9 +806,9 @@ ProcDMXGetInputAttributes(ClientPtr client)
         swapl(&rep.physicalId);
         swapl(&rep.nameLength);
     }
-    WriteToClient(client, sizeof(xDMXGetInputAttributesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXGetInputAttributesReply), &rep);
     if (length)
-        WriteToClient(client, length, (char *) attr.name);
+        WriteToClient(client, length, attr.name);
     return Success;
 }
 
@@ -862,7 +860,7 @@ ProcDMXAddInput(ClientPtr client)
         swapl(&rep.status);
         swapl(&rep.physicalId);
     }
-    WriteToClient(client, sizeof(xDMXAddInputReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXAddInputReply), &rep);
     return Success;
 }
 
@@ -889,7 +887,7 @@ ProcDMXRemoveInput(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.status);
     }
-    WriteToClient(client, sizeof(xDMXRemoveInputReply), (char *) &rep);
+    WriteToClient(client, sizeof(xDMXRemoveInputReply), &rep);
     return Success;
 }
 
diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c
index 49c6ef1..32684fa 100644
--- a/hw/dmx/glxProxy/glxcmds.c
+++ b/hw/dmx/glxProxy/glxcmds.c
@@ -465,8 +465,7 @@ __glXQueryMaxSwapBarriersSGIX(__GLXclientState * cl, GLbyte * pc)
         __glXSwapQueryMaxSwapBarriersSGIXReply(client, &reply);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryMaxSwapBarriersSGIXReply,
-                      (char *) &reply);
+        WriteToClient(client, sz_xGLXQueryMaxSwapBarriersSGIXReply, &reply);
     }
 
     return Success;
@@ -1388,8 +1387,7 @@ MakeCurrent(__GLXclientState * cl,
         __glXSwapMakeCurrentReply(client, &new_reply);
     }
     else {
-        WriteToClient(client, sz_xGLXMakeContextCurrentReply,
-                      (char *) &new_reply);
+        WriteToClient(client, sz_xGLXMakeContextCurrentReply, &new_reply);
     }
 
     return Success;
@@ -1449,7 +1447,7 @@ __glXIsDirect(__GLXclientState * cl, GLbyte * pc)
         __glXSwapIsDirectReply(client, &reply);
     }
     else {
-        WriteToClient(client, sz_xGLXIsDirectReply, (char *) &reply);
+        WriteToClient(client, sz_xGLXIsDirectReply, &reply);
     }
 
     return Success;
@@ -1478,7 +1476,7 @@ __glXQueryVersion(__GLXclientState * cl, GLbyte * pc)
         __glXSwapQueryVersionReply(client, &reply);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryVersionReply, (char *) &reply);
+        WriteToClient(client, sz_xGLXQueryVersionReply, &reply);
     }
     return Success;
 }
@@ -1689,7 +1687,7 @@ __glXGetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
     reply.type = X_Reply;
     reply.sequenceNumber = client->sequence;
 
-    WriteToClient(client, sz_xGLXGetVisualConfigsReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply);
 
     for (i = 0; i < pGlxScreen->numVisuals; i++) {
         pGlxVisual = &pGlxScreen->pGlxVisual[i];
@@ -1743,8 +1741,7 @@ __glXGetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
         buf[p++] = GLX_VISUAL_SELECT_GROUP_SGIX;
         buf[p++] = pGlxVisual->visualSelectGroup;
 
-        WriteToClient(client, __GLX_SIZE_CARD32 * __GLX_TOTAL_CONFIG,
-                      (char *) buf);
+        WriteToClient(client, __GLX_SIZE_CARD32 * __GLX_TOTAL_CONFIG, buf);
     }
     return Success;
 }
@@ -2637,9 +2634,8 @@ __glXQueryExtensionsString(__GLXclientState * cl, GLbyte * pc)
         glxSwapQueryExtensionsStringReply(client, &reply, be_buf);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryExtensionsStringReply,
-                      (char *) &reply);
-        WriteToClient(client, (int) (length << 2), (char *) be_buf);
+        WriteToClient(client, sz_xGLXQueryExtensionsStringReply, &reply);
+        WriteToClient(client, (int) (length << 2), be_buf);
     }
 
     return Success;
@@ -2719,7 +2715,7 @@ __glXQueryServerString(__GLXclientState * cl, GLbyte * pc)
         glxSwapQueryServerStringReply(client, &reply, be_buf);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryServerStringReply, (char *) &reply);
+        WriteToClient(client, sz_xGLXQueryServerStringReply, &reply);
         WriteToClient(client, (int) (length << 2), be_buf);
     }
 
@@ -2880,7 +2876,7 @@ __glXGetFBConfigs(__GLXclientState * cl, GLbyte * pc)
         __GLX_SWAP_INT(&reply.numFBConfigs);
         __GLX_SWAP_INT(&reply.numAttribs);
     }
-    WriteToClient(client, sz_xGLXGetFBConfigsReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXGetFBConfigsReply, &reply);
 
     for (i = 0; i < numFBConfigs; i++) {
         int associatedVisualId = 0;
@@ -3021,7 +3017,7 @@ __glXGetFBConfigs(__GLXclientState * cl, GLbyte * pc)
             __GLX_DECLARE_SWAP_ARRAY_VARIABLES;
             __GLX_SWAP_INT_ARRAY((int *) buf, 2 * numAttribs);
         }
-        WriteToClient(client, 2 * numAttribs * __GLX_SIZE_CARD32, (char *) buf);
+        WriteToClient(client, 2 * numAttribs * __GLX_SIZE_CARD32, buf);
     }
     return Success;
 }
@@ -3218,8 +3214,8 @@ __glXQueryContext(__GLXclientState * cl, GLbyte * pc)
         __glXSwapQueryContextReply(client, &reply, sendBuf);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryContextReply, (char *) &reply);
-        WriteToClient(client, nReplyBytes, (char *) sendBuf);
+        WriteToClient(client, sz_xGLXQueryContextReply, &reply);
+        WriteToClient(client, nReplyBytes, sendBuf);
     }
     free((char *) sendBuf);
 
@@ -3270,8 +3266,8 @@ __glXQueryContextInfoEXT(__GLXclientState * cl, GLbyte * pc)
         __glXSwapQueryContextInfoEXTReply(client, &reply, sendBuf);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, (char *) &reply);
-        WriteToClient(client, nReplyBytes, (char *) sendBuf);
+        WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, &reply);
+        WriteToClient(client, nReplyBytes, sendBuf);
     }
     free((char *) sendBuf);
 
@@ -3606,9 +3602,8 @@ __glXGetDrawableAttributes(__GLXclientState * cl, GLbyte * pc)
         __glXSwapGetDrawableAttributesReply(client, &reply, (int *) attribs);
     }
     else {
-        WriteToClient(client, sz_xGLXGetDrawableAttributesReply,
-                      (char *) &reply);
-        WriteToClient(client, attribs_size, (char *) attribs);
+        WriteToClient(client, sz_xGLXGetDrawableAttributesReply, &reply);
+        WriteToClient(client, attribs_size, attribs);
     }
 
     free(attribs);
diff --git a/hw/dmx/glxProxy/glxcmdsswap.c b/hw/dmx/glxProxy/glxcmdsswap.c
index ec0e83d..a11c919 100644
--- a/hw/dmx/glxProxy/glxcmdsswap.c
+++ b/hw/dmx/glxProxy/glxcmdsswap.c
@@ -304,7 +304,7 @@ __glXSwapGetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
     __GLX_SWAP_INT(&reply.length);
     __GLX_SWAP_INT(&reply.numVisuals);
     __GLX_SWAP_INT(&reply.numProps);
-    WriteToClient(client, sz_xGLXGetVisualConfigsReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply);
 
     for (i = 0; i < pGlxScreen->numVisuals; i++) {
         pGlxVisual = &pGlxScreen->pGlxVisual[i];
@@ -353,8 +353,7 @@ __glXSwapGetVisualConfigs(__GLXclientState * cl, GLbyte * pc)
         buf[p++] = pGlxVisual->transparentIndex;
 
         __GLX_SWAP_INT_ARRAY(buf, __GLX_TOTAL_CONFIG);
-        WriteToClient(client, __GLX_SIZE_CARD32 * __GLX_TOTAL_CONFIG,
-                      (char *) buf);
+        WriteToClient(client, __GLX_SIZE_CARD32 * __GLX_TOTAL_CONFIG, buf);
     }
     return Success;
 }
@@ -508,7 +507,7 @@ __glXSwapMakeCurrentReply(ClientPtr client, xGLXMakeCurrentReadSGIReply * reply)
     __GLX_SWAP_INT(&reply->writeType);
     __GLX_SWAP_INT(&reply->readVid);
     __GLX_SWAP_INT(&reply->readType);
-    WriteToClient(client, sz_xGLXMakeCurrentReadSGIReply, (char *) reply);
+    WriteToClient(client, sz_xGLXMakeCurrentReadSGIReply, reply);
 }
 
 void
@@ -517,7 +516,7 @@ __glXSwapIsDirectReply(ClientPtr client, xGLXIsDirectReply * reply)
     __GLX_DECLARE_SWAP_VARIABLES;
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
-    WriteToClient(client, sz_xGLXIsDirectReply, (char *) reply);
+    WriteToClient(client, sz_xGLXIsDirectReply, reply);
 }
 
 void
@@ -528,7 +527,7 @@ __glXSwapQueryVersionReply(ClientPtr client, xGLXQueryVersionReply * reply)
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->majorVersion);
     __GLX_SWAP_INT(&reply->minorVersion);
-    WriteToClient(client, sz_xGLXQueryVersionReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryVersionReply, reply);
 }
 
 void
@@ -543,7 +542,7 @@ glxSwapQueryExtensionsStringReply(ClientPtr client,
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
-    WriteToClient(client, sz_xGLXQueryExtensionsStringReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryExtensionsStringReply, reply);
     __GLX_SWAP_INT_ARRAY((int *) buf, length);
     WriteToClient(client, length << 2, buf);
 }
@@ -558,7 +557,7 @@ glxSwapQueryServerStringReply(ClientPtr client,
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
-    WriteToClient(client, sz_xGLXQueryServerStringReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryServerStringReply, reply);
     /** no swap is needed for an array of chars **/
     /* __GLX_SWAP_INT_ARRAY((int *)buf, length); */
     WriteToClient(client, length << 2, buf);
@@ -576,9 +575,9 @@ __glXSwapQueryContextInfoEXTReply(ClientPtr client,
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
-    WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryContextInfoEXTReply, reply);
     __GLX_SWAP_INT_ARRAY((int *) buf, length);
-    WriteToClient(client, length << 2, (char *) buf);
+    WriteToClient(client, length << 2, buf);
 }
 
 void
@@ -592,9 +591,9 @@ __glXSwapQueryContextReply(ClientPtr client,
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->n);
-    WriteToClient(client, sz_xGLXQueryContextReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryContextReply, reply);
     __GLX_SWAP_INT_ARRAY((int *) buf, length);
-    WriteToClient(client, length << 2, (char *) buf);
+    WriteToClient(client, length << 2, buf);
 }
 
 void
@@ -608,8 +607,8 @@ __glXSwapGetDrawableAttributesReply(ClientPtr client,
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->numAttribs);
     __GLX_SWAP_INT_ARRAY(buf, reply->length);
-    WriteToClient(client, sz_xGLXGetDrawableAttributesReply, (char *) reply);
-    WriteToClient(client, reply->length << 2, (char *) buf);
+    WriteToClient(client, sz_xGLXGetDrawableAttributesReply, reply);
+    WriteToClient(client, reply->length << 2, buf);
 }
 
 void
@@ -621,7 +620,7 @@ __glXSwapQueryMaxSwapBarriersSGIXReply(ClientPtr client,
     __GLX_SWAP_SHORT(&reply->sequenceNumber);
     __GLX_SWAP_INT(&reply->length);
     __GLX_SWAP_INT(&reply->max);
-    WriteToClient(client, sz_xGLXQueryMaxSwapBarriersSGIXReply, (char *) reply);
+    WriteToClient(client, sz_xGLXQueryMaxSwapBarriersSGIXReply, reply);
 }
 
 /************************************************************************/
diff --git a/hw/dmx/glxProxy/glxsingle.c b/hw/dmx/glxProxy/glxsingle.c
index 63786cf..2253060 100644
--- a/hw/dmx/glxProxy/glxsingle.c
+++ b/hw/dmx/glxProxy/glxsingle.c
@@ -147,9 +147,9 @@ SendSwappedReply(ClientPtr client,
 
     }
 
-    WriteToClient(client, sizeof(xGLXSingleReply), (char *) reply);
+    WriteToClient(client, sizeof(xGLXSingleReply), reply);
     if (buf_size > 0)
-        WriteToClient(client, buf_size, (char *) buf);
+        WriteToClient(client, buf_size, buf);
 
 }
 
@@ -281,9 +281,9 @@ __glXForwardPipe0WithReply(__GLXclientState * cl, GLbyte * pc)
         SendSwappedReply(client, &reply, be_buf, be_buf_size);
     }
     else {
-        WriteToClient(client, sizeof(xGLXSingleReply), (char *) &reply);
+        WriteToClient(client, sizeof(xGLXSingleReply), &reply);
         if (be_buf_size > 0)
-            WriteToClient(client, be_buf_size, (char *) be_buf);
+            WriteToClient(client, be_buf_size, be_buf);
     }
 
     if (be_buf_size > 0)
@@ -383,9 +383,9 @@ __glXForwardAllWithReply(__GLXclientState * cl, GLbyte * pc)
         SendSwappedReply(client, &reply, be_buf, be_buf_size);
     }
     else {
-        WriteToClient(client, sizeof(xGLXSingleReply), (char *) &reply);
+        WriteToClient(client, sizeof(xGLXSingleReply), &reply);
         if (be_buf_size > 0)
-            WriteToClient(client, be_buf_size, (char *) be_buf);
+            WriteToClient(client, be_buf_size, be_buf);
     }
 
     if (be_buf_size > 0)
@@ -1013,9 +1013,9 @@ __glXDisp_ReadPixels(__GLXclientState * cl, GLbyte * pc)
         __GLX_SWAP_INT(&reply.length);
     }
 
-    WriteToClient(client, sizeof(xGLXReadPixelsReply), (char *) &reply);
+    WriteToClient(client, sizeof(xGLXReadPixelsReply), &reply);
     if (buf_size > 0) {
-        WriteToClient(client, buf_size, (char *) buf);
+        WriteToClient(client, buf_size, buf);
         free(buf);
     }
 
diff --git a/hw/dmx/glxProxy/glxvendor.c b/hw/dmx/glxProxy/glxvendor.c
index 963c92e..e5c8da1 100644
--- a/hw/dmx/glxProxy/glxvendor.c
+++ b/hw/dmx/glxProxy/glxvendor.c
@@ -138,9 +138,9 @@ SendSwappedReply(ClientPtr client,
 
     }
 
-    WriteToClient(client, sizeof(xGLXVendorPrivReply), (char *) reply);
+    WriteToClient(client, sizeof(xGLXVendorPrivReply), reply);
     if (buf_size > 0)
-        WriteToClient(client, buf_size, (char *) buf);
+        WriteToClient(client, buf_size, buf);
 
 }
 
@@ -265,9 +265,9 @@ __glXVForwardPipe0WithReply(__GLXclientState * cl, GLbyte * pc)
         SendSwappedReply(client, &reply, be_buf, be_buf_size);
     }
     else {
-        WriteToClient(client, sizeof(xGLXVendorPrivReply), (char *) &reply);
+        WriteToClient(client, sizeof(xGLXVendorPrivReply), &reply);
         if (be_buf_size > 0)
-            WriteToClient(client, be_buf_size, (char *) be_buf);
+            WriteToClient(client, be_buf_size, be_buf);
     }
 
     if (be_buf_size > 0)
@@ -364,9 +364,9 @@ __glXVForwardAllWithReply(__GLXclientState * cl, GLbyte * pc)
         SendSwappedReply(client, &reply, be_buf, be_buf_size);
     }
     else {
-        WriteToClient(client, sizeof(xGLXVendorPrivReply), (char *) &reply);
+        WriteToClient(client, sizeof(xGLXVendorPrivReply), &reply);
         if (be_buf_size > 0)
-            WriteToClient(client, be_buf_size, (char *) be_buf);
+            WriteToClient(client, be_buf_size, be_buf);
     }
 
     if (be_buf_size > 0)
diff --git a/hw/dmx/glxProxy/unpack.h b/hw/dmx/glxProxy/unpack.h
index b4b7358..45c27c6 100644
--- a/hw/dmx/glxProxy/unpack.h
+++ b/hw/dmx/glxProxy/unpack.h
@@ -59,7 +59,7 @@ extern xGLXSingleReply __glXReply;
   	__glXReply.sequenceNumber = client->sequence;
 
 #define __GLX_SEND_HEADER() \
-	WriteToClient( client, sz_xGLXSingleReply, (char *)&__glXReply);
+	WriteToClient (client, sz_xGLXSingleReply, &__glXReply);
 
 #define __GLX_PUT_RETVAL(a) \
   	__glXReply.retval = (a);
@@ -112,19 +112,19 @@ extern xGLXSingleReply __glXReply;
   	*(GLdouble *)&__glXReply.pad3 = *(GLdouble *)answer
 
 #define __GLX_SEND_BYTE_ARRAY(len) \
-	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), (char *)answer)
+	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT8), answer)
 
 #define __GLX_SEND_SHORT_ARRAY(len) \
-	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), (char *)answer)
+	WriteToClient(client, __GLX_PAD((len)*__GLX_SIZE_INT16), answer)
 
 #define __GLX_SEND_INT_ARRAY(len) \
-	WriteToClient(client, (len)*__GLX_SIZE_INT32, (char *)answer)
+	WriteToClient(client, (len)*__GLX_SIZE_INT32, answer)
 
 #define __GLX_SEND_FLOAT_ARRAY(len) \
-	WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, (char *)answer)
+	WriteToClient(client, (len)*__GLX_SIZE_FLOAT32, answer)
 
 #define __GLX_SEND_DOUBLE_ARRAY(len) \
-	WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, (char *)answer)
+	WriteToClient(client, (len)*__GLX_SIZE_FLOAT64, answer)
 
 #define __GLX_SEND_VOID_ARRAY(len)  __GLX_SEND_BYTE_ARRAY(len)
 #define __GLX_SEND_UBYTE_ARRAY(len)  __GLX_SEND_BYTE_ARRAY(len)
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index 28486f5..aefbcfb 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -536,7 +536,7 @@ ProcXF86DRIQueryVersion(register ClientPtr client)
         swaps(&rep.minorVersion);
         swapl(&rep.patchVersion);
     }
-    WriteToClient(client, sizeof(xXF86DRIQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIQueryVersionReply), &rep);
     EPHYR_LOG("leave\n");
     return Success;
 }
@@ -574,7 +574,7 @@ ProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client)
     }
 
     WriteToClient(client, sizeof(xXF86DRIQueryDirectRenderingCapableReply),
-                  (char *) &rep);
+                  &rep);
     EPHYR_LOG("leave\n");
 
     return Success;
@@ -617,7 +617,7 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
     rep.hSAREAHigh = 0;
 #endif
 
-    WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), &rep);
     if (rep.busIdStringLength)
         WriteToClient(client, rep.busIdStringLength, busIdString);
     free(busIdString);
@@ -648,7 +648,7 @@ ProcXF86DRIAuthConnection(register ClientPtr client)
         ErrorF("Failed to authenticate %lu\n", (unsigned long) stuff->magic);
         rep.authenticated = 0;
     }
-    WriteToClient(client, sizeof(xXF86DRIAuthConnectionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIAuthConnectionReply), &rep);
     EPHYR_LOG("leave\n");
     return Success;
 }
@@ -702,8 +702,7 @@ ProcXF86DRIGetClientDriverName(register ClientPtr client)
                                 SIZEOF(xGenericReply) +
                                 pad_to_int32(rep.clientDriverNameLength));
 
-    WriteToClient(client,
-                  sizeof(xXF86DRIGetClientDriverNameReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIGetClientDriverNameReply), &rep);
     if (rep.clientDriverNameLength)
         WriteToClient(client, rep.clientDriverNameLength, clientDriverName);
     EPHYR_LOG("leave\n");
@@ -752,7 +751,7 @@ ProcXF86DRICreateContext(register ClientPtr client)
         return BadValue;
     }
 
-    WriteToClient(client, sizeof(xXF86DRICreateContextReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRICreateContextReply), &rep);
     EPHYR_LOG("leave\n");
     return Success;
 }
@@ -974,7 +973,7 @@ ProcXF86DRICreateDrawable(ClientPtr client)
         EPHYR_LOG("paired window '%p' with remote '%d'\n", window, remote_win);
     }
 
-    WriteToClient(client, sizeof(xXF86DRICreateDrawableReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRICreateDrawableReply), &rep);
     EPHYR_LOG("leave\n");
     return Success;
 }
@@ -1136,18 +1135,18 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client)
 
     rep.length = bytes_to_int32(rep.length);
 
-    WriteToClient(client, sizeof(xXF86DRIGetDrawableInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIGetDrawableInfoReply), &rep);
 
     if (rep.numClipRects) {
         WriteToClient(client,
                       sizeof(drm_clip_rect_t) * rep.numClipRects,
-                      (char *) clipRects);
+                      clipRects);
     }
 
     if (rep.numBackClipRects) {
         WriteToClient(client,
                       sizeof(drm_clip_rect_t) * rep.numBackClipRects,
-                      (char *) backClipRects);
+                      backClipRects);
     }
     free(clipRects);
     clipRects = NULL;
@@ -1200,9 +1199,9 @@ ProcXF86DRIGetDeviceInfo(register ClientPtr client)
                                     pad_to_int32(rep.devPrivateSize));
     }
 
-    WriteToClient(client, sizeof(xXF86DRIGetDeviceInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIGetDeviceInfoReply), &rep);
     if (rep.length) {
-        WriteToClient(client, rep.devPrivateSize, (char *) pDevPrivate);
+        WriteToClient(client, rep.devPrivateSize, pDevPrivate);
     }
     EPHYR_LOG("leave\n");
     return Success;
diff --git a/hw/kdrive/ephyr/ephyrglxext.c b/hw/kdrive/ephyr/ephyrglxext.c
index dab028b..1287e04 100644
--- a/hw/kdrive/ephyr/ephyrglxext.c
+++ b/hw/kdrive/ephyr/ephyrglxext.c
@@ -169,7 +169,7 @@ ephyrGLXQueryVersion(__GLXclientState * a_cl, GLbyte * a_pc)
         __glXSwapQueryVersionReply(client, &reply);
     }
     else {
-        WriteToClient(client, sz_xGLXQueryVersionReply, (char *) &reply);
+        WriteToClient(client, sz_xGLXQueryVersionReply, &reply);
     }
 
     res = Success;
@@ -228,7 +228,7 @@ ephyrGLXGetVisualConfigsReal(__GLXclientState * a_cl,
         __GLX_SWAP_INT(&reply.numProps);
         __GLX_SWAP_INT_ARRAY(props_buf, num_props);
     }
-    WriteToClient(client, sz_xGLXGetVisualConfigsReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply);
     props_per_visual_size = props_buf_size / num_visuals;
     for (i = 0; i < num_visuals; i++) {
         WriteToClient(client,
@@ -282,7 +282,7 @@ ephyrGLXGetFBConfigsSGIXReal(__GLXclientState * a_cl,
         __GLX_SWAP_INT(&reply.numProps);
         __GLX_SWAP_INT_ARRAY(props_buf, num_props);
     }
-    WriteToClient(client, sz_xGLXGetVisualConfigsReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXGetVisualConfigsReply, &reply);
     props_per_visual_size = props_buf_size / num_visuals;
     for (i = 0; i < num_visuals; i++) {
         WriteToClient(client,
@@ -375,7 +375,7 @@ ephyrGLXQueryServerString(__GLXclientState * a_cl, GLbyte * a_pc)
     }
     memcpy(buf, server_string, length);
 
-    WriteToClient(client, sz_xGLXQueryServerStringReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXQueryServerStringReply, &reply);
     WriteToClient(client, (int) (reply.length << 2), server_string);
 
     res = Success;
@@ -538,7 +538,7 @@ ephyrGLXMakeCurrentReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
         __GLX_SWAP_INT(&reply.length);
         __GLX_SWAP_INT(&reply.contextTag);
     }
-    WriteToClient(a_cl->client, sz_xGLXMakeCurrentReply, (char *) &reply);
+    WriteToClient(a_cl->client, sz_xGLXMakeCurrentReply, &reply);
 
     res = Success;
  out:
@@ -601,7 +601,7 @@ ephyrGLXGetStringReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
         __GLX_SWAP_REPLY_SIZE();
         __GLX_SWAP_REPLY_HEADER();
     }
-    WriteToClient(client, length, (char *) string);
+    WriteToClient(client, length, string);
 
     res = Success;
  out:
@@ -690,7 +690,7 @@ ephyrGLXIsDirectReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap)
     reply.length = 0;
     reply.type = X_Reply;
     reply.sequenceNumber = client->sequence;
-    WriteToClient(client, sz_xGLXIsDirectReply, (char *) &reply);
+    WriteToClient(client, sz_xGLXIsDirectReply, &reply);
     res = Success;
 
  out:
diff --git a/hw/kdrive/ephyr/ephyrproxyext.c b/hw/kdrive/ephyr/ephyrproxyext.c
index 3d86d2d..c24238c 100644
--- a/hw/kdrive/ephyr/ephyrproxyext.c
+++ b/hw/kdrive/ephyr/ephyrproxyext.c
@@ -75,7 +75,7 @@ ephyrProxyProcDispatch(ClientPtr a_client)
     reply.sequence_number = a_client->sequence;
     res = Success;
 
-    WriteToClient(a_client, 32, (char *) &reply);
+    WriteToClient(a_client, 32, &reply);
 
  out:
     return res;
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 6b33941..1ed6a50 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -84,7 +84,7 @@ ProcXDGAQueryVersion(ClientPtr client)
     rep.majorVersion = SERVER_XDGA_MAJOR_VERSION;
     rep.minorVersion = SERVER_XDGA_MINOR_VERSION;
 
-    WriteToClient(client, sizeof(xXDGAQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXDGAQueryVersionReply), &rep);
     return Success;
 }
 
@@ -117,7 +117,7 @@ ProcXDGAOpenFramebuffer(ClientPtr client)
     nameSize = deviceName ? (strlen(deviceName) + 1) : 0;
     rep.length = bytes_to_int32(nameSize);
 
-    WriteToClient(client, sizeof(xXDGAOpenFramebufferReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXDGAOpenFramebufferReply), &rep);
     if (rep.length)
         WriteToClient(client, nameSize, deviceName);
 
@@ -164,12 +164,12 @@ ProcXDGAQueryModes(ClientPtr client)
     if (!DGAAvailable(stuff->screen)) {
         rep.number = 0;
         rep.length = 0;
-        WriteToClient(client, sz_xXDGAQueryModesReply, (char *) &rep);
+        WriteToClient(client, sz_xXDGAQueryModesReply, &rep);
         return Success;
     }
 
     if (!(num = DGAGetModes(stuff->screen))) {
-        WriteToClient(client, sz_xXDGAQueryModesReply, (char *) &rep);
+        WriteToClient(client, sz_xXDGAQueryModesReply, &rep);
         return Success;
     }
 
@@ -186,7 +186,7 @@ ProcXDGAQueryModes(ClientPtr client)
     rep.number = num;
     rep.length = bytes_to_int32(size);
 
-    WriteToClient(client, sz_xXDGAQueryModesReply, (char *) &rep);
+    WriteToClient(client, sz_xXDGAQueryModesReply, &rep);
 
     for (i = 0; i < num; i++) {
         size = strlen(mode[i].name) + 1;
@@ -218,7 +218,7 @@ ProcXDGAQueryModes(ClientPtr client)
         info.reserved1 = mode[i].reserved1;
         info.reserved2 = mode[i].reserved2;
 
-        WriteToClient(client, sz_xXDGAModeInfo, (char *) (&info));
+        WriteToClient(client, sz_xXDGAModeInfo, (&info));
         WriteToClient(client, size, mode[i].name);
     }
 
@@ -293,7 +293,7 @@ ProcXDGASetMode(ClientPtr client)
         DGA_SETCLIENT(stuff->screen, NULL);
         DGASelectInput(stuff->screen, NULL, 0);
         DGASetMode(stuff->screen, 0, &mode, &pPix);
-        WriteToClient(client, sz_xXDGASetModeReply, (char *) &rep);
+        WriteToClient(client, sz_xXDGASetModeReply, &rep);
         return Success;
     }
 
@@ -345,8 +345,8 @@ ProcXDGASetMode(ClientPtr client)
 
     rep.length = bytes_to_int32(sz_xXDGAModeInfo + info.name_size);
 
-    WriteToClient(client, sz_xXDGASetModeReply, (char *) &rep);
-    WriteToClient(client, sz_xXDGAModeInfo, (char *) (&info));
+    WriteToClient(client, sz_xXDGASetModeReply, &rep);
+    WriteToClient(client, sz_xXDGAModeInfo, (&info));
     WriteToClient(client, size, mode.name);
 
     return Success;
@@ -494,7 +494,7 @@ ProcXDGAGetViewportStatus(ClientPtr client)
 
     rep.status = DGAGetViewportStatus(stuff->screen);
 
-    WriteToClient(client, sizeof(xXDGAGetViewportStatusReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXDGAGetViewportStatusReply), &rep);
     return Success;
 }
 
@@ -517,7 +517,7 @@ ProcXDGASync(ClientPtr client)
 
     DGASync(stuff->screen);
 
-    WriteToClient(client, sizeof(xXDGASyncReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXDGASyncReply), &rep);
     return Success;
 }
 
@@ -568,7 +568,7 @@ ProcXDGAChangePixmapMode(ClientPtr client)
 
     rep.x = x;
     rep.y = y;
-    WriteToClient(client, sizeof(xXDGAChangePixmapModeReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXDGAChangePixmapModeReply), &rep);
 
     return Success;
 }
@@ -641,7 +641,7 @@ ProcXF86DGAGetVideoLL(ClientPtr client)
     rep.width = mode.bytesPerScanline / (mode.bitsPerPixel >> 3);
     rep.ram_size = rep.bank_size >> 10;
 
-    WriteToClient(client, SIZEOF(xXF86DGAGetVideoLLReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xXF86DGAGetVideoLLReply), &rep);
     return Success;
 }
 
@@ -732,7 +732,7 @@ ProcXF86DGAGetViewPortSize(ClientPtr client)
     rep.width = mode.viewportWidth;
     rep.height = mode.viewportHeight;
 
-    WriteToClient(client, SIZEOF(xXF86DGAGetViewPortSizeReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xXF86DGAGetViewPortSizeReply), &rep);
     return Success;
 }
 
@@ -777,7 +777,7 @@ ProcXF86DGAGetVidPage(ClientPtr client)
     rep.sequenceNumber = client->sequence;
     rep.vpage = 0;              /* silently fail */
 
-    WriteToClient(client, SIZEOF(xXF86DGAGetVidPageReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xXF86DGAGetVidPageReply), &rep);
     return Success;
 }
 
@@ -844,7 +844,7 @@ ProcXF86DGAQueryDirectVideo(ClientPtr client)
     if (DGAAvailable(stuff->screen))
         rep.flags = XF86DGADirectPresent;
 
-    WriteToClient(client, SIZEOF(xXF86DGAQueryDirectVideoReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xXF86DGAQueryDirectVideoReply), &rep);
     return Success;
 }
 
@@ -870,7 +870,7 @@ ProcXF86DGAViewPortChanged(ClientPtr client)
     rep.sequenceNumber = client->sequence;
     rep.result = 1;
 
-    WriteToClient(client, SIZEOF(xXF86DGAViewPortChangedReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xXF86DGAViewPortChangedReply), &rep);
     return Success;
 }
 
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 68c4b58..bd23dc2 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -296,7 +296,7 @@ ProcXF86VidModeQueryVersion(ClientPtr client)
         swaps(&rep.majorVersion);
         swaps(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xXF86VidModeQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86VidModeQueryVersionReply), &rep);
     return Success;
 }
 
@@ -391,12 +391,10 @@ ProcXF86VidModeGetModeLine(ClientPtr client)
         oldrep.vtotal = rep.vtotal;
         oldrep.flags = rep.flags;
         oldrep.privsize = rep.privsize;
-        WriteToClient(client, sizeof(xXF86OldVidModeGetModeLineReply),
-                      (char *) &oldrep);
+        WriteToClient(client, sizeof(xXF86OldVidModeGetModeLineReply), &oldrep);
     }
     else {
-        WriteToClient(client, sizeof(xXF86VidModeGetModeLineReply),
-                      (char *) &rep);
+        WriteToClient(client, sizeof(xXF86VidModeGetModeLineReply), &rep);
     }
     return Success;
 }
@@ -443,8 +441,7 @@ ProcXF86VidModeGetAllModeLines(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.modecount);
     }
-    WriteToClient(client, sizeof(xXF86VidModeGetAllModeLinesReply),
-                  (char *) &rep);
+    WriteToClient(client, sizeof(xXF86VidModeGetAllModeLinesReply), &rep);
 
     do {
         mdinf.dotclock = dotClock;
@@ -485,12 +482,10 @@ ProcXF86VidModeGetAllModeLines(ClientPtr client)
             oldmdinf.vtotal = mdinf.vtotal;
             oldmdinf.flags = mdinf.flags;
             oldmdinf.privsize = mdinf.privsize;
-            WriteToClient(client, sizeof(xXF86OldVidModeModeInfo),
-                          (char *) &oldmdinf);
+            WriteToClient(client, sizeof(xXF86OldVidModeModeInfo), &oldmdinf);
         }
         else {
-            WriteToClient(client, sizeof(xXF86VidModeModeInfo),
-                          (char *) &mdinf);
+            WriteToClient(client, sizeof(xXF86VidModeModeInfo), &mdinf);
         }
 
     } while (VidModeGetNextModeline(stuff->screen, &mode, &dotClock));
@@ -1040,8 +1035,7 @@ ProcXF86VidModeValidateModeLine(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.status);
     }
-    WriteToClient(client, sizeof(xXF86VidModeValidateModeLineReply),
-                  (char *) &rep);
+    WriteToClient(client, sizeof(xXF86VidModeValidateModeLineReply), &rep);
     if (xf86GetVerbosity() > DEFAULT_XF86VIDMODE_VERBOSITY)
         ErrorF("ValidateModeLine - Succeeded (status = %d)\n", status);
     return Success;
@@ -1262,20 +1256,16 @@ ProcXF86VidModeGetMonitor(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
     }
-    WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xXF86VidModeGetMonitorReply), &rep);
     client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
     WriteSwappedDataToClient(client, nHsync * sizeof(CARD32), hsyncdata);
     WriteSwappedDataToClient(client, nVrefresh * sizeof(CARD32), vsyncdata);
     if (rep.vendorLength)
         WriteToClient(client, rep.vendorLength,
-                      (char
-                       *) (VidModeGetMonitorValue(monitor, VIDMODE_MON_VENDOR,
-                                                  0)).ptr);
+                 (VidModeGetMonitorValue(monitor, VIDMODE_MON_VENDOR, 0)).ptr);
     if (rep.modelLength)
         WriteToClient(client, rep.modelLength,
-                      (char
-                       *) (VidModeGetMonitorValue(monitor, VIDMODE_MON_MODEL,
-                                                  0)).ptr);
+                 (VidModeGetMonitorValue(monitor, VIDMODE_MON_MODEL, 0)).ptr);
 
     free(hsyncdata);
     free(vsyncdata);
@@ -1311,7 +1301,7 @@ ProcXF86VidModeGetViewPort(ClientPtr client)
         swapl(&rep.x);
         swapl(&rep.y);
     }
-    WriteToClient(client, SIZEOF(xXF86VidModeGetViewPortReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xXF86VidModeGetViewPortReply), &rep);
     return Success;
 }
 
@@ -1380,7 +1370,7 @@ ProcXF86VidModeGetDotClocks(ClientPtr client)
         swapl(&rep.maxclocks);
         swapl(&rep.flags);
     }
-    WriteToClient(client, sizeof(xXF86VidModeGetDotClocksReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86VidModeGetDotClocksReply), &rep);
     if (!ClockProg) {
         for (n = 0; n < numClocks; n++) {
             dotclock = *Clocks++;
@@ -1388,7 +1378,7 @@ ProcXF86VidModeGetDotClocks(ClientPtr client)
                 WriteSwappedDataToClient(client, 4, (char *) &dotclock);
             }
             else {
-                WriteToClient(client, 4, (char *) &dotclock);
+                WriteToClient(client, 4, &dotclock);
             }
         }
     }
@@ -1446,7 +1436,7 @@ ProcXF86VidModeGetGamma(ClientPtr client)
         swapl(&rep.green);
         swapl(&rep.blue);
     }
-    WriteToClient(client, sizeof(xXF86VidModeGetGammaReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86VidModeGetGammaReply), &rep);
 
     return Success;
 }
@@ -1520,10 +1510,10 @@ ProcXF86VidModeGetGammaRamp(ClientPtr client)
         swaps(&rep.size);
         SwapShorts((short *) ramp, length * 3);
     }
-    WriteToClient(client, sizeof(xXF86VidModeGetGammaRampReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86VidModeGetGammaRampReply), &rep);
 
     if (stuff->size) {
-        WriteToClient(client, ramplen, (char *) ramp);
+        WriteToClient(client, ramplen, ramp);
         free(ramp);
     }
 
@@ -1551,8 +1541,7 @@ ProcXF86VidModeGetGammaRampSize(ClientPtr client)
         swapl(&rep.length);
         swaps(&rep.size);
     }
-    WriteToClient(client, sizeof(xXF86VidModeGetGammaRampSizeReply),
-                  (char *) &rep);
+    WriteToClient(client, sizeof(xXF86VidModeGetGammaRampSizeReply), &rep);
 
     return Success;
 }
@@ -1582,8 +1571,7 @@ ProcXF86VidModeGetPermissions(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.permissions);
     }
-    WriteToClient(client, sizeof(xXF86VidModeGetPermissionsReply),
-                  (char *) &rep);
+    WriteToClient(client, sizeof(xXF86VidModeGetPermissionsReply), &rep);
 
     return Success;
 }
diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
index 72ce869..ee7b213 100644
--- a/hw/xfree86/dri/xf86dri.c
+++ b/hw/xfree86/dri/xf86dri.c
@@ -94,7 +94,7 @@ ProcXF86DRIQueryVersion(register ClientPtr client)
         swaps(&rep.minorVersion);
         swapl(&rep.patchVersion);
     }
-    WriteToClient(client, sizeof(xXF86DRIQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIQueryVersionReply), &rep);
     return Success;
 }
 
@@ -131,7 +131,7 @@ ProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client)
 
     WriteToClient(client,
                   sizeof(xXF86DRIQueryDirectRenderingCapableReply),
-                  (char *) &rep);
+                  &rep);
     return Success;
 }
 
@@ -171,7 +171,7 @@ ProcXF86DRIOpenConnection(register ClientPtr client)
     rep.hSAREAHigh = 0;
 #endif
 
-    WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), &rep);
     if (rep.busIdStringLength)
         WriteToClient(client, rep.busIdStringLength, busIdString);
     return Success;
@@ -198,7 +198,7 @@ ProcXF86DRIAuthConnection(register ClientPtr client)
         ErrorF("Failed to authenticate %lu\n", (unsigned long) stuff->magic);
         rep.authenticated = 0;
     }
-    WriteToClient(client, sizeof(xXF86DRIAuthConnectionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIAuthConnectionReply), &rep);
     return Success;
 }
 
@@ -245,8 +245,7 @@ ProcXF86DRIGetClientDriverName(register ClientPtr client)
                                 SIZEOF(xGenericReply) +
                                 pad_to_int32(rep.clientDriverNameLength));
 
-    WriteToClient(client,
-                  sizeof(xXF86DRIGetClientDriverNameReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIGetClientDriverNameReply), &rep);
     if (rep.clientDriverNameLength)
         WriteToClient(client, rep.clientDriverNameLength, clientDriverName);
     return Success;
@@ -277,7 +276,7 @@ ProcXF86DRICreateContext(register ClientPtr client)
         return BadValue;
     }
 
-    WriteToClient(client, sizeof(xXF86DRICreateContextReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRICreateContextReply), &rep);
     return Success;
 }
 
@@ -326,7 +325,7 @@ ProcXF86DRICreateDrawable(ClientPtr client)
         return BadValue;
     }
 
-    WriteToClient(client, sizeof(xXF86DRICreateDrawableReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRICreateDrawableReply), &rep);
     return Success;
 }
 
@@ -444,19 +443,19 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client)
 
     rep.length = bytes_to_int32(rep.length);
 
-    WriteToClient(client, sizeof(xXF86DRIGetDrawableInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIGetDrawableInfoReply), &rep);
 
     if (rep.numClipRects) {
         WriteToClient(client,
                       sizeof(drm_clip_rect_t) * rep.numClipRects,
-                      (char *) pClippedRects);
+                      pClippedRects);
         free(pClippedRects);
     }
 
     if (rep.numBackClipRects) {
         WriteToClient(client,
                       sizeof(drm_clip_rect_t) * rep.numBackClipRects,
-                      (char *) pBackClipRects);
+                      pBackClipRects);
     }
 
     return Success;
@@ -503,9 +502,9 @@ ProcXF86DRIGetDeviceInfo(register ClientPtr client)
                                     pad_to_int32(rep.devPrivateSize));
     }
 
-    WriteToClient(client, sizeof(xXF86DRIGetDeviceInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXF86DRIGetDeviceInfoReply), &rep);
     if (rep.length) {
-        WriteToClient(client, rep.devPrivateSize, (char *) pDevPrivate);
+        WriteToClient(client, rep.devPrivateSize, pDevPrivate);
     }
     return Success;
 }
diff --git a/hw/xquartz/applewm.c b/hw/xquartz/applewm.c
index 81db13e..d41a81d 100644
--- a/hw/xquartz/applewm.c
+++ b/hw/xquartz/applewm.c
@@ -157,7 +157,7 @@ ProcAppleWMQueryVersion(register ClientPtr client)
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
     }
-    WriteToClient(client, sizeof(xAppleWMQueryVersionReply), (char *)&rep);
+    WriteToClient(client, sizeof(xAppleWMQueryVersionReply),&rep);
     return Success;
 }
 
@@ -533,7 +533,7 @@ ProcAppleWMFrameGetRect(register ClientPtr client)
     rep.w = rr.x2 - rr.x1;
     rep.h = rr.y2 - rr.y1;
 
-    WriteToClient(client, sizeof(xAppleWMFrameGetRectReply), (char *)&rep);
+    WriteToClient(client, sizeof(xAppleWMFrameGetRectReply),&rep);
     return Success;
 }
 
@@ -560,7 +560,7 @@ ProcAppleWMFrameHitTest(register ClientPtr client)
 
     rep.ret = ret;
 
-    WriteToClient(client, sizeof(xAppleWMFrameHitTestReply), (char *)&rep);
+    WriteToClient(client, sizeof(xAppleWMFrameHitTestReply),&rep);
     return Success;
 }
 
diff --git a/hw/xquartz/pseudoramiX.c b/hw/xquartz/pseudoramiX.c
index 8bb7f2d..c146687 100644
--- a/hw/xquartz/pseudoramiX.c
+++ b/hw/xquartz/pseudoramiX.c
@@ -216,7 +216,7 @@ ProcPseudoramiXGetState(ClientPtr client)
         swapl(&rep.length);
         swaps(&rep.state);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetStateReply), (char *)&rep);
+    WriteToClient(client, sizeof(xPanoramiXGetStateReply),&rep);
     return Success;
 }
 
@@ -245,7 +245,7 @@ ProcPseudoramiXGetScreenCount(ClientPtr client)
         swapl(&rep.length);
         swaps(&rep.ScreenCount);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), (char *)&rep);
+    WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply),&rep);
     return Success;
 }
 
@@ -279,7 +279,7 @@ ProcPseudoramiXGetScreenSize(ClientPtr client)
         swaps(&rep.width);
         swaps(&rep.height);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), (char *)&rep);
+    WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply),&rep);
     return Success;
 }
 
@@ -303,7 +303,7 @@ ProcPseudoramiXIsActive(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.state);
     }
-    WriteToClient(client, sizeof(xXineramaIsActiveReply), (char *)&rep);
+    WriteToClient(client, sizeof(xXineramaIsActiveReply),&rep);
     return Success;
 }
 
@@ -329,7 +329,7 @@ ProcPseudoramiXQueryScreens(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.number);
     }
-    WriteToClient(client, sizeof(xXineramaQueryScreensReply), (char *)&rep);
+    WriteToClient(client, sizeof(xXineramaQueryScreensReply),&rep);
 
     if (!noPseudoramiXExtension) {
         xXineramaScreenInfo scratch;
@@ -347,7 +347,7 @@ ProcPseudoramiXQueryScreens(ClientPtr client)
                 swaps(&scratch.width);
                 swaps(&scratch.height);
             }
-            WriteToClient(client, sz_XineramaScreenInfo, (char *)&scratch);
+            WriteToClient(client, sz_XineramaScreenInfo,&scratch);
         }
     }
 
diff --git a/hw/xquartz/xpr/appledri.c b/hw/xquartz/xpr/appledri.c
index 1bb8379..f77848f 100644
--- a/hw/xquartz/xpr/appledri.c
+++ b/hw/xquartz/xpr/appledri.c
@@ -105,7 +105,7 @@ ProcAppleDRIQueryVersion(register ClientPtr client)
         swaps(&rep.minorVersion);
         swapl(&rep.patchVersion);
     }
-    WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *)&rep);
+    WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), &rep);
     return Success;
 }
 
@@ -139,7 +139,7 @@ ProcAppleDRIQueryDirectRenderingCapable(register ClientPtr client)
 
     WriteToClient(client,
                   sizeof(xAppleDRIQueryDirectRenderingCapableReply),
-                  (char *)&rep);
+                  &rep);
     return Success;
 }
 
@@ -168,7 +168,7 @@ ProcAppleDRIAuthConnection(register ClientPtr client)
         swapl(&rep.authenticated); /* Yes, this is a CARD32 ... sigh */
     }
 
-    WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *)&rep);
+    WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), &rep);
     return Success;
 }
 
@@ -232,7 +232,7 @@ ProcAppleDRICreateSurface(ClientPtr client)
         swapl(&rep.uid);
     }
 
-    WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *)&rep);
+    WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), &rep);
     return Success;
 }
 
diff --git a/hw/xwin/winwindowswm.c b/hw/xwin/winwindowswm.c
index f67c383..77c997a 100644
--- a/hw/xwin/winwindowswm.c
+++ b/hw/xwin/winwindowswm.c
@@ -95,7 +95,7 @@ ProcWindowsWMQueryVersion(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
     }
-    WriteToClient(client, sizeof(xWindowsWMQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xWindowsWMQueryVersionReply), &rep);
     return Success;
 }
 
@@ -366,7 +366,7 @@ ProcWindowsWMFrameGetRect(ClientPtr client)
            rep.x, rep.y, rep.w, rep.h);
 #endif
 
-    WriteToClient(client, sizeof(xWindowsWMFrameGetRectReply), (char *) &rep);
+    WriteToClient(client, sizeof(xWindowsWMFrameGetRectReply), &rep);
     return Success;
 }
 
diff --git a/include/dix.h b/include/dix.h
index 3d8b0e5..5bc1daa 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -102,12 +102,12 @@ SOFTWARE.
    if ((pClient)->swapped) \
       (*ReplySwapVector[((xReq *)(pClient)->requestBuffer)->reqType]) \
            (pClient, (int)(size), pReply); \
-      else (void) WriteToClient(pClient, (int)(size), (char *)(pReply)); }
+   else WriteToClient(pClient, (int)(size), (pReply)); }
 
 #define WriteSwappedDataToClient(pClient, size, pbuf) \
    if ((pClient)->swapped) \
       (*(pClient)->pSwapReplyFunc)(pClient, (int)(size), pbuf); \
-   else (void) WriteToClient (pClient, (int)(size), (char *)(pbuf));
+   else WriteToClient(pClient, (int)(size), (pbuf));
 
 typedef struct _TimeStamp *TimeStampPtr;
 
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 1a6e593..7616e7c 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -975,9 +975,9 @@ ProcRRGetCrtcInfo(ClientPtr client)
         swaps(&rep.nOutput);
         swaps(&rep.nPossibleOutput);
     }
-    WriteToClient(client, sizeof(xRRGetCrtcInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRGetCrtcInfoReply), &rep);
     if (extraLen) {
-        WriteToClient(client, extraLen, (char *) extra);
+        WriteToClient(client, extraLen, extra);
         free(extra);
     }
 
@@ -1181,7 +1181,7 @@ ProcRRSetCrtcConfig(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.newTimestamp);
     }
-    WriteToClient(client, sizeof(xRRSetCrtcConfigReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRSetCrtcConfigReply), &rep);
 
     return Success;
 }
@@ -1250,7 +1250,7 @@ ProcRRGetPanning(ClientPtr client)
         swaps(&rep.border_right);
         swaps(&rep.border_bottom);
     }
-    WriteToClient(client, sizeof(xRRGetPanningReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRGetPanningReply), &rep);
     return Success;
 }
 
@@ -1318,7 +1318,7 @@ ProcRRSetPanning(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.newTimestamp);
     }
-    WriteToClient(client, sizeof(xRRSetPanningReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRSetPanningReply), &rep);
     return Success;
 }
 
@@ -1345,7 +1345,7 @@ ProcRRGetCrtcGammaSize(ClientPtr client)
         swapl(&reply.length);
         swaps(&reply.size);
     }
-    WriteToClient(client, sizeof(xRRGetCrtcGammaSizeReply), (char *) &reply);
+    WriteToClient(client, sizeof(xRRGetCrtcGammaSizeReply), &reply);
     return Success;
 }
 
@@ -1382,7 +1382,7 @@ ProcRRGetCrtcGamma(ClientPtr client)
         swapl(&reply.length);
         swaps(&reply.size);
     }
-    WriteToClient(client, sizeof(xRRGetCrtcGammaReply), (char *) &reply);
+    WriteToClient(client, sizeof(xRRGetCrtcGammaReply), &reply);
     if (crtc->gammaSize) {
         memcpy(extra, crtc->gammaRed, len);
         client->pSwapReplyFunc = (ReplySwapPtr) CopySwap16Write;
@@ -1548,8 +1548,7 @@ ProcRRGetCrtcTransform(ClientPtr client)
         swaps(&reply->sequenceNumber);
         swapl(&reply->length);
     }
-    WriteToClient(client, sizeof(xRRGetCrtcTransformReply) + nextra,
-                  (char *) reply);
+    WriteToClient(client, sizeof(xRRGetCrtcTransformReply) + nextra, reply);
     free(reply);
     return Success;
 }
diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index 1942d74..d071787 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -63,7 +63,7 @@ ProcRRQueryVersion(ClientPtr client)
         swapl(&rep.majorVersion);
         swapl(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xRRQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRQueryVersionReply), &rep);
     return Success;
 }
 
diff --git a/randr/rrmode.c b/randr/rrmode.c
index 49a45c7..7e17d7d 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -320,7 +320,7 @@ ProcRRCreateMode(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.mode);
     }
-    WriteToClient(client, sizeof(xRRCreateModeReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRCreateModeReply), &rep);
     /* Drop out reference to this mode */
     RRModeDestroy(mode);
     return Success;
diff --git a/randr/rroutput.c b/randr/rroutput.c
index fbd0e32..fd03aab 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -489,9 +489,9 @@ ProcRRGetOutputInfo(ClientPtr client)
         swaps(&rep.nClones);
         swaps(&rep.nameLength);
     }
-    WriteToClient(client, sizeof(xRRGetOutputInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRGetOutputInfoReply), &rep);
     if (extraLen) {
-        WriteToClient(client, extraLen, (char *) extra);
+        WriteToClient(client, extraLen, extra);
         free(extra);
     }
 
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index 75948fc..e8f0578 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -407,7 +407,7 @@ ProcRRListOutputProperties(ClientPtr client)
     for (prop = output->properties; prop; prop = prop->next)
         *temppAtoms++ = prop->propertyName;
 
-    WriteToClient(client, sizeof(xRRListOutputPropertiesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRListOutputPropertiesReply), &rep);
     if (numProps) {
         client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
         WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms);
@@ -448,7 +448,7 @@ ProcRRQueryOutputProperty(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swapl(&rep.length);
     }
-    WriteToClient(client, sizeof(xRRQueryOutputPropertyReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRQueryOutputPropertyReply), &rep);
     if (prop->num_valid) {
         memcpy(extra, prop->valid_values, prop->num_valid * sizeof(INT32));
         client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 9bf9316..ec07bb1 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -228,7 +228,7 @@ ProcRRGetScreenSizeRange(ClientPtr client)
         swaps(&rep.maxWidth);
         swaps(&rep.maxHeight);
     }
-    WriteToClient(client, sizeof(xRRGetScreenSizeRangeReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRGetScreenSizeRangeReply), &rep);
     return Success;
 }
 
@@ -450,9 +450,9 @@ rrGetMultiScreenResources(ClientPtr client, Bool query, ScreenPtr pScreen)
         swaps(&rep.nModes);
         swaps(&rep.nbytesNames);
     }
-    WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRGetScreenResourcesReply), &rep);
     if (extraLen) {
-        WriteToClient(client, extraLen, (char *) extra);
+        WriteToClient(client, extraLen, extra);
         free(extra);
     }
     return Success;
@@ -860,9 +860,9 @@ ProcRRGetScreenInfo(ClientPtr client)
         swaps(&rep.rate);
         swaps(&rep.nrateEnts);
     }
-    WriteToClient(client, sizeof(xRRGetScreenInfoReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRGetScreenInfoReply), &rep);
     if (extraLen) {
-        WriteToClient(client, extraLen, (char *) extra);
+        WriteToClient(client, extraLen, extra);
         free(extra);
     }
     return Success;
@@ -1092,7 +1092,7 @@ ProcRRSetScreenConfig(ClientPtr client)
         swapl(&rep.newConfigTimestamp);
         swapl(&rep.root);
     }
-    WriteToClient(client, sizeof(xRRSetScreenConfigReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRRSetScreenConfigReply), &rep);
 
     return Success;
 }
diff --git a/randr/rrxinerama.c b/randr/rrxinerama.c
index aa8a61e..269a63f 100644
--- a/randr/rrxinerama.c
+++ b/randr/rrxinerama.c
@@ -103,7 +103,7 @@ ProcRRXineramaQueryVersion(ClientPtr client)
         swaps(&rep.majorVersion);
         swaps(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xPanoramiXQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xPanoramiXQueryVersionReply), &rep);
     return Success;
 }
 
@@ -140,7 +140,7 @@ ProcRRXineramaGetState(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.window);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetStateReply), (char *) &rep);
+    WriteToClient(client, sizeof(xPanoramiXGetStateReply), &rep);
     return Success;
 }
 
@@ -194,7 +194,7 @@ ProcRRXineramaGetScreenCount(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.window);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), (char *) &rep);
+    WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), &rep);
     return Success;
 }
 
@@ -230,7 +230,7 @@ ProcRRXineramaGetScreenSize(ClientPtr client)
         swapl(&rep.window);
         swapl(&rep.screen);
     }
-    WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), (char *) &rep);
+    WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), &rep);
     return Success;
 }
 
@@ -251,7 +251,7 @@ ProcRRXineramaIsActive(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.state);
     }
-    WriteToClient(client, sizeof(xXineramaIsActiveReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXineramaIsActiveReply), &rep);
     return Success;
 }
 
@@ -314,7 +314,7 @@ ProcRRXineramaQueryScreens(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.number);
     }
-    WriteToClient(client, sizeof(xXineramaQueryScreensReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXineramaQueryScreensReply), &rep);
 
     if (rep.number) {
         rrScrPriv(pScreen);
diff --git a/record/record.c b/record/record.c
index 8a38118..a3ee4dd 100644
--- a/record/record.c
+++ b/record/record.c
@@ -241,12 +241,12 @@ RecordFlushReplyBuffer(RecordContextPtr pContext,
     ++pContext->inFlush;
     if (pContext->numBufBytes)
         WriteToClient(pContext->pRecordingClient, pContext->numBufBytes,
-                      (char *) pContext->replyBuffer);
+                      pContext->replyBuffer);
     pContext->numBufBytes = 0;
     if (len1)
-        WriteToClient(pContext->pRecordingClient, len1, (char *) data1);
+        WriteToClient(pContext->pRecordingClient, len1, data1);
     if (len2)
-        WriteToClient(pContext->pRecordingClient, len2, (char *) data2);
+        WriteToClient(pContext->pRecordingClient, len2, data2);
     --pContext->inFlush;
 }                               /* RecordFlushReplyBuffer */
 
@@ -1829,8 +1829,7 @@ ProcRecordQueryVersion(ClientPtr client)
         swaps(&rep.majorVersion);
         swaps(&rep.minorVersion);
     }
-    (void) WriteToClient(client, sizeof(xRecordQueryVersionReply),
-                         (char *) &rep);
+    WriteToClient(client, sizeof(xRecordQueryVersionReply), &rep);
     return Success;
 }                               /* ProcRecordQueryVersion */
 
@@ -2240,7 +2239,7 @@ ProcRecordGetContext(ClientPtr client)
         swapl(&rep.length);
         swapl(&rep.nClients);
     }
-    (void) WriteToClient(client, sizeof(xRecordGetContextReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRecordGetContextReply), &rep);
 
     /* write all the CLIENT_INFOs */
 
@@ -2257,9 +2256,9 @@ ProcRecordGetContext(ClientPtr client)
             rci.clientResource = pRCAP->pClientIDs[i];
             if (client->swapped)
                 swapl(&rci.clientResource);
-            WriteToClient(client, sizeof(xRecordClientInfo), (char *) &rci);
+            WriteToClient(client, sizeof(xRecordClientInfo), &rci);
             WriteToClient(client, sizeof(xRecordRange) * pri->nRanges,
-                          (char *) pri->pRanges);
+                          pri->pRanges);
         }
     }
     err = Success;
diff --git a/render/render.c b/render/render.c
index fe7666d..be7d21e 100644
--- a/render/render.c
+++ b/render/render.c
@@ -296,7 +296,7 @@ ProcRenderQueryVersion(ClientPtr client)
         swapl(&rep.majorVersion);
         swapl(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xRenderQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xRenderQueryVersionReply), &rep);
     return Success;
 }
 
@@ -500,7 +500,7 @@ ProcRenderQueryPictFormats(ClientPtr client)
         swapl(&reply->numVisuals);
         swapl(&reply->numSubpixel);
     }
-    WriteToClient(client, rlength, (char *) reply);
+    WriteToClient(client, rlength, reply);
     free(reply);
     return Success;
 }
@@ -557,7 +557,7 @@ ProcRenderQueryPictIndexValues(ClientPtr client)
         swapl(&reply->numIndexValues);
     }
 
-    WriteToClient(client, rlength, (char *) reply);
+    WriteToClient(client, rlength, reply);
     free(reply);
     return Success;
 }
@@ -1748,7 +1748,7 @@ ProcRenderQueryFilters(ClientPtr client)
         swapl(&reply->numAliases);
         swapl(&reply->numFilters);
     }
-    WriteToClient(client, total_bytes, (char *) reply);
+    WriteToClient(client, total_bytes, reply);
     free(reply);
 
     return Success;
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 467529a..79530f9 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -409,8 +409,8 @@ ProcXFixesGetCursorImage(ClientPtr client)
         swapl(&rep->cursorSerial);
         SwapLongs(image, npixels);
     }
-    WriteToClient(client, sizeof(xXFixesGetCursorImageReply) +
-                  (npixels << 2), (char *) rep);
+    WriteToClient(client,
+                  sizeof(xXFixesGetCursorImageReply) + (npixels << 2), rep);
     free(rep);
     return Success;
 }
@@ -565,7 +565,7 @@ ProcXFixesGetCursorImageAndName(ClientPtr client)
         SwapLongs(image, npixels);
     }
     WriteToClient(client, sizeof(xXFixesGetCursorImageAndNameReply) +
-                  (npixels << 2) + nbytesRound, (char *) rep);
+                  (npixels << 2) + nbytesRound, rep);
     free(rep);
     return Success;
 }
diff --git a/xfixes/region.c b/xfixes/region.c
index 0acbada..89675e5 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -584,7 +584,7 @@ ProcXFixesFetchRegion(ClientPtr client)
         swaps(&reply->height);
         SwapShorts((INT16 *) pRect, nBox * 4);
     }
-    (void) WriteToClient(client, sizeof(xXFixesFetchRegionReply) +
+    WriteToClient(client, sizeof(xXFixesFetchRegionReply) +
                          nBox * sizeof(xRectangle), (char *) reply);
     free(reply);
     return Success;
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index f80230f..54f84f4 100644
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -90,7 +90,7 @@ ProcXFixesQueryVersion(ClientPtr client)
         swapl(&rep.majorVersion);
         swapl(&rep.minorVersion);
     }
-    WriteToClient(client, sizeof(xXFixesQueryVersionReply), (char *) &rep);
+    WriteToClient(client, sizeof(xXFixesQueryVersionReply), &rep);
     return Success;
 }
 
diff --git a/xkb/xkb.c b/xkb/xkb.c
index 0bec24f..b21815c 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -193,7 +193,7 @@ ProcXkbUseExtension(ClientPtr client)
         swaps(&rep.serverMajor);
         swaps(&rep.serverMinor);
     }
-    WriteToClient(client, SIZEOF(xkbUseExtensionReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbUseExtensionReply), &rep);
     return Success;
 }
 
@@ -596,7 +596,7 @@ ProcXkbGetState(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swaps(&rep.ptrBtnState);
     }
-    WriteToClient(client, SIZEOF(xkbGetStateReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbGetStateReply), &rep);
     return Success;
 }
 
@@ -741,7 +741,7 @@ ProcXkbGetControls(ClientPtr client)
         swaps(&rep.axtOptsValues);
         swaps(&rep.axOptions);
     }
-    WriteToClient(client, SIZEOF(xkbGetControlsReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbGetControlsReply), &rep);
     return Success;
 }
 
@@ -1433,7 +1433,7 @@ XkbSendMap(ClientPtr client, XkbDescPtr xkb, xkbGetMapReply * rep)
         swaps(&rep->totalSyms);
         swaps(&rep->totalActs);
     }
-    WriteToClient(client, (i = SIZEOF(xkbGetMapReply)), (char *) rep);
+    WriteToClient(client, (i = SIZEOF(xkbGetMapReply)), rep);
     WriteToClient(client, len, start);
     free((char *) start);
     return Success;
@@ -2744,7 +2744,7 @@ XkbSendCompatMap(ClientPtr client,
         swaps(&rep->nTotalSI);
     }
 
-    WriteToClient(client, SIZEOF(xkbGetCompatMapReply), (char *) rep);
+    WriteToClient(client, SIZEOF(xkbGetCompatMapReply), rep);
     if (data) {
         WriteToClient(client, size, data);
         free((char *) data);
@@ -3044,7 +3044,7 @@ ProcXkbGetIndicatorState(ClientPtr client)
         swaps(&rep.sequenceNumber);
         swapl(&rep.state);
     }
-    WriteToClient(client, SIZEOF(xkbGetIndicatorStateReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbGetIndicatorStateReply), &rep);
     return Success;
 }
 
@@ -3118,9 +3118,9 @@ XkbSendIndicatorMap(ClientPtr client,
         swapl(&rep->which);
         swapl(&rep->realIndicators);
     }
-    WriteToClient(client, SIZEOF(xkbGetIndicatorMapReply), (char *) rep);
+    WriteToClient(client, SIZEOF(xkbGetIndicatorMapReply), rep);
     if (map) {
-        WriteToClient(client, length, (char *) map);
+        WriteToClient(client, length, map);
         free((char *) map);
     }
     return Success;
@@ -3343,7 +3343,7 @@ ProcXkbGetNamedIndicator(ClientPtr client)
         swapl(&rep.ctrls);
     }
 
-    WriteToClient(client, SIZEOF(xkbGetNamedIndicatorReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbGetNamedIndicatorReply), &rep);
     return Success;
 }
 
@@ -3857,7 +3857,7 @@ XkbSendNames(ClientPtr client, XkbDescPtr xkb, xkbGetNamesReply * rep)
         ErrorF("[xkb] BOGUS LENGTH in write names, expected %d, got %ld\n",
                length, (unsigned long) (desc - start));
     }
-    WriteToClient(client, SIZEOF(xkbGetNamesReply), (char *) rep);
+    WriteToClient(client, SIZEOF(xkbGetNamesReply), rep);
     WriteToClient(client, length, start);
     free((char *) start);
     return Success;
@@ -4904,7 +4904,7 @@ XkbSendGeometry(ClientPtr client,
         swaps(&rep->nDoodads);
         swaps(&rep->nKeyAliases);
     }
-    WriteToClient(client, SIZEOF(xkbGetGeometryReply), (char *) rep);
+    WriteToClient(client, SIZEOF(xkbGetGeometryReply), rep);
     if (len > 0)
         WriteToClient(client, len, start);
     if (start != NULL)
@@ -5538,7 +5538,7 @@ ProcXkbPerClientFlags(ClientPtr client)
         swapl(&rep.autoCtrls);
         swapl(&rep.autoCtrlValues);
     }
-    WriteToClient(client, SIZEOF(xkbPerClientFlagsReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbPerClientFlagsReply), &rep);
     return Success;
 }
 
@@ -5667,9 +5667,9 @@ ProcXkbListComponents(ClientPtr client)
         swaps(&rep.nGeometries);
         swaps(&rep.extra);
     }
-    WriteToClient(client, SIZEOF(xkbListComponentsReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbListComponentsReply), &rep);
     if (list.nPool && list.pool) {
-        WriteToClient(client, XkbPaddedSize(list.nPool), (char *) list.pool);
+        WriteToClient(client, XkbPaddedSize(list.nPool), list.pool);
         free(list.pool);
         list.pool = NULL;
     }
@@ -5939,7 +5939,7 @@ ProcXkbGetKbdByName(ClientPtr client)
         swaps(&rep.found);
         swaps(&rep.reported);
     }
-    WriteToClient(client, SIZEOF(xkbGetKbdByNameReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbGetKbdByNameReply), &rep);
     if (reported & (XkbGBN_SymbolsMask | XkbGBN_TypesMask))
         XkbSendMap(client, new, &mrep);
     if (reported & XkbGBN_CompatMapMask)
@@ -6136,7 +6136,7 @@ SendDeviceLedInfo(XkbSrvLedInfoPtr sli, ClientPtr client)
         swapl(&wire.physIndicators);
         swapl(&wire.state);
     }
-    WriteToClient(client, SIZEOF(xkbDeviceLedsWireDesc), (char *) &wire);
+    WriteToClient(client, SIZEOF(xkbDeviceLedsWireDesc), &wire);
     length += SIZEOF(xkbDeviceLedsWireDesc);
     if (sli->namesPresent | sli->mapsPresent) {
         register unsigned i, bit;
@@ -6150,7 +6150,7 @@ SendDeviceLedInfo(XkbSrvLedInfoPtr sli, ClientPtr client)
                     if (client->swapped) {
                         swapl(&awire);
                     }
-                    WriteToClient(client, 4, (char *) &awire);
+                    WriteToClient(client, 4, &awire);
                     length += 4;
                 }
             }
@@ -6173,7 +6173,7 @@ SendDeviceLedInfo(XkbSrvLedInfoPtr sli, ClientPtr client)
                         swapl(&iwire.ctrls);
                     }
                     WriteToClient(client, SIZEOF(xkbIndicatorMapWireDesc),
-                                  (char *) &iwire);
+                                  &iwire);
                     length += SIZEOF(xkbIndicatorMapWireDesc);
                 }
             }
@@ -6343,7 +6343,7 @@ ProcXkbGetDeviceInfo(ClientPtr client)
         swaps(&rep.dfltLedFB);
         swapl(&rep.devType);
     }
-    WriteToClient(client, SIZEOF(xkbGetDeviceInfoReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbGetDeviceInfoReply), &rep);
 
     str = malloc(nameLen);
     if (!str)
@@ -6359,7 +6359,7 @@ ProcXkbGetDeviceInfo(ClientPtr client)
 
         sz = rep.nBtnsRtrn * SIZEOF(xkbActionWireDesc);
         awire = (xkbActionWireDesc *) & dev->button->xkb_acts[rep.firstBtnRtrn];
-        WriteToClient(client, sz, (char *) awire);
+        WriteToClient(client, sz, awire);
         length -= sz;
     }
     if (nDeviceLedFBs > 0) {
@@ -6760,7 +6760,7 @@ ProcXkbSetDebuggingFlags(ClientPtr client)
         swapl(&rep.supportedFlags);
         swapl(&rep.supportedCtrls);
     }
-    WriteToClient(client, SIZEOF(xkbSetDebuggingFlagsReply), (char *) &rep);
+    WriteToClient(client, SIZEOF(xkbSetDebuggingFlagsReply), &rep);
     return Success;
 }
 
diff --git a/xkb/xkbEvents.c b/xkb/xkbEvents.c
index d49e4c1..beb09cf 100644
--- a/xkb/xkbEvents.c
+++ b/xkb/xkbEvents.c
@@ -243,7 +243,7 @@ XkbSendStateNotify(DeviceIntPtr kbd, xkbStateNotify * pSN)
                 swaps(&pSN->changed);
                 swaps(&pSN->ptrBtnState);
             }
-            WriteToClient(interest->client, sizeof(xEvent), (char *) pSN);
+            WriteToClient(interest->client, sizeof(xEvent), pSN);
         }
         interest = interest->next;
     }
@@ -416,7 +416,7 @@ XkbSendControlsNotify(DeviceIntPtr kbd, xkbControlsNotify * pCN)
                 swapl(&pCN->enabledControlChanges);
                 swapl(&pCN->time);
             }
-            WriteToClient(interest->client, sizeof(xEvent), (char *) pCN);
+            WriteToClient(interest->client, sizeof(xEvent), pCN);
         }
         interest = interest->next;
     }
@@ -463,7 +463,7 @@ XkbSendIndicatorNotify(DeviceIntPtr kbd, int xkbType, xkbIndicatorNotify * pEv)
                 swapl(&pEv->changed);
                 swapl(&pEv->state);
             }
-            WriteToClient(interest->client, sizeof(xEvent), (char *) pEv);
+            WriteToClient(interest->client, sizeof(xEvent), pEv);
         }
         interest = interest->next;
     }
@@ -550,7 +550,7 @@ XkbHandleBell(BOOL force,
                 swapl(&bn.name);
                 swapl(&bn.window);
             }
-            WriteToClient(interest->client, sizeof(xEvent), (char *) &bn);
+            WriteToClient(interest->client, sizeof(xEvent), &bn);
         }
         interest = interest->next;
     }
@@ -594,7 +594,7 @@ XkbSendAccessXNotify(DeviceIntPtr kbd, xkbAccessXNotify * pEv)
                 swaps(&pEv->slowKeysDelay);
                 swaps(&pEv->debounceDelay);
             }
-            WriteToClient(interest->client, sizeof(xEvent), (char *) pEv);
+            WriteToClient(interest->client, sizeof(xEvent), pEv);
         }
         interest = interest->next;
     }
@@ -642,7 +642,7 @@ XkbSendNamesNotify(DeviceIntPtr kbd, xkbNamesNotify * pEv)
                 swapl(&pEv->changedIndicators);
                 swaps(&pEv->changedVirtualMods);
             }
-            WriteToClient(interest->client, sizeof(xEvent), (char *) pEv);
+            WriteToClient(interest->client, sizeof(xEvent), pEv);
         }
         interest = interest->next;
     }
@@ -689,7 +689,7 @@ XkbSendCompatMapNotify(DeviceIntPtr kbd, xkbCompatMapNotify * pEv)
                 swaps(&pEv->nSI);
                 swaps(&pEv->nTotalSI);
             }
-            WriteToClient(interest->client, sizeof(xEvent), (char *) pEv);
+            WriteToClient(interest->client, sizeof(xEvent), pEv);
         }
         interest = interest->next;
     }
@@ -732,7 +732,7 @@ XkbSendActionMessage(DeviceIntPtr kbd, xkbActionMessage * pEv)
                 swaps(&pEv->sequenceNumber);
                 swapl(&pEv->time);
             }
-            WriteToClient(interest->client, sizeof(xEvent), (char *) pEv);
+            WriteToClient(interest->client, sizeof(xEvent), pEv);
         }
         interest = interest->next;
     }
@@ -786,7 +786,7 @@ XkbSendExtensionDeviceNotify(DeviceIntPtr dev,
                 swaps(&pEv->reason);
                 swaps(&pEv->supported);
             }
-            WriteToClient(interest->client, sizeof(xEvent), (char *) pEv);
+            WriteToClient(interest->client, sizeof(xEvent), pEv);
         }
         interest = interest->next;
     }
commit 023127915e6922bc53e4c768de760d8a4f25c07c
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jul 9 16:34:39 2012 -0700

    Reliably reset signals at server init time
    
    Each DDX currently calls OsReleaseSIGIO in case it was suspended when
    the server regen started. This causes a BUG to occur if SIGIO was
    *not* blocked at that time. Instead of relying on each DDX, make the
    OS layer reliably reset all signal state at server init time, ensuring
    that signals are suitably unblocked and that the various signal state
    counting variables are set back to zero.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 9c31d82..0dedd7c 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1012,7 +1012,6 @@ OsVendorInit(void)
     }
 #endif
 #endif
-    OsReleaseSIGIO();
 
     beenHere = TRUE;
 }
diff --git a/include/os.h b/include/os.h
index 34ca1f5..7701c39 100644
--- a/include/os.h
+++ b/include/os.h
@@ -340,6 +340,9 @@ OsBlockSIGIO(void);
 extern _X_EXPORT void
 OsReleaseSIGIO(void);
 
+extern void
+OsResetSignals(void);
+
 extern _X_EXPORT void
 OsAbort(void)
     _X_NORETURN;
diff --git a/os/osinit.c b/os/osinit.c
index 6cc0401..2eb1f7a 100644
--- a/os/osinit.c
+++ b/os/osinit.c
@@ -288,6 +288,7 @@ OsInit(void)
     }
     TimerInit();
     OsVendorInit();
+    OsResetSignals();
     /*
      * No log file by default.  OsVendorInit() should call LogInit() with the
      * log file name if logging to a file is desired.
diff --git a/os/utils.c b/os/utils.c
index 2537934..82192e8 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1243,6 +1243,19 @@ OsReleaseSignals(void)
 #endif
 }
 
+void
+OsResetSignals(void)
+{
+#ifdef SIG_BLOCK
+    while (BlockedSignalCount > 0)
+        OsReleaseSignals();
+#ifdef SIGIO
+    while (sigio_blocked > 0)
+        OsReleaseSIGIO();
+#endif
+#endif
+}
+
 /*
  * Pending signals may interfere with core dumping. Provide a
  * mechanism to block signals when aborting.
commit d6756e0298e660a0aca58d75bcf79471ce07a634
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jul 9 16:33:11 2012 -0700

    xfree86: In InitOutput, only call OsReleaseSIGIO if OsBlockSIGIO was called
    
    Otherwise, OsReleaseSIGIO will complain, or perhaps something worse
    will happen (if SIGIO actually needs to be blocked here).
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 058d09f..9c31d82 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -401,6 +401,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
     MessageType pix24From = X_DEFAULT;
     Bool pix24Fail = FALSE;
     Bool autoconfig = FALSE;
+    Bool sigio_blocked = FALSE;
     GDevPtr configured_device;
 
     xf86Initialising = TRUE;
@@ -819,6 +820,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
 #endif
             xf86AccessEnter();
             OsBlockSIGIO();
+            sigio_blocked = TRUE;
         }
     }
 
@@ -924,7 +926,8 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
         AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
 
     xf86VGAarbiterWrapFunctions();
-    OsReleaseSIGIO();
+    if (sigio_blocked)
+        OsReleaseSIGIO();
 
     xf86InitOrigins();
 
commit ea8b04507e5464e4817791db516a20cfed2a6724
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jul 9 16:30:24 2012 -0700

    privates: Resize GPU screen-specific privates too
    
    When allocating new global privates, make sure the gpu
    screens get their private offsets updated.
    
    This only affects GPU screens that enumerate before the non-GPU
    screens, which generally requires that the related device be present
    when the system boots so that it can get an earlier DRM filename.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/privates.c b/dix/privates.c
index 740ead7..55b9345 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -317,6 +317,11 @@ grow_screen_specific_set(DevPrivateType type, unsigned bytes)
 
         grow_private_set(&pScreen->screenSpecificPrivates[type], bytes);
     }
+    for (s = 0; s < screenInfo.numGPUScreens; s++) {
+        ScreenPtr       pScreen = screenInfo.gpuscreens[s];
+
+        grow_private_set(&pScreen->screenSpecificPrivates[type], bytes);
+    }
 }
 
 /*
commit d1c639c006526b8cab14dac582508f3f54848967
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jul 9 16:29:04 2012 -0700

    Add 'install-headers' target in the top-level Makefile
    
    This target recursively locates directories with sdk headers and
    installs them all. Useful when you want to build a complete new X
    server and drivers without having to install the X server before the
    drivers are actually working.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Makefile.am b/Makefile.am
index cea140b..9a62853 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -95,3 +95,10 @@ DIST_SUBDIRS = \
 # gross hack
 relink: all
 	$(AM_V_at)$(MAKE) -C hw relink
+
+install-headers: Makefile
+	+find . -name Makefile | while read m; do			\
+		if grep -q install-sdkHEADERS $$m; then			\
+			(cd `dirname "$$m"` && make install-sdkHEADERS)	\
+		fi							\
+	done
commit 329db3292223cccd4887062956622285c45a1523
Author: Dave Airlie <airlied at redhat.com>
Date:   Sat Jul 7 10:10:08 2012 +0100

    dri2/prime: allocate prime id at screen allocation time
    
    Add a static mask of prime id and allocate them at screen time,
    if the driver supports the prime interfaces and is a gpu screen.
    
    This is instead of them changing due to user controlled randr commands,
    as suggested by Keith.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index 87158ff..887ce46 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -51,6 +51,8 @@
 CARD8 dri2_major;               /* version of DRI2 supported by DDX */
 CARD8 dri2_minor;
 
+uint32_t prime_id_allocate_bitmask;
+
 static DevPrivateKeyRec dri2ScreenPrivateKeyRec;
 
 #define dri2ScreenPrivateKey (&dri2ScreenPrivateKeyRec)
@@ -111,6 +113,7 @@ typedef struct _DRI2Screen {
     const char *deviceName;
     int fd;
     unsigned int lastSequence;
+    int prime_id;
 
     DRI2CreateBufferProcPtr CreateBuffer;
     DRI2DestroyBufferProcPtr DestroyBuffer;
@@ -145,16 +148,15 @@ static ScreenPtr
 GetScreenPrime(ScreenPtr master, int prime_id)
 {
     ScreenPtr slave;
-    int i;
-
     if (prime_id == 0 || xorg_list_is_empty(&master->offload_slave_list)) {
         return master;
     }
-    i = 0;
     xorg_list_for_each_entry(slave, &master->offload_slave_list, offload_head) {
-        if (i == (prime_id - 1))
+        DRI2ScreenPtr ds;
+
+        ds = DRI2GetScreen(slave);
+        if (ds->prime_id == prime_id)
             break;
-        i++;
     }
     if (!slave)
         return master;
@@ -1372,6 +1374,22 @@ DRI2ConfigNotify(WindowPtr pWin, int x, int y, int w, int h, int bw,
     return Success;
 }
 
+#define MAX_PRIME DRI2DriverPrimeMask
+static int
+get_prime_id(void)
+{
+    int i;
+    /* start at 1, prime id 0 is just normal driver */
+    for (i = 1; i < MAX_PRIME; i++) {
+         if (prime_id_allocate_bitmask & (1 << i))
+             continue;
+
+         prime_id_allocate_bitmask |= (1 << i);
+         return i;
+    }
+    return -1;
+}
+
 Bool
 DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
 {
@@ -1447,6 +1465,13 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
 
     if (info->version >= 9) {
         ds->CreateBuffer2 = info->CreateBuffer2;
+        if (info->CreateBuffer2 && pScreen->isGPU) {
+            ds->prime_id = get_prime_id();
+            if (ds->prime_id == -1) {
+                free(ds);
+                return FALSE;
+            }
+        }
         ds->DestroyBuffer2 = info->DestroyBuffer2;
         ds->CopyRegion2 = info->CopyRegion2;
     }
@@ -1520,6 +1545,8 @@ DRI2CloseScreen(ScreenPtr pScreen)
 
     pScreen->ConfigNotify = ds->ConfigNotify;
 
+    if (ds->prime_id)
+        prime_id_allocate_bitmask &= ~(1 << ds->prime_id);
     free(ds->driverNames);
     free(ds);
     dixSetPrivate(&pScreen->devPrivates, dri2ScreenPrivateKey, NULL);
commit 30298012162de7f76e8a4c7b0362e98703f80011
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 26 10:20:52 2012 +0100

    dri2: add initial prime support. (v1.2)
    
    This adds the initial prime support for dri2 offload. The main thing is
    when we get a connection from a prime client, we stored the information
    and mark all drawables from that client as prime. We then create all
    buffers for that drawable on the prime device dri2screen.
    
    Then DRI2UpdatePrime is provided which drivers can call to get a shared
    pixmap which they can use as the front buffer. The driver is then
    responsible for doing the back->front copy to the shared buffer.
    
    prime requires a compositing manager be run, but it handles the case where
    a window get un-redirected by allocating a new pixmap and pointing the crtc
    at it while the client is in that state.
    
    Currently prime can't handle pageflipping, so always does straight copy swap,
    
    v1.1: renumber on top of master.
    v1.2: fix auth on top of master.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 1e99179..e0f4cf7 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -929,7 +929,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
         return NULL;
 
     if (!xf86LoaderCheckSymbol("DRI2Connect") ||
-        !DRI2Connect(pScreen, DRI2DriverDRI,
+        !DRI2Connect(serverClient, pScreen, DRI2DriverDRI,
                      &screen->fd, &driverName, &deviceName)) {
         LogMessage(X_INFO,
                    "AIGLX: Screen %d is not DRI2 capable\n", pScreen->myNum);
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index d3b3c73..87158ff 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -45,7 +45,7 @@
 #include "dixstruct.h"
 #include "dri2.h"
 #include "xf86VGAarbiter.h"
-
+#include "damage.h"
 #include "xf86.h"
 
 CARD8 dri2_major;               /* version of DRI2 supported by DDX */
@@ -63,6 +63,17 @@ static DevPrivateKeyRec dri2PixmapPrivateKeyRec;
 
 #define dri2PixmapPrivateKey (&dri2PixmapPrivateKeyRec)
 
+static DevPrivateKeyRec dri2ClientPrivateKeyRec;
+
+#define dri2ClientPrivateKey (&dri2ClientPrivateKeyRec)
+
+#define dri2ClientPrivate(_pClient) (dixLookupPrivate(&(_pClient)->devPrivates, \
+                                                      dri2ClientPrivateKey))
+
+typedef struct _DRI2Client {
+    int prime_id;
+} DRI2ClientRec, *DRI2ClientPtr;
+
 static RESTYPE dri2DrawableRes;
 
 typedef struct _DRI2Screen *DRI2ScreenPtr;
@@ -87,6 +98,9 @@ typedef struct _DRI2Drawable {
     int swap_limit;             /* for N-buffering */
     unsigned long serialNumber;
     Bool needInvalidate;
+    int prime_id;
+    PixmapPtr prime_slave_pixmap;
+    PixmapPtr redirectpixmap;
 } DRI2DrawableRec, *DRI2DrawablePtr;
 
 typedef struct _DRI2Screen {
@@ -113,14 +127,47 @@ typedef struct _DRI2Screen {
     HandleExposuresProcPtr HandleExposures;
 
     ConfigNotifyProcPtr ConfigNotify;
+    DRI2CreateBuffer2ProcPtr CreateBuffer2;
+    DRI2DestroyBuffer2ProcPtr DestroyBuffer2;
+    DRI2CopyRegion2ProcPtr CopyRegion2;
 } DRI2ScreenRec;
 
+static void
+destroy_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, int prime_id);
+
 static DRI2ScreenPtr
 DRI2GetScreen(ScreenPtr pScreen)
 {
     return dixLookupPrivate(&pScreen->devPrivates, dri2ScreenPrivateKey);
 }
 
+static ScreenPtr
+GetScreenPrime(ScreenPtr master, int prime_id)
+{
+    ScreenPtr slave;
+    int i;
+
+    if (prime_id == 0 || xorg_list_is_empty(&master->offload_slave_list)) {
+        return master;
+    }
+    i = 0;
+    xorg_list_for_each_entry(slave, &master->offload_slave_list, offload_head) {
+        if (i == (prime_id - 1))
+            break;
+        i++;
+    }
+    if (!slave)
+        return master;
+    return slave;
+}
+
+static DRI2ScreenPtr
+DRI2GetScreenPrime(ScreenPtr master, int prime_id)
+{
+    ScreenPtr slave = GetScreenPrime(master, prime_id);
+    return DRI2GetScreen(slave);
+}
+
 static DRI2DrawablePtr
 DRI2GetDrawable(DrawablePtr pDraw)
 {
@@ -187,7 +234,8 @@ DRI2AllocateDrawable(DrawablePtr pDraw)
     xorg_list_init(&pPriv->reference_list);
     pPriv->serialNumber = DRI2DrawableSerial(pDraw);
     pPriv->needInvalidate = FALSE;
-
+    pPriv->redirectpixmap = NULL;
+    pPriv->prime_slave_pixmap = NULL;
     if (pDraw->type == DRAWABLE_WINDOW) {
         pWin = (WindowPtr) pDraw;
         dixSetPrivate(&pWin->devPrivates, dri2WindowPrivateKey, pPriv);
@@ -286,6 +334,7 @@ DRI2CreateDrawable(ClientPtr client, DrawablePtr pDraw, XID id,
                    DRI2InvalidateProcPtr invalidate, void *priv)
 {
     DRI2DrawablePtr pPriv;
+    DRI2ClientPtr dri2_client = dri2ClientPrivate(client);
     XID dri2_id;
     int rc;
 
@@ -295,6 +344,8 @@ DRI2CreateDrawable(ClientPtr client, DrawablePtr pDraw, XID id,
     if (pPriv == NULL)
         return BadAlloc;
 
+    pPriv->prime_id = dri2_client->prime_id;
+
     dri2_id = FakeClientID(client->index);
     rc = DRI2AddDrawableRef(pPriv, id, dri2_id, invalidate, priv);
     if (rc != Success)
@@ -307,7 +358,6 @@ static int
 DRI2DrawableGone(pointer p, XID id)
 {
     DRI2DrawablePtr pPriv = p;
-    DRI2ScreenPtr ds = pPriv->dri2_screen;
     DRI2DrawableRefPtr ref, next;
     WindowPtr pWin;
     PixmapPtr pPixmap;
@@ -347,16 +397,52 @@ DRI2DrawableGone(pointer p, XID id)
 
     if (pPriv->buffers != NULL) {
         for (i = 0; i < pPriv->bufferCount; i++)
-            (*ds->DestroyBuffer) (pDraw, pPriv->buffers[i]);
+            destroy_buffer(pDraw, pPriv->buffers[i], pPriv->prime_id);
 
         free(pPriv->buffers);
     }
 
+    if (pPriv->redirectpixmap) {
+        (*pDraw->pScreen->ReplaceScanoutPixmap)(pDraw, pPriv->redirectpixmap, FALSE);
+        (*pDraw->pScreen->DestroyPixmap)(pPriv->redirectpixmap);
+    }
+
     free(pPriv);
 
     return Success;
 }
 
+static DRI2BufferPtr
+create_buffer(DrawablePtr pDraw,
+              unsigned int attachment, unsigned int format)
+{
+    ScreenPtr primeScreen;
+    DRI2DrawablePtr pPriv;
+    DRI2ScreenPtr ds;
+    DRI2BufferPtr buffer;
+    pPriv = DRI2GetDrawable(pDraw);
+    primeScreen = GetScreenPrime(pDraw->pScreen, pPriv->prime_id);
+    ds = DRI2GetScreenPrime(pDraw->pScreen, pPriv->prime_id);
+    if (ds->CreateBuffer2)
+        buffer = (*ds->CreateBuffer2)(primeScreen, pDraw, attachment, format);
+    else
+        buffer = (*ds->CreateBuffer)(pDraw, attachment, format);
+    return buffer;
+}
+
+static void
+destroy_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, int prime_id)
+{
+    ScreenPtr primeScreen;
+    DRI2ScreenPtr ds;
+    primeScreen = GetScreenPrime(pDraw->pScreen, prime_id);
+    ds = DRI2GetScreen(primeScreen);
+    if (ds->DestroyBuffer2)
+        (*ds->DestroyBuffer2)(primeScreen, pDraw, buffer);
+    else
+        (*ds->DestroyBuffer)(pDraw, buffer);
+}
+
 static int
 find_attachment(DRI2DrawablePtr pPriv, unsigned attachment)
 {
@@ -387,7 +473,7 @@ allocate_or_reuse_buffer(DrawablePtr pDraw, DRI2ScreenPtr ds,
     if ((old_buf < 0)
         || attachment == DRI2BufferFrontLeft
         || !dimensions_match || (pPriv->buffers[old_buf]->format != format)) {
-        *buffer = (*ds->CreateBuffer) (pDraw, attachment, format);
+        *buffer = create_buffer (pDraw, attachment, format);
         pPriv->serialNumber = DRI2DrawableSerial(pDraw);
         return TRUE;
 
@@ -408,13 +494,12 @@ update_dri2_drawable_buffers(DRI2DrawablePtr pPriv, DrawablePtr pDraw,
                              DRI2BufferPtr * buffers, int out_count, int *width,
                              int *height)
 {
-    DRI2ScreenPtr ds = DRI2GetScreen(pDraw->pScreen);
     int i;
 
     if (pPriv->buffers != NULL) {
         for (i = 0; i < pPriv->bufferCount; i++) {
             if (pPriv->buffers[i] != NULL) {
-                (*ds->DestroyBuffer) (pDraw, pPriv->buffers[i]);
+                destroy_buffer(pDraw, pPriv->buffers[i], pPriv->prime_id);
             }
         }
 
@@ -434,8 +519,8 @@ do_get_buffers(DrawablePtr pDraw, int *width, int *height,
                unsigned int *attachments, int count, int *out_count,
                int has_format)
 {
-    DRI2ScreenPtr ds = DRI2GetScreen(pDraw->pScreen);
     DRI2DrawablePtr pPriv = DRI2GetDrawable(pDraw);
+    DRI2ScreenPtr ds;
     DRI2BufferPtr *buffers;
     int need_real_front = 0;
     int need_fake_front = 0;
@@ -452,6 +537,8 @@ do_get_buffers(DrawablePtr pDraw, int *width, int *height,
         return NULL;
     }
 
+    ds = DRI2GetScreen(pDraw->pScreen);
+
     dimensions_match = (pDraw->width == pPriv->width)
         && (pDraw->height == pPriv->height)
         && (pPriv->serialNumber == DRI2DrawableSerial(pDraw));
@@ -556,7 +643,7 @@ do_get_buffers(DrawablePtr pDraw, int *width, int *height,
     if (buffers) {
         for (i = 0; i < count; i++) {
             if (buffers[i] != NULL)
-                (*ds->DestroyBuffer) (pDraw, buffers[i]);
+                destroy_buffer(pDraw, buffers[i], 0);
         }
 
         free(buffers);
@@ -650,11 +737,118 @@ DRI2BlockClient(ClientPtr client, DrawablePtr pDraw)
     pPriv->blockedOnMsc = TRUE;
 }
 
+static inline PixmapPtr GetDrawablePixmap(DrawablePtr drawable)
+{
+    if (drawable->type == DRAWABLE_PIXMAP)
+        return (PixmapPtr)drawable;
+    else {
+        struct _Window *pWin = (struct _Window *)drawable;
+        return drawable->pScreen->GetWindowPixmap(pWin);
+    }
+}
+
+DrawablePtr DRI2UpdatePrime(DrawablePtr pDraw, DRI2BufferPtr pDest)
+{
+    DRI2DrawablePtr pPriv = DRI2GetDrawable(pDraw);
+    PixmapPtr spix;
+    PixmapPtr mpix = GetDrawablePixmap(pDraw);
+    ScreenPtr master, slave;
+    Bool ret;
+
+    master = mpix->drawable.pScreen;
+
+    if (pDraw->type == DRAWABLE_WINDOW) {
+        WindowPtr pWin = (WindowPtr)pDraw;
+        PixmapPtr pPixmap = pDraw->pScreen->GetWindowPixmap(pWin);
+
+        if (pDraw->pScreen->GetScreenPixmap(pDraw->pScreen) == pPixmap) {
+            if (pPriv->redirectpixmap &&
+                pPriv->redirectpixmap->drawable.width == pDraw->width &&
+                pPriv->redirectpixmap->drawable.height == pDraw->height &&
+                pPriv->redirectpixmap->drawable.depth == pDraw->depth) {
+                mpix = pPriv->redirectpixmap;
+            } else {
+                if (master->ReplaceScanoutPixmap) {
+                    mpix = (*master->CreatePixmap)(master, pDraw->width, pDraw->height,
+                                                   pDraw->depth, CREATE_PIXMAP_USAGE_SHARED);
+                    if (!mpix)
+                        return NULL;
+
+                    ret = (*master->ReplaceScanoutPixmap)(pDraw, mpix, TRUE);
+                    if (ret == FALSE) {
+                        (*master->DestroyPixmap)(mpix);
+                        return NULL;
+                    }
+                    pPriv->redirectpixmap = mpix;
+                } else
+                    return NULL;
+            }
+        } else if (pPriv->redirectpixmap) {
+            (*master->ReplaceScanoutPixmap)(pDraw, pPriv->redirectpixmap, FALSE);
+            (*master->DestroyPixmap)(pPriv->redirectpixmap);
+            pPriv->redirectpixmap = NULL;
+        }
+    }
+
+    slave = GetScreenPrime(pDraw->pScreen, pPriv->prime_id);
+
+    /* check if the pixmap is still fine */
+    if (pPriv->prime_slave_pixmap) {
+        if (pPriv->prime_slave_pixmap->master_pixmap == mpix)
+            return &pPriv->prime_slave_pixmap->drawable;
+        else {
+            (*master->DestroyPixmap)(pPriv->prime_slave_pixmap->master_pixmap);
+            (*slave->DestroyPixmap)(pPriv->prime_slave_pixmap);
+        }
+    }
+
+    spix = PixmapShareToSlave(mpix, slave);
+    if (!spix)
+        return NULL;
+
+    pPriv->prime_slave_pixmap = spix;
+#ifdef COMPOSITE
+    spix->screen_x = mpix->screen_x;
+    spix->screen_y = mpix->screen_y;
+#endif
+    return &spix->drawable;
+}
+
+static void dri2_copy_region(DrawablePtr pDraw, RegionPtr pRegion,
+                             DRI2BufferPtr pDest, DRI2BufferPtr pSrc)
+{
+    DRI2DrawablePtr pPriv = DRI2GetDrawable(pDraw);
+    DRI2ScreenPtr ds;
+    ScreenPtr primeScreen;
+
+    primeScreen = GetScreenPrime(pDraw->pScreen, pPriv->prime_id);
+    ds = DRI2GetScreen(primeScreen);
+
+    if (ds->CopyRegion2)
+        (*ds->CopyRegion2)(primeScreen, pDraw, pRegion, pDest, pSrc);
+    else
+        (*ds->CopyRegion) (pDraw, pRegion, pDest, pSrc);
+
+    /* cause damage to the box */
+    if (pPriv->prime_id) {
+       BoxRec box;
+       RegionRec region;
+       box.x1 = 0;
+       box.x2 = box.x1 + pDraw->width;
+       box.y1 = 0;
+       box.y2 = box.y1 + pDraw->height;
+       RegionInit(&region, &box, 1);
+       RegionTranslate(&region, pDraw->x, pDraw->y);
+       DamageRegionAppend(pDraw, &region);
+       DamageRegionProcessPending(pDraw);
+       RegionUninit(&region);
+    }
+}
+
 int
 DRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
                unsigned int dest, unsigned int src)
 {
-    DRI2ScreenPtr ds = DRI2GetScreen(pDraw->pScreen);
     DRI2DrawablePtr pPriv;
     DRI2BufferPtr pDestBuffer, pSrcBuffer;
     int i;
@@ -674,7 +868,7 @@ DRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
     if (pSrcBuffer == NULL || pDestBuffer == NULL)
         return BadValue;
 
-    (*ds->CopyRegion) (pDraw, pRegion, pDestBuffer, pSrcBuffer);
+    dri2_copy_region(pDraw, pRegion, pDestBuffer, pSrcBuffer);
 
     return Success;
 }
@@ -879,7 +1073,7 @@ DRI2SwapBuffers(ClientPtr client, DrawablePtr pDraw, CARD64 target_msc,
     }
 
     /* Old DDX or no swap interval, just blit */
-    if (!ds->ScheduleSwap || !pPriv->swap_interval) {
+    if (!ds->ScheduleSwap || !pPriv->swap_interval || pPriv->prime_id) {
         BoxRec box;
         RegionRec region;
 
@@ -891,7 +1085,7 @@ DRI2SwapBuffers(ClientPtr client, DrawablePtr pDraw, CARD64 target_msc,
 
         pPriv->swapsPending++;
 
-        (*ds->CopyRegion) (pDraw, &region, pDestBuffer, pSrcBuffer);
+        dri2_copy_region(pDraw, &region, pDestBuffer, pSrcBuffer);
         DRI2SwapComplete(client, pDraw, target_msc, 0, 0, DRI2_BLIT_COMPLETE,
                          func, data);
         return Success;
@@ -1091,22 +1285,34 @@ DRI2HasSwapControl(ScreenPtr pScreen)
 }
 
 Bool
-DRI2Connect(ScreenPtr pScreen, unsigned int driverType, int *fd,
+DRI2Connect(ClientPtr client, ScreenPtr pScreen,
+            unsigned int driverType, int *fd,
             const char **driverName, const char **deviceName)
 {
     DRI2ScreenPtr ds;
+    uint32_t prime_id = DRI2DriverPrimeId(driverType);
+    uint32_t driver_id = driverType & 0xffff;
 
     if (!dixPrivateKeyRegistered(dri2ScreenPrivateKey))
         return FALSE;
 
-    ds = DRI2GetScreen(pScreen);
-    if (ds == NULL || driverType >= ds->numDrivers ||
-        !ds->driverNames[driverType])
+    ds = DRI2GetScreenPrime(pScreen, prime_id);
+    if (ds == NULL)
         return FALSE;
 
-    *fd = ds->fd;
-    *driverName = ds->driverNames[driverType];
+    if (driver_id >= ds->numDrivers ||
+        !ds->driverNames[driver_id])
+        return FALSE;
+
+    *driverName = ds->driverNames[driver_id];
     *deviceName = ds->deviceName;
+    *fd = ds->fd;
+
+    if (client) {
+        DRI2ClientPtr dri2_client;
+        dri2_client = dri2ClientPrivate(client);
+        dri2_client->prime_id = prime_id;
+    }
 
     return TRUE;
 }
@@ -1122,13 +1328,19 @@ DRI2AuthMagic (ScreenPtr pScreen, uint32_t magic)
 }
 
 Bool
-DRI2Authenticate(ScreenPtr pScreen, uint32_t magic)
+DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic)
 {
-    DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
+    DRI2ScreenPtr ds;
+    DRI2ClientPtr dri2_client = dri2ClientPrivate(client);
+    ScreenPtr primescreen;
 
-    if (ds == NULL || (*ds->AuthMagic) (pScreen, magic))
+    ds = DRI2GetScreenPrime(pScreen, dri2_client->prime_id);
+    if (ds == NULL)
         return FALSE;
 
+    primescreen = GetScreenPrime(pScreen, dri2_client->prime_id);
+    if ((*ds->AuthMagic)(primescreen, magic))
+        return FALSE;
     return TRUE;
 }
 
@@ -1190,6 +1402,9 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
     if (!dixRegisterPrivateKey(&dri2PixmapPrivateKeyRec, PRIVATE_PIXMAP, 0))
         return FALSE;
 
+    if (!dixRegisterPrivateKey(&dri2ClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(DRI2ClientRec)))
+        return FALSE;
+
     ds = calloc(1, sizeof *ds);
     if (!ds)
         return FALSE;
@@ -1230,6 +1445,12 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
         cur_minor = 4;
     }
 
+    if (info->version >= 9) {
+        ds->CreateBuffer2 = info->CreateBuffer2;
+        ds->DestroyBuffer2 = info->DestroyBuffer2;
+        ds->CopyRegion2 = info->CopyRegion2;
+    }
+
     /*
      * if the driver doesn't provide an AuthMagic function or the info struct
      * version is too low, call through LegacyAuthMagic
diff --git a/hw/xfree86/dri2/dri2.h b/hw/xfree86/dri2/dri2.h
index 4fd0fbc..a59e680 100644
--- a/hw/xfree86/dri2/dri2.h
+++ b/hw/xfree86/dri2/dri2.h
@@ -176,6 +176,18 @@ typedef void (*DRI2InvalidateProcPtr) (DrawablePtr pDraw, void *data, XID id);
 typedef Bool (*DRI2SwapLimitValidateProcPtr) (DrawablePtr pDraw,
                                               int swap_limit);
 
+typedef DRI2BufferPtr(*DRI2CreateBuffer2ProcPtr) (ScreenPtr pScreen,
+                                                  DrawablePtr pDraw,
+                                                  unsigned int attachment,
+                                                  unsigned int format);
+typedef void (*DRI2DestroyBuffer2ProcPtr) (ScreenPtr pScreen, DrawablePtr pDraw,
+                                          DRI2BufferPtr buffer);
+
+typedef void (*DRI2CopyRegion2ProcPtr) (ScreenPtr pScreen, DrawablePtr pDraw,
+                                        RegionPtr pRegion,
+                                        DRI2BufferPtr pDestBuffer,
+                                        DRI2BufferPtr pSrcBuffer);
+
 /**
  * \brief Get the value of a parameter.
  *
@@ -193,7 +205,7 @@ typedef int (*DRI2GetParamProcPtr) (ClientPtr client,
 /**
  * Version of the DRI2InfoRec structure defined in this header
  */
-#define DRI2INFOREC_VERSION 8
+#define DRI2INFOREC_VERSION 9
 
 typedef struct {
     unsigned int version;       /**< Version of this struct */
@@ -228,7 +240,6 @@ typedef struct {
     DRI2SwapLimitValidateProcPtr SwapLimitValidate;
 
     /* added in version 7 */
-
     DRI2GetParamProcPtr GetParam;
 
     /* added in version 8 */
@@ -236,6 +247,11 @@ typedef struct {
     /* If this is NULL the AuthMagic callback is used */
     /* If this is non-NULL the AuthMagic callback is ignored */
     DRI2AuthMagic2ProcPtr AuthMagic2;
+
+    /* added in version 9 */
+    DRI2CreateBuffer2ProcPtr CreateBuffer2;
+    DRI2DestroyBuffer2ProcPtr DestroyBuffer2;
+    DRI2CopyRegion2ProcPtr CopyRegion2;
 } DRI2InfoRec, *DRI2InfoPtr;
 
 extern _X_EXPORT int DRI2EventBase;
@@ -246,13 +262,13 @@ extern _X_EXPORT void DRI2CloseScreen(ScreenPtr pScreen);
 
 extern _X_EXPORT Bool DRI2HasSwapControl(ScreenPtr pScreen);
 
-extern _X_EXPORT Bool DRI2Connect(ScreenPtr pScreen,
+extern _X_EXPORT Bool DRI2Connect(ClientPtr client, ScreenPtr pScreen,
                                   unsigned int driverType,
                                   int *fd,
                                   const char **driverName,
                                   const char **deviceName);
 
-extern _X_EXPORT Bool DRI2Authenticate(ScreenPtr pScreen, uint32_t magic);
+extern _X_EXPORT Bool DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic);
 
 extern _X_EXPORT int DRI2CreateDrawable(ClientPtr client,
                                         DrawablePtr pDraw,
@@ -339,4 +355,5 @@ extern _X_EXPORT int DRI2GetParam(ClientPtr client,
                                   BOOL *is_param_recognized,
                                   CARD64 *value);
 
+extern _X_EXPORT DrawablePtr DRI2UpdatePrime(DrawablePtr pDraw, DRI2BufferPtr pDest);
 #endif
diff --git a/hw/xfree86/dri2/dri2ext.c b/hw/xfree86/dri2/dri2ext.c
index c6f5b4e..3bc3ea7 100644
--- a/hw/xfree86/dri2/dri2ext.c
+++ b/hw/xfree86/dri2/dri2ext.c
@@ -116,7 +116,7 @@ ProcDRI2Connect(ClientPtr client)
     rep.driverNameLength = 0;
     rep.deviceNameLength = 0;
 
-    if (!DRI2Connect(pDraw->pScreen,
+    if (!DRI2Connect(client, pDraw->pScreen,
                      stuff->driverType, &fd, &driverName, &deviceName))
         goto fail;
 
@@ -149,7 +149,7 @@ ProcDRI2Authenticate(ClientPtr client)
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
     rep.length = 0;
-    rep.authenticated = DRI2Authenticate(pDraw->pScreen, stuff->magic);
+    rep.authenticated = DRI2Authenticate(client, pDraw->pScreen, stuff->magic);
     WriteToClient(client, sizeof(xDRI2AuthenticateReply), &rep);
 
     return Success;
commit 234022cfb3ad2a1b16ab7981ce69f9cd5ba0fbeb
Author: Dave Airlie <airlied at redhat.com>
Date:   Sat Jul 7 10:20:58 2012 +0100

    configure: bump dri2proto to 2.8
    
    This is required for the prime macros.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/configure.ac b/configure.ac
index 2442bac..74e7e9a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -775,7 +775,7 @@ RECORDPROTO="recordproto >= 1.13.99.1"
 SCRNSAVERPROTO="scrnsaverproto >= 1.1"
 RESOURCEPROTO="resourceproto >= 1.2.0"
 DRIPROTO="xf86driproto >= 2.1.0"
-DRI2PROTO="dri2proto >= 2.7"
+DRI2PROTO="dri2proto >= 2.8"
 XINERAMAPROTO="xineramaproto"
 BIGFONTPROTO="xf86bigfontproto >= 1.2.0"
 DGAPROTO="xf86dgaproto >= 2.0.99.1"
commit c41922940adbc8891575b3321fadf01ff4cb5854
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 26 10:00:21 2012 +0100

    dix/randr: add a hook into screen to replace scanout pixmap
    
    For DRI2 in some offload cases we need to set a new pixmap on the crtc,
    this hook allows dri2 to call into randr to do the necessary work to set
    a pixmap as the scanout pixmap for the crtc the drawable is currently on.
    
    This is really only to be used for unredirected full screen apps in composited
    environments.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 80601b9..df74073 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -351,6 +351,8 @@ typedef Bool (*StartPixmapTrackingProcPtr)(PixmapPtr, PixmapPtr,
 
 typedef Bool (*StopPixmapTrackingProcPtr)(PixmapPtr, PixmapPtr);
 
+typedef Bool (*ReplaceScanoutPixmapProcPtr)(DrawablePtr, PixmapPtr, Bool);
+
 typedef struct _Screen {
     int myNum;                  /* index of this instance in Screens[] */
     ATOM id;
@@ -510,6 +512,7 @@ typedef struct _Screen {
     struct xorg_list offload_slave_list;
     struct xorg_list offload_head;
 
+    ReplaceScanoutPixmapProcPtr ReplaceScanoutPixmap;
 } ScreenRec;
 
 static inline RegionPtr
diff --git a/randr/randr.c b/randr/randr.c
index ae81166..3050c54 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -324,7 +324,7 @@ RRScreenInit(ScreenPtr pScreen)
     wrap(pScrPriv, pScreen, CloseScreen, RRCloseScreen);
 
     pScreen->ConstrainCursorHarder = RRConstrainCursorHarder;
-
+    pScreen->ReplaceScanoutPixmap = RRReplaceScanoutPixmap;
     pScrPriv->numOutputs = 0;
     pScrPriv->outputs = NULL;
     pScrPriv->numCrtcs = 0;
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 16e7d01..62b9050 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -673,6 +673,9 @@ extern _X_EXPORT void
 extern _X_EXPORT void
  RRCrtcDetachScanoutPixmap(RRCrtcPtr crtc);
 
+extern _X_EXPORT Bool
+ RRReplaceScanoutPixmap(DrawablePtr pDrawable, PixmapPtr pPixmap, Bool enable);
+
 /*
  * Crtc dispatch
  */
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 949ae60..1a6e593 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1641,3 +1641,61 @@ RRConstrainCursorHarder(DeviceIntPtr pDev, ScreenPtr pScreen, int mode, int *x,
             return;
     }
 }
+
+Bool
+RRReplaceScanoutPixmap(DrawablePtr pDrawable, PixmapPtr pPixmap, Bool enable)
+{
+    rrScrPriv(pDrawable->pScreen);
+    int i;
+    Bool size_fits = FALSE;
+    Bool changed = FALSE;
+    Bool ret = TRUE;
+
+    for (i = 0; i < pScrPriv->numCrtcs; i++) {
+        RRCrtcPtr crtc = pScrPriv->crtcs[i];
+
+        if (!crtc->mode && enable)
+            continue;
+
+        changed = FALSE;
+        if (crtc->mode && crtc->x == pDrawable->x &&
+            crtc->y == pDrawable->y &&
+            crtc->mode->mode.width == pDrawable->width &&
+            crtc->mode->mode.height == pDrawable->height)
+            size_fits = TRUE;
+
+        /* is the pixmap already set? */
+        if (crtc->scanout_pixmap == pPixmap) {
+            /* if its a disable then don't care about size */
+            if (enable == FALSE) {
+                /* set scanout to NULL */
+                crtc->scanout_pixmap = NULL;
+                changed = TRUE;
+            } else {
+                /* if the size fits then we are already setup */
+                if (size_fits)
+                    return TRUE;
+                /* if the size no longer fits then drop off */
+                crtc->scanout_pixmap = NULL;
+                changed = TRUE;
+                ret = FALSE;
+            }
+        } else {
+            if (!size_fits)
+                return FALSE;
+            if (enable) {
+                crtc->scanout_pixmap = pPixmap;
+                pScrPriv->rrCrtcSetScanoutPixmap(crtc, pPixmap);
+                changed = TRUE;
+            }
+        }
+
+        if (changed && pScrPriv->rrCrtcSet) {
+            pScrPriv->rrCrtcSetScanoutPixmap(crtc, crtc->scanout_pixmap);
+
+            (*pScrPriv->rrCrtcSet) (pDrawable->pScreen, crtc, crtc->mode, crtc->x, crtc->y,
+                                    crtc->rotation, crtc->numOutputs, crtc->outputs);
+        }
+    }
+    return ret;
+}
commit e2fd447e76c4a1233374c9d8fa9cae54a55dad50
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jul 5 15:50:56 2012 +0100

    xf86: add callback for offloak sink setting support.
    
    This adds support for setting the offload sink to the xf86 ddx.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index c5c7cb7..d20152c 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -741,7 +741,11 @@ xf86CrtcCloseScreen(ScreenPtr screen)
     }
     /* detach any providers */
     if (config->randr_provider) {
-        if (config->randr_provider->output_source) {
+        if (config->randr_provider->offload_sink) {
+            DetachOffloadGPU(screen);
+            config->randr_provider->offload_sink = NULL;
+        }
+        else if (config->randr_provider->output_source) {
             DetachOutputGPU(screen);
             config->randr_provider->output_source = NULL;
         }
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 9548333..b4ed46a 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1789,6 +1789,32 @@ xf86RandR14ProviderSetOutputSource(ScreenPtr pScreen,
 }
 
 static Bool
+xf86RandR14ProviderSetOffloadSink(ScreenPtr pScreen,
+                                  RRProviderPtr provider,
+                                  RRProviderPtr sink_provider)
+{
+    if (!sink_provider) {
+        if (provider->offload_sink) {
+            ScreenPtr cmScreen = pScreen->current_master;
+            DetachOutputGPU(pScreen);
+            AttachUnboundGPU(cmScreen, pScreen);
+        }
+
+        provider->offload_sink = NULL;
+        return TRUE;
+    }
+
+    if (provider->offload_sink == sink_provider)
+        return TRUE;
+
+    DetachUnboundGPU(pScreen);
+    AttachOffloadGPU(sink_provider->pScreen, pScreen);
+
+    provider->offload_sink = sink_provider;
+    return TRUE;
+}
+
+static Bool
 xf86RandR14ProviderSetProperty(ScreenPtr pScreen,
                              RRProviderPtr randr_provider,
                              Atom property, RRPropertyValuePtr value)
@@ -1857,6 +1883,7 @@ xf86RandR12Init12(ScreenPtr pScreen)
     rp->rrSetConfig = NULL;
 
     rp->rrProviderSetOutputSource = xf86RandR14ProviderSetOutputSource;
+    rp->rrProviderSetOffloadSink = xf86RandR14ProviderSetOffloadSink;
 
     rp->rrProviderSetProperty = xf86RandR14ProviderSetProperty;
     rp->rrProviderGetProperty = xf86RandR14ProviderGetProperty;
commit 22f02120eb4092e1c283f81c8040f178693ff0a4
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 26 09:53:54 2012 +0100

    xf86: store scanout pixmap in the xf86 struct as well.
    
    This is so we can tell the scanout pixmap has changed between calls
    to the crtc set function.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 38b9ea5..802303f 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -225,7 +225,7 @@ typedef struct _xf86CrtcFuncs {
 
 } xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
 
-#define XF86_CRTC_VERSION 4
+#define XF86_CRTC_VERSION 5
 
 struct _xf86Crtc {
     /**
@@ -376,6 +376,10 @@ struct _xf86Crtc {
      * Added in ABI version 4
      */
     Bool driverIsPerformingTransform;
+
+    /* Added in ABI version 5
+     */
+    PixmapPtr current_scanout;
 };
 
 typedef struct _xf86OutputFuncs {
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 5fc33ca..9548333 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1157,6 +1157,9 @@ xf86RandR12CrtcSet(ScreenPtr pScreen,
     if (rotation != crtc->rotation)
         changed = TRUE;
 
+    if (crtc->current_scanout != randr_crtc->scanout_pixmap)
+        changed = TRUE;
+
     transform = RRCrtcGetTransform(randr_crtc);
     if ((transform != NULL) != crtc->transformPresent)
         changed = TRUE;
@@ -1218,6 +1221,7 @@ xf86RandR12CrtcSet(ScreenPtr pScreen,
              */
             crtc->desiredMode = mode;
             crtc->desiredRotation = rotation;
+            crtc->current_scanout = randr_crtc->scanout_pixmap;
             if (transform) {
                 crtc->desiredTransform = *transform;
                 crtc->desiredTransformPresent = TRUE;
commit 426bc0a28edbe0e9153f692a02dd25f744ffa034
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jul 5 15:41:38 2012 +0100

    randr: add hooks for offload sink provider protocol
    
    This adds the protocol handler and associated providers handling
    for the offload slaves, it allows two providers to be connected as
    offload sink/source.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/randr/randrstr.h b/randr/randrstr.h
index 5ca8830..16e7d01 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -164,6 +164,7 @@ struct _rrProvider {
     int nameLength;
     RRPropertyPtr properties;
     Bool pendingProperties;
+    struct _rrProvider *offload_sink;
     struct _rrProvider *output_source;
 };
 
@@ -226,6 +227,11 @@ typedef Bool (*RRProviderSetOutputSourceProcPtr)(ScreenPtr pScreen,
                                           RRProviderPtr provider,
                                           RRProviderPtr output_source);
 
+typedef Bool (*RRProviderSetOffloadSinkProcPtr)(ScreenPtr pScreen,
+                                         RRProviderPtr provider,
+                                         RRProviderPtr offload_sink);
+
+
 /* These are for 1.0 compatibility */
 
 typedef struct _rrRefresh {
@@ -278,6 +284,7 @@ typedef struct _rrScrPriv {
     RRCrtcSetScanoutPixmapProcPtr rrCrtcSetScanoutPixmap;
 
     RRProviderSetOutputSourceProcPtr rrProviderSetOutputSource;
+    RRProviderSetOffloadSinkProcPtr rrProviderSetOffloadSink;
     RRProviderGetPropertyProcPtr rrProviderGetProperty;
     RRProviderSetPropertyProcPtr rrProviderSetProperty;
     /*
@@ -888,6 +895,9 @@ ProcRRGetProviderInfo(ClientPtr client);
 extern _X_EXPORT int
 ProcRRSetProviderOutputSource(ClientPtr client);
 
+extern _X_EXPORT int
+ProcRRSetProviderOffloadSink(ClientPtr client);
+
 extern _X_EXPORT Bool
 RRProviderInit(void);
 
diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index 6fe51c7..1942d74 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -245,7 +245,7 @@ int (*ProcRandrVector[RRNumberRequests]) (ClientPtr) = {
 /* V1.4 additions */
         ProcRRGetProviders,     /* 32 */
         ProcRRGetProviderInfo,  /* 33 */
-        NULL, /* 34 */
+        ProcRRSetProviderOffloadSink, /* 34 */
         ProcRRSetProviderOutputSource, /* 35 */
         ProcRRListProviderProperties,    /* 36 */
         ProcRRQueryProviderProperty,     /* 37 */
diff --git a/randr/rrprovider.c b/randr/rrprovider.c
index 8385d3f..c4fe369 100644
--- a/randr/rrprovider.c
+++ b/randr/rrprovider.c
@@ -175,10 +175,15 @@ ProcRRGetProviderInfo (ClientPtr client)
 
     /* count associated providers */
     rep.nAssociatedProviders = 0;
+    if (provider->offload_sink)
+        rep.nAssociatedProviders++;
     if (provider->output_source)
         rep.nAssociatedProviders++;
     xorg_list_for_each_entry(provscreen, &pScreen->output_slave_list, output_head)
         rep.nAssociatedProviders++;
+    xorg_list_for_each_entry(provscreen, &pScreen->offload_slave_list, offload_head)
+        rep.nAssociatedProviders++;
+
     rep.length = (pScrPriv->numCrtcs + pScrPriv->numOutputs +
                   (rep.nAssociatedProviders * 2) + bytes_to_int32(rep.nameLength));
 
@@ -210,6 +215,15 @@ ProcRRGetProviderInfo (ClientPtr client)
     }
 
     i = 0;
+    if (provider->offload_sink) {
+        providers[i] = provider->offload_sink->id;
+        if (client->swapped)
+            swapl(&providers[i]);
+        prov_cap[i] = RR_Capability_SinkOffload;
+        if (client->swapped)
+            swapl(&prov_cap[i]);
+        i++;
+    }
     if (provider->output_source) {
         providers[i] = provider->output_source->id;
         if (client->swapped)
@@ -228,6 +242,17 @@ ProcRRGetProviderInfo (ClientPtr client)
             swapl(&prov_cap[i]);
         i++;
     }
+    xorg_list_for_each_entry(provscreen, &pScreen->offload_slave_list, offload_head) {
+        pScrProvPriv = rrGetScrPriv(provscreen);
+        providers[i] = pScrProvPriv->provider->id;
+        if (client->swapped)
+            swapl(&providers[i]);
+        prov_cap[i] = RR_Capability_SourceOffload;
+        if (client->swapped)
+            swapl(&prov_cap[i]);
+        i++;
+    }
+
 
     memcpy(name, provider->name, rep.nameLength);
     if (client->swapped) {
@@ -279,6 +304,35 @@ ProcRRSetProviderOutputSource(ClientPtr client)
     return Success;
 }
 
+int
+ProcRRSetProviderOffloadSink(ClientPtr client)
+{
+    REQUEST(xRRSetProviderOffloadSinkReq);
+    rrScrPrivPtr pScrPriv;
+    RRProviderPtr provider, sink_provider = NULL;
+    ScreenPtr pScreen;
+
+    REQUEST_AT_LEAST_SIZE(xRRSetProviderOffloadSinkReq);
+
+    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
+    if (!(provider->capabilities & RR_Capability_SourceOffload))
+        return BadValue;
+
+    if (stuff->sink_provider) {
+        VERIFY_RR_PROVIDER(stuff->sink_provider, sink_provider, DixReadAccess);
+        if (!(sink_provider->capabilities & RR_Capability_SinkOffload))
+            return BadValue;
+    }
+    pScreen = provider->pScreen;
+    pScrPriv = rrGetScrPriv(pScreen);
+
+    pScrPriv->rrProviderSetOffloadSink(pScreen, provider, sink_provider);
+
+    RRTellChanged (pScreen);
+
+    return Success;
+}
+
 RRProviderPtr
 RRProviderCreate(ScreenPtr pScreen, const char *name,
                  int nameLength)
commit 12905dfaf01088a00f4a0a78cffba03329e7b724
Author: Dave Airlie <airlied at redhat.com>
Date:   Sat May 26 13:11:01 2012 +0100

    dix/xf86: initial offload slave tracking (v1.1)
    
    add the linked list and provider hooks.
    
    v1.1: add another assert in the add path.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index bc803d7..bcce22f 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3745,6 +3745,7 @@ static int init_screen(ScreenPtr pScreen, int i, Bool gpu)
     xorg_list_init(&pScreen->pixmap_dirty_list);
     xorg_list_init(&pScreen->unattached_list);
     xorg_list_init(&pScreen->output_slave_list);
+    xorg_list_init(&pScreen->offload_slave_list);
 
     /*
      * This loop gets run once for every Screen that gets added,
@@ -3927,3 +3928,21 @@ DetachOutputGPU(ScreenPtr slave)
     xorg_list_del(&slave->output_head);
     slave->current_master = NULL;
 }
+
+void
+AttachOffloadGPU(ScreenPtr pScreen, ScreenPtr new)
+{
+    assert(new->isGPU);
+    assert(!new->current_master);
+    xorg_list_add(&new->offload_head, &pScreen->offload_slave_list);
+    new->current_master = pScreen;
+}
+
+void
+DetachOffloadGPU(ScreenPtr slave)
+{
+    assert(slave->isGPU);
+    xorg_list_del(&slave->offload_head);
+    slave->current_master = NULL;
+}
+
diff --git a/include/screenint.h b/include/screenint.h
index b992cc2..e36b4d8 100644
--- a/include/screenint.h
+++ b/include/screenint.h
@@ -82,6 +82,12 @@ AttachOutputGPU(ScreenPtr pScreen, ScreenPtr new);
 extern _X_EXPORT void
 DetachOutputGPU(ScreenPtr output);
 
+extern _X_EXPORT void
+AttachOffloadGPU(ScreenPtr pScreen, ScreenPtr new);
+
+extern _X_EXPORT void
+DetachOffloadGPU(ScreenPtr slave);
+
 typedef struct _ColormapRec *ColormapPtr;
 
 #endif                          /* SCREENINT_H */
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 5ef37ed..80601b9 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -507,6 +507,9 @@ typedef struct _Screen {
     StopPixmapTrackingProcPtr StopPixmapTracking;
 
     struct xorg_list pixmap_dirty_list;
+    struct xorg_list offload_slave_list;
+    struct xorg_list offload_head;
+
 } ScreenRec;
 
 static inline RegionPtr
diff --git a/randr/rrprovider.c b/randr/rrprovider.c
index f35ca6a..8385d3f 100644
--- a/randr/rrprovider.c
+++ b/randr/rrprovider.c
@@ -76,6 +76,10 @@ ProcRRGetProviders (ClientPtr client)
         pScrPriv = rrGetScrPriv(iter);
         total_providers += pScrPriv->provider ? 1 : 0;
     }
+    xorg_list_for_each_entry(iter, &pScreen->offload_slave_list, offload_head) {
+        pScrPriv = rrGetScrPriv(iter);
+        total_providers += pScrPriv->provider ? 1 : 0;
+    }
     xorg_list_for_each_entry(iter, &pScreen->unattached_list, unattached_head) {
         pScrPriv = rrGetScrPriv(iter);
         total_providers += pScrPriv->provider ? 1 : 0;
@@ -112,6 +116,9 @@ ProcRRGetProviders (ClientPtr client)
         xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head) {
             ADD_PROVIDER(iter);
         }
+        xorg_list_for_each_entry(iter, &pScreen->offload_slave_list, offload_head) {
+            ADD_PROVIDER(iter);
+        }
         xorg_list_for_each_entry(iter, &pScreen->unattached_list, unattached_head) {
             ADD_PROVIDER(iter);
         }
commit a7c01da54ab43f9d29333ccbd79dfc001f9dc5e3
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jul 5 20:34:54 2012 +0100

    xf86: make sure rotate calcs are done on the right screen boundaries
    
    This fixes a segfault where this code believes we are outside the screen
    boundaries on a slave device, but we aren't.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 31e0372..a393747 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -322,6 +322,12 @@ xf86CrtcFitsScreen(xf86CrtcPtr crtc, struct pict_f_transform *crtc_to_fb)
     /* When called before PreInit, the driver is
      * presumably doing load detect
      */
+    if (pScrn->is_gpu) {
+	ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
+	if (pScreen->current_master)
+	    pScrn = xf86ScreenToScrn(pScreen->current_master);
+    }
+
     if (pScrn->virtualX == 0 || pScrn->virtualY == 0)
         return TRUE;
 
commit cc02f4ef3e407be794132d004c947c9a4e14f4c2
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 19 16:01:16 2012 +0100

    xf86/cursor: fallback to sw cursor if we have slaves present.
    
    Current USB devices have no hw rendered cursors, so we need the
    master GPU to render the cursor, so whenever we plug in a
    slave device, fallback to sw rendered cursors.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c
index 8b91e05..8d48a75 100644
--- a/hw/xfree86/ramdac/xf86Cursor.c
+++ b/hw/xfree86/ramdac/xf86Cursor.c
@@ -336,7 +336,7 @@ xf86CursorSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCurs,
         if (!infoPtr->pScrn->vtSema)
             ScreenPriv->SavedCursor = pCurs;
 
-        if (infoPtr->pScrn->vtSema &&
+        if (infoPtr->pScrn->vtSema && xorg_list_is_empty(&pScreen->pixmap_dirty_list) &&
             (ScreenPriv->ForceHWCursorCount ||
              ((
 #ifdef ARGB_CURSOR
commit 98686512cbe1affb75222a63136854af79f1411b
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jul 5 15:50:24 2012 +0100

    xf86: add output source setting callback (v2)
    
    This adds support for the randr callback for setting the output source
    for a device.
    
    v2: drop root clip change on detach
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 6a005cd..c5c7cb7 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -741,7 +741,11 @@ xf86CrtcCloseScreen(ScreenPtr screen)
     }
     /* detach any providers */
     if (config->randr_provider) {
-        if (screen->current_master)
+        if (config->randr_provider->output_source) {
+            DetachOutputGPU(screen);
+            config->randr_provider->output_source = NULL;
+        }
+        else if (screen->current_master)
             DetachUnboundGPU(screen);
     }
     xf86RandR12CloseScreen(screen);
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index ebea4d5..5fc33ca 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1754,6 +1754,37 @@ xf86RandR12EnterVT(ScrnInfoPtr pScrn)
 }
 
 static Bool
+xf86RandR14ProviderSetOutputSource(ScreenPtr pScreen,
+                                   RRProviderPtr provider,
+                                   RRProviderPtr source_provider)
+{
+
+
+    if (!source_provider) {
+        if (provider->output_source) {
+            ScreenPtr cmScreen = pScreen->current_master;
+
+            DetachOutputGPU(pScreen);
+            AttachUnboundGPU(cmScreen, pScreen);
+        }
+        provider->output_source = NULL;
+        return TRUE;
+    }
+
+    if (provider->output_source == source_provider)
+        return TRUE;
+
+    SetRootClip(source_provider->pScreen, FALSE);
+
+    DetachUnboundGPU(pScreen);
+    AttachOutputGPU(source_provider->pScreen, pScreen);
+
+    provider->output_source = source_provider;
+    SetRootClip(source_provider->pScreen, TRUE);
+    return TRUE;
+}
+
+static Bool
 xf86RandR14ProviderSetProperty(ScreenPtr pScreen,
                              RRProviderPtr randr_provider,
                              Atom property, RRPropertyValuePtr value)
@@ -1821,6 +1852,8 @@ xf86RandR12Init12(ScreenPtr pScreen)
     rp->rrModeDestroy = xf86RandR12ModeDestroy;
     rp->rrSetConfig = NULL;
 
+    rp->rrProviderSetOutputSource = xf86RandR14ProviderSetOutputSource;
+
     rp->rrProviderSetProperty = xf86RandR14ProviderSetProperty;
     rp->rrProviderGetProperty = xf86RandR14ProviderGetProperty;
     rp->rrCrtcSetScanoutPixmap = xf86CrtcSetScanoutPixmap;
commit 4c92eb00f97f7b8258de8e366226880382cc9ce9
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jul 5 15:41:22 2012 +0100

    randr: add output source setup
    
    This adds the output sources to the associated list and adds the protocol
    handler for the randr SetProviderOutputSource.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/randr/randrstr.h b/randr/randrstr.h
index ac93414..5ca8830 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -164,6 +164,7 @@ struct _rrProvider {
     int nameLength;
     RRPropertyPtr properties;
     Bool pendingProperties;
+    struct _rrProvider *output_source;
 };
 
 #if RANDR_12_INTERFACE
@@ -221,6 +222,10 @@ typedef Bool (*RRProviderSetPropertyProcPtr) (ScreenPtr pScreen,
 typedef Bool (*RRGetInfoProcPtr) (ScreenPtr pScreen, Rotation * rotations);
 typedef Bool (*RRCloseScreenProcPtr) (ScreenPtr pscreen);
 
+typedef Bool (*RRProviderSetOutputSourceProcPtr)(ScreenPtr pScreen,
+                                          RRProviderPtr provider,
+                                          RRProviderPtr output_source);
+
 /* These are for 1.0 compatibility */
 
 typedef struct _rrRefresh {
@@ -272,6 +277,7 @@ typedef struct _rrScrPriv {
     /* TODO #if RANDR_15_INTERFACE */
     RRCrtcSetScanoutPixmapProcPtr rrCrtcSetScanoutPixmap;
 
+    RRProviderSetOutputSourceProcPtr rrProviderSetOutputSource;
     RRProviderGetPropertyProcPtr rrProviderGetProperty;
     RRProviderSetPropertyProcPtr rrProviderSetProperty;
     /*
@@ -879,6 +885,8 @@ ProcRRGetProviders(ClientPtr client);
 extern _X_EXPORT int
 ProcRRGetProviderInfo(ClientPtr client);
 
+extern _X_EXPORT int
+ProcRRSetProviderOutputSource(ClientPtr client);
 
 extern _X_EXPORT Bool
 RRProviderInit(void);
diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index 054e47a..6fe51c7 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -246,7 +246,7 @@ int (*ProcRandrVector[RRNumberRequests]) (ClientPtr) = {
         ProcRRGetProviders,     /* 32 */
         ProcRRGetProviderInfo,  /* 33 */
         NULL, /* 34 */
-        NULL, /* 35 */
+        ProcRRSetProviderOutputSource, /* 35 */
         ProcRRListProviderProperties,    /* 36 */
         ProcRRQueryProviderProperty,     /* 37 */
         ProcRRConfigureProviderProperty, /* 38 */
diff --git a/randr/rrprovider.c b/randr/rrprovider.c
index 3773200..f35ca6a 100644
--- a/randr/rrprovider.c
+++ b/randr/rrprovider.c
@@ -137,7 +137,7 @@ ProcRRGetProviderInfo (ClientPtr client)
 {
     REQUEST(xRRGetProviderInfoReq);
     xRRGetProviderInfoReply rep;
-    rrScrPrivPtr pScrPriv;
+    rrScrPrivPtr pScrPriv, pScrProvPriv;
     RRProviderPtr provider;
     ScreenPtr pScreen;
     CARD8 *extra;
@@ -168,6 +168,10 @@ ProcRRGetProviderInfo (ClientPtr client)
 
     /* count associated providers */
     rep.nAssociatedProviders = 0;
+    if (provider->output_source)
+        rep.nAssociatedProviders++;
+    xorg_list_for_each_entry(provscreen, &pScreen->output_slave_list, output_head)
+        rep.nAssociatedProviders++;
     rep.length = (pScrPriv->numCrtcs + pScrPriv->numOutputs +
                   (rep.nAssociatedProviders * 2) + bytes_to_int32(rep.nameLength));
 
@@ -198,6 +202,26 @@ ProcRRGetProviderInfo (ClientPtr client)
             swapl(&outputs[i]);
     }
 
+    i = 0;
+    if (provider->output_source) {
+        providers[i] = provider->output_source->id;
+        if (client->swapped)
+            swapl(&providers[i]);
+        prov_cap[i] = RR_Capability_SourceOutput;
+            swapl(&prov_cap[i]);
+        i++;
+    }
+    xorg_list_for_each_entry(provscreen, &pScreen->output_slave_list, output_head) {
+        pScrProvPriv = rrGetScrPriv(provscreen);
+        providers[i] = pScrProvPriv->provider->id;
+        if (client->swapped)
+            swapl(&providers[i]);
+        prov_cap[i] = RR_Capability_SinkOutput;
+        if (client->swapped)
+            swapl(&prov_cap[i]);
+        i++;
+    }
+
     memcpy(name, provider->name, rep.nameLength);
     if (client->swapped) {
               swaps(&rep.sequenceNumber);
@@ -216,6 +240,38 @@ ProcRRGetProviderInfo (ClientPtr client)
     return Success;
 }
 
+int
+ProcRRSetProviderOutputSource(ClientPtr client)
+{
+    REQUEST(xRRSetProviderOutputSourceReq);
+    rrScrPrivPtr pScrPriv;
+    RRProviderPtr provider, source_provider = NULL;
+    ScreenPtr pScreen;
+
+    REQUEST_AT_LEAST_SIZE(xRRSetProviderOutputSourceReq);
+
+    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
+
+    if (!(provider->capabilities & RR_Capability_SinkOutput))
+        return BadValue;
+
+    if (stuff->source_provider) {
+        VERIFY_RR_PROVIDER(stuff->source_provider, source_provider, DixReadAccess);
+
+        if (!(source_provider->capabilities & RR_Capability_SourceOutput))
+            return BadValue;
+    }
+
+    pScreen = provider->pScreen;
+    pScrPriv = rrGetScrPriv(pScreen);
+
+    pScrPriv->rrProviderSetOutputSource(pScreen, provider, source_provider);
+
+    RRTellChanged (pScreen);
+
+    return Success;
+}
+
 RRProviderPtr
 RRProviderCreate(ScreenPtr pScreen, const char *name,
                  int nameLength)
commit bec4cb72c55bb6dee09c65c0844af201067a090f
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu May 24 15:47:22 2012 +0100

    randr: hook up output slave to screen resources return
    
    When the client asks for the screen resources list, it will now
    get a list of crtc/outputs for the master + all attached slaves,
    this will let randr configure all attached slave devices properly.
    
    Keith asked I merge the two functions, but not just yet, the current
    multi screen code doesn't handle primary yet properly, will fix it up later.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index c564d1f..9bf9316 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -292,6 +292,172 @@ ProcRRSetScreenSize(ClientPtr client)
     return Success;
 }
 
+
+#define update_totals(gpuscreen, pScrPriv) do {       \
+    total_crtcs += pScrPriv->numCrtcs;                \
+    total_outputs += pScrPriv->numOutputs;            \
+    modes = RRModesForScreen(gpuscreen, &num_modes);  \
+    if (!modes)                                       \
+        return BadAlloc;                              \
+    for (j = 0; j < num_modes; j++)                   \
+        total_name_len += modes[j]->mode.nameLength;  \
+    total_modes += num_modes;                         \
+    free(modes);                                      \
+} while(0)
+
+static inline void swap_modeinfos(xRRModeInfo *modeinfos, int i)
+{
+    swapl(&modeinfos[i].id);
+    swaps(&modeinfos[i].width);
+    swaps(&modeinfos[i].height);
+    swapl(&modeinfos[i].dotClock);
+    swaps(&modeinfos[i].hSyncStart);
+    swaps(&modeinfos[i].hSyncEnd);
+    swaps(&modeinfos[i].hTotal);
+    swaps(&modeinfos[i].hSkew);
+    swaps(&modeinfos[i].vSyncStart);
+    swaps(&modeinfos[i].vSyncEnd);
+    swaps(&modeinfos[i].vTotal);
+    swaps(&modeinfos[i].nameLength);
+    swapl(&modeinfos[i].modeFlags);
+}
+
+#define update_arrays(gpuscreen, pScrPriv) do {            \
+    for (j = 0; j < pScrPriv->numCrtcs; j++) {             \
+        crtcs[crtc_count] = pScrPriv->crtcs[j]->id;        \
+        if (client->swapped)                               \
+            swapl(&crtcs[crtc_count]);                     \
+        crtc_count++;                                      \
+    }                                                      \
+    for (j = 0; j < pScrPriv->numOutputs; j++) {           \
+        outputs[output_count] = pScrPriv->outputs[j]->id;  \
+        if (client->swapped)                               \
+            swapl(&outputs[output_count]);                 \
+        output_count++;                                    \
+    }                                                      \
+    {                                                      \
+        RRModePtr mode;                                    \
+        modes = RRModesForScreen(gpuscreen, &num_modes);   \
+        for (j = 0; j < num_modes; j++) {                  \
+            mode = modes[j];                               \
+            modeinfos[mode_count] = mode->mode;            \
+            if (client->swapped) {                         \
+                swap_modeinfos(modeinfos, mode_count);     \
+            }                                              \
+            memcpy(names, mode->name, mode->mode.nameLength); \
+            names += mode->mode.nameLength;                \
+            mode_count++;                                  \
+        }                                                  \
+        free(modes);                                       \
+    }                                                      \
+    } while (0)
+
+static int
+rrGetMultiScreenResources(ClientPtr client, Bool query, ScreenPtr pScreen)
+{
+    int j;
+    int total_crtcs, total_outputs, total_modes, total_name_len;
+    int crtc_count, output_count, mode_count;
+    ScreenPtr iter;
+    rrScrPrivPtr pScrPriv;
+    int num_modes;
+    RRModePtr *modes;
+    xRRGetScreenResourcesReply rep;
+    unsigned long extraLen;
+    CARD8 *extra;
+    RRCrtc *crtcs;
+    RROutput *outputs;
+    xRRModeInfo *modeinfos;
+    CARD8 *names;
+
+    /* we need to iterate all the GPU masters and all their output slaves */
+    total_crtcs = 0;
+    total_outputs = 0;
+    total_modes = 0;
+    total_name_len = 0;
+
+    pScrPriv = rrGetScrPriv(pScreen);
+
+    if (query && pScrPriv)
+        if (!RRGetInfo(pScreen, query))
+            return BadAlloc;
+
+    update_totals(pScreen, pScrPriv);
+
+    xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head) {
+        pScrPriv = rrGetScrPriv(iter);
+
+        if (query)
+          if (!RRGetInfo(iter, query))
+            return BadAlloc;
+        update_totals(iter, pScrPriv);
+    }
+
+    ErrorF("reporting %d %d %d %d\n", total_crtcs, total_outputs, total_modes, total_name_len);
+
+    pScrPriv = rrGetScrPriv(pScreen);
+    rep.pad = 0;
+    rep.type = X_Reply;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    rep.timestamp = pScrPriv->lastSetTime.milliseconds;
+    rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
+    rep.nCrtcs = total_crtcs;
+    rep.nOutputs = total_outputs;
+    rep.nModes = total_modes;
+    rep.nbytesNames = total_name_len;
+
+    rep.length = (total_crtcs + total_outputs + total_modes * bytes_to_int32(SIZEOF(xRRModeInfo)) +
+                  bytes_to_int32(rep.nbytesNames));
+
+    extraLen = rep.length << 2;
+    if (extraLen) {
+        extra = malloc(extraLen);
+        if (!extra) {
+            return BadAlloc;
+        }
+    }
+    else
+        extra = NULL;
+
+    crtcs = (RRCrtc *)extra;
+    outputs = (RROutput *)(crtcs + total_crtcs);
+    modeinfos = (xRRModeInfo *)(outputs + total_outputs);
+    names = (CARD8 *)(modeinfos + total_modes);
+
+    /* TODO primary */
+    crtc_count = 0;
+    output_count = 0;
+    mode_count = 0;
+
+    pScrPriv = rrGetScrPriv(pScreen);
+    update_arrays(pScreen, pScrPriv);
+
+    xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head) {
+        pScrPriv = rrGetScrPriv(iter);
+
+        update_arrays(iter, pScrPriv);
+    }
+
+    assert(bytes_to_int32((char *) names - (char *) extra) == rep.length);
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.timestamp);
+        swapl(&rep.configTimestamp);
+        swaps(&rep.nCrtcs);
+        swaps(&rep.nOutputs);
+        swaps(&rep.nModes);
+        swaps(&rep.nbytesNames);
+    }
+    WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *) &rep);
+    if (extraLen) {
+        WriteToClient(client, extraLen, (char *) extra);
+        free(extra);
+    }
+    return Success;
+}
+
 static int
 rrGetScreenResources(ClientPtr client, Bool query)
 {
@@ -321,6 +487,9 @@ rrGetScreenResources(ClientPtr client, Bool query)
         if (!RRGetInfo(pScreen, query))
             return BadAlloc;
 
+    if (!xorg_list_is_empty(&pScreen->output_slave_list))
+        return rrGetMultiScreenResources(client, query, pScreen);
+
     if (!pScrPriv) {
         rep.type = X_Reply;
         rep.sequenceNumber = client->sequence;
commit 88bc02bfaae2c15a30c606d34cf7940e6ad5ea14
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Jun 18 14:11:24 2012 +0100

    xf86/crtc: add new interface to detach slave crtcs
    
    This will detach any scanout pixmaps attached to slave crtcs.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 31efd83..6a005cd 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -3228,3 +3228,23 @@ xf86ProviderSetup(ScrnInfoPtr scrn,
 #endif
 }
 
+void
+xf86DetachAllCrtc(ScrnInfoPtr scrn)
+{
+        xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+        int i;
+
+        for (i = 0; i < xf86_config->num_crtc; i++) {
+            xf86CrtcPtr crtc = xf86_config->crtc[i];
+
+            if (crtc->randr_crtc)
+                RRCrtcDetachScanoutPixmap(crtc->randr_crtc);
+
+            /* dpms off */
+            (*crtc->funcs->dpms) (crtc, DPMSModeOff);
+            /* force a reset the next time its used */
+            crtc->randr_crtc->mode = NULL;
+            crtc->mode.HDisplay = 0;
+            crtc->x = crtc->y = 0;
+        }
+}
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 25fb34d..38b9ea5 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -1014,4 +1014,7 @@ extern _X_EXPORT void
 xf86ProviderSetup(ScrnInfoPtr scrn,
                   const xf86ProviderFuncsRec * funcs, const char *name);
 
+extern _X_EXPORT void
+xf86DetachAllCrtc(ScrnInfoPtr scrn);
+
 #endif                          /* _XF86CRTC_H_ */
commit 9b8217f9ef6279fff6628631d18497bed0343ef9
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jun 14 15:24:46 2012 +0100

    dix/pixmap: track dirty pixmaps in server. (v4)
    
    This adds two functions for drivers to use directly to keep a
    linked list of slave pixmaps to do damage tracking on and keep
    updated. It also adds a helper function that drivers may optionally
    call to do a simple copy area damage update.
    
    v2: use damage.h not damagestr.h, fixes ephyr build.
    
    v3: address ajax review: use slave_dst, drop unused dst member.
    
    v4: check DamageCreate return, add SourceValidate comment,
    add a comment addressing possible optimisation possibility
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 29ac5a4..bc803d7 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3742,6 +3742,7 @@ static int init_screen(ScreenPtr pScreen, int i, Bool gpu)
     pScreen->ClipNotify = 0;    /* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
 
+    xorg_list_init(&pScreen->pixmap_dirty_list);
     xorg_list_init(&pScreen->unattached_list);
     xorg_list_init(&pScreen->output_slave_list);
 
diff --git a/dix/pixmap.c b/dix/pixmap.c
index 11b1b04..9163e99 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -158,3 +158,109 @@ PixmapPtr PixmapShareToSlave(PixmapPtr pixmap, ScreenPtr slave)
 
     return spix;
 }
+
+Bool
+PixmapStartDirtyTracking(PixmapPtr src,
+                         PixmapPtr slave_dst,
+                         int x, int y)
+{
+    ScreenPtr screen = src->drawable.pScreen;
+    PixmapDirtyUpdatePtr dirty_update;
+
+    dirty_update = calloc(1, sizeof(PixmapDirtyUpdateRec));
+    if (!dirty_update)
+        return FALSE;
+
+    dirty_update->src = src;
+    dirty_update->slave_dst = slave_dst;
+    dirty_update->x = x;
+    dirty_update->y = y;
+
+    dirty_update->damage = DamageCreate(NULL, NULL,
+                                        DamageReportNone,
+                                        TRUE, src->drawable.pScreen,
+                                        src->drawable.pScreen);
+    if (!dirty_update->damage) {
+        free(dirty_update);
+        return FALSE;
+    }
+
+    DamageRegister(&src->drawable, dirty_update->damage);
+    xorg_list_add(&dirty_update->ent, &screen->pixmap_dirty_list);
+    return TRUE;
+}
+
+Bool
+PixmapStopDirtyTracking(PixmapPtr src, PixmapPtr slave_dst)
+{
+    ScreenPtr screen = src->drawable.pScreen;
+    PixmapDirtyUpdatePtr ent, safe;
+
+    xorg_list_for_each_entry_safe(ent, safe, &screen->pixmap_dirty_list, ent) {
+        if (ent->src == src && ent->slave_dst == slave_dst) {
+            DamageUnregister(&src->drawable, ent->damage);
+            DamageDestroy(ent->damage);
+            xorg_list_del(&ent->ent);
+            free(ent);
+        }
+    }
+    return TRUE;
+}
+
+/*
+ * this function can possibly be improved and optimised, by clipping
+ * instead of iterating
+ */
+Bool PixmapSyncDirtyHelper(PixmapDirtyUpdatePtr dirty, RegionPtr dirty_region)
+{
+    ScreenPtr pScreen = dirty->src->drawable.pScreen;
+    int n;
+    BoxPtr b;
+    RegionPtr region = DamageRegion(dirty->damage);
+    GCPtr pGC;
+    PixmapPtr dst;
+    SourceValidateProcPtr SourceValidate;
+
+    /*
+     * SourceValidate is used by the software cursor code
+     * to pull the cursor off of the screen when reading
+     * bits from the frame buffer. Bypassing this function
+     * leaves the software cursor in place
+     */
+    SourceValidate = pScreen->SourceValidate;
+    pScreen->SourceValidate = NULL;
+
+    RegionTranslate(dirty_region, dirty->x, dirty->y);
+    RegionIntersect(dirty_region, dirty_region, region);
+
+    if (RegionNil(dirty_region)) {
+        RegionUninit(dirty_region);
+        return FALSE;
+    }
+
+    dst = dirty->slave_dst->master_pixmap;
+
+    RegionTranslate(dirty_region, -dirty->x, -dirty->y);
+    n = RegionNumRects(dirty_region);
+    b = RegionRects(dirty_region);
+
+    pGC = GetScratchGC(dirty->src->drawable.depth, pScreen);
+    ValidateGC(&dst->drawable, pGC);
+
+    while (n--) {
+        BoxRec dst_box;
+        int w, h;
+
+        dst_box = *b;
+        w = dst_box.x2 - dst_box.x1;
+        h = dst_box.y2 - dst_box.y1;
+
+        pGC->ops->CopyArea(&dirty->src->drawable, &dst->drawable, pGC,
+                           dirty->x + dst_box.x1, dirty->y + dst_box.y1, w, h, dst_box.x1, dst_box.y1);
+        b++;
+    }
+    FreeScratchGC(pGC);
+
+    pScreen->SourceValidate = SourceValidate;
+    return TRUE;
+}
diff --git a/include/pixmap.h b/include/pixmap.h
index 8c523bd..921a94d 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -49,6 +49,7 @@ SOFTWARE.
 
 #include "misc.h"
 #include "screenint.h"
+#include "regionstr.h"
 
 /* types for Drawable */
 #define DRAWABLE_WINDOW 0
@@ -73,6 +74,8 @@ SOFTWARE.
 typedef struct _Drawable *DrawablePtr;
 typedef struct _Pixmap *PixmapPtr;
 
+typedef struct _PixmapDirtyUpdate *PixmapDirtyUpdatePtr;
+
 typedef union _PixUnion {
     PixmapPtr pixmap;
     unsigned long pixel;
@@ -112,4 +115,17 @@ extern _X_EXPORT void FreePixmap(PixmapPtr /*pPixmap */ );
 extern _X_EXPORT PixmapPtr
 PixmapShareToSlave(PixmapPtr pixmap, ScreenPtr slave);
 
+extern _X_EXPORT Bool
+PixmapStartDirtyTracking(PixmapPtr src,
+                         PixmapPtr slave_dst,
+                         int x, int y);
+
+extern _X_EXPORT Bool
+PixmapStopDirtyTracking(PixmapPtr src, PixmapPtr slave_dst);
+
+/* helper function, drivers can do this themselves if they can do it more
+   efficently */
+extern _X_EXPORT Bool
+PixmapSyncDirtyHelper(PixmapDirtyUpdatePtr dirty, RegionPtr dirty_region);
+
 #endif                          /* PIXMAP_H */
diff --git a/include/pixmapstr.h b/include/pixmapstr.h
index 40af5c4..2a1ef9b 100644
--- a/include/pixmapstr.h
+++ b/include/pixmapstr.h
@@ -50,6 +50,7 @@ SOFTWARE.
 #include "screenint.h"
 #include "regionstr.h"
 #include "privates.h"
+#include "damage.h"
 
 typedef struct _Drawable {
     unsigned char type;         /* DRAWABLE_<type> */
@@ -84,6 +85,13 @@ typedef struct _Pixmap {
     PixmapPtr master_pixmap;    /* pointer to master copy of pixmap for pixmap sharing */
 } PixmapRec;
 
+typedef struct _PixmapDirtyUpdate {
+    PixmapPtr src, slave_dst;
+    int x, y;
+    DamagePtr damage;
+    struct xorg_list ent;
+} PixmapDirtyUpdateRec;
+
 static inline void
 PixmapBox(BoxPtr box, PixmapPtr pixmap)
 {
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 3a738d3..5ef37ed 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -505,6 +505,8 @@ typedef struct _Screen {
 
     StartPixmapTrackingProcPtr StartPixmapTracking;
     StopPixmapTrackingProcPtr StopPixmapTracking;
+
+    struct xorg_list pixmap_dirty_list;
 } ScreenRec;
 
 static inline RegionPtr
commit c5cc2a8243c5e6bf454af989b7512ec7e20fc3f2
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue May 29 14:41:39 2012 +0100

    randr: check the screen size bounds against the master
    
    The master contains the complete screen size bounds, so check
    the width/height against it.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index e5fe059..949ae60 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1125,6 +1125,16 @@ ProcRRSetCrtcConfig(ClientPtr client)
             int source_height;
             PictTransform transform;
             struct pixman_f_transform f_transform, f_inverse;
+            int width, height;
+
+            if (pScreen->isGPU) {
+                width = pScreen->current_master->width;
+                height = pScreen->current_master->height;
+            }
+            else {
+                width = pScreen->width;
+                height = pScreen->height;
+            }
 
             RRTransformCompute(stuff->x, stuff->y,
                                mode->mode.width, mode->mode.height,
@@ -1134,13 +1144,13 @@ ProcRRSetCrtcConfig(ClientPtr client)
 
             RRModeGetScanoutSize(mode, &transform, &source_width,
                                  &source_height);
-            if (stuff->x + source_width > pScreen->width) {
+            if (stuff->x + source_width > width) {
                 client->errorValue = stuff->x;
                 free(outputs);
                 return BadValue;
             }
 
-            if (stuff->y + source_height > pScreen->height) {
+            if (stuff->y + source_height > height) {
                 client->errorValue = stuff->y;
                 free(outputs);
                 return BadValue;
commit 26d848cb916c8a85f2c69d2aeb004665ba07bf00
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue May 29 14:35:24 2012 +0100

    randr: fix tellchanged to work with slave scanouts
    
    Tell changed need to tell only for the master pixmap,
    however it gets called from various places for slave screens,
    so convert to telling clients about changes on the master screen.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/randr/randr.c b/randr/randr.c
index 103c31e..ae81166 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -467,25 +467,37 @@ TellChanged(WindowPtr pWin, pointer value)
 void
 RRTellChanged(ScreenPtr pScreen)
 {
+    ScreenPtr master;
     rrScrPriv(pScreen);
+    rrScrPrivPtr mastersp;
     int i;
 
+    if (pScreen->isGPU) {
+        master = pScreen->current_master;
+        mastersp = rrGetScrPriv(master);
+    }
+    else {
+        master = pScreen;
+        mastersp = pScrPriv;
+    }
+
     if (pScrPriv->changed) {
         UpdateCurrentTimeIf();
-        if (pScrPriv->configChanged) {
-            pScrPriv->lastConfigTime = currentTime;
-            pScrPriv->configChanged = FALSE;
+        if (mastersp->configChanged) {
+            mastersp->lastConfigTime = currentTime;
+            mastersp->configChanged = FALSE;
         }
         pScrPriv->changed = FALSE;
-        WalkTree(pScreen, TellChanged, (pointer) pScreen);
+        mastersp->changed = FALSE;
+        WalkTree(master, TellChanged, (pointer) master);
         for (i = 0; i < pScrPriv->numOutputs; i++)
             pScrPriv->outputs[i]->changed = FALSE;
         for (i = 0; i < pScrPriv->numCrtcs; i++)
             pScrPriv->crtcs[i]->changed = FALSE;
-        if (pScrPriv->layoutChanged) {
+        if (mastersp->layoutChanged) {
             pScrPriv->layoutChanged = FALSE;
-            RRPointerScreenConfigured(pScreen);
-            RRSendConfigNotify(pScreen);
+            RRPointerScreenConfigured(master);
+            RRSendConfigNotify(master);
         }
     }
 }
commit 4bf0192d810e01c89a1903cc4bc5e639fc13a547
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue May 29 14:37:11 2012 +0100

    randr: fixup constrain to work with slave screens.
    
    Current code constrains the cursor to the crtcs on the master
    device, for slave outputs to work we have to include their crtcs
    in the constrain calculations.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 29b02a9..e5fe059 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -1544,18 +1544,10 @@ ProcRRGetCrtcTransform(ClientPtr client)
     return Success;
 }
 
-void
-RRConstrainCursorHarder(DeviceIntPtr pDev, ScreenPtr pScreen, int mode, int *x,
-                        int *y)
+static Bool check_all_screen_crtcs(ScreenPtr pScreen, int *x, int *y)
 {
     rrScrPriv(pScreen);
     int i;
-
-    /* intentional dead space -> let it float */
-    if (pScrPriv->discontiguous)
-        return;
-
-    /* if we're moving inside a crtc, we're fine */
     for (i = 0; i < pScrPriv->numCrtcs; i++) {
         RRCrtcPtr crtc = pScrPriv->crtcs[i];
 
@@ -1567,8 +1559,15 @@ RRConstrainCursorHarder(DeviceIntPtr pDev, ScreenPtr pScreen, int mode, int *x,
         crtc_bounds(crtc, &left, &right, &top, &bottom);
 
         if ((*x >= left) && (*x < right) && (*y >= top) && (*y < bottom))
-            return;
+            return TRUE;
     }
+    return FALSE;
+}
+
+static Bool constrain_all_screen_crtcs(DeviceIntPtr pDev, ScreenPtr pScreen, int *x, int *y)
+{
+    rrScrPriv(pScreen);
+    int i;
 
     /* if we're trying to escape, clamp to the CRTC we're coming from */
     for (i = 0; i < pScrPriv->numCrtcs; i++) {
@@ -1592,7 +1591,43 @@ RRConstrainCursorHarder(DeviceIntPtr pDev, ScreenPtr pScreen, int mode, int *x,
             if (*y >= bottom)
                 *y = bottom - 1;
 
-            return;
+            return TRUE;
         }
     }
+    return FALSE;
+}
+
+void
+RRConstrainCursorHarder(DeviceIntPtr pDev, ScreenPtr pScreen, int mode, int *x,
+                        int *y)
+{
+    rrScrPriv(pScreen);
+    Bool ret;
+    ScreenPtr slave;
+
+    /* intentional dead space -> let it float */
+    if (pScrPriv->discontiguous)
+        return;
+
+    /* if we're moving inside a crtc, we're fine */
+    ret = check_all_screen_crtcs(pScreen, x, y);
+    if (ret == TRUE)
+        return;
+
+    xorg_list_for_each_entry(slave, &pScreen->output_slave_list, output_head) {
+        ret = check_all_screen_crtcs(slave, x, y);
+        if (ret == TRUE)
+            return;
+    }
+
+    /* if we're trying to escape, clamp to the CRTC we're coming from */
+    ret = constrain_all_screen_crtcs(pDev, pScreen, x, y);
+    if (ret == TRUE)
+        return;
+
+    xorg_list_for_each_entry(slave, &pScreen->output_slave_list, output_head) {
+        ret = constrain_all_screen_crtcs(pDev, slave, x, y);
+        if (ret == TRUE)
+            return;
+    }
 }
commit 2ed3f64d9d453628ab5c03b8aee006093019c933
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jun 20 12:37:26 2012 +0100

    xf86: add initial scanout pixmap support (v2)
    
    Add the simple passthrough interface for drivers to use,
    so they can set scanout pixmaps.
    
    v2: detach scanout pixmap properly.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 0bf14eb..31efd83 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -734,6 +734,9 @@ xf86CrtcCloseScreen(ScreenPtr screen)
     for (c = 0; c < config->num_crtc; c++) {
         xf86CrtcPtr crtc = config->crtc[c];
 
+        if (crtc->randr_crtc->scanout_pixmap)
+            RRCrtcDetachScanoutPixmap(crtc->randr_crtc);
+
         crtc->randr_crtc = NULL;
     }
     /* detach any providers */
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 58d8cec..25fb34d 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -218,6 +218,11 @@ typedef struct _xf86CrtcFuncs {
     void
      (*set_origin) (xf86CrtcPtr crtc, int x, int y);
 
+    /**
+     */
+    Bool
+    (*set_scanout_pixmap)(xf86CrtcPtr crtc, PixmapPtr pixmap);
+
 } xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
 
 #define XF86_CRTC_VERSION 4
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 41c0b11..ebea4d5 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1790,6 +1790,15 @@ xf86RandR14ProviderGetProperty(ScreenPtr pScreen,
 }
 
 static Bool
+xf86CrtcSetScanoutPixmap(RRCrtcPtr randr_crtc, PixmapPtr pixmap)
+{
+    xf86CrtcPtr crtc = randr_crtc->devPrivate;
+    if (!crtc->funcs->set_scanout_pixmap)
+        return FALSE;
+    return crtc->funcs->set_scanout_pixmap(crtc, pixmap);
+}
+
+static Bool
 xf86RandR12Init12(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
@@ -1814,6 +1823,7 @@ xf86RandR12Init12(ScreenPtr pScreen)
 
     rp->rrProviderSetProperty = xf86RandR14ProviderSetProperty;
     rp->rrProviderGetProperty = xf86RandR14ProviderGetProperty;
+    rp->rrCrtcSetScanoutPixmap = xf86CrtcSetScanoutPixmap;
 
     pScrn->PointerMoved = xf86RandR12PointerMoved;
     pScrn->ChangeGamma = xf86RandR12ChangeGamma;
commit f2da2c12042d3447b1c954e7301632d174a08b4f
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jun 20 12:37:12 2012 +0100

    randr: add initial scanout pixmap support (v3)
    
    When randr notices a crtc configuration request for a slave device,
    it checks if the slave allocated pixmap exists and is suitable,
    if not it allocates a new shared pixmap from the master, shares
    it to the slave, and starts the master tracking damage to it,
    to keep it updated from the current front pixmap.
    
    If the resize means the crtc is no longer used it will destroy
    the slave pixmap.
    
    This adds the concept of a scanout_pixmap to the randr_crtc object,
    and also adds a master pixmap pointer to the pixmap object, along
    with defining some pixmap helper functions for getting pixmap box/regions.
    
    v2: split out pixmap sharing to a separate function.
    
    v3: update for void *
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/pixmap.c b/dix/pixmap.c
index 0c85c3f..11b1b04 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -129,3 +129,32 @@ FreePixmap(PixmapPtr pPixmap)
     dixFiniPrivates(pPixmap, PRIVATE_PIXMAP);
     free(pPixmap);
 }
+
+PixmapPtr PixmapShareToSlave(PixmapPtr pixmap, ScreenPtr slave)
+{
+    PixmapPtr spix;
+    int ret;
+    void *handle;
+    ScreenPtr master = pixmap->drawable.pScreen;
+    int depth = pixmap->drawable.depth;
+
+    ret = master->SharePixmapBacking(pixmap, slave, &handle);
+    if (ret == FALSE)
+        return NULL;
+
+    spix = slave->CreatePixmap(slave, 0, 0, depth,
+                               CREATE_PIXMAP_USAGE_SHARED);
+    slave->ModifyPixmapHeader(spix, pixmap->drawable.width,
+                              pixmap->drawable.height, depth, 0,
+                              pixmap->devKind, NULL);
+
+    spix->master_pixmap = pixmap;
+
+    ret = slave->SetSharedPixmapBacking(spix, handle);
+    if (ret == FALSE) {
+        slave->DestroyPixmap(spix);
+        return NULL;
+    }
+
+    return spix;
+}
diff --git a/include/pixmap.h b/include/pixmap.h
index 9bb5bb7..8c523bd 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -109,4 +109,7 @@ extern _X_EXPORT PixmapPtr AllocatePixmap(ScreenPtr /*pScreen */ ,
 
 extern _X_EXPORT void FreePixmap(PixmapPtr /*pPixmap */ );
 
+extern _X_EXPORT PixmapPtr
+PixmapShareToSlave(PixmapPtr pixmap, ScreenPtr slave);
+
 #endif                          /* PIXMAP_H */
diff --git a/include/pixmapstr.h b/include/pixmapstr.h
index 0800c62..40af5c4 100644
--- a/include/pixmapstr.h
+++ b/include/pixmapstr.h
@@ -80,6 +80,28 @@ typedef struct _Pixmap {
     short screen_y;
 #endif
     unsigned usage_hint;        /* see CREATE_PIXMAP_USAGE_* */
+
+    PixmapPtr master_pixmap;    /* pointer to master copy of pixmap for pixmap sharing */
 } PixmapRec;
 
+static inline void
+PixmapBox(BoxPtr box, PixmapPtr pixmap)
+{
+    box->x1 = 0;
+    box->x2 = pixmap->drawable.width;
+
+    box->y1 = 0;
+    box->y2 = pixmap->drawable.height;
+}
+
+
+static inline void
+PixmapRegionInit(RegionPtr region, PixmapPtr pixmap)
+{
+    BoxRec box;
+
+    PixmapBox(&box, pixmap);
+    RegionInit(region, &box, 1);
+}
+
 #endif                          /* PIXMAPSTRUCT_H */
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 3dac633..ac93414 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -127,6 +127,8 @@ struct _rrCrtc {
     PictTransform transform;
     struct pict_f_transform f_transform;
     struct pict_f_transform f_inverse;
+
+    PixmapPtr scanout_pixmap;
 };
 
 struct _rrOutput {
@@ -242,6 +244,8 @@ typedef Bool (*RRSetConfigProcPtr) (ScreenPtr pScreen,
 
 #endif
 
+typedef Bool (*RRCrtcSetScanoutPixmapProcPtr)(RRCrtcPtr crtc, PixmapPtr pixmap);
+
 typedef struct _rrScrPriv {
     /*
      * 'public' part of the structure; DDXen fill this in
@@ -265,6 +269,8 @@ typedef struct _rrScrPriv {
     RRGetPanningProcPtr rrGetPanning;
     RRSetPanningProcPtr rrSetPanning;
 #endif
+    /* TODO #if RANDR_15_INTERFACE */
+    RRCrtcSetScanoutPixmapProcPtr rrCrtcSetScanoutPixmap;
 
     RRProviderGetPropertyProcPtr rrProviderGetProperty;
     RRProviderSetPropertyProcPtr rrProviderSetProperty;
@@ -649,6 +655,12 @@ extern _X_EXPORT void
  RRCrtcInitErrorValue(void);
 
 /*
+ * Detach and free a scanout pixmap
+ */
+extern _X_EXPORT void
+ RRCrtcDetachScanoutPixmap(RRCrtcPtr crtc);
+
+/*
  * Crtc dispatch
  */
 
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 0c596dd..29b02a9 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -367,6 +367,154 @@ RRComputeContiguity(ScreenPtr pScreen)
     pScrPriv->discontiguous = discontiguous;
 }
 
+void
+RRCrtcDetachScanoutPixmap(RRCrtcPtr crtc)
+{
+    ScreenPtr master = crtc->pScreen->current_master;
+    int ret;
+    PixmapPtr mscreenpix;
+    rrScrPriv(crtc->pScreen);
+
+    mscreenpix = master->GetScreenPixmap(master);
+
+    ret = pScrPriv->rrCrtcSetScanoutPixmap(crtc, NULL);
+    if (crtc->scanout_pixmap) {
+        master->StopPixmapTracking(mscreenpix, crtc->scanout_pixmap);
+        master->DestroyPixmap(crtc->scanout_pixmap->master_pixmap);
+        crtc->pScreen->DestroyPixmap(crtc->scanout_pixmap);
+    }
+    crtc->scanout_pixmap = NULL;
+    RRCrtcChanged(crtc, TRUE);
+}
+
+static Bool
+rrCreateSharedPixmap(RRCrtcPtr crtc, int width, int height,
+                     int x, int y)
+{
+    PixmapPtr mpix, spix;
+    ScreenPtr master = crtc->pScreen->current_master;
+    Bool ret;
+    int depth;
+    PixmapPtr mscreenpix;
+    PixmapPtr protopix = crtc->pScreen->current_master->GetScreenPixmap(crtc->pScreen->current_master);
+    rrScrPriv(crtc->pScreen);
+
+    /* create a pixmap on the master screen,
+       then get a shared handle for it
+       create a shared pixmap on the slave screen using the handle
+       set the master screen to do dirty updates to the shared pixmap
+       from the screen pixmap.
+       set slave screen to scanout shared linear pixmap
+    */
+
+    mscreenpix = master->GetScreenPixmap(master);
+    depth = protopix->drawable.depth;
+
+    if (crtc->scanout_pixmap)
+        RRCrtcDetachScanoutPixmap(crtc);
+
+    if (width == 0 && height == 0) {
+        return TRUE;
+    }
+
+    mpix = master->CreatePixmap(master, width, height, depth,
+                                CREATE_PIXMAP_USAGE_SHARED);
+    if (!mpix)
+        return FALSE;
+
+    spix = PixmapShareToSlave(mpix, crtc->pScreen);
+    if (spix == NULL) {
+        master->DestroyPixmap(mpix);
+        return FALSE;
+    }
+
+    ret = pScrPriv->rrCrtcSetScanoutPixmap(crtc, spix);
+    if (ret == FALSE) {
+        ErrorF("failed to set shadow slave pixmap\n");
+        return FALSE;
+    }
+
+    crtc->scanout_pixmap = spix;
+
+    master->StartPixmapTracking(mscreenpix, spix, x, y);
+    return TRUE;
+}
+
+static Bool
+rrCheckPixmapBounding(ScreenPtr pScreen,
+                      RRCrtcPtr rr_crtc, int x, int y, int w, int h)
+{
+    RegionRec root_pixmap_region, total_region, new_crtc_region;
+    int i, c;
+    BoxRec newbox;
+    BoxPtr newsize;
+    ScreenPtr slave;
+    int new_width, new_height;
+    PixmapPtr screen_pixmap = pScreen->GetScreenPixmap(pScreen);
+    rrScrPriv(pScreen);
+
+    PixmapRegionInit(&root_pixmap_region, screen_pixmap);
+    RegionInit(&total_region, NULL, 0);
+
+    /* have to iterate all the crtcs of the attached gpu masters
+       and all their output slaves */
+    for (c = 0; c < pScrPriv->numCrtcs; c++) {
+        if (pScrPriv->crtcs[c] == rr_crtc) {
+            newbox.x1 = x;
+            newbox.x2 = x + w;
+            newbox.y1 = y;
+            newbox.y2 = y + h;
+        } else {
+            if (!pScrPriv->crtcs[c]->mode)
+                continue;
+            newbox.x1 = pScrPriv->crtcs[c]->x;
+            newbox.x2 = pScrPriv->crtcs[c]->x + pScrPriv->crtcs[c]->mode->mode.width;
+            newbox.y1 = pScrPriv->crtcs[c]->y;
+            newbox.y2 = pScrPriv->crtcs[c]->y + pScrPriv->crtcs[c]->mode->mode.height;
+        }
+        RegionInit(&new_crtc_region, &newbox, 1);
+        RegionUnion(&total_region, &total_region, &new_crtc_region);
+    }
+
+    xorg_list_for_each_entry(slave, &pScreen->output_slave_list, output_head) {
+        rrScrPriv(slave);
+        for (c = 0; c < pScrPriv->numCrtcs; c++)
+            if (pScrPriv->crtcs[c] == rr_crtc) {
+                newbox.x1 = x;
+                newbox.x2 = x + w;
+                newbox.y1 = y;
+                newbox.y2 = y + h;
+            }
+            else {
+                if (!pScrPriv->crtcs[c]->mode)
+                    continue;
+                newbox.x1 = pScrPriv->crtcs[c]->x;
+                newbox.x2 = pScrPriv->crtcs[c]->x + pScrPriv->crtcs[c]->mode->mode.width;
+                newbox.y1 = pScrPriv->crtcs[c]->y;
+                newbox.y2 = pScrPriv->crtcs[c]->y + pScrPriv->crtcs[c]->mode->mode.height;
+            }
+        RegionInit(&new_crtc_region, &newbox, 1);
+        RegionUnion(&total_region, &total_region, &new_crtc_region);
+    }
+
+    newsize = RegionExtents(&total_region);
+    new_width = newsize->x2 - newsize->x1;
+    new_height = newsize->y2 - newsize->y1;
+
+    if (new_width == screen_pixmap->drawable.width &&
+        new_height == screen_pixmap->drawable.height) {
+        ErrorF("adjust shatters %d %d\n", newsize->x1, newsize->x2);
+    } else {
+        int ret;
+        rrScrPriv(pScreen);
+        ret = pScrPriv->rrScreenSetSize(pScreen,
+                                           new_width, new_height, 0, 0);
+    }
+
+    /* set shatters TODO */
+    return TRUE;
+}
+
 /*
  * Request that the Crtc be reconfigured
  */
@@ -394,6 +542,26 @@ RRCrtcSet(RRCrtcPtr crtc,
         ret = TRUE;
     }
     else {
+        if (pScreen->isGPU) {
+            ScreenPtr master = pScreen->current_master;
+            int width = 0, height = 0;
+
+            if (mode) {
+                width = mode->mode.width;
+                height = mode->mode.height;
+            }
+            ErrorF("have a master to look out for\n");
+            ret = rrCheckPixmapBounding(master, crtc,
+                                        x, y, width, height);
+            if (!ret)
+                return FALSE;
+
+            if (pScreen->current_master) {
+                ret = rrCreateSharedPixmap(crtc, width, height, x, y);
+                ErrorF("need to create shared pixmap %d", ret);
+
+            }
+        }
 #if RANDR_12_INTERFACE
         if (pScrPriv->rrCrtcSet) {
             ret = (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y,
@@ -508,6 +676,9 @@ RRCrtcDestroyResource(pointer value, XID pid)
             }
         }
     }
+
+    if (crtc->scanout_pixmap)
+        RRCrtcDetachScanoutPixmap(crtc);
     free(crtc->gammaRed);
     if (crtc->mode)
         RRModeDestroy(crtc->mode);
commit 0b0e7148925e1f835d4f4f06e402a97023531828
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu May 24 16:03:31 2012 +0100

    exa: pixmap sharing infrastructure (v3)
    
    This just adds exa interfaces for mixed exa so drivers can
    share and set shared pixmaps up correctly.
    
    v2: update for passing slave screen.
    v3: update for void *
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/exa/exa.c b/exa/exa.c
index 623ece0..d12344f 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -782,6 +782,10 @@ exaCloseScreen(ScreenPtr pScreen)
     unwrap(pExaScr, pScreen, ChangeWindowAttributes);
     unwrap(pExaScr, pScreen, BitmapToRegion);
     unwrap(pExaScr, pScreen, CreateScreenResources);
+    if (pExaScr->SavedSharePixmapBacking)
+        unwrap(pExaScr, pScreen, SharePixmapBacking);
+    if (pExaScr->SavedSetSharedPixmapBacking)
+        unwrap(pExaScr, pScreen, SetSharedPixmapBacking);
     unwrap(pExaScr, ps, Composite);
     if (pExaScr->SavedGlyphs)
         unwrap(pExaScr, ps, Glyphs);
@@ -976,6 +980,9 @@ exaDriverInit(ScreenPtr pScreen, ExaDriverPtr pScreenInfo)
                 wrap(pExaScr, pScreen, DestroyPixmap, exaDestroyPixmap_mixed);
                 wrap(pExaScr, pScreen, ModifyPixmapHeader,
                      exaModifyPixmapHeader_mixed);
+                wrap(pExaScr, pScreen, SharePixmapBacking, exaSharePixmapBacking_mixed);
+                wrap(pExaScr, pScreen, SetSharedPixmapBacking, exaSetSharedPixmapBacking_mixed);
+
                 pExaScr->do_migration = exaDoMigration_mixed;
                 pExaScr->pixmap_has_gpu_copy = exaPixmapHasGpuCopy_mixed;
                 pExaScr->do_move_in_pixmap = exaMoveInPixmap_mixed;
diff --git a/exa/exa.h b/exa/exa.h
index 8a6539f..be022b2 100644
--- a/exa/exa.h
+++ b/exa/exa.h
@@ -39,7 +39,7 @@
 #include "fb.h"
 
 #define EXA_VERSION_MAJOR   2
-#define EXA_VERSION_MINOR   5
+#define EXA_VERSION_MINOR   6
 #define EXA_VERSION_RELEASE 0
 
 typedef struct _ExaOffscreenArea ExaOffscreenArea;
@@ -694,6 +694,10 @@ typedef struct _ExaDriver {
                             int depth, int usage_hint, int bitsPerPixel,
                             int *new_fb_pitch);
     /** @} */
+    Bool (*SharePixmapBacking)(PixmapPtr pPixmap, ScreenPtr slave, void **handle_p);
+
+    Bool (*SetSharedPixmapBacking)(PixmapPtr pPixmap, void *handle);
+
 } ExaDriverRec, *ExaDriverPtr;
 
 /** @name EXA driver flags
diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c
index 0681731..0fb4091 100644
--- a/exa/exa_mixed.c
+++ b/exa/exa_mixed.c
@@ -294,3 +294,36 @@ exaPixmapHasGpuCopy_mixed(PixmapPtr pPixmap)
 
     return ret;
 }
+
+Bool
+exaSharePixmapBacking_mixed(PixmapPtr pPixmap, ScreenPtr slave, void **handle_p)
+{
+    ScreenPtr pScreen = pPixmap->drawable.pScreen;
+    ExaScreenPriv(pScreen);
+    Bool ret = FALSE;
+
+    exaMoveInPixmap(pPixmap);
+    /* get the driver to give us a handle */
+    if (pExaScr->info->SharePixmapBacking)
+        ret = pExaScr->info->SharePixmapBacking(pPixmap, slave, handle_p);
+
+    return ret;
+}
+
+Bool
+exaSetSharedPixmapBacking_mixed(PixmapPtr pPixmap, void *handle)
+{
+    ScreenPtr pScreen = pPixmap->drawable.pScreen;
+    ExaScreenPriv(pScreen);
+    Bool ret = FALSE;
+
+    if (pExaScr->info->SetSharedPixmapBacking)
+        ret = pExaScr->info->SetSharedPixmapBacking(pPixmap, handle);
+
+    if (ret == TRUE)
+        exaMoveInPixmap(pPixmap);
+
+    return ret;
+}
+
+
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 68eadc5..ea7e7fa 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -163,6 +163,8 @@ typedef struct {
     BitmapToRegionProcPtr SavedBitmapToRegion;
     CreateScreenResourcesProcPtr SavedCreateScreenResources;
     ModifyPixmapHeaderProcPtr SavedModifyPixmapHeader;
+    SharePixmapBackingProcPtr SavedSharePixmapBacking;
+    SetSharedPixmapBackingProcPtr SavedSetSharedPixmapBacking;
     SourceValidateProcPtr SavedSourceValidate;
     CompositeProcPtr SavedComposite;
     TrianglesProcPtr SavedTriangles;
@@ -658,6 +660,11 @@ void
 void
  exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg);
 
+Bool
+exaSetSharedPixmapBacking_mixed(PixmapPtr pPixmap, void *handle);
+Bool
+exaSharePixmapBacking_mixed(PixmapPtr pPixmap, ScreenPtr slave, void **handle_p);
+
 /* exa_render.c */
 Bool
  exaOpReadsDestination(CARD8 op);
commit fd6c1bf0a3efced3ad4623dbd4716230a5f2419e
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu May 24 16:03:19 2012 +0100

    dix: pixmap sharing infrastructure (v3)
    
    This is a hooks for pixmap sharing and tracking.
    
    The pixmap sharing ones get an integer handle for the pixmap
    and use a handle to be the backing for a pixmap.
    
    The tracker interface is to be used when a GPU needs to
    track pixmaps to be updated for another GPU.
    
    v2: pass slave to sharing so it can use it to work out driver.
    
    v3: use void * as per keithp's suggestion.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 7efc5c3..3a738d3 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -179,6 +179,8 @@ typedef void (*ClipNotifyProcPtr) (WindowPtr /*pWindow */ ,
 #define CREATE_PIXMAP_USAGE_BACKING_PIXMAP              2
 /* pixmap will contain a glyph */
 #define CREATE_PIXMAP_USAGE_GLYPH_PICTURE               3
+/* pixmap will be shared */
+#define CREATE_PIXMAP_USAGE_SHARED                      4
 
 typedef PixmapPtr (*CreatePixmapProcPtr) (ScreenPtr /*pScreen */ ,
                                           int /*width */ ,
@@ -339,6 +341,16 @@ typedef void (*DeviceCursorCleanupProcPtr) (DeviceIntPtr /* pDev */ ,
 typedef void (*ConstrainCursorHarderProcPtr) (DeviceIntPtr, ScreenPtr, int,
                                               int *, int *);
 
+
+typedef Bool (*SharePixmapBackingProcPtr)(PixmapPtr, ScreenPtr, void **);
+
+typedef Bool (*SetSharedPixmapBackingProcPtr)(PixmapPtr, void *);
+
+typedef Bool (*StartPixmapTrackingProcPtr)(PixmapPtr, PixmapPtr,
+                                           int x, int y);
+
+typedef Bool (*StopPixmapTrackingProcPtr)(PixmapPtr, PixmapPtr);
+
 typedef struct _Screen {
     int myNum;                  /* index of this instance in Screens[] */
     ATOM id;
@@ -488,6 +500,11 @@ typedef struct _Screen {
     struct xorg_list output_slave_list;
     struct xorg_list output_head;
 
+    SharePixmapBackingProcPtr SharePixmapBacking;
+    SetSharedPixmapBackingProcPtr SetSharedPixmapBacking;
+
+    StartPixmapTrackingProcPtr StartPixmapTracking;
+    StopPixmapTrackingProcPtr StopPixmapTracking;
 } ScreenRec;
 
 static inline RegionPtr
commit 382dd45bb88fa92764bf0ecd655cb9890eb84960
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu May 24 15:39:05 2012 +0100

    dix: add ability to link output slave gpus to the current gpu (v1.1)
    
    Just add the interfaces to attach/detach output slaves, and
    a linked list to keep track of them. Hook up the randr providers
    list to include these slaves.
    
    v1.1: add another assert to the add path.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 9e84621..29ac5a4 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3743,6 +3743,7 @@ static int init_screen(ScreenPtr pScreen, int i, Bool gpu)
     pScreen->CreateScreenResources = 0;
 
     xorg_list_init(&pScreen->unattached_list);
+    xorg_list_init(&pScreen->output_slave_list);
 
     /*
      * This loop gets run once for every Screen that gets added,
@@ -3909,3 +3910,19 @@ DetachUnboundGPU(ScreenPtr slave)
     slave->current_master = NULL;
 }
 
+void
+AttachOutputGPU(ScreenPtr pScreen, ScreenPtr new)
+{
+    assert(new->isGPU);
+    assert(!new->current_master);
+    xorg_list_add(&new->output_head, &pScreen->output_slave_list);
+    new->current_master = pScreen;
+}
+
+void
+DetachOutputGPU(ScreenPtr slave)
+{
+    assert(slave->isGPU);
+    xorg_list_del(&slave->output_head);
+    slave->current_master = NULL;
+}
diff --git a/include/screenint.h b/include/screenint.h
index c0c60ef..b992cc2 100644
--- a/include/screenint.h
+++ b/include/screenint.h
@@ -76,6 +76,12 @@ AttachUnboundGPU(ScreenPtr pScreen, ScreenPtr new);
 extern _X_EXPORT void
 DetachUnboundGPU(ScreenPtr unbound);
 
+extern _X_EXPORT void
+AttachOutputGPU(ScreenPtr pScreen, ScreenPtr new);
+
+extern _X_EXPORT void
+DetachOutputGPU(ScreenPtr output);
+
 typedef struct _ColormapRec *ColormapPtr;
 
 #endif                          /* SCREENINT_H */
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 6b738de..7efc5c3 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -485,6 +485,9 @@ typedef struct _Screen {
 
     ScreenPtr current_master;
 
+    struct xorg_list output_slave_list;
+    struct xorg_list output_head;
+
 } ScreenRec;
 
 static inline RegionPtr
diff --git a/randr/rrprovider.c b/randr/rrprovider.c
index aae3095..3773200 100644
--- a/randr/rrprovider.c
+++ b/randr/rrprovider.c
@@ -72,6 +72,10 @@ ProcRRGetProviders (ClientPtr client)
 
     if (pScrPriv->provider)
         total_providers++;
+    xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head) {
+        pScrPriv = rrGetScrPriv(iter);
+        total_providers += pScrPriv->provider ? 1 : 0;
+    }
     xorg_list_for_each_entry(iter, &pScreen->unattached_list, unattached_head) {
         pScrPriv = rrGetScrPriv(iter);
         total_providers += pScrPriv->provider ? 1 : 0;
@@ -105,6 +109,9 @@ ProcRRGetProviders (ClientPtr client)
 
         providers = (RRProvider *)extra;
         ADD_PROVIDER(pScreen);
+        xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head) {
+            ADD_PROVIDER(iter);
+        }
         xorg_list_for_each_entry(iter, &pScreen->unattached_list, unattached_head) {
             ADD_PROVIDER(iter);
         }
commit 05d2472cd242293a5fa205efff5734a3380072b4
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jun 14 15:03:02 2012 +0100

    xf86dga: handle DGAAvailable for gpu screens. (v2)
    
    v2: Split out DGAAvailable into two interfaces, one for calls from protocol
    decoding and one for internal usage, after discussion with ajax and keithp.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index 6416372..61612c3 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -521,18 +521,27 @@ DGAChangePixmapMode(int index, int *x, int *y, int mode)
 }
 
 Bool
-DGAAvailable(int index)
+DGAScreenAvailable(ScreenPtr pScreen)
 {
     if (!DGAScreenKeyRegistered)
         return FALSE;
 
-    if (DGA_GET_SCREEN_PRIV(screenInfo.screens[index]))
+    if (DGA_GET_SCREEN_PRIV(pScreen))
         return TRUE;
-
     return FALSE;
 }
 
 Bool
+DGAAvailable(int index)
+{
+    ScreenPtr pScreen;
+
+    assert(index < MAXSCREENS);
+    pScreen = screenInfo.screens[index];
+    return DGAScreenAvailable(pScreen);
+}
+
+Bool
 DGAActive(int index)
 {
     DGAScreenPtr pScreenPriv;
diff --git a/hw/xfree86/dixmods/extmod/dgaproc.h b/hw/xfree86/dixmods/extmod/dgaproc.h
index b4e0ddf..2c2fae0 100644
--- a/hw/xfree86/dixmods/extmod/dgaproc.h
+++ b/hw/xfree86/dixmods/extmod/dgaproc.h
@@ -64,6 +64,7 @@ extern _X_EXPORT void
  DGASelectInput(int Index, ClientPtr client, long mask);
 
 extern _X_EXPORT Bool DGAAvailable(int Index);
+extern _X_EXPORT Bool DGAScreenAvailable(ScreenPtr pScreen);
 extern _X_EXPORT Bool DGAActive(int Index);
 extern _X_EXPORT void DGAShutdown(void);
 extern _X_EXPORT void DGAInstallCmap(ColormapPtr cmap);
diff --git a/hw/xfree86/modes/xf86DiDGA.c b/hw/xfree86/modes/xf86DiDGA.c
index bb954ac..3f1a330 100644
--- a/hw/xfree86/modes/xf86DiDGA.c
+++ b/hw/xfree86/modes/xf86DiDGA.c
@@ -178,7 +178,7 @@ _xf86_di_dga_reinit_internal(ScreenPtr pScreen)
     ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
     xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
 
-    if (!DGAAvailable(pScreen->myNum))
+    if (!DGAScreenAvailable(pScreen))
         return TRUE;
 
     if (!xf86_dga_get_modes(pScreen))
diff --git a/hw/xfree86/vgahw/vgaCmap.c b/hw/xfree86/vgahw/vgaCmap.c
index a1aa405..e7a0d02 100644
--- a/hw/xfree86/vgahw/vgaCmap.c
+++ b/hw/xfree86/vgahw/vgaCmap.c
@@ -97,7 +97,7 @@ xColorItem *pdefs;
     }
 
     writeColormap = scrninfp->vtSema;
-    if (DGAAvailable(scrnIndex)) {
+    if (DGAScreenAvailable(pmap->pScreen)) {
         writeColormap = writeColormap ||
             (DGAGetDirectMode(scrnIndex) &&
              !(DGAGetFlags(scrnIndex) & XF86DGADirectColormap)) ||
commit 3cbc4c10b52896324fe14d2ab56bd54577c9294c
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jun 13 14:35:49 2012 +0100

    randr: expose unattached providers to the clients.
    
    This provides the unattached provider list to the clients.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/randr/rrprovider.c b/randr/rrprovider.c
index db7074c..aae3095 100644
--- a/randr/rrprovider.c
+++ b/randr/rrprovider.c
@@ -59,6 +59,7 @@ ProcRRGetProviders (ClientPtr client)
     unsigned int extraLen;
     RRProvider *providers;
     int total_providers = 0, count_providers = 0;
+    ScreenPtr iter;
 
     REQUEST_SIZE_MATCH(xRRGetProvidersReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
@@ -71,6 +72,10 @@ ProcRRGetProviders (ClientPtr client)
 
     if (pScrPriv->provider)
         total_providers++;
+    xorg_list_for_each_entry(iter, &pScreen->unattached_list, unattached_head) {
+        pScrPriv = rrGetScrPriv(iter);
+        total_providers += pScrPriv->provider ? 1 : 0;
+    }
 
     pScrPriv = rrGetScrPriv(pScreen);
     rep.pad = 0;
@@ -100,6 +105,9 @@ ProcRRGetProviders (ClientPtr client)
 
         providers = (RRProvider *)extra;
         ADD_PROVIDER(pScreen);
+        xorg_list_for_each_entry(iter, &pScreen->unattached_list, unattached_head) {
+            ADD_PROVIDER(iter);
+        }
     }
 
     if (client->swapped) {
commit d0e138c3f3e58ef127dad6c6aef48b1713b5ce58
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jun 13 14:32:05 2012 +0100

    dix: attach unbound screens to protocol screen 0 (v2)
    
    This is the default attachment, unbound gpu screens get
    attached to the 0 protocol screen.
    
    detach on hotunplug.
    
    v2: detach after tearing down crtc/outputs.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index aa17a58..058d09f 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -920,6 +920,9 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
 #endif
     }
 
+    for (i = 0; i < xf86NumGPUScreens; i++)
+        AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
+
     xf86VGAarbiterWrapFunctions();
     OsReleaseSIGIO();
 
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index a2cd856..0bf14eb 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -736,6 +736,11 @@ xf86CrtcCloseScreen(ScreenPtr screen)
 
         crtc->randr_crtc = NULL;
     }
+    /* detach any providers */
+    if (config->randr_provider) {
+        if (screen->current_master)
+            DetachUnboundGPU(screen);
+    }
     xf86RandR12CloseScreen(screen);
 
     free(config->name);
commit 4caad34c932115dc0a9fd9c2995ebb2d38b9359c
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jun 13 14:27:42 2012 +0100

    dix: add unattached list for attaching screens to initially. (v1.1)
    
    This list is meant for attaching unbound gpu screens to initially,
    before the client side rebinds them.
    
    v1.1: add another assert in the add path.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index fa39728..9e84621 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3742,6 +3742,8 @@ static int init_screen(ScreenPtr pScreen, int i, Bool gpu)
     pScreen->ClipNotify = 0;    /* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
 
+    xorg_list_init(&pScreen->unattached_list);
+
     /*
      * This loop gets run once for every Screen that gets added,
      * but thats ok.  If the ddx layer initializes the formats
@@ -3889,3 +3891,21 @@ RemoveGPUScreen(ScreenPtr pScreen)
     free(pScreen);
 
 }
+
+void
+AttachUnboundGPU(ScreenPtr pScreen, ScreenPtr new)
+{
+    assert(new->isGPU);
+    assert(!new->current_master);
+    xorg_list_add(&new->unattached_head, &pScreen->unattached_list);
+    new->current_master = pScreen;
+}
+
+void
+DetachUnboundGPU(ScreenPtr slave)
+{
+    assert(slave->isGPU);
+    xorg_list_del(&slave->unattached_head);
+    slave->current_master = NULL;
+}
+
diff --git a/include/screenint.h b/include/screenint.h
index 8205f63..c0c60ef 100644
--- a/include/screenint.h
+++ b/include/screenint.h
@@ -71,6 +71,11 @@ extern _X_EXPORT int AddGPUScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
 
 extern _X_EXPORT void RemoveGPUScreen(ScreenPtr pScreen);
 
+extern _X_EXPORT void
+AttachUnboundGPU(ScreenPtr pScreen, ScreenPtr new);
+extern _X_EXPORT void
+DetachUnboundGPU(ScreenPtr unbound);
+
 typedef struct _ColormapRec *ColormapPtr;
 
 #endif                          /* SCREENINT_H */
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index bcac475..6b738de 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -479,6 +479,12 @@ typedef struct _Screen {
     Bool canDoBGNoneRoot;
 
     Bool isGPU;
+
+    struct xorg_list unattached_list;
+    struct xorg_list unattached_head;
+
+    ScreenPtr current_master;
+
 } ScreenRec;
 
 static inline RegionPtr
commit 9b5cf2ed76b00937af12304e0e8dbd60df62067e
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jun 13 14:17:06 2012 +0100

    xfree86: add framework for provider support in ddx. (v4)
    
    This adds the framework for DDX provider support.
    
    v2: as per keithp's suggestion remove the xf86 provider object
    and just store it in the toplevel object.
    
    v3: update for new protocol
    
    v4: drop devPrivate, free name
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index 6bd6a62..0590262 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -814,6 +814,7 @@ typedef struct _ScrnInfoRec {
     funcPointer reservedFuncs[NUM_RESERVED_FUNCS];
 
     Bool is_gpu;
+    uint32_t capabilities;
 } ScrnInfoRec;
 
 typedef struct {
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index 2c8878f..a2cd856 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -738,6 +738,7 @@ xf86CrtcCloseScreen(ScreenPtr screen)
     }
     xf86RandR12CloseScreen(screen);
 
+    free(config->name);
     return screen->CloseScreen(screen);
 }
 
@@ -3202,3 +3203,20 @@ xf86_crtc_supports_gamma(ScrnInfoPtr pScrn)
 
     return FALSE;
 }
+
+void
+xf86ProviderSetup(ScrnInfoPtr scrn,
+                  const xf86ProviderFuncsRec *funcs, const char *name)
+{
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    assert(!xf86_config->name);
+    assert(name);
+
+    xf86_config->name = strdup(name);
+    xf86_config->provider_funcs = funcs;
+#ifdef RANDR_12_INTERFACE
+    xf86_config->randr_provider = NULL;
+#endif
+}
+
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index a6a3c2e..58d8cec 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -607,6 +607,29 @@ struct _xf86Output {
     INT16 initialBorder[4];
 };
 
+typedef struct _xf86ProviderFuncs {
+    /**
+     * Called to allow the provider a chance to create properties after the
+     * RandR objects have been created.
+     */
+    void
+    (*create_resources) (ScrnInfoPtr scrn);
+
+    /**
+     * Callback when an provider's property has changed.
+     */
+    Bool
+    (*set_property) (ScrnInfoPtr scrn,
+                     Atom property, RRPropertyValuePtr value);
+
+    /**
+     * Callback to get an updated property value
+     */
+    Bool
+    (*get_property) (ScrnInfoPtr provider, Atom property);
+
+} xf86ProviderFuncsRec, *xf86ProviderFuncsPtr;
+
 typedef struct _xf86CrtcConfigFuncs {
     /**
      * Requests that the driver resize the screen.
@@ -681,6 +704,13 @@ typedef struct _xf86CrtcConfig {
     /* callback when crtc configuration changes */
     xf86_crtc_notify_proc_ptr xf86_crtc_notify;
 
+    char *name;
+    const xf86ProviderFuncsRec *provider_funcs;
+#ifdef RANDR_12_INTERFACE
+    RRProviderPtr randr_provider;
+#else
+    void *randr_provider;
+#endif
 } xf86CrtcConfigRec, *xf86CrtcConfigPtr;
 
 extern _X_EXPORT int xf86CrtcConfigPrivateIndex;
@@ -975,4 +1005,8 @@ extern _X_EXPORT void
 extern _X_EXPORT Bool
  xf86_crtc_supports_gamma(ScrnInfoPtr pScrn);
 
+extern _X_EXPORT void
+xf86ProviderSetup(ScrnInfoPtr scrn,
+                  const xf86ProviderFuncsRec * funcs, const char *name);
+
 #endif                          /* _XF86CRTC_H_ */
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 59b6f82..41c0b11 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -1552,6 +1552,14 @@ xf86RandR12CreateObjects12(ScreenPtr pScreen)
             output->funcs->create_resources(output);
         RRPostPendingProperties(output->randr_output);
     }
+
+    if (config->name) {
+        config->randr_provider = RRProviderCreate(pScreen, config->name,
+                                                  strlen(config->name));
+
+        RRProviderSetCapabilities(config->randr_provider, pScrn->capabilities);
+    }
+
     return TRUE;
 }
 
@@ -1746,6 +1754,42 @@ xf86RandR12EnterVT(ScrnInfoPtr pScrn)
 }
 
 static Bool
+xf86RandR14ProviderSetProperty(ScreenPtr pScreen,
+                             RRProviderPtr randr_provider,
+                             Atom property, RRPropertyValuePtr value)
+{
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+    /* If we don't have any property handler, then we don't care what the
+     * user is setting properties to.
+     */
+    if (config->provider_funcs->set_property == NULL)
+        return TRUE;
+
+    /*
+     * This function gets called even when vtSema is FALSE, as
+     * drivers will need to remember the correct value to apply
+     * when the VT switch occurs
+     */
+    return config->provider_funcs->set_property(pScrn, property, value);
+}
+
+static Bool
+xf86RandR14ProviderGetProperty(ScreenPtr pScreen,
+                               RRProviderPtr randr_provider, Atom property)
+{
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+    if (config->provider_funcs->get_property == NULL)
+        return TRUE;
+
+    /* Should be safe even w/o vtSema */
+    return config->provider_funcs->get_property(pScrn, property);
+}
+
+static Bool
 xf86RandR12Init12(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
@@ -1767,6 +1811,10 @@ xf86RandR12Init12(ScreenPtr pScreen)
 #endif
     rp->rrModeDestroy = xf86RandR12ModeDestroy;
     rp->rrSetConfig = NULL;
+
+    rp->rrProviderSetProperty = xf86RandR14ProviderSetProperty;
+    rp->rrProviderGetProperty = xf86RandR14ProviderGetProperty;
+
     pScrn->PointerMoved = xf86RandR12PointerMoved;
     pScrn->ChangeGamma = xf86RandR12ChangeGamma;
 
commit 66d92afeaeed9f4a19267d95a1f81b9bf27162a5
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jun 13 14:03:04 2012 +0100

    randr: add provider object and provider property support (v6)
    
    This adds the initial provider object and provider property
    support to the randr dix code.
    
    v2: destroy provider in screen close
    v2.1: fix whitespace
    
    v3: update for latest rev of protocol + renumber after 1.4 tearout.
    
    v4: fix logic issue, thanks Samsagax on irc
    
    v5: keithp's review: fix current_role, fix copyrights, fix master
    reporting crtc/outputs.
    
    v6: port to new randr interface, drop all set role bits for now
    
    v7: drop devPrivate in provider, not needed, add BadMatch returns
    for NULL SetProviderOffloadSink and SetProviderOutputSource, drop
    the old typedef.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 3bfb22e..24b9473 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -432,14 +432,17 @@ xf86platformAddDevice(int index)
         xf86DeleteScreen(xf86GPUScreens[i]);
         return -1;
     }
-        
+
    scr_index = AddGPUScreen(xf86GPUScreens[i]->ScreenInit, 0, NULL);
-   
+
    dixSetPrivate(&xf86GPUScreens[i]->pScreen->devPrivates,
                  xf86ScreenKey, xf86GPUScreens[i]);
 
    CreateScratchPixmapsForScreen(xf86GPUScreens[i]->pScreen);
-  
+
+   /* attach unbound to 0 protocol screen */
+   AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
+
    return 0;
 }
 
diff --git a/randr/Makefile.am b/randr/Makefile.am
index de338b9..ccaff3f 100644
--- a/randr/Makefile.am
+++ b/randr/Makefile.am
@@ -18,6 +18,8 @@ librandr_la_SOURCES =	\
 	rroutput.c	\
 	rrpointer.c	\
 	rrproperty.c	\
+	rrprovider.c    \
+	rrproviderproperty.c    \
 	rrscreen.c	\
 	rrsdispatch.c	\
 	rrtransform.h	\
diff --git a/randr/randr.c b/randr/randr.c
index 103da48..103c31e 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -94,6 +94,9 @@ RRCloseScreen(ScreenPtr pScreen)
     for (j = pScrPriv->numOutputs - 1; j >= 0; j--)
         RROutputDestroy(pScrPriv->outputs[j]);
 
+    if (pScrPriv->provider)
+        RRProviderDestroy(pScrPriv->provider);
+
     free(pScrPriv->crtcs);
     free(pScrPriv->outputs);
     free(pScrPriv);
@@ -176,6 +179,47 @@ SRROutputPropertyNotifyEvent(xRROutputPropertyNotifyEvent * from,
 }
 
 static void
+SRRProviderChangeNotifyEvent(xRRProviderChangeNotifyEvent * from,
+                         xRRProviderChangeNotifyEvent * to)
+{
+    to->type = from->type;
+    to->subCode = from->subCode;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->timestamp, to->timestamp);
+    cpswapl(from->window, to->window);
+    cpswapl(from->provider, to->provider);
+}
+
+static void
+SRRProviderPropertyNotifyEvent(xRRProviderPropertyNotifyEvent * from,
+                               xRRProviderPropertyNotifyEvent * to)
+{
+    to->type = from->type;
+    to->subCode = from->subCode;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->window, to->window);
+    cpswapl(from->provider, to->provider);
+    cpswapl(from->atom, to->atom);
+    cpswapl(from->timestamp, to->timestamp);
+    to->state = from->state;
+    /* pad1 */
+    /* pad2 */
+    /* pad3 */
+    /* pad4 */
+}
+
+static void
+SRRResourceChangeNotifyEvent(xRRResourceChangeNotifyEvent * from,
+                             xRRResourceChangeNotifyEvent * to)
+{
+    to->type = from->type;
+    to->subCode = from->subCode;
+    cpswaps(from->sequenceNumber, to->sequenceNumber);
+    cpswapl(from->timestamp, to->timestamp);
+    cpswapl(from->window, to->window);
+}
+
+static void
 SRRNotifyEvent(xEvent *from, xEvent *to)
 {
     switch (from->u.u.detail) {
@@ -191,6 +235,17 @@ SRRNotifyEvent(xEvent *from, xEvent *to)
         SRROutputPropertyNotifyEvent((xRROutputPropertyNotifyEvent *) from,
                                      (xRROutputPropertyNotifyEvent *) to);
         break;
+    case RRNotify_ProviderChange:
+        SRRProviderChangeNotifyEvent((xRRProviderChangeNotifyEvent *) from,
+                                   (xRRProviderChangeNotifyEvent *) to);
+        break;
+    case RRNotify_ProviderProperty:
+        SRRProviderPropertyNotifyEvent((xRRProviderPropertyNotifyEvent *) from,
+                                       (xRRProviderPropertyNotifyEvent *) to);
+        break;
+    case RRNotify_ResourceChange:
+        SRRResourceChangeNotifyEvent((xRRResourceChangeNotifyEvent *) from,
+                                   (xRRResourceChangeNotifyEvent *) to);
     default:
         break;
     }
@@ -356,7 +411,7 @@ RRExtensionInit(void)
     RRModeInitErrorValue();
     RRCrtcInitErrorValue();
     RROutputInitErrorValue();
-
+    RRProviderInitErrorValue();
 #ifdef PANORAMIX
     RRXineramaExtensionInit();
 #endif
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 38fb107..3dac633 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -62,6 +62,7 @@
 typedef XID RRMode;
 typedef XID RROutput;
 typedef XID RRCrtc;
+typedef XID RRProvider;
 
 extern _X_EXPORT int RREventBase, RRErrorBase;
 
@@ -78,6 +79,7 @@ typedef struct _rrPropertyValue RRPropertyValueRec, *RRPropertyValuePtr;
 typedef struct _rrProperty RRPropertyRec, *RRPropertyPtr;
 typedef struct _rrCrtc RRCrtcRec, *RRCrtcPtr;
 typedef struct _rrOutput RROutputRec, *RROutputPtr;
+typedef struct _rrProvider RRProviderRec, *RRProviderPtr;
 
 struct _rrMode {
     int refcnt;
@@ -152,6 +154,16 @@ struct _rrOutput {
     void *devPrivate;
 };
 
+struct _rrProvider {
+    RRProvider id;
+    ScreenPtr pScreen;
+    uint32_t capabilities;
+    char *name;
+    int nameLength;
+    RRPropertyPtr properties;
+    Bool pendingProperties;
+};
+
 #if RANDR_12_INTERFACE
 typedef Bool (*RRScreenSetSizeProcPtr) (ScreenPtr pScreen,
                                         CARD16 width,
@@ -197,6 +209,13 @@ typedef Bool (*RRSetPanningProcPtr) (ScreenPtr pScrn,
 
 #endif                          /* RANDR_13_INTERFACE */
 
+typedef Bool (*RRProviderGetPropertyProcPtr) (ScreenPtr pScreen,
+                                            RRProviderPtr provider, Atom property);
+typedef Bool (*RRProviderSetPropertyProcPtr) (ScreenPtr pScreen,
+                                              RRProviderPtr provider,
+                                              Atom property,
+                                              RRPropertyValuePtr value);
+
 typedef Bool (*RRGetInfoProcPtr) (ScreenPtr pScreen, Rotation * rotations);
 typedef Bool (*RRCloseScreenProcPtr) (ScreenPtr pscreen);
 
@@ -247,6 +266,8 @@ typedef struct _rrScrPriv {
     RRSetPanningProcPtr rrSetPanning;
 #endif
 
+    RRProviderGetPropertyProcPtr rrProviderGetProperty;
+    RRProviderSetPropertyProcPtr rrProviderSetProperty;
     /*
      * Private part of the structure; not considered part of the ABI
      */
@@ -288,6 +309,8 @@ typedef struct _rrScrPriv {
     int size;
 #endif
     Bool discontiguous;
+
+    RRProviderPtr provider;
 } rrScrPrivRec, *rrScrPrivPtr;
 
 extern _X_EXPORT DevPrivateKeyRec rrPrivKeyRec;
@@ -331,7 +354,7 @@ extern _X_EXPORT RESTYPE RRClientType, RREventType;     /* resource types for ev
 extern _X_EXPORT DevPrivateKeyRec RRClientPrivateKeyRec;
 
 #define RRClientPrivateKey (&RRClientPrivateKeyRec)
-extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType;
+extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType, RRProviderType;
 
 #define VERIFY_RR_OUTPUT(id, ptr, a)\
     {\
@@ -363,6 +386,16 @@ extern _X_EXPORT RESTYPE RRCrtcType, RRModeType, RROutputType;
 	}\
     }
 
+#define VERIFY_RR_PROVIDER(id, ptr, a)\
+    {\
+        int rc = dixLookupResourceByType((pointer *)&(ptr), id,\
+                                         RRProviderType, client, a);\
+        if (rc != Success) {\
+            client->errorValue = id;\
+            return rc;\
+        }\
+    }
+
 #define GetRRClient(pClient)    ((RRClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RRClientPrivateKey))
 #define rrClientPriv(pClient)	RRClientPtr pRRClient = GetRRClient(pClient)
 
@@ -824,6 +857,69 @@ extern _X_EXPORT int
 extern _X_EXPORT int
  ProcRRDeleteOutputProperty(ClientPtr client);
 
+/* rrprovider.c */
+extern _X_EXPORT void
+RRProviderInitErrorValue(void);
+
+extern _X_EXPORT int
+ProcRRGetProviders(ClientPtr client);
+
+extern _X_EXPORT int
+ProcRRGetProviderInfo(ClientPtr client);
+
+
+extern _X_EXPORT Bool
+RRProviderInit(void);
+
+extern _X_EXPORT RRProviderPtr
+RRProviderCreate(ScreenPtr pScreen, const char *name,
+                 int nameLength);
+
+extern _X_EXPORT void
+RRProviderDestroy (RRProviderPtr provider);
+
+extern _X_EXPORT void
+RRProviderSetCapabilities(RRProviderPtr provider, uint32_t capabilities);
+
+extern _X_EXPORT Bool
+RRProviderLookup(XID id, RRProviderPtr *provider_p);
+
+/* rrproviderproperty.c */
+
+extern _X_EXPORT void
+ RRDeleteAllProviderProperties(RRProviderPtr provider);
+
+extern _X_EXPORT RRPropertyValuePtr
+ RRGetProviderProperty(RRProviderPtr provider, Atom property, Bool pending);
+
+extern _X_EXPORT RRPropertyPtr
+ RRQueryProviderProperty(RRProviderPtr provider, Atom property);
+
+extern _X_EXPORT void
+ RRDeleteProviderProperty(RRProviderPtr provider, Atom property);
+
+extern _X_EXPORT int
+RRChangeProviderProperty(RRProviderPtr provider, Atom property, Atom type,
+                       int format, int mode, unsigned long len,
+                       pointer value, Bool sendevent, Bool pending);
+
+extern _X_EXPORT int
+ ProcRRGetProviderProperty(ClientPtr client);
+
+extern _X_EXPORT int
+ ProcRRListProviderProperties(ClientPtr client);
+
+extern _X_EXPORT int
+ ProcRRQueryProviderProperty(ClientPtr client);
+
+extern _X_EXPORT int
+ProcRRConfigureProviderProperty(ClientPtr client);
+
+extern _X_EXPORT int
+ProcRRChangeProviderProperty(ClientPtr client);
+
+extern _X_EXPORT int
+ ProcRRDeleteProviderProperty(ClientPtr client);
 /* rrxinerama.c */
 #ifdef XINERAMA
 extern _X_EXPORT void
diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index 85cf037..054e47a 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -90,7 +90,8 @@ ProcRRSelectInput(ClientPtr client)
     if (stuff->enable & (RRScreenChangeNotifyMask |
                          RRCrtcChangeNotifyMask |
                          RROutputChangeNotifyMask |
-                         RROutputPropertyNotifyMask)) {
+                         RROutputPropertyNotifyMask |
+                         RRProviderPropertyNotifyMask)) {
         ScreenPtr pScreen = pWin->drawable.pScreen;
 
         rrScrPriv(pScreen);
@@ -241,4 +242,15 @@ int (*ProcRandrVector[RRNumberRequests]) (ClientPtr) = {
         ProcRRSetPanning,       /* 29 */
         ProcRRSetOutputPrimary, /* 30 */
         ProcRRGetOutputPrimary, /* 31 */
+/* V1.4 additions */
+        ProcRRGetProviders,     /* 32 */
+        ProcRRGetProviderInfo,  /* 33 */
+        NULL, /* 34 */
+        NULL, /* 35 */
+        ProcRRListProviderProperties,    /* 36 */
+        ProcRRQueryProviderProperty,     /* 37 */
+        ProcRRConfigureProviderProperty, /* 38 */
+        ProcRRChangeProviderProperty, /* 39 */
+        ProcRRDeleteProviderProperty, /* 40 */
+        ProcRRGetProviderProperty,    /* 41 */
 };
diff --git a/randr/rrprovider.c b/randr/rrprovider.c
new file mode 100644
index 0000000..db7074c
--- /dev/null
+++ b/randr/rrprovider.c
@@ -0,0 +1,279 @@
+/*
+ * Copyright © 2012 Red Hat Inc.
+ *
+ * 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.
+ *
+ * Authors: Dave Airlie
+ */
+
+#include "randrstr.h"
+#include "swaprep.h"
+
+RESTYPE RRProviderType;
+
+/*
+ * Initialize provider type error value
+ */
+void
+RRProviderInitErrorValue(void)
+{
+    SetResourceTypeErrorValue(RRProviderType, RRErrorBase + BadRRProvider);
+}
+
+#define ADD_PROVIDER(_pScreen) do {                                 \
+    pScrPriv = rrGetScrPriv((_pScreen));                            \
+    if (pScrPriv->provider) {                                   \
+        providers[count_providers] = pScrPriv->provider->id;    \
+        if (client->swapped)                                    \
+            swapl(&providers[count_providers]);                 \
+        count_providers++;                                      \
+    }                                                           \
+    } while(0)
+
+int
+ProcRRGetProviders (ClientPtr client)
+{
+    REQUEST(xRRGetProvidersReq);
+    xRRGetProvidersReply rep;
+    WindowPtr pWin;
+    ScreenPtr pScreen;
+    rrScrPrivPtr pScrPriv;
+    int rc;
+    CARD8 *extra;
+    unsigned int extraLen;
+    RRProvider *providers;
+    int total_providers = 0, count_providers = 0;
+
+    REQUEST_SIZE_MATCH(xRRGetProvidersReq);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
+    if (rc != Success)
+        return rc;
+
+    pScreen = pWin->drawable.pScreen;
+
+    pScrPriv = rrGetScrPriv(pScreen);
+
+    if (pScrPriv->provider)
+        total_providers++;
+
+    pScrPriv = rrGetScrPriv(pScreen);
+    rep.pad = 0;
+
+    if (!pScrPriv)
+    {
+        rep.type = X_Reply;
+        rep.sequenceNumber = client->sequence;
+        rep.length = 0;
+        rep.timestamp = currentTime.milliseconds;
+        rep.nProviders = 0;
+        extra = NULL;
+        extraLen = 0;
+    } else {
+        rep.type = X_Reply;
+        rep.sequenceNumber = client->sequence;
+        rep.timestamp = pScrPriv->lastSetTime.milliseconds;
+        rep.nProviders = total_providers;
+        rep.length = total_providers;
+        extraLen = rep.length << 2;
+        if (extraLen) {
+            extra = malloc(extraLen);
+            if (!extra)
+                return BadAlloc;
+        } else
+            extra = NULL;
+
+        providers = (RRProvider *)extra;
+        ADD_PROVIDER(pScreen);
+    }
+
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.timestamp);
+        swaps(&rep.nProviders);
+    }
+    WriteToClient(client, sizeof(xRRGetProvidersReply), (char *)&rep);
+    if (extraLen)
+    {
+        WriteToClient (client, extraLen, (char *) extra);
+        free(extra);
+    }
+    return Success;
+}
+
+int
+ProcRRGetProviderInfo (ClientPtr client)
+{
+    REQUEST(xRRGetProviderInfoReq);
+    xRRGetProviderInfoReply rep;
+    rrScrPrivPtr pScrPriv;
+    RRProviderPtr provider;
+    ScreenPtr pScreen;
+    CARD8 *extra;
+    unsigned int extraLen = 0;
+    RRCrtc *crtcs;
+    RROutput *outputs;
+    int i;
+    char *name;
+    ScreenPtr provscreen;
+    RRProvider *providers;
+    uint32_t *prov_cap;
+ 
+    REQUEST_SIZE_MATCH(xRRGetProviderInfoReq);
+    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
+
+    pScreen = provider->pScreen;
+    pScrPriv = rrGetScrPriv(pScreen);
+
+    rep.type = X_Reply;
+    rep.status = RRSetConfigSuccess;
+    rep.sequenceNumber = client->sequence;
+    rep.length = 0;
+    rep.capabilities = provider->capabilities;
+    rep.nameLength = provider->nameLength;
+    rep.timestamp = pScrPriv->lastSetTime.milliseconds;
+    rep.nCrtcs = pScrPriv->numCrtcs;
+    rep.nOutputs = pScrPriv->numOutputs;
+
+    /* count associated providers */
+    rep.nAssociatedProviders = 0;
+    rep.length = (pScrPriv->numCrtcs + pScrPriv->numOutputs +
+                  (rep.nAssociatedProviders * 2) + bytes_to_int32(rep.nameLength));
+
+    extraLen = rep.length << 2;
+    if (extraLen) {
+        extra = malloc(extraLen);
+        if (!extra)
+            return BadAlloc;
+    }
+    else
+        extra = NULL;
+
+    crtcs = (RRCrtc *)extra;
+    outputs = (RROutput *)(crtcs + rep.nCrtcs);
+    providers = (RRProvider *)(outputs + rep.nOutputs);
+    prov_cap = (unsigned int *)(providers + rep.nAssociatedProviders);
+    name = (char *)(prov_cap + rep.nAssociatedProviders);
+
+    for (i = 0; i < pScrPriv->numCrtcs; i++) {
+        crtcs[i] = pScrPriv->crtcs[i]->id;
+        if (client->swapped)
+            swapl(&crtcs[i]);
+    }
+
+    for (i = 0; i < pScrPriv->numOutputs; i++) {
+        outputs[i] = pScrPriv->outputs[i]->id;
+        if (client->swapped)
+            swapl(&outputs[i]);
+    }
+
+    memcpy(name, provider->name, rep.nameLength);
+    if (client->swapped) {
+              swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swapl(&rep.capabilities);
+        swaps(&rep.nCrtcs);
+        swaps(&rep.nOutputs);
+        swaps(&rep.nameLength);
+    }
+    WriteToClient(client, sizeof(xRRGetProviderInfoReply), (char *)&rep);
+    if (extraLen)
+    {
+        WriteToClient (client, extraLen, (char *) extra);
+        free(extra);
+    }
+    return Success;
+}
+
+RRProviderPtr
+RRProviderCreate(ScreenPtr pScreen, const char *name,
+                 int nameLength)
+{
+    RRProviderPtr provider;
+    rrScrPrivPtr pScrPriv;
+
+    pScrPriv = rrGetScrPriv(pScreen);
+
+    provider = calloc(1, sizeof(RRProviderRec) + nameLength + 1);
+    if (!provider)
+        return NULL;
+
+    provider->id = FakeClientID(0);
+    provider->pScreen = pScreen;
+    provider->name = (char *) (provider + 1);
+    provider->nameLength = nameLength;
+    memcpy(provider->name, name, nameLength);
+    provider->name[nameLength] = '\0';
+
+    if (!AddResource (provider->id, RRProviderType, (pointer) provider))
+        return NULL;
+    pScrPriv->provider = provider;
+    return provider;
+}
+
+/*
+ * Destroy a provider at shutdown
+ */
+void
+RRProviderDestroy (RRProviderPtr provider)
+{
+    FreeResource (provider->id, 0);
+}
+
+void
+RRProviderSetCapabilities(RRProviderPtr provider, uint32_t capabilities)
+{
+    provider->capabilities = capabilities;
+}
+
+static int
+RRProviderDestroyResource (pointer value, XID pid)
+{
+    RRProviderPtr provider = (RRProviderPtr)value;
+    ScreenPtr pScreen = provider->pScreen;
+
+    if (pScreen)
+    {
+        rrScrPriv(pScreen);
+
+        pScrPriv->provider = NULL;
+    }
+    free(provider);
+    return 1;
+}
+
+Bool
+RRProviderInit(void)
+{
+    RRProviderType = CreateNewResourceType(RRProviderDestroyResource, "Provider");
+    if (!RRProviderType)
+        return FALSE;
+
+    return TRUE;
+}
+
+extern _X_EXPORT Bool
+RRProviderLookup(XID id, RRProviderPtr *provider_p)
+{
+    int rc = dixLookupResourceByType((void **)provider_p, id,
+                                   RRProviderType, NullClient, DixReadAccess);
+    if (rc == Success)
+        return TRUE;
+    return FALSE;
+}
diff --git a/randr/rrproviderproperty.c b/randr/rrproviderproperty.c
new file mode 100644
index 0000000..5e04fab
--- /dev/null
+++ b/randr/rrproviderproperty.c
@@ -0,0 +1,716 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * 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.
+ */
+
+#include "randrstr.h"
+#include "propertyst.h"
+#include "swaprep.h"
+
+static int
+DeliverPropertyEvent(WindowPtr pWin, void *value)
+{
+    xRRProviderPropertyNotifyEvent *event = value;
+    RREventPtr *pHead, pRREvent;
+
+    dixLookupResourceByType((pointer *) &pHead, pWin->drawable.id,
+                            RREventType, serverClient, DixReadAccess);
+    if (!pHead)
+        return WT_WALKCHILDREN;
+
+    for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) {
+        if (!(pRREvent->mask & RRProviderPropertyNotifyMask))
+            continue;
+
+        event->window = pRREvent->window->drawable.id;
+        WriteEventsToClient(pRREvent->client, 1, (xEvent *) event);
+    }
+
+    return WT_WALKCHILDREN;
+}
+
+static void
+RRDeliverPropertyEvent(ScreenPtr pScreen, xEvent *event)
+{
+    if (!(dispatchException & (DE_RESET | DE_TERMINATE)))
+        WalkTree(pScreen, DeliverPropertyEvent, event);
+}
+
+static void
+RRDestroyProviderProperty(RRPropertyPtr prop)
+{
+    free(prop->valid_values);
+    free(prop->current.data);
+    free(prop->pending.data);
+    free(prop);
+}
+
+static void
+RRDeleteProperty(RRProviderRec * provider, RRPropertyRec * prop)
+{
+    xRRProviderPropertyNotifyEvent event;
+
+    event.type = RREventBase + RRNotify;
+    event.subCode = RRNotify_ProviderProperty;
+    event.provider = provider->id;
+    event.state = PropertyDelete;
+    event.atom = prop->propertyName;
+    event.timestamp = currentTime.milliseconds;
+
+    RRDeliverPropertyEvent(provider->pScreen, (xEvent *) &event);
+
+    RRDestroyProviderProperty(prop);
+}
+
+void
+RRDeleteAllProviderProperties(RRProviderPtr provider)
+{
+    RRPropertyPtr prop, next;
+
+    for (prop = provider->properties; prop; prop = next) {
+        next = prop->next;
+        RRDeleteProperty(provider, prop);
+    }
+}
+
+static void
+RRInitProviderPropertyValue(RRPropertyValuePtr property_value)
+{
+    property_value->type = None;
+    property_value->format = 0;
+    property_value->size = 0;
+    property_value->data = NULL;
+}
+
+static RRPropertyPtr
+RRCreateProviderProperty(Atom property)
+{
+    RRPropertyPtr prop;
+
+    prop = (RRPropertyPtr) malloc(sizeof(RRPropertyRec));
+    if (!prop)
+        return NULL;
+    prop->next = NULL;
+    prop->propertyName = property;
+    prop->is_pending = FALSE;
+    prop->range = FALSE;
+    prop->immutable = FALSE;
+    prop->num_valid = 0;
+    prop->valid_values = NULL;
+    RRInitProviderPropertyValue(&prop->current);
+    RRInitProviderPropertyValue(&prop->pending);
+    return prop;
+}
+
+void
+RRDeleteProviderProperty(RRProviderPtr provider, Atom property)
+{
+    RRPropertyRec *prop, **prev;
+
+    for (prev = &provider->properties; (prop = *prev); prev = &(prop->next))
+        if (prop->propertyName == property) {
+            *prev = prop->next;
+            RRDeleteProperty(provider, prop);
+            return;
+        }
+}
+
+int
+RRChangeProviderProperty(RRProviderPtr provider, Atom property, Atom type,
+                       int format, int mode, unsigned long len,
+                       pointer value, Bool sendevent, Bool pending)
+{
+    RRPropertyPtr prop;
+    xRRProviderPropertyNotifyEvent event;
+    rrScrPrivPtr pScrPriv = rrGetScrPriv(provider->pScreen);
+    int size_in_bytes;
+    int total_size;
+    unsigned long total_len;
+    RRPropertyValuePtr prop_value;
+    RRPropertyValueRec new_value;
+    Bool add = FALSE;
+
+    size_in_bytes = format >> 3;
+
+    /* first see if property already exists */
+    prop = RRQueryProviderProperty(provider, property);
+    if (!prop) {                /* just add to list */
+        prop = RRCreateProviderProperty(property);
+        if (!prop)
+            return BadAlloc;
+        add = TRUE;
+        mode = PropModeReplace;
+    }
+    if (pending && prop->is_pending)
+        prop_value = &prop->pending;
+    else
+        prop_value = &prop->current;
+
+    /* To append or prepend to a property the request format and type
+       must match those of the already defined property.  The
+       existing format and type are irrelevant when using the mode
+       "PropModeReplace" since they will be written over. */
+
+    if ((format != prop_value->format) && (mode != PropModeReplace))
+        return BadMatch;
+    if ((prop_value->type != type) && (mode != PropModeReplace))
+        return BadMatch;
+    new_value = *prop_value;
+    if (mode == PropModeReplace)
+        total_len = len;
+    else
+        total_len = prop_value->size + len;
+
+    if (mode == PropModeReplace || len > 0) {
+        pointer new_data = NULL, old_data = NULL;
+
+        total_size = total_len * size_in_bytes;
+        new_value.data = (pointer) malloc(total_size);
+        if (!new_value.data && total_size) {
+            if (add)
+                RRDestroyProviderProperty(prop);
+            return BadAlloc;
+        }
+        new_value.size = len;
+        new_value.type = type;
+        new_value.format = format;
+
+        switch (mode) {
+        case PropModeReplace:
+            new_data = new_value.data;
+            old_data = NULL;
+            break;
+        case PropModeAppend:
+            new_data = (pointer) (((char *) new_value.data) +
+                                  (prop_value->size * size_in_bytes));
+            old_data = new_value.data;
+            break;
+        case PropModePrepend:
+            new_data = new_value.data;
+            old_data = (pointer) (((char *) new_value.data) +
+                                  (prop_value->size * size_in_bytes));
+            break;
+        }
+        if (new_data)
+            memcpy((char *) new_data, (char *) value, len * size_in_bytes);
+        if (old_data)
+            memcpy((char *) old_data, (char *) prop_value->data,
+                   prop_value->size * size_in_bytes);
+
+        if (pending && pScrPriv->rrProviderSetProperty &&
+            !pScrPriv->rrProviderSetProperty(provider->pScreen, provider,
+                                           prop->propertyName, &new_value)) {
+            free(new_value.data);
+            return BadValue;
+        }
+        free(prop_value->data);
+        *prop_value = new_value;
+    }
+
+    else if (len == 0) {
+        /* do nothing */
+    }
+
+    if (add) {
+        prop->next = provider->properties;
+        provider->properties = prop;
+    }
+
+    if (pending && prop->is_pending)
+        provider->pendingProperties = TRUE;
+
+    if (sendevent) {
+        event.type = RREventBase + RRNotify;
+        event.subCode = RRNotify_ProviderProperty;
+        event.provider = provider->id;
+        event.state = PropertyNewValue;
+        event.atom = prop->propertyName;
+        event.timestamp = currentTime.milliseconds;
+        RRDeliverPropertyEvent(provider->pScreen, (xEvent *) &event);
+    }
+    return Success;
+}
+
+Bool
+RRPostProviderPendingProperties(RRProviderPtr provider)
+{
+    RRPropertyValuePtr pending_value;
+    RRPropertyValuePtr current_value;
+    RRPropertyPtr property;
+    Bool ret = TRUE;
+
+    if (!provider->pendingProperties)
+        return TRUE;
+
+    provider->pendingProperties = FALSE;
+    for (property = provider->properties; property; property = property->next) {
+        /* Skip non-pending properties */
+        if (!property->is_pending)
+            continue;
+
+        pending_value = &property->pending;
+        current_value = &property->current;
+
+        /*
+         * If the pending and current values are equal, don't mark it
+         * as changed (which would deliver an event)
+         */
+        if (pending_value->type == current_value->type &&
+            pending_value->format == current_value->format &&
+            pending_value->size == current_value->size &&
+            !memcmp(pending_value->data, current_value->data,
+                    pending_value->size * (pending_value->format / 8)))
+            continue;
+
+        if (RRChangeProviderProperty(provider, property->propertyName,
+                                   pending_value->type, pending_value->format,
+                                   PropModeReplace, pending_value->size,
+                                   pending_value->data, TRUE, FALSE) != Success)
+            ret = FALSE;
+    }
+    return ret;
+}
+
+RRPropertyPtr
+RRQueryProviderProperty(RRProviderPtr provider, Atom property)
+{
+    RRPropertyPtr prop;
+
+    for (prop = provider->properties; prop; prop = prop->next)
+        if (prop->propertyName == property)
+            return prop;
+    return NULL;
+}
+
+RRPropertyValuePtr
+RRGetProviderProperty(RRProviderPtr provider, Atom property, Bool pending)
+{
+    RRPropertyPtr prop = RRQueryProviderProperty(provider, property);
+    rrScrPrivPtr pScrPriv = rrGetScrPriv(provider->pScreen);
+
+    if (!prop)
+        return NULL;
+    if (pending && prop->is_pending)
+        return &prop->pending;
+    else {
+#if RANDR_13_INTERFACE
+        /* If we can, try to update the property value first */
+        if (pScrPriv->rrProviderGetProperty)
+            pScrPriv->rrProviderGetProperty(provider->pScreen, provider,
+                                          prop->propertyName);
+#endif
+        return &prop->current;
+    }
+}
+
+int
+RRConfigureProviderProperty(RRProviderPtr provider, Atom property,
+                          Bool pending, Bool range, Bool immutable,
+                          int num_values, INT32 *values)
+{
+    RRPropertyPtr prop = RRQueryProviderProperty(provider, property);
+    Bool add = FALSE;
+    INT32 *new_values;
+
+    if (!prop) {
+        prop = RRCreateProviderProperty(property);
+        if (!prop)
+            return BadAlloc;
+        add = TRUE;
+    }
+    else if (prop->immutable && !immutable)
+        return BadAccess;
+
+    /*
+     * ranges must have even number of values
+     */
+    if (range && (num_values & 1))
+        return BadMatch;
+
+    new_values = malloc(num_values * sizeof(INT32));
+    if (!new_values && num_values)
+        return BadAlloc;
+    if (num_values)
+        memcpy(new_values, values, num_values * sizeof(INT32));
+
+    /*
+     * Property moving from pending to non-pending
+     * loses any pending values
+     */
+    if (prop->is_pending && !pending) {
+        free(prop->pending.data);
+        RRInitProviderPropertyValue(&prop->pending);
+    }
+
+    prop->is_pending = pending;
+    prop->range = range;
+    prop->immutable = immutable;
+    prop->num_valid = num_values;
+    free(prop->valid_values);
+    prop->valid_values = new_values;
+
+    if (add) {
+        prop->next = provider->properties;
+        provider->properties = prop;
+    }
+
+    return Success;
+}
+
+int
+ProcRRListProviderProperties(ClientPtr client)
+{
+    REQUEST(xRRListProviderPropertiesReq);
+    Atom *pAtoms = NULL, *temppAtoms;
+    xRRListProviderPropertiesReply rep;
+    int numProps = 0;
+    RRProviderPtr provider;
+    RRPropertyPtr prop;
+
+    REQUEST_SIZE_MATCH(xRRListProviderPropertiesReq);
+
+    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
+
+    for (prop = provider->properties; prop; prop = prop->next)
+        numProps++;
+    if (numProps)
+        if (!(pAtoms = (Atom *) malloc(numProps * sizeof(Atom))))
+            return BadAlloc;
+
+    rep.type = X_Reply;
+    rep.length = bytes_to_int32(numProps * sizeof(Atom));
+    rep.sequenceNumber = client->sequence;
+    rep.nAtoms = numProps;
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+        swaps(&rep.nAtoms);
+    }
+    temppAtoms = pAtoms;
+    for (prop = provider->properties; prop; prop = prop->next)
+        *temppAtoms++ = prop->propertyName;
+
+    WriteToClient(client, sizeof(xRRListProviderPropertiesReply), (char *) &rep);
+    if (numProps) {
+        client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+        WriteSwappedDataToClient(client, numProps * sizeof(Atom), pAtoms);
+        free(pAtoms);
+    }
+    return Success;
+}
+
+int
+ProcRRQueryProviderProperty(ClientPtr client)
+{
+    REQUEST(xRRQueryProviderPropertyReq);
+    xRRQueryProviderPropertyReply rep;
+    RRProviderPtr provider;
+    RRPropertyPtr prop;
+    char *extra = NULL;
+
+    REQUEST_SIZE_MATCH(xRRQueryProviderPropertyReq);
+
+    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
+
+    prop = RRQueryProviderProperty(provider, stuff->property);
+    if (!prop)
+        return BadName;
+
+    if (prop->num_valid) {
+        extra = malloc(prop->num_valid * sizeof(INT32));
+        if (!extra)
+            return BadAlloc;
+    }
+    rep.type = X_Reply;
+    rep.length = prop->num_valid;
+    rep.sequenceNumber = client->sequence;
+    rep.pending = prop->is_pending;
+    rep.range = prop->range;
+    rep.immutable = prop->immutable;
+    if (client->swapped) {
+        swaps(&rep.sequenceNumber);
+        swapl(&rep.length);
+    }
+    WriteToClient(client, sizeof(xRRQueryProviderPropertyReply), (char *) &rep);
+    if (prop->num_valid) {
+        memcpy(extra, prop->valid_values, prop->num_valid * sizeof(INT32));
+        client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
+        WriteSwappedDataToClient(client, prop->num_valid * sizeof(INT32),
+                                 extra);
+        free(extra);
+    }
+    return Success;
+}
+
+int
+ProcRRConfigureProviderProperty(ClientPtr client)
+{
+    REQUEST(xRRConfigureProviderPropertyReq);
+    RRProviderPtr provider;
+    int num_valid;
+
+    REQUEST_AT_LEAST_SIZE(xRRConfigureProviderPropertyReq);
+
+    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
+
+    num_valid =
+        stuff->length - bytes_to_int32(sizeof(xRRConfigureProviderPropertyReq));
+    return RRConfigureProviderProperty(provider, stuff->property, stuff->pending,
+                                     stuff->range, FALSE, num_valid,
+                                     (INT32 *) (stuff + 1));
+}
+
+int
+ProcRRChangeProviderProperty(ClientPtr client)
+{
+    REQUEST(xRRChangeProviderPropertyReq);
+    RRProviderPtr provider;
+    char format, mode;
+    unsigned long len;
+    int sizeInBytes;
+    int totalSize;
+    int err;
+
+    REQUEST_AT_LEAST_SIZE(xRRChangeProviderPropertyReq);
+    UpdateCurrentTime();
+    format = stuff->format;
+    mode = stuff->mode;
+    if ((mode != PropModeReplace) && (mode != PropModeAppend) &&
+        (mode != PropModePrepend)) {
+        client->errorValue = mode;
+        return BadValue;
+    }
+    if ((format != 8) && (format != 16) && (format != 32)) {
+        client->errorValue = format;
+        return BadValue;
+    }
+    len = stuff->nUnits;
+    if (len > bytes_to_int32((0xffffffff - sizeof(xChangePropertyReq))))
+        return BadLength;
+    sizeInBytes = format >> 3;
+    totalSize = len * sizeInBytes;
+    REQUEST_FIXED_SIZE(xRRChangeProviderPropertyReq, totalSize);
+
+    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
+
+    if (!ValidAtom(stuff->property)) {
+        client->errorValue = stuff->property;
+        return BadAtom;
+    }
+    if (!ValidAtom(stuff->type)) {
+        client->errorValue = stuff->type;
+        return BadAtom;
+    }
+
+    err = RRChangeProviderProperty(provider, stuff->property,
+                                 stuff->type, (int) format,
+                                 (int) mode, len, (pointer) &stuff[1], TRUE,
+                                 TRUE);
+    if (err != Success)
+        return err;
+    else
+        return Success;
+}
+
+int
+ProcRRDeleteProviderProperty(ClientPtr client)
+{
+    REQUEST(xRRDeleteProviderPropertyReq);
+    RRProviderPtr provider;
+    RRPropertyPtr prop;
+
+    REQUEST_SIZE_MATCH(xRRDeleteProviderPropertyReq);
+    UpdateCurrentTime();
+    VERIFY_RR_PROVIDER(stuff->provider, provider, DixReadAccess);
+
+    if (!ValidAtom(stuff->property)) {
+        client->errorValue = stuff->property;
+        return BadAtom;
+    }
+
+    prop = RRQueryProviderProperty(provider, stuff->property);
+    if (!prop) {
+        client->errorValue = stuff->property;
+        return BadName;
+    }
+
+    if (prop->immutable) {
+        client->errorValue = stuff->property;
+        return BadAccess;
+    }
+
+    RRDeleteProviderProperty(provider, stuff->property);
+    return Success;
+}
+
+int
+ProcRRGetProviderProperty(ClientPtr client)
+{
+    REQUEST(xRRGetProviderPropertyReq);
+    RRPropertyPtr prop, *prev;
+    RRPropertyValuePtr prop_value;
+    unsigned long n, len, ind;
+    RRProviderPtr provider;
+    xRRGetProviderPropertyReply reply;
+    char *extra = NULL;
+
+    REQUEST_SIZE_MATCH(xRRGetProviderPropertyReq);
+    if (stuff->delete)
+        UpdateCurrentTime();
+    VERIFY_RR_PROVIDER(stuff->provider, provider,
+                     stuff->delete ? DixWriteAccess : DixReadAccess);
+
+    if (!ValidAtom(stuff->property)) {
+        client->errorValue = stuff->property;
+        return BadAtom;
+    }
+    if ((stuff->delete != xTrue) && (stuff->delete != xFalse)) {
+        client->errorValue = stuff->delete;
+        return BadValue;
+    }
+    if ((stuff->type != AnyPropertyType) && !ValidAtom(stuff->type)) {
+        client->errorValue = stuff->type;
+        return BadAtom;
+    }
+
+    for (prev = &provider->properties; (prop = *prev); prev = &prop->next)
+        if (prop->propertyName == stuff->property)
+            break;
+
+    reply.type = X_Reply;
+    reply.sequenceNumber = client->sequence;
+    if (!prop) {
+        reply.nItems = 0;
+        reply.length = 0;
+        reply.bytesAfter = 0;
+        reply.propertyType = None;
+        reply.format = 0;
+        if (client->swapped) {
+            swaps(&reply.sequenceNumber);
+            swapl(&reply.length);
+            swapl(&reply.propertyType);
+            swapl(&reply.bytesAfter);
+            swapl(&reply.nItems);
+        }
+        WriteToClient(client, sizeof(xRRGetProviderPropertyReply), &reply);
+        return Success;
+    }
+
+    if (prop->immutable && stuff->delete)
+        return BadAccess;
+
+    prop_value = RRGetProviderProperty(provider, stuff->property, stuff->pending);
+    if (!prop_value)
+        return BadAtom;
+
+    /* If the request type and actual type don't match. Return the
+       property information, but not the data. */
+
+    if (((stuff->type != prop_value->type) && (stuff->type != AnyPropertyType))
+        ) {
+        reply.bytesAfter = prop_value->size;
+        reply.format = prop_value->format;
+        reply.length = 0;
+        reply.nItems = 0;
+        reply.propertyType = prop_value->type;
+        if (client->swapped) {
+            swaps(&reply.sequenceNumber);
+            swapl(&reply.length);
+            swapl(&reply.propertyType);
+            swapl(&reply.bytesAfter);
+            swapl(&reply.nItems);
+        }
+        WriteToClient(client, sizeof(xRRGetProviderPropertyReply), &reply);
+        return Success;
+    }
+
+/*
+ *  Return type, format, value to client
+ */
+    n = (prop_value->format / 8) * prop_value->size;    /* size (bytes) of prop */
+    ind = stuff->longOffset << 2;
+
+    /* If longOffset is invalid such that it causes "len" to
+       be negative, it's a value error. */
+
+    if (n < ind) {
+        client->errorValue = stuff->longOffset;
+        return BadValue;
+    }
+
+    len = min(n - ind, 4 * stuff->longLength);
+
+    if (len) {
+        extra = malloc(len);
+        if (!extra)
+            return BadAlloc;
+    }
+    reply.bytesAfter = n - (ind + len);
+    reply.format = prop_value->format;
+    reply.length = bytes_to_int32(len);
+    if (prop_value->format)
+        reply.nItems = len / (prop_value->format / 8);
+    else
+        reply.nItems = 0;
+    reply.propertyType = prop_value->type;
+
+    if (stuff->delete && (reply.bytesAfter == 0)) {
+        xRRProviderPropertyNotifyEvent event;
+
+        event.type = RREventBase + RRNotify;
+        event.subCode = RRNotify_ProviderProperty;
+        event.provider = provider->id;
+        event.state = PropertyDelete;
+        event.atom = prop->propertyName;
+        event.timestamp = currentTime.milliseconds;
+        RRDeliverPropertyEvent(provider->pScreen, (xEvent *) &event);
+    }
+
+    if (client->swapped) {
+        swaps(&reply.sequenceNumber);
+        swapl(&reply.length);
+        swapl(&reply.propertyType);
+        swapl(&reply.bytesAfter);
+        swapl(&reply.nItems);
+    }
+    WriteToClient(client, sizeof(xGenericReply), &reply);
+    if (len) {
+        memcpy(extra, (char *) prop_value->data + ind, len);
+        switch (reply.format) {
+        case 32:
+            client->pSwapReplyFunc = (ReplySwapPtr) CopySwap32Write;
+            break;
+        case 16:
+            client->pSwapReplyFunc = (ReplySwapPtr) CopySwap16Write;
+            break;
+        default:
+            client->pSwapReplyFunc = (ReplySwapPtr) WriteToClient;
+            break;
+        }
+        WriteSwappedDataToClient(client, len, extra);
+        free(extra);
+    }
+
+    if (stuff->delete && (reply.bytesAfter == 0)) {     /* delete the Property */
+        *prev = prop->next;
+        RRDestroyProviderProperty(prop);
+    }
+    return Success;
+}
commit 44eae69f1df2d00e0c9f1ea8d3c4fae06bcacfbc
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jul 5 21:11:16 2012 +0100

    configure: bump randrproto min requirements to 1.4.0
    
    Needed to build latest randr stuff.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/configure.ac b/configure.ac
index d1358a2..2442bac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -787,7 +787,7 @@ APPLEWMPROTO="applewmproto >= 1.4"
 
 dnl Required modules
 XPROTO="xproto >= 7.0.22"
-RANDRPROTO="randrproto >= 1.2.99.3"
+RANDRPROTO="randrproto >= 1.4.0"
 RENDERPROTO="renderproto >= 0.11"
 XEXTPROTO="xextproto >= 7.1.99"
 INPUTPROTO="inputproto >= 2.1.99.6"
commit 4d24192bd24fb20d16d0054d77bffda883faeb79
Merge: 7c9d8cb 74b786f
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Jul 6 12:17:17 2012 -0700

    Merge remote-tracking branch 'airlied/for-keithp-stage1'

commit 7c9d8cbd368cac53e7aed9308292614337db3be2
Author: Torsten Kaiser <just.for.lkml at googlemail.com>
Date:   Fri Jul 6 12:10:25 2012 -0700

    xfree86: EDID Est III parsing skips some modes
    
    This loop needs to count from 7 to 0, not only from 7 to 1.
    The current code always skips the modes {1152, 864, 75, 0}, {1280, 1024, 85, 0},
    {1400, 1050, 75, 0}, {1600, 1200, 70, 0} and {1920, 1200, 60, 0}.
    
    Signed-off-by: Torsten Kaiser <x11 at ariolc.dyndns.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index 47c169c..258ada5 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -738,7 +738,7 @@ DDCModesFromEstIII(unsigned char *est)
     int i, j, m;
 
     for (i = 0; i < 6; i++) {
-        for (j = 7; j > 0; j--) {
+        for (j = 7; j >= 0; j--) {
             if (est[i] & (1 << j)) {
                 m = (i * 8) + (7 - j);
                 if (EstIIIModes[m].w)
commit 0b3abacb6430e6593c4358420ba457d8149bd32b
Author: Torsten Kaiser <just.for.lkml at googlemail.com>
Date:   Fri Jul 6 12:06:13 2012 -0700

    xfree86: EDID Est III parsing can walk off end of array
    
    Using -O3 gcc notes that m could reach beyound the end of the EstIIIModes array,
    if the last bits of the 11s byte where set.
    Fix this, by extending the array to cover all possible bits from est.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=45623
    
    Signed-off-by: Torsten Kaiser <x11 at ariolc.dyndns.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c
index 8aa82d1..47c169c 100644
--- a/hw/xfree86/modes/xf86EdidModes.c
+++ b/hw/xfree86/modes/xf86EdidModes.c
@@ -723,7 +723,13 @@ static const struct {
     1920, 1200, 75, 0}, {
     1920, 1200, 85, 0}, {
     1920, 1440, 60, 0}, {
-1920, 1440, 75, 0},};
+    1920, 1440, 75, 0},
+        /* fill up last byte */
+    {
+    0,0,0,0}, {
+    0,0,0,0}, {
+    0,0,0,0}, {
+    0,0,0,0}, };
 
 static DisplayModePtr
 DDCModesFromEstIII(unsigned char *est)
@@ -735,7 +741,8 @@ DDCModesFromEstIII(unsigned char *est)
         for (j = 7; j > 0; j--) {
             if (est[i] & (1 << j)) {
                 m = (i * 8) + (7 - j);
-                modes = xf86ModesAdd(modes,
+                if (EstIIIModes[m].w)
+                    modes = xf86ModesAdd(modes,
                                      FindDMTMode(EstIIIModes[m].w,
                                                  EstIIIModes[m].h,
                                                  EstIIIModes[m].r,
commit 74b786f7cee5723468bba251a2155a65770b2ad4
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 17:45:03 2012 +0100

    xfree86: add autoAddGPU option (v2)
    
    This option is to stop the X server adding non-primary devices as
    gpu screens.
    
    v2: fix per Keith's suggestion.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 3ec40fe..6b806a3 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -712,7 +712,8 @@ typedef enum {
     FLAG_AUTO_ENABLE_DEVICES,
     FLAG_GLX_VISUALS,
     FLAG_DRI2,
-    FLAG_USE_SIGIO
+    FLAG_USE_SIGIO,
+    FLAG_AUTO_ADD_GPU,
 } FlagValues;
 
 /**
@@ -770,6 +771,8 @@ static OptionInfoRec FlagOptions[] = {
      {0}, FALSE},
     {FLAG_USE_SIGIO, "UseSIGIO", OPTV_BOOLEAN,
      {0}, FALSE},
+    {FLAG_AUTO_ADD_GPU, "AutoAddGPU", OPTV_BOOLEAN,
+     {0}, FALSE},
     {-1, NULL, OPTV_NONE,
      {0}, FALSE},
 };
@@ -862,6 +865,16 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
     xf86Msg(from, "%sutomatically enabling devices\n",
             xf86Info.autoEnableDevices ? "A" : "Not a");
 
+    if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ADD_GPU)) {
+        xf86GetOptValBool(FlagOptions, FLAG_AUTO_ADD_GPU,
+                          &xf86Info.autoAddGPU);
+        from = X_CONFIG;
+    }
+    else {
+        from = X_DEFAULT;
+    }
+    xf86Msg(from, "%sutomatically adding GPU devices\n",
+            xf86Info.autoAddGPU ? "A" : "Not a");
     /*
      * Set things up based on the config file information.  Some of these
      * settings may be overridden later when the command line options are
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index bb08917..7df7a80 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -126,11 +126,16 @@ xf86InfoRec xf86Info = {
 #if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
     .forceInputDevices = FALSE,
     .autoAddDevices = TRUE,
-    .autoEnableDevices = TRUE
+    .autoEnableDevices = TRUE,
 #else
     .forceInputDevices = TRUE,
     .autoAddDevices = FALSE,
-    .autoEnableDevices = FALSE
+    .autoEnableDevices = FALSE,
+#endif
+#if defined(CONFIG_UDEV_KMS)
+    .autoAddGPU = TRUE,
+#else
+    .autoAddGPU = FALSE,
 #endif
 };
 
diff --git a/hw/xfree86/common/xf86Privstr.h b/hw/xfree86/common/xf86Privstr.h
index e78cd40..e20be03 100644
--- a/hw/xfree86/common/xf86Privstr.h
+++ b/hw/xfree86/common/xf86Privstr.h
@@ -110,6 +110,8 @@ typedef struct {
 
     Bool dri2;
     MessageType dri2From;
+
+    Bool autoAddGPU;
 } xf86InfoRec, *xf86InfoPtr;
 
 #ifdef DPMSExtension
diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 0cc6c0a..3bfb22e 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -373,6 +373,13 @@ xf86platformProbeDev(DriverPtr drvp)
             continue;
     }
 
+    /* if autoaddgpu devices is enabled then go find a few more and add them as GPU screens */
+    if (xf86Info.autoAddGPU && numDevs) {
+        for (j = 0; j < xf86_num_platform_devices; j++) {
+            probeSingleDevice(&xf86_platform_devices[j], drvp, devList[0], PLATFORM_PROBE_GPU_SCREEN);
+        }
+    }
+
     return foundScreen;
 }
 
commit ef6686480ad1de6582b9ef5d13e5d4ffb3b3918c
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 17:30:39 2012 +0100

    xfree86: add platform bus hotplug support (v3)
    
    This provides add/remove support for platform devices at xfree86 ddx level.
    
    v2: cleanup properly if no driver found.
    
    v3: load the modesetting driver before checking driver list.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 50b7636..0cc6c0a 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -376,4 +376,107 @@ xf86platformProbeDev(DriverPtr drvp)
     return foundScreen;
 }
 
+int
+xf86platformAddDevice(int index)
+{
+    int i, old_screens, scr_index;
+    DriverPtr drvp = NULL;
+    int entity;
+    screenLayoutPtr layout;
+    static char *hotplug_driver_name = "modesetting";
+
+    /* force load the driver for now */
+    xf86LoadOneModule(hotplug_driver_name, NULL);
+
+    for (i = 0; i < xf86NumDrivers; i++) {
+        if (!xf86DriverList[i])
+            continue;
+
+        if (!strcmp(xf86DriverList[i]->driverName, hotplug_driver_name)) {
+            drvp = xf86DriverList[i];
+            break;
+        }
+    }
+    if (i == xf86NumDrivers)
+        return -1;
+
+    old_screens = xf86NumGPUScreens;
+    entity = xf86ClaimPlatformSlot(&xf86_platform_devices[index],
+                                   drvp, 0, 0, 0);
+    if (!drvp->platformProbe(drvp, entity, PLATFORM_PROBE_GPU_SCREEN, &xf86_platform_devices[index], 0)) {
+        xf86UnclaimPlatformSlot(&xf86_platform_devices[index], NULL);
+    }
+    if (old_screens == xf86NumGPUScreens)
+        return -1;
+    i = old_screens;
+
+    for (layout = xf86ConfigLayout.screens; layout->screen != NULL;
+         layout++) {
+        xf86GPUScreens[i]->confScreen = layout->screen;
+        break;
+    }
+
+    if (xf86GPUScreens[i]->PreInit &&
+        xf86GPUScreens[i]->PreInit(xf86GPUScreens[i], 0))
+        xf86GPUScreens[i]->configured = TRUE; 
+
+    if (!xf86GPUScreens[i]->configured) {
+        ErrorF("hotplugged device %d didn't configure\n", i);
+        xf86DeleteScreen(xf86GPUScreens[i]);
+        return -1;
+    }
+        
+   scr_index = AddGPUScreen(xf86GPUScreens[i]->ScreenInit, 0, NULL);
+   
+   dixSetPrivate(&xf86GPUScreens[i]->pScreen->devPrivates,
+                 xf86ScreenKey, xf86GPUScreens[i]);
+
+   CreateScratchPixmapsForScreen(xf86GPUScreens[i]->pScreen);
+  
+   return 0;
+}
+
+void
+xf86platformRemoveDevice(int index)
+{
+    EntityPtr entity;
+    int ent_num, i, j;
+    Bool found;
+
+    for (ent_num = 0; ent_num < xf86NumEntities; ent_num++) {
+        entity = xf86Entities[ent_num];
+        if (entity->bus.type == BUS_PLATFORM &&
+            entity->bus.id.plat == &xf86_platform_devices[index])
+            break;
+    }
+    if (ent_num == xf86NumEntities)
+        goto out;
+
+    found = FALSE;
+    for (i = 0; i < xf86NumGPUScreens; i++) {
+        for (j = 0; j < xf86GPUScreens[i]->numEntities; j++)
+            if (xf86GPUScreens[i]->entityList[j] == ent_num) {
+                found = TRUE;
+                break;
+            }
+        if (found)
+            break;
+    }
+    if (!found) {
+        ErrorF("failed to find screen to remove\n");
+        goto out;
+    }
+
+    xf86GPUScreens[i]->pScreen->CloseScreen(xf86GPUScreens[i]->pScreen);
+
+    RemoveGPUScreen(xf86GPUScreens[i]->pScreen);
+    xf86DeleteScreen(xf86GPUScreens[i]);
+
+    xf86UnclaimPlatformSlot(&xf86_platform_devices[index], NULL);
+
+    xf86_remove_platform_device(index);
+
+ out:
+    return;
+}
 #endif
diff --git a/hw/xfree86/common/xf86platformBus.h b/hw/xfree86/common/xf86platformBus.h
index 15a3022..49afc24 100644
--- a/hw/xfree86/common/xf86platformBus.h
+++ b/hw/xfree86/common/xf86platformBus.h
@@ -47,6 +47,11 @@ xf86_remove_platform_device(int dev_index);
 extern Bool
 xf86_add_platform_device_attrib(int index, int attrib_id, char *attrib_str);
 
+extern int
+xf86platformAddDevice(int index);
+extern void
+xf86platformRemoveDevice(int index);
+
 extern _X_EXPORT char *
 xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib_id);
 extern _X_EXPORT Bool
diff --git a/hw/xfree86/os-support/linux/lnx_platform.c b/hw/xfree86/os-support/linux/lnx_platform.c
index 9c63ee5..76f5583 100644
--- a/hw/xfree86/os-support/linux/lnx_platform.c
+++ b/hw/xfree86/os-support/linux/lnx_platform.c
@@ -15,6 +15,8 @@
 #include "xf86platformBus.h"
 #include "xf86Bus.h"
 
+#include "hotplug.h"
+
 static Bool
 get_drm_info(struct OdevAttributes *attribs, char *path)
 {
@@ -127,4 +129,51 @@ out_free:
     config_odev_free_attribute_list(attribs);
 }
 
+void NewGPUDeviceRequest(struct OdevAttributes *attribs)
+{
+    int old_num = xf86_num_platform_devices;
+    int ret;
+    xf86PlatformDeviceProbe(attribs);
+
+    if (old_num == xf86_num_platform_devices)
+        return;
+
+    ret = xf86platformAddDevice(xf86_num_platform_devices-1);
+    if (ret == -1)
+        xf86_remove_platform_device(xf86_num_platform_devices-1);
+
+    ErrorF("xf86: found device %d\n", xf86_num_platform_devices);
+    return;
+}
+
+void DeleteGPUDeviceRequest(struct OdevAttributes *attribs)
+{
+    struct OdevAttribute *attrib;
+    int index;
+    char *syspath = NULL;
+
+    xorg_list_for_each_entry(attrib, &attribs->list, member) {
+        if (attrib->attrib_id == ODEV_ATTRIB_SYSPATH) {
+            syspath = attrib->attrib_name;
+            break;
+        }
+    }
+
+    for (index = 0; index < xf86_num_platform_devices; index++) {
+        char *dspath;
+        dspath = xf86_get_platform_attrib(index, ODEV_ATTRIB_SYSPATH);
+        if (!strcmp(syspath, dspath))
+            break;
+    }
+
+    if (index == xf86_num_platform_devices)
+        goto out;
+
+    ErrorF("xf86: remove device %d %s\n", index, syspath);
+
+    xf86platformRemoveDevice(index);
+out:
+    config_odev_free_attribute_list(attribs);
+}
+
 #endif
commit b27cf30995e05da11e827ec41060051673336a7b
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 17:29:56 2012 +0100

    xserver/config: add udev/drm hotplug callbacks. (v2)
    
    This adds callbacks into the ddx for udev gpu hotplug.
    
    v2: fix some strncmp returns.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/config/udev.c b/config/udev.c
index efa8d32..5297b90 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -52,6 +52,12 @@
 
 static struct udev_monitor *udev_monitor;
 
+#ifdef CONFIG_UDEV_KMS
+static Bool
+config_udev_odev_setup_attribs(const char *path, const char *syspath,
+                               config_odev_probe_proc_ptr probe_callback);
+#endif
+
 static void
 device_added(struct udev_device *udev_device)
 {
@@ -85,6 +91,20 @@ device_added(struct udev_device *udev_device)
     if (!SeatId && strcmp(dev_seat, "seat0"))
         return;
 
+#ifdef CONFIG_UDEV_KMS
+    if (!strcmp(udev_device_get_subsystem(udev_device), "drm")) {
+        const char *sysname = udev_device_get_sysname(udev_device);
+
+        if (strncmp(sysname, "card", 4) != 0)
+            return;
+
+        LogMessage(X_INFO, "config/udev: Adding drm device (%s)\n", path);
+
+        config_udev_odev_setup_attribs(path, syspath, NewGPUDeviceRequest);
+        return;
+    }
+#endif
+
     if (!udev_device_get_property_value(udev_device, "ID_INPUT")) {
         LogMessageVerb(X_INFO, 10,
                        "config/udev: ignoring device %s without "
@@ -240,6 +260,22 @@ device_removed(struct udev_device *device)
     char *value;
     const char *syspath = udev_device_get_syspath(device);
 
+#ifdef CONFIG_UDEV_KMS
+    if (!strcmp(udev_device_get_subsystem(device), "drm")) {
+        const char *sysname = udev_device_get_sysname(device);
+        const char *path = udev_device_get_devnode(device);
+
+        if (strncmp(sysname,"card", 4) != 0)
+            return;
+        ErrorF("removing GPU device %s %d\n", syspath, path);
+        if (!path)
+            return;
+
+        config_udev_odev_setup_attribs(path, syspath, DeleteGPUDeviceRequest);
+        return;
+    }
+#endif
+
     if (asprintf(&value, "udev:%s", syspath) == -1)
         return;
 
@@ -296,6 +332,9 @@ config_udev_pre_init(void)
     udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "input",
                                                     NULL);
     udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL); /* For Wacom serial devices */
+#ifdef CONFIG_UDEV_KMS
+    udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "drm", NULL); /* For output GPU devices */
+#endif
 
 #ifdef HAVE_UDEV_MONITOR_FILTER_ADD_MATCH_TAG
     if (SeatId && strcmp(SeatId, "seat0"))
@@ -322,6 +361,9 @@ config_udev_init(void)
 
     udev_enumerate_add_match_subsystem(enumerate, "input");
     udev_enumerate_add_match_subsystem(enumerate, "tty");
+#ifdef CONFIG_UDEV_KMS
+    udev_enumerate_add_match_subsystem(enumerate, "drm");
+#endif
 
 #ifdef HAVE_UDEV_ENUMERATE_ADD_MATCH_TAG
     if (SeatId && strcmp(SeatId, "seat0"))
diff --git a/include/hotplug.h b/include/hotplug.h
index 5000762..96b078d 100644
--- a/include/hotplug.h
+++ b/include/hotplug.h
@@ -65,4 +65,8 @@ config_odev_free_attributes(struct OdevAttributes *attribs);
 typedef void (*config_odev_probe_proc_ptr)(struct OdevAttributes *attribs);
 void config_odev_probe(config_odev_probe_proc_ptr probe_callback);
 
+#ifdef CONFIG_UDEV_KMS
+void NewGPUDeviceRequest(struct OdevAttributes *attribs);
+void DeleteGPUDeviceRequest(struct OdevAttributes *attribs);
+#endif
 #endif                          /* HOTPLUG_H */
commit 53b66c084fbf5bf47f8121632fabdc39b9fe8337
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 17:18:10 2012 +0100

    xfree86: add DDX gpu screen support. (v3)
    
    This just adds the structures and interfaces required for adding/deleteing
    gpu screens at the DDX level. The platform probe can pass a new flag
    to the driver, so they can call xf86AllocateScreen and pass back the new
    gpu screen flag.
    
    It also calls the gpu screens preinit and screeninit routines at
    startup.
    
    v2: fix delete screen use after free.
    
    v3: split out pScrn into separate patch
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 88a219c..6116985 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -465,4 +465,7 @@ extern _X_EXPORT ScreenPtr xf86ScrnToScreen(ScrnInfoPtr pScrn);
 
 #define XF86_SCRN_INTERFACE 1 /* define for drivers to use in api compat */
 
+/* flags passed to xf86 allocate screen */
+#define XF86_ALLOCATE_GPU_SCREEN 1
+
 #endif                          /* _XF86_H */
diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index d0cfb2b..6de8409 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -189,6 +189,10 @@ xf86BusConfig(void)
         }
     }
 
+    /* bind GPU conf screen to protocol screen 0 */
+    for (i = 0; i < xf86NumGPUScreens; i++)
+        xf86GPUScreens[i]->confScreen = xf86Screens[0]->confScreen;
+
     /* If no screens left, return now.  */
     if (xf86NumScreens == 0) {
         xf86Msg(X_ERROR,
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 0071004..bb08917 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -51,6 +51,7 @@ DevPrivateKeyRec xf86CreateRootWindowKeyRec;
 DevPrivateKeyRec xf86ScreenKeyRec;
 
 ScrnInfoPtr *xf86Screens = NULL;        /* List of ScrnInfos */
+ScrnInfoPtr *xf86GPUScreens = NULL;        /* List of ScrnInfos */
 
 const unsigned char byte_reversed[256] = {
     0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
@@ -153,6 +154,7 @@ int xf86NumDrivers = 0;
 InputDriverPtr *xf86InputDriverList = NULL;
 int xf86NumInputDrivers = 0;
 int xf86NumScreens = 0;
+int xf86NumGPUScreens = 0;
 
 const char *xf86VisualNames[] = {
     "StaticGray",
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 18f30b7..f681a85 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -169,15 +169,28 @@ xf86AllocateScreen(DriverPtr drv, int flags)
     int i;
     ScrnInfoPtr pScrn;
 
-    if (xf86Screens == NULL)
-        xf86NumScreens = 0;
-
-    i = xf86NumScreens++;
-    xf86Screens = xnfrealloc(xf86Screens, xf86NumScreens * sizeof(ScrnInfoPtr));
-    xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1);
-    pScrn = xf86Screens[i];
-    pScrn->scrnIndex = i;      /* Changes when a screen is removed */
-    pScrn->origIndex = i;      /* This never changes */
+    if (flags & XF86_ALLOCATE_GPU_SCREEN) {
+        if (xf86GPUScreens == NULL)
+            xf86NumGPUScreens = 0;
+        i = xf86NumGPUScreens++;
+        xf86GPUScreens = xnfrealloc(xf86GPUScreens, xf86NumGPUScreens * sizeof(ScrnInfoPtr));
+        xf86GPUScreens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1);
+        pScrn = xf86GPUScreens[i];
+        pScrn->scrnIndex = i + GPU_SCREEN_OFFSET;      /* Changes when a screen is removed */
+        pScrn->is_gpu = TRUE;
+    } else {
+        if (xf86Screens == NULL)
+            xf86NumScreens = 0;
+
+        i = xf86NumScreens++;
+        xf86Screens = xnfrealloc(xf86Screens, xf86NumScreens * sizeof(ScrnInfoPtr));
+        xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1);
+        pScrn = xf86Screens[i];
+
+        pScrn->scrnIndex = i;      /* Changes when a screen is removed */
+    }
+
+    pScrn->origIndex = pScrn->scrnIndex;      /* This never changes */
     pScrn->privates = xnfcalloc(sizeof(DevUnion), xf86ScrnInfoPrivateCount);
     /*
      * EnableDisableFBAccess now gets initialized in InitOutput()
@@ -203,10 +216,17 @@ xf86DeleteScreen(ScrnInfoPtr pScrn)
 {
     int i;
     int scrnIndex;
-
-    /* First check if the screen is valid */
-    if (xf86NumScreens == 0 || xf86Screens == NULL)
-        return;
+    Bool is_gpu = FALSE;
+    if (pScrn->is_gpu) {
+        /* First check if the screen is valid */
+        if (xf86NumGPUScreens == 0 || xf86GPUScreens == NULL)
+            return;
+        is_gpu = TRUE;
+    } else {
+        /* First check if the screen is valid */
+        if (xf86NumScreens == 0 || xf86Screens == NULL)
+            return;
+    }
 
     if (!pScrn)
         return;
@@ -238,12 +258,23 @@ xf86DeleteScreen(ScrnInfoPtr pScrn)
 
     /* Move the other entries down, updating their scrnIndex fields */
 
-    xf86NumScreens--;
+    if (is_gpu) {
+        xf86NumGPUScreens--;
+        scrnIndex -= GPU_SCREEN_OFFSET;
+        for (i = scrnIndex; i < xf86NumGPUScreens; i++) {
+            xf86GPUScreens[i] = xf86GPUScreens[i + 1];
+            xf86GPUScreens[i]->scrnIndex = i + GPU_SCREEN_OFFSET;
+            /* Also need to take care of the screen layout settings */
+        }
+    }
+    else {
+        xf86NumScreens--;
 
-    for (i = scrnIndex; i < xf86NumScreens; i++) {
-        xf86Screens[i] = xf86Screens[i + 1];
-        xf86Screens[i]->scrnIndex = i;
-        /* Also need to take care of the screen layout settings */
+        for (i = scrnIndex; i < xf86NumScreens; i++) {
+            xf86Screens[i] = xf86Screens[i + 1];
+            xf86Screens[i]->scrnIndex = i;
+            /* Also need to take care of the screen layout settings */
+        }
     }
 }
 
@@ -267,6 +298,14 @@ xf86AllocateScrnInfoPrivateIndex(void)
         memset(&nprivs[idx], 0, sizeof(DevUnion));
         pScr->privates = nprivs;
     }
+    for (i = 0; i < xf86NumGPUScreens; i++) {
+        pScr = xf86GPUScreens[i];
+        nprivs = xnfrealloc(pScr->privates,
+                            xf86ScrnInfoPrivateCount * sizeof(DevUnion));
+        /* Zero the new private */
+        memset(&nprivs[idx], 0, sizeof(DevUnion));
+        pScr->privates = nprivs;
+    }
     return idx;
 }
 
@@ -1059,6 +1098,11 @@ xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format,
         xf86Screens[scrnIndex]->name)
         LogHdrMessageVerb(type, verb, format, args, "%s(%d): ",
                           xf86Screens[scrnIndex]->name, scrnIndex);
+    else if (scrnIndex >= GPU_SCREEN_OFFSET &&
+             scrnIndex < GPU_SCREEN_OFFSET + xf86NumGPUScreens &&
+             xf86GPUScreens[scrnIndex - GPU_SCREEN_OFFSET]->name)
+        LogHdrMessageVerb(type, verb, format, args, "%s(G%d): ",
+                          xf86GPUScreens[scrnIndex - GPU_SCREEN_OFFSET]->name, scrnIndex - GPU_SCREEN_OFFSET);
     else
         LogVMessageVerb(type, verb, format, args);
 }
@@ -1834,13 +1878,23 @@ xf86MotionHistoryAllocate(InputInfoPtr pInfo)
 ScrnInfoPtr
 xf86ScreenToScrn(ScreenPtr pScreen)
 {
-    assert(pScreen->myNum < xf86NumScreens);
-    return xf86Screens[pScreen->myNum];
+    if (pScreen->isGPU) {
+        assert(pScreen->myNum - GPU_SCREEN_OFFSET < xf86NumGPUScreens);
+        return xf86GPUScreens[pScreen->myNum - GPU_SCREEN_OFFSET];
+    } else {
+        assert(pScreen->myNum < xf86NumScreens);
+        return xf86Screens[pScreen->myNum];
+    }
 }
 
 ScreenPtr
 xf86ScrnToScreen(ScrnInfoPtr pScrn)
 {
-    assert(pScrn->scrnIndex < screenInfo.numScreens);
-    return screenInfo.screens[pScrn->scrnIndex];
+    if (pScrn->is_gpu) {
+        assert(pScrn->scrnIndex - GPU_SCREEN_OFFSET < screenInfo.numGPUScreens);
+        return screenInfo.gpuscreens[pScrn->scrnIndex - GPU_SCREEN_OFFSET];
+    } else {
+        assert(pScrn->scrnIndex < screenInfo.numScreens);
+        return screenInfo.screens[pScrn->scrnIndex];
+    }
 }
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 1f5a382..aa17a58 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -593,6 +593,18 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
             if (!xf86Screens[i]->configured)
                 xf86DeleteScreen(xf86Screens[i--]);
 
+        for (i = 0; i < xf86NumGPUScreens; i++) {
+            xf86VGAarbiterScrnInit(xf86GPUScreens[i]);
+            xf86VGAarbiterLock(xf86GPUScreens[i]);
+            if (xf86GPUScreens[i]->PreInit &&
+                xf86GPUScreens[i]->PreInit(xf86GPUScreens[i], 0))
+                xf86GPUScreens[i]->configured = TRUE;
+            xf86VGAarbiterUnlock(xf86GPUScreens[i]);
+        }
+        for (i = 0; i < xf86NumGPUScreens; i++)
+            if (!xf86GPUScreens[i]->configured)
+                xf86DeleteScreen(xf86GPUScreens[i--]);
+
         /*
          * If no screens left, return now.
          */
@@ -818,6 +830,36 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
         !dixRegisterPrivateKey(&xf86CreateRootWindowKeyRec, PRIVATE_SCREEN, 0))
         FatalError("Cannot register DDX private keys");
 
+    for (i = 0; i < xf86NumGPUScreens; i++) {
+        ScrnInfoPtr pScrn = xf86GPUScreens[i];
+        xf86VGAarbiterLock(pScrn);
+
+        /*
+         * Almost everything uses these defaults, and many of those that
+         * don't, will wrap them.
+         */
+        pScrn->EnableDisableFBAccess = xf86EnableDisableFBAccess;
+#ifdef XFreeXDGA
+        pScrn->SetDGAMode = xf86SetDGAMode;
+#endif
+        pScrn->DPMSSet = NULL;
+        pScrn->LoadPalette = NULL;
+        pScrn->SetOverscan = NULL;
+        pScrn->DriverFunc = NULL;
+        pScrn->pScreen = NULL;
+        scr_index = AddGPUScreen(pScrn->ScreenInit, argc, argv);
+        xf86VGAarbiterUnlock(pScrn);
+        if (scr_index == i) {
+            dixSetPrivate(&screenInfo.gpuscreens[scr_index]->devPrivates,
+                          xf86ScreenKey, xf86GPUScreens[i]);
+            pScrn->pScreen = screenInfo.gpuscreens[scr_index];
+            /* The driver should set this, but make sure it is set anyway */
+            pScrn->vtSema = TRUE;
+        } else {
+            FatalError("AddScreen/ScreenInit failed for gpu driver %d %d\n", i, scr_index);
+        }
+    }
+
     for (i = 0; i < xf86NumScreens; i++) {
         xf86VGAarbiterLock(xf86Screens[i]);
         /*
diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
index 42a3b30..c9f2e7e 100644
--- a/hw/xfree86/common/xf86Priv.h
+++ b/hw/xfree86/common/xf86Priv.h
@@ -95,6 +95,8 @@ extern _X_EXPORT Bool xorgHWAccess;
 
 extern _X_EXPORT RootWinPropPtr *xf86RegisteredPropertiesTable;
 
+extern ScrnInfoPtr *xf86GPUScreens;      /* List of pointers to ScrnInfoRecs */
+extern int xf86NumGPUScreens;
 #ifndef DEFAULT_VERBOSE
 #define DEFAULT_VERBOSE		0
 #endif
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index e12dcc4..6bd6a62 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -332,9 +332,9 @@ typedef struct _DriverRec {
 
 /*
  * platform probe flags
- * no flags are defined yet - but drivers should fail to load if a flag they
- * don't understand is passed.
  */
+#define PLATFORM_PROBE_GPU_SCREEN 1
+
 /*
  *  AddDriver flags
  */
@@ -813,6 +813,7 @@ typedef struct _ScrnInfoRec {
      */
     funcPointer reservedFuncs[NUM_RESERVED_FUNCS];
 
+    Bool is_gpu;
 } ScrnInfoRec;
 
 typedef struct {
commit 726d467b534a30d8cbaafb858339c638c9f83195
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Jun 25 11:51:26 2012 +0100

    xf86: cleanup helper code to use a pointer. (v1.1)
    
    This is in preparation for gpu screens in here, just use
    a pScrn pointer to point at the new screen.
    
    suggested by Keith.
    v1.1: fix spacing as suggested by Aaron.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 5ef1dab..18f30b7 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -167,6 +167,7 @@ ScrnInfoPtr
 xf86AllocateScreen(DriverPtr drv, int flags)
 {
     int i;
+    ScrnInfoPtr pScrn;
 
     if (xf86Screens == NULL)
         xf86NumScreens = 0;
@@ -174,22 +175,22 @@ xf86AllocateScreen(DriverPtr drv, int flags)
     i = xf86NumScreens++;
     xf86Screens = xnfrealloc(xf86Screens, xf86NumScreens * sizeof(ScrnInfoPtr));
     xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1);
-    xf86Screens[i]->scrnIndex = i;      /* Changes when a screen is removed */
-    xf86Screens[i]->origIndex = i;      /* This never changes */
-    xf86Screens[i]->privates = xnfcalloc(sizeof(DevUnion),
-                                         xf86ScrnInfoPrivateCount);
+    pScrn = xf86Screens[i];
+    pScrn->scrnIndex = i;      /* Changes when a screen is removed */
+    pScrn->origIndex = i;      /* This never changes */
+    pScrn->privates = xnfcalloc(sizeof(DevUnion), xf86ScrnInfoPrivateCount);
     /*
      * EnableDisableFBAccess now gets initialized in InitOutput()
-     * xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess;
+     * pScrn->EnableDisableFBAccess = xf86EnableDisableFBAccess;
      */
 
-    xf86Screens[i]->drv = drv;
+    pScrn->drv = drv;
     drv->refCount++;
-    xf86Screens[i]->module = DuplicateModule(drv->module, NULL);
+    pScrn->module = DuplicateModule(drv->module, NULL);
 
-    xf86Screens[i]->DriverFunc = drv->driverFunc;
+    pScrn->DriverFunc = drv->driverFunc;
 
-    return xf86Screens[i];
+    return pScrn;
 }
 
 /*
commit 9d179818293b466ec6f1777f0b792e1fbbeb318c
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 17:09:38 2012 +0100

    dix: introduce gpu screens. (v5)
    
    This patch introduces gpu screens into screenInfo. It adds interfaces
    for adding and removing gpu screens, along with adding private fixup,
    block handler support, and scratch pixmap init.
    
    GPU screens have a myNum that is offset by GPU_SCREEN_OFFSET (256),
    this is used for logging etc.
    
    RemoveGPUScreen isn't used until "xfree86: add platform bus hotplug support".
    
    v2: no glyph pictures for GPU screens for now.
    v3: introduce MAXGPUSCREENS, fix return value check
    v4: fixup myNum when renumbering screens (ajax)
    v5: drop cursor privates for now.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 39d791d..fa39728 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3724,7 +3724,7 @@ with its screen number, a pointer to its ScreenRec, argc, and argv.
 
 */
 
-static int init_screen(ScreenPtr pScreen, int i)
+static int init_screen(ScreenPtr pScreen, int i, Bool gpu)
 {
     int scanlinepad, format, depth, bitsPerPixel, j, k;
 
@@ -3734,6 +3734,10 @@ static int init_screen(ScreenPtr pScreen, int i)
         return -1;
     }
     pScreen->myNum = i;
+    if (gpu) {
+        pScreen->myNum += GPU_SCREEN_OFFSET;
+        pScreen->isGPU = TRUE;
+    }
     pScreen->totalPixmapSize = 0;       /* computed in CreateScratchPixmapForScreen */
     pScreen->ClipNotify = 0;    /* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
@@ -3790,7 +3794,7 @@ AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
     if (!pScreen)
         return -1;
 
-    ret = init_screen(pScreen, i);
+    ret = init_screen(pScreen, i, FALSE);
     if (ret != 0) {
         free(pScreen);
         return ret;
@@ -3820,3 +3824,68 @@ AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
 
     return i;
 }
+
+int
+AddGPUScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
+                              int /*argc */ ,
+                              char **      /*argv */
+                              ),
+             int argc, char **argv)
+{
+    int i;
+    ScreenPtr pScreen;
+    Bool ret;
+
+    i = screenInfo.numGPUScreens;
+    if (i == MAXGPUSCREENS)
+        return -1;
+
+    pScreen = (ScreenPtr) calloc(1, sizeof(ScreenRec));
+    if (!pScreen)
+        return -1;
+
+    ret = init_screen(pScreen, i, TRUE);
+    if (ret != 0) {
+        free(pScreen);
+        return ret;
+    }
+
+    /* This is where screen specific stuff gets initialized.  Load the
+       screen structure, call the hardware, whatever.
+       This is also where the default colormap should be allocated and
+       also pixel values for blackPixel, whitePixel, and the cursor
+       Note that InitScreen is NOT allowed to modify argc, argv, or
+       any of the strings pointed to by argv.  They may be passed to
+       multiple screens.
+     */
+    screenInfo.gpuscreens[i] = pScreen;
+    screenInfo.numGPUScreens++;
+    if (!(*pfnInit) (pScreen, argc, argv)) {
+        dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
+        free(pScreen);
+        screenInfo.numGPUScreens--;
+        return -1;
+    }
+
+    update_desktop_dimensions();
+
+    return i;
+}
+
+void
+RemoveGPUScreen(ScreenPtr pScreen)
+{
+    int idx, j;
+    if (!pScreen->isGPU)
+        return;
+
+    idx = pScreen->myNum - GPU_SCREEN_OFFSET;
+    for (j = idx; j < screenInfo.numGPUScreens - 1; j++) {
+        screenInfo.gpuscreens[j] = screenInfo.gpuscreens[j + 1];
+        screenInfo.gpuscreens[j]->myNum = j + GPU_SCREEN_OFFSET;
+    }
+    screenInfo.numGPUScreens--;
+
+    free(pScreen);
+
+}
diff --git a/dix/dixutils.c b/dix/dixutils.c
index b249a81..3f24629 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -386,6 +386,9 @@ BlockHandler(pointer pTimeout, pointer pReadmask)
     for (i = 0; i < screenInfo.numScreens; i++)
         (*screenInfo.screens[i]->BlockHandler) (screenInfo.screens[i],
                                                 pTimeout, pReadmask);
+    for (i = 0; i < screenInfo.numGPUScreens; i++)
+        (*screenInfo.gpuscreens[i]->BlockHandler) (screenInfo.gpuscreens[i],
+                                                   pTimeout, pReadmask);
     for (i = 0; i < numHandlers; i++)
         if (!handlers[i].deleted)
             (*handlers[i].BlockHandler) (handlers[i].blockData,
@@ -422,6 +425,9 @@ WakeupHandler(int result, pointer pReadmask)
     for (i = 0; i < screenInfo.numScreens; i++)
         (*screenInfo.screens[i]->WakeupHandler) (screenInfo.screens[i],
                                                  result, pReadmask);
+    for (i = 0; i < screenInfo.numGPUScreens; i++)
+        (*screenInfo.gpuscreens[i]->WakeupHandler) (screenInfo.gpuscreens[i],
+                                                    result, pReadmask);
     if (handlerDeleted) {
         for (i = 0; i < numHandlers;)
             if (handlers[i].deleted) {
diff --git a/dix/main.c b/dix/main.c
index 9524189..42f517d 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -207,6 +207,12 @@ main(int argc, char *argv[], char *envp[])
             FatalError("no screens found");
         InitExtensions(argc, argv);
 
+        for (i = 0; i < screenInfo.numGPUScreens; i++) {
+            ScreenPtr pScreen = screenInfo.gpuscreens[i];
+            if (!CreateScratchPixmapsForScreen(pScreen))
+                FatalError("failed to create scratch pixmaps");
+        }
+
         for (i = 0; i < screenInfo.numScreens; i++) {
             ScreenPtr pScreen = screenInfo.screens[i];
 
@@ -336,6 +342,15 @@ main(int argc, char *argv[], char *envp[])
             screenInfo.numScreens = i;
         }
 
+        for (i = screenInfo.numGPUScreens - 1; i >= 0; i--) {
+            ScreenPtr pScreen = screenInfo.gpuscreens[i];
+            FreeScratchPixmapsForScreen(pScreen);
+            (*pScreen->CloseScreen) (pScreen);
+            dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
+            free(pScreen);
+            screenInfo.numGPUScreens = i;
+        }
+
         ReleaseClientIds(serverClient);
         dixFreePrivates(serverClient->devPrivates, PRIVATE_CLIENT);
         serverClient->devPrivates = NULL;
diff --git a/dix/privates.c b/dix/privates.c
index b58085f..740ead7 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -222,6 +222,10 @@ fixupScreens(FixupFunc fixup, unsigned bytes)
     for (s = 0; s < screenInfo.numScreens; s++)
         if (!fixupOneScreen (screenInfo.screens[s], fixup, bytes))
             return FALSE;
+
+    for (s = 0; s < screenInfo.numGPUScreens; s++)
+        if (!fixupOneScreen (screenInfo.gpuscreens[s], fixup, bytes))
+            return FALSE;
     return TRUE;
 }
 
diff --git a/include/misc.h b/include/misc.h
index aa62f6a..6bea82f 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -83,10 +83,14 @@ OF THIS SOFTWARE.
 #ifndef MAXSCREENS
 #define MAXSCREENS	16
 #endif
+#ifndef MAXGPUSCREENS
+#define MAXGPUSCREENS	16
+#endif
 #define MAXCLIENTS	256
 #define MAXEXTENSIONS   128
 #define MAXFORMATS	8
 #define MAXDEVICES	40      /* input devices */
+#define GPU_SCREEN_OFFSET 256
 
 /* 128 event opcodes for core + extension events, excluding GE */
 #define MAXEVENTS       128
diff --git a/include/screenint.h b/include/screenint.h
index 6b0cc70..8205f63 100644
--- a/include/screenint.h
+++ b/include/screenint.h
@@ -62,6 +62,15 @@ extern _X_EXPORT int AddScreen(Bool (* /*pfnInit */ )(
                                int /*argc */ ,
                                char ** /*argv */ );
 
+
+extern _X_EXPORT int AddGPUScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
+                                                   int /*argc */ ,
+                                                   char **      /*argv */
+                                                   ),
+                                  int argc, char **argv);
+
+extern _X_EXPORT void RemoveGPUScreen(ScreenPtr pScreen);
+
 typedef struct _ColormapRec *ColormapPtr;
 
 #endif                          /* SCREENINT_H */
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 7af2bf5..bcac475 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -477,6 +477,8 @@ typedef struct _Screen {
      * malicious users to steal framebuffer's content if that would be the
      * default */
     Bool canDoBGNoneRoot;
+
+    Bool isGPU;
 } ScreenRec;
 
 static inline RegionPtr
@@ -494,6 +496,8 @@ typedef struct _ScreenInfo {
      PixmapFormatRec formats[MAXFORMATS];
     int numScreens;
     ScreenPtr screens[MAXSCREENS];
+    int numGPUScreens;
+    ScreenPtr gpuscreens[MAXGPUSCREENS];
     int x;                      /* origin */
     int y;                      /* origin */
     int width;                  /* total width of all screens together */
diff --git a/render/glyph.c b/render/glyph.c
index acb573f..c121e64 100644
--- a/render/glyph.c
+++ b/render/glyph.c
@@ -687,6 +687,8 @@ miGlyphs(CARD8 op,
 
 PicturePtr GetGlyphPicture(GlyphPtr glyph, ScreenPtr pScreen)
 {
+    if (pScreen->isGPU)
+        return NULL;
     return GlyphPicture(glyph)[pScreen->myNum];
 }
 
commit 3478af3374abffa0c226ee077fda1fcfc0751e74
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 17:01:21 2012 +0100

    screen: split out screen init code. (v2)
    
    This is a precursor for reusing this code to init gpu screens.
    
    v2: fixup int check as per Keith's review.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 7d2d3b7..39d791d 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3724,29 +3724,13 @@ with its screen number, a pointer to its ScreenRec, argc, and argv.
 
 */
 
-int
-AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
-                           int /*argc */ ,
-                           char **      /*argv */
-          ), int argc, char **argv)
+static int init_screen(ScreenPtr pScreen, int i)
 {
-
-    int i;
     int scanlinepad, format, depth, bitsPerPixel, j, k;
-    ScreenPtr pScreen;
-
-    i = screenInfo.numScreens;
-    if (i == MAXSCREENS)
-        return -1;
-
-    pScreen = (ScreenPtr) calloc(1, sizeof(ScreenRec));
-    if (!pScreen)
-        return -1;
 
     dixInitScreenSpecificPrivates(pScreen);
 
     if (!dixAllocatePrivates(&pScreen->devPrivates, PRIVATE_SCREEN)) {
-        free(pScreen);
         return -1;
     }
     pScreen->myNum = i;
@@ -3784,7 +3768,33 @@ AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
             PixmapWidthPaddingInfo[depth].notPower2 = 0;
         }
     }
+    return 0;
+}
+
+int
+AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
+                           int /*argc */ ,
+                           char **      /*argv */
+          ), int argc, char **argv)
+{
 
+    int i;
+    ScreenPtr pScreen;
+    Bool ret;
+
+    i = screenInfo.numScreens;
+    if (i == MAXSCREENS)
+        return -1;
+
+    pScreen = (ScreenPtr) calloc(1, sizeof(ScreenRec));
+    if (!pScreen)
+        return -1;
+
+    ret = init_screen(pScreen, i);
+    if (ret != 0) {
+        free(pScreen);
+        return ret;
+    }
     /* This is where screen specific stuff gets initialized.  Load the
        screen structure, call the hardware, whatever.
        This is also where the default colormap should be allocated and
commit cf66471353ac5899383b573a3cfca407e90d501e
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue May 8 14:26:47 2012 +0100

    xfree86: use udev to provide device enumeration for kms devices (v10)
    
    On Linux in order for future hotplug work, we are required to interface
    to udev to detect device creation/removal. In order to try and get
    some earlier testing on this, this patch adds the ability to use
    udev for device enumeration on Linux.
    
    At startup the list of drm/kms devices is probed and this info is
    used to load drivers.
    
    A new driver probing method is introduced that passes the udev
    device info to the driver for probing.
    
    The probing integrates with the pci probing code and will fallback
    to the pci probe and old school probe functions in turn.
    
    The flags parameter to the probe function will be used later
    to provide hotplug and gpu screen flags for the driver to behave
    in a different way.
    
    This patch changes the driver ABI, all drivers should at least
    be set with a NULL udev probe function after this commit.
    
    v2: rename to platform bus, now with 100% less udev specific,
    
    this version passes config_odev_attribs around which are an array
    of id/string pairs, then the udev code can attach the set of attribs
    it understands, the OS specific code can attach its attrib, and then
    the core/drivers can lookup the required attribs.
    
    also add MATCH_PCI_DEVICES macro.
    
    This version is mainly to address concerns raised by ajax.
    
    v3: Address comments from Peter.
    fix whitespace that snuck in.
    rework to use a linked list with some core functions that
    xf86 wraps.
    
    v4: add free list, fix struct whitespace.
    ajax this address most of your issues?
    
    v5: drop probe ifdef, fix logic issue
    
    v6: some overhaul after more testing.
    
    Implement primaryBus for platform devices.
    document hotplug.h dev attribs - drop sysname attrib
    fix build with udev kms disabled
    make probing work like the PCI probe code,
       match against bus id if one exists, or primary device.
    
    RFC: add new bus id support "PLAT:syspath". we probably
    want to match on this a bit different, or use a different
    property maybe. I was mainly wanting this for use with
    specifying usb devices in xorg.conf directly, but PLAT:path
    could also work I suppose.
    
    v6.1: add missing noop platform function
    
    v7: fix two interactions with pci probing and slot claiming, prevents
    pci and platform trying to load two drivers for same slot.
    
    v8: test with zaphod mode on -ati driver, fixup resulting issue
    clean up common probe code into another function, change busid
    matching to allow dropping end of strings.
    
    v9: fix platform probing logic so it actually works.
    v9.1: fix pdev init to NULL properly.
    
    v10: address most of Keith's concerns.
    
    v4 was thanks to Reviewed-by: Adam Jackson <ajax at redhat.com>
    v5 was Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/config/config-backends.h b/config/config-backends.h
index 62abc0a..6423701 100644
--- a/config/config-backends.h
+++ b/config/config-backends.h
@@ -36,6 +36,7 @@ BOOL device_is_duplicate(const char *config_info);
 int config_udev_pre_init(void);
 int config_udev_init(void);
 void config_udev_fini(void);
+void config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback);
 #else
 
 #ifdef CONFIG_NEED_DBUS
diff --git a/config/config.c b/config/config.c
index 24e7ba7..d0889a3 100644
--- a/config/config.c
+++ b/config/config.c
@@ -85,6 +85,14 @@ config_fini(void)
 #endif
 }
 
+void
+config_odev_probe(config_odev_probe_proc_ptr probe_callback)
+{
+#if defined(CONFIG_UDEV_KMS)
+    config_udev_odev_probe(probe_callback);
+#endif
+}
+
 static void
 remove_device(const char *backend, DeviceIntPtr dev)
 {
@@ -133,3 +141,51 @@ device_is_duplicate(const char *config_info)
 
     return FALSE;
 }
+
+struct OdevAttributes *
+config_odev_allocate_attribute_list(void)
+{
+    struct OdevAttributes *attriblist;
+
+    attriblist = malloc(sizeof(struct OdevAttributes));
+    if (!attriblist)
+        return NULL;
+
+    xorg_list_init(&attriblist->list);
+    return attriblist;
+}
+
+void
+config_odev_free_attribute_list(struct OdevAttributes *attribs)
+{
+    config_odev_free_attributes(attribs);
+    free(attribs);
+}
+
+Bool
+config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
+                          const char *attrib_name)
+{
+    struct OdevAttribute *oa;
+
+    oa = malloc(sizeof(struct OdevAttribute));
+    if (!oa)
+        return FALSE;
+
+    oa->attrib_id = attrib;
+    oa->attrib_name = strdup(attrib_name);
+    xorg_list_append(&oa->member, &attribs->list);
+    return TRUE;
+}
+
+void
+config_odev_free_attributes(struct OdevAttributes *attribs)
+{
+    struct OdevAttribute *iter, *safe;
+
+    xorg_list_for_each_entry_safe(iter, safe, &attribs->list, member) {
+        xorg_list_del(&iter->member);
+        free(iter->attrib_name);
+        free(iter);
+    }
+}
diff --git a/config/udev.c b/config/udev.c
index 1995184..efa8d32 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -366,3 +366,72 @@ config_udev_fini(void)
     udev_monitor = NULL;
     udev_unref(udev);
 }
+
+#ifdef CONFIG_UDEV_KMS
+
+static Bool
+config_udev_odev_setup_attribs(const char *path, const char *syspath,
+                               config_odev_probe_proc_ptr probe_callback)
+{
+    struct OdevAttributes *attribs = config_odev_allocate_attribute_list();
+    int ret;
+
+    if (!attribs)
+        return FALSE;
+
+    ret = config_odev_add_attribute(attribs, ODEV_ATTRIB_PATH, path);
+    if (ret == FALSE)
+        goto fail;
+
+    ret = config_odev_add_attribute(attribs, ODEV_ATTRIB_SYSPATH, syspath);
+    if (ret == FALSE)
+        goto fail;
+
+    /* ownership of attribs is passed to probe layer */
+    probe_callback(attribs);
+    return TRUE;
+fail:
+    config_odev_free_attributes(attribs);
+    free(attribs);
+    return FALSE;
+}
+
+void
+config_udev_odev_probe(config_odev_probe_proc_ptr probe_callback)
+{
+    struct udev *udev;
+    struct udev_enumerate *enumerate;
+    struct udev_list_entry *devices, *device;
+
+    udev = udev_monitor_get_udev(udev_monitor);
+    enumerate = udev_enumerate_new(udev);
+    if (!enumerate)
+        return;
+
+    udev_enumerate_add_match_subsystem(enumerate, "drm");
+    udev_enumerate_add_match_sysname(enumerate, "card[0-9]*");
+    udev_enumerate_scan_devices(enumerate);
+    devices = udev_enumerate_get_list_entry(enumerate);
+    udev_list_entry_foreach(device, devices) {
+        const char *syspath = udev_list_entry_get_name(device);
+        struct udev_device *udev_device = udev_device_new_from_syspath(udev, syspath);
+        const char *path = udev_device_get_devnode(udev_device);
+        const char *sysname = udev_device_get_sysname(udev_device);
+
+        if (!path || !syspath)
+            goto no_probe;
+        else if (strcmp(udev_device_get_subsystem(udev_device), "drm") != 0)
+            goto no_probe;
+        else if (strncmp(sysname, "card", 4) != 0)
+            goto no_probe;
+
+        config_udev_odev_setup_attribs(path, syspath, probe_callback);
+
+    no_probe:
+        udev_device_unref(udev_device);
+    }
+    udev_enumerate_unref(enumerate);
+    return;
+}
+#endif
+
diff --git a/configure.ac b/configure.ac
index d5ddf6e..d1358a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -615,6 +615,7 @@ AC_ARG_ENABLE(dbe,            AS_HELP_STRING([--disable-dbe], [Build DBE extensi
 AC_ARG_ENABLE(xf86bigfont,    AS_HELP_STRING([--enable-xf86bigfont], [Build XF86 Big Font extension (default: disabled)]), [XF86BIGFONT=$enableval], [XF86BIGFONT=no])
 AC_ARG_ENABLE(dpms,           AS_HELP_STRING([--disable-dpms], [Build DPMS extension (default: enabled)]), [DPMSExtension=$enableval], [DPMSExtension=yes])
 AC_ARG_ENABLE(config-udev,    AS_HELP_STRING([--enable-config-udev], [Build udev support (default: auto)]), [CONFIG_UDEV=$enableval], [CONFIG_UDEV=auto])
+AC_ARG_ENABLE(config-udev-kms,    AS_HELP_STRING([--enable-config-udev-kms], [Build udev kms support (default: auto)]), [CONFIG_UDEV_KMS=$enableval], [CONFIG_UDEV_KMS=auto])
 AC_ARG_ENABLE(config-dbus,    AS_HELP_STRING([--enable-config-dbus], [Build D-BUS API support (default: no)]), [CONFIG_DBUS_API=$enableval], [CONFIG_DBUS_API=no])
 AC_ARG_ENABLE(config-hal,     AS_HELP_STRING([--disable-config-hal], [Build HAL support (default: auto)]), [CONFIG_HAL=$enableval], [CONFIG_HAL=auto])
 AC_ARG_ENABLE(config-wscons,  AS_HELP_STRING([--enable-config-wscons], [Build wscons config support (default: auto)]), [CONFIG_WSCONS=$enableval], [CONFIG_WSCONS=auto])
@@ -704,6 +705,7 @@ case $host_os in
 		CONFIG_DBUS_API=no
 		CONFIG_HAL=no
 		CONFIG_UDEV=no
+		CONFIG_UDEV_KMS=no
 		DGA=no
 		DRI2=no
 		INT10MODULE=no
@@ -838,11 +840,16 @@ AM_CONDITIONAL(CONFIG_UDEV, [test "x$CONFIG_UDEV" = xyes])
 if test "x$CONFIG_UDEV" = xyes; then
 	CONFIG_DBUS_API=no
 	CONFIG_HAL=no
+	if test "x$CONFIG_UDEV_KMS" = xauto; then
+		CONFIG_UDEV_KMS="$HAVE_LIBUDEV"
+	fi
 	if ! test "x$HAVE_LIBUDEV" = xyes; then
 		AC_MSG_ERROR([udev configuration API requested, but libudev is not installed])
 	fi
 	AC_DEFINE(CONFIG_UDEV, 1, [Use libudev for input hotplug])
-
+	if test "x$CONFIG_UDEV_KMS" = xyes; then
+		AC_DEFINE(CONFIG_UDEV_KMS, 1, [Use libudev for kms enumeration])
+	fi
 	SAVE_LIBS=$LIBS
 	SAVE_CFLAGS=$CFLAGS
 	CFLAGS=$UDEV_CFLAGS
@@ -852,6 +859,7 @@ if test "x$CONFIG_UDEV" = xyes; then
 	LIBS=$SAVE_LIBS
 	CFLAGS=$SAVE_CFLAGS
 fi
+AM_CONDITIONAL(CONFIG_UDEV_KMS, [test "x$CONFIG_UDEV_KMS" = xyes])
 
 dnl HAVE_DBUS is true if we actually have the D-Bus library, whereas
 dnl CONFIG_DBUS_API is true if we want to enable the D-Bus config
@@ -1099,7 +1107,7 @@ case "$DRI2,$HAVE_DRI2PROTO" in
 esac
 AM_CONDITIONAL(DRI2, test "x$DRI2" = xyes)
 
-if test "x$DRI" = xyes || test "x$DRI2" = xyes; then
+if test "x$DRI" = xyes || test "x$DRI2" = xyes || test "x$CONFIG_UDEV_KMS" = xyes; then
 	if test "x$DRM" = xyes; then
 		AC_DEFINE(WITH_LIBDRM, 1, [Building with libdrm support])
 		PKG_CHECK_MODULES([LIBDRM], $LIBDRM)
@@ -1650,7 +1658,7 @@ if test "x$XORG" = xyes; then
 
 	PKG_CHECK_MODULES([PCIACCESS], $LIBPCIACCESS)
 	SDK_REQUIRED_MODULES="$SDK_REQUIRED_MODULES $LIBPCIACCESS"
-	XORG_SYS_LIBS="$XORG_SYS_LIBS $PCIACCESS_LIBS $GLX_SYS_LIBS"
+	XORG_SYS_LIBS="$XORG_SYS_LIBS $PCIACCESS_LIBS $GLX_SYS_LIBS $LIBDRM_LIBS"
 	XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
 
 	AC_DEFINE(XSERVER_LIBPCIACCESS, 1, [Use libpciaccess for all pci manipulation])
@@ -1668,6 +1676,10 @@ if test "x$XORG" = xyes; then
 	fi
 	AC_MSG_RESULT([$PCI])
 
+	if test "x$CONFIG_UDEV_KMS" = xyes; then
+		AC_DEFINE(XSERVER_PLATFORM_BUS, 1, [X server supports platform device enumeration])
+	fi
+	AC_MSG_RESULT([$XSERVER_PLATFORM_BUS])
 	dnl ===================================================================
 	dnl ==================== end of PCI configuration =====================
 	dnl ===================================================================
@@ -1856,7 +1868,7 @@ AM_CONDITIONAL([SOLARIS_ASM_INLINE], [test "x$solaris_asm_inline" = xyes])
 AM_CONDITIONAL([SOLARIS_VT], [test "x$solaris_vt" = xyes])
 AM_CONDITIONAL([DGA], [test "x$DGA" = xyes])
 AM_CONDITIONAL([XF86VIDMODE], [test "x$XF86VIDMODE" = xyes])
-
+AM_CONDITIONAL([XORG_BUS_PLATFORM], [test "x$CONFIG_UDEV_KMS" = xyes])
 dnl XWin DDX
 
 AC_MSG_CHECKING([whether to build XWin DDX])
diff --git a/hw/xfree86/common/Makefile.am b/hw/xfree86/common/Makefile.am
index 2792177..65d98e6 100644
--- a/hw/xfree86/common/Makefile.am
+++ b/hw/xfree86/common/Makefile.am
@@ -22,9 +22,13 @@ if DGA
 DGASOURCES = xf86DGA.c
 endif
 
+if XORG_BUS_PLATFORM
+PLATSOURCES = xf86platformBus.c
+endif
+
 RANDRSOURCES = xf86RandR.c
 
-BUSSOURCES = xf86fbBus.c xf86noBus.c $(PCI_SOURCES) $(SBUS_SOURCES)
+BUSSOURCES = xf86fbBus.c xf86noBus.c $(PCI_SOURCES) $(SBUS_SOURCES) $(PLATSOURCES)
 
 MODEDEFSOURCES = $(srcdir)/vesamodes $(srcdir)/extramodes
 
@@ -56,7 +60,7 @@ sdk_HEADERS = compiler.h fourcc.h xf86.h xf86Module.h xf86Opt.h \
               xf86PciInfo.h xf86Priv.h xf86Privstr.h \
               xf86cmap.h xf86fbman.h xf86str.h xf86Xinput.h xisb.h \
               $(XVSDKINCS) $(XF86VMODE_SDK) xorgVersion.h \
-              xf86sbusBus.h xf86VGAarbiter.h xf86Optionstr.h
+              xf86sbusBus.h xf86VGAarbiter.h xf86Optionstr.h xf86platformBus.h
 
 DISTCLEANFILES = xf86Build.h
 CLEANFILES = $(BUILT_SOURCES)
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 129660d..88a219c 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -71,6 +71,11 @@ extern _X_EXPORT Bool fbSlotClaimed;
 #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
 extern _X_EXPORT Bool sbusSlotClaimed;
 #endif
+
+#if defined(XSERVER_PLATFORM_BUS)
+extern _X_EXPORT int platformSlotClaimed;
+#endif
+
 extern _X_EXPORT confDRIRec xf86ConfigDRI;
 extern _X_EXPORT Bool xf86DRI2Enabled(void);
 
diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index d0eb0af..271ce86 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -198,10 +198,13 @@ listPossibleVideoDrivers(char *matches[], int nmatches)
     }
     i = 0;
 
+#ifdef XSERVER_PLATFORM_BUS
+    i = xf86PlatformMatchDriver(matches, nmatches);
+#endif
 #ifdef sun
     /* Check for driver type based on /dev/fb type and if valid, use
        it instead of PCI bus probe results */
-    if (xf86Info.consoleFd >= 0) {
+    if (xf86Info.consoleFd >= 0 && (i < (nmatches - 1))) {
         struct vis_identifier visid;
         const char *cp;
         extern char xf86SolarisFbDev[PATH_MAX];
@@ -251,6 +254,7 @@ listPossibleVideoDrivers(char *matches[], int nmatches)
     }
 #endif
 #ifdef __sparc__
+    if (i < (nmatches - 1))
     {
         char *sbusDriver = sparcDriverName();
 
@@ -259,7 +263,8 @@ listPossibleVideoDrivers(char *matches[], int nmatches)
     }
 #endif
 #ifdef XSERVER_LIBPCIACCESS
-    i = xf86PciMatchDriver(matches, nmatches);
+    if (i < (nmatches - 1))
+        i = xf86PciMatchDriver(matches, nmatches);
 #endif
     /* Fallback to platform default hardware */
     if (i < (nmatches - 1)) {
diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index 6c86f5e..d0cfb2b 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -77,8 +77,14 @@ xf86CallDriverProbe(DriverPtr drv, Bool detect_only)
 {
     Bool foundScreen = FALSE;
 
+#ifdef XSERVER_PLATFORM_BUS
+    if (drv->platformProbe != NULL) {
+        foundScreen = xf86platformProbeDev(drv);
+    }
+#endif
+
 #ifdef XSERVER_LIBPCIACCESS
-    if (drv->PciProbe != NULL) {
+    if (!foundScreen && (drv->PciProbe != NULL)) {
         if (xf86DoConfigure && xf86DoConfigurePass1) {
             assert(detect_only);
             foundScreen = xf86PciAddMatchingDev(drv);
@@ -202,6 +208,9 @@ xf86BusConfig(void)
 void
 xf86BusProbe(void)
 {
+#ifdef XSERVER_PLATFORM_BUS
+    xf86platformProbe();
+#endif
 #ifdef XSERVER_LIBPCIACCESS
     xf86PciProbe();
 #endif
@@ -238,6 +247,8 @@ StringToBusType(const char *busID, const char **retID)
         ret = BUS_PCI;
     if (!xf86NameCmp(p, "sbus"))
         ret = BUS_SBUS;
+    if (!xf86NameCmp(p, "platform"))
+        ret = BUS_PLATFORM;
     if (ret != BUS_NONE)
         if (retID)
             *retID = busID + strlen(p) + 1;
@@ -270,6 +281,8 @@ xf86IsEntityPrimary(int entityIndex)
         return pEnt->bus.id.pci == primaryBus.id.pci;
     case BUS_SBUS:
         return pEnt->bus.id.sbus.fbNum == primaryBus.id.sbus.fbNum;
+    case BUS_PLATFORM:
+        return pEnt->bus.id.plat == primaryBus.id.plat;
     default:
         return FALSE;
     }
@@ -541,6 +554,9 @@ xf86PostProbe(void)
 #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
                              sbusSlotClaimed ||
 #endif
+#ifdef XSERVER_PLATFORM_BUS
+                             platformSlotClaimed ||
+#endif
 #ifdef XSERVER_LIBPCIACCESS
                              pciSlotClaimed
 #else
diff --git a/hw/xfree86/common/xf86Bus.h b/hw/xfree86/common/xf86Bus.h
index abf2efd..e83ba78 100644
--- a/hw/xfree86/common/xf86Bus.h
+++ b/hw/xfree86/common/xf86Bus.h
@@ -42,6 +42,7 @@
 #if defined(__sparc__) || defined(__sparc)
 #include "xf86sbusBus.h"
 #endif
+#include "xf86platformBus.h"
 
 typedef struct {
     DriverPtr driver;
diff --git a/hw/xfree86/common/xf86fbBus.c b/hw/xfree86/common/xf86fbBus.c
index 1e51623..303b9c2 100644
--- a/hw/xfree86/common/xf86fbBus.c
+++ b/hw/xfree86/common/xf86fbBus.c
@@ -54,6 +54,10 @@ xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active)
     EntityPtr p;
     int num;
 
+#ifdef XSERVER_PLATFORM_BUS
+    if (platformSlotClaimed)
+        return -1;
+#endif
 #ifdef XSERVER_LIBPCIACCESS
     if (pciSlotClaimed)
         return -1;
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index d758260..a2c18eb 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -110,7 +110,7 @@ xf86PciProbe(void)
             xf86PciVideoInfo[num - 1] = info;
 
             pci_device_probe(info);
-            if (pci_device_is_boot_vga(info)) {
+            if (primaryBus.type == BUS_NONE && pci_device_is_boot_vga(info)) {
                 primaryBus.type = BUS_PCI;
                 primaryBus.id.pci = info;
             }
@@ -352,7 +352,15 @@ xf86ComparePciBusString(const char *busID, int bus, int device, int func)
 Bool
 xf86IsPrimaryPci(struct pci_device *pPci)
 {
-    return ((primaryBus.type == BUS_PCI) && (pPci == primaryBus.id.pci));
+    if (primaryBus.type == BUS_PCI)
+        return pPci == primaryBus.id.pci;
+#ifdef XSERVER_PLATFORM_BUS
+    if (primaryBus.type == BUS_PLATFORM)
+        if (primaryBus.id.plat->pdev)
+            if (MATCH_PCI_DEVICES(primaryBus.id.plat->pdev, pPci))
+                return TRUE;
+#endif
+    return FALSE;
 }
 
 /*
@@ -367,7 +375,15 @@ xf86GetPciInfoForEntity(int entityIndex)
         return NULL;
 
     p = xf86Entities[entityIndex];
-    return (p->bus.type == BUS_PCI) ? p->bus.id.pci : NULL;
+    switch (p->bus.type) {
+    case BUS_PCI:
+        return p->bus.id.pci;
+    case BUS_PLATFORM:
+        return p->bus.id.plat->pdev;
+    default:
+        break;
+    }
+    return NULL;
 }
 
 /*
@@ -400,6 +416,13 @@ xf86CheckPciSlot(const struct pci_device *d)
         if ((p->bus.type == BUS_PCI) && (p->bus.id.pci == d)) {
             return FALSE;
         }
+#ifdef XSERVER_PLATFORM_BUS
+        if ((p->bus.type == BUS_PLATFORM) && (p->bus.id.plat->pdev)) {
+            struct pci_device *ud = p->bus.id.plat->pdev;
+            if (MATCH_PCI_DEVICES(ud, d))
+                return FALSE;
+        }
+#endif
     }
     return TRUE;
 }
@@ -1065,8 +1088,8 @@ xf86ConfigActivePciEntity(ScrnInfoPtr pScrn, int entityIndex,
     return TRUE;
 }
 
-static int
-videoPtrToDriverList(struct pci_device *dev,
+int
+xf86VideoPtrToDriverList(struct pci_device *dev,
                      char *returnList[], int returnListMax)
 {
     int i;
@@ -1249,8 +1272,8 @@ xchomp(char *line)
  * don't export their PCI ID's properly. If distros don't end up using this
  * feature it can and should be removed because the symbol-based resolution
  * scheme should be the primary one */
-static void
-matchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_chip)
+void
+xf86MatchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_chip)
 {
     DIR *idsdir;
     FILE *fp;
@@ -1379,7 +1402,7 @@ xf86PciMatchDriver(char *matches[], int nmatches)
     pci_iterator_destroy(iter);
 #ifdef __linux__
     if (info)
-        matchDriverFromFiles(matches, info->vendor_id, info->device_id);
+        xf86MatchDriverFromFiles(matches, info->vendor_id, info->device_id);
 #endif
 
     for (i = 0; (i < nmatches) && (matches[i]); i++) {
@@ -1387,7 +1410,7 @@ xf86PciMatchDriver(char *matches[], int nmatches)
     }
 
     if ((info != NULL) && (i < nmatches)) {
-        i += videoPtrToDriverList(info, &(matches[i]), nmatches - i);
+        i += xf86VideoPtrToDriverList(info, &(matches[i]), nmatches - i);
     }
 
     return i;
diff --git a/hw/xfree86/common/xf86pciBus.h b/hw/xfree86/common/xf86pciBus.h
index 56ec6e9..4972c36 100644
--- a/hw/xfree86/common/xf86pciBus.h
+++ b/hw/xfree86/common/xf86pciBus.h
@@ -42,4 +42,14 @@ Bool xf86PciConfigure(void *busData, struct pci_device *pDev);
 void xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo,
                             GDevRec * GDev, int *chipset);
 
+#define MATCH_PCI_DEVICES(x, y) (((x)->domain == (y)->domain) &&        \
+                                 ((x)->bus == (y)->bus) &&              \
+                                 ((x)->func == (y)->func) &&            \
+                                 ((x)->dev == (y)->dev))
+
+void
+xf86MatchDriverFromFiles(char **matches, uint16_t match_vendor, uint16_t match_chip);
+int
+xf86VideoPtrToDriverList(struct pci_device *dev,
+                         char *returnList[], int returnListMax);
 #endif                          /* _XF86_PCI_BUS_H */
diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
new file mode 100644
index 0000000..50b7636
--- /dev/null
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -0,0 +1,379 @@
+/*
+ * Copyright © 2012 Red Hat.
+ *
+ * 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, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Author: Dave Airlie <airlied at redhat.com>
+ */
+
+/*
+ * This file contains the interfaces to the bus-specific code
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef XSERVER_PLATFORM_BUS
+#include <errno.h>
+
+#include <pciaccess.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include "os.h"
+#include "hotplug.h"
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+#include "xf86Priv.h"
+#include "xf86str.h"
+#include "xf86Bus.h"
+#include "Pci.h"
+#include "xf86platformBus.h"
+
+int platformSlotClaimed;
+
+int xf86_num_platform_devices;
+
+static struct xf86_platform_device *xf86_platform_devices;
+
+int
+xf86_add_platform_device(struct OdevAttributes *attribs)
+{
+    xf86_platform_devices = xnfrealloc(xf86_platform_devices,
+                                   (sizeof(struct xf86_platform_device)
+                                    * (xf86_num_platform_devices + 1)));
+
+    xf86_platform_devices[xf86_num_platform_devices].attribs = attribs;
+    xf86_platform_devices[xf86_num_platform_devices].pdev = NULL;
+
+    xf86_num_platform_devices++;
+    return 0;
+}
+
+int
+xf86_remove_platform_device(int dev_index)
+{
+    int j;
+
+    config_odev_free_attribute_list(xf86_platform_devices[dev_index].attribs);
+
+    for (j = dev_index; j < xf86_num_platform_devices - 1; j++)
+        memcpy(&xf86_platform_devices[j], &xf86_platform_devices[j + 1], sizeof(struct xf86_platform_device));
+    xf86_num_platform_devices--;
+    return 0;
+}
+
+Bool
+xf86_add_platform_device_attrib(int index, int attrib_id, char *attrib_name)
+{
+    struct xf86_platform_device *device = &xf86_platform_devices[index];
+
+    return config_odev_add_attribute(device->attribs, attrib_id, attrib_name);
+}
+
+char *
+xf86_get_platform_attrib(int index, int attrib_id)
+{
+    struct xf86_platform_device *device = &xf86_platform_devices[index];
+    struct OdevAttribute *oa;
+
+    xorg_list_for_each_entry(oa, &device->attribs->list, member) {
+        if (oa->attrib_id == attrib_id)
+            return oa->attrib_name;
+    }
+    return NULL;
+}
+
+char *
+xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib_id)
+{
+    struct OdevAttribute *oa;
+
+    xorg_list_for_each_entry(oa, &device->attribs->list, member) {
+        if (oa->attrib_id == attrib_id)
+            return oa->attrib_name;
+    }
+    return NULL;
+}
+
+
+/*
+ * xf86IsPrimaryPlatform() -- return TRUE if primary device
+ * is a platform device and it matches this one.
+ */
+
+static Bool
+xf86IsPrimaryPlatform(struct xf86_platform_device *plat)
+{
+    return ((primaryBus.type == BUS_PLATFORM) && (plat == primaryBus.id.plat));
+}
+
+static void
+platform_find_pci_info(struct xf86_platform_device *pd, char *busid)
+{
+    struct pci_slot_match devmatch;
+    struct pci_device *info;
+    struct pci_device_iterator *iter;
+    int ret;
+
+    ret = sscanf(busid, "pci:%04x:%02x:%02x.%u",
+                 &devmatch.domain, &devmatch.bus, &devmatch.dev,
+                 &devmatch.func);
+    if (ret != 4)
+        return;
+
+    iter = pci_slot_match_iterator_create(&devmatch);
+    info = pci_device_next(iter);
+    if (info) {
+        pd->pdev = info;
+        pci_device_probe(info);
+        if (pci_device_is_boot_vga(info)) {
+            primaryBus.type = BUS_PLATFORM;
+            primaryBus.id.plat = pd;
+        }
+    }
+    pci_iterator_destroy(iter);
+
+}
+
+static Bool
+xf86_check_platform_slot(const struct xf86_platform_device *pd)
+{
+    int i;
+
+    for (i = 0; i < xf86NumEntities; i++) {
+        const EntityPtr u = xf86Entities[i];
+
+        if (pd->pdev && u->bus.type == BUS_PCI)
+            return !MATCH_PCI_DEVICES(pd->pdev, u->bus.id.pci);
+        if ((u->bus.type == BUS_PLATFORM) && (pd == u->bus.id.plat)) {
+            return FALSE;
+        }
+    }
+    return TRUE;
+}
+
+/**
+ *  @return The numbers of found devices that match with the current system
+ *  drivers.
+ */
+int
+xf86PlatformMatchDriver(char *matches[], int nmatches)
+{
+    int i, j = 0;
+    struct pci_device *info = NULL;
+    int pass = 0;
+
+    for (pass = 0; pass < 2; pass++) {
+        for (i = 0; i < xf86_num_platform_devices; i++) {
+
+            if (xf86IsPrimaryPlatform(&xf86_platform_devices[i]) && (pass == 1))
+                continue;
+            else if (!xf86IsPrimaryPlatform(&xf86_platform_devices[i]) && (pass == 0))
+                continue;
+
+            info = xf86_platform_devices[i].pdev;
+#ifdef __linux__
+            if (info)
+                xf86MatchDriverFromFiles(matches, info->vendor_id, info->device_id);
+#endif
+
+            for (j = 0; (j < nmatches) && (matches[j]); j++) {
+                /* find end of matches list */
+            }
+
+            if ((info != NULL) && (j < nmatches)) {
+                j += xf86VideoPtrToDriverList(info, &(matches[j]), nmatches - j);
+            }
+        }
+    }
+    return j;
+}
+
+int
+xf86platformProbe(void)
+{
+    int i;
+    Bool pci = TRUE;
+
+    if (!xf86scanpci()) {
+        pci = FALSE;
+    }
+
+    config_odev_probe(&xf86PlatformDeviceProbe);
+    for (i = 0; i < xf86_num_platform_devices; i++) {
+        char *busid = xf86_get_platform_attrib(i, ODEV_ATTRIB_BUSID);
+
+        if (pci && (strncmp(busid, "pci:", 4) == 0)) {
+            platform_find_pci_info(&xf86_platform_devices[i], busid);
+        }
+    }
+    return 0;
+}
+
+static int
+xf86ClaimPlatformSlot(struct xf86_platform_device * d, DriverPtr drvp,
+                  int chipset, GDevPtr dev, Bool active)
+{
+    EntityPtr p = NULL;
+    int num;
+
+    if (xf86_check_platform_slot(d)) {
+        num = xf86AllocateEntity();
+        p = xf86Entities[num];
+        p->driver = drvp;
+        p->chipset = chipset;
+        p->bus.type = BUS_PLATFORM;
+        p->bus.id.plat = d;
+        p->active = active;
+        p->inUse = FALSE;
+        if (dev)
+            xf86AddDevToEntity(num, dev);
+
+        platformSlotClaimed++;
+        return num;
+    }
+    else
+        return -1;
+}
+
+static int
+xf86UnclaimPlatformSlot(struct xf86_platform_device *d, GDevPtr dev)
+{
+    int i;
+
+    for (i = 0; i < xf86NumEntities; i++) {
+        const EntityPtr p = xf86Entities[i];
+
+        if ((p->bus.type == BUS_PLATFORM) && (p->bus.id.plat == d)) {
+            if (dev)
+                xf86RemoveDevFromEntity(i, dev);
+            platformSlotClaimed--;
+            p->bus.type = BUS_NONE;
+            return 0;
+        }
+    }
+    return 0;
+}
+
+
+#define END_OF_MATCHES(m)                                               \
+    (((m).vendor_id == 0) && ((m).device_id == 0) && ((m).subvendor_id == 0))
+
+static Bool doPlatformProbe(struct xf86_platform_device *dev, DriverPtr drvp,
+                            GDevPtr gdev, int flags, intptr_t match_data)
+{
+    Bool foundScreen = FALSE;
+    int entity;
+
+    if (gdev->screen == 0 && !xf86_check_platform_slot(dev))
+        return FALSE;
+
+    entity = xf86ClaimPlatformSlot(dev, drvp, 0,
+                                   gdev, gdev->active);
+
+    if ((entity == -1) && (gdev->screen > 0)) {
+        unsigned nent;
+
+        for (nent = 0; nent < xf86NumEntities; nent++) {
+            EntityPtr pEnt = xf86Entities[nent];
+
+            if (pEnt->bus.type != BUS_PLATFORM)
+                continue;
+            if (pEnt->bus.id.plat == dev) {
+                entity = nent;
+                xf86AddDevToEntity(nent, gdev);
+                break;
+            }
+        }
+    }
+    if (entity != -1) {
+        if (drvp->platformProbe(drvp, entity, flags, dev, match_data))
+            foundScreen = TRUE;
+        else
+            xf86UnclaimPlatformSlot(dev, gdev);
+    }
+    return foundScreen;
+}
+
+static Bool
+probeSingleDevice(struct xf86_platform_device *dev, DriverPtr drvp, GDevPtr gdev, int flags)
+{
+    int k;
+    Bool foundScreen = FALSE;
+    struct pci_device *pPci;
+    const struct pci_id_match *const devices = drvp->supported_devices;
+
+    if (dev->pdev && devices) {
+        int device_id = dev->pdev->device_id;
+        pPci = dev->pdev;
+        for (k = 0; !END_OF_MATCHES(devices[k]); k++) {
+            if (PCI_ID_COMPARE(devices[k].vendor_id, pPci->vendor_id)
+                && PCI_ID_COMPARE(devices[k].device_id, device_id)
+                && ((devices[k].device_class_mask & pPci->device_class)
+                    ==  devices[k].device_class)) {
+                foundScreen = doPlatformProbe(dev, drvp, gdev, flags, devices[k].match_data);
+                if (foundScreen)
+                    break;
+            }
+        }
+    }
+    else if (dev->pdev && !devices)
+        return FALSE;
+    else
+        foundScreen = doPlatformProbe(dev, drvp, gdev, flags, 0);
+    return foundScreen;
+}
+
+int
+xf86platformProbeDev(DriverPtr drvp)
+{
+    Bool foundScreen = FALSE;
+    GDevPtr *devList;
+    const unsigned numDevs = xf86MatchDevice(drvp->driverName, &devList);
+    int i, j;
+
+    /* find the main device or any device specificed in xorg.conf */
+    for (i = 0; i < numDevs; i++) {
+        for (j = 0; j < xf86_num_platform_devices; j++) {
+            if (devList[i]->busID && *devList[i]->busID) {
+                if (xf86PlatformDeviceCheckBusID(&xf86_platform_devices[j], devList[i]->busID))
+                    break;
+            }
+            else {
+                if (xf86_platform_devices[j].pdev) {
+                    if (xf86IsPrimaryPlatform(&xf86_platform_devices[j]))
+                        break;
+                }
+            }
+        }
+
+        if (j == xf86_num_platform_devices)
+             continue;
+
+        foundScreen = probeSingleDevice(&xf86_platform_devices[j], drvp, devList[i], 0);
+        if (!foundScreen)
+            continue;
+    }
+
+    return foundScreen;
+}
+
+#endif
diff --git a/hw/xfree86/common/xf86platformBus.h b/hw/xfree86/common/xf86platformBus.h
new file mode 100644
index 0000000..15a3022
--- /dev/null
+++ b/hw/xfree86/common/xf86platformBus.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright © 2012 Red Hat.
+ *
+ * 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, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Author: Dave Airlie <airlied at redhat.com>
+ */
+#ifndef XF86_PLATFORM_BUS_H
+#define XF86_PLATFORM_BUS_H
+
+#include "hotplug.h"
+
+struct xf86_platform_device {
+    struct OdevAttributes *attribs;
+    /* for PCI devices */
+    struct pci_device *pdev;
+};
+
+#ifdef XSERVER_PLATFORM_BUS
+int xf86platformProbe(void);
+int xf86platformProbeDev(DriverPtr drvp);
+
+extern int xf86_num_platform_devices;
+
+extern char *
+xf86_get_platform_attrib(int index, int attrib_id);
+extern int
+xf86_add_platform_device(struct OdevAttributes *attribs);
+extern int
+xf86_remove_platform_device(int dev_index);
+extern Bool
+xf86_add_platform_device_attrib(int index, int attrib_id, char *attrib_str);
+
+extern _X_EXPORT char *
+xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib_id);
+extern _X_EXPORT Bool
+xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid);
+
+extern _X_EXPORT int
+xf86PlatformMatchDriver(char *matches[], int nmatches);
+#endif
+
+#endif
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index a1404c3..e12dcc4 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -311,6 +311,7 @@ struct _SymTabRec;
 struct _PciChipsets;
 
 struct pci_device;
+struct xf86_platform_device;
 
 typedef struct _DriverRec {
     int driverVersion;
@@ -325,9 +326,16 @@ typedef struct _DriverRec {
     const struct pci_id_match *supported_devices;
     Bool (*PciProbe) (struct _DriverRec * drv, int entity_num,
                       struct pci_device * dev, intptr_t match_data);
+    Bool (*platformProbe) (struct _DriverRec * drv, int entity_num, int flags,
+                           struct xf86_platform_device * dev, intptr_t match_data);
 } DriverRec, *DriverPtr;
 
 /*
+ * platform probe flags
+ * no flags are defined yet - but drivers should fail to load if a flag they
+ * don't understand is passed.
+ */
+/*
  *  AddDriver flags
  */
 #define HaveDriverFuncs 1
@@ -343,6 +351,7 @@ typedef struct _DriverRec {
 #undef BUS_NONE
 #undef BUS_PCI
 #undef BUS_SBUS
+#undef BUS_PLATFORM
 #undef BUS_last
 #endif
 
@@ -350,6 +359,7 @@ typedef enum {
     BUS_NONE,
     BUS_PCI,
     BUS_SBUS,
+    BUS_PLATFORM,
     BUS_last                    /* Keep last */
 } BusType;
 
@@ -362,6 +372,7 @@ typedef struct _bus {
     union {
         struct pci_device *pci;
         SbusBusId sbus;
+        struct xf86_platform_device *plat;
     } id;
 } BusRec, *BusPtr;
 
diff --git a/hw/xfree86/os-support/linux/Makefile.am b/hw/xfree86/os-support/linux/Makefile.am
index 36748df..61175b3 100644
--- a/hw/xfree86/os-support/linux/Makefile.am
+++ b/hw/xfree86/os-support/linux/Makefile.am
@@ -22,7 +22,7 @@ XORG_CFLAGS += -DHAVE_APM
 endif
 
 liblinux_la_SOURCES = lnx_init.c lnx_video.c \
-                     lnx_agp.c lnx_kmod.c lnx_bell.c \
+                     lnx_agp.c lnx_kmod.c lnx_bell.c lnx_platform.c \
                      $(srcdir)/../shared/bios_mmap.c \
 		     $(srcdir)/../shared/VTsw_usl.c \
 		     $(srcdir)/../shared/posix_tty.c \
diff --git a/hw/xfree86/os-support/linux/lnx_platform.c b/hw/xfree86/os-support/linux/lnx_platform.c
new file mode 100644
index 0000000..9c63ee5
--- /dev/null
+++ b/hw/xfree86/os-support/linux/lnx_platform.c
@@ -0,0 +1,130 @@
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef XSERVER_PLATFORM_BUS
+
+#include <xf86drm.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+/* Linux platform device support */
+#include "xf86_OSproc.h"
+
+#include "xf86.h"
+#include "xf86platformBus.h"
+#include "xf86Bus.h"
+
+static Bool
+get_drm_info(struct OdevAttributes *attribs, char *path)
+{
+    drmSetVersion sv;
+    char *buf;
+    int fd;
+
+    fd = open(path, O_RDWR, O_CLOEXEC);
+    if (fd == -1)
+        return FALSE;
+
+    sv.drm_di_major = 1;
+    sv.drm_di_minor = 4;
+    sv.drm_dd_major = -1;       /* Don't care */
+    sv.drm_dd_minor = -1;       /* Don't care */
+    if (drmSetInterfaceVersion(fd, &sv)) {
+        ErrorF("setversion 1.4 failed\n");
+        return FALSE;
+    }
+
+    xf86_add_platform_device(attribs);
+
+    buf = drmGetBusid(fd);
+    xf86_add_platform_device_attrib(xf86_num_platform_devices - 1,
+                                    ODEV_ATTRIB_BUSID, buf);
+    drmFreeBusid(buf);
+    close(fd);
+    return TRUE;
+}
+
+Bool
+xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid)
+{
+    struct OdevAttribute *attrib;
+    const char *syspath = NULL;
+    BusType bustype;
+    const char *id;
+    xorg_list_for_each_entry(attrib, &device->attribs->list, member) {
+        if (attrib->attrib_id == ODEV_ATTRIB_SYSPATH) {
+            syspath = attrib->attrib_name;
+            break;
+        }
+    }
+
+    if (!syspath)
+        return FALSE;
+
+    bustype = StringToBusType(busid, &id);
+    if (bustype == BUS_PCI) {
+        struct pci_device *pPci = device->pdev;
+        if (xf86ComparePciBusString(busid,
+                                    ((pPci->domain << 8)
+                                     | pPci->bus),
+                                    pPci->dev, pPci->func)) {
+            return TRUE;
+        }
+    }
+    else if (bustype == BUS_PLATFORM) {
+        /* match on the minimum string */
+        int len = strlen(id);
+
+        if (strlen(syspath) < strlen(id))
+            len = strlen(syspath);
+
+        if (strncmp(id, syspath, len))
+            return FALSE;
+        return TRUE;
+    }
+    return FALSE;
+}
+
+void
+xf86PlatformDeviceProbe(struct OdevAttributes *attribs)
+{
+    struct OdevAttribute *attrib;
+    int i;
+    char *path = NULL;
+    Bool ret;
+
+    xorg_list_for_each_entry(attrib, &attribs->list, member) {
+        if (attrib->attrib_id == ODEV_ATTRIB_PATH) {
+            path = attrib->attrib_name;
+            break;
+        }
+    }
+    if (!path)
+        goto out_free;
+
+    for (i = 0; i < xf86_num_platform_devices; i++) {
+        char *dpath;
+        dpath = xf86_get_platform_attrib(i, ODEV_ATTRIB_PATH);
+
+        if (!strcmp(path, dpath))
+            break;
+    }
+
+    if (i != xf86_num_platform_devices)
+        goto out_free;
+
+    LogMessage(X_INFO, "config/udev: Adding drm device (%s)\n",
+               path);
+
+    ret = get_drm_info(attribs, path);
+    if (ret == FALSE)
+        goto out_free;
+
+    return;
+
+out_free:
+    config_odev_free_attribute_list(attribs);
+}
+
+#endif
diff --git a/hw/xfree86/os-support/shared/platform_noop.c b/hw/xfree86/os-support/shared/platform_noop.c
new file mode 100644
index 0000000..199ae5e
--- /dev/null
+++ b/hw/xfree86/os-support/shared/platform_noop.c
@@ -0,0 +1,23 @@
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#endif
+
+#ifdef XSERVER_PLATFORM_BUS
+/* noop platform device support */
+#include "xf86_OSproc.h"
+
+#include "xf86.h"
+#include "xf86platformBus.h"
+
+Bool
+xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid)
+{
+    return FALSE;
+}
+
+void xf86PlatformDeviceProbe(struct OdevAttributes *attribs)
+{
+
+}
+#endif
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index e171146..2f0172e 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -221,6 +221,12 @@ extern _X_EXPORT void xf86InitVidMem(void);
 
 #endif                          /* XF86_OS_PRIVS */
 
+#ifdef XSERVER_PLATFORM_BUS
+#include "hotplug.h"
+void
+xf86PlatformDeviceProbe(struct OdevAttributes *attribs);
+#endif
+
 _XFUNCPROTOEND
 #endif                          /* NO_OSLIB_PROTOTYPES */
 #endif                          /* _XF86_OSPROC_H */
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 3c9bbaf..77681a9 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -390,6 +390,9 @@
 /* Use libudev for input hotplug */
 #undef CONFIG_UDEV
 
+/* Use libudev for kms enumeration */
+#undef CONFIG_UDEV_KMS
+
 /* Use udev_monitor_filter_add_match_tag() */
 #undef HAVE_UDEV_MONITOR_FILTER_ADD_MATCH_TAG
 
diff --git a/include/hotplug.h b/include/hotplug.h
index f3eeea2..5000762 100644
--- a/include/hotplug.h
+++ b/include/hotplug.h
@@ -26,8 +26,43 @@
 #ifndef HOTPLUG_H
 #define HOTPLUG_H
 
+#include "list.h"
+
 extern _X_EXPORT void config_pre_init(void);
 extern _X_EXPORT void config_init(void);
 extern _X_EXPORT void config_fini(void);
 
+struct OdevAttribute {
+    struct xorg_list member;
+    int attrib_id;
+    char *attrib_name;
+};
+
+struct OdevAttributes {
+    struct xorg_list list;
+};
+
+struct OdevAttributes *
+config_odev_allocate_attribute_list(void);
+
+void
+config_odev_free_attribute_list(struct OdevAttributes *attribs);
+
+Bool
+config_odev_add_attribute(struct OdevAttributes *attribs, int attrib,
+                          const char *attrib_name);
+
+void
+config_odev_free_attributes(struct OdevAttributes *attribs);
+
+/* path to kernel device node - Linux e.g. /dev/dri/card0 */
+#define ODEV_ATTRIB_PATH 1
+/* system device path - Linux e.g. /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card1 */
+#define ODEV_ATTRIB_SYSPATH 2
+/* DRI-style bus id */
+#define ODEV_ATTRIB_BUSID 3
+
+typedef void (*config_odev_probe_proc_ptr)(struct OdevAttributes *attribs);
+void config_odev_probe(config_odev_probe_proc_ptr probe_callback);
+
 #endif                          /* HOTPLUG_H */
diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in
index 2cc416a..a71b25d 100644
--- a/include/xorg-config.h.in
+++ b/include/xorg-config.h.in
@@ -136,4 +136,7 @@
 /* Have getresuid */
 #undef HAVE_GETRESUID
 
+/* Have X server platform bus support */
+#undef XSERVER_PLATFORM_BUS
+
 #endif /* _XORG_CONFIG_H_ */
diff --git a/include/xorg-server.h.in b/include/xorg-server.h.in
index 8086f32..c0761f7 100644
--- a/include/xorg-server.h.in
+++ b/include/xorg-server.h.in
@@ -205,6 +205,9 @@
 /* X Access Control Extension */
 #undef XACE
 
+/* Have X server platform bus support */
+#undef XSERVER_PLATFORM_BUS
+
 #ifdef _LP64
 #define _XSERVER64 1
 #endif
commit 2c52d776a42a28bb3e1463edf0cfe0672d0c08a9
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 19 16:01:08 2012 +0100

    xf86: cursor code got mangled by indenting
    
    This fixes some really ugly code that got mangled by the indenting.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c
index 15e2ada..8b91e05 100644
--- a/hw/xfree86/ramdac/xf86Cursor.c
+++ b/hw/xfree86/ramdac/xf86Cursor.c
@@ -336,28 +336,19 @@ xf86CursorSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCurs,
         if (!infoPtr->pScrn->vtSema)
             ScreenPriv->SavedCursor = pCurs;
 
-        if (infoPtr->pScrn->vtSema && (ScreenPriv->ForceHWCursorCount || ((
+        if (infoPtr->pScrn->vtSema &&
+            (ScreenPriv->ForceHWCursorCount ||
+             ((
 #ifdef ARGB_CURSOR
-                                                                              pCurs->
-                                                                              bits->
-                                                                              argb
-                                                                              &&
-                                                                              infoPtr->
-                                                                              UseHWCursorARGB
-                                                                              &&
-                                                                              (*infoPtr->
-                                                                               UseHWCursorARGB)
-                                                                              (pScreen,
-                                                                               pCurs))
-                                                                          ||
-                                                                          (pCurs->
-                                                                           bits->
-                                                                           argb
-                                                                           == 0
-                                                                           &&
+               pCurs->bits->argb &&
+               infoPtr->UseHWCursorARGB &&
+               (*infoPtr->UseHWCursorARGB)(pScreen, pCurs)) ||
+              (pCurs->bits->argb == 0 &&
 #endif
-                                                                           (pCurs->bits->height <= infoPtr->MaxHeight) && (pCurs->bits->width <= infoPtr->MaxWidth) && (!infoPtr->UseHWCursor || (*infoPtr->UseHWCursor) (pScreen, pCurs)))))) {
-
+               (pCurs->bits->height <= infoPtr->MaxHeight) &&
+               (pCurs->bits->width <= infoPtr->MaxWidth) &&
+               (!infoPtr->UseHWCursor || (*infoPtr->UseHWCursor) (pScreen, pCurs)))))) {
+            
             if (ScreenPriv->SWCursor)   /* remove the SW cursor */
                 (*ScreenPriv->spriteFuncs->SetCursor) (pDev, pScreen,
                                                        NullCursor, x, y);
commit 9e4b8b74b008dd72d1da7074bd7ecae677cefd20
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jul 5 11:31:55 2012 -0700

    privates: Allow device privates to be allocated after server start
    
    This will permit midispcur to allocate its privates for hotplug outputs
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/privates.c b/dix/privates.c
index e353108..b58085f 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -62,6 +62,7 @@ from The Open Group.
 #include "inputstr.h"
 #include "scrnintstr.h"
 #include "extnsionst.h"
+#include "inputstr.h"
 
 static DevPrivateSetRec global_keys[PRIVATE_LAST];
 
@@ -91,9 +92,9 @@ static const char *key_names[PRIVATE_LAST] = {
     [PRIVATE_SCREEN] = "SCREEN",
     [PRIVATE_EXTENSION] = "EXTENSION",
     [PRIVATE_COLORMAP] = "COLORMAP",
+    [PRIVATE_DEVICE] = "DEVICE",
 
     /* These cannot have any objects before all relevant keys are registered */
-    [PRIVATE_DEVICE] = "DEVICE",
     [PRIVATE_CLIENT] = "CLIENT",
     [PRIVATE_PROPERTY] = "PROPERTY",
     [PRIVATE_SELECTION] = "SELECTION",
@@ -265,11 +266,30 @@ fixupDefaultColormaps(FixupFunc fixup, unsigned bytes)
     return TRUE;
 }
 
+static Bool
+fixupDeviceList(DeviceIntPtr device, FixupFunc fixup, unsigned bytes)
+{
+    while (device) {
+        if (!fixup(&device->devPrivates, global_keys[PRIVATE_DEVICE].offset, bytes))
+            return FALSE;
+        device = device->next;
+    }
+    return TRUE;
+}
+
+static Bool
+fixupDevices(FixupFunc fixup, unsigned bytes)
+{
+    return (fixupDeviceList(inputInfo.devices, fixup, bytes) &&
+            fixupDeviceList(inputInfo.off_devices, fixup, bytes));
+}
+
 static Bool (*const allocated_early[PRIVATE_LAST]) (FixupFunc, unsigned) = {
     [PRIVATE_SCREEN] = fixupScreens,
     [PRIVATE_CLIENT] = fixupServerClient,
     [PRIVATE_EXTENSION] = fixupExtensions,
     [PRIVATE_COLORMAP] = fixupDefaultColormaps,
+    [PRIVATE_DEVICE] = fixupDevices,
 };
 
 static void
diff --git a/include/privates.h b/include/privates.h
index a0874f6..2c8864b 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -33,9 +33,9 @@ typedef enum {
     PRIVATE_SCREEN,
     PRIVATE_EXTENSION,
     PRIVATE_COLORMAP,
+    PRIVATE_DEVICE,
 
     /* These cannot have any objects before all relevant keys are registered */
-    PRIVATE_DEVICE,
     PRIVATE_CLIENT,
     PRIVATE_PROPERTY,
     PRIVATE_SELECTION,
commit 493ad833233707b0a42e5fbdd957a24fc6e52917
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jul 5 11:31:29 2012 -0700

    dix: Allocate device privates separate from devices
    
    This will allow device privates to be resized.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/devices.c b/dix/devices.c
index 08875bc..70fb273 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -246,13 +246,17 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
 
     if (devid >= MAXDEVICES)
         return (DeviceIntPtr) NULL;
-    dev =
-        _dixAllocateObjectWithPrivates(sizeof(DeviceIntRec) +
-                                       sizeof(SpriteInfoRec),
-                                       sizeof(DeviceIntRec) +
-                                       sizeof(SpriteInfoRec),
-                                       offsetof(DeviceIntRec, devPrivates),
-                                       PRIVATE_DEVICE);
+    dev = calloc(1,
+                 sizeof(DeviceIntRec) +
+                 sizeof(SpriteInfoRec));
+    if (!dev)
+        return (DeviceIntPtr) NULL;
+
+    if (!dixAllocatePrivates(&dev->devPrivates, PRIVATE_DEVICE)) {
+        free(dev);
+        return NULL;
+    }
+
     if (!dev)
         return (DeviceIntPtr) NULL;
 
@@ -282,6 +286,7 @@ AddInputDevice(ClientPtr client, DeviceProc deviceProc, Bool autoStart)
     /*  security creation/labeling check
      */
     if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixCreateAccess)) {
+        dixFreePrivates(dev->devPrivates, PRIVATE_DEVICE);
         free(dev);
         return NULL;
     }
@@ -961,7 +966,8 @@ CloseDevice(DeviceIntPtr dev)
         free(dev->last.touches[j].valuators);
     free(dev->last.touches);
     dev->config_info = NULL;
-    dixFreeObjectWithPrivates(dev, PRIVATE_DEVICE);
+    dixFreePrivates(dev->devPrivates, PRIVATE_DEVICE);
+    free(dev);
 }
 
 /**
commit f38b2b628322f4d763b0c7f8387d5ab0472a7d2b
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jul 5 11:15:18 2012 -0700

    mi: Don't save midispcur rendering resources for each cursor
    
    Instead, only save them for the most recently drawn cursor. This saves
    a bunch of storage for idle cursors.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/mi/midispcur.c b/mi/midispcur.c
index df141cd..edca969 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -56,9 +56,7 @@ in this Software without prior written authorization from The Open Group.
 static DevPrivateKeyRec miDCScreenKeyRec;
 
 #define miDCScreenKey (&miDCScreenKeyRec)
-static DevScreenPrivateKeyRec miDCCursorBitsKeyRec;
 
-#define miDCCursorBitsKey (&miDCCursorBitsKeyRec)
 static DevScreenPrivateKeyRec miDCDeviceKeyRec;
 
 #define miDCDeviceKey (&miDCDeviceKeyRec)
@@ -86,18 +84,15 @@ typedef struct {
  */
 typedef struct {
     CloseScreenProcPtr CloseScreen;
-} miDCScreenRec, *miDCScreenPtr;
-
-#define miGetDCScreen(s)	((miDCScreenPtr)(dixLookupPrivate(&(s)->devPrivates, miDCScreenKey)))
-
-/* per-cursor per-screen private data */
-typedef struct {
     PixmapPtr sourceBits;       /* source bits */
     PixmapPtr maskBits;         /* mask bits */
 #ifdef ARGB_CURSOR
     PicturePtr pPicture;
 #endif
-} miDCCursorRec, *miDCCursorPtr;
+    CursorPtr pCursor;
+} miDCScreenRec, *miDCScreenPtr;
+
+#define miGetDCScreen(s)	((miDCScreenPtr)(dixLookupPrivate(&(s)->devPrivates, miDCScreenKey)))
 
 Bool
 miDCInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
@@ -105,13 +100,11 @@ miDCInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
     miDCScreenPtr pScreenPriv;
 
     if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0) ||
-        !dixRegisterScreenPrivateKey(&miDCCursorBitsKeyRec, pScreen,
-                                     PRIVATE_CURSOR_BITS, 0) ||
         !dixRegisterScreenPrivateKey(&miDCDeviceKeyRec, pScreen, PRIVATE_DEVICE,
                                      0))
         return FALSE;
 
-    pScreenPriv = malloc(sizeof(miDCScreenRec));
+    pScreenPriv = calloc(1, sizeof(miDCScreenRec));
     if (!pScreenPriv)
         return FALSE;
 
@@ -127,6 +120,28 @@ miDCInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
     return TRUE;
 }
 
+static void
+miDCSwitchScreenCursor(ScreenPtr pScreen, CursorPtr pCursor, PixmapPtr sourceBits, PixmapPtr maskBits, PicturePtr pPicture)
+{
+    miDCScreenPtr pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, miDCScreenKey);
+
+    if (pScreenPriv->sourceBits)
+        (*pScreen->DestroyPixmap)(pScreenPriv->sourceBits);
+    pScreenPriv->sourceBits = sourceBits;
+
+    if (pScreenPriv->maskBits)
+        (*pScreen->DestroyPixmap)(pScreenPriv->maskBits);
+    pScreenPriv->maskBits = maskBits;
+
+#ifdef ARGB_CURSOR
+    if (pScreenPriv->pPicture)
+        FreePicture(pScreenPriv->pPicture, 0);
+    pScreenPriv->pPicture = pPicture;
+#endif
+
+    pScreenPriv->pCursor = pCursor;
+}
+
 static Bool
 miDCCloseScreen(ScreenPtr pScreen)
 {
@@ -135,6 +150,8 @@ miDCCloseScreen(ScreenPtr pScreen)
     pScreenPriv = (miDCScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
                                                    miDCScreenKey);
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
+
+    miDCSwitchScreenCursor(pScreen, NULL, NULL, NULL, NULL);
     free((pointer) pScreenPriv);
     return (*pScreen->CloseScreen) (pScreen);
 }
@@ -142,9 +159,6 @@ miDCCloseScreen(ScreenPtr pScreen)
 Bool
 miDCRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
 {
-    if (pCursor->bits->refcnt <= 1)
-        dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey,
-                            pScreen, NULL);
     return TRUE;
 }
 
@@ -154,8 +168,6 @@ miDCRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
 static PicturePtr
 miDCMakePicture(PicturePtr * ppPicture, DrawablePtr pDraw, WindowPtr pWin)
 {
-    ScreenPtr pScreen = pDraw->pScreen;
-    VisualPtr pVisual;
     PictFormatPtr pFormat;
     XID subwindow_mode = IncludeInferiors;
     PicturePtr pPicture;
@@ -172,42 +184,39 @@ miDCMakePicture(PicturePtr * ppPicture, DrawablePtr pDraw, WindowPtr pWin)
 }
 #endif
 
-static miDCCursorPtr
+static Bool
 miDCRealize(ScreenPtr pScreen, CursorPtr pCursor)
 {
-    miDCCursorPtr pPriv;
+    miDCScreenPtr pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, miDCScreenKey);
     GCPtr pGC;
     ChangeGCVal gcvals;
+    PixmapPtr   sourceBits, maskBits;
+
+    if (pScreenPriv->pCursor == pCursor)
+        return TRUE;
 
-    pPriv = malloc(sizeof(miDCCursorRec));
-    if (!pPriv)
-        return NULL;
 #ifdef ARGB_CURSOR
+
     if (pCursor->bits->argb) {
         PixmapPtr pPixmap;
         PictFormatPtr pFormat;
         int error;
+        PicturePtr  pPicture;
 
         pFormat = PictureMatchFormat(pScreen, 32, PICT_a8r8g8b8);
-        if (!pFormat) {
-            free((pointer) pPriv);
-            return NULL;
-        }
+        if (!pFormat)
+            return FALSE;
 
-        pPriv->sourceBits = 0;
-        pPriv->maskBits = 0;
         pPixmap = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
                                             pCursor->bits->height, 32,
                                             CREATE_PIXMAP_USAGE_SCRATCH);
-        if (!pPixmap) {
-            free((pointer) pPriv);
-            return NULL;
-        }
+        if (!pPixmap)
+            return FALSE;
+
         pGC = GetScratchGC(32, pScreen);
         if (!pGC) {
             (*pScreen->DestroyPixmap) (pPixmap);
-            free((pointer) pPriv);
-            return NULL;
+            return FALSE;
         }
         ValidateGC(&pPixmap->drawable, pGC);
         (*pGC->ops->PutImage) (&pPixmap->drawable, pGC, 32,
@@ -215,105 +224,86 @@ miDCRealize(ScreenPtr pScreen, CursorPtr pCursor)
                                pCursor->bits->height,
                                0, ZPixmap, (char *) pCursor->bits->argb);
         FreeScratchGC(pGC);
-        pPriv->pPicture = CreatePicture(0, &pPixmap->drawable,
-                                        pFormat, 0, 0, serverClient, &error);
+        pPicture = CreatePicture(0, &pPixmap->drawable,
+                                 pFormat, 0, 0, serverClient, &error);
         (*pScreen->DestroyPixmap) (pPixmap);
-        if (!pPriv->pPicture) {
-            free((pointer) pPriv);
-            return NULL;
-        }
-        dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey,
-                            pScreen, pPriv);
-        return pPriv;
+        if (!pPicture)
+            return FALSE;
+
+        miDCSwitchScreenCursor(pScreen, pCursor, NULL, NULL, pPicture);
+        return TRUE;
     }
-    pPriv->pPicture = 0;
 #endif
-    pPriv->sourceBits =
-        (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
-                                  pCursor->bits->height, 1, 0);
-    if (!pPriv->sourceBits) {
-        free((pointer) pPriv);
-        return NULL;
-    }
-    pPriv->maskBits =
-        (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
-                                  pCursor->bits->height, 1, 0);
-    if (!pPriv->maskBits) {
-        (*pScreen->DestroyPixmap) (pPriv->sourceBits);
-        free((pointer) pPriv);
-        return NULL;
+    sourceBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
+                                           pCursor->bits->height, 1, 0);
+    if (!sourceBits)
+        return FALSE;
+
+    maskBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
+                                         pCursor->bits->height, 1, 0);
+    if (!maskBits) {
+        (*pScreen->DestroyPixmap) (sourceBits);
+        return FALSE;
     }
-    dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey, pScreen,
-                        pPriv);
 
     /* create the two sets of bits, clipping as appropriate */
 
     pGC = GetScratchGC(1, pScreen);
     if (!pGC) {
-        (void) miDCUnrealizeCursor(pScreen, pCursor);
-        return NULL;
+        (*pScreen->DestroyPixmap) (sourceBits);
+        (*pScreen->DestroyPixmap) (maskBits);
+        return FALSE;
     }
 
-    ValidateGC((DrawablePtr) pPriv->sourceBits, pGC);
-    (*pGC->ops->PutImage) ((DrawablePtr) pPriv->sourceBits, pGC, 1,
+    ValidateGC((DrawablePtr) sourceBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr) sourceBits, pGC, 1,
                            0, 0, pCursor->bits->width, pCursor->bits->height,
                            0, XYPixmap, (char *) pCursor->bits->source);
     gcvals.val = GXand;
     ChangeGC(NullClient, pGC, GCFunction, &gcvals);
-    ValidateGC((DrawablePtr) pPriv->sourceBits, pGC);
-    (*pGC->ops->PutImage) ((DrawablePtr) pPriv->sourceBits, pGC, 1,
+    ValidateGC((DrawablePtr) sourceBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr) sourceBits, pGC, 1,
                            0, 0, pCursor->bits->width, pCursor->bits->height,
                            0, XYPixmap, (char *) pCursor->bits->mask);
 
     /* mask bits -- pCursor->mask & ~pCursor->source */
     gcvals.val = GXcopy;
     ChangeGC(NullClient, pGC, GCFunction, &gcvals);
-    ValidateGC((DrawablePtr) pPriv->maskBits, pGC);
-    (*pGC->ops->PutImage) ((DrawablePtr) pPriv->maskBits, pGC, 1,
+    ValidateGC((DrawablePtr) maskBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr) maskBits, pGC, 1,
                            0, 0, pCursor->bits->width, pCursor->bits->height,
                            0, XYPixmap, (char *) pCursor->bits->mask);
     gcvals.val = GXandInverted;
     ChangeGC(NullClient, pGC, GCFunction, &gcvals);
-    ValidateGC((DrawablePtr) pPriv->maskBits, pGC);
-    (*pGC->ops->PutImage) ((DrawablePtr) pPriv->maskBits, pGC, 1,
+    ValidateGC((DrawablePtr) maskBits, pGC);
+    (*pGC->ops->PutImage) ((DrawablePtr) maskBits, pGC, 1,
                            0, 0, pCursor->bits->width, pCursor->bits->height,
                            0, XYPixmap, (char *) pCursor->bits->source);
     FreeScratchGC(pGC);
-    return pPriv;
+
+    miDCSwitchScreenCursor(pScreen, pCursor, sourceBits, maskBits, NULL);
+    return TRUE;
 }
 
 Bool
 miDCUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
 {
-    miDCCursorPtr pPriv;
-
-    pPriv = (miDCCursorPtr) dixLookupScreenPrivate(&pCursor->bits->devPrivates,
-                                                   miDCCursorBitsKey, pScreen);
-    if (pPriv && (pCursor->bits->refcnt <= 1)) {
-        if (pPriv->sourceBits)
-            (*pScreen->DestroyPixmap) (pPriv->sourceBits);
-        if (pPriv->maskBits)
-            (*pScreen->DestroyPixmap) (pPriv->maskBits);
-#ifdef ARGB_CURSOR
-        if (pPriv->pPicture)
-            FreePicture(pPriv->pPicture, 0);
-#endif
-        free((pointer) pPriv);
-        dixSetScreenPrivate(&pCursor->bits->devPrivates, miDCCursorBitsKey,
-                            pScreen, NULL);
-    }
+    miDCScreenPtr pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, miDCScreenKey);
+
+    if (pCursor == pScreenPriv->pCursor)
+        miDCSwitchScreenCursor(pScreen, NULL, NULL, NULL, NULL);
     return TRUE;
 }
 
 static void
 miDCPutBits(DrawablePtr pDrawable,
-            miDCCursorPtr pPriv,
             GCPtr sourceGC,
             GCPtr maskGC,
             int x_org,
             int y_org,
             unsigned w, unsigned h, unsigned long source, unsigned long mask)
 {
+    miDCScreenPtr pScreenPriv = dixLookupPrivate(&pDrawable->pScreen->devPrivates, miDCScreenKey);
     ChangeGCVal gcval;
     int x, y;
 
@@ -333,7 +323,7 @@ miDCPutBits(DrawablePtr pDrawable,
         y = y_org;
     }
 
-    (*sourceGC->ops->PushPixels) (sourceGC, pPriv->sourceBits, pDrawable, w, h,
+    (*sourceGC->ops->PushPixels) (sourceGC, pScreenPriv->sourceBits, pDrawable, w, h,
                                   x, y);
     if (maskGC->fgPixel != mask) {
         gcval.val = mask;
@@ -351,7 +341,7 @@ miDCPutBits(DrawablePtr pDrawable,
         y = y_org;
     }
 
-    (*maskGC->ops->PushPixels) (maskGC, pPriv->maskBits, pDrawable, w, h, x, y);
+    (*maskGC->ops->PushPixels) (maskGC, pScreenPriv->maskBits, pDrawable, w, h, x, y);
 }
 
 static GCPtr
@@ -373,27 +363,22 @@ Bool
 miDCPutUpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
                 int x, int y, unsigned long source, unsigned long mask)
 {
-    miDCCursorPtr pPriv;
+    miDCScreenPtr pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, miDCScreenKey);
     miDCBufferPtr pBuffer;
     WindowPtr pWin;
 
-    pPriv = (miDCCursorPtr) dixLookupScreenPrivate(&pCursor->bits->devPrivates,
-                                                   miDCCursorBitsKey, pScreen);
-    if (!pPriv) {
-        pPriv = miDCRealize(pScreen, pCursor);
-        if (!pPriv)
-            return FALSE;
-    }
+    if (!miDCRealize(pScreen, pCursor))
+        return FALSE;
 
     pWin = pScreen->root;
     pBuffer = miGetDCDevice(pDev, pScreen);
 
 #ifdef ARGB_CURSOR
-    if (pPriv->pPicture) {
+    if (pScreenPriv->pPicture) {
         if (!EnsurePicture(pBuffer->pRootPicture, &pWin->drawable, pWin))
             return FALSE;
         CompositePicture(PictOpOver,
-                         pPriv->pPicture,
+                         pScreenPriv->pPicture,
                          NULL,
                          pBuffer->pRootPicture,
                          0, 0, 0, 0,
@@ -402,7 +387,7 @@ miDCPutUpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
     else
 #endif
     {
-        miDCPutBits((DrawablePtr) pWin, pPriv,
+        miDCPutBits((DrawablePtr) pWin,
                     pBuffer->pSourceGC, pBuffer->pMaskGC,
                     x, y, pCursor->bits->width, pCursor->bits->height,
                     source, mask);
commit 7651176b0093cf3a4cff2277f6918a7d0451af41
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Jul 3 16:12:59 2012 -0700

    Use screen-specific privates for exa pixmap and gc privates
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/exa/exa.c b/exa/exa.c
index 0f90e59..623ece0 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -38,8 +38,6 @@
 #include "exa.h"
 
 DevPrivateKeyRec exaScreenPrivateKeyRec;
-DevPrivateKeyRec exaPixmapPrivateKeyRec;
-DevPrivateKeyRec exaGCPrivateKeyRec;
 
 #ifdef MITSHM
 static ShmFuncs exaShmFuncs = { NULL, NULL };
@@ -915,8 +913,8 @@ exaDriverInit(ScreenPtr pScreen, ExaDriverPtr pScreenInfo)
 
     exaDDXDriverInit(pScreen);
 
-    if (!dixRegisterPrivateKey
-        (&exaGCPrivateKeyRec, PRIVATE_GC, sizeof(ExaGCPrivRec))) {
+    if (!dixRegisterScreenSpecificPrivateKey
+        (pScreen, &pExaScr->gcPrivateKeyRec, PRIVATE_GC, sizeof(ExaGCPrivRec))) {
         LogMessage(X_WARNING, "EXA(%d): Failed to allocate GC private\n",
                    pScreen->myNum);
         return FALSE;
@@ -964,8 +962,8 @@ exaDriverInit(ScreenPtr pScreen, ExaDriverPtr pScreenInfo)
      * Hookup offscreen pixmaps
      */
     if (pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS) {
-        if (!dixRegisterPrivateKey
-            (&exaPixmapPrivateKeyRec, PRIVATE_PIXMAP,
+        if (!dixRegisterScreenSpecificPrivateKey
+            (pScreen, &pExaScr->pixmapPrivateKeyRec, PRIVATE_PIXMAP,
              sizeof(ExaPixmapPrivRec))) {
             LogMessage(X_WARNING,
                        "EXA(%d): Failed to allocate pixmap private\n",
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index f980fea..68eadc5 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -208,6 +208,8 @@ typedef struct {
     RegionRec maskReg;
     PixmapPtr srcPix;
 
+    DevPrivateKeyRec pixmapPrivateKeyRec;
+    DevPrivateKeyRec gcPrivateKeyRec;
 } ExaScreenPrivRec, *ExaScreenPrivPtr;
 
 /*
@@ -225,17 +227,11 @@ typedef struct {
 extern DevPrivateKeyRec exaScreenPrivateKeyRec;
 
 #define exaScreenPrivateKey (&exaScreenPrivateKeyRec)
-extern DevPrivateKeyRec exaPixmapPrivateKeyRec;
-
-#define exaPixmapPrivateKey (&exaPixmapPrivateKeyRec)
-extern DevPrivateKeyRec exaGCPrivateKeyRec;
-
-#define exaGCPrivateKey (&exaGCPrivateKeyRec)
 
 #define ExaGetScreenPriv(s) ((ExaScreenPrivPtr)dixGetPrivate(&(s)->devPrivates, exaScreenPrivateKey))
 #define ExaScreenPriv(s)	ExaScreenPrivPtr    pExaScr = ExaGetScreenPriv(s)
 
-#define ExaGetGCPriv(gc) ((ExaGCPrivPtr)dixGetPrivateAddr(&(gc)->devPrivates, exaGCPrivateKey))
+#define ExaGetGCPriv(gc) ((ExaGCPrivPtr)dixGetPrivateAddr(&(gc)->devPrivates, &ExaGetScreenPriv(gc->pScreen)->gcPrivateKeyRec))
 #define ExaGCPriv(gc) ExaGCPrivPtr pExaGC = ExaGetGCPriv(gc)
 
 /*
@@ -286,7 +282,7 @@ extern DevPrivateKeyRec exaGCPrivateKeyRec;
 #define EXA_PIXMAP_SCORE_PINNED	    1000
 #define EXA_PIXMAP_SCORE_INIT	    1001
 
-#define ExaGetPixmapPriv(p) ((ExaPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, exaPixmapPrivateKey))
+#define ExaGetPixmapPriv(p) ((ExaPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &ExaGetScreenPriv((p)->drawable.pScreen)->pixmapPrivateKeyRec))
 #define ExaPixmapPriv(p)	ExaPixmapPrivPtr pExaPixmap = ExaGetPixmapPriv(p)
 
 #define EXA_RANGE_PITCH (1 << 0)
commit 7ca32f1c282cb6d4d7255f118a1e2e6f54e6b3fa
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Jul 3 16:05:42 2012 -0700

    Use new screen-specific privates for fb window and gc privates
    
    This ensures that only screens using fb will have this space allocated.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/fb/fb.h b/fb/fb.h
index cc3b6ee..40a7e38 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -570,12 +570,6 @@ 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 const GCOps fbGCOps;
 extern _X_EXPORT const GCFuncs fbGCFuncs;
 
@@ -605,7 +599,7 @@ typedef void (*FinishWrapProcPtr) (DrawablePtr pDraw);
 #endif
 
 extern _X_EXPORT DevPrivateKey
- fbGetScreenPrivateKey(void);
+fbGetScreenPrivateKey(void);
 
 /* private field of a screen */
 typedef struct {
@@ -615,6 +609,8 @@ typedef struct {
     SetupWrapProcPtr setupWrap; /* driver hook to set pixmap access wrapping */
     FinishWrapProcPtr finishWrap;       /* driver hook to clean up pixmap access wrapping */
 #endif
+    DevPrivateKeyRec    gcPrivateKeyRec;
+    DevPrivateKeyRec    winPrivateKeyRec;
 } FbScreenPrivRec, *FbScreenPrivPtr;
 
 #define fbGetScreenPrivate(pScreen) ((FbScreenPrivPtr) \
@@ -630,8 +626,10 @@ typedef struct {
     unsigned char bpp;          /* current drawable bpp */
 } FbGCPrivRec, *FbGCPrivPtr;
 
+#define fbGetGCPrivateKey(pGC)  (&fbGetScreenPrivate((pGC)->pScreen)->gcPrivateKeyRec)
+
 #define fbGetGCPrivate(pGC)	((FbGCPrivPtr)\
-				 dixLookupPrivate(&(pGC)->devPrivates, fbGetGCPrivateKey()))
+				 dixLookupPrivate(&(pGC)->devPrivates, fbGetGCPrivateKey(pGC)))
 
 #define fbGetCompositeClip(pGC) ((pGC)->pCompositeClip)
 #define fbGetExpose(pGC)	((pGC)->fExpose)
@@ -639,8 +637,11 @@ typedef struct {
 #define fbGetRotatedPixmap(pGC)	((pGC)->pRotatedPixmap)
 
 #define fbGetScreenPixmap(s)	((PixmapPtr) (s)->devPrivate)
+
+#define fbGetWinPrivateKey(pWin)        (&fbGetScreenPrivate(((DrawablePtr) (pWin))->pScreen)->winPrivateKeyRec)
+
 #define fbGetWindowPixmap(pWin)	((PixmapPtr)\
-				 dixLookupPrivate(&((WindowPtr)(pWin))->devPrivates, fbGetWinPrivateKey()))
+				 dixLookupPrivate(&((WindowPtr)(pWin))->devPrivates, fbGetWinPrivateKey(pWin)))
 
 #ifdef ROOTLESS
 #define __fbPixDrawableX(pPix)	((pPix)->drawable.x)
@@ -782,14 +783,14 @@ fb24_32ModifyPixmapHeader(PixmapPtr pPixmap,
  * fballpriv.c
  */
 extern _X_EXPORT Bool
- fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCIndex);
+fbAllocatePrivates(ScreenPtr pScreen);
 
 /*
  * fbarc.c
  */
 
 extern _X_EXPORT void
- fbPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc * parcs);
+fbPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs, xArc * parcs);
 
 /*
  * fbbits.c
diff --git a/fb/fballpriv.c b/fb/fballpriv.c
index c6504f9..187d0b0 100644
--- a/fb/fballpriv.c
+++ b/fb/fballpriv.c
@@ -33,33 +33,20 @@ fbGetScreenPrivateKey(void)
     return &fbScreenPrivateKeyRec;
 }
 
-static DevPrivateKeyRec fbGCPrivateKeyRec;
-DevPrivateKey
-fbGetGCPrivateKey(void)
-{
-    return &fbGCPrivateKeyRec;
-}
-
-static DevPrivateKeyRec fbWinPrivateKeyRec;
-DevPrivateKey
-fbGetWinPrivateKey(void)
-{
-    return &fbWinPrivateKeyRec;
-}
-
 Bool
-fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCKey)
+fbAllocatePrivates(ScreenPtr pScreen)
 {
-    if (pGCKey)
-        *pGCKey = &fbGCPrivateKeyRec;
+    FbScreenPrivPtr     pScrPriv;
 
     if (!dixRegisterPrivateKey
-        (&fbGCPrivateKeyRec, PRIVATE_GC, sizeof(FbGCPrivRec)))
-        return FALSE;
-    if (!dixRegisterPrivateKey
         (&fbScreenPrivateKeyRec, PRIVATE_SCREEN, sizeof(FbScreenPrivRec)))
         return FALSE;
-    if (!dixRegisterPrivateKey(&fbWinPrivateKeyRec, PRIVATE_WINDOW, 0))
+
+    pScrPriv = fbGetScreenPrivate(pScreen);
+
+    if (!dixRegisterScreenSpecificPrivateKey (pScreen, &pScrPriv->gcPrivateKeyRec, PRIVATE_GC, sizeof(FbGCPrivRec)))
+        return FALSE;
+    if (!dixRegisterScreenSpecificPrivateKey (pScreen, &pScrPriv->winPrivateKeyRec, PRIVATE_WINDOW, 0))
         return FALSE;
 
     return TRUE;
diff --git a/fb/fboverlay.c b/fb/fboverlay.c
index a882ffa..c6802e4 100644
--- a/fb/fboverlay.c
+++ b/fb/fboverlay.c
@@ -63,7 +63,7 @@ fbOverlayCreateWindow(WindowPtr pWin)
     for (i = 0; i < pScrPriv->nlayers; i++) {
         pPixmap = pScrPriv->layer[i].u.run.pixmap;
         if (pWin->drawable.depth == pPixmap->drawable.depth) {
-            dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(), pPixmap);
+            dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(pWin), pPixmap);
             /*
              * Make sure layer keys are written correctly by
              * having non-root layers set to full while the
@@ -103,7 +103,7 @@ fbOverlayWindowLayer(WindowPtr pWin)
     int i;
 
     for (i = 0; i < pScrPriv->nlayers; i++)
-        if (dixLookupPrivate(&pWin->devPrivates, fbGetWinPrivateKey()) ==
+        if (dixLookupPrivate(&pWin->devPrivates, fbGetWinPrivateKey(pWin)) ==
             (pointer) pScrPriv->layer[i].u.run.pixmap)
             return i;
     return 0;
diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index 0833cd4..7c7d656 100644
--- a/fb/fbscreen.c
+++ b/fb/fbscreen.c
@@ -85,7 +85,7 @@ _fbGetWindowPixmap(WindowPtr pWindow)
 void
 _fbSetWindowPixmap(WindowPtr pWindow, PixmapPtr pPixmap)
 {
-    dixSetPrivate(&pWindow->devPrivates, fbGetWinPrivateKey(), pPixmap);
+    dixSetPrivate(&pWindow->devPrivates, fbGetWinPrivateKey(pWindow), pPixmap);
 }
 
 Bool
@@ -95,7 +95,7 @@ fbSetupScreen(ScreenPtr pScreen, pointer pbits, /* pointer to screen bitmap */
               int dpiy, int width,      /* pixel width of frame buffer */
               int bpp)
 {                               /* bits per pixel for screen */
-    if (!fbAllocatePrivates(pScreen, NULL))
+    if (!fbAllocatePrivates(pScreen))
         return FALSE;
     pScreen->defColormap = FakeClientID(0);
     /* let CreateDefColormap do whatever it wants for pixels */
diff --git a/fb/fbwindow.c b/fb/fbwindow.c
index d27ccd4..368c4b8 100644
--- a/fb/fbwindow.c
+++ b/fb/fbwindow.c
@@ -31,7 +31,7 @@
 Bool
 fbCreateWindow(WindowPtr pWin)
 {
-    dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(),
+    dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(pWin),
                   fbGetScreenPixmap(pWin->drawable.pScreen));
     if (pWin->drawable.bitsPerPixel == 32)
         pWin->drawable.bitsPerPixel =
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index 8b896eb..588440c 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -69,15 +69,11 @@
 #define fbFixCoordModePrevious wfbFixCoordModePrevious
 #define fbGCFuncs wfbGCFuncs
 #define fbGCOps wfbGCOps
-#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
 #define fbGlyph32 wfbGlyph32
commit 9d457f9c55f12106ba44c1c9db59d14f978f0ae8
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Jul 3 15:45:09 2012 -0700

    Add screen-specific privates.
    
    Screen-specific privates areas are only allocated for objects related
    to the target screen; objects allocated for other screens will not
    have the private space reserved. This saves memory in these objects
    while also allowing hot-plug screens to have additional private
    allocation space beyond what the core screens are using.
    
    Drivers are encouraged to switch to this mechanism as it will reduce
    memory usage in multi-GPU environments, but it is only required for
    drivers which will be loaded after the server starts, like
    modesetting.
    
    Objects providing screen-specific privates *must* be managed by the
    screen-specific private API when allocating or initializing privates
    so that the per-screen area can be initialized properly.
    
    The objects which support screen-specific privates are:
    
    	Windows
    	Pixmaps
    	GCs
    	Pictures
    
    Extending this list to include Colormaps would be possible, but
    require slightly more work as the default colormap is created before
    all colormap privates are allocated during server startup, and hence
    gets a bunch of special treatment.
    
    Of particular note, glyphs are *not* capable of supporting
    screen-specific privates as they are global objects, not allocated on
    a screen-specific basis, and so each driver must be able to see their
    privates within the glyph.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index b88f974..7d2d3b7 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3743,6 +3743,8 @@ AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
     if (!pScreen)
         return -1;
 
+    dixInitScreenSpecificPrivates(pScreen);
+
     if (!dixAllocatePrivates(&pScreen->devPrivates, PRIVATE_SCREEN)) {
         free(pScreen);
         return -1;
@@ -3794,6 +3796,7 @@ AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
     screenInfo.screens[i] = pScreen;
     screenInfo.numScreens++;
     if (!(*pfnInit) (pScreen, argc, argv)) {
+        dixFreeScreenSpecificPrivates(pScreen);
         dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
         free(pScreen);
         screenInfo.numScreens--;
diff --git a/dix/gc.c b/dix/gc.c
index ac67643..60f54ec 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -463,7 +463,7 @@ NewGCObject(ScreenPtr pScreen, int depth)
 {
     GCPtr pGC;
 
-    pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
+    pGC = dixAllocateScreenObjectWithPrivates(pScreen, GC, PRIVATE_GC);
     if (!pGC) {
         return (GCPtr) NULL;
     }
diff --git a/dix/main.c b/dix/main.c
index e95ca1c..9524189 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -329,6 +329,7 @@ main(int argc, char *argv[], char *envp[])
             FreeScratchPixmapsForScreen(screenInfo.screens[i]);
             FreeGCperDepth(i);
             FreeDefaultStipple(i);
+            dixFreeScreenSpecificPrivates(screenInfo.screens[i]);
             (*screenInfo.screens[i]->CloseScreen) (screenInfo.screens[i]);
             dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN);
             free(screenInfo.screens[i]);
diff --git a/dix/pixmap.c b/dix/pixmap.c
index 545ff54..0c85c3f 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -88,7 +88,7 @@ CreateScratchPixmapsForScreen(ScreenPtr pScreen)
 {
     unsigned int pixmap_size;
 
-    pixmap_size = sizeof(PixmapRec) + dixPrivatesSize(PRIVATE_PIXMAP);
+    pixmap_size = sizeof(PixmapRec) + dixScreenSpecificPrivatesSize(pScreen, PRIVATE_PIXMAP);
     pScreen->totalPixmapSize =
         BitmapBytePad(pixmap_size * 8);
 
@@ -118,7 +118,7 @@ AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
     if (!pPixmap)
         return NullPixmap;
 
-    dixInitPrivates(pPixmap, pPixmap + 1, PRIVATE_PIXMAP);
+    dixInitScreenPrivates(pScreen, pPixmap, pPixmap + 1, PRIVATE_PIXMAP);
     return pPixmap;
 }
 
diff --git a/dix/privates.c b/dix/privates.c
index 15fbf75..e353108 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -63,12 +63,7 @@ from The Open Group.
 #include "scrnintstr.h"
 #include "extnsionst.h"
 
-static struct {
-    DevPrivateKey key;
-    unsigned offset;
-    int created;
-    int allocated;
-} keys[PRIVATE_LAST];
+static DevPrivateSetRec global_keys[PRIVATE_LAST];
 
 static const Bool xselinux_private[PRIVATE_LAST] = {
     [PRIVATE_SCREEN] = TRUE,
@@ -86,8 +81,57 @@ static const Bool xselinux_private[PRIVATE_LAST] = {
     [PRIVATE_GLYPHSET] = TRUE,
 };
 
+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",
+    [PRIVATE_SYNC_FENCE] = "SYNC_FENCE",
+};
+
+static const Bool screen_specific_private[PRIVATE_LAST] = {
+    [PRIVATE_SCREEN] = FALSE,
+    [PRIVATE_CLIENT] = FALSE,
+    [PRIVATE_WINDOW] = TRUE,
+    [PRIVATE_PIXMAP] = TRUE,
+    [PRIVATE_GC] = TRUE,
+    [PRIVATE_CURSOR] = FALSE,
+    [PRIVATE_COLORMAP] = FALSE,
+    [PRIVATE_DEVICE] = FALSE,
+    [PRIVATE_EXTENSION] = FALSE,
+    [PRIVATE_SELECTION] = FALSE,
+    [PRIVATE_PROPERTY] = FALSE,
+    [PRIVATE_PICTURE] = TRUE,
+    [PRIVATE_GLYPHSET] = FALSE,
+};
+
 typedef Bool (*FixupFunc) (PrivatePtr *privates, int offset, unsigned bytes);
 
+typedef enum { FixupMove, FixupRealloc } FixupType;
+
 static Bool
 dixReallocPrivates(PrivatePtr *privates, int old_offset, unsigned bytes)
 {
@@ -110,14 +154,72 @@ dixMovePrivates(PrivatePtr *privates, int new_offset, unsigned bytes)
 }
 
 static Bool
+fixupOneScreen(ScreenPtr pScreen, FixupFunc fixup, unsigned bytes)
+{
+    intptr_t        dist;
+    char            *old;
+    char            *new;
+    DevPrivateKey   *keyp, key;
+    DevPrivateType  type;
+    int             size;
+
+    old = (char *) pScreen->devPrivates;
+    size = global_keys[PRIVATE_SCREEN].offset;
+    if (!fixup (&pScreen->devPrivates, size, bytes))
+        return FALSE;
+
+    /* Screen privates can contain screen-specific private keys
+     * for other types. When they move, the linked list we use to
+     * track them gets scrambled. Fix that by computing the change
+     * in the location of each private adjusting our linked list
+     * pointers to match
+     */
+
+    new = (char *) pScreen->devPrivates;
+
+    /* Moving means everyone shifts up in the privates by 'bytes' amount,
+     * realloc means the base pointer moves
+     */
+    if (fixup == dixMovePrivates)
+        new += bytes;
+
+    dist = new - old;
+
+    if (dist) {
+        for (type = PRIVATE_XSELINUX; type < PRIVATE_LAST; type++)
+
+            /* Walk the privates list, being careful as the
+             * pointers are scrambled before we patch them.
+             */
+            for (keyp = &pScreen->screenSpecificPrivates[type].key;
+                 (key = *keyp) != NULL;
+                 keyp = &key->next)
+            {
+
+                /* Only mangle things if the private structure
+                 * is contained within the allocation. Privates
+                 * stored elsewhere will be left alone
+                 */
+                if (old <= (char *) key && (char *) key < old + size)
+                {
+                    /* Compute new location of key */
+                    key = (DevPrivateKey) ((char *) key + dist);
+
+                    /* Patch the list */
+                    *keyp = key;
+                }
+            }
+    }
+    return TRUE;
+}
+
+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))
+        if (!fixupOneScreen (screenInfo.screens[s], fixup, bytes))
             return FALSE;
     return TRUE;
 }
@@ -126,7 +228,7 @@ static Bool
 fixupServerClient(FixupFunc fixup, unsigned bytes)
 {
     if (serverClient)
-        return fixup(&serverClient->devPrivates, keys[PRIVATE_CLIENT].offset,
+        return fixup(&serverClient->devPrivates, global_keys[PRIVATE_CLIENT].offset,
                      bytes);
     return TRUE;
 }
@@ -140,7 +242,7 @@ fixupExtensions(FixupFunc fixup, unsigned bytes)
     for (major = EXTENSION_BASE; (extension = GetExtensionEntry(major));
          major++)
         if (!fixup
-            (&extension->devPrivates, keys[PRIVATE_EXTENSION].offset, bytes))
+            (&extension->devPrivates, global_keys[PRIVATE_EXTENSION].offset, bytes))
             return FALSE;
     return TRUE;
 }
@@ -157,17 +259,41 @@ fixupDefaultColormaps(FixupFunc fixup, unsigned bytes)
                                 screenInfo.screens[s]->defColormap, RT_COLORMAP,
                                 serverClient, DixCreateAccess);
         if (cmap &&
-            !fixup(&cmap->devPrivates, keys[PRIVATE_COLORMAP].offset, bytes))
+            !fixup(&cmap->devPrivates, screenInfo.screens[s]->screenSpecificPrivates[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,};
+    [PRIVATE_SCREEN] = fixupScreens,
+    [PRIVATE_CLIENT] = fixupServerClient,
+    [PRIVATE_EXTENSION] = fixupExtensions,
+    [PRIVATE_COLORMAP] = fixupDefaultColormaps,
+};
+
+static void
+grow_private_set(DevPrivateSetPtr set, unsigned bytes)
+{
+    DevPrivateKey       k;
+
+    for (k = set->key; k; k = k->next)
+        k->offset += bytes;
+    set->offset += bytes;
+}
+
+static void
+grow_screen_specific_set(DevPrivateType type, unsigned bytes)
+{
+    int s;
+
+    /* Update offsets for all screen-specific keys */
+    for (s = 0; s < screenInfo.numScreens; s++) {
+        ScreenPtr       pScreen = screenInfo.screens[s];
+
+        grow_private_set(&pScreen->screenSpecificPrivates[type], bytes);
+    }
+}
 
 /*
  * Register a private key. This takes the type of object the key will
@@ -199,14 +325,13 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
 
     /* 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);
+                    assert(!global_keys[t].created);
                 else if (!allocated_early[t] (dixReallocPrivates, bytes))
                     return FALSE;
             }
@@ -216,12 +341,12 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
          */
         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;
+                grow_private_set(&global_keys[t], bytes);
+                grow_screen_specific_set(t, bytes);
                 if (allocated_early[t])
                     allocated_early[t] (dixMovePrivates, bytes);
             }
+
         }
 
         offset = 0;
@@ -229,11 +354,12 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
     else {
         /* Resize if we can, or make sure nothing's allocated if we can't */
         if (!allocated_early[type])
-            assert(!keys[type].created);
+            assert(!global_keys[type].created);
         else if (!allocated_early[type] (dixReallocPrivates, bytes))
             return FALSE;
-        offset = keys[type].offset;
-        keys[type].offset += bytes;
+        offset = global_keys[type].offset;
+        global_keys[type].offset += bytes;
+        grow_screen_specific_set(type, bytes);
     }
 
     /* Setup this key */
@@ -242,8 +368,8 @@ dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size)
     key->initialized = TRUE;
     key->type = type;
     key->allocated = FALSE;
-    key->next = keys[type].key;
-    keys[type].key = key;
+    key->next = global_keys[type].key;
+    global_keys[type].key = key;
 
     return TRUE;
 }
@@ -286,13 +412,15 @@ _dixGetScreenPrivateKey(const DevScreenPrivateKey key, ScreenPtr pScreen)
 void
 _dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type)
 {
-    keys[type].created++;
+    assert (!screen_specific_private[type]);
+
+    global_keys[type].created++;
     if (xselinux_private[type])
-        keys[PRIVATE_XSELINUX].created++;
-    if (keys[type].offset == 0)
+        global_keys[PRIVATE_XSELINUX].created++;
+    if (global_keys[type].offset == 0)
         addr = 0;
     *privates = addr;
-    memset(addr, '\0', keys[type].offset);
+    memset(addr, '\0', global_keys[type].offset);
 }
 
 /*
@@ -301,9 +429,9 @@ _dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type)
 void
 _dixFiniPrivates(PrivatePtr privates, DevPrivateType type)
 {
-    keys[type].created--;
+    global_keys[type].created--;
     if (xselinux_private[type])
-        keys[PRIVATE_XSELINUX].created--;
+        global_keys[PRIVATE_XSELINUX].created--;
 }
 
 /*
@@ -322,10 +450,11 @@ _dixAllocateObjectWithPrivates(unsigned baseSize, unsigned clear,
     PrivatePtr *devPrivates;
 
     assert(type > PRIVATE_SCREEN && type < PRIVATE_LAST);
+    assert(!screen_specific_private[type]);
 
     /* round up so that void * is aligned */
     baseSize = (baseSize + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
-    totalSize = baseSize + keys[type].offset;
+    totalSize = baseSize + global_keys[type].offset;
     object = malloc(totalSize);
     if (!object)
         return NULL;
@@ -350,8 +479,9 @@ dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type)
     PrivatePtr p;
 
     assert(type > PRIVATE_XSELINUX && type < PRIVATE_LAST);
+    assert(!screen_specific_private[type]);
 
-    size = keys[type].offset;
+    size = global_keys[type].offset;
     if (!size) {
         p = NULL;
     }
@@ -361,7 +491,7 @@ dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type)
     }
 
     _dixInitPrivates(privates, p, type);
-    ++keys[type].allocated;
+    ++global_keys[type].allocated;
 
     return TRUE;
 }
@@ -387,7 +517,7 @@ void
 dixFreePrivates(PrivatePtr privates, DevPrivateType type)
 {
     _dixFiniPrivates(privates, type);
-    --keys[type].allocated;
+    --global_keys[type].allocated;
     free(privates);
 }
 
@@ -398,8 +528,9 @@ extern _X_EXPORT int
 dixPrivatesSize(DevPrivateType type)
 {
     assert(type >= PRIVATE_SCREEN && type < PRIVATE_LAST);
+    assert (!screen_specific_private[type]);
 
-    return keys[type].offset;
+    return global_keys[type].offset;
 }
 
 /* Table of devPrivates offsets */
@@ -434,36 +565,136 @@ dixLookupPrivateOffset(RESTYPE type)
     return -1;
 }
 
-static const char *key_names[PRIVATE_LAST] = {
-    /* XSELinux uses the same private keys for numerous objects */
-    [PRIVATE_XSELINUX] = "XSELINUX",
+/*
+ * Screen-specific privates
+ */
 
-    /* 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",
+extern _X_EXPORT Bool
+dixRegisterScreenSpecificPrivateKey(ScreenPtr pScreen, DevPrivateKey key,
+                                    DevPrivateType type, unsigned size)
+{
+    int offset;
+    unsigned bytes;
 
-    /* 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",
+    if (!screen_specific_private[type])
+        FatalError("Attempt to allocate screen-specific private storage for type %s\n",
+                   key_names[type]);
 
-    /* extension privates */
-    [PRIVATE_DBE_WINDOW] = "DBE_WINDOW",
-    [PRIVATE_DAMAGE] = "DAMAGE",
-    [PRIVATE_GLYPH] = "GLYPH",
-    [PRIVATE_GLYPHSET] = "GLYPHSET",
-    [PRIVATE_PICTURE] = "PICTURE",
-    [PRIVATE_SYNC_FENCE] = "SYNC_FENCE",
-};
+    if (key->initialized) {
+        assert(size == key->size);
+        return TRUE;
+    }
+
+    /* Compute required space */
+    bytes = size;
+    if (size == 0)
+        bytes = sizeof(void *);
+
+    /* align to void * size */
+    bytes = (bytes + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
+
+    assert (!allocated_early[type]);
+    assert (!pScreen->screenSpecificPrivates[type].created);
+    offset = pScreen->screenSpecificPrivates[type].offset;
+    pScreen->screenSpecificPrivates[type].offset += bytes;
+
+    /* Setup this key */
+    key->offset = offset;
+    key->size = size;
+    key->initialized = TRUE;
+    key->type = type;
+    key->allocated = FALSE;
+    key->next = pScreen->screenSpecificPrivates[type].key;
+    pScreen->screenSpecificPrivates[type].key = key;
+
+    return TRUE;
+}
+
+/* Clean up screen-specific privates before CloseScreen */
+void
+dixFreeScreenSpecificPrivates(ScreenPtr pScreen)
+{
+}
+
+/* Initialize screen-specific privates in AddScreen */
+void
+dixInitScreenSpecificPrivates(ScreenPtr pScreen)
+{
+    DevPrivateType      t;
+
+    for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++)
+        pScreen->screenSpecificPrivates[t].offset = global_keys[t].offset;
+}
+
+/* Initialize screen-specific privates in AddScreen */
+void
+_dixInitScreenPrivates(ScreenPtr pScreen, PrivatePtr *privates, void *addr, DevPrivateType type)
+{
+    int privates_size;
+    assert (screen_specific_private[type]);
+
+    if (pScreen) {
+        privates_size = pScreen->screenSpecificPrivates[type].offset;
+        pScreen->screenSpecificPrivates[type].created++;
+    }
+    else
+        privates_size = global_keys[type].offset;
+
+    global_keys[type].created++;
+    if (xselinux_private[type])
+        global_keys[PRIVATE_XSELINUX].created++;
+    if (privates_size == 0)
+        addr = 0;
+    *privates = addr;
+    memset(addr, '\0', privates_size);
+}
+
+void *
+_dixAllocateScreenObjectWithPrivates(ScreenPtr pScreen,
+                                     unsigned baseSize,
+                                     unsigned clear,
+                                     unsigned offset,
+                                     DevPrivateType type)
+{
+    unsigned totalSize;
+    void *object;
+    PrivatePtr privates;
+    PrivatePtr *devPrivates;
+    int privates_size;
+
+    assert(type > PRIVATE_SCREEN && type < PRIVATE_LAST);
+    assert (screen_specific_private[type]);
+
+    if (pScreen)
+        privates_size = pScreen->screenSpecificPrivates[type].offset;
+    else
+        privates_size = global_keys[type].offset;
+    /* round up so that void * is aligned */
+    baseSize = (baseSize + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
+    totalSize = baseSize + privates_size;
+    object = malloc(totalSize);
+    if (!object)
+        return NULL;
+
+    memset(object, '\0', clear);
+    privates = (PrivatePtr) (((char *) object) + baseSize);
+    devPrivates = (PrivatePtr *) ((char *) object + offset);
+
+    _dixInitScreenPrivates(pScreen, devPrivates, privates, type);
+
+    return object;
+}
+
+int
+dixScreenSpecificPrivatesSize(ScreenPtr pScreen, DevPrivateType type)
+{
+    assert(type >= PRIVATE_SCREEN && type < PRIVATE_LAST);
+
+    if (screen_specific_private[type])
+        return pScreen->screenSpecificPrivates[type].offset;
+    else
+        return global_keys[type].offset;
+}
 
 void
 dixPrivateUsage(void)
@@ -474,14 +705,14 @@ dixPrivateUsage(void)
     DevPrivateType t;
 
     for (t = PRIVATE_XSELINUX + 1; t < PRIVATE_LAST; t++) {
-        if (keys[t].offset) {
+        if (global_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;
+                 key_names[t], global_keys[t].created, global_keys[t].offset,
+                 global_keys[t].created * global_keys[t].offset, global_keys[t].allocated);
+            bytes += global_keys[t].created * global_keys[t].offset;
+            objects += global_keys[t].created;
+            alloc += global_keys[t].allocated;
         }
     }
     ErrorF("TOTAL: %d objects, %d bytes, %d allocs\n", objects, bytes, alloc);
@@ -495,7 +726,7 @@ dixResetPrivates(void)
     for (t = PRIVATE_XSELINUX; t < PRIVATE_LAST; t++) {
         DevPrivateKey key, next;
 
-        for (key = keys[t].key; key; key = next) {
+        for (key = global_keys[t].key; key; key = next) {
             next = key->next;
             key->offset = 0;
             key->initialized = FALSE;
@@ -504,14 +735,14 @@ dixResetPrivates(void)
             if (key->allocated)
                 free(key);
         }
-        if (keys[t].created) {
+        if (global_keys[t].created) {
             ErrorF("%d %ss still allocated at reset\n",
-                   keys[t].created, key_names[t]);
+                   global_keys[t].created, key_names[t]);
             dixPrivateUsage();
         }
-        keys[t].key = NULL;
-        keys[t].offset = 0;
-        keys[t].created = 0;
-        keys[t].allocated = 0;
+        global_keys[t].key = NULL;
+        global_keys[t].offset = 0;
+        global_keys[t].created = 0;
+        global_keys[t].allocated = 0;
     }
 }
diff --git a/dix/window.c b/dix/window.c
index 5cc3a50..b660808 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -446,7 +446,7 @@ CreateRootWindow(ScreenPtr pScreen)
     BoxRec box;
     PixmapFormatRec *format;
 
-    pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW);
+    pWin = dixAllocateScreenObjectWithPrivates(pScreen, WindowRec, PRIVATE_WINDOW);
     if (!pWin)
         return FALSE;
 
@@ -710,7 +710,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
         return NullWindow;
     }
 
-    pWin = dixAllocateObjectWithPrivates(WindowRec, PRIVATE_WINDOW);
+    pWin = dixAllocateScreenObjectWithPrivates(pScreen, WindowRec, PRIVATE_WINDOW);
     if (!pWin) {
         *error = BadAlloc;
         return NullWindow;
diff --git a/doc/Xserver-spec.xml b/doc/Xserver-spec.xml
index 31b6fb0..cd1a9d0 100644
--- a/doc/Xserver-spec.xml
+++ b/doc/Xserver-spec.xml
@@ -109,6 +109,12 @@
 	<revremark>Revised for Xorg 1.9 devPrivates changes
 	  and 1.8 CreateNewResourceType changes</revremark>
       </revision>
+      <revision>
+	<revnumber>3.6</revnumber>
+	<date>July 2012</date>
+	<authorinitials>kp</authorinitials>
+	<revremark>Revised for X server 1.13 screen-specific devPrivates changes</revremark>
+      </revision>
     </revhistory>
     <abstract>
       <para>The following document explains the structure of the X Window System display server and the interfaces among the larger pieces.  It is intended as a reference for programmers who are implementing an X Display Server on their workstation hardware.  It is included with the X Window System source tape, along with the document "Strategies for Porting the X v11 Sample Server."  The order in which you should read these documents is:
@@ -4714,7 +4720,8 @@ Two new extensibility concepts have been developed for release 4, Wrappers
 and devPrivates.  These replace the R3 GCInterest queues, which were not a
 general enough mechanism for many extensions and only provided hooks into a
 single data structure.  devPrivates have been revised substantially for
-X.Org X server release 1.5, and updated again for the 1.9 release.</para>
+X.Org X server release 1.5, updated again for the 1.9 release and extended
+again for the 1.13 relealse.</para>
 <section>
   <title>devPrivates</title>
 <para>
@@ -4758,6 +4765,23 @@ the specified type with distinct storage for the given
 that are otherwise equivalent to the following Private functions.</para>
 
 <para>
+  To request private space in objects created for a specific screen, use
+  <blockquote><programlisting>
+    Bool dixRegisterScreenSpecificPrivateKey(ScreenPtr pScreen, DevPrivateKey key, DevPrivateType type, unsigned size);
+  </programlisting></blockquote>
+  The <parameter>type</parameter> and <parameter>size</parameter> arguments are
+  the same as those to <function>dixRegisterPrivateKey</function> but this
+  function ensures only that the given <parameter>key</parameter> exists on objects of
+  the specified type that are allocated with reference to the specified
+  <parameter>pScreen</parameter>. Using the key on objects allocated for
+  other screens will result in incorrect results; there is no check made to
+  ensure that the caller's screen matches the private's screen. The key is
+  usable in any of the following functions. Screen-specific private storage is available
+  only for Windows, GCs, Pixmaps and Pictures. Attempts to allocate screen-specific
+  privates on other objects will result in a call to FatalError.
+</para>
+
+<para>
 To attach a piece of private data to an object, use:
 <blockquote><programlisting>
 	void dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
diff --git a/include/privates.h b/include/privates.h
index c34b951..a0874f6 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -66,6 +66,13 @@ typedef struct _DevPrivateKeyRec {
     struct _DevPrivateKeyRec *next;
 } DevPrivateKeyRec, *DevPrivateKey;
 
+typedef struct _DevPrivateSetRec {
+    DevPrivateKey key;
+    unsigned offset;
+    int created;
+    int allocated;
+} DevPrivateSetRec, *DevPrivateSetPtr;
+
 typedef struct _DevScreenPrivateKeyRec {
     DevPrivateKeyRec screenKey;
 } DevScreenPrivateKeyRec, *DevScreenPrivateKey;
@@ -219,6 +226,51 @@ dixLookupScreenPrivateAddr(PrivatePtr *privates, const DevScreenPrivateKey key,
 }
 
 /*
+ * These functions relate to allocations related to a specific screen;
+ * space will only be available for objects allocated for use on that
+ * screen. As such, only objects which are related directly to a specific
+ * screen are candidates for allocation this way, this includes
+ * windows, pixmaps, gcs, pictures and colormaps. This key is
+ * used just like any other key using dixGetPrivate and friends.
+ *
+ * This is distinctly different from the ScreenPrivateKeys above which
+ * allocate space in global objects like cursor bits for a specific
+ * screen, allowing multiple screen-related chunks of storage in a
+ * single global object.
+ */
+
+#define HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS       1
+
+extern _X_EXPORT Bool
+dixRegisterScreenSpecificPrivateKey(ScreenPtr pScreen, DevPrivateKey key,
+                                    DevPrivateType type, unsigned size);
+
+/* Clean up screen-specific privates before CloseScreen */
+extern void
+dixFreeScreenSpecificPrivates(ScreenPtr pScreen);
+
+/* Initialize screen-specific privates in AddScreen */
+extern void
+dixInitScreenSpecificPrivates(ScreenPtr pScreen);
+
+extern _X_EXPORT void *
+_dixAllocateScreenObjectWithPrivates(ScreenPtr pScreen,
+                                     unsigned size,
+                                     unsigned clear,
+                                     unsigned offset,
+                                     DevPrivateType type);
+
+#define dixAllocateScreenObjectWithPrivates(s, t, type) _dixAllocateScreenObjectWithPrivates(s, sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
+
+extern _X_EXPORT int
+dixScreenSpecificPrivatesSize(ScreenPtr pScreen, DevPrivateType type);
+
+extern _X_EXPORT void
+_dixInitScreenPrivates(ScreenPtr pScreen, PrivatePtr *privates, void *addr, DevPrivateType type);
+
+#define dixInitScreenPrivates(s, o, v, type) _dixInitScreenPrivates(s, &(o)->devPrivates, (v), type);
+
+/*
  * Allocates private data separately from main object.
  *
  * For objects created during server initialization, this allows those
@@ -240,7 +292,7 @@ extern _X_EXPORT void
  * Initialize privates by zeroing them
  */
 extern _X_EXPORT void
- _dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type);
+_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type);
 
 #define dixInitPrivates(o, v, type) _dixInitPrivates(&(o)->devPrivates, (v), type);
 
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index c592d1f..7af2bf5 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -367,6 +367,8 @@ typedef struct _Screen {
     WindowPtr root;
     ScreenSaverStuffRec screensaver;
 
+    DevPrivateSetRec    screenSpecificPrivates[PRIVATE_LAST];
+
     /* Random screen procedures */
 
     CloseScreenProcPtr CloseScreen;
diff --git a/render/picture.c b/render/picture.c
index ebbfa29..2908b76 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -763,7 +763,8 @@ CreatePicture(Picture pid,
     PicturePtr pPicture;
     PictureScreenPtr ps = GetPictureScreen(pDrawable->pScreen);
 
-    pPicture = dixAllocateObjectWithPrivates(PictureRec, PRIVATE_PICTURE);
+    pPicture = dixAllocateScreenObjectWithPrivates(pDrawable->pScreen,
+                                                   PictureRec, PRIVATE_PICTURE);
     if (!pPicture) {
         *error = BadAlloc;
         return 0;
@@ -853,7 +854,7 @@ createSourcePicture(void)
 {
     PicturePtr pPicture;
 
-    pPicture = dixAllocateObjectWithPrivates(PictureRec, PRIVATE_PICTURE);
+    pPicture = dixAllocateScreenObjectWithPrivates(NULL, PictureRec, PRIVATE_PICTURE);
     pPicture->pDrawable = 0;
     pPicture->pFormat = 0;
     pPicture->pNext = 0;
commit ed6daa15a7dcf8dba930f67401f4c1c8ca2e6fac
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:09 2012 -0700

    glx/dri2: Enable GLX_ARB_create_context_robustness
    
    If the driver supports __DRI2_ROBUSTNESS, then enable
    GLX_ARB_create_cotnext_robustness as well.  If robustness values are
    passed to glXCreateContextAttribsARB and the driver doesn't support
    __DRI2_ROBUSTNESS, existing drivers will already generate the correct
    error values (so that the correct GLX errors are generated).
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 8210a2b..1e99179 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -59,6 +59,16 @@ typedef struct __GLXDRIscreen __GLXDRIscreen;
 typedef struct __GLXDRIcontext __GLXDRIcontext;
 typedef struct __GLXDRIdrawable __GLXDRIdrawable;
 
+
+#ifdef __DRI2_ROBUSTNESS
+#define ALL_DRI_CTX_FLAGS (__DRI_CTX_FLAG_DEBUG                         \
+                           | __DRI_CTX_FLAG_FORWARD_COMPATIBLE          \
+                           | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS)
+#else
+#define ALL_DRI_CTX_FLAGS (__DRI_CTX_FLAG_DEBUG                         \
+                           | __DRI_CTX_FLAG_FORWARD_COMPATIBLE)
+#endif
+
 struct __GLXDRIscreen {
     __GLXscreen base;
     __DRIscreen *driScreen;
@@ -381,7 +391,7 @@ __glXDRIscreenDestroy(__GLXscreen * baseScreen)
 static Bool
 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                          unsigned *major_ver, unsigned *minor_ver,
-                         uint32_t *flags, int *api, unsigned *error)
+                         uint32_t *flags, int *api, int *reset, unsigned *error)
 {
     unsigned i;
 
@@ -395,6 +405,11 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
 
     *major_ver = 1;
     *minor_ver = 0;
+#ifdef __DRI2_ROBUSTNESS
+    *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
+#else
+    (void) reset;
+#endif
 
     for (i = 0; i < num_attribs; i++) {
         switch (attribs[i * 2]) {
@@ -425,6 +440,26 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                 return False;
             }
             break;
+#ifdef __DRI2_ROBUSTNESS
+        case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB:
+            if (screen->dri2->base.version >= 4) {
+                *error = BadValue;
+                return False;
+            }
+
+            switch (attribs[i * 2 + 1]) {
+            case GLX_NO_RESET_NOTIFICATION_ARB:
+                *reset = __DRI_CTX_RESET_NO_NOTIFICATION;
+                break;
+            case GLX_LOSE_CONTEXT_ON_RESET_ARB:
+                *reset = __DRI_CTX_RESET_LOSE_CONTEXT;
+                break;
+            default:
+                *error = BadValue;
+                return False;
+            }
+            break;
+#endif
         default:
             /* If an unknown attribute is received, fail.
              */
@@ -435,7 +470,7 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
 
     /* Unknown flag value.
      */
-    if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE)) {
+    if ((*flags & ~ALL_DRI_CTX_FLAGS) != 0) {
         *error = BadValue;
         return False;
     }
@@ -473,12 +508,14 @@ create_driver_context(__GLXDRIcontext * context,
         unsigned major_ver;
         unsigned minor_ver;
         uint32_t flags;
+        int reset;
         int api;
 
         if (num_attribs != 0) {
             if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                           &major_ver, &minor_ver,
-                                          &flags, &api, (unsigned *) error))
+                                          &flags, &api, &reset,
+                                          (unsigned *) error))
                 return NULL;
 
             ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
@@ -494,6 +531,14 @@ create_driver_context(__GLXDRIcontext * context,
                  */
                 ctx_attribs[num_ctx_attribs++] = flags;
             }
+
+#ifdef __DRI2_ROBUSTNESS
+            if (reset != __DRI_CTX_NO_RESET_NOTIFICATION) {
+                ctx_attribs[num_ctx_attribs++] =
+                    __DRI_CTX_ATTRIB_RESET_NOTIFICATION;
+                ctx_attribs[num_ctx_attribs++] = reset;
+            }
+#endif
         }
 
         context->driContext =
@@ -857,6 +902,16 @@ initializeExtensions(__GLXDRIscreen * screen)
         }
 #endif
 
+#ifdef __DRI2_ROBUSTNESS
+        if (strcmp(extensions[i]->name, __DRI2_ROBUSTNESS) == 0 &&
+            screen->dri2->base.version >= 3) {
+            __glXEnableExtension(screen->glx_enable_bits,
+                                 "GLX_ARB_create_context_robustness");
+            LogMessage(X_INFO,
+                       "AIGLX: enabled GLX_ARB_create_context_robustness\n");
+        }
+#endif
+
         /* Ignore unknown extensions */
     }
 }
commit 90aa2486e394c0344aceb2a70432761665a79333
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:08 2012 -0700

    glx: Allow attributes and flags from GLX_ARB_create_context_robustness
    
    The assumtion is that if the underlying provider (e.g., glxdri2.c) doesn't
    support this extension, it will generate BadMatch for these flags and
    attributes.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 7d653e9..13d21cc 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -30,7 +30,8 @@
 #include "indirect_dispatch.h"
 
 #define ALL_VALID_FLAGS \
-    (GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB)
+    (GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB \
+     | GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB)
 
 static Bool
 validate_GL_version(int major_version, int minor_version)
@@ -183,6 +184,14 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
             profile = attribs[2 * i + 1];
             break;
 
+        case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB:
+            reset = attribs[2 * i + 1];
+            if (reset != GLX_NO_RESET_NOTIFICATION_ARB
+                && reset != GLX_LOSE_CONTEXT_ON_RESET_ARB)
+                return BadValue;
+
+            break;
+
         default:
             return BadValue;
         }
commit aef0b4593e165634ca7fa0745882dad12a54ebed
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:07 2012 -0700

    glx: Track the reset notification strategy for a context
    
    Also require that the reset notification for a new context and the other
    context in the share group match.  There isn't yet any way to specify a
    non-default reset notification strategy, but that will come.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 205a919..7d653e9 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -90,6 +90,13 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     __GLXconfig *config;
     int err;
 
+    /* The GLX_ARB_create_context_robustness spec says:
+     *
+     *     "The default value for GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB
+     *     is GLX_NO_RESET_NOTIFICATION_ARB."
+     */
+    int reset = GLX_NO_RESET_NOTIFICATION_ARB;
+
     /* The GLX_ARB_create_context_profile spec says:
      *
      *     "The default value for GLX_CONTEXT_PROFILE_MASK_ARB is
@@ -259,6 +266,14 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
         return __glXError(GLXBadProfileARB);
     }
 
+    /* The GLX_ARB_create_context_robustness spec says:
+     *
+     *     "* If the reset notification behavior of <share_context> and the
+     *        newly created context are different, BadMatch is generated."
+     */
+    if (shareCtx != NULL && shareCtx->resetNotificationStrategy != reset)
+        return BadMatch;
+
     /* There is no GLX protocol for desktop OpenGL versions after 1.4.  There
      * is no GLX protocol for any version of OpenGL ES.  If the application is
      * requested an indirect rendering context for a version that cannot be
@@ -306,6 +321,7 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     ctx->selectBufSize = 0;
     ctx->drawPriv = NULL;
     ctx->readPriv = NULL;
+    ctx->resetNotificationStrategy = reset;
 
     /* Add the new context to the various global tables of GLX contexts.
      */
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index d483bbf..d054219 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -308,6 +308,16 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
     glxc->drawPriv = NULL;
     glxc->readPriv = NULL;
 
+    /* The GLX_ARB_create_context_robustness spec says:
+     *
+     *     "The default value for GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB
+     *     is GLX_NO_RESET_NOTIFICATION_ARB."
+     *
+     * Without using glXCreateContextAttribsARB, there is no way to specify a
+     * non-default reset notification strategy.
+     */
+    glxc->resetNotificationStrategy = GLX_NO_RESET_NOTIFICATION_ARB;
+
     /* Add the new context to the various global tables of GLX contexts.
      */
     if (!__glXAddContext(glxc)) {
diff --git a/glx/glxcontext.h b/glx/glxcontext.h
index b803a7f..4764e56 100644
--- a/glx/glxcontext.h
+++ b/glx/glxcontext.h
@@ -104,6 +104,11 @@ struct __GLXcontext {
      */
     GLenum renderMode;
 
+    /**
+     * Reset notification strategy used when a GPU reset occurs.
+     */
+    GLenum resetNotificationStrategy;
+
     /*
      ** Buffers for feedback and selection.
      */
commit f8198285cfc4704bc4d56922e5a2e99030a83778
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:06 2012 -0700

    glx: Add extension string tracking for GLX_ARB_create_context_robustness
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/extension_string.c b/glx/extension_string.c
index 2d550a9..ee9864e 100644
--- a/glx/extension_string.c
+++ b/glx/extension_string.c
@@ -70,6 +70,7 @@ static const struct extension_info known_glx_extensions[] = {
     /* *INDENT-OFF* */
     { GLX(ARB_create_context),          VER(0,0), N, },
     { GLX(ARB_create_context_profile),  VER(0,0), N, },
+    { GLX(ARB_create_context_robustness), VER(0,0), N, },
     { GLX(ARB_multisample),             VER(1,4), Y, },
 
     { GLX(EXT_create_context_es2_profile), VER(0,0), N, },
diff --git a/glx/extension_string.h b/glx/extension_string.h
index 1704696..7a4a8b1 100644
--- a/glx/extension_string.h
+++ b/glx/extension_string.h
@@ -38,6 +38,7 @@ enum {
 /*   GLX_ARB_get_proc_address is implemented on the client. */
     ARB_create_context_bit = 0,
     ARB_create_context_profile_bit,
+    ARB_create_context_robustness_bit,
     ARB_multisample_bit,
     EXT_create_context_es2_profile_bit,
     EXT_import_context_bit,
commit 4ffbc984eac8a15925094614021de30dc8084e65
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:05 2012 -0700

    glx: Reject creations of indirect contexts with unsupportable versions.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 2ba0e18..205a919 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -259,6 +259,23 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
         return __glXError(GLXBadProfileARB);
     }
 
+    /* There is no GLX protocol for desktop OpenGL versions after 1.4.  There
+     * is no GLX protocol for any version of OpenGL ES.  If the application is
+     * requested an indirect rendering context for a version that cannot be
+     * satisfied, reject it.
+     *
+     * The GLX_ARB_create_context spec says:
+     *
+     *     "* If <config> does not support compatible OpenGL contexts
+     *        providing the requested API major and minor version,
+     *        forward-compatible flag, and debug context flag, GLXBadFBConfig
+     *        is generated."
+     */
+    if (!req->isDirect && (major_version > 1 || minor_version > 4
+                           || profile == GLX_CONTEXT_ES2_PROFILE_BIT_EXT)) {
+        return __glXError(GLXBadFBConfig);
+    }
+
     /* Allocate memory for the new context
      */
     if (req->isDirect) {
commit 41d5120eaf2bdf308eb904cac9b5027b003fea8d
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:04 2012 -0700

    glx: Implement GLX_EXT_create_context_es2_profile
    
    This patch builds on the infrastucture put in place for
    GLX_ARB_create_context_profile.  If GLX_CONTEXT_ES2_PROFILE_BIT_EXT is
    specified and the requested version is 2.0, create a context with the
    __DRI_API_GLES2 API.
    
    This change assumes that any DRI2 driver can handle (possibly by saying "no
    seeing an API setting other than __DRI_API_OPENGL or __DRI_API_OPENGL_CORE.
    This allows enabling the extension any time GLX_ARB_create_context (and
    GLX_ARB_create_context_profile) is enabled.
    
    v2: Clean up some comments.  Note that our behavior for
    GLX_CONTEXT_ES2_PROFILE_BIT_EXT w/version != 2.0 matches NVIDIA's.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 6f580f0..2ba0e18 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -229,6 +229,32 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
     case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
         break;
+    case GLX_CONTEXT_ES2_PROFILE_BIT_EXT:
+        /* The GLX_EXT_create_context_es2_profile spec says:
+         *
+         *     "... If the version requested is 2.0, and the
+         *     GLX_CONTEXT_ES2_PROFILE_BIT_EXT bit is set in the
+         *     GLX_CONTEXT_PROFILE_MASK_ARB attribute (see below), then the
+         *     context returned will implement OpenGL ES 2.0."
+         *
+         * It also says:
+         *
+         *     "* If attribute GLX_CONTEXT_PROFILE_MASK_ARB has no bits set;
+         *        has any bits set other than
+         *        GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
+         *        GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, or
+         *        GLX_CONTEXT_ES2_PROFILE_BIT_EXT; has more than one of these
+         *        bits set; or if the implementation does not supported the
+         *        requested profile, then GLXBadProfileARB is generated."
+         *
+         * It does not specifically say what is supposed to happen if
+         * GLX_CONTEXT_ES2_PROFILE_BIT_EXT is set but the version requested is
+         * not 2.0.  We choose to generate GLXBadProfileARB as this matches
+         * NVIDIA's behavior.
+         */
+        if (major_version != 2 || minor_version != 0)
+            return __glXError(GLXBadProfileARB);
+        break;
     default:
         return __glXError(GLXBadProfileARB);
     }
diff --git a/glx/extension_string.c b/glx/extension_string.c
index 6a1a6c6..2d550a9 100644
--- a/glx/extension_string.c
+++ b/glx/extension_string.c
@@ -72,6 +72,7 @@ static const struct extension_info known_glx_extensions[] = {
     { GLX(ARB_create_context_profile),  VER(0,0), N, },
     { GLX(ARB_multisample),             VER(1,4), Y, },
 
+    { GLX(EXT_create_context_es2_profile), VER(0,0), N, },
     { GLX(EXT_import_context),          VER(0,0), Y, },
     { GLX(EXT_texture_from_pixmap),     VER(0,0), Y, },
     { GLX(EXT_visual_info),             VER(0,0), Y, },
diff --git a/glx/extension_string.h b/glx/extension_string.h
index 947bf89..1704696 100644
--- a/glx/extension_string.h
+++ b/glx/extension_string.h
@@ -39,6 +39,7 @@ enum {
     ARB_create_context_bit = 0,
     ARB_create_context_profile_bit,
     ARB_multisample_bit,
+    EXT_create_context_es2_profile_bit,
     EXT_import_context_bit,
     EXT_texture_from_pixmap_bit,
     EXT_visual_info_bit,
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 7ec4337..8210a2b 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -417,6 +417,9 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
             case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
                 *api = __DRI_API_OPENGL;
                 break;
+            case GLX_CONTEXT_ES2_PROFILE_BIT_EXT:
+                *api = __DRI_API_GLES2;
+                break;
             default:
                 *error = __glXError(GLXBadProfileARB);
                 return False;
@@ -812,8 +815,12 @@ initializeExtensions(__GLXDRIscreen * screen)
                              "GLX_ARB_create_context");
         __glXEnableExtension(screen->glx_enable_bits,
                              "GLX_ARB_create_context_profile");
+        __glXEnableExtension(screen->glx_enable_bits,
+                             "GLX_EXT_create_context_es2_profile");
         LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context\n");
         LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context_profile\n");
+        LogMessage(X_INFO,
+                   "AIGLX: enabled GLX_EXT_create_context_es2_profile\n");
     }
 #endif
 
commit cef0b808d3152a20cd98d32457dde08bd5434e7c
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:03 2012 -0700

    glx: Implement GLX_ARB_create_context_profile
    
    Most of the infrastructure was already in place.  This just adds:
    
        * Validate values specified with the GLX_CONTEXT_PROFILE_MASK_ARB
          attribute.
    
        * Select a DRI2 "api" based on the setting of
          GLX_CONTEXT_PROFILE_MASK_ARB.
    
        * Enable GLX_ARB_create_context_profile extension.
    
    This change assumes that any DRI2 driver can handle (possibly by saying "no")
    seeing an API setting other than __DRI_API_OPENGL.  This allows enabling this
    extension any time GLX_ARB_create_context is enabled.
    
    Also, the validation code in __glXDisp_CreateContextAttribsARB is structured
    in a very verbose manner (using a switch-statement) to ease the addition of
    GLX_EXT_create_context_es2_profile.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 025c423..6f580f0 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -90,6 +90,17 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     __GLXconfig *config;
     int err;
 
+    /* The GLX_ARB_create_context_profile spec says:
+     *
+     *     "The default value for GLX_CONTEXT_PROFILE_MASK_ARB is
+     *     GLX_CONTEXT_CORE_PROFILE_BIT_ARB."
+     *
+     * The core profile only makes sense for OpenGL versions 3.2 and later.
+     * If the version ultimately specified is less than 3.2, the core profile
+     * bit is cleared (see below).
+     */
+    int profile = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
+
     /* Verify that the size of the packet matches the size inferred from the
      * sizes specified for the various fields.
      */
@@ -161,6 +172,10 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
             render_type = attribs[2 * i + 1];
             break;
 
+        case GLX_CONTEXT_PROFILE_MASK_ARB:
+            profile = attribs[2 * i + 1];
+            break;
+
         default:
             return BadValue;
         }
@@ -202,6 +217,22 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
     if ((flags & ~ALL_VALID_FLAGS) != 0)
         return BadValue;
 
+    /* The GLX_ARB_create_context_profile spec says:
+     *
+     *     "* If attribute GLX_CONTEXT_PROFILE_MASK_ARB has no bits set; has
+     *        any bits set other than GLX_CONTEXT_CORE_PROFILE_BIT_ARB and
+     *        GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; has more than one of
+     *        these bits set; or if the implementation does not support the
+     *        requested profile, then GLXBadProfileARB is generated."
+     */
+    switch (profile) {
+    case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
+    case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
+        break;
+    default:
+        return __glXError(GLXBadProfileARB);
+    }
+
     /* Allocate memory for the new context
      */
     if (req->isDirect) {
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 7b76c3a..7ec4337 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -381,7 +381,7 @@ __glXDRIscreenDestroy(__GLXscreen * baseScreen)
 static Bool
 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
                          unsigned *major_ver, unsigned *minor_ver,
-                         uint32_t *flags, unsigned *error)
+                         uint32_t *flags, int *api, unsigned *error)
 {
     unsigned i;
 
@@ -409,6 +409,19 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
             break;
         case GLX_RENDER_TYPE:
             break;
+        case GLX_CONTEXT_PROFILE_MASK_ARB:
+            switch (attribs[i * 2 + 1]) {
+            case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
+                *api = __DRI_API_OPENGL_CORE;
+                break;
+            case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
+                *api = __DRI_API_OPENGL;
+                break;
+            default:
+                *error = __glXError(GLXBadProfileARB);
+                return False;
+            }
+            break;
         default:
             /* If an unknown attribute is received, fail.
              */
@@ -424,6 +437,16 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
         return False;
     }
 
+    /* If the core profile is requested for a GL version is less than 3.2,
+     * request the non-core profile from the DRI driver.  The core profile
+     * only makes sense for GL versions >= 3.2, and many DRI drivers that
+     * don't support OpenGL 3.2 may fail the request for a core profile.
+     */
+    if (*api == __DRI_API_OPENGL_CORE
+        && (*major_ver < 3 || (*major_ver < 3 && *minor_ver < 2))) {
+        *api == __DRI_API_OPENGL;
+    }
+
     *error = Success;
     return True;
 }
@@ -447,11 +470,12 @@ create_driver_context(__GLXDRIcontext * context,
         unsigned major_ver;
         unsigned minor_ver;
         uint32_t flags;
+        int api;
 
         if (num_attribs != 0) {
             if (!dri2_convert_glx_attribs(num_attribs, attribs,
                                           &major_ver, &minor_ver,
-                                          &flags, (unsigned *) error))
+                                          &flags, &api, (unsigned *) error))
                 return NULL;
 
             ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
@@ -471,7 +495,7 @@ create_driver_context(__GLXDRIcontext * context,
 
         context->driContext =
             (*screen->dri2->createContextAttribs)(screen->driScreen,
-                                                  __DRI_API_OPENGL,
+                                                  api,
                                                   config->driConfig,
                                                   driShare,
                                                   num_ctx_attribs / 2,
@@ -786,7 +810,10 @@ initializeExtensions(__GLXDRIscreen * screen)
     if (screen->dri2->base.version >= 3) {
         __glXEnableExtension(screen->glx_enable_bits,
                              "GLX_ARB_create_context");
+        __glXEnableExtension(screen->glx_enable_bits,
+                             "GLX_ARB_create_context_profile");
         LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context\n");
+        LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context_profile\n");
     }
 #endif
 
commit 09a8a169d5929665778ae33e58e345fe1192b64c
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:02 2012 -0700

    glx: Implement GLX SetClientInfo2ARB protocol
    
    The protocol is almost identical to SetClientInfoARB.  The only
    difference is the GL versions include an extra 4 bytes for the supported
    profile.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/clientinfo.c b/glx/clientinfo.c
index b26ac1a..4aaa4c9 100644
--- a/glx/clientinfo.c
+++ b/glx/clientinfo.c
@@ -29,10 +29,10 @@
 #include "glxbyteorder.h"
 #include "unpack.h"
 
-int
-__glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
+static int
+set_client_info(__GLXclientState * cl, xGLXSetClientInfoARBReq * req,
+                unsigned bytes_per_version)
 {
-    xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
     char *gl_extensions;
     char *glx_extensions;
 
@@ -40,7 +40,7 @@ __glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
      * sizes specified for the various fields.
      */
     const unsigned expected_size = sz_xGLXSetClientInfoARBReq
-        + (req->numVersions * 8)
+        + (req->numVersions * bytes_per_version)
         + __GLX_PAD(req->numGLExtensionBytes)
         + __GLX_PAD(req->numGLXExtensionBytes);
 
@@ -50,7 +50,7 @@ __glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
     /* Verify that the actual length of the GL extension string matches what's
      * encoded in protocol packet.
      */
-    gl_extensions = (char *) (req + 1) + (req->numVersions * 8);
+    gl_extensions = (char *) (req + 1) + (req->numVersions * bytes_per_version);
     if (req->numGLExtensionBytes != 0
         && memchr(gl_extensions, 0,
                   __GLX_PAD(req->numGLExtensionBytes)) == NULL)
@@ -72,6 +72,12 @@ __glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
 }
 
 int
+__glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
+{
+    return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 8);
+}
+
+int
 __glXDispSwap_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
 {
     xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
@@ -87,11 +93,18 @@ __glXDispSwap_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc)
 {
-    return BadRequest;
+    return set_client_info(cl, (xGLXSetClientInfoARBReq *) pc, 12);
 }
 
 int
 __glXDispSwap_SetClientInfo2ARB(__GLXclientState * cl, GLbyte * pc)
 {
-    return BadRequest;
+    xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
+
+    req->length = bswap_16(req->length);
+    req->numVersions = bswap_32(req->numVersions);
+    req->numGLExtensionBytes = bswap_32(req->numGLExtensionBytes);
+    req->numGLXExtensionBytes = bswap_32(req->numGLXExtensionBytes);
+
+    return __glXDisp_SetClientInfo2ARB(cl, pc);
 }
commit 167993254a5cbe11a1f44fad1e8ae042089c1619
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Jul 5 16:17:56 2012 +1000

    list.h: don't crash when removing an element from a NULL list
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/list.h b/include/list.h
index 96c0bcb..d54a207 100644
--- a/include/list.h
+++ b/include/list.h
@@ -453,7 +453,7 @@ xorg_list_is_empty(struct xorg_list *head)
 #define nt_list_del(_entry, _list, _type, _member)		\
 	do {							\
 		_type *__e = _entry;				\
-		if (__e == NULL) break;				\
+		if (__e == NULL || _list == NULL) break;        \
 		if ((_list) == __e) {				\
 		    _list = __e->_member;			\
 		} else {					\
commit 8aa6d49d46dacc31a85023d0159c1fb67401df73
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Wed Jul 4 15:21:01 2012 -0700

    glx: Don't request prototypes for GL extension functions
    
    The server does not want GL extension prototypes.  It never links with
    anything that could possibly provide implementations of these functions.  It
    *is* the provide, and it does not provde these symbols.  All this does is
    create hundreds of warnings like:
    
    incude/GL/glext.h:5570:45: warning: redundant redeclaration of 'glMultTransposeMatrixd' [-Wredundant-decls]
    include/GL/gl.h:1940:45: note: previous declaration of 'glMultTransposeMatrixd' was here
    
    I believe this was necessary back before the AIGLX days, but that was a long,
    long time ago.  The warnings recently showed up with the addition of
    -Wredundant-decls to the CWARNFLAGS.
    
    v2: Update the commit message, no code changes.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Cc: Adam Jackson <ajax at redhat.com>
    Cc: Dave Airlie <airlied at redhat.com>
    Acked-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxserver.h b/glx/glxserver.h
index 87c94d9..24e3d62 100644
--- a/glx/glxserver.h
+++ b/glx/glxserver.h
@@ -46,7 +46,6 @@
 #include <resource.h>
 #include <scrnintstr.h>
 
-#define GL_GLEXT_PROTOTYPES     /* we want prototypes */
 #include <GL/gl.h>
 #include <GL/glxproto.h>
 
commit 258abbf823f753757e4dddc13ef495f4024680db
Author: Michal Srb <msrb at suse.com>
Date:   Thu Jun 28 17:17:12 2012 +0200

    Look for ModuleData only in appropriate library
    
    LoaderSymbol calls dlsym with RTLD_DEFAULT pseudo handle making it search in
    every loaded library. In addition glibc adds NODELETE flag to the library
    containing the symbol.
    
    It's used in doLoadModule to locate <modulename>ModuleData symbol, the
    module's library gets the flag and is kept in memory even after it is
    unloaded.
    
    This patch adds LoaderSymbolFromModule function that looks for symbol only in
    library specified by handle. That way the NODELETE flag isn't added.
    
    This glibc behavior doesn't seem to be documented, but even if other
    implementations differ, there is no reason to search ModuleData symbol outside
    the module's library.
    
    Signed-off-by: Michal Srb <msrb at suse.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    
    v2: Switch LoaderSymbolFromModule arguments order.
        Correct description.
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index edaefb8..5fbea38 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -160,6 +160,12 @@ LoaderSymbol(const char *name)
     return NULL;
 }
 
+void *
+LoaderSymbolFromModule(void *handle, const char *name)
+{
+    return dlsym(handle, name);
+}
+
 void
 LoaderUnload(const char *name, void *handle)
 {
diff --git a/hw/xfree86/loader/loader.h b/hw/xfree86/loader/loader.h
index 5cadd5a..c89c641 100644
--- a/hw/xfree86/loader/loader.h
+++ b/hw/xfree86/loader/loader.h
@@ -72,5 +72,6 @@ extern unsigned long LoaderOptions;
 
 /* Internal Functions */
 void *LoaderOpen(const char *, int *, int *);
+void *LoaderSymbolFromModule(void *, const char *);
 
 #endif                          /* _LOADER_H */
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 72020a5..dd20573 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -956,7 +956,7 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
             *errmin = 0;
         goto LoadModule_fail;
     }
-    initdata = LoaderSymbol(p);
+    initdata = LoaderSymbolFromModule(ret->handle, p);
     if (initdata) {
         ModuleSetupProc setup;
         ModuleTearDownProc teardown;
commit d84f0f823eeeecdf0498aadd3fbb1d11dabc0837
Merge: 12bfb4c d04dfe3
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jul 4 21:23:48 2012 +1000

    Merge branch 'sigio-vt-switch-issues' into for-keith
    
    Conflicts:
    	test/Makefile.am
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --cc test/Makefile.am
index e5b25c9,436351c..15c51ed
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@@ -5,7 -5,7 +5,7 @@@ if XOR
  # Tests that require at least some DDX functions in order to fully link
  # For now, requires xf86 ddx, could be adjusted to use another
  SUBDIRS += xi2
- noinst_PROGRAMS += xkb input xtest misc fixes xfree86 hashtabletest signal-logging
 -noinst_PROGRAMS += xkb input xtest misc fixes xfree86  hashtabletest os
++noinst_PROGRAMS += xkb input xtest misc fixes xfree86 hashtabletest os signal-logging
  endif
  check_LTLIBRARIES = libxservertest.la
  
@@@ -36,8 -36,8 +36,9 @@@ misc_LDADD=$(TEST_LDADD
  fixes_LDADD=$(TEST_LDADD)
  xfree86_LDADD=$(TEST_LDADD)
  touch_LDADD=$(TEST_LDADD)
 +signal_logging_LDADD=$(TEST_LDADD)
  hashtabletest_LDADD=$(TEST_LDADD) $(top_srcdir)/Xext/hashtable.c
+ os_LDADD=$(TEST_LDADD)
  
  libxservertest_la_LIBADD = $(XSERVER_LIBS)
  if XORG
commit 12bfb4cf1bebb66d2c2eb76b93c18a2915b865e5
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Jun 26 09:19:33 2012 +1000

    Xi: extend PropagateMask to EMASKSIZE
    
    Number of devices is 2 + MAXDEVICES, with index 0 and 1 reserved for
    XIAll{Master}Devices. At the current size, PropagateMask would be overrun in
    RecalculateDeviceDeliverableEvents().
    
    Found by Coverity.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/Xi/extinit.c b/Xi/extinit.c
index 494e887..94f46f7 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -365,7 +365,7 @@ RESTYPE RT_INPUTCLIENT;
 
 extern XExtensionVersion XIVersion;
 
-Mask PropagateMask[MAXDEVICES];
+Mask PropagateMask[EMASKSIZE];
 
 /*****************************************************************
  *
commit a9c09f8f8e2a97e4bfe927bc4c7f29b04ee3403a
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jun 25 14:24:11 2012 +1000

    dix: fix memory leak in TouchEventHistoryReplay
    
    Don't leak if ti->history is NULL.
    
    Found by coverity.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/touch.c b/dix/touch.c
index 06b15ef..497ad7d 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -463,14 +463,17 @@ TouchEventHistoryPush(TouchPointInfoPtr ti, const DeviceEvent *ev)
 void
 TouchEventHistoryReplay(TouchPointInfoPtr ti, DeviceIntPtr dev, XID resource)
 {
-    InternalEvent *tel = InitEventList(GetMaximumEventsNum());
-    ValuatorMask *mask = valuator_mask_new(0);
+    InternalEvent *tel;
+    ValuatorMask *mask;
     int i, nev;
     int flags;
 
     if (!ti->history)
         return;
 
+    tel = InitEventList(GetMaximumEventsNum());
+    mask = valuator_mask_new(0);
+
     valuator_mask_set_double(mask, 0, ti->history[0].valuators.data[0]);
     valuator_mask_set_double(mask, 1, ti->history[0].valuators.data[1]);
 
commit 55ff20eb37f00a3ad07b5acff19d4497ab513a97
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jun 25 14:22:31 2012 +1000

    dix: fix dereference before null check
    
    Found by Coverity.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/dix/touch.c b/dix/touch.c
index a01f152..06b15ef 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -160,11 +160,13 @@ TouchBeginDDXTouch(DeviceIntPtr dev, uint32_t ddx_id)
     int i;
     TouchClassPtr t = dev->touch;
     DDXTouchPointInfoPtr ti = NULL;
-    Bool emulate_pointer = (t->mode == XIDirectTouch);
+    Bool emulate_pointer;
 
     if (!t)
         return NULL;
 
+    emulate_pointer = (t->mode == XIDirectTouch);
+
     /* Look for another active touchpoint with the same DDX ID. DDX
      * touchpoints must be unique. */
     if (TouchFindByDDXID(dev, ddx_id, FALSE))
commit e3f47be9fbc489e3eb5832445924810b2ff300f7
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Oct 24 10:01:26 2011 +1000

    xfree86: fix use-after-free issue in checkInput
    
    *dev is the condition of the while loop we're in, reset to NULL after
    freeing
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index b22b617..3ec40fe 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -2329,6 +2329,7 @@ checkInput(serverLayoutPtr layout, Bool implicit_layout)
 
                 current = dev;
                 free(*dev);
+                *dev = NULL;
 
                 do {
                     *current = *(current + 1);
commit 252a69b592001b34714d0fe7508e1898883f9d01
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jun 20 14:25:54 2012 +1000

    xkb: use local variable instead of casting arg
    
    No functional changes.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index fe28e12..082c0db 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -281,12 +281,12 @@ AccessXStickyKeysTurnOff(DeviceIntPtr dev, xkbControlsNotify * pCN)
 static CARD32
 AccessXKRGExpire(OsTimerPtr timer, CARD32 now, pointer arg)
 {
-    XkbSrvInfoPtr xkbi = ((DeviceIntPtr) arg)->key->xkbInfo;
     xkbControlsNotify cn;
+    DeviceIntPtr dev = arg;
+    XkbSrvInfoPtr xkbi = dev->key->xkbInfo;
 
     if (xkbi->krgTimerActive == _KRG_WARN_TIMER) {
-        XkbDDXAccessXBeep((DeviceIntPtr) arg, _BEEP_SLOW_WARN,
-                          XkbStickyKeysMask);
+        XkbDDXAccessXBeep(dev, _BEEP_SLOW_WARN, XkbStickyKeysMask);
         xkbi->krgTimerActive = _KRG_TIMER;
         return 4000;
     }
@@ -296,11 +296,11 @@ AccessXKRGExpire(OsTimerPtr timer, CARD32 now, pointer arg)
     cn.requestMajor = 0;
     cn.requestMinor = 0;
     if (xkbi->desc->ctrls->enabled_ctrls & XkbSlowKeysMask) {
-        AccessXKRGTurnOff((DeviceIntPtr) arg, &cn);
+        AccessXKRGTurnOff(dev, &cn);
         LogMessage(X_INFO, "XKB SlowKeys are disabled.\n");
     }
     else {
-        AccessXKRGTurnOn((DeviceIntPtr) arg, XkbSlowKeysMask, &cn);
+        AccessXKRGTurnOn(dev, XkbSlowKeysMask, &cn);
         LogMessage(X_INFO, "XKB SlowKeys are now enabled. Hold shift to disable.\n");
     }
 
commit d04dfe3f754ad3a5f158057175cbd44319c1ae51
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jun 22 15:18:53 2012 +1000

    Drop custom sigio block/unblock functions from kdrive, ephyr and dmx
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/dmx/input/dmxevents.c b/hw/dmx/input/dmxevents.c
index f734808..2875620 100644
--- a/hw/dmx/input/dmxevents.c
+++ b/hw/dmx/input/dmxevents.c
@@ -227,25 +227,25 @@ dmxCoreMotion(DevicePtr pDev, int x, int y, int delta, DMXBlockType block)
             && pScreen->myNum == dmxScreen->index) {
             /* Screen is old screen */
             if (block)
-                dmxSigioBlock();
+                OsBlockSIGIO();
             if (pDev)
                 enqueueMotion(pDev, localX, localY);
             if (block)
-                dmxSigioUnblock();
+                OsReleaseSIGIO();
         }
         else {
             /* Screen is new */
             DMXDBG4("   New screen: old=%d new=%d localX=%d localY=%d\n",
                     pScreen->myNum, dmxScreen->index, localX, localY);
             if (block)
-                dmxSigioBlock();
+                OsBlockSIGIO();
             mieqProcessInputEvents();
             miPointerSetScreen(inputInfo.pointer, dmxScreen->index,
                                localX, localY);
             if (pDev)
                 enqueueMotion(pDev, localX, localY);
             if (block)
-                dmxSigioUnblock();
+                OsReleaseSIGIO();
         }
 #if 00
         miPointerGetPosition(inputInfo.pointer, &localX, &localY);
@@ -387,12 +387,12 @@ dmxExtMotion(DMXLocalInputInfoPtr dmxLocal,
     }
 
     if (block)
-        dmxSigioBlock();
+        OsBlockSIGIO();
     valuator_mask_set_range(&mask, firstAxis, axesCount, v);
     QueuePointerEvents(pDevice, MotionNotify, 0, POINTER_ABSOLUTE, &mask);
 
     if (block)
-        dmxSigioUnblock();
+        OsReleaseSIGIO();
 }
 
 static int
@@ -492,10 +492,10 @@ dmxTranslateAndEnqueueExtEvent(DMXLocalInputInfoPtr dmxLocal,
         valuator_mask_set_range(&mask, ke->first_axis, ke->axes_count,
                                 valuators);
         if (block)
-            dmxSigioBlock();
+            OsBlockSIGIO();
         QueueKeyboardEvents(pDevice, event, ke->keycode, &mask);
         if (block)
-            dmxSigioUnblock();
+            OsReleaseSIGIO();
         break;
     case XI_DeviceButtonPress:
     case XI_DeviceButtonRelease:
@@ -503,11 +503,11 @@ dmxTranslateAndEnqueueExtEvent(DMXLocalInputInfoPtr dmxLocal,
         valuator_mask_set_range(&mask, ke->first_axis, ke->axes_count,
                                 valuators);
         if (block)
-            dmxSigioBlock();
+            OsBlockSIGIO();
         QueuePointerEvents(pDevice, event, ke->keycode,
                            POINTER_ABSOLUTE, &mask);
         if (block)
-            dmxSigioUnblock();
+            OsReleaseSIGIO();
         break;
     case XI_ProximityIn:
     case XI_ProximityOut:
@@ -515,10 +515,10 @@ dmxTranslateAndEnqueueExtEvent(DMXLocalInputInfoPtr dmxLocal,
         valuator_mask_set_range(&mask, ke->first_axis, ke->axes_count,
                                 valuators);
         if (block)
-            dmxSigioBlock();
+            OsBlockSIGIO();
         QueueProximityEvents(pDevice, event, &mask);
         if (block)
-            dmxSigioUnblock();
+            OsReleaseSIGIO();
         break;
 
         break;
diff --git a/hw/dmx/input/dmxsigio.c b/hw/dmx/input/dmxsigio.c
index 9b1b493..6ef543c 100644
--- a/hw/dmx/input/dmxsigio.c
+++ b/hw/dmx/input/dmxsigio.c
@@ -84,28 +84,6 @@ dmxSigioHandler(int sig)
     }
 }
 
-/** Block SIGIO handling. */
-void
-dmxSigioBlock(void)
-{
-    sigset_t s;
-
-    sigemptyset(&s);
-    sigaddset(&s, SIGIO);
-    sigprocmask(SIG_BLOCK, &s, 0);
-}
-
-/** Unblock SIGIO handling. */
-void
-dmxSigioUnblock(void)
-{
-    sigset_t s;
-
-    sigemptyset(&s);
-    sigaddset(&s, SIGIO);
-    sigprocmask(SIG_UNBLOCK, &s, 0);
-}
-
 static void
 dmxSigioHook(void)
 {
diff --git a/hw/dmx/input/dmxsigio.h b/hw/dmx/input/dmxsigio.h
index 4e48749..9f30662 100644
--- a/hw/dmx/input/dmxsigio.h
+++ b/hw/dmx/input/dmxsigio.h
@@ -36,8 +36,6 @@
 
 #ifndef _DMXSIGIO_H_
 #define _DMXSIGIO_H_
-extern void dmxSigioBlock(void);
-extern void dmxSigioUnblock(void);
 extern void dmxSigioEnableInput(void);
 extern void dmxSigioDisableInput(void);
 extern void dmxSigioRegister(DMXInputInfo * dmxInput, int fd);
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 8eda539..fe3dae6 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -772,26 +772,6 @@ ephyrUpdateModifierState(unsigned int state)
     }
 }
 
-static void
-ephyrBlockSigio(void)
-{
-    sigset_t set;
-
-    sigemptyset(&set);
-    sigaddset(&set, SIGIO);
-    sigprocmask(SIG_BLOCK, &set, 0);
-}
-
-static void
-ephyrUnblockSigio(void)
-{
-    sigset_t set;
-
-    sigemptyset(&set);
-    sigaddset(&set, SIGIO);
-    sigprocmask(SIG_UNBLOCK, &set, 0);
-}
-
 static Bool
 ephyrCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y)
 {
@@ -808,11 +788,11 @@ int ephyrCurScreen;             /*current event screen */
 static void
 ephyrWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
 {
-    ephyrBlockSigio();
+    OsBlockSIGIO();
     ephyrCurScreen = pScreen->myNum;
     miPointerWarpCursor(inputInfo.pointer, pScreen, x, y);
 
-    ephyrUnblockSigio();
+    OsReleaseSIGIO();
 }
 
 miPointerScreenFuncRec ephyrPointerScreenFuncs = {
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 58ae552..000bda9 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -102,26 +102,6 @@ KdSigio(int sig)
         (*kdInputFds[i].read) (kdInputFds[i].fd, kdInputFds[i].closure);
 }
 
-static void
-KdBlockSigio(void)
-{
-    sigset_t set;
-
-    sigemptyset(&set);
-    sigaddset(&set, SIGIO);
-    sigprocmask(SIG_BLOCK, &set, 0);
-}
-
-static void
-KdUnblockSigio(void)
-{
-    sigset_t set;
-
-    sigemptyset(&set);
-    sigaddset(&set, SIGIO);
-    sigprocmask(SIG_UNBLOCK, &set, 0);
-}
-
 #ifdef DEBUG_SIGIO
 
 void
@@ -261,7 +241,7 @@ KdDisableInput(void)
     KdPointerInfo *pi;
     int found = 0, i = 0;
 
-    KdBlockSigio();
+    OsBlockSIGIO();
 
     for (ki = kdKeyboards; ki; ki = ki->next) {
         if (ki->driver && ki->driver->Disable)
@@ -343,7 +323,7 @@ KdEnableInput(void)
     NoticeEventTime(&ev, pi->dixdev);
     NoticeEventTime(&ev, ki->dixdev);
 
-    KdUnblockSigio();
+    OsReleaseSIGIO();
 }
 
 static KdKeyboardDriver *
@@ -1801,7 +1781,7 @@ KdReleaseAllKeys(void)
     int key;
     KdKeyboardInfo *ki;
 
-    KdBlockSigio();
+    OsBlockSIGIO();
 
     for (ki = kdKeyboards; ki; ki = ki->next) {
         for (key = ki->keySyms.minKeyCode; key < ki->keySyms.maxKeyCode; key++) {
@@ -1812,7 +1792,7 @@ KdReleaseAllKeys(void)
         }
     }
 
-    KdUnblockSigio();
+    OsReleaseSIGIO();
 #endif
 }
 
@@ -2009,18 +1989,18 @@ KdWakeupHandler(ScreenPtr pScreen,
     if (kdInputEnabled && result > 0) {
         for (i = 0; i < kdNumInputFds; i++)
             if (FD_ISSET(kdInputFds[i].fd, pReadmask)) {
-                KdBlockSigio();
+                OsBlockSIGIO();
                 (*kdInputFds[i].read) (kdInputFds[i].fd, kdInputFds[i].closure);
-                KdUnblockSigio();
+                OsReleaseSIGIO();
             }
     }
     for (pi = kdPointers; pi; pi = pi->next) {
         if (pi->timeoutPending) {
             if ((long) (GetTimeInMillis() - pi->emulationTimeout) >= 0) {
                 pi->timeoutPending = FALSE;
-                KdBlockSigio();
+                OsBlockSIGIO();
                 KdReceiveTimeout(pi);
-                KdUnblockSigio();
+                OsReleaseSIGIO();
             }
         }
     }
@@ -2117,10 +2097,10 @@ int KdCurScreen;                /* current event screen */
 static void
 KdWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
 {
-    KdBlockSigio();
+    OsBlockSIGIO();
     KdCurScreen = pScreen->myNum;
     miPointerWarpCursor(pDev, pScreen, x, y);
-    KdUnblockSigio();
+    OsReleaseSIGIO();
 }
 
 miPointerScreenFuncRec kdPointerScreenFuncs = {
commit 5d309af2ed93e91c7d72f548a11052051efbb40f
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jun 22 14:56:25 2012 +1000

    xfree86: drop ddx-specific SIGIO blocking
    
    The hooks are left for this cycle, we can drop it next cycle once the
    drivers that need it (e.g. wacom) have been updated.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
index c01cfd1..65a9e82 100644
--- a/hw/xfree86/common/xf86Cursor.c
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -199,7 +199,7 @@ xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode)
     ScrnInfoPtr pScr = xf86ScreenToScrn(pScreen);
     ScreenPtr pCursorScreen;
     Bool Switched;
-    int px, py, was_blocked;
+    int px, py;
     DeviceIntPtr dev, it;
 
     if (!pScr->vtSema || !mode || !pScr->SwitchMode)
@@ -228,7 +228,7 @@ xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode)
     if (pScreen == pCursorScreen)
         miPointerGetPosition(dev, &px, &py);
 
-    was_blocked = xf86BlockSIGIO();
+    OsBlockSIGIO();
     Switched = (*pScr->SwitchMode) (pScr, mode);
     if (Switched) {
         pScr->currentMode = mode;
@@ -267,7 +267,7 @@ xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode)
             pScr->frameY1 = pScr->virtualY - 1;
         }
     }
-    xf86UnblockSIGIO(was_blocked);
+    OsReleaseSIGIO();
 
     if (pScr->AdjustFrame)
         (*pScr->AdjustFrame) (pScr, pScr->frameX0, pScr->frameY0);
@@ -469,13 +469,11 @@ xf86CrossScreen(ScreenPtr pScreen, Bool entering)
 static void
 xf86WarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
 {
-    int sigstate;
-
-    sigstate = xf86BlockSIGIO();
+    OsBlockSIGIO();
     miPointerWarpCursor(pDev, pScreen, x, y);
 
     xf86Info.currentScreen = pScreen;
-    xf86UnblockSIGIO(sigstate);
+    OsReleaseSIGIO();
 }
 
 void *
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 4fcad40..47429ec 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -254,7 +254,7 @@ xf86Wakeup(pointer blockData, int err, pointer pReadmask)
             while (pInfo) {
                 if (pInfo->read_input && pInfo->fd >= 0 &&
                     (FD_ISSET(pInfo->fd, &devicesWithInput) != 0)) {
-                    int sigstate = xf86BlockSIGIO();
+                    OsBlockSIGIO();
 
                     /*
                      * Remove the descriptior from the set because more than one
@@ -263,7 +263,7 @@ xf86Wakeup(pointer blockData, int err, pointer pReadmask)
                     FD_CLR(pInfo->fd, &devicesWithInput);
 
                     pInfo->read_input(pInfo);
-                    xf86UnblockSIGIO(sigstate);
+                    OsReleaseSIGIO();
                 }
                 pInfo = pInfo->next;
             }
@@ -397,9 +397,9 @@ xf86ReleaseKeys(DeviceIntPtr pDev)
     for (i = keyc->xkbInfo->desc->min_key_code;
          i < keyc->xkbInfo->desc->max_key_code; i++) {
         if (key_is_down(pDev, i, KEY_POSTED)) {
-            sigstate = xf86BlockSIGIO();
+            OsBlockSIGIO();
             QueueKeyboardEvents(pDev, KeyRelease, i, NULL);
-            xf86UnblockSIGIO(sigstate);
+            OsReleaseSIGIO();
         }
     }
 }
@@ -457,7 +457,7 @@ xf86VTSwitch(void)
             }
         }
 
-        prevSIGIO = xf86BlockSIGIO();
+        OsBlockSIGIO();
         for (i = 0; i < xf86NumScreens; i++)
             xf86Screens[i]->LeaveVT(xf86Screens[i]);
 
@@ -492,7 +492,7 @@ xf86VTSwitch(void)
             for (ih = InputHandlers; ih; ih = ih->next)
                 xf86EnableInputHandler(ih);
 
-            xf86UnblockSIGIO(prevSIGIO);
+            OsReleaseSIGIO();
 
         }
         else {
@@ -549,7 +549,7 @@ xf86VTSwitch(void)
         for (ih = InputHandlers; ih; ih = ih->next)
             xf86EnableInputHandler(ih);
 
-        xf86UnblockSIGIO(prevSIGIO);
+        OsReleaseSIGIO();
     }
 }
 
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 526b95d..0f8f810 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -394,7 +394,7 @@ InstallSignalHandlers(void)
 void
 InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
 {
-    int i, j, k, scr_index, was_blocked = 0;
+    int i, j, k, scr_index;
     char **modulelist;
     pointer *optionlist;
     Pix24Flags screenpix24, pix24;
@@ -806,7 +806,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
             ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ);
 #endif
             xf86AccessEnter();
-            was_blocked = xf86BlockSIGIO();
+            OsBlockSIGIO();
         }
     }
 
@@ -879,7 +879,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
     }
 
     xf86VGAarbiterWrapFunctions();
-    xf86UnblockSIGIO(was_blocked);
+    OsReleaseSIGIO();
 
     xf86InitOrigins();
 
@@ -964,7 +964,7 @@ OsVendorInit(void)
     }
 #endif
 #endif
-    xf86UnblockSIGIO(0);
+    OsReleaseSIGIO();
 
     beenHere = TRUE;
 }
@@ -1023,7 +1023,7 @@ AbortDDX(enum ExitCode error)
 {
     int i;
 
-    xf86BlockSIGIO();
+    OsBlockSIGIO();
 
     /*
      * try to restore the original video state
diff --git a/hw/xfree86/common/xf86PM.c b/hw/xfree86/common/xf86PM.c
index 1830640..15257cb 100644
--- a/hw/xfree86/common/xf86PM.c
+++ b/hw/xfree86/common/xf86PM.c
@@ -92,8 +92,6 @@ eventName(pmEvent event, const char **str)
     }
 }
 
-static int sigio_blocked_for_suspend;
-
 static void
 suspend(pmEvent event, Bool undo)
 {
@@ -109,7 +107,7 @@ suspend(pmEvent event, Bool undo)
         DisableDevice(pInfo->dev, TRUE);
         pInfo = pInfo->next;
     }
-    sigio_blocked_for_suspend = xf86BlockSIGIO();
+    OsBlockSIGIO();
     for (i = 0; i < xf86NumScreens; i++) {
         if (xf86Screens[i]->PMEvent)
             xf86Screens[i]->PMEvent(xf86Screens[i], event, undo);
@@ -137,7 +135,7 @@ resume(pmEvent event, Bool undo)
             xf86Screens[i]->EnterVT(xf86Screens[i]);
         }
     }
-    xf86UnblockSIGIO(sigio_blocked_for_suspend);
+    OsReleaseSIGIO();
     for (i = 0; i < xf86NumScreens; i++) {
         if (xf86Screens[i]->EnableDisableFBAccess)
             (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE);
@@ -153,7 +151,7 @@ resume(pmEvent event, Bool undo)
 static void
 DoApmEvent(pmEvent event, Bool undo)
 {
-    int i, was_blocked;
+    int i;
 
     switch (event) {
 #if 0
@@ -184,13 +182,13 @@ DoApmEvent(pmEvent event, Bool undo)
         }
         break;
     default:
-        was_blocked = xf86BlockSIGIO();
+        OsBlockSIGIO();
         for (i = 0; i < xf86NumScreens; i++) {
             if (xf86Screens[i]->PMEvent) {
                 xf86Screens[i]->PMEvent(xf86Screens[i], event, undo);
             }
         }
-        xf86UnblockSIGIO(was_blocked);
+        OsReleaseSIGIO();
         break;
     }
 }
diff --git a/hw/xfree86/os-support/shared/sigio.c b/hw/xfree86/os-support/shared/sigio.c
index e9c1c0e..696a215 100644
--- a/hw/xfree86/os-support/shared/sigio.c
+++ b/hw/xfree86/os-support/shared/sigio.c
@@ -132,7 +132,6 @@ xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), void *closure)
     struct sigaction sa;
     struct sigaction osa;
     int i;
-    int blocked;
     int installed = FALSE;
 
     if (!xf86Info.useSIGIO)
@@ -142,7 +141,7 @@ xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), void *closure)
         if (!xf86SigIOFuncs[i].f) {
             if (xf86IsPipe(fd))
                 return 0;
-            blocked = xf86BlockSIGIO();
+            OsBlockSIGIO();
 #ifdef O_ASYNC
             if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC) == -1) {
                 xf86Msg(X_WARNING, "fcntl(%d, O_ASYNC): %s\n",
@@ -170,7 +169,7 @@ xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), void *closure)
             }
 #endif
             if (!installed) {
-                xf86UnblockSIGIO(blocked);
+                OsReleaseSIGIO();
                 return 0;
             }
             sigemptyset(&sa.sa_mask);
@@ -186,7 +185,7 @@ xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), void *closure)
             if (fd >= xf86SigIOMaxFd)
                 xf86SigIOMaxFd = fd + 1;
             FD_SET(fd, &xf86SigIOMask);
-            xf86UnblockSIGIO(blocked);
+            OsReleaseSIGIO();
             return 1;
         }
         /* Allow overwriting of the closure and callback */
commit ff67135bec3ecea8cebeb46b42ece0a6671e231d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jun 22 13:09:35 2012 +1000

    xfree86: use OsBlockSIGIO from the ddx
    
    We can ignore the "wasset" argument now since the DIX will keep proper
    refcounting.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/os-support/shared/sigio.c b/hw/xfree86/os-support/shared/sigio.c
index 12ae8a4..e9c1c0e 100644
--- a/hw/xfree86/os-support/shared/sigio.c
+++ b/hw/xfree86/os-support/shared/sigio.c
@@ -259,26 +259,13 @@ xf86RemoveSIGIOHandler(int fd)
 int
 xf86BlockSIGIO(void)
 {
-    sigset_t set, old;
-    int ret;
-
-    sigemptyset(&set);
-    sigaddset(&set, SIGIO);
-    sigprocmask(SIG_BLOCK, &set, &old);
-    ret = sigismember(&old, SIGIO);
-    return ret;
+    return OsBlockSIGIO();
 }
 
 void
 xf86UnblockSIGIO(int wasset)
 {
-    sigset_t set;
-
-    if (!wasset) {
-        sigemptyset(&set);
-        sigaddset(&set, SIGIO);
-        sigprocmask(SIG_UNBLOCK, &set, NULL);
-    }
+    OsReleaseSIGIO();
 }
 
 void
commit 6bf356ef2831baeccd7a650ed3fde0831e33c6c0
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jun 22 13:02:40 2012 +1000

    os: add OsBlockSIGIO and OsReleaseSIGIO
    
    Let the dix be in charge of changing the sigprocmask so we only have one
    entity that changes it.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/include/os.h b/include/os.h
index 276eb52..8540b82 100644
--- a/include/os.h
+++ b/include/os.h
@@ -333,6 +333,12 @@ OsBlockSignals(void);
 extern _X_EXPORT void
 OsReleaseSignals(void);
 
+extern _X_EXPORT int
+OsBlockSIGIO(void);
+
+extern _X_EXPORT void
+OsReleaseSIGIO(void);
+
 extern _X_EXPORT void
 OsAbort(void)
     _X_NORETURN;
diff --git a/os/utils.c b/os/utils.c
index 3a1ef93..55f58b9 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1165,15 +1165,15 @@ OsBlockSignals(void)
     if (BlockedSignalCount++ == 0) {
         sigset_t set;
 
+#ifdef SIGIO
+        OsBlockSIGIO();
+#endif
         sigemptyset(&set);
         sigaddset(&set, SIGALRM);
         sigaddset(&set, SIGVTALRM);
 #ifdef SIGWINCH
         sigaddset(&set, SIGWINCH);
 #endif
-#ifdef SIGIO
-        sigaddset(&set, SIGIO);
-#endif
         sigaddset(&set, SIGTSTP);
         sigaddset(&set, SIGTTIN);
         sigaddset(&set, SIGTTOU);
@@ -1183,12 +1183,60 @@ OsBlockSignals(void)
 #endif
 }
 
+#ifdef SIG_BLOCK
+static sig_atomic_t sigio_blocked;
+#endif
+
+/**
+ * returns zero if this call caused SIGIO to be blocked now, non-zero if it
+ * was already blocked by a previous call to this function.
+ */
+int
+OsBlockSIGIO(void)
+{
+#ifdef SIGIO
+#ifdef SIG_BLOCK
+    if (sigio_blocked++ == 0) {
+        sigset_t set, old;
+        int ret;
+
+        sigemptyset(&set);
+        sigaddset(&set, SIGIO);
+        sigprocmask(SIG_BLOCK, &set, &old);
+        ret = sigismember(&old, SIGIO);
+        return ret;
+    } else
+        return 1;
+#endif
+#endif
+}
+
+void
+OsReleaseSIGIO(void)
+{
+#ifdef SIGIO
+#ifdef SIG_BLOCK
+    if (--sigio_blocked == 0) {
+        sigset_t set;
+
+        sigemptyset(&set);
+        sigaddset(&set, SIGIO);
+        sigprocmask(SIG_UNBLOCK, &set, NULL);
+    } else if (sigio_blocked < 0) {
+        BUG_WARN(sigio_blocked < 0);
+        sigio_blocked = 0;
+    }
+#endif
+#endif
+}
+
 void
 OsReleaseSignals(void)
 {
 #ifdef SIG_BLOCK
     if (--BlockedSignalCount == 0) {
         sigprocmask(SIG_SETMASK, &PreviousSignalMask, 0);
+        OsReleaseSIGIO();
     }
 #endif
 }
diff --git a/test/Makefile.am b/test/Makefile.am
index b2a53aa..436351c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -5,7 +5,7 @@ if XORG
 # Tests that require at least some DDX functions in order to fully link
 # For now, requires xf86 ddx, could be adjusted to use another
 SUBDIRS += xi2
-noinst_PROGRAMS += xkb input xtest misc fixes xfree86  hashtabletest
+noinst_PROGRAMS += xkb input xtest misc fixes xfree86  hashtabletest os
 endif
 check_LTLIBRARIES = libxservertest.la
 
@@ -37,6 +37,7 @@ fixes_LDADD=$(TEST_LDADD)
 xfree86_LDADD=$(TEST_LDADD)
 touch_LDADD=$(TEST_LDADD)
 hashtabletest_LDADD=$(TEST_LDADD) $(top_srcdir)/Xext/hashtable.c
+os_LDADD=$(TEST_LDADD)
 
 libxservertest_la_LIBADD = $(XSERVER_LIBS)
 if XORG
diff --git a/test/os.c b/test/os.c
new file mode 100644
index 0000000..1460a34
--- /dev/null
+++ b/test/os.c
@@ -0,0 +1,130 @@
+/**
+ * Copyright © 2012 Red Hat, Inc.
+ *
+ *  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, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice (including the next
+ *  paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <signal.h>
+#include "os.h"
+
+static int
+sig_is_blocked(int sig)
+{
+    sigset_t current;
+
+    sigemptyset(&current);
+    assert(sigprocmask(SIG_BLOCK, NULL, &current) == 0);
+    return sigismember(&current, sig);
+}
+
+static void block_sigio_test(void)
+{
+#ifdef SIG_BLOCK
+    sigset_t current;
+
+    sigemptyset(&current);
+    assert(!sig_is_blocked(SIGIO));
+
+    /* block once */
+    OsBlockSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSIGIO();
+    assert(!sig_is_blocked(SIGIO));
+
+    /* block twice, nested */
+    OsBlockSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsBlockSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSIGIO();
+    assert(!sig_is_blocked(SIGIO));
+
+    /* block all */
+    OsBlockSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSignals();
+    assert(!sig_is_blocked(SIGIO));
+
+    /* block all nested */
+    OsBlockSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsBlockSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSignals();
+    assert(!sig_is_blocked(SIGIO));
+
+    /* mix the two */
+    /* ABBA */
+    OsBlockSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsBlockSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSignals();
+    assert(!sig_is_blocked(SIGIO));
+
+    /* ABAB */
+    OsBlockSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsBlockSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSIGIO();
+    assert(!sig_is_blocked(SIGIO));
+
+    /* BAAB */
+    OsBlockSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsBlockSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSIGIO();
+    assert(!sig_is_blocked(SIGIO));
+
+    /* BABA */
+    OsBlockSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsBlockSignals();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSIGIO();
+    assert(sig_is_blocked(SIGIO));
+    OsReleaseSignals();
+    assert(!sig_is_blocked(SIGIO));
+
+#endif
+}
+
+int
+main(int argc, char **argv)
+{
+    block_sigio_test();
+    return 0;
+}
commit 24525d96a3b9dba67eb75042500b2f208a2cc246
Merge: 4cd91bd 35e3d22
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jul 2 22:35:39 2012 -0700

    Merge branch 'sigsafe-logging-varargs'
    
    This merge includes a minor fixup for '%p' arguments; must cast to
    uintptr_t instead of uint64_t as we use -Werror=pointer-to-int-cast
    which complains when doing a cast (even explicitly) from a pointer
    to an integer of different size.

commit 35e3d229150395a222a0f53318daf5dbeb8f6eb6
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 24 14:04:42 2012 +1000

    Bump to ABI_XINPUT_VERSION 18
    
    The input ABI hasn't changed, but input drivers need something to hook on if
    they want to log from within signal handlers and the input ABI is the
    simplest way of doing so.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index bf56acd..7671cea 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -83,7 +83,7 @@ typedef enum {
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
 #define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(13, 0)
-#define ABI_XINPUT_VERSION	SET_ABI_VERSION(17, 0)
+#define ABI_XINPUT_VERSION	SET_ABI_VERSION(18, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(6, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
 
commit 541934168dbeb17059542bb5a1da8eba7995fa05
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon May 28 10:10:30 2012 +1000

    xfree86: constify InputDriverPtr->driverName and default_options
    
    Already treated as const anyway by all drivers.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 6ccccf1..35c38a5 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -68,14 +68,14 @@
 /* This holds the input driver entry and module information. */
 typedef struct _InputDriverRec {
     int driverVersion;
-    char *driverName;
+    const char *driverName;
     void (*Identify) (int flags);
     int (*PreInit) (struct _InputDriverRec * drv,
                     struct _InputInfoRec * pInfo, int flags);
     void (*UnInit) (struct _InputDriverRec * drv,
                     struct _InputInfoRec * pInfo, int flags);
     pointer module;
-    char **default_options;
+    const char **default_options;
 } InputDriverRec, *InputDriverPtr;
 
 /* This is to input devices what the ScrnInfoRec is to screens. */
commit c66089d2206bafc01307a8327ff6089edcb4ed2d
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon May 28 09:57:33 2012 +1000

    xfree86: constify InputInfoPtr->type_name
    
    This corresponds to XListInputDevice(3)'s "type" field (after being
    converted to an Atom). Input drivers use the XI_KEYBOARD and similar
    defines, even Wacom which falls out of the common defines uses constant
    strings here. The use-case for having this non-const is small.
    
    Input ABI break technically, since we never freed this information anyway it
    is not a noticable change.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 1d4363a..6ccccf1 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -98,7 +98,7 @@ typedef struct _InputInfoRec {
     int fd;
     DeviceIntPtr dev;
     pointer private;
-    char *type_name;
+    const char *type_name;
     InputDriverPtr drv;
     pointer module;
     XF86OptionPtr options;
commit 505c8a2b2cae0318db1148417ec850d54b38f7df
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Mon Apr 9 09:41:38 2012 -0700

    Log in OsVendorFatalError() in a signal safe manner
    
    The function can be called from a fatal signal handler.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index ca6efd4..84c8669 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1058,16 +1058,16 @@ void
 OsVendorFatalError(const char *f, va_list args)
 {
 #ifdef VENDORSUPPORT
-    ErrorF("\nPlease refer to your Operating System Vendor support pages\n"
-           "at %s for support on this crash.\n", VENDORSUPPORT);
+    ErrorFSigSafe("\nPlease refer to your Operating System Vendor support "
+                 "pages\nat %s for support on this crash.\n", VENDORSUPPORT);
 #else
-    ErrorF("\nPlease consult the " XVENDORNAME " support \n"
-           "\t at " __VENDORDWEBSUPPORT__ "\n for help. \n");
+    ErrorFSigSafe("\nPlease consult the " XVENDORNAME " support \n\t at "
+                 __VENDORDWEBSUPPORT__ "\n for help. \n");
 #endif
     if (xf86LogFile && xf86LogFileWasOpened)
-        ErrorF("Please also check the log file at \"%s\" for additional "
-               "information.\n", xf86LogFile);
-    ErrorF("\n");
+        ErrorFSigSafe("Please also check the log file at \"%s\" for additional "
+                     "information.\n", xf86LogFile);
+    ErrorFSigSafe("\n");
 }
 
 int
commit d51aebdbf99a9f240f7c318a70ba40e61cd43049
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Mon Apr 9 08:30:50 2012 -0700

    Log in LoaderUnload() in a signal safe manner
    
    The function may be called from a fatal signal handler.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index b72b8b8..edaefb8 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -163,7 +163,7 @@ LoaderSymbol(const char *name)
 void
 LoaderUnload(const char *name, void *handle)
 {
-    xf86Msg(X_INFO, "Unloading %s\n", name);
+    LogMessageVerbSigSafe(X_INFO, 1, "Unloading %s\n", name);
     if (handle)
         dlclose(handle);
 }
commit c3e1168778ec20beeac9979dc57e36400c70dd63
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Mon Apr 9 08:28:17 2012 -0700

    Log in UnloadModuleOrDriver() in a signal safe manner
    
    The function may be called from a fatal signal handler.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 706b9b3..72020a5 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -1093,9 +1093,10 @@ UnloadModuleOrDriver(ModuleDescPtr mod)
         return;
 
     if (mod->parent)
-        xf86MsgVerb(X_INFO, 3, "UnloadSubModule: \"%s\"\n", mod->name);
+        LogMessageVerbSigSafe(X_INFO, 3, "UnloadSubModule: \"%s\"\n",
+                              mod->name);
     else
-        xf86MsgVerb(X_INFO, 3, "UnloadModule: \"%s\"\n", mod->name);
+        LogMessageVerbSigSafe(X_INFO, 3, "UnloadModule: \"%s\"\n", mod->name);
 
     if (mod->TearDownData != ModuleDuplicated) {
         if ((mod->TearDownProc) && (mod->TearDownData))
commit 89e3ac07aca1def155299aff6f7a57ccafb68fd7
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Mon Apr 9 08:23:32 2012 -0700

    Log safely in fatal signal handler
    
    While we probably don't need to be signal safe here since we will never
    return to the normal context, the logging signal context check will
    cause unsafe logging to be unhandled. Using signal safe logging here
    resolves the issue.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/os/osinit.c b/os/osinit.c
index e2a2208..6cc0401 100644
--- a/os/osinit.c
+++ b/os/osinit.c
@@ -113,7 +113,7 @@ OsSigHandler(int signo)
     const char *dlerr = dlerror();
 
     if (dlerr) {
-        LogMessage(X_ERROR, "Dynamic loader error: %s\n", dlerr);
+        LogMessageVerbSigSafe(X_ERROR, 1, "Dynamic loader error: %s\n", dlerr);
     }
 #endif                          /* RTLD_DI_SETSIGNAL */
 
@@ -129,8 +129,8 @@ OsSigHandler(int signo)
 
 #ifdef SA_SIGINFO
     if (sip->si_code == SI_USER) {
-        ErrorF("Recieved signal %d sent by process %ld, uid %ld\n",
-               signo, (long) sip->si_pid, (long) sip->si_uid);
+        ErrorFSigSafe("Recieved signal %u sent by process %u, uid %u\n", signo,
+                     sip->si_pid, sip->si_uid);
     }
     else {
         switch (signo) {
@@ -138,7 +138,7 @@ OsSigHandler(int signo)
         case SIGBUS:
         case SIGILL:
         case SIGFPE:
-            ErrorF("%s at address %p\n", strsignal(signo), sip->si_addr);
+            ErrorFSigSafe("%s at address %p\n", strsignal(signo), sip->si_addr);
         }
     }
 #endif
commit 6fd5add005d0660b591d808583d1a6c6a85f1277
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 6 16:17:41 2012 -0700

    Log mieq enqueue overflow in a signal safe manner
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/mi/mieq.c b/mi/mieq.c
index e117a8d..b2c7769 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -276,23 +276,22 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
          */
         miEventQueue.dropped++;
         if (miEventQueue.dropped == 1) {
-            ErrorF
-                ("[mi] EQ overflowing.  Additional events will be discarded until existing events are processed.\n");
+            ErrorFSigSafe("[mi] EQ overflowing.  Additional events will be "
+                         "discarded until existing events are processed.\n");
             xorg_backtrace();
-            ErrorF
-                ("[mi] These backtraces from mieqEnqueue may point to a culprit higher up the stack.\n");
-            ErrorF("[mi] mieq is *NOT* the cause.  It is a victim.\n");
+            ErrorFSigSafe("[mi] These backtraces from mieqEnqueue may point to "
+                         "a culprit higher up the stack.\n");
+            ErrorFSigSafe("[mi] mieq is *NOT* the cause.  It is a victim.\n");
         }
         else if (miEventQueue.dropped % QUEUE_DROP_BACKTRACE_FREQUENCY == 0 &&
                  miEventQueue.dropped / QUEUE_DROP_BACKTRACE_FREQUENCY <=
                  QUEUE_DROP_BACKTRACE_MAX) {
-            ErrorF
-                ("[mi] EQ overflow continuing.  %lu events have been dropped.\n",
-                 miEventQueue.dropped);
+            ErrorFSigSafe("[mi] EQ overflow continuing.  %u events have been "
+                         "dropped.\n", miEventQueue.dropped);
             if (miEventQueue.dropped / QUEUE_DROP_BACKTRACE_FREQUENCY ==
                 QUEUE_DROP_BACKTRACE_MAX) {
-                ErrorF
-                    ("[mi] No further overflow reports will be reported until the clog is cleared.\n");
+                ErrorFSigSafe("[mi] No further overflow reports will be "
+                             "reported until the clog is cleared.\n");
             }
             xorg_backtrace();
         }
commit 7f4a69b628a6246855054a0b94d6d6dd14e8842c
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 13 16:01:38 2012 -0700

    Log messages in TouchBeginDDXTouch() in a signal-safe manner
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/touch.c b/dix/touch.c
index aa17faf..a01f152 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -198,8 +198,9 @@ TouchBeginDDXTouch(DeviceIntPtr dev, uint32_t ddx_id)
     /* If we get here, then we've run out of touches and we need to drop the
      * event (we're inside the SIGIO handler here) schedule a WorkProc to
      * grow the queue for us for next time. */
-    ErrorF("%s: not enough space for touch events (max %d touchpoints). "
-           "Dropping this event.\n", dev->name, dev->last.num_touches);
+    ErrorFSigSafe("%s: not enough space for touch events (max %u touchpoints). "
+                  "Dropping this event.\n", dev->name, dev->last.num_touches);
+
     if (!BitIsOn(resize_waiting, dev->id)) {
         SetBit(resize_waiting, dev->id);
         QueueWorkProc(TouchResizeQueue, serverClient, NULL);
commit f752226e40890643df213a62f0c96e6a0243e754
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 6 10:21:14 2012 -0700

    Log messages in GetTouchEvents() in a signal safe manner
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index baa26c4..3fa3a1e 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1839,8 +1839,8 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid,
         touchpoint.ti =
             TouchFindByDDXID(dev, ddx_touchid, (type == XI_TouchBegin));
         if (!touchpoint.ti) {
-            ErrorF("[dix] %s: unable to %s touch point %x\n", dev->name,
-                   type == XI_TouchBegin ? "begin" : "find", ddx_touchid);
+            ErrorFSigSafe("[dix] %s: unable to %s touch point %u\n", dev->name,
+                          type == XI_TouchBegin ? "begin" : "find", ddx_touchid);
             return 0;
         }
         client_id = touchpoint.ti->client_id;
commit 82d1c6b310eaa5095eed9ee4ea958261a46a78e1
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 6 08:32:28 2012 -0700

    Warn when attempting to log in a signal unsafe manner from signal context
    
    Also, print out the offending message format. This will hopefully help
    developers track down unsafe logging.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/os/log.c b/os/log.c
index 47ba348..25da9f6 100644
--- a/os/log.c
+++ b/os/log.c
@@ -463,6 +463,16 @@ LogVMessageVerb(MessageType type, int verb, const char *format, va_list args)
     Bool newline;
     size_t len = 0;
 
+    if (inSignalContext) {
+        BUG_WARN_MSG(inSignalContext,
+                     "Warning: attempting to log data in a signal unsafe "
+                     "manner while in signal context. Please update to check "
+                     "inSignalContext and/or use LogMessageVerbSigSafe() or "
+                     "ErrorFSigSafe(). The offending log format message is:\n"
+                     "%s\n", format);
+        return;
+    }
+
     type_str = LogMessageTypeVerbString(type, verb);
     if (!type_str)
         return;
@@ -552,6 +562,16 @@ LogVHdrMessageVerb(MessageType type, int verb, const char *msg_format,
     Bool newline;
     size_t len = 0;
 
+    if (inSignalContext) {
+        BUG_WARN_MSG(inSignalContext,
+                     "Warning: attempting to log data in a signal unsafe "
+                     "manner while in signal context. Please update to check "
+                     "inSignalContext and/or use LogMessageVerbSigSafe(). The "
+                     "offending header and log message formats are:\n%s %s\n",
+                     hdr_format, msg_format);
+        return;
+    }
+
     type_str = LogMessageTypeVerbString(type, verb);
     if (!type_str)
         return;
commit 512bec06be6c79ca263da9de8f40430b8095b57b
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Mon Apr 16 09:47:42 2012 -0700

    Make BUG_WARN* signal safe
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/include/misc.h b/include/misc.h
index 6ae020a..aa62f6a 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -371,10 +371,10 @@ extern _X_EXPORT unsigned long serverGeneration;
 /* Don't use this directly, use BUG_WARN or BUG_WARN_MSG instead */
 #define __BUG_WARN_MSG(cond, with_msg, ...)                                \
           do { if (cond) {                                                \
-              ErrorF("BUG: triggered 'if (" #cond ")'\n");                \
-              ErrorF("BUG: %s:%d in %s()\n",                              \
-                      __FILE__, __LINE__, __func__);                      \
-              if (with_msg) ErrorF(__VA_ARGS__);                          \
+              ErrorFSigSafe("BUG: triggered 'if (" #cond ")'\n");          \
+              ErrorFSigSafe("BUG: %s:%u in %s()\n",                        \
+                           __FILE__, __LINE__, __func__);                 \
+              if (with_msg) ErrorFSigSafe(__VA_ARGS__);                    \
               xorg_backtrace();                                           \
           } } while(0)
 
commit 0fa5217836cf7fd3872fccc9f3ff9ff32426c25b
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 6 16:09:05 2012 -0700

    Print backtrace in a signal-safe manner
    
    Backtraces are often printed in signal context, such as when a segfault
    occurs.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    
    os: print offset as unsigned int, not long unsigned int
    
    pnprintf() takes unsigned int for %u
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/os/backtrace.c b/os/backtrace.c
index 81348f4..daac60c 100644
--- a/os/backtrace.c
+++ b/os/backtrace.c
@@ -45,29 +45,37 @@ xorg_backtrace(void)
     int size, i;
     Dl_info info;
 
-    ErrorF("\n");
-    ErrorF("Backtrace:\n");
+    ErrorFSigSafe("\n");
+    ErrorFSigSafe("Backtrace:\n");
     size = backtrace(array, 64);
     for (i = 0; i < size; i++) {
         int rc = dladdr(array[i], &info);
 
         if (rc == 0) {
-            ErrorF("%d: ?? [%p]\n", i, array[i]);
+            ErrorFSigSafe("%u: ?? [%p]\n", i, array[i]);
             continue;
         }
         mod = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)";
         if (info.dli_saddr)
-            ErrorF("%d: %s (%s+0x%lx) [%p]\n", i, mod,
-                   info.dli_sname,
-                   (long unsigned int) ((char *) array[i] -
-                                        (char *) info.dli_saddr), array[i]);
+            ErrorFSigSafe(
+                "%u: %s (%s+0x%x) [%p]\n",
+                i,
+                mod,
+                info.dli_sname,
+                (unsigned int)((char *) array[i] -
+                               (char *) info.dli_saddr),
+                array[i]);
         else
-            ErrorF("%d: %s (%p+0x%lx) [%p]\n", i, mod,
-                   info.dli_fbase,
-                   (long unsigned int) ((char *) array[i] -
-                                        (char *) info.dli_fbase), array[i]);
+            ErrorFSigSafe(
+                "%u: %s (%p+0x%x) [%p]\n",
+                i,
+                mod,
+                info.dli_fbase,
+                (unsigned int)((char *) array[i] -
+                               (char *) info.dli_fbase),
+                array[i]);
     }
-    ErrorF("\n");
+    ErrorFSigSafe("\n");
 }
 
 #else                           /* not glibc or glibc < 2.1 */
@@ -105,7 +113,7 @@ xorg_backtrace_frame(uintptr_t pc, int signo, void *arg)
             strcpy(signame, "unknown");
         }
 
-        ErrorF("** Signal %d (%s)\n", signo, signame);
+        ErrorFSigSafe("** Signal %u (%s)\n", signo, signame);
     }
 
     snprintf(header, sizeof(header), "%d: 0x%lx", depth, pc);
@@ -123,7 +131,8 @@ xorg_backtrace_frame(uintptr_t pc, int signo, void *arg)
             symname = "<section start>";
             offset = pc - (uintptr_t) dlinfo.dli_fbase;
         }
-        ErrorF("%s: %s:%s+0x%lx\n", header, dlinfo.dli_fname, symname, offset);
+        ErrorFSigSafe("%s: %s:%s+0x%x\n", header, dlinfo.dli_fname, symname,
+                     offset);
 
     }
     else {
@@ -131,7 +140,7 @@ xorg_backtrace_frame(uintptr_t pc, int signo, void *arg)
          * probably poke elfloader here, but haven't written that code yet,
          * so we just print the pc.
          */
-        ErrorF("%s\n", header);
+        ErrorFSigSafe("%s\n", header);
     }
 
     return 0;
@@ -183,7 +192,7 @@ xorg_backtrace_pstack(void)
 
             if (bytesread > 0) {
                 btline[bytesread] = 0;
-                ErrorF("%s", btline);
+                ErrorFSigSafe("%s", btline);
             }
             else if ((bytesread < 0) || ((errno != EINTR) && (errno != EAGAIN)))
                 done = 1;
@@ -203,8 +212,8 @@ void
 xorg_backtrace(void)
 {
 
-    ErrorF("\n");
-    ErrorF("Backtrace:\n");
+    ErrorFSigSafe("\n");
+    ErrorFSigSafe("Backtrace:\n");
 
 #ifdef HAVE_PSTACK
 /* First try fork/exec of pstack - otherwise fall back to walkcontext
@@ -221,9 +230,9 @@ xorg_backtrace(void)
             walkcontext(&u, xorg_backtrace_frame, &depth);
         else
 #endif
-            ErrorF("Failed to get backtrace info: %s\n", strerror(errno));
+            ErrorFSigSafe("Failed to get backtrace info: %s\n", strerror(errno));
     }
-    ErrorF("\n");
+    ErrorFSigSafe("\n");
 }
 
 #else
commit ac20815d5235e7a8e7b331365aabf5a489fc5e34
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Tue Jun 5 15:39:41 2012 +1000

    Add ErrorFSigSafe() alternative to ErrorF()
    
    ErrorF() is not signal safe. Use ErrorSigSafe() whenever an error
    message may be logged in signal context.
    
    [whot: edited to "ErrorFSigSafe"]
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/include/os.h b/include/os.h
index b3f9088..e93c48a 100644
--- a/include/os.h
+++ b/include/os.h
@@ -656,6 +656,12 @@ extern _X_EXPORT void
 ErrorF(const char *f, ...)
 _X_ATTRIBUTE_PRINTF(1, 2);
 extern _X_EXPORT void
+VErrorFSigSafe(const char *f, va_list args)
+_X_ATTRIBUTE_PRINTF(1, 0);
+extern _X_EXPORT void
+ErrorFSigSafe(const char *f, ...)
+_X_ATTRIBUTE_PRINTF(1, 2);
+extern _X_EXPORT void
 LogPrintMarkers(void);
 
 extern _X_EXPORT void
diff --git a/os/log.c b/os/log.c
index f1a6e3b..47ba348 100644
--- a/os/log.c
+++ b/os/log.c
@@ -780,6 +780,22 @@ ErrorF(const char *f, ...)
 }
 
 void
+VErrorFSigSafe(const char *f, va_list args)
+{
+    LogVMessageVerbSigSafe(X_ERROR, -1, f, args);
+}
+
+void
+ErrorFSigSafe(const char *f, ...)
+{
+    va_list args;
+
+    va_start(args, f);
+    VErrorFSigSafe(f, args);
+    va_end(args);
+}
+
+void
 LogPrintMarkers(void)
 {
     /* Show what the message marker symbols mean. */
commit 164b38c72fe9c69d13ea4f9c46d4ccc46566d826
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 6 08:28:40 2012 -0700

    Add LogMessageVerbSigSafe() for logging messages while in signal context
    
    [whot: edited to use varargs, squashed commit below]
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    
    os: fix vararg length calculation
    
    Make %u and %x sizeof(unsigned int), %p sizeof(void*). This is printf
    behaviour and we can't guarantee that void* is uint64_t anyway.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/include/os.h b/include/os.h
index 276eb52..b3f9088 100644
--- a/include/os.h
+++ b/include/os.h
@@ -49,6 +49,7 @@ SOFTWARE.
 
 #include "misc.h"
 #include <stdarg.h>
+#include <stdint.h>
 #include <string.h>
 
 #define SCREEN_SAVER_ON   0
@@ -604,6 +605,12 @@ _X_ATTRIBUTE_PRINTF(3, 4);
 extern _X_EXPORT void
 LogMessage(MessageType type, const char *format, ...)
 _X_ATTRIBUTE_PRINTF(2, 3);
+extern _X_EXPORT void
+LogMessageVerbSigSafe(MessageType type, int verb, const char *format, ...)
+_X_ATTRIBUTE_PRINTF(3, 4);
+extern _X_EXPORT void
+LogVMessageVerbSigSafe(MessageType type, int verb, const char *format, va_list args)
+_X_ATTRIBUTE_PRINTF(3, 0);
 
 extern _X_EXPORT void
 LogVHdrMessageVerb(MessageType type, int verb,
diff --git a/os/log.c b/os/log.c
index 5394847..f1a6e3b 100644
--- a/os/log.c
+++ b/os/log.c
@@ -172,6 +172,14 @@ asm(".desc ___crashreporter_info__, 0x10");
 #define X_NONE_STRING			""
 #endif
 
+static size_t
+strlen_sigsafe(const char *s)
+{
+    size_t len;
+    for (len = 0; s[len]; len++);
+    return len;
+}
+
 /*
  * LogInit is called to start logging to a file.  It is also called (with
  * NULL arguments) when logging to a file is not wanted.  It must always be
@@ -271,16 +279,97 @@ LogSetParameter(LogParameter param, int value)
     }
 }
 
-/* This function does the actual log message writes. */
+static int
+pnprintf(char *string, size_t size, const char *f, va_list args)
+{
+    int f_idx = 0;
+    int s_idx = 0;
+    int f_len = strlen_sigsafe(f);
+    char *string_arg;
+    char number[21];
+    int p_len;
+    int i;
+    uint64_t ui;
+
+    for (; f_idx < f_len && s_idx < size - 1; f_idx++) {
+        if (f[f_idx] != '%') {
+            string[s_idx++] = f[f_idx];
+            continue;
+        }
+
+        switch (f[++f_idx]) {
+        case 's':
+            string_arg = va_arg(args, char*);
+            p_len = strlen_sigsafe(string_arg);
+
+            for (i = 0; i < p_len && s_idx < size - 1; i++)
+                string[s_idx++] = string_arg[i];
+            break;
+
+        case 'u':
+            ui = va_arg(args, unsigned);
+            FormatUInt64(ui, number);
+            p_len = strlen_sigsafe(number);
+
+            for (i = 0; i < p_len && s_idx < size - 1; i++)
+                string[s_idx++] = number[i];
+            break;
+
+        case 'p':
+            string[s_idx++] = '0';
+            if (s_idx < size - 1)
+                string[s_idx++] = 'x';
+            ui = (uintptr_t)va_arg(args, void*);
+            FormatUInt64Hex(ui, number);
+            p_len = strlen_sigsafe(number);
+
+            for (i = 0; i < p_len && s_idx < size - 1; i++)
+                string[s_idx++] = number[i];
+            break;
+
+        case 'x':
+            ui = va_arg(args, unsigned);
+            FormatUInt64Hex(ui, number);
+            p_len = strlen_sigsafe(number);
+
+            for (i = 0; i < p_len && s_idx < size - 1; i++)
+                string[s_idx++] = number[i];
+            break;
+
+        default:
+            va_arg(args, char*);
+            string[s_idx++] = '%';
+            if (s_idx < size - 1)
+                string[s_idx++] = f[f_idx];
+            break;
+        }
+    }
+
+    string[s_idx] = '\0';
+
+    return s_idx;
+}
+
+/* This function does the actual log message writes. It must be signal safe.
+ * When attempting to call non-signal-safe functions, guard them with a check
+ * of the inSignalContext global variable. */
 static void
 LogSWrite(int verb, const char *buf, size_t len, Bool end_line)
 {
     static Bool newline = TRUE;
 
     if (verb < 0 || logVerbosity >= verb)
-        fwrite(buf, len, 1, stderr);
+        write(2, buf, len);
+
     if (verb < 0 || logFileVerbosity >= verb) {
-        if (logFile) {
+        if (inSignalContext && logFileFd >= 0) {
+            write(logFileFd, buf, len);
+#ifdef WIN32
+            if (logFlush && logSync)
+                fsync(logFileFd);
+#endif
+        }
+        else if (!inSignalContext && logFile) {
             if (newline)
                 fprintf(logFile, "[%10.3f] ", GetTimeInMillis() / 1000.0);
             newline = end_line;
@@ -293,7 +382,7 @@ LogSWrite(int verb, const char *buf, size_t len, Bool end_line)
 #endif
             }
         }
-        else if (needBuffer) {
+        else if (!inSignalContext && needBuffer) {
             if (len > bufferUnused) {
                 bufferSize += 1024;
                 bufferUnused += 1024;
@@ -415,6 +504,44 @@ LogMessage(MessageType type, const char *format, ...)
     va_end(ap);
 }
 
+/* Log a message using only signal safe functions. */
+void
+LogMessageVerbSigSafe(MessageType type, int verb, const char *format, ...)
+{
+    va_list ap;
+    va_start(ap, format);
+    LogVMessageVerbSigSafe(type, verb, format, ap);
+    va_end(ap);
+}
+
+void
+LogVMessageVerbSigSafe(MessageType type, int verb, const char *format, va_list args)
+{
+    const char *type_str;
+    char buf[1024];
+    int len;
+    Bool newline;
+
+    type_str = LogMessageTypeVerbString(type, verb);
+    if (!type_str)
+        return;
+
+    /* if type_str is not "", prepend it and ' ', to message */
+    if (type_str[0] != '\0') {
+        LogSWrite(verb, type_str, strlen_sigsafe(type_str), FALSE);
+        LogSWrite(verb, " ", 1, FALSE);
+    }
+
+    len = pnprintf(buf, sizeof(buf), format, args);
+
+    /* Force '\n' at end of truncated line */
+    if (sizeof(buf) - len == 1)
+        buf[len - 1] = '\n';
+
+    newline = (buf[len - 1] == '\n');
+    LogSWrite(verb, buf, len, newline);
+}
+
 void
 LogVHdrMessageVerb(MessageType type, int verb, const char *msg_format,
                    va_list msg_args, const char *hdr_format, va_list hdr_args)
commit 4cd91bd4c6325b2e617ca90a725f02ac124c2372
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat May 12 10:11:33 2012 -0700

    Enable no-undefined symbols mode in Solaris builds if -z parent is in ld
    
    The Solaris linker recently added a -z parent flag for easier checking
    of symbol definitions in plugins against the program that loads them.
    If that's present, this enables it, along with -z defs to error on
    undefined symbols to alert us if any modules call symbols that won't
    be found at runtime.
    
    This builds upon, and requires, the recent Cygwin work to build Xorg.
    It moves a couple more modules to be after the Xorg binary in the build
    order so that they can find the binary to check against, much as the
    Cygwin changes did (these would be modules built on Solaris but not
    Cygwin).
    
    v2: This version only sets the flags for the xorg-server build itself,
    and does not yet export them in xorg-server.pc to the drivers, since
    most of the drivers are not ready to build with -no-undefined yet.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>

diff --git a/configure.ac b/configure.ac
index 7576dae..d5ddf6e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1499,6 +1499,26 @@ case "$host_os" in
 	XORG_DRIVER_LIBS="-lXorg.exe -L\${moduledir} -lshadow -lfb -no-undefined"
 	CYGWIN=yes
 	;;
+    solaris*)
+	# We use AC_LINK_IFELSE to generate a temporary program conftest$EXEEXT
+	# that we can link against for testing if the system linker is new
+	# enough to support -z parent=<program> for verifying loadable modules
+	# are only calling functions defined in either the loading program or
+	# the libraries they're linked with.
+	AC_LINK_IFELSE(
+	    [AC_LANG_SOURCE([int main(int argc, char **argv) { return 0; }])],
+	    [mv conftest$EXEEXT conftest.parent
+	     XORG_CHECK_LINKER_FLAGS([-Wl,-z,parent=conftest.parent -G],
+		[LD_NO_UNDEFINED_FLAG="-Wl,-z,defs -Wl,-z,parent=\$(top_builddir)/hw/xfree86/Xorg"
+# Not set yet, since this gets exported in xorg-server.pc to all the drivers,
+# and they're not all fixed to build correctly with it yet.
+#		 XORG_DRIVER_LIBS="-Wl,-z,defs -Wl,-z,parent=${bindir}/Xorg"
+         ],[],
+		[AC_LANG_SOURCE([extern int main(int argc, char **argv);
+			int call_main(void) { return main(0, NULL); }])])
+	     rm -f conftest.parent
+	    ])
+	;;
 esac
 AC_SUBST([LD_EXPORT_SYMBOLS_FLAG])
 AC_SUBST([LD_NO_UNDEFINED_FLAG])
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index e50cb88..4d5d576 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -26,9 +26,9 @@ INT10_SUBDIR = int10
 endif
 
 SUBDIRS = common ddc x86emu $(INT10_SUBDIR) os-support parser \
-	  ramdac $(VBE_SUBDIR) $(VGAHW_SUBDIR) $(XAA_SUBDIR) \
-	  loader modes . i2c dixmods fbdevhw shadowfb exa \
-	  $(DRI_SUBDIR) $(DRI2_SUBDIR) $(XF86UTILS_SUBDIR) doc man
+	  ramdac $(VGAHW_SUBDIR) loader modes . $(VBE_SUBDIR) \
+	  $(XAA_SUBDIR) $(DRI_SUBDIR) $(DRI2_SUBDIR) i2c dixmods \
+	  fbdevhw shadowfb exa $(XF86UTILS_SUBDIR) doc man
 
 DIST_SUBDIRS = common ddc i2c x86emu int10 fbdevhw os-support \
                parser ramdac shadowfb vbe vgahw xaa \
commit d31942e15c619e9355ef8183223f9165902a9d56
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat May 12 10:10:49 2012 -0700

    Add pixman to module dependencies for pixman_region_* functions
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>

diff --git a/hw/xfree86/dri/Makefile.am b/hw/xfree86/dri/Makefile.am
index 194cf8e..9528d53 100644
--- a/hw/xfree86/dri/Makefile.am
+++ b/hw/xfree86/dri/Makefile.am
@@ -13,7 +13,7 @@ libdri_la_CFLAGS = -I$(top_srcdir)/hw/xfree86/common \
                    @LIBDRM_CFLAGS@ \
                    @DRI_CFLAGS@
 libdri_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-libdri_la_LIBADD = @LIBDRM_LIBS@
+libdri_la_LIBADD = @LIBDRM_LIBS@ $(PIXMAN_LIBS)
 libdri_ladir = $(moduledir)/extensions
 libdri_la_SOURCES = \
 	dri.c \
diff --git a/hw/xfree86/dri2/Makefile.am b/hw/xfree86/dri2/Makefile.am
index 0e40fbc..390ed12 100644
--- a/hw/xfree86/dri2/Makefile.am
+++ b/hw/xfree86/dri2/Makefile.am
@@ -7,7 +7,7 @@ libdri2_la_CFLAGS = \
 	-I$(top_srcdir)/hw/xfree86/os-support/bus
 
 libdri2_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-libdri2_la_LIBADD = @LIBDRM_LIBS@
+libdri2_la_LIBADD = @LIBDRM_LIBS@ $(PIXMAN_LIBS)
 libdri2_ladir = $(moduledir)/extensions
 libdri2_la_SOURCES = \
 	dri2.c \
diff --git a/hw/xfree86/xaa/Makefile.am b/hw/xfree86/xaa/Makefile.am
index f6480a7..5614d72 100644
--- a/hw/xfree86/xaa/Makefile.am
+++ b/hw/xfree86/xaa/Makefile.am
@@ -11,8 +11,9 @@ POLYSEG = s-xaaLine.c s-xaaDashLine.c
 if XAA
 
 libxaa_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
+libxaa_la_LIBADD = $(PIXMAN_LIBS)
 if COMPOSITE
-libxaa_la_LIBADD = $(top_builddir)/miext/cw/libcw.la
+libxaa_la_LIBADD += $(top_builddir)/miext/cw/libcw.la
 endif
 
 module_LTLIBRARIES = libxaa.la
commit 339f38ef380d750c4c7afd60331a559845e4184e
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sat May 12 10:09:41 2012 -0700

    Build tda9885.c functions into fi1236 to avoid libtool relinking problems
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>

diff --git a/hw/xfree86/i2c/Makefile.am b/hw/xfree86/i2c/Makefile.am
index f08541c..cb18db1 100644
--- a/hw/xfree86/i2c/Makefile.am
+++ b/hw/xfree86/i2c/Makefile.am
@@ -25,10 +25,7 @@ bt829_drv_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
 bt829_drv_la_SOURCES = bt829.c bt829.h bt829_module.c
 
 fi1236_drv_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-fi1236_drv_la_SOURCES = fi1236.c fi1236.h fi1236_module.c
-if NO_UNDEFINED
-fi1236_drv_la_LIBADD = tda9885_drv.la
-endif
+fi1236_drv_la_SOURCES = fi1236.c fi1236.h fi1236_module.c tda9885.c
 
 msp3430_drv_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
 msp3430_drv_la_SOURCES = msp3430.c msp3430.h msp3430_module.c
commit a00066d2916b6910429cc1c7feedafbaee0d4750
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Thu Jun 28 15:15:53 2012 -0700

    Add dixGetGlyphs to replace GetGlyphs from libXfont to simplify linking
    
    No other Xfont consumer used it, and this saves us from having to link
    callers against libXfont for one simple function when doing
    -no-undefined symbols builds.
    
    The function is given a new name to avoid clashing with existing libXfont
    binaries, but a #define is provided to preserve the API so we don't have
    to fix all the callers at the same time.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>

diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 19fd31e..dd93311 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -115,6 +115,15 @@ LoadGlyphs(ClientPtr client, FontPtr pfont, unsigned nchars, int item_size,
         return Successful;
 }
 
+void
+dixGetGlyphs(FontPtr font, unsigned long count, unsigned char *chars,
+             FontEncoding fontEncoding,
+             unsigned long *glyphcount,    /* RETURN */
+             CharInfoPtr *glyphs)          /* RETURN */
+{
+    (*font->get_glyphs) (font, count, chars, fontEncoding, glyphcount, glyphs);
+}
+
 /*
  * adding RT_FONT prevents conflict with default cursor font
  */
diff --git a/include/dixfont.h b/include/dixfont.h
index 9333041..3d09eb5 100644
--- a/include/dixfont.h
+++ b/include/dixfont.h
@@ -117,12 +117,13 @@ extern _X_EXPORT void FreeFonts(void);
 
 extern _X_EXPORT FontPtr find_old_font(XID /*id */ );
 
-extern _X_EXPORT void GetGlyphs(FontPtr /*font */ ,
-                                unsigned long /*count */ ,
-                                unsigned char * /*chars */ ,
-                                FontEncoding /*fontEncoding */ ,
-                                unsigned long * /*glyphcount */ ,
-                                CharInfoPtr * /*glyphs */ );
+#define GetGlyphs dixGetGlyphs
+extern _X_EXPORT void dixGetGlyphs(FontPtr /*font */ ,
+                                   unsigned long /*count */ ,
+                                   unsigned char * /*chars */ ,
+                                   FontEncoding /*fontEncoding */ ,
+                                   unsigned long * /*glyphcount */ ,
+                                   CharInfoPtr * /*glyphs */ );
 
 extern _X_EXPORT void QueryGlyphExtents(FontPtr /*pFont */ ,
                                         CharInfoPtr * /*charinfo */ ,
commit 212b9803238d2de2e77cbe5de62d3f616ae50daf
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Fri Jun 29 13:33:58 2012 -0700

    randr: Fix REQUEST vs. REQUEST_SIZE_MATCH mismatch
    
    ProcRRGetScreenSizeRange uses REQUEST(xRRGetScreenSizeRangeReq) followed by
    REQUEST_SIZE_MATCH(xRRGetScreenInfoReq).  This happens to work out because both
    requests have the same size, so this is not a functional change, just a cosmetic
    one.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index 55110e0..c564d1f 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -195,7 +195,7 @@ ProcRRGetScreenSizeRange(ClientPtr client)
     rrScrPrivPtr pScrPriv;
     int rc;
 
-    REQUEST_SIZE_MATCH(xRRGetScreenInfoReq);
+    REQUEST_SIZE_MATCH(xRRGetScreenSizeRangeReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
commit 957bf959fb577b292a3e4f6bb67740ca09e7aeb9
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jun 27 14:36:04 2012 +0100

    dix/render: consolidate window format matching code.
    
    This code existed in 3 different forms, perhaps it should be
    consolidated.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/composite/compalloc.c b/composite/compalloc.c
index b958b09..cc69c68 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -560,8 +560,8 @@ compNewPixmap(WindowPtr pWin, int x, int y, int w, int h)
         }
     }
     else {
-        PictFormatPtr pSrcFormat = compWindowFormat(pParent);
-        PictFormatPtr pDstFormat = compWindowFormat(pWin);
+        PictFormatPtr pSrcFormat = PictureWindowFormat(pParent);
+        PictFormatPtr pDstFormat = PictureWindowFormat(pWin);
         XID inferiors = IncludeInferiors;
         int error;
 
diff --git a/composite/compint.h b/composite/compint.h
index 9e2713e..30b724e 100644
--- a/composite/compint.h
+++ b/composite/compint.h
@@ -272,8 +272,6 @@ void
 #define compCheckTree(s)
 #endif
 
-PictFormatPtr compWindowFormat(WindowPtr pWin);
-
 void
  compSetPixmap(WindowPtr pWin, PixmapPtr pPixmap);
 
diff --git a/composite/compwindow.c b/composite/compwindow.c
index 6eb624b..d0bcd18 100644
--- a/composite/compwindow.c
+++ b/composite/compwindow.c
@@ -631,28 +631,6 @@ compGetRedirectBorderClip(WindowPtr pWin)
     return &cw->borderClip;
 }
 
-static VisualPtr
-compGetWindowVisual(WindowPtr pWin)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    VisualID vid = wVisual(pWin);
-    int i;
-
-    for (i = 0; i < pScreen->numVisuals; i++)
-        if (pScreen->visuals[i].vid == vid)
-            return &pScreen->visuals[i];
-    return 0;
-}
-
-PictFormatPtr
-compWindowFormat(WindowPtr pWin)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    return PictureMatchVisual(pScreen, pWin->drawable.depth,
-                              compGetWindowVisual(pWin));
-}
-
 static void
 compWindowUpdateAutomatic(WindowPtr pWin)
 {
@@ -660,8 +638,8 @@ compWindowUpdateAutomatic(WindowPtr pWin)
     ScreenPtr pScreen = pWin->drawable.pScreen;
     WindowPtr pParent = pWin->parent;
     PixmapPtr pSrcPixmap = (*pScreen->GetWindowPixmap) (pWin);
-    PictFormatPtr pSrcFormat = compWindowFormat(pWin);
-    PictFormatPtr pDstFormat = compWindowFormat(pWin->parent);
+    PictFormatPtr pSrcFormat = PictureWindowFormat(pWin);
+    PictFormatPtr pDstFormat = PictureWindowFormat(pWin->parent);
     int error;
     RegionPtr pRegion = DamageRegion(cw->damage);
     PicturePtr pSrcPicture = CreatePicture(0, &pSrcPixmap->drawable,
diff --git a/dix/window.c b/dix/window.c
index 98f5604..5cc3a50 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -3660,3 +3660,16 @@ SetRootClip(ScreenPtr pScreen, Bool enable)
         WindowsRestructured();
     FlushAllOutput();
 }
+
+VisualPtr
+WindowGetVisual(WindowPtr pWin)
+{
+    ScreenPtr pScreen = pWin->drawable.pScreen;
+    VisualID vid = wVisual(pWin);
+    int i;
+
+    for (i = 0; i < pScreen->numVisuals; i++)
+        if (pScreen->visuals[i].vid == vid)
+            return &pScreen->visuals[i];
+    return 0;
+}
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 6a661e1..31e0372 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -46,28 +46,6 @@
 
 /* borrowed from composite extension, move to Render and publish? */
 
-static VisualPtr
-compGetWindowVisual(WindowPtr pWin)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    VisualID vid = wVisual(pWin);
-    int i;
-
-    for (i = 0; i < pScreen->numVisuals; i++)
-        if (pScreen->visuals[i].vid == vid)
-            return &pScreen->visuals[i];
-    return 0;
-}
-
-static PictFormatPtr
-compWindowFormat(WindowPtr pWin)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    return PictureMatchVisual(pScreen, pWin->drawable.depth,
-                              compGetWindowVisual(pWin));
-}
-
 #define F(x)	IntToxFixed(x)
 
 #define toF(x)	((float) (x) / 65536.0f)
@@ -79,7 +57,7 @@ xf86RotateCrtcRedisplay(xf86CrtcPtr crtc, RegionPtr region)
     ScreenPtr screen = scrn->pScreen;
     WindowPtr root = screen->root;
     PixmapPtr dst_pixmap = crtc->rotatedPixmap;
-    PictFormatPtr format = compWindowFormat(screen->root);
+    PictFormatPtr format = PictureWindowFormat(screen->root);
     int error;
     PicturePtr src, dst;
     int n = RegionNumRects(region);
diff --git a/include/window.h b/include/window.h
index 64c56ae..7842b4d 100644
--- a/include/window.h
+++ b/include/window.h
@@ -229,4 +229,5 @@ extern _X_EXPORT void EnableMapUnmapEvents(WindowPtr /* pWin */ );
 extern _X_EXPORT void SetRootClip(ScreenPtr pScreen, Bool enable);
 extern _X_EXPORT void PrintWindowTree(void);
 
+extern _X_EXPORT VisualPtr WindowGetVisual(WindowPtr /*pWin*/);
 #endif                          /* WINDOW_H */
diff --git a/mi/midispcur.c b/mi/midispcur.c
index 9ee8242..df141cd 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -151,19 +151,6 @@ miDCRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
 #ifdef ARGB_CURSOR
 #define EnsurePicture(picture,draw,win) (picture || miDCMakePicture(&picture,draw,win))
 
-static VisualPtr
-miDCGetWindowVisual(WindowPtr pWin)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    VisualID vid = wVisual(pWin);
-    int i;
-
-    for (i = 0; i < pScreen->numVisuals; i++)
-        if (pScreen->visuals[i].vid == vid)
-            return &pScreen->visuals[i];
-    return 0;
-}
-
 static PicturePtr
 miDCMakePicture(PicturePtr * ppPicture, DrawablePtr pDraw, WindowPtr pWin)
 {
@@ -174,10 +161,7 @@ miDCMakePicture(PicturePtr * ppPicture, DrawablePtr pDraw, WindowPtr pWin)
     PicturePtr pPicture;
     int error;
 
-    pVisual = miDCGetWindowVisual(pWin);
-    if (!pVisual)
-        return 0;
-    pFormat = PictureMatchVisual(pScreen, pDraw->depth, pVisual);
+    pFormat = PictureWindowFormat(pWin);
     if (!pFormat)
         return 0;
     pPicture = CreatePicture(0, pDraw, pFormat,
diff --git a/render/picture.c b/render/picture.c
index 7887853..ebbfa29 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -50,6 +50,14 @@ RESTYPE PictFormatType;
 RESTYPE GlyphSetType;
 int PictureCmapPolicy = PictureCmapPolicyDefault;
 
+PictFormatPtr
+PictureWindowFormat(WindowPtr pWindow)
+{
+    ScreenPtr pScreen = pWindow->drawable.pScreen;
+    return PictureMatchVisual(pScreen, pWindow->drawable.depth,
+                              WindowGetVisual(pWindow));
+}
+
 Bool
 PictureDestroyWindow(WindowPtr pWindow)
 {
diff --git a/render/picturestr.h b/render/picturestr.h
index 6da5656..1cda88a 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -377,6 +377,9 @@ extern _X_EXPORT RESTYPE GlyphSetType;
     } \
 } \
 
+extern _X_EXPORT PictFormatPtr
+ PictureWindowFormat(WindowPtr pWindow);
+
 extern _X_EXPORT Bool
  PictureDestroyWindow(WindowPtr pWindow);
 
commit a7b97b0fa85d695ae19d194cfa3267159d149e5d
Author: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
Date:   Thu Jun 28 12:07:11 2012 +1000

    dri2: Fix authentication for < v8 clients (v2).
    
    The legacy logic was embarassingly wrong; AuthMagic should return errno,
    so returning FALSE only when AuthMagic returns nonzero is exactly wrong.
    
    v2: Match drmAuthMagic by returning -EINVAL rather than EINVAL
        Fix trailing whitespace
    
    https://bugs.freedesktop.org/show_bug.cgi?id=51400
    Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
    Tested-by: Chris Wilson <chris at chris-wilson.co.uk>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Tested-by: Knut Petersen <knut_petersen at t-online.de>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index d0f1789..d3b3c73 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -1111,14 +1111,14 @@ DRI2Connect(ScreenPtr pScreen, unsigned int driverType, int *fd,
     return TRUE;
 }
 
-static Bool
+static int
 DRI2AuthMagic (ScreenPtr pScreen, uint32_t magic)
 {
     DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
-    if (ds == NULL || (*ds->LegacyAuthMagic) (ds->fd, magic))
-        return FALSE;
+    if (ds == NULL)
+        return -EINVAL;
 
-    return TRUE;
+    return (*ds->LegacyAuthMagic) (ds->fd, magic);
 }
 
 Bool
commit 8b4f0a4fdd6c15f49458bc3a8c3135b8c389240d
Merge: 59294a2 d642e71
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jun 28 10:38:26 2012 -0700

    Merge remote-tracking branch 'jturney/master'

commit 59294a2179bd5bb996693af004b470932df00ac6
Merge: 855003c 191b630
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jun 28 10:11:44 2012 -0700

    Merge remote-tracking branch 'whot/for-keith'

commit 855003c333a0ead1db912695bc9705ef2b3144b4
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jun 21 18:45:18 2012 -0700

    randr: Catch two more potential unset rrScrPriv uses
    
    Ricardo Salveti <ricardo.salveti at linaro.org> found one place where the
    randr code could use the randr screen private data without checking
    for null first. This happens when the X server is running with
    multiple screens, some of which are randr enabled and some of which
    are not. Applications making protocol requests to the non-randr
    screens can cause segfaults where the server touches the unset private
    structure.
    
    I audited the code and found two more possible problem spots; the
    trick to auditing for this issue was to look for functions not taking
    a RandR data structure and where there was no null screen private
    check above them in the call graph.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/randr/rroutput.c b/randr/rroutput.c
index 091e06b..fbd0e32 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -546,7 +546,8 @@ ProcRRSetOutputPrimary(ClientPtr client)
     }
 
     pScrPriv = rrGetScrPriv(pWin->drawable.pScreen);
-    RRSetPrimaryOutput(pWin->drawable.pScreen, pScrPriv, output);
+    if (pScrPriv)
+        RRSetPrimaryOutput(pWin->drawable.pScreen, pScrPriv, output);
 
     return Success;
 }
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
index f570afa..55110e0 100644
--- a/randr/rrscreen.c
+++ b/randr/rrscreen.c
@@ -248,6 +248,9 @@ ProcRRSetScreenSize(ClientPtr client)
 
     pScreen = pWin->drawable.pScreen;
     pScrPriv = rrGetScrPriv(pScreen);
+    if (!pScrPriv)
+        return BadMatch;
+
     if (stuff->width < pScrPriv->minWidth || pScrPriv->maxWidth < stuff->width) {
         client->errorValue = stuff->width;
         return BadValue;
commit 32603f57ca03b6390b109960f8bb5ea53ac95ecb
Author: Ricardo Salveti de Araujo <ricardo.salveti at linaro.org>
Date:   Thu Jun 21 00:55:53 2012 -0300

    randr: first check pScrPriv before using the pointer at RRFirstOutput
    
    Fix a seg fault in case pScrPriv is NULL at ProcRRGetScreenInfo,
    which later calls RRFirstOutput.
    
    Signed-off-by: Ricardo Salveti de Araujo <ricardo.salveti at linaro.org>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/randr/randr.c b/randr/randr.c
index 4d4298a..103da48 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -446,6 +446,9 @@ RRFirstOutput(ScreenPtr pScreen)
     RROutputPtr output;
     int i, j;
 
+    if (!pScrPriv)
+        return NULL;
+
     if (pScrPriv->primaryOutput && pScrPriv->primaryOutput->crtc)
         return pScrPriv->primaryOutput;
 
commit d642e7128790ec6b709df8d1a91333ab87598077
Author: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
Date:   Thu Jun 21 20:01:49 2012 +0100

    configure.ac: link XWIN with GLX_SYS_LIBS
    
    Link XWIN with GLX_SYS_LIBS, just like all the other DDXs
    
    Signed-off-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
    Reviewed-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/configure.ac b/configure.ac
index fb3d120..7576dae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1879,8 +1879,9 @@ if test "x$XWIN" = xyes; then
 			XWIN_SYS_LIBS=-lws2_32
 			;;
 	esac
+
 	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
-	XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS"
+	XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS $GLX_SYS_LIBS"
 	AC_SUBST(XWIN_LIBS)
 	AC_SUBST(XWIN_SERVER_NAME)
 	AC_SUBST(XWIN_SYS_LIBS)
commit 9f1edced9abc066f0ba47672d006fe50fb206371
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Fri Jun 15 10:00:51 2012 +1000

    xfree86: always enable SIGIO on OsVendorInit (#50957)
    
    Drivers call xf86InstallSIGIOHandler() for their fd on DEVICE_ON. That
    function does not actually enable the signal if it was blocked to begin
    with. As a result, if one vt-switches away from the server (SIGIO is
    blocked) and then triggers a server regeneration, the signal remains
    blocked and input devices are dead.
    
    Avoid this by always unblocking SIGIO when we start the server.
    
    X.Org Bug 50957 <http://bugs.freedesktop.org/show_bug.cgi?id=50957>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index ca6efd4..526b95d 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -964,6 +964,7 @@ OsVendorInit(void)
     }
 #endif
 #endif
+    xf86UnblockSIGIO(0);
 
     beenHere = TRUE;
 }
commit 4ba340cfaa8d430c808566495f8deda0ff1b4424
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jun 21 18:42:46 2012 -0700

    randr: Clean up compiler warnings about unused and shadowing variables
    
    set but not used variables
    shadowing a previous local
    
    A hidden problem was that the VERIFY_RR_* macros define local 'rc'
    variables, any other local definitions for those would be shadowed and
    generate warnings from gcc. I've renamed the other locals 'ret'
    instead of 'rc'.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 36caa58..0c596dd 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -825,10 +825,9 @@ ProcRRSetCrtcConfig(ClientPtr client)
     int numOutputs;
     RROutputPtr *outputs = NULL;
     RROutput *outputIds;
-    TimeStamp configTime;
     TimeStamp time;
     Rotation rotation;
-    int rc, i, j;
+    int ret, i, j;
 
     REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigReq);
     numOutputs = (stuff->length - bytes_to_int32(SIZEOF(xRRSetCrtcConfigReq)));
@@ -855,11 +854,11 @@ ProcRRSetCrtcConfig(ClientPtr client)
 
     outputIds = (RROutput *) (stuff + 1);
     for (i = 0; i < numOutputs; i++) {
-        rc = dixLookupResourceByType((pointer *) (outputs + i), outputIds[i],
+        ret = dixLookupResourceByType((pointer *) (outputs + i), outputIds[i],
                                      RROutputType, client, DixSetAttrAccess);
-        if (rc != Success) {
+        if (ret != Success) {
             free(outputs);
-            return rc;
+            return ret;
         }
         /* validate crtc for this output */
         for (j = 0; j < outputs[i]->numCrtcs; j++)
@@ -904,7 +903,6 @@ ProcRRSetCrtcConfig(ClientPtr client)
     pScrPriv = rrGetScrPriv(pScreen);
 
     time = ClientTimeToServerTime(stuff->timestamp);
-    configTime = ClientTimeToServerTime(stuff->configTimestamp);
 
     if (!pScrPriv) {
         time = currentTime;
diff --git a/randr/rrinfo.c b/randr/rrinfo.c
index 114ec34..1408d6f 100644
--- a/randr/rrinfo.c
+++ b/randr/rrinfo.c
@@ -82,6 +82,7 @@ RRScanOldConfig(ScreenPtr pScreen, Rotation rotations)
     int i;
     CARD16 minWidth = MAXSHORT, minHeight = MAXSHORT;
     CARD16 maxWidth = 0, maxHeight = 0;
+    CARD16 width, height;
 
     /*
      * First time through, create a crtc and output and hook
@@ -141,11 +142,11 @@ RRScanOldConfig(ScreenPtr pScreen, Rotation rotations)
 
     /* find size bounds */
     for (i = 0; i < output->numModes + output->numUserModes; i++) {
-        RRModePtr mode = (i < output->numModes ?
+        mode = (i < output->numModes ?
                           output->modes[i] :
                           output->userModes[i - output->numModes]);
-        CARD16 width = mode->mode.width;
-        CARD16 height = mode->mode.height;
+        width = mode->mode.width;
+        height = mode->mode.height;
 
         if (width < minWidth)
             minWidth = width;
diff --git a/randr/rrmode.c b/randr/rrmode.c
index b637c06..49a45c7 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -173,7 +173,7 @@ RRModesForScreen(ScreenPtr pScreen, int *num_ret)
      */
     for (o = 0; o < pScrPriv->numOutputs; o++) {
         RROutputPtr output = pScrPriv->outputs[o];
-        int m, n;
+        int n;
 
         for (m = 0; m < output->numModes + output->numUserModes; m++) {
             RRModePtr mode = (m < output->numModes ?
@@ -285,7 +285,6 @@ ProcRRCreateMode(ClientPtr client)
     xRRCreateModeReply rep = { 0 };
     WindowPtr pWin;
     ScreenPtr pScreen;
-    rrScrPrivPtr pScrPriv;
     xRRModeInfo *modeInfo;
     long units_after;
     char *name;
@@ -298,7 +297,6 @@ ProcRRCreateMode(ClientPtr client)
         return rc;
 
     pScreen = pWin->drawable.pScreen;
-    pScrPriv = rrGetScrPriv(pScreen);
 
     modeInfo = &stuff->modeInfo;
     name = (char *) (stuff + 1);
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 0890c55..091e06b 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -528,13 +528,13 @@ ProcRRSetOutputPrimary(ClientPtr client)
     RROutputPtr output = NULL;
     WindowPtr pWin;
     rrScrPrivPtr pScrPriv;
-    int rc;
+    int ret;
 
     REQUEST_SIZE_MATCH(xRRSetOutputPrimaryReq);
 
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
-    if (rc != Success)
-        return rc;
+    ret = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
+    if (ret != Success)
+        return ret;
 
     if (stuff->output) {
         VERIFY_RR_OUTPUT(stuff->output, output, DixReadAccess);
commit 191b630656ba206ad78b7803c3a76f7d9567d9d8
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Jun 21 11:25:24 2012 +1000

    include: document _XkbErrCode2 macros
    
    Why sending the number of the (implementation-dependent) error statement to
    the client is a good idea is a bit beyond me, but at least document it so we
    can all share the despair.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index a19c8fb..d584785 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -301,6 +301,11 @@ extern _X_EXPORT const char *XkbBinDirectory;
 extern _X_EXPORT CARD32 xkbDebugFlags;
 
 #define	_XkbLibError(c,l,d)     /* Epoch fail */
+
+/* "a" is a "unique" numeric identifier that just defines which error
+ * code statement it is. _XkbErrCode2(4, foo) means "this is the 4th error
+ * statement in this function". lovely.
+ */
 #define	_XkbErrCode2(a,b) ((XID)((((unsigned int)(a))<<24)|((b)&0xffffff)))
 #define	_XkbErrCode3(a,b,c)	_XkbErrCode2(a,(((unsigned int)(b))<<16)|(c))
 #define	_XkbErrCode4(a,b,c,d) _XkbErrCode3(a,b,((((unsigned int)(c))<<8)|(d)))
commit 7100118c8d3314d73bfef0a262af56686b227055
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Jun 18 11:28:52 2012 +1000

    AC_SUBST the GLX_SYS_LIBS
    
    libxservertest needs -lpthread from glxapi.c's pthread_once() call. Usually
    this would be pulled in by the XORG_LIBS but not when building without Xorg.
    
    This commit has no visible effect on the current tree, preparation for test
    cleanups.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/test/Makefile.am b/test/Makefile.am
index b2a53aa..a5a2e5c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -20,7 +20,7 @@ INCLUDES += -I$(top_srcdir)/hw/xfree86/parser \
 	-I$(top_srcdir)/hw/xfree86/i2c -I$(top_srcdir)/hw/xfree86/modes \
 	-I$(top_srcdir)/hw/xfree86/ramdac
 endif
-TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS)
+TEST_LDADD=libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) $(GLX_SYS_LIBS)
 
 if XORG
 if SPECIAL_DTRACE_OBJECTS
diff --git a/test/xi2/Makefile.am b/test/xi2/Makefile.am
index 913ba0f..9de7abf 100644
--- a/test/xi2/Makefile.am
+++ b/test/xi2/Makefile.am
@@ -18,7 +18,7 @@ TESTS_ENVIRONMENT = $(XORG_MALLOC_DEBUG_ENV)
 
 AM_CFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@
 INCLUDES = @XORG_INCS@
-TEST_LDADD=../libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS)
+TEST_LDADD=../libxservertest.la $(XORG_SYS_LIBS) $(XSERVER_SYS_LIBS) $(GLX_SYS_LIBS)
 COMMON_SOURCES=protocol-common.h protocol-common.c
 
 if SPECIAL_DTRACE_OBJECTS
commit 014ad46f1b353a95e2c4289443ee857cfbabb3ae
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Jun 21 14:26:15 2012 +1000

    os: print newline after printing display name
    
    Much easier for scripts that try to read the display value off the file
    descriptor. Plus, this restores the behaviour we had for this patch in
    Fedora since server 1.6 (April 2009).
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/os/connection.c b/os/connection.c
index 039942f..3441472 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -353,6 +353,7 @@ NotifyParentProcess(void)
 #if !defined(WIN32)
     if (dynamic_display[0]) {
         write(displayfd, dynamic_display, strlen(dynamic_display));
+        write(displayfd, "\n", 1);
         close(displayfd);
     }
     if (RunFromSmartParent) {
commit e1f86a7c77ed49e001ea42ef76ab83e87dbdf126
Author: Sergei Trofimovich <slyfox at gentoo.org>
Date:   Mon Jun 18 01:13:21 2012 +0300

    test/.gitignore: add hashtabletest
    
    Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/test/.gitignore b/test/.gitignore
index 5d4fdfa..23d4c8f 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,4 +1,5 @@
 fixes
+hashtabletest
 input
 list
 misc
commit c9bbf8fe574591c8e191eeef20f8994781718772
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Jun 21 19:38:55 2012 +0100

    hw/xwin/glx: Fix glxWinCreateContext() function pointer mismatch
    
    Fix glxWinCreateContext() function signature to align with commit 96d74138
    "glx: Extend __GLXscreen::createContext to take attributes", which added more
    parameters to the screen createContext function for implementing GLX_ARB_create_context
    
    indirect.c: In function 'glxWinScreenProbe':
    indirect.c:683:36: warning: assignment from incompatible pointer type
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c
index 0582569..3f34146 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -398,7 +398,9 @@ fbConfigsDump(unsigned int n, __GLXconfig * c)
 static __GLXscreen *glxWinScreenProbe(ScreenPtr pScreen);
 static __GLXcontext *glxWinCreateContext(__GLXscreen * screen,
                                          __GLXconfig * modes,
-                                         __GLXcontext * baseShareContext);
+                                         __GLXcontext * baseShareContext,
+                                         unsigned num_attribs,
+                                         const uint32_t * attribs, int *error);
 static __GLXdrawable *glxWinCreateDrawable(ClientPtr client,
                                            __GLXscreen * screen,
                                            DrawablePtr pDraw,
@@ -1582,7 +1584,8 @@ glxWinContextDestroy(__GLXcontext * base)
 
 static __GLXcontext *
 glxWinCreateContext(__GLXscreen * screen,
-                    __GLXconfig * modes, __GLXcontext * baseShareContext)
+                    __GLXconfig * modes, __GLXcontext * baseShareContext,
+                    unsigned num_attribs, const uint32_t * attribs, int *error)
 {
     __GLXWinContext *context;
     __GLXWinContext *shareContext = (__GLXWinContext *) baseShareContext;
commit 6e85660c7503c7e88e24003562444dffde6c88ff
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Mar 5 23:07:56 2012 +0000

    hw/xwin/glx: Update gen_gl_wrappers.py for the current glx/dispatch.h
    
    Fix the code generator for the dispatch table initialization after
    the whitespace/coding style changes to glx/dispatch.h
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/glx/gen_gl_wrappers.py b/hw/xwin/glx/gen_gl_wrappers.py
index d86acc8..15f7ef8 100755
--- a/hw/xwin/glx/gen_gl_wrappers.py
+++ b/hw/xwin/glx/gen_gl_wrappers.py
@@ -67,7 +67,7 @@ if dispatchheader :
         fh = open(dispatchheader)
         dispatchh = fh.readlines()
 
-        dispatch_regex = re.compile(r'#define\sSET_(\S*)\(')
+        dispatch_regex = re.compile(r'^SET_(\S*)\(')
 
         for line in dispatchh :
                 line = line.strip()
commit cb638ed9c81f07d8603b07db395e31a41fed8685
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Jun 21 18:55:57 2012 +0100

    hw/xwin/glx: Blacklist 'GDI generic' GL renderer
    
    If the native GL renderer is the GDI generic renderer (as can happen
    if we are in safe mode, or the video driver is VGA, or we have hybrid
    graphics which hasn't noticed that xwin requires 3d acceleration), don't
    use it.  It's not accelerated and we will probably get better conformance
    and perfomance from swrast.
    
    Fix so we don't install screen function wrappers in glxWinScreenProbe
    unless we are succesful.
    
    Also, move fbConfig dumping to after GLX version has been determined
    from extensions
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c
index 41b4cd8..0582569 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -517,6 +517,7 @@ glxWinScreenProbe(ScreenPtr pScreen)
 {
     glxWinScreen *screen;
     const char *gl_extensions;
+    const char *gl_renderer;
     const char *wgl_extensions;
     HWND hwnd;
     HDC hdc;
@@ -540,14 +541,6 @@ glxWinScreenProbe(ScreenPtr pScreen)
     if (NULL == screen)
         return NULL;
 
-    /* Wrap RealizeWindow, UnrealizeWindow and CopyWindow on this screen */
-    screen->RealizeWindow = pScreen->RealizeWindow;
-    pScreen->RealizeWindow = glxWinRealizeWindow;
-    screen->UnrealizeWindow = pScreen->UnrealizeWindow;
-    pScreen->UnrealizeWindow = glxWinUnrealizeWindow;
-    screen->CopyWindow = pScreen->CopyWindow;
-    pScreen->CopyWindow = glxWinCopyWindow;
-
     /* Dump out some useful information about the native renderer */
 
     // create window class
@@ -597,7 +590,8 @@ glxWinScreenProbe(ScreenPtr pScreen)
 
     ErrorF("GL_VERSION:     %s\n", glGetStringWrapperNonstatic(GL_VERSION));
     ErrorF("GL_VENDOR:      %s\n", glGetStringWrapperNonstatic(GL_VENDOR));
-    ErrorF("GL_RENDERER:    %s\n", glGetStringWrapperNonstatic(GL_RENDERER));
+    gl_renderer = (const char *) glGetStringWrapperNonstatic(GL_RENDERER);
+    ErrorF("GL_RENDERER:    %s\n", gl_renderer);
     gl_extensions = (const char *) glGetStringWrapperNonstatic(GL_EXTENSIONS);
     glxLogExtensions("GL_EXTENSIONS:  ", gl_extensions);
     wgl_extensions = wglGetExtensionsStringARBWrapper(hdc);
@@ -605,6 +599,13 @@ glxWinScreenProbe(ScreenPtr pScreen)
         wgl_extensions = "";
     glxLogExtensions("WGL_EXTENSIONS: ", wgl_extensions);
 
+    if (strcasecmp(gl_renderer, "GDI Generic") == 0) {
+        free(screen);
+        LogMessage(X_ERROR,
+                   "AIGLX: Won't use generic native renderer as it is not accelerated\n");
+        return NULL;
+    }
+
     // Can you see the problem here?  The extensions string is DC specific
     // Different DCs for windows on a multimonitor system driven by multiple cards
     // might have completely different capabilities.  Of course, good luck getting
@@ -722,9 +723,6 @@ glxWinScreenProbe(ScreenPtr pScreen)
 
         __glXScreenInit(&screen->base, pScreen);
 
-        // dump out fbConfigs now fbConfigIds and visualIDs have been assigned
-        fbConfigsDump(screen->base.numFBConfigs, screen->base.fbconfigs);
-
         // Override the GL extensions string set by __glXScreenInit()
         screen->base.GLextensions = strdup(gl_extensions);
 
@@ -767,6 +765,17 @@ glxWinScreenProbe(ScreenPtr pScreen)
     ReleaseDC(hwnd, hdc);
     DestroyWindow(hwnd);
 
+    // dump out fbConfigs now fbConfigIds and visualIDs have been assigned
+    fbConfigsDump(screen->base.numFBConfigs, screen->base.fbconfigs);
+
+    /* Wrap RealizeWindow, UnrealizeWindow and CopyWindow on this screen */
+    screen->RealizeWindow = pScreen->RealizeWindow;
+    pScreen->RealizeWindow = glxWinRealizeWindow;
+    screen->UnrealizeWindow = pScreen->UnrealizeWindow;
+    pScreen->UnrealizeWindow = glxWinUnrealizeWindow;
+    screen->CopyWindow = pScreen->CopyWindow;
+    pScreen->CopyWindow = glxWinCopyWindow;
+
     return &screen->base;
 }
 
commit 8c24d20933ba9c2ef0e9a81815c3be23fa896aea
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Jun 21 18:05:24 2012 +0100

    hw/xwin/glx: Fix glxLogExtensions to handle a null string without crashing
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c
index 56f677a..41b4cd8 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -473,7 +473,7 @@ static void
 glxLogExtensions(const char *prefix, const char *extensions)
 {
     int length = 0;
-    char *strl;
+    const char *strl;
     char *str = strdup(extensions);
 
     if (str == NULL) {
@@ -482,6 +482,8 @@ glxLogExtensions(const char *prefix, const char *extensions)
     }
 
     strl = strtok(str, " ");
+    if (strl == NULL)
+        strl = "";
     ErrorF("%s%s", prefix, strl);
     length = strlen(prefix) + strlen(strl);
 
commit c08c7c8f655d7721c1e02bfeeb965b6379f72553
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Jun 24 13:32:10 2011 +0100

    hw/xwin/glx: Create a new dispatch table rather than modifying the existing one
    
    Create a new dispatch table rather than modifying the existing one
    
    struct _glapi_table is not a complete type after including glapi.h, so we use
    glapi_get_dispatch_table_size() to determine it's size (alternatively, we could
    include glapitable.h, to complete the type)
    
    This could possibly be written to use _glapi_create_table_from_handle() instead, but
    that requires making all the wrapper functions exports
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/glx/gen_gl_wrappers.py b/hw/xwin/glx/gen_gl_wrappers.py
index e2d960e..d86acc8 100755
--- a/hw/xwin/glx/gen_gl_wrappers.py
+++ b/hw/xwin/glx/gen_gl_wrappers.py
@@ -308,12 +308,20 @@ for w in sorted(wrappers.keys()) :
 if dispatchheader :
         print 'void glWinSetupDispatchTable(void)'
         print '{'
-        print '  struct _glapi_table *disp = _glapi_get_dispatch();'
+        print '  static struct _glapi_table *disp = NULL;'
+        print ''
+        print '  if (!disp)'
+        print '    {'
+        print '      disp = calloc(sizeof(void *), _glapi_get_dispatch_table_size());'
+        print '      assert(disp);'
 
         for d in sorted(dispatch.keys()) :
                 if wrappers.has_key(d) :
-                        print '  SET_'+ d + '(disp, (void *)' + prefix + d + 'Wrapper);'
+                        print '      SET_'+ d + '(disp, (void *)' + prefix + d + 'Wrapper);'
                 else :
                         print '#warning  No wrapper for ' + prefix + d + ' !'
 
+        print '    }'
+        print ''
+        print '  _glapi_set_dispatch(disp);'
         print '}'
commit 3ef3ce069d52dcfa932c90ccd30854a8d9daa15a
Merge: a0c8716 ff541e0
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jun 21 08:52:34 2012 -0700

    Merge remote-tracking branch 'alanc/master'

commit 704b847abfd29e9adde27127a15a963414f8bcf4
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 6 10:13:45 2012 -0700

    Add FormatUInt64{,Hex}() for formatting numbers in a signal safe manner
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/include/misc.h b/include/misc.h
index fea74b8..6ae020a 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -229,6 +229,8 @@ pad_to_int32(const int bytes)
 }
 
 extern char **xstrtokenize(const char *str, const char *separators);
+extern void FormatUInt64(uint64_t num, char *string);
+extern void FormatUInt64Hex(uint64_t num, char *string);
 
 /**
  * Compare the two version numbers comprising of major.minor.
diff --git a/os/utils.c b/os/utils.c
index 2f07548..998c3ed 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1793,3 +1793,47 @@ xstrtokenize(const char *str, const char *separators)
     free(list);
     return NULL;
 }
+
+/* Format a number into a string in a signal safe manner. The string should be
+ * at least 21 characters in order to handle all uint64_t values. */
+void
+FormatUInt64(uint64_t num, char *string)
+{
+    uint64_t divisor;
+    int len;
+    int i;
+
+    for (len = 1, divisor = 10;
+         len < 20 && num / divisor;
+         len++, divisor *= 10);
+
+    for (i = len, divisor = 1; i > 0; i--, divisor *= 10)
+        string[i - 1] = '0' + ((num / divisor) % 10);
+
+    string[len] = '\0';
+}
+
+/* Format a number into a hexadecimal string in a signal safe manner. The string
+ * should be at least 17 characters in order to handle all uint64_t values. */
+void
+FormatUInt64Hex(uint64_t num, char *string)
+{
+    uint64_t divisor;
+    int len;
+    int i;
+
+    for (len = 1, divisor = 0x10;
+         len < 16 && num / divisor;
+         len++, divisor *= 0x10);
+
+    for (i = len, divisor = 1; i > 0; i--, divisor *= 0x10) {
+        int val = (num / divisor) % 0x10;
+
+        if (val < 10)
+            string[i - 1] = '0' + val;
+        else
+            string[i - 1] = 'a' + val - 10;
+    }
+
+    string[len] = '\0';
+}
diff --git a/test/.gitignore b/test/.gitignore
index 5d4fdfa..27eb254 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -7,3 +7,4 @@ touch
 xfree86
 xkb
 xtest
+signal-logging
diff --git a/test/Makefile.am b/test/Makefile.am
index b2a53aa..c049b26 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -5,7 +5,7 @@ if XORG
 # Tests that require at least some DDX functions in order to fully link
 # For now, requires xf86 ddx, could be adjusted to use another
 SUBDIRS += xi2
-noinst_PROGRAMS += xkb input xtest misc fixes xfree86  hashtabletest
+noinst_PROGRAMS += xkb input xtest misc fixes xfree86 hashtabletest signal-logging
 endif
 check_LTLIBRARIES = libxservertest.la
 
@@ -36,6 +36,7 @@ misc_LDADD=$(TEST_LDADD)
 fixes_LDADD=$(TEST_LDADD)
 xfree86_LDADD=$(TEST_LDADD)
 touch_LDADD=$(TEST_LDADD)
+signal_logging_LDADD=$(TEST_LDADD)
 hashtabletest_LDADD=$(TEST_LDADD) $(top_srcdir)/Xext/hashtable.c
 
 libxservertest_la_LIBADD = $(XSERVER_LIBS)
diff --git a/test/signal-logging.c b/test/signal-logging.c
new file mode 100644
index 0000000..8aab0dd
--- /dev/null
+++ b/test/signal-logging.c
@@ -0,0 +1,115 @@
+/**
+ * Copyright © 2012 Canonical, Ltd.
+ *
+ *  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, and to permit persons to whom the
+ *  Software is furnished to do so, subject to the following conditions:
+ *
+ *  The above copyright notice and this permission notice (including the next
+ *  paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdint.h>
+#include "assert.h"
+#include "misc.h"
+
+struct number_format_test {
+    uint64_t number;
+    char string[21];
+    char hex_string[17];
+};
+
+static Bool
+check_number_format_test(const struct number_format_test *test)
+{
+    char string[21];
+
+    FormatUInt64(test->number, string);
+    if(strncmp(string, test->string, 21) != 0) {
+        fprintf(stderr, "Failed to convert %ju to decimal string (%s vs %s)\n",
+                test->number, test->string, string);
+        return FALSE;
+    }
+    FormatUInt64Hex(test->number, string);
+    if(strncmp(string, test->hex_string, 17) != 0) {
+        fprintf(stderr,
+                "Failed to convert %ju to hexadecimal string (%s vs %s)\n",
+                test->number, test->hex_string, string);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static Bool
+number_formatting(void)
+{
+    int i;
+    struct number_format_test tests[] = {
+        { /* Zero */
+            0,
+            "0",
+            "0",
+        },
+        { /* Single digit number */
+            5,
+            "5",
+            "5",
+        },
+        { /* Two digit decimal number */
+            12,
+            "12",
+            "c",
+        },
+        { /* Two digit hex number */
+            37,
+            "37",
+            "25",
+        },
+        { /* Large < 32 bit number */
+            0xC90B2,
+            "823474",
+            "c90b2",
+        },
+        { /* Large > 32 bit number */
+            0x15D027BF211B37A,
+            "98237498237498234",
+            "15d027bf211b37a",
+        },
+        { /* Maximum 64-bit number */
+            0xFFFFFFFFFFFFFFFF,
+            "18446744073709551615",
+            "ffffffffffffffff",
+        },
+    };
+
+    for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
+        if (!check_number_format_test(tests + i))
+            return FALSE;
+
+    return TRUE;
+}
+
+int
+main(int argc, char **argv)
+{
+    int ok = number_formatting();
+
+    return ok ? 0 : 1;
+}
commit bc85c81687a24aea738094ff11f4448fb3b3afbb
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 6 08:03:09 2012 -0700

    Save log file file descriptor for signal context logging
    
    None of the FILE based functions are signal safe, including fileno(), so
    we need to save the file descriptor for when we are in signal context.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/os/log.c b/os/log.c
index 2c13c1a..5394847 100644
--- a/os/log.c
+++ b/os/log.c
@@ -108,6 +108,7 @@ void (*OsVendorVErrorFProc) (const char *, va_list args) = NULL;
 #endif
 
 static FILE *logFile = NULL;
+static int logFileFd = -1;
 static Bool logFlush = FALSE;
 static Bool logSync = FALSE;
 static int logVerbosity = DEFAULT_LOG_VERBOSITY;
@@ -211,6 +212,8 @@ LogInit(const char *fname, const char *backup)
             FatalError("Cannot open log file \"%s\"\n", logFileName);
         setvbuf(logFile, NULL, _IONBF, 0);
 
+        logFileFd = fileno(logFile);
+
         /* Flush saved log information. */
         if (saveBuffer && bufferSize > 0) {
             fwrite(saveBuffer, bufferPos, 1, logFile);
@@ -243,6 +246,7 @@ LogClose(enum ExitCode error)
                (error == EXIT_NO_ERROR) ? "successfully" : "with error", error);
         fclose(logFile);
         logFile = NULL;
+        logFileFd = -1;
     }
 }
 
commit d3725549f0276487fba1d419094209d18e86669f
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 6 07:43:57 2012 -0700

    Add global variable inSignalContext
    
    This will be used for checking for proper logging when in signal
    context.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/os-support/shared/sigio.c b/hw/xfree86/os-support/shared/sigio.c
index 12ae8a4..231d6c0 100644
--- a/hw/xfree86/os-support/shared/sigio.c
+++ b/hw/xfree86/os-support/shared/sigio.c
@@ -99,6 +99,8 @@ xf86SIGIO(int sig)
     int save_errno = errno;     /* do not clobber the global errno */
     int r;
 
+    inSignalContext = TRUE;
+
     ready = xf86SigIOMask;
     to.tv_sec = 0;
     to.tv_usec = 0;
@@ -114,6 +116,8 @@ xf86SIGIO(int sig)
     }
     /* restore global errno */
     errno = save_errno;
+
+    inSignalContext = FALSE;
 }
 
 static int
diff --git a/include/globals.h b/include/globals.h
index 8076955..6d3f3d7 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -2,6 +2,8 @@
 #ifndef _XSERV_GLOBAL_H_
 #define _XSERV_GLOBAL_H_
 
+#include <signal.h>
+
 #include "window.h"             /* for WindowPtr */
 
 /* Global X server variables that are visible to mi, dix, os, and ddx */
@@ -23,6 +25,7 @@ extern _X_EXPORT int GrabInProgress;
 extern _X_EXPORT Bool noTestExtensions;
 extern _X_EXPORT char *SeatId;
 extern _X_EXPORT char *ConnectionInfo;
+extern _X_EXPORT sig_atomic_t inSignalContext;
 
 #ifdef DPMSExtension
 extern _X_EXPORT CARD32 DPMSStandbyTime;
diff --git a/os/utils.c b/os/utils.c
index 3a1ef93..2f07548 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -204,6 +204,8 @@ int auditTrailLevel = 1;
 
 char *SeatId = NULL;
 
+sig_atomic_t inSignalContext = FALSE;
+
 #if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
 #define HAS_SAVED_IDS_AND_SETEUID
 #endif
commit a0c8716cdca139059e7aec8a3cb75726dd37a4a1
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Jun 21 13:45:06 2012 +1000

    kdrive: adjust BlockHandler/WakeupHandler to new API
    
    Missing API update caused Xephyr to crash on startup, garbage memory
    dereference when accessing timeout.
    Introduced in 1f0e8bd5eb1a5539689cfc4f5a6b86b530907ec5
    
    kdrive.c:868:27: warning: assignment from incompatible pointer type
    kdrive.c:869:28: warning: assignment from incompatible pointer type
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index a08a218..b37041f 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -537,13 +537,11 @@ void
 
 void
 
-KdBlockHandler(ScreenPtr pScreen,
-               pointer blockData, pointer timeout, pointer readmask);
+KdBlockHandler(ScreenPtr pScreen, pointer timeout, pointer readmask);
 
 void
 
-KdWakeupHandler(ScreenPtr pScreen,
-                pointer data, unsigned long result, pointer readmask);
+KdWakeupHandler(ScreenPtr pScreen, unsigned long result, pointer readmask);
 
 void
  KdDisableInput(void);
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 58ae552..0e06fd4 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1972,7 +1972,7 @@ _KdEnqueuePointerEvent(KdPointerInfo * pi, int type, int x, int y, int z,
 }
 
 void
-KdBlockHandler(ScreenPtr pScreen, pointer blockData, pointer timeout, pointer readmask)
+KdBlockHandler(ScreenPtr pScreen, pointer timeout, pointer readmask)
 {
     KdPointerInfo *pi;
     int myTimeout = 0;
@@ -1998,8 +1998,7 @@ KdBlockHandler(ScreenPtr pScreen, pointer blockData, pointer timeout, pointer re
 }
 
 void
-KdWakeupHandler(ScreenPtr pScreen,
-                pointer data, unsigned long lresult, pointer readmask)
+KdWakeupHandler(ScreenPtr pScreen, unsigned long lresult, pointer readmask)
 {
     int result = (int) lresult;
     fd_set *pReadmask = (fd_set *) readmask;
commit ff541e0a1f84bd98966148793f35afeaf71c271b
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Wed Jun 13 21:20:51 2012 -0700

    Remove obsolete tab stop comments from hw/xfree86/parser/*.c
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/parser/Device.c b/hw/xfree86/parser/Device.c
index f27b56f..bb1ba88 100644
--- a/hw/xfree86/parser/Device.c
+++ b/hw/xfree86/parser/Device.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Files.c b/hw/xfree86/parser/Files.c
index d8152c0..0d3e47a 100644
--- a/hw/xfree86/parser/Files.c
+++ b/hw/xfree86/parser/Files.c
@@ -51,8 +51,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c
index 29a60a2..2461476 100644
--- a/hw/xfree86/parser/Flags.c
+++ b/hw/xfree86/parser/Flags.c
@@ -51,8 +51,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Input.c b/hw/xfree86/parser/Input.c
index 6e00734..ff2b9ac 100644
--- a/hw/xfree86/parser/Input.c
+++ b/hw/xfree86/parser/Input.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c
index 8493685..de6a816 100644
--- a/hw/xfree86/parser/InputClass.c
+++ b/hw/xfree86/parser/InputClass.c
@@ -23,8 +23,6 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Layout.c b/hw/xfree86/parser/Layout.c
index bd33d6d..cbd8d24 100644
--- a/hw/xfree86/parser/Layout.c
+++ b/hw/xfree86/parser/Layout.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Module.c b/hw/xfree86/parser/Module.c
index 1c458ae..87ddfc6 100644
--- a/hw/xfree86/parser/Module.c
+++ b/hw/xfree86/parser/Module.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Monitor.c b/hw/xfree86/parser/Monitor.c
index b237dfb..36b4ebe 100644
--- a/hw/xfree86/parser/Monitor.c
+++ b/hw/xfree86/parser/Monitor.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Pointer.c b/hw/xfree86/parser/Pointer.c
index cdbc09c..ff748d9 100644
--- a/hw/xfree86/parser/Pointer.c
+++ b/hw/xfree86/parser/Pointer.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Screen.c b/hw/xfree86/parser/Screen.c
index 71778d8..f294ec4 100644
--- a/hw/xfree86/parser/Screen.c
+++ b/hw/xfree86/parser/Screen.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Vendor.c b/hw/xfree86/parser/Vendor.c
index b4e2165..9b7695c 100644
--- a/hw/xfree86/parser/Vendor.c
+++ b/hw/xfree86/parser/Vendor.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/Video.c b/hw/xfree86/parser/Video.c
index fc1f1e5..68d611a 100644
--- a/hw/xfree86/parser/Video.c
+++ b/hw/xfree86/parser/Video.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/read.c b/hw/xfree86/parser/read.c
index eef873e..6545bcd 100644
--- a/hw/xfree86/parser/read.c
+++ b/hw/xfree86/parser/read.c
@@ -52,8 +52,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index 795da61..f852b83 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -51,8 +51,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
diff --git a/hw/xfree86/parser/write.c b/hw/xfree86/parser/write.c
index c001c3d..9c706a0 100644
--- a/hw/xfree86/parser/write.c
+++ b/hw/xfree86/parser/write.c
@@ -51,8 +51,6 @@
  * authorization from the copyright holder(s) and author(s).
  */
 
-/* View/edit this file with tab stops set to 4 */
-
 #ifdef HAVE_XORG_CONFIG_H
 #include <xorg-config.h>
 #endif
commit 687536b1044a3297f6b9a45f6a2d2987daa7be59
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Jun 12 22:38:46 2012 -0700

    Fix some overly indented/poorly line wrapped comments in dix/events.c
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/events.c b/dix/events.c
index f571329..89877a1 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4347,12 +4347,10 @@ EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask)
             return rc;
     }
     check = (mask & AtMostOneClient);
-    if (check & (pWin->eventMask | wOtherEventMasks(pWin))) {   /* It is illegal for two different
-                                                                   clients to select on any of the
-                                                                   events for AtMostOneClient. However,
-                                                                   it is OK, for some client to
-                                                                   continue selecting on one of those
-                                                                   events.  */
+    if (check & (pWin->eventMask | wOtherEventMasks(pWin))) {
+        /* It is illegal for two different clients to select on any of the
+           events for AtMostOneClient. However, it is OK, for some client to
+           continue selecting on one of those events.  */
         if ((wClient(pWin) != client) && (check & pWin->eventMask))
             return BadAccess;
         for (others = wOtherClients(pWin); others; others = others->next) {
@@ -5632,8 +5630,8 @@ DeleteWindowFromAnyEvents(WindowPtr pWin, Bool freeResources)
         if (IsKeyboardDevice(keybd)) {
             focus = keybd->focus;
 
-            /* If the focus window is a root window (ie. has no parent) then don't
-               delete the focus from it. */
+            /* If the focus window is a root window (ie. has no parent)
+               then don't delete the focus from it. */
 
             if ((pWin == focus->win) && (pWin->parent != NullWindow)) {
                 int focusEventMode = NotifyNormal;
@@ -5655,12 +5653,12 @@ DeleteWindowFromAnyEvents(WindowPtr pWin, Bool freeResources)
                         parent = parent->parent;
                         focus->traceGood--;
                     } while (!parent->realized
-                             /* This would be a good protocol change -- windows being reparented
-                                during SaveSet processing would cause the focus to revert to the
-                                nearest enclosing window which will survive the death of the exiting
-                                client, instead of ending up reverting to a dying window and thence
-                                to None
-                              */
+                    /* This would be a good protocol change -- windows being
+                       reparented during SaveSet processing would cause the
+                       focus to revert to the nearest enclosing window which
+                       will survive the death of the exiting client, instead
+                       of ending up reverting to a dying window and thence
+                       to None */
 #ifdef NOTDEF
                              || wClient(parent)->clientGone
 #endif
commit 93a378aad4a4a03f37ddafccfedeb9d6e2be2a6a
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Tue Jun 12 22:29:51 2012 -0700

    OtherClientGone: Remove unreachable return statement
    
    Now that FatalError is marked as _X_NORETURN, the compilers know we
    can't get here, and the return statement added to make them happy in
    the past now makes them unhappy.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/events.c b/dix/events.c
index 49894fa..f571329 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4325,7 +4325,6 @@ OtherClientGone(pointer value, XID id)
         prev = other;
     }
     FatalError("client not on event list");
-     /*NOTREACHED*/ return -1;  /* make compiler happy */
 }
 
 int
commit 3f97284b10c250457888902debd4d793cb4544d4
Author: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
Date:   Wed Jun 20 13:53:53 2012 +1000

    dri2: Pass a ScreenPtr through to the driver's AuthMagic function. (v3)
    
    xwayland drivers need access to their screen private data to authenticate.
    Now that drivers no longer have direct access to the global screen arrays,
    this needs to be passed in as function context.
    
    v2: Don't break ABI
    v3: Paint the bikeshed blue; drop fd from AuthMagic2ProcPtr prototype
    
    Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
    Reviewed-by: Kristian Høgsberg <krh at bitplanet.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index babf32f..d0f1789 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -104,7 +104,8 @@ typedef struct _DRI2Screen {
     DRI2ScheduleSwapProcPtr ScheduleSwap;
     DRI2GetMSCProcPtr GetMSC;
     DRI2ScheduleWaitMSCProcPtr ScheduleWaitMSC;
-    DRI2AuthMagicProcPtr AuthMagic;
+    DRI2AuthMagic2ProcPtr AuthMagic;
+    DRI2AuthMagicProcPtr LegacyAuthMagic;
     DRI2ReuseBufferNotifyProcPtr ReuseBufferNotify;
     DRI2SwapLimitValidateProcPtr SwapLimitValidate;
     DRI2GetParamProcPtr GetParam;
@@ -1110,12 +1111,22 @@ DRI2Connect(ScreenPtr pScreen, unsigned int driverType, int *fd,
     return TRUE;
 }
 
+static Bool
+DRI2AuthMagic (ScreenPtr pScreen, uint32_t magic)
+{
+    DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
+    if (ds == NULL || (*ds->LegacyAuthMagic) (ds->fd, magic))
+        return FALSE;
+
+    return TRUE;
+}
+
 Bool
 DRI2Authenticate(ScreenPtr pScreen, uint32_t magic)
 {
     DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
 
-    if (ds == NULL || (*ds->AuthMagic) (ds->fd, magic))
+    if (ds == NULL || (*ds->AuthMagic) (pScreen, magic))
         return FALSE;
 
     return TRUE;
@@ -1202,8 +1213,11 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
         cur_minor = 1;
     }
 
+    if (info->version >= 8) {
+        ds->AuthMagic = info->AuthMagic2;
+    }
     if (info->version >= 5) {
-        ds->AuthMagic = info->AuthMagic;
+        ds->LegacyAuthMagic = info->AuthMagic;
     }
 
     if (info->version >= 6) {
@@ -1218,14 +1232,21 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
 
     /*
      * if the driver doesn't provide an AuthMagic function or the info struct
-     * version is too low, it relies on the old method (using libdrm) or fail
+     * version is too low, call through LegacyAuthMagic
      */
-    if (!ds->AuthMagic)
+    if (!ds->AuthMagic) {
+        ds->AuthMagic = DRI2AuthMagic;
+        /*
+         * If the driver doesn't provide an AuthMagic function
+         * it relies on the old method (using libdrm) or fails
+         */
+        if (!ds->LegacyAuthMagic)
 #ifdef WITH_LIBDRM
-        ds->AuthMagic = drmAuthMagic;
+            ds->LegacyAuthMagic = drmAuthMagic;
 #else
-        goto err_out;
+            goto err_out;
 #endif
+    }
 
     /* Initialize minor if needed and set to minimum provied by DDX */
     if (!dri2_minor || dri2_minor > cur_minor)
diff --git a/hw/xfree86/dri2/dri2.h b/hw/xfree86/dri2/dri2.h
index f849be6..4fd0fbc 100644
--- a/hw/xfree86/dri2/dri2.h
+++ b/hw/xfree86/dri2/dri2.h
@@ -64,6 +64,7 @@ typedef void (*DRI2CopyRegionProcPtr) (DrawablePtr pDraw,
                                        DRI2BufferPtr pSrcBuffer);
 typedef void (*DRI2WaitProcPtr) (WindowPtr pWin, unsigned int sequence);
 typedef int (*DRI2AuthMagicProcPtr) (int fd, uint32_t magic);
+typedef int (*DRI2AuthMagic2ProcPtr) (ScreenPtr pScreen, uint32_t magic);
 
 /**
  * Schedule a buffer swap
@@ -192,7 +193,7 @@ typedef int (*DRI2GetParamProcPtr) (ClientPtr client,
 /**
  * Version of the DRI2InfoRec structure defined in this header
  */
-#define DRI2INFOREC_VERSION 7
+#define DRI2INFOREC_VERSION 8
 
 typedef struct {
     unsigned int version;       /**< Version of this struct */
@@ -229,6 +230,12 @@ typedef struct {
     /* added in version 7 */
 
     DRI2GetParamProcPtr GetParam;
+
+    /* added in version 8 */
+    /* AuthMagic callback which passes extra context */
+    /* If this is NULL the AuthMagic callback is used */
+    /* If this is non-NULL the AuthMagic callback is ignored */
+    DRI2AuthMagic2ProcPtr AuthMagic2;
 } DRI2InfoRec, *DRI2InfoPtr;
 
 extern _X_EXPORT int DRI2EventBase;
commit dae317e7265007b38012244722e3b3a06e904ed5
Author: Andy Ritger <aritger at nvidia.com>
Date:   Thu Jun 14 09:15:37 2012 -0700

    randr: Don't recurse into mieqProcessInputEvents() from RRTellChanged().
    
    Call UpdateCurrentTimeIf(), not UpdateCurrentTime(), from RRTellChanged().
    The latter calls ProcessInputEvents(), which can trigger a recursion
    into mieqProcessInputEvents().  The former omits the call to
    ProcessInputEvents().
    
    Signed-off-by: Andy Ritger <aritger at nvidia.com>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/randr/randr.c b/randr/randr.c
index a64aae3..4d4298a 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -416,7 +416,7 @@ RRTellChanged(ScreenPtr pScreen)
     int i;
 
     if (pScrPriv->changed) {
-        UpdateCurrentTime();
+        UpdateCurrentTimeIf();
         if (pScrPriv->configChanged) {
             pScrPriv->lastConfigTime = currentTime;
             pScrPriv->configChanged = FALSE;
commit 54476b5e4461ff523e935961affabcf0de12c556
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu Jun 7 16:52:20 2012 +1000

    dix: if the scroll valuator reaches INT_MAX, reset to 0
    
    Too much scrolling down may eventually trigger an overflow of the valuator.
    If this happens, reset the valuator to 0 and skip this event for button
    emulation. Clients will have to figure out a way to deal with this, but a
    scroll event from (close to) INT_MAX to 0 is a hint of that it needs to be
    ignored.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/getevents.c b/dix/getevents.c
index baa26c4..7570852 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -35,6 +35,7 @@
 #include <X11/keysym.h>
 #include <X11/Xproto.h>
 #include <math.h>
+#include <limits.h>
 
 #include "misc.h"
 #include "resource.h"
@@ -756,6 +757,29 @@ clipAbsolute(DeviceIntPtr dev, ValuatorMask *mask)
     }
 }
 
+static void
+add_to_scroll_valuator(DeviceIntPtr dev, ValuatorMask *mask, int valuator, double value)
+{
+    double v;
+
+    if (!valuator_mask_fetch_double(mask, valuator, &v))
+        return;
+
+    /* protect against scrolling overflow. INT_MAX for double, because
+     * we'll eventually write this as 32.32 fixed point */
+    if ((value > 0 && v > INT_MAX - value) || (value < 0 && v < INT_MIN - value)) {
+        v = 0;
+
+        /* reset last.scroll to avoid a button storm */
+        valuator_mask_set_double(dev->last.scroll, valuator, 0);
+    }
+    else
+        v += value;
+
+    valuator_mask_set_double(mask, valuator, v);
+}
+
+
 /**
  * Move the device's pointer by the values given in @valuators.
  *
@@ -774,13 +798,17 @@ moveRelative(DeviceIntPtr dev, ValuatorMask *mask)
 
         if (!valuator_mask_isset(mask, i))
             continue;
-        val += valuator_mask_get_double(mask, i);
+
+        add_to_scroll_valuator(dev, mask, i, val);
+
         /* x & y need to go over the limits to cross screens if the SD
          * isn't currently attached; otherwise, clip to screen bounds. */
         if (valuator_get_mode(dev, i) == Absolute &&
-            ((i != 0 && i != 1) || clip_xy))
+            ((i != 0 && i != 1) || clip_xy)) {
+            val = valuator_mask_get_double(mask, i);
             clipAxis(dev, i, &val);
-        valuator_mask_set_double(mask, i, val);
+            valuator_mask_set_double(mask, i, val);
+        }
     }
 }
 
@@ -1506,6 +1534,7 @@ emulate_scroll_button_events(InternalEvent *events,
     return num_events;
 }
 
+
 /**
  * Generate a complete series of InternalEvents (filled into the EventList)
  * representing pointer motion, or button presses.  If the device is a slave
@@ -1560,7 +1589,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
      * necessary. This only needs to cater for the XIScrollFlagPreferred
      * axis (if more than one scrolling axis is present) */
     if (type == ButtonPress) {
-        double val, adj;
+        double adj;
         int axis;
         int h_scroll_axis = -1;
         int v_scroll_axis = -1;
@@ -1596,8 +1625,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
 
         if (adj != 0.0 && axis != -1) {
             adj *= pDev->valuator->axes[axis].scroll.increment;
-            val = valuator_mask_get_double(&mask, axis) + adj;
-            valuator_mask_set_double(&mask, axis, val);
+            add_to_scroll_valuator(pDev, &mask, axis, adj);
             type = MotionNotify;
             buttons = 0;
             flags |= POINTER_EMULATED;
commit 8dc70acbf3d82611ac9ec1ec2a52edcc01934850
Merge: ffb47a1 b59adc9
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jun 14 13:04:29 2012 -0700

    Merge remote-tracking branch 'alanc/master'

commit ffb47a123ddd1233fb4229cf23483652065c5e82
Merge: db9d2b8 b840ba5
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jun 14 13:01:17 2012 -0700

    Merge remote-tracking branch 'idr/GLX_ARB_create_context'

commit db9d2b8a508ab812e5c717a41310faad81879b09
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jun 7 15:01:59 2012 +0100

    xserver: fix build on arm tinderbox
    
    Rob Clark got an ARM tinderbox up and running, and this code is built there
    but not here, this should fix it, though I hope that code never gets executed.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c
index 5343e47..4633120 100644
--- a/hw/xfree86/int10/generic.c
+++ b/hw/xfree86/int10/generic.c
@@ -179,7 +179,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
     vbiosMem = (char *) base + V_BIOS;
     memset(vbiosMem, 0, 2 * V_BIOS_SIZE);
     if (pci_device_read_rom(pInt->dev, vbiosMem) < V_BIOS_SIZE) {
-        xf86DrvMsg(screen, X_WARNING,
+        xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
                    "Unable to retrieve all of segment 0x0C0000.\n");
     }
 
@@ -194,10 +194,10 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
         vbiosMem = (unsigned char *) base + bios_location;
 
         if (xf86IsEntityPrimary(entityIndex)) {
-            if (int10_check_bios(screen, bios_location >> 4, vbiosMem))
+            if (int10_check_bios(pScrn->scrnIndex, bios_location >> 4, vbiosMem))
                 done = TRUE;
             else
-                xf86DrvMsg(screen, X_INFO,
+                xf86DrvMsg(pScrn->scrnIndex, X_INFO,
                            "No legacy BIOS found -- trying PCI\n");
         }
         if (!done) {
@@ -207,7 +207,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
 
             err = pci_device_read_rom(rom_device, vbiosMem);
             if (err) {
-                xf86DrvMsg(screen, X_ERROR, "Cannot read V_BIOS (5) %s\n",
+                xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Cannot read V_BIOS (5) %s\n",
                            strerror(err));
                 goto error1;
             }
commit 6d86b64dbaef5a16712fd1fdc3157f716d238877
Merge: 812786f 4c68f5d
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jun 14 11:05:22 2012 -0700

    Merge remote-tracking branch 'whot/for-keith'

commit b59adc9c2427e5efac3513c20992723e23f92691
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Thu Jun 7 20:58:01 2012 -0700

    Make stub version of fbdevHWAdjustFrame match new prototype in fbdevhw.h
    
    Removed flags argument to match api rework in commit 1f0e8bd5eb1a55
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/fbdevhw/fbdevhwstub.c b/hw/xfree86/fbdevhw/fbdevhwstub.c
index b7b4d2e..7d554e6 100644
--- a/hw/xfree86/fbdevhw/fbdevhwstub.c
+++ b/hw/xfree86/fbdevhw/fbdevhwstub.c
@@ -143,7 +143,7 @@ fbdevHWSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 }
 
 void
-fbdevHWAdjustFrame(ScrnInfoPtr pScrn, int x, int y, int flags)
+fbdevHWAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
 {
 }
 
commit 4c68f5d395c66f28b56e488cb3cd12f36820357b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed May 9 09:21:28 2012 +1000

    dix: disable all devices before shutdown
    
    f3410b97cf9b48a47bee3d15d232f8a88e75f4ef introduced a regression on server
    shutdown. If any button or key was held on shutdown (ctrl, alt, backspace
    are usually still down) sending a raw event will segfault the server. The
    the root windows are set to NULL before calling CloseDownDevices().
    
    Avoid this by disabling all devices first when shutting down. Disabled
    devices won't send events anymore.
    
    Master keyboards must be disabled first, otherwise disabling the pointer
    will trigger DisableDevice(keyboard) and the keyboard is removed from the
    inputInfo.devices list and moved to inputInfo.off_devices. A regular loop
    through inputInfo.devices would thus jump to off_devices and not recover.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Acked-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/devices.c b/dix/devices.c
index c5a713f..08875bc 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -501,6 +501,26 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent)
     return TRUE;
 }
 
+void
+DisableAllDevices(void)
+{
+    DeviceIntPtr dev, tmp;
+
+    nt_list_for_each_entry_safe(dev, tmp, inputInfo.devices, next) {
+        if (!IsMaster(dev))
+            DisableDevice(dev, FALSE);
+    }
+    /* master keyboards need to be disabled first */
+    nt_list_for_each_entry_safe(dev, tmp, inputInfo.devices, next) {
+        if (dev->enabled && IsMaster(dev) && IsKeyboardDevice(dev))
+            DisableDevice(dev, FALSE);
+    }
+    nt_list_for_each_entry_safe(dev, tmp, inputInfo.devices, next) {
+        if (dev->enabled)
+            DisableDevice(dev, FALSE);
+    }
+}
+
 /**
  * Initialise a new device through the driver and tell all clients about the
  * new device.
diff --git a/dix/main.c b/dix/main.c
index 70dcc94..df9023e 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -104,6 +104,7 @@ Equipment Corporation.
 #include "privates.h"
 #include "registry.h"
 #include "client.h"
+#include "exevents.h"
 #ifdef PANORAMIX
 #include "panoramiXsrv.h"
 #else
@@ -295,6 +296,7 @@ main(int argc, char *argv[], char *envp[])
 #endif
 
         UndisplayDevices();
+        DisableAllDevices();
 
         /* Now free up whatever must be freed */
         if (screenIsSaved == SCREEN_SAVER_ON)
@@ -318,7 +320,9 @@ main(int argc, char *argv[], char *envp[])
 
         for (i = 0; i < screenInfo.numScreens; i++)
             screenInfo.screens[i]->root = NullWindow;
+
         CloseDownDevices();
+
         CloseDownEvents();
 
         for (i = screenInfo.numScreens - 1; i >= 0; i--) {
diff --git a/include/input.h b/include/input.h
index bcf98a6..5747f3c 100644
--- a/include/input.h
+++ b/include/input.h
@@ -264,7 +264,7 @@ extern _X_EXPORT Bool ActivateDevice(DeviceIntPtr /*device */ ,
 
 extern _X_EXPORT Bool DisableDevice(DeviceIntPtr /*device */ ,
                                     BOOL /* sendevent */ );
-
+extern void DisableAllDevices(void);
 extern int InitAndStartDevices(void);
 
 extern void CloseDownDevices(void);
commit 9c0e820216cd1631f75b037b7908d55ac091692c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 12:55:44 2012 +1000

    Xi: drop forced unpairing when changing the hierarchy
    
    Devices are unpaired as needed on DisableDevice now.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
index 756aaac..89f16d8 100644
--- a/Xi/xichangehierarchy.c
+++ b/Xi/xichangehierarchy.c
@@ -293,12 +293,6 @@ remove_master(ClientPtr client, xXIRemoveMasterInfo * r, int flags[MAXDEVICES])
         }
     }
 
-    /* can't disable until we removed pairing */
-    keybd->spriteInfo->paired = NULL;
-    ptr->spriteInfo->paired = NULL;
-    XTestptr->spriteInfo->paired = NULL;
-    XTestkeybd->spriteInfo->paired = NULL;
-
     /* disable the remove the devices, XTest devices must be done first
        else the sprites they rely on will be destroyed  */
     DisableDevice(XTestptr, FALSE);
commit e433d1046c222f9d969c2c28a4651ff9097614f4
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 12:42:59 2012 +1000

    dix: disable non-sprite-owners first when disabling paired devices
    
    If a sprite-owner is to be disabled but still paired, disable the paired
    device first. i.e. disabling a master pointer will disable the master
    keyboard first.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/devices.c b/dix/devices.c
index f134f31..c5a713f 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -458,10 +458,13 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent)
 
     if (IsMaster(dev) && dev->spriteInfo->sprite) {
         for (other = inputInfo.devices; other; other = other->next)
-            BUG_RETURN_VAL_MSG(other->spriteInfo->paired == dev, FALSE,
-                               "%s still paired with %s", dev->name, other->spriteInfo->paired->name);
+            if (other->spriteInfo->paired == dev && !other->spriteInfo->spriteOwner)
+                DisableDevice(other, sendevent);
     }
 
+    if (dev->spriteInfo->paired)
+        dev->spriteInfo->paired = NULL;
+
     (void) (*dev->deviceProc) (dev, DEVICE_OFF);
     dev->enabled = FALSE;
 
commit df1704365e700d3cf1d36a241bdfc479159a8df7
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 15:33:15 2012 +1000

    dix: free the sprite when disabling the device
    
    Disabled devices don't need sprites (they can't send events anyway) and the
    device init process is currently geared to check for whether sprite is
    present to check if the device should be paired/attached.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/devices.c b/dix/devices.c
index a280dee..f134f31 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -465,6 +465,8 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent)
     (void) (*dev->deviceProc) (dev, DEVICE_OFF);
     dev->enabled = FALSE;
 
+    FreeSprite(dev);
+
     /* now that the device is disabled, we can reset the signal handler's
      * last.slave */
     OsBlockSignals();
commit e57d6a89027c55fef987cdc259668c48a8b4ea1b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 15:32:20 2012 +1000

    dix: move freeing the sprite into a function
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/devices.c b/dix/devices.c
index 6acff4f..a280dee 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -918,12 +918,7 @@ CloseDevice(DeviceIntPtr dev)
         free(classes);
     }
 
-    if (DevHasCursor(dev) && dev->spriteInfo->sprite) {
-        if (dev->spriteInfo->sprite->current)
-            FreeCursor(dev->spriteInfo->sprite->current, None);
-        free(dev->spriteInfo->sprite->spriteTrace);
-        free(dev->spriteInfo->sprite);
-    }
+    FreeSprite(dev);
 
     /* a client may have the device set as client pointer */
     for (j = 0; j < currentMaxClients; j++) {
diff --git a/dix/events.c b/dix/events.c
index 83ae5c9..49894fa 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3192,6 +3192,18 @@ InitializeSprite(DeviceIntPtr pDev, WindowPtr pWin)
 #endif
 }
 
+void FreeSprite(DeviceIntPtr dev)
+{
+    if (DevHasCursor(dev) && dev->spriteInfo->sprite) {
+        if (dev->spriteInfo->sprite->current)
+            FreeCursor(dev->spriteInfo->sprite->current, None);
+        free(dev->spriteInfo->sprite->spriteTrace);
+        free(dev->spriteInfo->sprite);
+    }
+    dev->spriteInfo->sprite = NULL;
+}
+
+
 /**
  * Update the mouse sprite info when the server switches from a pScreen to another.
  * Otherwise, the pScreen of the mouse sprite is never updated when we switch
diff --git a/include/dix.h b/include/dix.h
index 5dc2ac5..3d8b0e5 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -395,6 +395,8 @@ DeliverTouchEvents(DeviceIntPtr /* dev */ ,
 extern void
 InitializeSprite(DeviceIntPtr /* pDev */ ,
                  WindowPtr /* pWin */ );
+extern void
+FreeSprite(DeviceIntPtr pDev);
 
 extern void
 UpdateSpriteForScreen(DeviceIntPtr /* pDev */ ,
commit 46adcefb0e08515195d8e49985a4e210395700b3
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 12:10:12 2012 +1000

    dix: return early from DisableDevice if the device is already disabled
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/devices.c b/dix/devices.c
index df46497..6acff4f 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -428,6 +428,9 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent)
     BOOL enabled;
     int flags[MAXDEVICES] = { 0 };
 
+    if (!dev->enabled)
+        return TRUE;
+
     for (prev = &inputInfo.devices;
          *prev && (*prev != dev); prev = &(*prev)->next);
     if (*prev != dev)
commit 076f9d3a6660fa7fef4ae9decaffd2feebdd32c4
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 12:20:37 2012 +1000

    dix: drop client argument from PairDevices - unused
    
    This is a leftover from early MPX days where any keyboard could be paired
    with any pointer (before the device hierarchy).
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/devices.c b/dix/devices.c
index c6fd3aa..df46497 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -178,12 +178,9 @@ DeviceSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
 
 /* Pair the keyboard to the pointer device. Keyboard events will follow the
  * pointer sprite. Only applicable for master devices.
- * If the client is set, the request to pair comes from some client. In this
- * case, we need to check for access. If the client is NULL, it's from an
- * internal automatic pairing, we must always permit this.
  */
 static int
-PairDevices(ClientPtr client, DeviceIntPtr ptr, DeviceIntPtr kbd)
+PairDevices(DeviceIntPtr ptr, DeviceIntPtr kbd)
 {
     if (!ptr)
         return BadDevice;
@@ -369,7 +366,7 @@ EnableDevice(DeviceIntPtr dev, BOOL sendevent)
                 other = NextFreePointerDevice();
                 BUG_RETURN_VAL_MSG(other == NULL, FALSE,
                                    "[dix] cannot find pointer to pair with.\n");
-                PairDevices(NULL, other, dev);
+                PairDevices(other, dev);
             }
         }
         else {
commit d034605f3914e41e0d636eafff9278be1c041b2c
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 14:13:20 2012 +1000

    dix: rename shadowing loop variable in TouchResizeQueue
    
    second 'i' shadows the function-wide one, rename to 'j'
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/touch.c b/dix/touch.c
index 082e8f6..aa17faf 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -103,11 +103,11 @@ TouchResizeQueue(ClientPtr client, pointer closure)
 
         tmp = realloc(dev->last.touches, size * sizeof(*dev->last.touches));
         if (tmp) {
-            int i;
+            int j;
 
             dev->last.touches = tmp;
-            for (i = dev->last.num_touches; i < size; i++)
-                TouchInitDDXTouchPoint(dev, &dev->last.touches[i]);
+            for (j = dev->last.num_touches; j < size; j++)
+                TouchInitDDXTouchPoint(dev, &dev->last.touches[j]);
             dev->last.num_touches = size;
         }
 
commit a86f3ef511db16be5ddc723bf14e770dad23ee45
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 11:55:21 2012 +1000

    dix: change "still paired warning" to use BUG_RETURN_VAL
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/dix/devices.c b/dix/devices.c
index bbb4fa2..c6fd3aa 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -457,13 +457,9 @@ DisableDevice(DeviceIntPtr dev, BOOL sendevent)
     }
 
     if (IsMaster(dev) && dev->spriteInfo->sprite) {
-        for (other = inputInfo.devices; other; other = other->next) {
-            if (other->spriteInfo->paired == dev) {
-                ErrorF("[dix] cannot disable device, still paired. "
-                       "This is a bug. \n");
-                return FALSE;
-            }
-        }
+        for (other = inputInfo.devices; other; other = other->next)
+            BUG_RETURN_VAL_MSG(other->spriteInfo->paired == dev, FALSE,
+                               "%s still paired with %s", dev->name, other->spriteInfo->paired->name);
     }
 
     (void) (*dev->deviceProc) (dev, DEVICE_OFF);
commit 4bcf43919a14cd2cd20af4099cd213ce25792edb
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 15:32:47 2012 +1000

    dix: use BUG_RETURN_VAL for pairing errors
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/dix/devices.c b/dix/devices.c
index 0c62a01..bbb4fa2 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -365,13 +365,12 @@ EnableDevice(DeviceIntPtr dev, BOOL sendevent)
                 /* mode doesn't matter */
                 EnterWindow(dev, screenInfo.screens[0]->root, NotifyAncestor);
             }
-            else if ((other = NextFreePointerDevice()) == NULL) {
-                ErrorF("[dix] cannot find pointer to pair with. "
-                       "This is a bug.\n");
-                return FALSE;
-            }
-            else
+            else {
+                other = NextFreePointerDevice();
+                BUG_RETURN_VAL_MSG(other == NULL, FALSE,
+                                   "[dix] cannot find pointer to pair with.\n");
                 PairDevices(NULL, other, dev);
+            }
         }
         else {
             if (dev->coreEvents)
commit 642569fc79a1814acca1c8f529539b054bf36907
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 12:11:57 2012 +1000

    Replace a few BUG_WARN with BUG_RETURN_VAL
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 4aad527..e99bf6c 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -926,10 +926,10 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent *event)
     else if (event->type == ET_ProximityOut)
         device->proximity->in_proximity = FALSE;
     else if (event->type == ET_TouchBegin) {
-        BUG_WARN(!b || !v);
-        BUG_WARN(!t);
+        BUG_RETURN_VAL(!b || !v, DONT_PROCESS);
+        BUG_RETURN_VAL(!t, DONT_PROCESS);
 
-        if (!b || !t || !b->map[key])
+        if (!b->map[key])
             return DONT_PROCESS;
 
         if (!(event->flags & TOUCH_POINTER_EMULATED) ||
@@ -941,10 +941,10 @@ UpdateDeviceState(DeviceIntPtr device, DeviceEvent *event)
         UpdateDeviceMotionMask(device, t->state, DeviceButtonMotionMask);
     }
     else if (event->type == ET_TouchEnd) {
-        BUG_WARN(!b || !v);
-        BUG_WARN(!t);
+        BUG_RETURN_VAL(!b || !v, DONT_PROCESS);
+        BUG_RETURN_VAL(!t, DONT_PROCESS);
 
-        if (!b || !t || t->buttonsDown <= 0 || !b->map[key])
+        if (t->buttonsDown <= 0 || !b->map[key])
             return DONT_PROCESS;
 
         if (!(event->flags & TOUCH_POINTER_EMULATED))
@@ -1356,9 +1356,8 @@ RetrieveTouchDeliveryData(DeviceIntPtr dev, TouchPointInfoPtr ti,
                                    wOtherInputMasks(*win)->inputClients, next)
                 if (xi2mask_isset(iclients->xi2mask, dev, evtype))
                 break;
-            BUG_WARN(!iclients);
-            if (!iclients)
-                return FALSE;
+
+            BUG_RETURN_VAL(!iclients, FALSE);
 
             *mask = iclients->xi2mask;
             *client = rClient(iclients);
@@ -1371,9 +1370,7 @@ RetrieveTouchDeliveryData(DeviceIntPtr dev, TouchPointInfoPtr ti,
                                    wOtherInputMasks(*win)->inputClients, next)
                 if (iclients->mask[dev->id] & xi_filter)
                 break;
-            BUG_WARN(!iclients);
-            if (!iclients)
-                return FALSE;
+            BUG_RETURN_VAL(!iclients, FALSE);
 
             *client = rClient(iclients);
         }
@@ -1414,9 +1411,7 @@ DeliverTouchEmulatedEvent(DeviceIntPtr dev, TouchPointInfoPtr ti,
         return Success;
 
     nevents = TouchConvertToPointerEvent(ev, &motion, &button);
-    BUG_WARN(nevents == 0);
-    if (nevents == 0)
-        return BadValue;
+    BUG_RETURN_VAL(nevents == 0, BadValue);
 
     if (nevents > 1)
         ptrev = &button;
diff --git a/dix/getevents.c b/dix/getevents.c
index 4fbaa6c..baa26c4 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1821,10 +1821,7 @@ GetTouchEvents(InternalEvent *events, DeviceIntPtr dev, uint32_t ddx_touchid,
 
     if (flags & TOUCH_CLIENT_ID) {      /* A DIX-submitted TouchEnd */
         touchpoint.dix_ti = TouchFindByClientID(dev, ddx_touchid);
-        BUG_WARN(!touchpoint.dix_ti);
-
-        if (!touchpoint.dix_ti)
-            return 0;
+        BUG_RETURN_VAL(!touchpoint.dix_ti, 0);
 
         if (!mask_in ||
             !valuator_mask_isset(mask_in, 0) ||
diff --git a/dix/touch.c b/dix/touch.c
index 401cb98..082e8f6 100644
--- a/dix/touch.c
+++ b/dix/touch.c
@@ -598,8 +598,8 @@ TouchConvertToPointerEvent(const InternalEvent *event,
     int ptrtype;
     int nevents = 0;
 
-    BUG_WARN(!event);
-    BUG_WARN(!motion_event);
+    BUG_RETURN_VAL(!event, 0);
+    BUG_RETURN_VAL(!motion_event, 0);
 
     switch (event->any.type) {
     case ET_TouchUpdate:
@@ -627,7 +627,7 @@ TouchConvertToPointerEvent(const InternalEvent *event,
     motion_event->device_event.flags = XIPointerEmulated;
 
     if (nevents > 1) {
-        BUG_WARN(!button_event);
+        BUG_RETURN_VAL(!button_event, 0);
         *button_event = *event;
         button_event->any.type = ptrtype;
         button_event->device_event.flags = XIPointerEmulated;
@@ -966,10 +966,8 @@ TouchListenerAcceptReject(DeviceIntPtr dev, TouchPointInfoPtr ti, int listener,
     int nev;
     int i;
 
-    BUG_WARN(listener < 0);
-    BUG_WARN(listener >= ti->num_listeners);
-    if (listener < 0 || listener >= ti->num_listeners)
-        return BadMatch;
+    BUG_RETURN_VAL(listener < 0, BadMatch);
+    BUG_RETURN_VAL(listener >= ti->num_listeners, BadMatch);
 
     if (listener > 0) {
         if (mode == XIRejectTouch)
@@ -981,10 +979,7 @@ TouchListenerAcceptReject(DeviceIntPtr dev, TouchPointInfoPtr ti, int listener,
     }
 
     events = InitEventList(GetMaximumEventsNum());
-    if (!events) {
-        BUG_WARN_MSG(TRUE, "Failed to allocate touch ownership events\n");
-        return BadAlloc;
-    }
+    BUG_RETURN_VAL_MSG(!events, BadAlloc, "Failed to allocate touch ownership events\n");
 
     nev = GetTouchOwnershipEvents(events, dev, ti, mode,
                                   ti->listeners[0].listener, 0);
commit 11ecfb8884b7c4def0863a57868a6b9fa1b63ae5
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Thu May 10 11:48:05 2012 +1000

    include: add BUG_RETURN_* macros
    
    Helper functions to avoid things like
    
    if (foo) {
        BUG_WARN(foo);
        return 1;
    }
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>

diff --git a/include/misc.h b/include/misc.h
index 41c1333..fea74b8 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -381,4 +381,16 @@ extern _X_EXPORT unsigned long serverGeneration;
 
 #define BUG_WARN(cond)  __BUG_WARN_MSG(cond, 0, NULL)
 
+#define BUG_RETURN(cond) \
+        do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return; } } while(0)
+
+#define BUG_RETURN_MSG(cond, ...) \
+        do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return; } } while(0)
+
+#define BUG_RETURN_VAL(cond, val) \
+        do { if (cond) { __BUG_WARN_MSG(cond, 0, NULL); return (val); } } while(0)
+
+#define BUG_RETURN_VAL_MSG(cond, val, ...) \
+        do { if (cond) { __BUG_WARN_MSG(cond, 1, __VA_ARGS__); return (val); } } while(0)
+
 #endif                          /* MISC_H */
commit ff41753b1bee414b16c0f1e8d183776e87c94065
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Jun 6 14:38:49 2012 +1000

    xkb: warn if XKB SlowKeys have been automatically enabled
    
    Slow keys are enabled when the XKB AccessX features are generally enabled
    (ctrls->enabled_ctrls & XkbAccessXKeysMask) and either shift key is held for
    8 seconds. For the unsuspecting user this appears as if the keyboard
    suddenly stops working.
    
    Print a warning to the log, so we can later tell them "told you so".
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>

diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 95e28e7..fe28e12 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -295,10 +295,15 @@ AccessXKRGExpire(OsTimerPtr timer, CARD32 now, pointer arg)
     cn.eventType = 0;
     cn.requestMajor = 0;
     cn.requestMinor = 0;
-    if (xkbi->desc->ctrls->enabled_ctrls & XkbSlowKeysMask)
+    if (xkbi->desc->ctrls->enabled_ctrls & XkbSlowKeysMask) {
         AccessXKRGTurnOff((DeviceIntPtr) arg, &cn);
-    else
+        LogMessage(X_INFO, "XKB SlowKeys are disabled.\n");
+    }
+    else {
         AccessXKRGTurnOn((DeviceIntPtr) arg, XkbSlowKeysMask, &cn);
+        LogMessage(X_INFO, "XKB SlowKeys are now enabled. Hold shift to disable.\n");
+    }
+
     return 0;
 }
 
commit f20a532ba3c7b7d74530f3906c7bacf016bb8faf
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun May 20 00:00:59 2012 -0700

    Fix statement not reached warning in _DMXXineramaActive
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Mark Kettenis <kettenis at openbsd.org>

diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c
index add0e53..a226c5d 100644
--- a/hw/dmx/dmx.c
+++ b/hw/dmx/dmx.c
@@ -74,8 +74,9 @@ _DMXXineramaActive(void)
 {
 #ifdef PANORAMIX
     return !noPanoramiXExtension;
-#endif
+#else
     return 0;
+#endif
 }
 
 static void
commit 1be317c4e5d99d11a124ad4e7a90a5dcae591e20
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Wed May 23 19:27:23 2012 -0700

    Provide prototypes for Mmio functions for Solaris Studio on SPARC
    
    Actual inline implementations are provided via external *.il files
    generated from *.S files in hw/xfree86/os-support/solaris
    
    Fixes missing prototype warnings that xorg-macros has recently elevated
    to build-breaking errors.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Henry Zhao <henry.zhao at oracle.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 0abdfb6..c980bee 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -119,6 +119,23 @@ extern _X_EXPORT unsigned int inb(unsigned long);
 extern _X_EXPORT unsigned int inw(unsigned long);
 extern _X_EXPORT unsigned int inl(unsigned long);
 
+#ifdef __SUNPRO_C
+extern _X_EXPORT unsigned char  xf86ReadMmio8    (void *, unsigned long);
+extern _X_EXPORT unsigned short xf86ReadMmio16Be (void *, unsigned long);
+extern _X_EXPORT unsigned short xf86ReadMmio16Le (void *, unsigned long);
+extern _X_EXPORT unsigned int   xf86ReadMmio32Be (void *, unsigned long);
+extern _X_EXPORT unsigned int   xf86ReadMmio32Le (void *, unsigned long);
+extern _X_EXPORT void xf86WriteMmio8    (void *, unsigned long, unsigned int);
+extern _X_EXPORT void xf86WriteMmio16Be (void *, unsigned long, unsigned int);
+extern _X_EXPORT void xf86WriteMmio16Le (void *, unsigned long, unsigned int);
+extern _X_EXPORT void xf86WriteMmio32Be (void *, unsigned long, unsigned int);
+extern _X_EXPORT void xf86WriteMmio32Le (void *, unsigned long, unsigned int);
+extern _X_EXPORT void xf86WriteMmio8NB    (void *, unsigned long, unsigned int);
+extern _X_EXPORT void xf86WriteMmio16BeNB (void *, unsigned long, unsigned int);
+extern _X_EXPORT void xf86WriteMmio16LeNB (void *, unsigned long, unsigned int);
+extern _X_EXPORT void xf86WriteMmio32BeNB (void *, unsigned long, unsigned int);
+extern _X_EXPORT void xf86WriteMmio32LeNB (void *, unsigned long, unsigned int);
+#endif                          /* _SUNPRO_C */
 #endif                          /* __sparc__,  __arm32__, __alpha__, __nds32__ */
 #endif                          /* __arm__ */
 
commit 812786f4d4306cb16f8ed57fa4a1a32bb1d13fe3
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 19:55:52 2012 +0100

    xwin: fixup block/wakeup handlers
    
    These got missed out in the api changeover.
    
    Reported-by: Colin Harrison <colin.harrison at virgin.net>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index 878419d..b84ea9b 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -780,7 +780,7 @@ void winSetAuthorization(void);
 void
 
 winBlockHandler(ScreenPtr pScreen,
-                pointer pBlockData, pointer pTimeout, pointer pReadMask);
+                pointer pTimeout, pointer pReadMask);
 
 #ifdef XWIN_NATIVEGDI
 /*
@@ -1123,7 +1123,6 @@ Bool
 void
 
 winWakeupHandler(ScreenPtr pScreen,
-                 pointer pWakeupData,
                  unsigned long ulResult, pointer pReadmask);
 
 /*
diff --git a/hw/xwin/winblock.c b/hw/xwin/winblock.c
index 5faa113..c1a6e70 100644
--- a/hw/xwin/winblock.c
+++ b/hw/xwin/winblock.c
@@ -37,10 +37,10 @@
 /* See Porting Layer Definition - p. 6 */
 void
 winBlockHandler(ScreenPtr pScreen,
-                pointer pBlockData, pointer pTimeout, pointer pReadMask)
+                pointer pTimeout, pointer pReadMask)
 {
 #if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
-    winScreenPriv((ScreenPtr) pBlockData);
+    winScreenPriv(pScreen);
 #endif
     MSG msg;
 
diff --git a/hw/xwin/winwakeup.c b/hw/xwin/winwakeup.c
index 8c9140b..77c1605 100644
--- a/hw/xwin/winwakeup.c
+++ b/hw/xwin/winwakeup.c
@@ -39,7 +39,7 @@
 /* See Porting Layer Definition - p. 7 */
 void
 winWakeupHandler(ScreenPtr pScreen,
-                 pointer pWakeupData, unsigned long ulResult, pointer pReadmask)
+                 unsigned long ulResult, pointer pReadmask)
 {
     MSG msg;
 
commit 3cbaf621782fb5f5679acf9104571d3ae2b48b72
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 17:54:02 2012 +0100

    xfree86: fix new warnings introduced in rebase.
    
    Spotted these in tinderbox:
    xf86xv.c: In function 'xf86XVScreenInit':
    xf86xv.c:282: warning: assignment from incompatible pointer type
    xf86xv.c: In function 'xf86XVCloseScreen':
    xf86xv.c:1275: warning: assignment from incompatible pointer type
    xf86xv.c: In function 'xf86XVAdjustFrame':
    xf86xv.c:1366: warning: assignment from incompatible pointer type
    
    Missed removing one flags.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Tested-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86xvpriv.h b/hw/xfree86/common/xf86xvpriv.h
index 9bedd90..e95f959 100644
--- a/hw/xfree86/common/xf86xvpriv.h
+++ b/hw/xfree86/common/xf86xvpriv.h
@@ -41,7 +41,7 @@ typedef struct {
     ClipNotifyProcPtr ClipNotify;
     WindowExposuresProcPtr WindowExposures;
     PostValidateTreeProcPtr PostValidateTree;
-    void (*AdjustFrame) (ScrnInfoPtr, int, int, int);
+    void (*AdjustFrame) (ScrnInfoPtr, int, int);
     Bool (*EnterVT) (ScrnInfoPtr);
     void (*LeaveVT) (ScrnInfoPtr);
     xf86ModeSetProc *ModeSet;
commit 1f0e8bd5eb1a5539689cfc4f5a6b86b530907ec5
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 13:22:18 2012 +0100

    api: rework the X server driver API to avoid global arrays.
    
    This is a squash merge containing all the API changes, as
    well as the video ABI bump.
    
    Its been squashed to make bisection easier.
    
    Full patch log below:
    
    commit b202738bbf0c5a1c1172767119c2c71f1e7f8070
    Author: Aaron Plattner <aplattner at nvidia.com>
    Date:   Mon May 14 15:16:11 2012 -0700
    
        xfree86: Bump video ABI to 13.0
    
        The ABI was broken by changes to convert from screen index numbers to ScreenPtr
        / ScrnInfoPtr in various structures and function signatures.
    
        Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Dave Airlie <airlied at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 3d5f7d9f8d408bcad3f83277d255f25d3b0edbf3
    Author: Dave Airlie <airlied at redhat.com>
    Date:   Thu May 24 10:56:57 2012 +0100
    
        xf86: xf86ClearEntityListForScreen should take a pScrn
    
        When adding GPU screens this make life easier.
    
        (also fix comment, as pointed out by Alan)
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit afee8b5ab4501597ecc1ade34124d7ca227ab055
    Author: Dave Airlie <airlied at redhat.com>
    Date:   Thu May 24 07:07:32 2012 +0100
    
        xf86i2c: add pscrn for drivers to use
    
        This just adds a pScrn pointer into the struct for the drivers to use
        instead of scrnIndex. Mostly scrnIndex is used for logging, but some
        drivers use it to lookup xf86Screens, so let them stash a pScrn instead.
    
        Removing the scrnIndex is a bit more involved and I'm not sure its worth
        the effort. Doing i2c in the X server is legacy code as far as I'm concerned.
    
        Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit ea5092f1f679691d187f1eee9427e6057beec56e
    Author: Dave Airlie <airlied at redhat.com>
    Date:   Wed May 23 19:25:20 2012 +0100
    
        dix/gc: consolidate GC object creation in one place
    
        The standard GC create and scratch GC create were 90% the same really,
        and I have a need in the future for creating GC objects without the
        other bits, so wanted to avoid a third copy.
    
        Reviewed-by: Keith Packard <keithp at keithp.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 3d91482ea9b4883e64e496f2768168e0ffa21ba1
    Author: Dave Airlie <airlied at redhat.com>
    Date:   Wed May 23 10:24:06 2012 +0100
    
        xf86: add a define to denote the new non-index interfaces are being used
    
        This can be used by drivers to provide compatible APIs.
    
        Reviewed-by: Keith Packard <keithp at keithp.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 37c3ae3e6cd4f3dedc72f371096d6743f8f99df3
    Author: Dave Airlie <airlied at redhat.com>
    Date:   Wed May 23 15:09:12 2012 +0100
    
        dix: make Create/Free scratch pixmaps take a ScreenPtr
    
        While technically an API/ABI change I doubt anyone uses it,
        but it helps in splitting screens up.
    
        Reviewed-by: Keith Packard <keithp at keithp.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 75f2062a3fe94f04764ecc7d2ff2fbbeccb9da60
    Author: Dave Airlie <airlied at redhat.com>
    Date:   Wed May 23 14:57:55 2012 +0100
    
        xf86/xv: remove scrnIndexfrom xf86FindXvOptions.
    
        Move this interface to taking an ScrnInfoPtr.
    
        Reviewed-by: Keith Packard <keithp at keithp.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit f80c2374f40ea7b2ee0556e2e76cc07406f3d843
    Author: Dave Airlie <airlied at redhat.com>
    Date:   Wed May 23 14:53:59 2012 +0100
    
        xf86: make xf86DeleteScreen take a ScrnInfoPtr (v2)
    
        stop passing indices into this function.
    
        v2: drop flags argument.
    
        Reviewed-by: Keith Packard <keithp at keithp.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 58824e414f35682435f15bfe6c4b656bd90b9235
    Author: Dave Airlie <airlied at redhat.com>
    Date:   Wed May 23 14:48:09 2012 +0100
    
        xf86: fix xf86IsScreenPrimary interface to take a pScrn (API/ABI)
    
        Reviewed-by: Keith Packard <keithp at keithp.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 6b4fc1f9d391bcdf7ca288766e49bce60f4635cd
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 14:18:59 2012 +0100
    
        xserver: convert block/wakeup handlers to passing ScreenPtr (ABI/API) (v2)
    
        Instead of passing an index, pass the actual ScreenPtr. This allows
        more moving towards not abusing xf86Screens + screenInfo.
    
        v2: drop the blockData/wakeupData args as per ajax's suggestion.,
        fix docs.
    
        Reviewed-by: Keith Packard <keithp at keithp.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 790d003de20fb47674420a24dadd92412d78620d
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Wed Apr 11 09:53:14 2012 +0100
    
        xf86/common: remove some more pScrn->pScreen uses
    
        remove some more conversions that appeared after api cleanups.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit aac85e18d1dd093f2cad6bd29375e40bd7af0b8f
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 16:34:53 2012 +0100
    
        ddc: change API to take ScrnInfoPtr (v2)
    
        This removes all xf86Screens usage from ddc code,
        it modifies the API for some functions to avoid taking indices.
    
        v2: address Alan's comments about dropping DDC2Init parameter.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit fe3f57b6eaf6860a33876a54f9439f69578f03a5
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 16:31:26 2012 +0100
    
        vbe: don't use index for VBEInterpretPanelID (API)
    
        Remove use of xf86screens from vbe module.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit abf1965f4ed91529036d3fdb470d6a3ce6f29675
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 16:25:11 2012 +0100
    
        int10/vbe: don't use xf86Screens. (ABI) (v3)
    
        Pass the ScrnInfoPtr instead of the index in the int10 struct.
    
        This saves us using it to dereference xf86Screens.
    
        v2: address Alan's comment to fix struct alignment.
    
        v3: squash in all the int10 fixes, test the vm86 code builds,
        after comments by Keith.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 23cca612b4fb5efc33683c7624b803b457387e3d
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 15:30:18 2012 +0100
    
        xserver: drop index argument to ScreenInit (ABI/API) (v2)
    
        This drops the index argument, its the same as pScreen->myNum,
        and its the last major index abuse I can find.
    
        v2: address Alan's review - update docs, fix xwin/xnest/darwin
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 40d360e2d7e832407f3ed64e3a02c27ecc89a960
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 15:23:01 2012 +0100
    
        xf86: migrate PointerMoved from index to ScrnInfoPtr (ABI/API)
    
        This migrates PointerMoved from an index to ScrnInfoPtr.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit aa60a2f38679d0eeb979a9c2648c9bc771409bf9
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 15:20:46 2012 +0100
    
        xf86: migrate PMEvent to a ScrnInfoPtr (ABI/API)
    
        This migrates the PMEvent from index to ScrnInfoPtr.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit d3f28ef44371ed4a039ffc5dd7eb6408d1269ba2
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 15:18:30 2012 +0100
    
        xf86: migrate SetDGAMode from index to ScrnInfoPtr (ABI/API)
    
        This migrates the SetDGAMode callback from an index to ScrnInfoPtr.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit baf5e4818a74f2b68c3dfdcc56f54322351039a0
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 15:14:11 2012 +0100
    
        xf86: migrate ChangeGamma from index to ScrnInfoPtr (ABI/API) (v2)
    
        This migrates the ChangeGamma interface to avoid passing a index.
    
        v2: fix xf86RandR12.c + xf86cmap.c call
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 51e5f90ada929d6b23176090badbb42fdb3fa550
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 15:11:09 2012 +0100
    
        xf86/exa: migrate index to screen types for EnableDisableFBAccess (ABI/API)
    
        The EXA interface migrates to ScreenPtr,
        and the xf86 interface migrated to ScrnInfoPtr.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 94f1f21d17e86f96d4a54292a399160950087675
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 15:02:11 2012 +0100
    
        xf86: migrate ValidMode callback to ScrnInfoPtr (ABI/API)
    
        This migrates the ValidMode to passing a ScrnInfoPtr instead
        of an index.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 3f8f18198fed4f39ec805b508a3482e91eea26b2
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 14:59:46 2012 +0100
    
        xf86: migrate SwitchMode to taking ScrnInfoPtr (ABI/API) (v2)
    
        This migrate the SwitchMode interface to take a ScrnInfoPtr
        instead of an index.
    
        v2: drop flags.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit d06a038a5c49328ab3a8d969d24f9fcd22c63202
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 14:50:37 2012 +0100
    
        xf86: move AdjustFrame to passing ScrnInfoPtr (ABI/API) (v2)
    
        This converts AdjustFrame code paths to passing a ScrnInfoPtr
        instead of an integer index.
    
        v2: drop flags args.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 53d2f8608ffd4090d08e7d5cf2e92fb954959b90
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 14:41:27 2012 +0100
    
        xf86: modify FreeScreen callback to take pScrn instead of index. (ABI/API) (v2)
    
        Another index->pScrn conversion.
    
        v2: drop flags arg.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 60db37c0b247052e0f5c54b1921fe58a3609c2e3
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 14:35:41 2012 +0100
    
        xf86: change EnterVT/LeaveVT to take a ScrnInfoPtr (ABI/API break) (v2)
    
        This modifies the EnterVT/LeaveVT interfaces to take a ScrnInfoPtr
        instead of an index into xf86Screens. This allows dropping more
        public dereferences of the xf86Screens and screenInfo.
    
        v2: drop flags args as suggested by Keith, fix docs.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>
    
    commit 06729dbbc804a20242e6499f446acb5d94023c3c
    Author: Dave Airlie <airlied at gmail.com>
    Date:   Tue Apr 10 14:04:59 2012 +0100
    
        xserver: remove index from CloseScreen (API/ABI breakage)
    
        This drops the index from the CloseScreen callback,
        its always been useless really, since the pScreen contains it.
    
        Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
        Acked-by: Aaron Plattner <aplattner at nvidia.com>
        Reviewed-by: Adam Jackson <ajax at redhat.com>
        Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 98d327f..de62a35 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -150,7 +150,7 @@ static GCFuncs XineramaGCFuncs = {
     (pGC)->funcs = &XineramaGCFuncs;
 
 static Bool
-XineramaCloseScreen(int i, ScreenPtr pScreen)
+XineramaCloseScreen(ScreenPtr pScreen)
 {
     PanoramiXScreenPtr pScreenPriv = (PanoramiXScreenPtr)
         dixLookupPrivate(&pScreen->devPrivates, PanoramiXScreenKey);
@@ -163,7 +163,7 @@ XineramaCloseScreen(int i, ScreenPtr pScreen)
 
     free((pointer) pScreenPriv);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static Bool
diff --git a/Xext/shm.c b/Xext/shm.c
index de48020..e9c4a4e 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -202,14 +202,14 @@ CheckForShmSyscall(void)
 #endif
 
 static Bool
-ShmCloseScreen(int i, ScreenPtr pScreen)
+ShmCloseScreen(ScreenPtr pScreen)
 {
     ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen);
 
     pScreen->CloseScreen = screen_priv->CloseScreen;
     dixSetPrivate(&pScreen->devPrivates, shmScrPrivateKey, NULL);
     free(screen_priv);
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static ShmScrPrivateRec *
diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index d226726..59fc1ff 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -215,7 +215,7 @@ typedef struct {
     DestroyWindowProcPtr DestroyWindow;
     DestroyPixmapProcPtr DestroyPixmap;
     CloseScreenProcPtr CloseScreen;
-    Bool (*ddCloseScreen) (int, ScreenPtr);
+    Bool (*ddCloseScreen) (ScreenPtr);
     int (*ddQueryAdaptors) (ScreenPtr, XvAdaptorPtr *, int *);
     DevUnion devPriv;
 } XvScreenRec, *XvScreenPtr;
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 48061a2..736114b 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -129,7 +129,7 @@ static void WriteSwappedVideoNotifyEvent(xvEvent *, xvEvent *);
 static void WriteSwappedPortNotifyEvent(xvEvent *, xvEvent *);
 static Bool CreateResourceTypes(void);
 
-static Bool XvCloseScreen(int, ScreenPtr);
+static Bool XvCloseScreen(ScreenPtr);
 static Bool XvDestroyPixmap(PixmapPtr);
 static Bool XvDestroyWindow(WindowPtr);
 static void XvResetProc(ExtensionEntry *);
@@ -290,7 +290,7 @@ XvScreenInit(ScreenPtr pScreen)
 }
 
 static Bool
-XvCloseScreen(int ii, ScreenPtr pScreen)
+XvCloseScreen(ScreenPtr pScreen)
 {
 
     XvScreenPtr pxvs;
@@ -301,13 +301,13 @@ XvCloseScreen(int ii, ScreenPtr pScreen)
     pScreen->DestroyWindow = pxvs->DestroyWindow;
     pScreen->CloseScreen = pxvs->CloseScreen;
 
-    (*pxvs->ddCloseScreen) (ii, pScreen);
+    (*pxvs->ddCloseScreen) (pScreen);
 
     free(pxvs);
 
     dixSetPrivate(&pScreen->devPrivates, XvScreenKey, NULL);
 
-    return (*pScreen->CloseScreen) (ii, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static void
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 8a1d940..4aaff4d 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -709,7 +709,7 @@ XvMCExtensionInit(void)
 }
 
 static Bool
-XvMCCloseScreen(int i, ScreenPtr pScreen)
+XvMCCloseScreen(ScreenPtr pScreen)
 {
     XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pScreen);
 
@@ -717,7 +717,7 @@ XvMCCloseScreen(int i, ScreenPtr pScreen)
 
     free(pScreenPriv);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 int
diff --git a/composite/compalloc.c b/composite/compalloc.c
index 15a6cd2..b958b09 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -55,14 +55,13 @@ compScreenUpdate(ScreenPtr pScreen)
 }
 
 static void
-compBlockHandler(int i, pointer blockData, pointer pTimeout, pointer pReadmask)
+compBlockHandler(ScreenPtr pScreen, pointer pTimeout, pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[i];
     CompScreenPtr cs = GetCompScreen(pScreen);
 
     pScreen->BlockHandler = cs->BlockHandler;
     compScreenUpdate(pScreen);
-    (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
+    (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
 
     /* Next damage will restore the block handler */
     cs->BlockHandler = NULL;
diff --git a/composite/compinit.c b/composite/compinit.c
index eaa1256..bc1130e 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -53,7 +53,7 @@ DevPrivateKeyRec CompWindowPrivateKeyRec;
 DevPrivateKeyRec CompSubwindowsPrivateKeyRec;
 
 static Bool
-compCloseScreen(int index, ScreenPtr pScreen)
+compCloseScreen(ScreenPtr pScreen)
 {
     CompScreenPtr cs = GetCompScreen(pScreen);
     Bool ret;
@@ -82,7 +82,7 @@ compCloseScreen(int index, ScreenPtr pScreen)
 
     free(cs);
     dixSetPrivate(&pScreen->devPrivates, CompScreenPrivateKey, NULL);
-    ret = (*pScreen->CloseScreen) (index, pScreen);
+    ret = (*pScreen->CloseScreen) (pScreen);
 
     return ret;
 }
diff --git a/dix/dispatch.c b/dix/dispatch.c
index d971805..b88f974 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3725,8 +3725,7 @@ with its screen number, a pointer to its ScreenRec, argc, and argv.
 */
 
 int
-AddScreen(Bool (*pfnInit) (int /*index */ ,
-                           ScreenPtr /*pScreen */ ,
+AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
                            int /*argc */ ,
                            char **      /*argv */
           ), int argc, char **argv)
@@ -3794,7 +3793,7 @@ AddScreen(Bool (*pfnInit) (int /*index */ ,
      */
     screenInfo.screens[i] = pScreen;
     screenInfo.numScreens++;
-    if (!(*pfnInit) (i, pScreen, argc, argv)) {
+    if (!(*pfnInit) (pScreen, argc, argv)) {
         dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
         free(pScreen);
         screenInfo.numScreens--;
diff --git a/dix/dixutils.c b/dix/dixutils.c
index 9eb5489..b249a81 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -384,9 +384,8 @@ BlockHandler(pointer pTimeout, pointer pReadmask)
 
     ++inHandler;
     for (i = 0; i < screenInfo.numScreens; i++)
-        (*screenInfo.screens[i]->BlockHandler) (i,
-                                                screenInfo.screens[i]->
-                                                blockData, pTimeout, pReadmask);
+        (*screenInfo.screens[i]->BlockHandler) (screenInfo.screens[i],
+                                                pTimeout, pReadmask);
     for (i = 0; i < numHandlers; i++)
         if (!handlers[i].deleted)
             (*handlers[i].BlockHandler) (handlers[i].blockData,
@@ -421,9 +420,8 @@ WakeupHandler(int result, pointer pReadmask)
             (*handlers[i].WakeupHandler) (handlers[i].blockData,
                                           result, pReadmask);
     for (i = 0; i < screenInfo.numScreens; i++)
-        (*screenInfo.screens[i]->WakeupHandler) (i,
-                                                 screenInfo.screens[i]->
-                                                 wakeupData, result, pReadmask);
+        (*screenInfo.screens[i]->WakeupHandler) (screenInfo.screens[i],
+                                                 result, pReadmask);
     if (handlerDeleted) {
         for (i = 0; i < numHandlers;)
             if (handlers[i].deleted) {
diff --git a/dix/gc.c b/dix/gc.c
index 7be0502..ac67643 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -458,32 +458,21 @@ ChangeGCXIDs(ClientPtr client, GC * pGC, BITS32 mask, CARD32 *pC32)
     return ChangeGC(client, pGC, mask, vals);
 }
 
-/* CreateGC(pDrawable, mask, pval, pStatus)
-   creates a default GC for the given drawable, using mask to fill
-   in any non-default values.
-   Returns a pointer to the new GC on success, NULL otherwise.
-   returns status of non-default fields in pStatus
-BUG:
-   should check for failure to create default tile
-
-*/
-GCPtr
-CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
-         XID gcid, ClientPtr client)
+static GCPtr
+NewGCObject(ScreenPtr pScreen, int depth)
 {
     GCPtr pGC;
 
     pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
     if (!pGC) {
-        *pStatus = BadAlloc;
         return (GCPtr) NULL;
     }
 
-    pGC->pScreen = pDrawable->pScreen;
-    pGC->depth = pDrawable->depth;
+    pGC->pScreen = pScreen;
+    pGC->depth = depth;
     pGC->alu = GXcopy;          /* dst <- src */
     pGC->planemask = ~0;
-    pGC->serialNumber = GC_CHANGE_SERIAL_BIT;
+    pGC->serialNumber = 0;
     pGC->funcs = 0;
     pGC->fgPixel = 0;
     pGC->bgPixel = 1;
@@ -496,17 +485,8 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
     pGC->arcMode = ArcPieSlice;
     pGC->tile.pixel = 0;
     pGC->tile.pixmap = NullPixmap;
-    if (mask & GCForeground) {
-        /*
-         * magic special case -- ChangeGC checks for this condition
-         * and snags the Foreground value to create a pseudo default-tile
-         */
-        pGC->tileIsPixel = FALSE;
-    }
-    else {
-        pGC->tileIsPixel = TRUE;
-    }
 
+    pGC->tileIsPixel = TRUE;
     pGC->patOrg.x = 0;
     pGC->patOrg.y = 0;
     pGC->subWindowMode = ClipByChildren;
@@ -521,12 +501,49 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
 
     /* use the default font and stipple */
     pGC->font = defaultFont;
-    defaultFont->refcnt++;
+    if (pGC->font)              /* necessary, because open of default font could fail */
+        pGC->font->refcnt++;
     pGC->stipple = pGC->pScreen->PixmapPerDepth[0];
-    pGC->stipple->refcnt++;
+    if (pGC->stipple)
+        pGC->stipple->refcnt++;
 
     /* this is not a scratch GC */
     pGC->scratch_inuse = FALSE;
+    return pGC;
+}
+
+/* CreateGC(pDrawable, mask, pval, pStatus)
+   creates a default GC for the given drawable, using mask to fill
+   in any non-default values.
+   Returns a pointer to the new GC on success, NULL otherwise.
+   returns status of non-default fields in pStatus
+BUG:
+   should check for failure to create default tile
+
+*/
+GCPtr
+CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
+         XID gcid, ClientPtr client)
+{
+    GCPtr pGC;
+
+    pGC = NewGCObject(pDrawable->pScreen, pDrawable->depth);
+    if (!pGC) {
+        *pStatus = BadAlloc;
+        return (GCPtr) NULL;
+    }
+
+    pGC->serialNumber = GC_CHANGE_SERIAL_BIT;
+    if (mask & GCForeground) {
+        /*
+         * magic special case -- ChangeGC checks for this condition
+         * and snags the Foreground value to create a pseudo default-tile
+         */
+        pGC->tileIsPixel = FALSE;
+    }
+    else {
+        pGC->tileIsPixel = TRUE;
+    }
 
     /* security creation/labeling check */
     *pStatus = XaceHook(XACE_RESOURCE_ACCESS, client, gcid, RT_GC, pGC,
@@ -784,45 +801,10 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth)
 {
     GCPtr pGC;
 
-    pGC = dixAllocateObjectWithPrivates(GC, PRIVATE_GC);
+    pGC = NewGCObject(pScreen, depth);
     if (!pGC)
         return (GCPtr) NULL;
 
-    pGC->pScreen = pScreen;
-    pGC->depth = depth;
-    pGC->alu = GXcopy;          /* dst <- src */
-    pGC->planemask = ~0;
-    pGC->serialNumber = 0;
-    pGC->fgPixel = 0;
-    pGC->bgPixel = 1;
-    pGC->lineWidth = 0;
-    pGC->lineStyle = LineSolid;
-    pGC->capStyle = CapButt;
-    pGC->joinStyle = JoinMiter;
-    pGC->fillStyle = FillSolid;
-    pGC->fillRule = EvenOddRule;
-    pGC->arcMode = ArcPieSlice;
-    pGC->font = defaultFont;
-    if (pGC->font)              /* necessary, because open of default font could fail */
-        pGC->font->refcnt++;
-    pGC->tileIsPixel = TRUE;
-    pGC->tile.pixel = 0;
-    pGC->tile.pixmap = NullPixmap;
-    pGC->stipple = NullPixmap;
-    pGC->patOrg.x = 0;
-    pGC->patOrg.y = 0;
-    pGC->subWindowMode = ClipByChildren;
-    pGC->graphicsExposures = TRUE;
-    pGC->clipOrg.x = 0;
-    pGC->clipOrg.y = 0;
-    pGC->clientClipType = CT_NONE;
-    pGC->dashOffset = 0;
-    pGC->numInDashList = 2;
-    pGC->dash = DefaultDash;
-
-    /* scratch GCs in the GCperDepth pool start off unused */
-    pGC->scratch_inuse = FALSE;
-
     pGC->stateChanges = GCAllBits;
     if (!(*pScreen->CreateGC) (pGC)) {
         FreeGC(pGC, (XID) 0);
diff --git a/dix/main.c b/dix/main.c
index 70dcc94..83efa7d 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -209,7 +209,7 @@ main(int argc, char *argv[], char *envp[])
         for (i = 0; i < screenInfo.numScreens; i++) {
             ScreenPtr pScreen = screenInfo.screens[i];
 
-            if (!CreateScratchPixmapsForScreen(i))
+            if (!CreateScratchPixmapsForScreen(pScreen))
                 FatalError("failed to create scratch pixmaps");
             if (pScreen->CreateScreenResources &&
                 !(*pScreen->CreateScreenResources) (pScreen))
@@ -322,10 +322,10 @@ main(int argc, char *argv[], char *envp[])
         CloseDownEvents();
 
         for (i = screenInfo.numScreens - 1; i >= 0; i--) {
-            FreeScratchPixmapsForScreen(i);
+            FreeScratchPixmapsForScreen(screenInfo.screens[i]);
             FreeGCperDepth(i);
             FreeDefaultStipple(i);
-            (*screenInfo.screens[i]->CloseScreen) (i, screenInfo.screens[i]);
+            (*screenInfo.screens[i]->CloseScreen) (screenInfo.screens[i]);
             dixFreePrivates(screenInfo.screens[i]->devPrivates, PRIVATE_SCREEN);
             free(screenInfo.screens[i]);
             screenInfo.numScreens = i;
diff --git a/dix/pixmap.c b/dix/pixmap.c
index 47b220b..545ff54 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -84,23 +84,23 @@ FreeScratchPixmapHeader(PixmapPtr pPixmap)
 }
 
 Bool
-CreateScratchPixmapsForScreen(int scrnum)
+CreateScratchPixmapsForScreen(ScreenPtr pScreen)
 {
     unsigned int pixmap_size;
 
     pixmap_size = sizeof(PixmapRec) + dixPrivatesSize(PRIVATE_PIXMAP);
-    screenInfo.screens[scrnum]->totalPixmapSize =
+    pScreen->totalPixmapSize =
         BitmapBytePad(pixmap_size * 8);
 
     /* let it be created on first use */
-    screenInfo.screens[scrnum]->pScratchPixmap = NULL;
+    pScreen->pScratchPixmap = NULL;
     return TRUE;
 }
 
 void
-FreeScratchPixmapsForScreen(int scrnum)
+FreeScratchPixmapsForScreen(ScreenPtr pScreen)
 {
-    FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap);
+    FreeScratchPixmapHeader(pScreen->pScratchPixmap);
 }
 
 /* callable by ddx */
diff --git a/doc/Xserver-spec.xml b/doc/Xserver-spec.xml
index 2b11828..31b6fb0 100644
--- a/doc/Xserver-spec.xml
+++ b/doc/Xserver-spec.xml
@@ -680,7 +680,7 @@ pReadmask is a pointer to the information describing the descriptors
 that will be waited on.
 </para>
 <para>
-In the sample server,  pTimeout is a struct timeval **,  and pReadmask is
+In the sample server,  pTimeout is a pointer,  and pReadmask is
 the address of the select() mask for reading.
 </para>
 <para>
@@ -688,15 +688,14 @@ The DIX BlockHandler() iterates through the Screens,  for each one calling
 its BlockHandler.  A BlockHandler is declared thus:
 <blockquote>
 <programlisting>
-	void xxxBlockHandler(nscreen, pbdata, pptv, pReadmask)
-		int nscreen;
-		pointer pbdata;
-		struct timeval ** pptv;
+	void xxxBlockHandler(pScreen, pTimeout, pReadmask)
+		ScreenPtr pScreen;
+		pointer pTimeout;
 		pointer pReadmask;
 </programlisting>
 </blockquote>
-The arguments are the index of the Screen,  the blockData field
-of the Screen,  and the arguments to the DIX BlockHandler().
+The arguments are a pointer to the Screen, and the arguments to the
+DIX BlockHandler().
 </para>
 <para>
 Immediately after WaitForSomething returns from the
@@ -721,15 +720,14 @@ The DIX WakeupHandler() calls each Screen's
 WakeupHandler.  A WakeupHandler is declared thus:
 <blockquote>
 <programlisting>
-	void xxxWakeupHandler(nscreen, pbdata, err, pReadmask)
-		int nscreen;
-		pointer pbdata;
+	void xxxWakeupHandler(pScreen, result, pReadmask)
+		ScreenPtr pScreen;
 		unsigned long result;
 		pointer pReadmask;
 </programlisting>
 </blockquote>
-The arguments are the index of the Screen,  the blockData field
-of the Screen,  and the arguments to the DIX WakeupHandler().
+The arguments are the Screen, of the Screen, and the arguments to
+the DIX WakeupHandler().
 </para>
 <para>
 In addition to the per-screen BlockHandlers, any module may register
@@ -1942,18 +1940,15 @@ FALSE.</para>
 The scrInitProc should be of the following form:
 <blockquote><programlisting>
 
-	Bool scrInitProc(iScreen, pScreen, argc, argv)
-		int iScreen;
+	Bool scrInitProc(pScreen, argc, argv)
 		ScreenPtr pScreen;
 		int argc;
 		char **argv;
 </programlisting></blockquote>
-iScreen is the index for this screen; 0 for the first one initialized,
-1 for the second, etc.  pScreen is the pointer to the screen's new
-ScreenRec.  argc and argv are as before.  Your screen initialize
-procedure should return TRUE upon success or FALSE if the screen
-cannot be initialized (for instance, if the screen hardware does not
-exist on this machine).</para>
+pScreen is the pointer to the screen's new ScreenRec. argc and argv
+are as before.  Your screen initialize procedure should return TRUE
+upon success or FALSE if the screen cannot be initialized (for
+ instance, if the screen hardware does not exist on this machine).</para>
 <para>
 This procedure must determine what actual device it is supposed to initialize.
 If you have a different procedure for each screen, then it is no problem.
diff --git a/exa/exa.c b/exa/exa.c
index e22f2f0..0f90e59 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -704,11 +704,9 @@ exaCreateScreenResources(ScreenPtr pScreen)
 }
 
 static void
-ExaBlockHandler(int screenNum, pointer blockData, pointer pTimeout,
+ExaBlockHandler(ScreenPtr pScreen, pointer pTimeout,
                 pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[screenNum];
-
     ExaScreenPriv(pScreen);
 
     /* Move any deferred results from a software fallback to the driver pixmap */
@@ -716,7 +714,7 @@ ExaBlockHandler(int screenNum, pointer blockData, pointer pTimeout,
         exaMoveInPixmap_mixed(pExaScr->deferred_mixed_pixmap);
 
     unwrap(pExaScr, pScreen, BlockHandler);
-    (*pScreen->BlockHandler) (screenNum, blockData, pTimeout, pReadmask);
+    (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
     wrap(pExaScr, pScreen, BlockHandler, ExaBlockHandler);
 
     /* The rest only applies to classic EXA */
@@ -736,15 +734,13 @@ ExaBlockHandler(int screenNum, pointer blockData, pointer pTimeout,
 }
 
 static void
-ExaWakeupHandler(int screenNum, pointer wakeupData, unsigned long result,
+ExaWakeupHandler(ScreenPtr pScreen, unsigned long result,
                  pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[screenNum];
-
     ExaScreenPriv(pScreen);
 
     unwrap(pExaScr, pScreen, WakeupHandler);
-    (*pScreen->WakeupHandler) (screenNum, wakeupData, result, pReadmask);
+    (*pScreen->WakeupHandler) (pScreen, result, pReadmask);
     wrap(pExaScr, pScreen, WakeupHandler, ExaWakeupHandler);
 
     if (result == 0 && pExaScr->numOffscreenAvailable > 1) {
@@ -762,7 +758,7 @@ ExaWakeupHandler(int screenNum, pointer wakeupData, unsigned long result,
  * screen private, before calling down to the next CloseSccreen.
  */
 static Bool
-exaCloseScreen(int i, ScreenPtr pScreen)
+exaCloseScreen(ScreenPtr pScreen)
 {
     ExaScreenPriv(pScreen);
     PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
@@ -797,7 +793,7 @@ exaCloseScreen(int i, ScreenPtr pScreen)
 
     free(pExaScr);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 /**
diff --git a/exa/exa.h b/exa/exa.h
index 7534002..8a6539f 100644
--- a/exa/exa.h
+++ b/exa/exa.h
@@ -789,7 +789,7 @@ extern _X_EXPORT void
  ExaOffscreenMarkUsed(PixmapPtr pPixmap);
 
 extern _X_EXPORT void
- exaEnableDisableFBAccess(int index, Bool enable);
+ exaEnableDisableFBAccess(ScreenPtr pScreen, Bool enable);
 
 extern _X_EXPORT Bool
  exaDrawableIsOffscreen(DrawablePtr pDrawable);
diff --git a/exa/exa_offscreen.c b/exa/exa_offscreen.c
index 5e1d139..1f571cf 100644
--- a/exa/exa_offscreen.c
+++ b/exa/exa_offscreen.c
@@ -360,10 +360,8 @@ ExaOffscreenSwapIn(ScreenPtr pScreen)
  * swapped out.
  */
 void
-exaEnableDisableFBAccess(int index, Bool enable)
+exaEnableDisableFBAccess(ScreenPtr pScreen, Bool enable)
 {
-    ScreenPtr pScreen = screenInfo.screens[index];
-
     ExaScreenPriv(pScreen);
 
     if (pExaScr->info->flags & EXA_HANDLES_PIXMAPS)
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index bde78c3..f980fea 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -147,7 +147,7 @@ typedef struct _ExaMigrationRec {
     RegionPtr pReg;
 } ExaMigrationRec, *ExaMigrationPtr;
 
-typedef void (*EnableDisableFBAccessProcPtr) (int, Bool);
+typedef void (*EnableDisableFBAccessProcPtr) (ScreenPtr, Bool);
 typedef struct {
     ExaDriverPtr info;
     ScreenBlockHandlerProcPtr SavedBlockHandler;
diff --git a/fb/fb.h b/fb/fb.h
index b327ce6..cc3b6ee 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1419,7 +1419,7 @@ fbPushPixels(GCPtr pGC,
  */
 
 extern _X_EXPORT Bool
- fbCloseScreen(int indx, ScreenPtr pScreen);
+ fbCloseScreen(ScreenPtr pScreen);
 
 extern _X_EXPORT Bool
  fbRealizeFont(ScreenPtr pScreen, FontPtr pFont);
diff --git a/fb/fboverlay.c b/fb/fboverlay.c
index 998be66..a882ffa 100644
--- a/fb/fboverlay.c
+++ b/fb/fboverlay.c
@@ -81,7 +81,7 @@ fbOverlayCreateWindow(WindowPtr pWin)
 }
 
 Bool
-fbOverlayCloseScreen(int iScreen, ScreenPtr pScreen)
+fbOverlayCloseScreen(ScreenPtr pScreen)
 {
     FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pScreen);
     int i;
diff --git a/fb/fboverlay.h b/fb/fboverlay.h
index 76198cd..9a93457 100644
--- a/fb/fboverlay.h
+++ b/fb/fboverlay.h
@@ -63,7 +63,7 @@ extern _X_EXPORT Bool
  fbOverlayCreateWindow(WindowPtr pWin);
 
 extern _X_EXPORT Bool
- fbOverlayCloseScreen(int iScreen, ScreenPtr pScreen);
+ fbOverlayCloseScreen(ScreenPtr pScreen);
 
 extern _X_EXPORT int
  fbOverlayWindowLayer(WindowPtr pWin);
diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index c0903ec..0833cd4 100644
--- a/fb/fbscreen.c
+++ b/fb/fbscreen.c
@@ -27,7 +27,7 @@
 #include "fb.h"
 
 Bool
-fbCloseScreen(int index, ScreenPtr pScreen)
+fbCloseScreen(ScreenPtr pScreen)
 {
     int d;
     DepthPtr depths = pScreen->allowedDepths;
diff --git a/glx/glxdri.c b/glx/glxdri.c
index b2209c5..f3690c8 100644
--- a/glx/glxdri.c
+++ b/glx/glxdri.c
@@ -846,18 +846,17 @@ static const __DRIextension *loader_extensions[] = {
 };
 
 static Bool
-glxDRIEnterVT(int index, int flags)
+glxDRIEnterVT(ScrnInfoPtr scrn)
 {
-    ScrnInfoPtr scrn = xf86Screens[index];
     Bool ret;
     __GLXDRIscreen *screen = (__GLXDRIscreen *)
-        glxGetScreen(screenInfo.screens[index]);
+        glxGetScreen(xf86ScrnToScreen(scrn));
 
     LogMessage(X_INFO, "AIGLX: Resuming AIGLX clients after VT switch\n");
 
     scrn->EnterVT = screen->enterVT;
 
-    ret = scrn->EnterVT(index, flags);
+    ret = scrn->EnterVT(scrn);
 
     screen->enterVT = scrn->EnterVT;
     scrn->EnterVT = glxDRIEnterVT;
@@ -871,18 +870,17 @@ glxDRIEnterVT(int index, int flags)
 }
 
 static void
-glxDRILeaveVT(int index, int flags)
+glxDRILeaveVT(ScrnInfoPtr scrn)
 {
-    ScrnInfoPtr scrn = xf86Screens[index];
     __GLXDRIscreen *screen = (__GLXDRIscreen *)
-        glxGetScreen(screenInfo.screens[index]);
+        glxGetScreen(xf86ScrnToScreen(scrn));
 
     LogMessage(X_INFO, "AIGLX: Suspending AIGLX clients for VT switch\n");
 
     glxSuspendClients();
 
     scrn->LeaveVT = screen->leaveVT;
-    (*screen->leaveVT) (index, flags);
+    (*screen->leaveVT) (scrn);
     screen->leaveVT = scrn->LeaveVT;
     scrn->LeaveVT = glxDRILeaveVT;
 }
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index cceb126..6614666 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -587,18 +587,17 @@ static const __DRIextension *loader_extensions[] = {
 };
 
 static Bool
-glxDRIEnterVT(int index, int flags)
+glxDRIEnterVT(ScrnInfoPtr scrn)
 {
-    ScrnInfoPtr scrn = xf86Screens[index];
     Bool ret;
     __GLXDRIscreen *screen = (__GLXDRIscreen *)
-        glxGetScreen(screenInfo.screens[index]);
+        glxGetScreen(xf86ScrnToScreen(scrn));
 
     LogMessage(X_INFO, "AIGLX: Resuming AIGLX clients after VT switch\n");
 
     scrn->EnterVT = screen->enterVT;
 
-    ret = scrn->EnterVT(index, flags);
+    ret = scrn->EnterVT(scrn);
 
     screen->enterVT = scrn->EnterVT;
     scrn->EnterVT = glxDRIEnterVT;
@@ -612,18 +611,17 @@ glxDRIEnterVT(int index, int flags)
 }
 
 static void
-glxDRILeaveVT(int index, int flags)
+glxDRILeaveVT(ScrnInfoPtr scrn)
 {
-    ScrnInfoPtr scrn = xf86Screens[index];
     __GLXDRIscreen *screen = (__GLXDRIscreen *)
-        glxGetScreen(screenInfo.screens[index]);
+        glxGetScreen(xf86ScrnToScreen(scrn));
 
     LogMessage(X_INFO, "AIGLX: Suspending AIGLX clients for VT switch\n");
 
     glxSuspendClients();
 
     scrn->LeaveVT = screen->leaveVT;
-    (*screen->leaveVT) (index, flags);
+    (*screen->leaveVT) (scrn);
     screen->leaveVT = scrn->LeaveVT;
     scrn->LeaveVT = glxDRILeaveVT;
 }
diff --git a/glx/glxscreens.c b/glx/glxscreens.c
index 74b4c42..386987e 100644
--- a/glx/glxscreens.c
+++ b/glx/glxscreens.c
@@ -177,7 +177,7 @@ static char GLXServerExtensions[] =
     "GLX_SGIX_pbuffer " "GLX_MESA_copy_sub_buffer " "GLX_INTEL_swap_event";
 
 static Bool
-glxCloseScreen(int index, ScreenPtr pScreen)
+glxCloseScreen(ScreenPtr pScreen)
 {
     __GLXscreen *pGlxScreen = glxGetScreen(pScreen);
 
@@ -185,7 +185,7 @@ glxCloseScreen(int index, ScreenPtr pScreen)
 
     pGlxScreen->destroy(pGlxScreen);
 
-    return pScreen->CloseScreen(index, pScreen);
+    return pScreen->CloseScreen(pScreen);
 }
 
 __GLXscreen *
diff --git a/glx/glxscreens.h b/glx/glxscreens.h
index d5420ee..172268b 100644
--- a/glx/glxscreens.h
+++ b/glx/glxscreens.h
@@ -153,7 +153,7 @@ struct __GLXscreen {
     unsigned GLXminor;
     /*@} */
 
-    Bool (*CloseScreen) (int index, ScreenPtr pScreen);
+    Bool (*CloseScreen) (ScreenPtr pScreen);
 };
 
 void __glXScreenInit(__GLXscreen * screen, ScreenPtr pScreen);
diff --git a/hw/dmx/dmxextension.c b/hw/dmx/dmxextension.c
index faa28a5..d7296ae 100644
--- a/hw/dmx/dmxextension.c
+++ b/hw/dmx/dmxextension.c
@@ -1318,7 +1318,7 @@ dmxAttachScreen(int idx, DMXScreenAttributesPtr attr)
     }
 
     /* Initialize the BE screen resources */
-    dmxBEScreenInit(idx, screenInfo.screens[idx]);
+    dmxBEScreenInit(screenInfo.screens[idx]);
 
     /* TODO: Handle GLX visual initialization.  GLXProxy needs to be
      * updated to handle dynamic addition/removal of screens. */
diff --git a/hw/dmx/dmxscrinit.c b/hw/dmx/dmxscrinit.c
index 37b3f3b..849ef16 100644
--- a/hw/dmx/dmxscrinit.c
+++ b/hw/dmx/dmxscrinit.c
@@ -59,7 +59,7 @@
 #include "mipointer.h"
 #include "micmap.h"
 
-extern Bool dmxCloseScreen(int idx, ScreenPtr pScreen);
+extern Bool dmxCloseScreen(ScreenPtr pScreen);
 static Bool dmxSaveScreen(ScreenPtr pScreen, int what);
 
 static unsigned long dmxGeneration;
@@ -77,9 +77,9 @@ DevPrivateKeyRec dmxGlyphSetPrivateKeyRec;
 /** Initialize the parts of screen \a idx that require access to the
  *  back-end server. */
 void
-dmxBEScreenInit(int idx, ScreenPtr pScreen)
+dmxBEScreenInit(ScreenPtr pScreen)
 {
-    DMXScreenInfo *dmxScreen = &dmxScreens[idx];
+    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
     XSetWindowAttributes attribs;
     XGCValues gcvals;
     unsigned long mask;
@@ -192,11 +192,11 @@ dmxBEScreenInit(int idx, ScreenPtr pScreen)
     }
 }
 
-/** Initialize screen number \a idx. */
+/** Initialize screen number \a pScreen->myNum. */
 Bool
-dmxScreenInit(int idx, ScreenPtr pScreen, int argc, char *argv[])
+dmxScreenInit(ScreenPtr pScreen, int argc, char *argv[])
 {
-    DMXScreenInfo *dmxScreen = &dmxScreens[idx];
+    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
     int i, j;
 
     if (!dixRegisterPrivateKey(&dmxScreenPrivateKeyRec, PRIVATE_SCREEN, 0))
@@ -286,20 +286,20 @@ dmxScreenInit(int idx, ScreenPtr pScreen, int argc, char *argv[])
     }
     else {
         MAXSCREENSALLOC(dmxCursorGeneration);
-        if (dmxCursorGeneration[idx] != serverGeneration) {
+        if (dmxCursorGeneration[pScreen->myNum] != serverGeneration) {
             if (!(miPointerInitialize(pScreen,
                                       &dmxPointerSpriteFuncs,
                                       &dmxPointerCursorFuncs, FALSE)))
                 return FALSE;
 
-            dmxCursorGeneration[idx] = serverGeneration;
+            dmxCursorGeneration[pScreen->myNum] = serverGeneration;
         }
     }
 
     DMX_WRAP(CloseScreen, dmxCloseScreen, dmxScreen, pScreen);
     DMX_WRAP(SaveScreen, dmxSaveScreen, dmxScreen, pScreen);
 
-    dmxBEScreenInit(idx, pScreen);
+    dmxBEScreenInit(pScreen);
 
     if (!dmxShadowFB) {
         /* Wrap GC functions */
@@ -422,12 +422,12 @@ dmxBECloseScreen(ScreenPtr pScreen)
 
 /** Close screen number \a idx. */
 Bool
-dmxCloseScreen(int idx, ScreenPtr pScreen)
+dmxCloseScreen(ScreenPtr pScreen)
 {
-    DMXScreenInfo *dmxScreen = &dmxScreens[idx];
+    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
 
     /* Reset the proc vectors */
-    if (idx == 0) {
+    if (pScreen->myNum == 0) {
         dmxResetRender();
         dmxResetFonts();
     }
@@ -498,7 +498,7 @@ dmxCloseScreen(int idx, ScreenPtr pScreen)
     }
 
     DMX_UNWRAP(CloseScreen, dmxScreen, pScreen);
-    return pScreen->CloseScreen(idx, pScreen);
+    return pScreen->CloseScreen(pScreen);
 }
 
 static Bool
diff --git a/hw/dmx/dmxscrinit.h b/hw/dmx/dmxscrinit.h
index 5c0bfac..9fe9c98 100644
--- a/hw/dmx/dmxscrinit.h
+++ b/hw/dmx/dmxscrinit.h
@@ -40,9 +40,9 @@
 
 #include "scrnintstr.h"
 
-extern Bool dmxScreenInit(int idx, ScreenPtr pScreen, int argc, char *argv[]);
+extern Bool dmxScreenInit(ScreenPtr pScreen, int argc, char *argv[]);
 
-extern void dmxBEScreenInit(int idx, ScreenPtr pScreen);
+extern void dmxBEScreenInit(ScreenPtr pScreen);
 extern void dmxBECloseScreen(ScreenPtr pScreen);
 
 #endif                          /* DMXSCRINIT_H */
diff --git a/hw/dmx/input/dmxconsole.c b/hw/dmx/input/dmxconsole.c
index f63772b..600a705 100644
--- a/hw/dmx/input/dmxconsole.c
+++ b/hw/dmx/input/dmxconsole.c
@@ -640,7 +640,7 @@ dmxCloseConsole(myPrivate * priv)
 }
 
 static Bool
-dmxCloseConsoleScreen(int idx, ScreenPtr pScreen)
+dmxCloseConsoleScreen(ScreenPtr pScreen)
 {
     myPrivate *priv, *last;
 
@@ -650,7 +650,7 @@ dmxCloseConsoleScreen(int idx, ScreenPtr pScreen)
         dmxCloseConsole(last = priv);
 
     DMX_UNWRAP(CloseScreen, last, pScreen);
-    return pScreen->CloseScreen(idx, pScreen);
+    return pScreen->CloseScreen(pScreen);
 }
 
 static Cursor
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index ecdae19..a3b9434 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -606,7 +606,7 @@ KdCreateScreenResources(ScreenPtr pScreen)
 }
 
 Bool
-KdCloseScreen(int index, ScreenPtr pScreen)
+KdCloseScreen(ScreenPtr pScreen)
 {
     KdScreenPriv(pScreen);
     KdScreenInfo *screen = pScreenPriv->screen;
@@ -616,7 +616,7 @@ KdCloseScreen(int index, ScreenPtr pScreen)
     pScreenPriv->closed = TRUE;
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     if (pScreen->CloseScreen)
-        ret = (*pScreen->CloseScreen) (index, pScreen);
+        ret = (*pScreen->CloseScreen) (pScreen);
     else
         ret = TRUE;
 
@@ -776,7 +776,7 @@ KdSetSubpixelOrder(ScreenPtr pScreen, Rotation randr)
 static KdScreenInfo *kdCurrentScreen;
 
 Bool
-KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
+KdScreenInit(ScreenPtr pScreen, int argc, char **argv)
 {
     KdScreenInfo *screen = kdCurrentScreen;
     KdCardInfo *card = screen->card;
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 293798a..a08a218 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -442,13 +442,13 @@ Bool
  KdCreateScreenResources(ScreenPtr pScreen);
 
 Bool
- KdCloseScreen(int index, ScreenPtr pScreen);
+ KdCloseScreen(ScreenPtr pScreen);
 
 Bool
  KdSaveScreen(ScreenPtr pScreen, int on);
 
 Bool
- KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv);
+ KdScreenInit(ScreenPtr pScreen, int argc, char **argv);
 
 void
 
@@ -537,12 +537,12 @@ void
 
 void
 
-KdBlockHandler(int screen,
+KdBlockHandler(ScreenPtr pScreen,
                pointer blockData, pointer timeout, pointer readmask);
 
 void
 
-KdWakeupHandler(int screen,
+KdWakeupHandler(ScreenPtr pScreen,
                 pointer data, unsigned long result, pointer readmask);
 
 void
diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c
index 66cdf67..58ae552 100644
--- a/hw/kdrive/src/kinput.c
+++ b/hw/kdrive/src/kinput.c
@@ -1972,7 +1972,7 @@ _KdEnqueuePointerEvent(KdPointerInfo * pi, int type, int x, int y, int z,
 }
 
 void
-KdBlockHandler(int screen, pointer blockData, pointer timeout, pointer readmask)
+KdBlockHandler(ScreenPtr pScreen, pointer blockData, pointer timeout, pointer readmask)
 {
     KdPointerInfo *pi;
     int myTimeout = 0;
@@ -1998,7 +1998,7 @@ KdBlockHandler(int screen, pointer blockData, pointer timeout, pointer readmask)
 }
 
 void
-KdWakeupHandler(int screen,
+KdWakeupHandler(ScreenPtr pScreen,
                 pointer data, unsigned long lresult, pointer readmask)
 {
     int result = (int) lresult;
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 7097aee..b02dd88 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -58,7 +58,7 @@ of the copyright holder.
 
 /* XvScreenRec fields */
 
-static Bool KdXVCloseScreen(int, ScreenPtr);
+static Bool KdXVCloseScreen(ScreenPtr);
 static int KdXVQueryAdaptors(ScreenPtr, XvAdaptorPtr *, int *);
 
 /* XvAdaptorRec fields */
@@ -1118,7 +1118,7 @@ KdXVClipNotify(WindowPtr pWin, int dx, int dy)
 /**** Required XvScreenRec fields ****/
 
 static Bool
-KdXVCloseScreen(int i, ScreenPtr pScreen)
+KdXVCloseScreen(ScreenPtr pScreen)
 {
     XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
     KdXVScreenPtr ScreenPriv = GET_KDXV_SCREEN(pScreen);
diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index 16edf43..955624f 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -760,9 +760,9 @@ static miPointerScreenFuncRec vfbPointerCursorFuncs = {
 };
 
 static Bool
-vfbCloseScreen(int index, ScreenPtr pScreen)
+vfbCloseScreen(ScreenPtr pScreen)
 {
-    vfbScreenInfoPtr pvfb = &vfbScreens[index];
+    vfbScreenInfoPtr pvfb = &vfbScreens[pScreen->myNum];
     int i;
 
     pScreen->CloseScreen = pvfb->closeScreen;
@@ -781,13 +781,13 @@ vfbCloseScreen(int index, ScreenPtr pScreen)
         (*pScreen->DestroyPixmap) (pScreen->devPrivate);
     pScreen->devPrivate = NULL;
 
-    return pScreen->CloseScreen(index, pScreen);
+    return pScreen->CloseScreen(pScreen);
 }
 
 static Bool
-vfbScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
+vfbScreenInit(ScreenPtr pScreen, int argc, char **argv)
 {
-    vfbScreenInfoPtr pvfb = &vfbScreens[index];
+    vfbScreenInfoPtr pvfb = &vfbScreens[pScreen->myNum];
     int dpix = monitorResolution, dpiy = monitorResolution;
     int ret;
     char *pbits;
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 0eb000d..129660d 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -244,7 +244,7 @@ extern _X_EXPORT void xf86AddDriver(DriverPtr driver, pointer module,
                                     int flags);
 extern _X_EXPORT void xf86DeleteDriver(int drvIndex);
 extern _X_EXPORT ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags);
-extern _X_EXPORT void xf86DeleteScreen(int scrnIndex, int flags);
+extern _X_EXPORT void xf86DeleteScreen(ScrnInfoPtr pScrn);
 extern _X_EXPORT int xf86AllocateScrnInfoPrivateIndex(void);
 extern _X_EXPORT Bool xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp,
                                        int pad);
@@ -256,7 +256,7 @@ extern _X_EXPORT Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual);
 extern _X_EXPORT Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma newGamma);
 extern _X_EXPORT void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y);
 extern _X_EXPORT void xf86SetBlackWhitePixels(ScreenPtr pScreen);
-extern _X_EXPORT void xf86EnableDisableFBAccess(int scrnIndex, Bool enable);
+extern _X_EXPORT void xf86EnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable);
 extern _X_EXPORT void
 xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb,
                 const char *format, va_list args)
@@ -347,7 +347,7 @@ xf86SetBackingStore(ScreenPtr pScreen);
 extern _X_EXPORT void
 xf86SetSilkenMouse(ScreenPtr pScreen);
 extern _X_EXPORT pointer
-xf86FindXvOptions(int scrnIndex, int adapt_index, char *port_name,
+xf86FindXvOptions(ScrnInfoPtr pScrn, int adapt_index, char *port_name,
                   char **adaptor_name, pointer *adaptor_options);
 extern _X_EXPORT void
 xf86GetOS(const char **name, int *major, int *minor, int *teeny);
@@ -357,7 +357,7 @@ xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag,
                    EntityProc enter, EntityProc leave, pointer private);
 
 extern _X_EXPORT Bool
-xf86IsScreenPrimary(int scrnIndex);
+xf86IsScreenPrimary(ScrnInfoPtr pScrn);
 extern _X_EXPORT int
 xf86RegisterRootWindowProperty(int ScrnIndex, Atom property, Atom type,
                                int format, unsigned long len, pointer value);
@@ -458,4 +458,6 @@ extern _X_EXPORT ScreenPtr xf86ScrnToScreen(ScrnInfoPtr pScrn);
 
 #define XF86_HAS_SCRN_CONV 1 /* define for drivers to use in api compat */
 
+#define XF86_SCRN_INTERFACE 1 /* define for drivers to use in api compat */
+
 #endif                          /* _XF86_H */
diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index b876434..6c86f5e 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -179,7 +179,7 @@ xf86BusConfig(void)
             xf86Msg(X_ERROR,
                     "Screen %d deleted because of no matching config section.\n",
                     i);
-            xf86DeleteScreen(i--, 0);
+            xf86DeleteScreen(xf86Screens[i--]);
         }
     }
 
@@ -377,13 +377,12 @@ xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex)
 }
 
 /*
- * xf86ClearEntitiesForScreen() - called when a screen is deleted
+ * xf86ClearEntityListForScreen() - called when a screen is deleted
  * to mark it's entities unused. Called by xf86DeleteScreen().
  */
 void
-xf86ClearEntityListForScreen(int scrnIndex)
+xf86ClearEntityListForScreen(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     int i, entityIndex;
 
     if (pScrn->entityList == NULL || pScrn->numEntities == 0)
diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
index 61cae6a..c01cfd1 100644
--- a/hw/xfree86/common/xf86Cursor.c
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -66,7 +66,7 @@ static Bool xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y);
 static void xf86CrossScreen(ScreenPtr pScreen, Bool entering);
 static void xf86WarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y);
 
-static void xf86PointerMoved(int scrnIndex, int x, int y);
+static void xf86PointerMoved(ScrnInfoPtr pScrn, int x, int y);
 
 static miPointerScreenFuncRec xf86PointerScreenFuncs = {
     xf86CursorOffScreen,
@@ -135,14 +135,13 @@ xf86SetViewport(ScreenPtr pScreen, int x, int y)
 {
     ScrnInfoPtr pScr = xf86ScreenToScrn(pScreen);
 
-    (*pScr->PointerMoved) (pScreen->myNum, x, y);
+    (*pScr->PointerMoved) (pScr, x, y);
 }
 
 static void
-xf86PointerMoved(int scrnIndex, int x, int y)
+xf86PointerMoved(ScrnInfoPtr pScr, int x, int y)
 {
     Bool frameChanged = FALSE;
-    ScrnInfoPtr pScr = xf86Screens[scrnIndex];
 
     /*
      * check wether (x,y) belongs to the visual part of the screen
@@ -173,7 +172,7 @@ xf86PointerMoved(int scrnIndex, int x, int y)
     }
 
     if (frameChanged && pScr->AdjustFrame != NULL)
-        pScr->AdjustFrame(pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0);
+        pScr->AdjustFrame(pScr, pScr->frameX0, pScr->frameY0);
 }
 
 /*
@@ -230,7 +229,7 @@ xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode)
         miPointerGetPosition(dev, &px, &py);
 
     was_blocked = xf86BlockSIGIO();
-    Switched = (*pScr->SwitchMode) (pScr->scrnIndex, mode, 0);
+    Switched = (*pScr->SwitchMode) (pScr, mode);
     if (Switched) {
         pScr->currentMode = mode;
 
@@ -271,7 +270,7 @@ xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode)
     xf86UnblockSIGIO(was_blocked);
 
     if (pScr->AdjustFrame)
-        (*pScr->AdjustFrame) (pScr->scrnIndex, pScr->frameX0, pScr->frameY0, 0);
+        (*pScr->AdjustFrame) (pScr, pScr->frameX0, pScr->frameY0);
 
     /* The original code centered the frame around the cursor if possible.
      * Since this is hard to achieve with multiple cursors, we do the following:
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index e0314d8..6416372 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -56,7 +56,7 @@ static DevPrivateKeyRec DGAScreenKeyRec;
 #define DGAScreenKeyRegistered dixPrivateKeyRegistered(&DGAScreenKeyRec)
 static Bool mieq_installed;
 
-static Bool DGACloseScreen(int i, ScreenPtr pScreen);
+static Bool DGACloseScreen(ScreenPtr pScreen);
 static void DGADestroyColormap(ColormapPtr pmap);
 static void DGAInstallColormap(ColormapPtr pmap);
 static void DGAUninstallColormap(ColormapPtr pmap);
@@ -235,7 +235,7 @@ FreeMarkedVisuals(ScreenPtr pScreen)
 }
 
 static Bool
-DGACloseScreen(int i, ScreenPtr pScreen)
+DGACloseScreen(ScreenPtr pScreen)
 {
     DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
@@ -256,7 +256,7 @@ DGACloseScreen(int i, ScreenPtr pScreen)
 
     free(pScreenPriv);
 
-    return ((*pScreen->CloseScreen) (i, pScreen));
+    return ((*pScreen->CloseScreen) (pScreen));
 }
 
 static void
@@ -323,11 +323,10 @@ DGAUninstallColormap(ColormapPtr pmap)
 }
 
 int
-xf86SetDGAMode(int index, int num, DGADevicePtr devRet)
+xf86SetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr devRet)
 {
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     DGAScreenPtr pScreenPriv;
-    ScrnInfoPtr pScrn;
     DGADevicePtr device;
     PixmapPtr pPix = NULL;
     DGAModePtr pMode = NULL;
@@ -338,7 +337,6 @@ xf86SetDGAMode(int index, int num, DGADevicePtr devRet)
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
     if (!pScreenPriv)
         return BadValue;
-    pScrn = pScreenPriv->pScrn;
 
     if (!num) {
         if (pScreenPriv->current) {
@@ -359,7 +357,7 @@ xf86SetDGAMode(int index, int num, DGADevicePtr devRet)
                 pScreenPriv->savedColormap = NULL;
             }
             pScreenPriv->dgaColormap = NULL;
-            (*pScrn->EnableDisableFBAccess) (index, TRUE);
+            (*pScrn->EnableDisableFBAccess) (pScrn, TRUE);
 
             FreeMarkedVisuals(pScreen);
         }
@@ -385,7 +383,7 @@ xf86SetDGAMode(int index, int num, DGADevicePtr devRet)
         Bool oldVTSema = pScrn->vtSema;
 
         pScrn->vtSema = FALSE;  /* kludge until we rewrite VT switching */
-        (*pScrn->EnableDisableFBAccess) (index, FALSE);
+        (*pScrn->EnableDisableFBAccess) (pScrn, FALSE);
         pScrn->vtSema = oldVTSema;
     }
 
@@ -564,7 +562,7 @@ DGAShutdown(void)
     for (i = 0; i < screenInfo.numScreens; i++) {
         pScrn = xf86Screens[i];
 
-        (void) (*pScrn->SetDGAMode) (pScrn->scrnIndex, 0, NULL);
+        (void) (*pScrn->SetDGAMode) (pScrn, 0, NULL);
     }
 }
 
@@ -579,7 +577,7 @@ DGASetMode(int index, int num, XDGAModePtr mode, PixmapPtr *pPix)
 
     /* We rely on the extension to check that DGA is available */
 
-    ret = (*pScrn->SetDGAMode) (index, num, &device);
+    ret = (*pScrn->SetDGAMode) (pScrn, num, &device);
     if ((ret == Success) && num) {
         DGACopyModeInfo(device.mode, mode);
         *pPix = device.pPix;
diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index 54ad842..ef4a2c1 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -49,7 +49,7 @@
 #ifdef DPMSExtension
 static DevPrivateKeyRec DPMSKeyRec;
 static DevPrivateKey DPMSKey;
-static Bool DPMSClose(int i, ScreenPtr pScreen);
+static Bool DPMSClose(ScreenPtr pScreen);
 static int DPMSCount = 0;
 #endif
 
@@ -99,10 +99,10 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
 #ifdef DPMSExtension
 
 static Bool
-DPMSClose(int i, ScreenPtr pScreen)
+DPMSClose(ScreenPtr pScreen)
 {
     DPMSPtr pDPMS;
-
+    ScrnInfoPtr pScrn;
     /* This shouldn't happen */
     if (DPMSKey == NULL)
         return FALSE;
@@ -114,20 +114,20 @@ DPMSClose(int i, ScreenPtr pScreen)
         return FALSE;
 
     pScreen->CloseScreen = pDPMS->CloseScreen;
-
+    pScrn = xf86ScreenToScrn(pScreen);
     /*
      * Turn on DPMS when shutting down. If this function can be used
      * depends on the order the driver wraps things. If this is called
      * after the driver has shut down everything the driver will have
      * to deal with this internally.
      */
-    if (xf86Screens[i]->vtSema && xf86Screens[i]->DPMSSet) {
-        xf86Screens[i]->DPMSSet(xf86Screens[i], DPMSModeOn, 0);
+    if (pScrn->vtSema && pScrn->DPMSSet) {
+        pScrn->DPMSSet(pScrn, DPMSModeOn, 0);
     }
 
     if (--DPMSCount == 0)
         DPMSKey = NULL;
-    return pScreen->CloseScreen(i, pScreen);
+    return pScreen->CloseScreen(pScreen);
 }
 
 /*
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 5896f22..4fcad40 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -438,7 +438,7 @@ xf86VTSwitch(void)
         for (i = 0; i < xf86NumScreens; i++) {
             if (!(dispatchException & DE_TERMINATE))
                 if (xf86Screens[i]->EnableDisableFBAccess)
-                    (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE);
+                    (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], FALSE);
         }
 
         /*
@@ -459,7 +459,7 @@ xf86VTSwitch(void)
 
         prevSIGIO = xf86BlockSIGIO();
         for (i = 0; i < xf86NumScreens; i++)
-            xf86Screens[i]->LeaveVT(i, 0);
+            xf86Screens[i]->LeaveVT(xf86Screens[i]);
 
         xf86AccessLeave();      /* We need this here, otherwise */
 
@@ -471,13 +471,13 @@ xf86VTSwitch(void)
             DebugF("xf86VTSwitch: Leave failed\n");
             xf86AccessEnter();
             for (i = 0; i < xf86NumScreens; i++) {
-                if (!xf86Screens[i]->EnterVT(i, 0))
+                if (!xf86Screens[i]->EnterVT(xf86Screens[i]))
                     FatalError("EnterVT failed for screen %d\n", i);
             }
             if (!(dispatchException & DE_TERMINATE)) {
                 for (i = 0; i < xf86NumScreens; i++) {
                     if (xf86Screens[i]->EnableDisableFBAccess)
-                        (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE);
+                        (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE);
                 }
             }
             dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
@@ -527,12 +527,12 @@ xf86VTSwitch(void)
         xf86AccessEnter();
         for (i = 0; i < xf86NumScreens; i++) {
             xf86Screens[i]->vtSema = TRUE;
-            if (!xf86Screens[i]->EnterVT(i, 0))
+            if (!xf86Screens[i]->EnterVT(xf86Screens[i]))
                 FatalError("EnterVT failed for screen %d\n", i);
         }
         for (i = 0; i < xf86NumScreens; i++) {
             if (xf86Screens[i]->EnableDisableFBAccess)
-                (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE);
+                (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE);
         }
 
         /* Turn screen saver off when switching back */
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index fb56a0b..5ef1dab 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -198,24 +198,22 @@ xf86AllocateScreen(DriverPtr drv, int flags)
  */
 
 void
-xf86DeleteScreen(int scrnIndex, int flags)
+xf86DeleteScreen(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn;
     int i;
+    int scrnIndex;
 
     /* First check if the screen is valid */
     if (xf86NumScreens == 0 || xf86Screens == NULL)
         return;
 
-    if (scrnIndex > xf86NumScreens - 1)
-        return;
-
-    if (!(pScrn = xf86Screens[scrnIndex]))
+    if (!pScrn)
         return;
 
+    scrnIndex = pScrn->scrnIndex;
     /* If a FreeScreen function is defined, call it here */
     if (pScrn->FreeScreen != NULL)
-        pScrn->FreeScreen(scrnIndex, 0);
+        pScrn->FreeScreen(pScrn);
 
     while (pScrn->modes)
         xf86DeleteMode(&pScrn->modes, pScrn->modes);
@@ -233,7 +231,7 @@ xf86DeleteScreen(int scrnIndex, int flags)
 
     free(pScrn->privates);
 
-    xf86ClearEntityListForScreen(scrnIndex);
+    xf86ClearEntityListForScreen(pScrn);
 
     free(pScrn);
 
@@ -1027,9 +1025,8 @@ xf86SetBlackWhitePixels(ScreenPtr pScreen)
  * private data, and therefore don't need to access pScrnInfo->vtSema.
  */
 void
-xf86EnableDisableFBAccess(int scrnIndex, Bool enable)
+xf86EnableDisableFBAccess(ScrnInfoPtr pScrnInfo, Bool enable)
 {
-    ScrnInfoPtr pScrnInfo = xf86Screens[scrnIndex];
     ScreenPtr pScreen = pScrnInfo->pScreen;
     PixmapPtr pspix;
 
@@ -1651,10 +1648,9 @@ xf86SetSilkenMouse(ScreenPtr pScreen)
 /* Wrote this function for the PM2 Xv driver, preliminary. */
 
 pointer
-xf86FindXvOptions(int scrnIndex, int adaptor_index, char *port_name,
+xf86FindXvOptions(ScrnInfoPtr pScrn, int adaptor_index, char *port_name,
                   char **adaptor_name, pointer *adaptor_options)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     confXvAdaptorPtr adaptor;
     int i;
 
@@ -1726,9 +1722,8 @@ xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex,
 }
 
 Bool
-xf86IsScreenPrimary(int scrnIndex)
+xf86IsScreenPrimary(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     int i;
 
     for (i = 0; i < pScrn->numEntities; i++) {
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index ead47cc..ca6efd4 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -591,7 +591,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
         }
         for (i = 0; i < xf86NumScreens; i++)
             if (!xf86Screens[i]->configured)
-                xf86DeleteScreen(i--, 0);
+                xf86DeleteScreen(xf86Screens[i--]);
 
         /*
          * If no screens left, return now.
@@ -1040,7 +1040,7 @@ AbortDDX(enum ExitCode error)
                  * screen explicitely.
                  */
                 xf86VGAarbiterLock(xf86Screens[i]);
-                (xf86Screens[i]->LeaveVT) (i, 0);
+                (xf86Screens[i]->LeaveVT) (xf86Screens[i]);
                 xf86VGAarbiterUnlock(xf86Screens[i]);
             }
     }
diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c
index ab4d595..d80dec8 100644
--- a/hw/xfree86/common/xf86Mode.c
+++ b/hw/xfree86/common/xf86Mode.c
@@ -950,7 +950,7 @@ xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode,
                 mode->SynthClock /= 2;
         }
 
-        status = (*scrp->ValidMode) (scrp->scrnIndex, mode, FALSE,
+        status = (*scrp->ValidMode) (scrp, mode, FALSE,
                                      MODECHECK_INITIAL);
         if (status != MODE_OK)
             return status;
@@ -1840,7 +1840,7 @@ xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes,
             scrp->virtualX = newVirtX;
             scrp->virtualY = newVirtY;
             scrp->displayWidth = newLinePitch;
-            p->status = (scrp->ValidMode) (scrp->scrnIndex, p, FALSE,
+            p->status = (scrp->ValidMode) (scrp, p, FALSE,
                                            MODECHECK_FINAL);
 
             if (p->status != MODE_OK) {
diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h
index 31f5c6a..bf56acd 100644
--- a/hw/xfree86/common/xf86Module.h
+++ b/hw/xfree86/common/xf86Module.h
@@ -82,7 +82,7 @@ typedef enum {
  * mask is 0xFFFF0000.
  */
 #define ABI_ANSIC_VERSION	SET_ABI_VERSION(0, 4)
-#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(12, 0)
+#define ABI_VIDEODRV_VERSION	SET_ABI_VERSION(13, 0)
 #define ABI_XINPUT_VERSION	SET_ABI_VERSION(17, 0)
 #define ABI_EXTENSION_VERSION	SET_ABI_VERSION(6, 0)
 #define ABI_FONT_VERSION	SET_ABI_VERSION(0, 6)
diff --git a/hw/xfree86/common/xf86PM.c b/hw/xfree86/common/xf86PM.c
index f69fffa..1830640 100644
--- a/hw/xfree86/common/xf86PM.c
+++ b/hw/xfree86/common/xf86PM.c
@@ -102,7 +102,7 @@ suspend(pmEvent event, Bool undo)
 
     for (i = 0; i < xf86NumScreens; i++) {
         if (xf86Screens[i]->EnableDisableFBAccess)
-            (*xf86Screens[i]->EnableDisableFBAccess) (i, FALSE);
+            (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], FALSE);
     }
     pInfo = xf86InputDevs;
     while (pInfo) {
@@ -112,9 +112,9 @@ suspend(pmEvent event, Bool undo)
     sigio_blocked_for_suspend = xf86BlockSIGIO();
     for (i = 0; i < xf86NumScreens; i++) {
         if (xf86Screens[i]->PMEvent)
-            xf86Screens[i]->PMEvent(i, event, undo);
+            xf86Screens[i]->PMEvent(xf86Screens[i], event, undo);
         else {
-            xf86Screens[i]->LeaveVT(i, 0);
+            xf86Screens[i]->LeaveVT(xf86Screens[i]);
             xf86Screens[i]->vtSema = FALSE;
         }
     }
@@ -131,16 +131,16 @@ resume(pmEvent event, Bool undo)
     xf86AccessEnter();
     for (i = 0; i < xf86NumScreens; i++) {
         if (xf86Screens[i]->PMEvent)
-            xf86Screens[i]->PMEvent(i, event, undo);
+            xf86Screens[i]->PMEvent(xf86Screens[i], event, undo);
         else {
             xf86Screens[i]->vtSema = TRUE;
-            xf86Screens[i]->EnterVT(i, 0);
+            xf86Screens[i]->EnterVT(xf86Screens[i]);
         }
     }
     xf86UnblockSIGIO(sigio_blocked_for_suspend);
     for (i = 0; i < xf86NumScreens; i++) {
         if (xf86Screens[i]->EnableDisableFBAccess)
-            (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE);
+            (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE);
     }
     dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
     pInfo = xf86InputDevs;
@@ -187,7 +187,7 @@ DoApmEvent(pmEvent event, Bool undo)
         was_blocked = xf86BlockSIGIO();
         for (i = 0; i < xf86NumScreens; i++) {
             if (xf86Screens[i]->PMEvent) {
-                xf86Screens[i]->PMEvent(i, event, undo);
+                xf86Screens[i]->PMEvent(xf86Screens[i], event, undo);
             }
         }
         xf86UnblockSIGIO(was_blocked);
diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
index 6c5efea..42a3b30 100644
--- a/hw/xfree86/common/xf86Priv.h
+++ b/hw/xfree86/common/xf86Priv.h
@@ -114,7 +114,7 @@ extern _X_EXPORT void xf86BusProbe(void);
 extern _X_EXPORT void xf86AccessEnter(void);
 extern _X_EXPORT void xf86AccessLeave(void);
 extern _X_EXPORT void xf86PostProbe(void);
-extern _X_EXPORT void xf86ClearEntityListForScreen(int scrnIndex);
+extern _X_EXPORT void xf86ClearEntityListForScreen(ScrnInfoPtr pScrn);
 extern _X_EXPORT void xf86AddDevToEntity(int entityIndex, GDevPtr dev);
 extern _X_EXPORT void xf86RemoveDevFromEntity(int entityIndex, GDevPtr dev);
 
diff --git a/hw/xfree86/common/xf86RandR.c b/hw/xfree86/common/xf86RandR.c
index b17f601..5606bee 100644
--- a/hw/xfree86/common/xf86RandR.c
+++ b/hw/xfree86/common/xf86RandR.c
@@ -159,7 +159,7 @@ xf86RandRSetMode(ScreenPtr pScreen,
     Bool ret = TRUE;
 
     if (pRoot && scrp->vtSema)
-        (*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE);
+        (*scrp->EnableDisableFBAccess) (scrp, FALSE);
     if (useVirtual) {
         scrp->virtualX = randrp->virtualX;
         scrp->virtualY = randrp->virtualY;
@@ -220,7 +220,7 @@ xf86RandRSetMode(ScreenPtr pScreen,
     xf86SetViewport(pScreen, pScreen->width, pScreen->height);
     xf86SetViewport(pScreen, 0, 0);
     if (pRoot && scrp->vtSema)
-        (*scrp->EnableDisableFBAccess) (pScreen->myNum, TRUE);
+        (*scrp->EnableDisableFBAccess) (scrp, TRUE);
     return ret;
 }
 
@@ -365,7 +365,7 @@ xf86RandRCreateScreenResources(ScreenPtr pScreen)
  * Reset size back to original
  */
 static Bool
-xf86RandRCloseScreen(int index, ScreenPtr pScreen)
+xf86RandRCloseScreen(ScreenPtr pScreen)
 {
     ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen);
     XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
@@ -376,7 +376,7 @@ xf86RandRCloseScreen(int index, ScreenPtr pScreen)
     pScreen->CloseScreen = randrp->CloseScreen;
     free(randrp);
     dixSetPrivate(&pScreen->devPrivates, xf86RandRKey, NULL);
-    return (*pScreen->CloseScreen) (index, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 Rotation
diff --git a/hw/xfree86/common/xf86VGAarbiter.c b/hw/xfree86/common/xf86VGAarbiter.c
index b9b46f6..225fff0 100644
--- a/hw/xfree86/common/xf86VGAarbiter.c
+++ b/hw/xfree86/common/xf86VGAarbiter.c
@@ -221,7 +221,7 @@ xf86VGAarbiterWrapFunctions(void)
 
 /* Screen funcs */
 static Bool
-VGAarbiterCloseScreen(int i, ScreenPtr pScreen)
+VGAarbiterCloseScreen(ScreenPtr pScreen)
 {
     Bool val;
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
@@ -258,34 +258,30 @@ VGAarbiterCloseScreen(int i, ScreenPtr pScreen)
     UNWRAP_SPRITE;
 
     free((pointer) pScreenPriv);
-    xf86VGAarbiterLock(xf86Screens[i]);
-    val = (*pScreen->CloseScreen) (i, pScreen);
-    xf86VGAarbiterUnlock(xf86Screens[i]);
+    xf86VGAarbiterLock(xf86ScreenToScrn(pScreen));
+    val = (*pScreen->CloseScreen) (pScreen);
+    xf86VGAarbiterUnlock(xf86ScreenToScrn(pScreen));
     return val;
 }
 
 static void
-VGAarbiterBlockHandler(int i,
-                       pointer blockData, pointer pTimeout, pointer pReadmask)
+VGAarbiterBlockHandler(ScreenPtr pScreen,
+                       pointer pTimeout, pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[i];
-
     SCREEN_PROLOG(BlockHandler);
     VGAGet(pScreen);
-    pScreen->BlockHandler(i, blockData, pTimeout, pReadmask);
+    pScreen->BlockHandler(pScreen, pTimeout, pReadmask);
     VGAPut();
     SCREEN_EPILOG(BlockHandler, VGAarbiterBlockHandler);
 }
 
 static void
-VGAarbiterWakeupHandler(int i, pointer blockData, unsigned long result,
+VGAarbiterWakeupHandler(ScreenPtr pScreen, unsigned long result,
                         pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[i];
-
     SCREEN_PROLOG(WakeupHandler);
     VGAGet(pScreen);
-    pScreen->WakeupHandler(i, blockData, result, pReadmask);
+    pScreen->WakeupHandler(pScreen, result, pReadmask);
     VGAPut();
     SCREEN_EPILOG(WakeupHandler, VGAarbiterWakeupHandler);
 }
@@ -466,46 +462,45 @@ VGAarbiterSetCursorPosition(DeviceIntPtr pDev,
 }
 
 static void
-VGAarbiterAdjustFrame(int index, int x, int y, int flags)
+VGAarbiterAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
 {
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     VGAarbiterScreenPtr pScreenPriv =
         (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
                                                VGAarbiterScreenKey);
 
     VGAGet(pScreen);
-    (*pScreenPriv->AdjustFrame) (index, x, y, flags);
+    (*pScreenPriv->AdjustFrame) (pScrn, x, y);
     VGAPut();
 }
 
 static Bool
-VGAarbiterSwitchMode(int index, DisplayModePtr mode, int flags)
+VGAarbiterSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 {
     Bool val;
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     VGAarbiterScreenPtr pScreenPriv =
         (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
                                                VGAarbiterScreenKey);
 
     VGAGet(pScreen);
-    val = (*pScreenPriv->SwitchMode) (index, mode, flags);
+    val = (*pScreenPriv->SwitchMode) (pScrn, mode);
     VGAPut();
     return val;
 }
 
 static Bool
-VGAarbiterEnterVT(int index, int flags)
+VGAarbiterEnterVT(ScrnInfoPtr pScrn)
 {
     Bool val;
-    ScrnInfoPtr pScrn = xf86Screens[index];
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     VGAarbiterScreenPtr pScreenPriv =
         (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
                                                VGAarbiterScreenKey);
 
     VGAGet(pScreen);
     pScrn->EnterVT = pScreenPriv->EnterVT;
-    val = (*pScrn->EnterVT) (index, flags);
+    val = (*pScrn->EnterVT) (pScrn);
     pScreenPriv->EnterVT = pScrn->EnterVT;
     pScrn->EnterVT = VGAarbiterEnterVT;
     VGAPut();
@@ -513,32 +508,31 @@ VGAarbiterEnterVT(int index, int flags)
 }
 
 static void
-VGAarbiterLeaveVT(int index, int flags)
+VGAarbiterLeaveVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[index];
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     VGAarbiterScreenPtr pScreenPriv =
         (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
                                                VGAarbiterScreenKey);
 
     VGAGet(pScreen);
     pScrn->LeaveVT = pScreenPriv->LeaveVT;
-    (*pScreenPriv->LeaveVT) (index, flags);
+    (*pScreenPriv->LeaveVT) (pScrn);
     pScreenPriv->LeaveVT = pScrn->LeaveVT;
     pScrn->LeaveVT = VGAarbiterLeaveVT;
     VGAPut();
 }
 
 static void
-VGAarbiterFreeScreen(int index, int flags)
+VGAarbiterFreeScreen(ScrnInfoPtr pScrn)
 {
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     VGAarbiterScreenPtr pScreenPriv =
         (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
                                                VGAarbiterScreenKey);
 
     VGAGet(pScreen);
-    (*pScreenPriv->FreeScreen) (index, flags);
+    (*pScreenPriv->FreeScreen) (pScrn);
     VGAPut();
 }
 
diff --git a/hw/xfree86/common/xf86VGAarbiterPriv.h b/hw/xfree86/common/xf86VGAarbiterPriv.h
index ebc8854..ba6edfc 100644
--- a/hw/xfree86/common/xf86VGAarbiterPriv.h
+++ b/hw/xfree86/common/xf86VGAarbiterPriv.h
@@ -125,11 +125,11 @@ typedef struct _VGAarbiterScreen {
     UnrealizeCursorProcPtr UnrealizeCursor;
     RecolorCursorProcPtr RecolorCursor;
     SetCursorPositionProcPtr SetCursorPosition;
-    void (*AdjustFrame) (int, int, int, int);
-    Bool (*SwitchMode) (int, DisplayModePtr, int);
-    Bool (*EnterVT) (int, int);
-    void (*LeaveVT) (int, int);
-    void (*FreeScreen) (int, int);
+    void (*AdjustFrame) (ScrnInfoPtr, int, int);
+    Bool (*SwitchMode) (ScrnInfoPtr, DisplayModePtr);
+    Bool (*EnterVT) (ScrnInfoPtr);
+    void (*LeaveVT) (ScrnInfoPtr);
+    void (*FreeScreen) (ScrnInfoPtr);
     miPointerSpriteFuncPtr miSprite;
     CompositeProcPtr Composite;
     GlyphsProcPtr Glyphs;
@@ -142,11 +142,11 @@ typedef struct _VGAarbiterGC {
 } VGAarbiterGCRec, *VGAarbiterGCPtr;
 
 /* Screen funcs */
-static void VGAarbiterBlockHandler(int i, pointer blockData, pointer pTimeout,
+static void VGAarbiterBlockHandler(ScreenPtr pScreen, pointer pTimeout,
                                    pointer pReadmask);
-static void VGAarbiterWakeupHandler(int i, pointer blockData,
+static void VGAarbiterWakeupHandler(ScreenPtr pScreen,
                                     unsigned long result, pointer pReadmask);
-static Bool VGAarbiterCloseScreen(int i, ScreenPtr pScreen);
+static Bool VGAarbiterCloseScreen(ScreenPtr pScreen);
 static void VGAarbiterGetImage(DrawablePtr pDrawable, int sx, int sy, int w,
                                int h, unsigned int format,
                                unsigned long planemask, char *pdstLine);
@@ -176,11 +176,11 @@ static Bool VGAarbiterDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
 static Bool VGAarbiterSetCursorPosition(DeviceIntPtr pDev, ScreenPtr
                                         pScreen, int x, int y,
                                         Bool generateEvent);
-static void VGAarbiterAdjustFrame(int index, int x, int y, int flags);
-static Bool VGAarbiterSwitchMode(int index, DisplayModePtr mode, int flags);
-static Bool VGAarbiterEnterVT(int index, int flags);
-static void VGAarbiterLeaveVT(int index, int flags);
-static void VGAarbiterFreeScreen(int index, int flags);
+static void VGAarbiterAdjustFrame(ScrnInfoPtr pScrn, int x, int y);
+static Bool VGAarbiterSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode);
+static Bool VGAarbiterEnterVT(ScrnInfoPtr pScrn);
+static void VGAarbiterLeaveVT(ScrnInfoPtr pScrn);
+static void VGAarbiterFreeScreen(ScrnInfoPtr pScrn);
 
 /* GC funcs */
 static void VGAarbiterValidateGC(GCPtr pGC, unsigned long changes,
diff --git a/hw/xfree86/common/xf86VidMode.c b/hw/xfree86/common/xf86VidMode.c
index 13ffe06..a7d1c25 100644
--- a/hw/xfree86/common/xf86VidMode.c
+++ b/hw/xfree86/common/xf86VidMode.c
@@ -50,7 +50,7 @@
 static DevPrivateKeyRec VidModeKeyRec;
 static DevPrivateKey VidModeKey;
 static int VidModeCount = 0;
-static Bool VidModeClose(int i, ScreenPtr pScreen);
+static Bool VidModeClose(ScreenPtr pScreen);
 
 #define VMPTR(p) ((VidModePtr)dixLookupPrivate(&(p)->devPrivates, VidModeKey))
 
@@ -93,7 +93,7 @@ VidModeExtensionInit(ScreenPtr pScreen)
 #ifdef XF86VIDMODE
 
 static Bool
-VidModeClose(int i, ScreenPtr pScreen)
+VidModeClose(ScreenPtr pScreen)
 {
     VidModePtr pVidMode = VMPTR(pScreen);
 
@@ -108,7 +108,7 @@ VidModeClose(int i, ScreenPtr pScreen)
         dixSetPrivate(&pScreen->devPrivates, VidModeKey, NULL);
         VidModeKey = NULL;
     }
-    return pScreen->CloseScreen(i, pScreen);
+    return pScreen->CloseScreen(pScreen);
 }
 
 Bool
@@ -303,7 +303,7 @@ VidModeSetViewPort(int scrnIndex, int x, int y)
                          pScrn->virtualY - pScrn->currentMode->VDisplay);
     pScrn->frameY1 = pScrn->frameY0 + pScrn->currentMode->VDisplay - 1;
     if (pScrn->AdjustFrame != NULL)
-        (pScrn->AdjustFrame) (scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+        (pScrn->AdjustFrame) (pScrn, pScrn->frameX0, pScrn->frameY0);
 
     return TRUE;
 }
diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index 460fafd..25f84e5 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -80,9 +80,9 @@ typedef struct {
     DestroyColormapProcPtr DestroyColormap;
     InstallColormapProcPtr InstallColormap;
     StoreColorsProcPtr StoreColors;
-    Bool (*EnterVT) (int, int);
-    Bool (*SwitchMode) (int, DisplayModePtr, int);
-    int (*SetDGAMode) (int, int, DGADevicePtr);
+    Bool (*EnterVT) (ScrnInfoPtr);
+    Bool (*SwitchMode) (ScrnInfoPtr, DisplayModePtr);
+    int (*SetDGAMode) (ScrnInfoPtr, int, DGADevicePtr);
     xf86ChangeGammaProc *ChangeGamma;
     int maxColors;
     int sigRGBbits;
@@ -111,17 +111,17 @@ static DevPrivateKeyRec CMapColormapKeyRec;
 
 static void CMapInstallColormap(ColormapPtr);
 static void CMapStoreColors(ColormapPtr, int, xColorItem *);
-static Bool CMapCloseScreen(int, ScreenPtr);
+static Bool CMapCloseScreen(ScreenPtr);
 static Bool CMapCreateColormap(ColormapPtr);
 static void CMapDestroyColormap(ColormapPtr);
 
-static Bool CMapEnterVT(int, int);
-static Bool CMapSwitchMode(int, DisplayModePtr, int);
+static Bool CMapEnterVT(ScrnInfoPtr);
+static Bool CMapSwitchMode(ScrnInfoPtr, DisplayModePtr);
 
 #ifdef XFreeXDGA
-static int CMapSetDGAMode(int, int, DGADevicePtr);
+static int CMapSetDGAMode(ScrnInfoPtr, int, DGADevicePtr);
 #endif
-static int CMapChangeGamma(int, Gamma);
+static int CMapChangeGamma(ScrnInfoPtr, Gamma);
 
 static void ComputeGamma(CMapScreenPtr);
 static Bool CMapAllocateColormapPrivate(ColormapPtr);
@@ -241,11 +241,11 @@ xf86HandleColormaps(ScreenPtr pScreen,
 /**** Screen functions ****/
 
 static Bool
-CMapCloseScreen(int i, ScreenPtr pScreen)
+CMapCloseScreen(ScreenPtr pScreen)
 {
     CMapUnwrapScreen(pScreen);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static Bool
@@ -462,16 +462,15 @@ CMapInstallColormap(ColormapPtr pmap)
 /**** ScrnInfoRec functions ****/
 
 static Bool
-CMapEnterVT(int index, int flags)
+CMapEnterVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[index];
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     Bool ret;
     CMapScreenPtr pScreenPriv =
         (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
 
     pScrn->EnterVT = pScreenPriv->EnterVT;
-    ret = (*pScreenPriv->EnterVT) (index, flags);
+    ret = (*pScreenPriv->EnterVT) (pScrn);
     pScreenPriv->EnterVT = pScrn->EnterVT;
     pScrn->EnterVT = CMapEnterVT;
     if (ret) {
@@ -483,13 +482,13 @@ CMapEnterVT(int index, int flags)
 }
 
 static Bool
-CMapSwitchMode(int index, DisplayModePtr mode, int flags)
+CMapSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 {
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     CMapScreenPtr pScreenPriv =
         (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
 
-    if ((*pScreenPriv->SwitchMode) (index, mode, flags)) {
+    if ((*pScreenPriv->SwitchMode) (pScrn, mode)) {
         if (GetInstalledmiColormap(pScreen))
             CMapReinstallMap(GetInstalledmiColormap(pScreen));
         return TRUE;
@@ -499,16 +498,16 @@ CMapSwitchMode(int index, DisplayModePtr mode, int flags)
 
 #ifdef XFreeXDGA
 static int
-CMapSetDGAMode(int index, int num, DGADevicePtr dev)
+CMapSetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr dev)
 {
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     CMapScreenPtr pScreenPriv =
         (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
     int ret;
 
-    ret = (*pScreenPriv->SetDGAMode) (index, num, dev);
+    ret = (*pScreenPriv->SetDGAMode) (pScrn, num, dev);
 
-    pScreenPriv->isDGAmode = DGAActive(index);
+    pScreenPriv->isDGAmode = DGAActive(pScrn->scrnIndex);
 
     if (!pScreenPriv->isDGAmode && GetInstalledmiColormap(pScreen)
         && xf86ScreenToScrn(pScreen)->vtSema)
@@ -908,11 +907,10 @@ ComputeGamma(CMapScreenPtr priv)
 }
 
 int
-CMapChangeGamma(int index, Gamma gamma)
+CMapChangeGamma(ScrnInfoPtr pScrn, Gamma gamma)
 {
     int ret = Success;
-    ScrnInfoPtr pScrn = xf86Screens[index];
-    ScreenPtr pScreen = pScrn->pScreen;
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     CMapColormapPtr pColPriv;
     CMapScreenPtr pScreenPriv;
     CMapLinkPtr pLink;
@@ -979,7 +977,7 @@ CMapChangeGamma(int index, Gamma gamma)
 
     pScrn->ChangeGamma = pScreenPriv->ChangeGamma;
     if (pScrn->ChangeGamma)
-        ret = pScrn->ChangeGamma(index, gamma);
+        ret = pScrn->ChangeGamma(pScrn, gamma);
     pScrn->ChangeGamma = CMapChangeGamma;
 
     return ret;
@@ -1175,7 +1173,7 @@ xf86ChangeGamma(ScreenPtr pScreen, Gamma gamma)
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
 
     if (pScrn->ChangeGamma)
-        return (*pScrn->ChangeGamma) (pScreen->myNum, gamma);
+        return (*pScrn->ChangeGamma) (pScrn, gamma);
 
     return BadImplementation;
 }
diff --git a/hw/xfree86/common/xf86fbman.c b/hw/xfree86/common/xf86fbman.c
index e2db1c3..c2e7bab 100644
--- a/hw/xfree86/common/xf86fbman.c
+++ b/hw/xfree86/common/xf86fbman.c
@@ -1149,7 +1149,7 @@ static FBManagerFuncs xf86FBManFuncs = {
 };
 
 static Bool
-xf86FBCloseScreen(int i, ScreenPtr pScreen)
+xf86FBCloseScreen(ScreenPtr pScreen)
 {
     FBLinkPtr pLink, tmp;
     FBLinearLinkPtr pLinearLink, tmp2;
@@ -1180,7 +1180,7 @@ xf86FBCloseScreen(int i, ScreenPtr pScreen)
     free(offman);
     dixSetPrivate(&pScreen->devPrivates, xf86FBScreenKey, NULL);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 Bool
diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c
index 27d24f8..b6a6b94 100644
--- a/hw/xfree86/common/xf86sbusBus.c
+++ b/hw/xfree86/common/xf86sbusBus.c
@@ -667,7 +667,7 @@ xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
 }
 
 static Bool
-xf86SbusCmapCloseScreen(int i, ScreenPtr pScreen)
+xf86SbusCmapCloseScreen(ScreenPtr pScreen)
 {
     sbusCmapPtr cmap;
     struct fbcmap fbcmap;
@@ -683,7 +683,7 @@ xf86SbusCmapCloseScreen(int i, ScreenPtr pScreen)
     }
     pScreen->CloseScreen = cmap->CloseScreen;
     free(cmap);
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 Bool
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index 6294845..a1404c3 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -630,18 +630,18 @@ typedef struct {
 
 typedef Bool xf86ProbeProc(DriverPtr, int);
 typedef Bool xf86PreInitProc(ScrnInfoPtr, int);
-typedef Bool xf86ScreenInitProc(int, ScreenPtr, int, char **);
-typedef Bool xf86SwitchModeProc(int, DisplayModePtr, int);
-typedef void xf86AdjustFrameProc(int, int, int, int);
-typedef Bool xf86EnterVTProc(int, int);
-typedef void xf86LeaveVTProc(int, int);
-typedef void xf86FreeScreenProc(int, int);
-typedef ModeStatus xf86ValidModeProc(int, DisplayModePtr, Bool, int);
-typedef void xf86EnableDisableFBAccessProc(int, Bool);
-typedef int xf86SetDGAModeProc(int, int, DGADevicePtr);
-typedef int xf86ChangeGammaProc(int, Gamma);
-typedef void xf86PointerMovedProc(int, int, int);
-typedef Bool xf86PMEventProc(int, pmEvent, Bool);
+typedef Bool xf86ScreenInitProc(ScreenPtr, int, char **);
+typedef Bool xf86SwitchModeProc(ScrnInfoPtr, DisplayModePtr);
+typedef void xf86AdjustFrameProc(ScrnInfoPtr, int, int);
+typedef Bool xf86EnterVTProc(ScrnInfoPtr);
+typedef void xf86LeaveVTProc(ScrnInfoPtr);
+typedef void xf86FreeScreenProc(ScrnInfoPtr);
+typedef ModeStatus xf86ValidModeProc(ScrnInfoPtr, DisplayModePtr, Bool, int);
+typedef void xf86EnableDisableFBAccessProc(ScrnInfoPtr, Bool);
+typedef int xf86SetDGAModeProc(ScrnInfoPtr, int, DGADevicePtr);
+typedef int xf86ChangeGammaProc(ScrnInfoPtr, Gamma);
+typedef void xf86PointerMovedProc(ScrnInfoPtr, int, int);
+typedef Bool xf86PMEventProc(ScrnInfoPtr, pmEvent, Bool);
 typedef void xf86DPMSSetProc(ScrnInfoPtr, int, int);
 typedef void xf86LoadPaletteProc(ScrnInfoPtr, int, int *, LOCO *, VisualPtr);
 typedef void xf86SetOverscanProc(ScrnInfoPtr, int);
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index b100348..1a964d2 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -56,7 +56,7 @@
 
 /* XvScreenRec fields */
 
-static Bool xf86XVCloseScreen(int, ScreenPtr);
+static Bool xf86XVCloseScreen(ScreenPtr);
 static int xf86XVQueryAdaptors(ScreenPtr, XvAdaptorPtr *, int *);
 
 /* XvAdaptorRec fields */
@@ -100,9 +100,9 @@ static void xf86XVClipNotify(WindowPtr pWin, int dx, int dy);
 
 /* ScrnInfoRec functions */
 
-static Bool xf86XVEnterVT(int, int);
-static void xf86XVLeaveVT(int, int);
-static void xf86XVAdjustFrame(int index, int x, int y, int flags);
+static Bool xf86XVEnterVT(ScrnInfoPtr);
+static void xf86XVLeaveVT(ScrnInfoPtr);
+static void xf86XVAdjustFrame(ScrnInfoPtr, int x, int y);
 static void xf86XVModeSet(ScrnInfoPtr pScrn);
 
 /* misc */
@@ -1066,7 +1066,7 @@ xf86XVReputOrStopPort(XvPortRecPrivatePtr pPriv, WindowPtr pWin, Bool visible)
 static void
 xf86XVReputOrStopAllPorts(ScrnInfoPtr pScrn, Bool onlyChanged)
 {
-    ScreenPtr pScreen = pScrn->pScreen;
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
     XvAdaptorPtr pa;
     int c, i;
@@ -1255,7 +1255,7 @@ xf86XVClipNotify(WindowPtr pWin, int dx, int dy)
 /**** Required XvScreenRec fields ****/
 
 static Bool
-xf86XVCloseScreen(int i, ScreenPtr pScreen)
+xf86XVCloseScreen(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
@@ -1299,15 +1299,14 @@ xf86XVQueryAdaptors(ScreenPtr pScreen,
 /**** ScrnInfoRec fields ****/
 
 static Bool
-xf86XVEnterVT(int index, int flags)
+xf86XVEnterVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[index];
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
     Bool ret;
 
     pScrn->EnterVT = ScreenPriv->EnterVT;
-    ret = (*ScreenPriv->EnterVT) (index, flags);
+    ret = (*ScreenPriv->EnterVT) (pScrn);
     ScreenPriv->EnterVT = pScrn->EnterVT;
     pScrn->EnterVT = xf86XVEnterVT;
 
@@ -1318,10 +1317,9 @@ xf86XVEnterVT(int index, int flags)
 }
 
 static void
-xf86XVLeaveVT(int index, int flags)
+xf86XVLeaveVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[index];
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
     XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
     XvAdaptorPtr pAdaptor;
@@ -1353,21 +1351,20 @@ xf86XVLeaveVT(int index, int flags)
     }
 
     pScrn->LeaveVT = ScreenPriv->LeaveVT;
-    (*ScreenPriv->LeaveVT) (index, flags);
+    (*ScreenPriv->LeaveVT) (pScrn);
     ScreenPriv->LeaveVT = pScrn->LeaveVT;
     pScrn->LeaveVT = xf86XVLeaveVT;
 }
 
 static void
-xf86XVAdjustFrame(int index, int x, int y, int flags)
+xf86XVAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
 {
-    ScrnInfoPtr pScrn = xf86Screens[index];
-    ScreenPtr pScreen = pScrn->pScreen;
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
 
     if (ScreenPriv->AdjustFrame) {
         pScrn->AdjustFrame = ScreenPriv->AdjustFrame;
-        (*pScrn->AdjustFrame) (index, x, y, flags);
+        (*pScrn->AdjustFrame) (pScrn, x, y);
         pScrn->AdjustFrame = xf86XVAdjustFrame;
     }
 
@@ -1377,7 +1374,7 @@ xf86XVAdjustFrame(int index, int x, int y, int flags)
 static void
 xf86XVModeSet(ScrnInfoPtr pScrn)
 {
-    ScreenPtr pScreen = pScrn->pScreen;
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XF86XVScreenPtr ScreenPriv;
 
     /* Can be called before pScrn->pScreen is set */
diff --git a/hw/xfree86/common/xf86xvmc.c b/hw/xfree86/common/xf86xvmc.c
index b7da758..2e529dd 100644
--- a/hw/xfree86/common/xf86xvmc.c
+++ b/hw/xfree86/common/xf86xvmc.c
@@ -132,7 +132,7 @@ xf86XvMCDestroySubpicture(XvMCSubpicturePtr pSubpicture)
 }
 
 static Bool
-xf86XvMCCloseScreen(int i, ScreenPtr pScreen)
+xf86XvMCCloseScreen(ScreenPtr pScreen)
 {
     xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pScreen);
 
@@ -141,7 +141,7 @@ xf86XvMCCloseScreen(int i, ScreenPtr pScreen)
     free(pScreenPriv->dixinfo);
     free(pScreenPriv);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 Bool
diff --git a/hw/xfree86/common/xf86xvpriv.h b/hw/xfree86/common/xf86xvpriv.h
index 289ca58..9bedd90 100644
--- a/hw/xfree86/common/xf86xvpriv.h
+++ b/hw/xfree86/common/xf86xvpriv.h
@@ -41,9 +41,9 @@ typedef struct {
     ClipNotifyProcPtr ClipNotify;
     WindowExposuresProcPtr WindowExposures;
     PostValidateTreeProcPtr PostValidateTree;
-    void (*AdjustFrame) (int, int, int, int);
-    Bool (*EnterVT) (int, int);
-    void (*LeaveVT) (int, int);
+    void (*AdjustFrame) (ScrnInfoPtr, int, int, int);
+    Bool (*EnterVT) (ScrnInfoPtr);
+    void (*LeaveVT) (ScrnInfoPtr);
     xf86ModeSetProc *ModeSet;
 } XF86XVScreenRec, *XF86XVScreenPtr;
 
diff --git a/hw/xfree86/ddc/ddc.c b/hw/xfree86/ddc/ddc.c
index a1281d7..28c9696 100644
--- a/hw/xfree86/ddc/ddc.c
+++ b/hw/xfree86/ddc/ddc.c
@@ -258,10 +258,9 @@ EDIDRead_DDC1(ScrnInfoPtr pScrn, DDC1SetSpeedProc DDCSpeed,
  * @return NULL if no monitor attached or failure to interpret the EDID.
  */
 xf86MonPtr
-xf86DoEDID_DDC1(int scrnIndex, DDC1SetSpeedProc DDC1SetSpeed,
+xf86DoEDID_DDC1(ScrnInfoPtr pScrn, DDC1SetSpeedProc DDC1SetSpeed,
                 unsigned int (*DDC1Read) (ScrnInfoPtr))
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     unsigned char *EDID_block = NULL;
     xf86MonPtr tmp = NULL;
 
@@ -285,7 +284,7 @@ xf86DoEDID_DDC1(int scrnIndex, DDC1SetSpeedProc DDC1SetSpeed,
     OsReleaseSignals();
 
     if (EDID_block) {
-        tmp = xf86InterpretEDID(scrnIndex, EDID_block);
+        tmp = xf86InterpretEDID(pScrn->scrnIndex, EDID_block);
     }
 #ifdef DEBUG
     else
@@ -323,7 +322,7 @@ DDC2MakeDevice(I2CBusPtr pBus, int address, char *name)
 }
 
 static I2CDevPtr
-DDC2Init(int scrnIndex, I2CBusPtr pBus)
+DDC2Init(I2CBusPtr pBus)
 {
     I2CDevPtr dev = NULL;
 
@@ -403,9 +402,8 @@ DDC2Read(I2CDevPtr dev, int block, unsigned char *R_Buffer)
  * @return NULL if no monitor attached or failure to interpret the EDID.
  */
 xf86MonPtr
-xf86DoEEDID(int scrnIndex, I2CBusPtr pBus, Bool complete)
+xf86DoEEDID(ScrnInfoPtr pScrn, I2CBusPtr pBus, Bool complete)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     unsigned char *EDID_block = NULL;
     xf86MonPtr tmp = NULL;
     I2CDevPtr dev = NULL;
@@ -427,7 +425,7 @@ xf86DoEEDID(int scrnIndex, I2CBusPtr pBus, Bool complete)
     if (noddc || noddc2)
         return NULL;
 
-    if (!(dev = DDC2Init(scrnIndex, pBus)))
+    if (!(dev = DDC2Init(pBus)))
         return NULL;
 
     EDID_block = calloc(1, EDID1_LEN);
@@ -444,7 +442,7 @@ xf86DoEEDID(int scrnIndex, I2CBusPtr pBus, Bool complete)
                 DDC2Read(dev, i + 1, EDID_block + (EDID1_LEN * (1 + i)));
         }
 
-        tmp = xf86InterpretEEDID(scrnIndex, EDID_block);
+        tmp = xf86InterpretEEDID(pScrn->scrnIndex, EDID_block);
     }
 
     if (tmp && complete)
@@ -465,9 +463,9 @@ xf86DoEEDID(int scrnIndex, I2CBusPtr pBus, Bool complete)
  * @return NULL if no monitor attached or failure to interpret the EDID.
  */
 xf86MonPtr
-xf86DoEDID_DDC2(int scrnIndex, I2CBusPtr pBus)
+xf86DoEDID_DDC2(ScrnInfoPtr pScrn, I2CBusPtr pBus)
 {
-    return xf86DoEEDID(scrnIndex, pBus, FALSE);
+    return xf86DoEEDID(pScrn, pBus, FALSE);
 }
 
 /* XXX write me */
@@ -489,9 +487,8 @@ DDC2ReadDisplayID(void)
  * @return NULL if no monitor attached or failure to interpret the DisplayID.
  */
 xf86MonPtr
-xf86DoDisplayID(int scrnIndex, I2CBusPtr pBus)
+xf86DoDisplayID(ScrnInfoPtr pScrn, I2CBusPtr pBus)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     unsigned char *did = NULL;
     xf86MonPtr tmp = NULL;
     I2CDevPtr dev = NULL;
@@ -513,7 +510,7 @@ xf86DoDisplayID(int scrnIndex, I2CBusPtr pBus)
     if (noddc || noddc2)
         return NULL;
 
-    if (!(dev = DDC2Init(scrnIndex, pBus)))
+    if (!(dev = DDC2Init(pBus)))
         return NULL;
 
     if ((did = DDC2ReadDisplayID())) {
@@ -521,7 +518,7 @@ xf86DoDisplayID(int scrnIndex, I2CBusPtr pBus)
         if (!tmp)
             return NULL;
 
-        tmp->scrnIndex = scrnIndex;
+        tmp->scrnIndex = pScrn->scrnIndex;
         tmp->flags |= MONITOR_DISPLAYID;
         tmp->rawData = did;
     }
diff --git a/hw/xfree86/ddc/xf86DDC.h b/hw/xfree86/ddc/xf86DDC.h
index 2071d53..c63da8b 100644
--- a/hw/xfree86/ddc/xf86DDC.h
+++ b/hw/xfree86/ddc/xf86DDC.h
@@ -24,15 +24,15 @@ typedef enum {
 
 typedef void (*DDC1SetSpeedProc) (ScrnInfoPtr, xf86ddcSpeed);
 
-extern _X_EXPORT xf86MonPtr xf86DoEDID_DDC1(int scrnIndex,
+extern _X_EXPORT xf86MonPtr xf86DoEDID_DDC1(ScrnInfoPtr pScrn,
                                             DDC1SetSpeedProc DDC1SetSpeed,
                                             unsigned
                                             int (*DDC1Read) (ScrnInfoPtr)
     );
 
-extern _X_EXPORT xf86MonPtr xf86DoEDID_DDC2(int scrnIndex, I2CBusPtr pBus);
+extern _X_EXPORT xf86MonPtr xf86DoEDID_DDC2(ScrnInfoPtr pScrn, I2CBusPtr pBus);
 
-extern _X_EXPORT xf86MonPtr xf86DoEEDID(int scrnIndex, I2CBusPtr pBus, Bool);
+extern _X_EXPORT xf86MonPtr xf86DoEEDID(ScrnInfoPtr pScrn, I2CBusPtr pBus, Bool);
 
 extern _X_EXPORT xf86MonPtr xf86PrintEDID(xf86MonPtr monPtr);
 
@@ -50,7 +50,7 @@ extern _X_EXPORT DisplayModePtr xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC);
 extern _X_EXPORT Bool
  xf86MonitorIsHDMI(xf86MonPtr mon);
 
-extern _X_EXPORT xf86MonPtr xf86DoDisplayID(int scrnIndex, I2CBusPtr pBus);
+extern _X_EXPORT xf86MonPtr xf86DoDisplayID(ScrnInfoPtr pScrn, I2CBusPtr pBus);
 
 extern _X_EXPORT void
  xf86DisplayIDMonitorSet(int scrnIndex, MonPtr mon, xf86MonPtr DDC);
diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml
index a6b9da2..24b0c03 100644
--- a/hw/xfree86/doc/ddxDesign.xml
+++ b/hw/xfree86/doc/ddxDesign.xml
@@ -1306,7 +1306,7 @@ Here is what <function>InitOutput()</function> does:
 
       <blockquote><para>
 	  <programlisting>
-    Bool ChipScreenInit(int index, ScreenPtr pScreen,
+    Bool ChipScreenInit(ScreenPtr pScreen,
                         int argc, char **argv);
 	  </programlisting>
 	  <blockquote><para>
@@ -1442,7 +1442,7 @@ Here is what <function>InitOutput()</function> does:
 
       <blockquote><para>
 	  <programlisting>
-    Bool ChipSwitchMode(int index, DisplayModePtr mode, int flags);
+    Bool ChipSwitchMode(int index, DisplayModePtr mode);
 	  </programlisting>
 	  <blockquote><para>
       Initialises the new mode for the screen identified by
@@ -1464,7 +1464,7 @@ Here is what <function>InitOutput()</function> does:
 
       <blockquote><para>
 	  <programlisting>
-    void ChipAdjustFrame(int index, int x, int y, int flags);
+    void ChipAdjustFrame(int index, int x, int y);
 	  </programlisting>
 	  <blockquote><para>
       Changes the viewport for the screen identified by
@@ -1572,7 +1572,7 @@ Here is what <function>InitOutput()</function> does:
 
       <blockquote><para>
 	  <programlisting>
-    Bool ChipEnterVT(int index, int flags);
+    Bool ChipEnterVT(ScrnInfoPtr pScrn);
 	  </programlisting>
 	  <blockquote><para>
       This function should initialise the current video mode and
@@ -1589,7 +1589,7 @@ Here is what <function>InitOutput()</function> does:
 
       <blockquote><para>
 	  <programlisting>
-    void ChipLeaveVT(int index, int flags);
+    void ChipLeaveVT(ScrnInfoPtr pScrn);
 	  </programlisting>
 	  <blockquote><para>
       This function should restore the saved video state.  If
@@ -1691,7 +1691,7 @@ but their presence is optional.
 
       <blockquote><para>
 	  <programlisting>
-    ModeStatus ChipValidMode(int index, DisplayModePtr mode,
+    ModeStatus ChipValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode,
                              Bool verbose, int flags);
 	  </programlisting>
 	  <blockquote><para>
@@ -1739,7 +1739,7 @@ MODECHECK_FINAL are intended for checks that may involve more than one mode.
 
       <blockquote><para>
 	  <programlisting>
-    void ChipFreeScreen(int scrnindex, int flags);
+    void ChipFreeScreen(ScrnInfoPtr pScrn);
 	  </programlisting>
 	  <blockquote><para>
       Free any driver-allocated data that may have been allocated up to
@@ -2824,12 +2824,12 @@ Several functions are provided to simplify resource registration:
 
 	  <blockquote><para>
 	      <programlisting>
-    Bool xf86IsScreenPrimary(int scrnIndex);
+    Bool xf86IsScreenPrimary(ScrnInfoPtr pScrn);
 	      </programlisting>
 	      <blockquote><para>
       This function returns <constant>TRUE</constant> if the primary entity
       is registered with the screen referenced by
-      <parameter>scrnIndex</parameter>.
+      <parameter>pScrn</parameter>.
 		</para>
 
 	      </blockquote></para></blockquote>
@@ -9033,7 +9033,7 @@ ZZZModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
 
 	<programlisting>
 static Bool
-ZZZScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
+ZZZScreenInit(ScreenPtr pScreen, int argc, char **argv)
 {
     /* Get the ScrnInfoRec */
     pScrn = xf86ScreenToScrn(pScreen);
@@ -9051,7 +9051,7 @@ ZZZScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     /* Set the viewport if supported */
 
-    ZZZAdjustFrame(scrnIndex, pScrn-&gt;frameX0, pScrn-&gt;frameY0, 0);
+    ZZZAdjustFrame(pScrn, pScrn-&gt;frameX0, pScrn-&gt;frameY0);
 
     /*
      * Setup the screen's visuals, and initialise the framebuffer
@@ -9220,9 +9220,9 @@ ZZZScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
 	<programlisting>
 static Bool
-ZZZSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+ZZZSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 {
-    return ZZZModeInit(xf86Screens[scrnIndex], mode);
+    return ZZZModeInit(pScrn, mode);
 }
 	</programlisting>
       </sect3>
@@ -9237,7 +9237,7 @@ ZZZSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
 
 	<programlisting>
 static void
-ZZZAdjustFrame(int scrnIndex, int x, int y, int flags)
+ZZZAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
 {
     /* Adjust the viewport */
 }
@@ -9258,16 +9258,14 @@ ZZZAdjustFrame(int scrnIndex, int x, int y, int flags)
 
 	<programlisting>
 static Bool
-ZZZEnterVT(int scrnIndex, int flags)
+ZZZEnterVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     return ZZZModeInit(pScrn, pScrn-&gt;currentMode);
 }
 
 static void
-ZZZLeaveVT(int scrnIndex, int flags)
+ZZZLeaveVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     ZZZRestore(pScrn);
 }
 	</programlisting>
@@ -9288,16 +9286,16 @@ ZZZLeaveVT(int scrnIndex, int flags)
 
 	<programlisting>
 static Bool
-ZZZCloseScreen(int scrnIndex, ScreenPtr pScreen)
+ZZZCloseScreen(ScreenPtr pScreen)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     if (pScrn-&gt;vtSema) {
         ZZZRestore(pScrn);
         ZZZUnmapMem(pScrn);
     }
     pScrn-&gt;vtSema = FALSE;
     pScreen-&gt;CloseScreen = ZZZPTR(pScrn)-&gt;CloseScreen;
-    return (*pScreen-&gt;CloseScreen)(scrnIndex, pScreen);
+    return (*pScreen-&gt;CloseScreen)(pScreen);
 }
 	</programlisting>
       </sect3>
@@ -9342,13 +9340,13 @@ ZZZSaveScreen(ScreenPtr pScreen, int mode)
 
 	<programlisting>
 static void
-ZZZFreeScreen(int scrnIndex, int flags)
+ZZZFreeScreen(ScrnInfoPtr pScrn)
 {
     /*
      * If the vgahw module is used vgaHWFreeHWRec() would be called
      * here.
      */
-    ZZZFreeRec(xf86Screens[scrnIndex]);
+    ZZZFreeRec(pScrn);
 }
 
 	</programlisting>
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index 20eb683..46a9ae4 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1618,7 +1618,7 @@ DRIWakeupHandler(pointer wakeupData, int result, pointer pReadmask)
         DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
         if (pDRIPriv && pDRIPriv->pDriverInfo->wrap.WakeupHandler)
-            (*pDRIPriv->pDriverInfo->wrap.WakeupHandler) (i, wakeupData,
+            (*pDRIPriv->pDriverInfo->wrap.WakeupHandler) (pScreen,
                                                           result, pReadmask);
     }
 }
@@ -1633,16 +1633,15 @@ DRIBlockHandler(pointer blockData, OSTimePtr pTimeout, pointer pReadmask)
         DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
         if (pDRIPriv && pDRIPriv->pDriverInfo->wrap.BlockHandler)
-            (*pDRIPriv->pDriverInfo->wrap.BlockHandler) (i, blockData,
+            (*pDRIPriv->pDriverInfo->wrap.BlockHandler) (pScreen,
                                                          pTimeout, pReadmask);
     }
 }
 
 void
-DRIDoWakeupHandler(int screenNum, pointer wakeupData,
+DRIDoWakeupHandler(ScreenPtr pScreen,
                    unsigned long result, pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[screenNum];
     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
     DRILock(pScreen, 0);
@@ -1658,10 +1657,9 @@ DRIDoWakeupHandler(int screenNum, pointer wakeupData,
 }
 
 void
-DRIDoBlockHandler(int screenNum, pointer blockData,
+DRIDoBlockHandler(ScreenPtr pScreen,
                   pointer pTimeout, pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[screenNum];
     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
     if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) {
@@ -2307,15 +2305,14 @@ _DRIAdjustFrame(ScrnInfoPtr pScrn, DRIScreenPrivPtr pDRIPriv, int x, int y)
 }
 
 void
-DRIAdjustFrame(int scrnIndex, int x, int y, int flags)
+DRIAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
 {
-    ScreenPtr pScreen = screenInfo.screens[scrnIndex];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     int px, py;
 
     if (!pDRIPriv || !pDRIPriv->pSAREA) {
-        DRIDrvMsg(scrnIndex, X_ERROR, "[DRI] No SAREA (%p %p)\n",
+        DRIDrvMsg(pScrn->scrnIndex, X_ERROR, "[DRI] No SAREA (%p %p)\n",
                   pDRIPriv, pDRIPriv ? pDRIPriv->pSAREA : NULL);
         return;
     }
@@ -2347,7 +2344,7 @@ DRIAdjustFrame(int scrnIndex, int x, int y, int flags)
         /* unwrap */
         pScrn->AdjustFrame = pDRIPriv->wrap.AdjustFrame;
         /* call lower layers */
-        (*pScrn->AdjustFrame) (scrnIndex, x, y, flags);
+        (*pScrn->AdjustFrame) (pScrn, x, y);
         /* rewrap */
         pDRIPriv->wrap.AdjustFrame = pScrn->AdjustFrame;
         pScrn->AdjustFrame = DRIAdjustFrame;
diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h
index 53458bb..0a4036c 100644
--- a/hw/xfree86/dri/dri.h
+++ b/hw/xfree86/dri/dri.h
@@ -73,7 +73,7 @@ typedef int DRIWindowRequests;
 #define DRI_ALL_WINDOWS      2
 
 typedef void (*ClipNotifyPtr) (WindowPtr, int, int);
-typedef void (*AdjustFramePtr) (int scrnIndex, int x, int y, int flags);
+typedef void (*AdjustFramePtr) (ScrnInfoPtr pScrn, int x, int y);
 
 /*
  * These functions can be wrapped by the DRI.  Each of these have
@@ -271,13 +271,11 @@ extern _X_EXPORT void DRIWakeupHandler(pointer wakeupData,
 extern _X_EXPORT void DRIBlockHandler(pointer blockData,
                                       OSTimePtr pTimeout, pointer pReadmask);
 
-extern _X_EXPORT void DRIDoWakeupHandler(int screenNum,
-                                         pointer wakeupData,
+extern _X_EXPORT void DRIDoWakeupHandler(ScreenPtr pScreen,
                                          unsigned long result,
                                          pointer pReadmask);
 
-extern _X_EXPORT void DRIDoBlockHandler(int screenNum,
-                                        pointer blockData,
+extern _X_EXPORT void DRIDoBlockHandler(ScreenPtr pScreen,
                                         pointer pTimeout, pointer pReadmask);
 
 extern _X_EXPORT void DRISwapContext(int drmFD, void *oldctx, void *newctx);
@@ -334,7 +332,7 @@ extern _X_EXPORT drm_context_t DRIGetContext(ScreenPtr pScreen);
 extern _X_EXPORT void DRIQueryVersion(int *majorVersion,
                                       int *minorVersion, int *patchVersion);
 
-extern _X_EXPORT void DRIAdjustFrame(int scrnIndex, int x, int y, int flags);
+extern _X_EXPORT void DRIAdjustFrame(ScrnInfoPtr pScrn, int x, int y);
 
 extern _X_EXPORT void DRIMoveBuffersHelper(ScreenPtr pScreen,
                                            int dx,
diff --git a/hw/xfree86/exa/examodule.c b/hw/xfree86/exa/examodule.c
index 5092458..4e809ea 100644
--- a/hw/xfree86/exa/examodule.c
+++ b/hw/xfree86/exa/examodule.c
@@ -38,7 +38,7 @@
 
 typedef struct _ExaXorgScreenPrivRec {
     CloseScreenProcPtr SavedCloseScreen;
-    EnableDisableFBAccessProcPtr SavedEnableDisableFBAccess;
+    xf86EnableDisableFBAccessProc *SavedEnableDisableFBAccess;
     OptionInfoPtr options;
 } ExaXorgScreenPrivRec, *ExaXorgScreenPrivPtr;
 
@@ -70,7 +70,7 @@ static const OptionInfoRec EXAOptions[] = {
 };
 
 static Bool
-exaXorgCloseScreen(int i, ScreenPtr pScreen)
+exaXorgCloseScreen(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr)
@@ -83,24 +83,24 @@ exaXorgCloseScreen(int i, ScreenPtr pScreen)
     free(pScreenPriv->options);
     free(pScreenPriv);
 
-    return pScreen->CloseScreen(i, pScreen);
+    return pScreen->CloseScreen(pScreen);
 }
 
 static void
-exaXorgEnableDisableFBAccess(int index, Bool enable)
+exaXorgEnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable)
 {
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr)
         dixLookupPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey);
 
     if (!enable)
-        exaEnableDisableFBAccess(index, enable);
+        exaEnableDisableFBAccess(pScreen, enable);
 
     if (pScreenPriv->SavedEnableDisableFBAccess)
-        pScreenPriv->SavedEnableDisableFBAccess(index, enable);
+        pScreenPriv->SavedEnableDisableFBAccess(pScrn, enable);
 
     if (enable)
-        exaEnableDisableFBAccess(index, enable);
+        exaEnableDisableFBAccess(pScreen, enable);
 }
 
 /**
diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c
index 0444d48..d4b5558 100644
--- a/hw/xfree86/fbdevhw/fbdevhw.c
+++ b/hw/xfree86/fbdevhw/fbdevhw.c
@@ -775,10 +775,8 @@ fbdevHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
 /* these can be hooked directly into ScrnInfoRec                        */
 
 ModeStatus
-fbdevHWValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
+fbdevHWValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, Bool verbose, int flags)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-
     if (!fbdevHWSetMode(pScrn, mode, TRUE))
         return MODE_BAD;
 
@@ -786,10 +784,8 @@ fbdevHWValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
 }
 
 Bool
-fbdevHWSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+fbdevHWSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-
     if (!fbdevHWSetMode(pScrn, mode, FALSE))
         return FALSE;
 
@@ -797,9 +793,8 @@ fbdevHWSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
 }
 
 void
-fbdevHWAdjustFrame(int scrnIndex, int x, int y, int flags)
+fbdevHWAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     fbdevHWPtr fPtr = FBDEVHWPTR(pScrn);
 
     if (x < 0 || x + fPtr->var.xres > fPtr->var.xres_virtual ||
@@ -809,26 +804,22 @@ fbdevHWAdjustFrame(int scrnIndex, int x, int y, int flags)
     fPtr->var.xoffset = x;
     fPtr->var.yoffset = y;
     if (-1 == ioctl(fPtr->fd, FBIOPAN_DISPLAY, (void *) &fPtr->var))
-        xf86DrvMsgVerb(scrnIndex, X_WARNING, 5,
+        xf86DrvMsgVerb(pScrn->scrnIndex, X_WARNING, 5,
                        "FBIOPAN_DISPLAY: %s\n", strerror(errno));
 }
 
 Bool
-fbdevHWEnterVT(int scrnIndex, int flags)
+fbdevHWEnterVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-
     if (!fbdevHWModeInit(pScrn, pScrn->currentMode))
         return FALSE;
-    fbdevHWAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+    fbdevHWAdjustFrame(pScrn, pScrn->frameX0, pScrn->frameY0);
     return TRUE;
 }
 
 void
-fbdevHWLeaveVT(int scrnIndex, int flags)
+fbdevHWLeaveVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-
     fbdevHWRestore(pScrn);
 }
 
diff --git a/hw/xfree86/fbdevhw/fbdevhw.h b/hw/xfree86/fbdevhw/fbdevhw.h
index 5369871..4984ccf 100644
--- a/hw/xfree86/fbdevhw/fbdevhw.h
+++ b/hw/xfree86/fbdevhw/fbdevhw.h
@@ -44,14 +44,12 @@ extern _X_EXPORT void fbdevHWLoadPalette(ScrnInfoPtr pScrn, int numColors,
                                          int *indices, LOCO * colors,
                                          VisualPtr pVisual);
 
-extern _X_EXPORT ModeStatus fbdevHWValidMode(int scrnIndex, DisplayModePtr mode,
+extern _X_EXPORT ModeStatus fbdevHWValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode,
                                              Bool verbose, int flags);
-extern _X_EXPORT Bool fbdevHWSwitchMode(int scrnIndex, DisplayModePtr mode,
-                                        int flags);
-extern _X_EXPORT void fbdevHWAdjustFrame(int scrnIndex, int x, int y,
-                                         int flags);
-extern _X_EXPORT Bool fbdevHWEnterVT(int scrnIndex, int flags);
-extern _X_EXPORT void fbdevHWLeaveVT(int scrnIndex, int flags);
+extern _X_EXPORT Bool fbdevHWSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode);
+extern _X_EXPORT void fbdevHWAdjustFrame(ScrnInfoPtr pScrn, int x, int y);
+extern _X_EXPORT Bool fbdevHWEnterVT(ScrnInfoPtr pScrn);
+extern _X_EXPORT void fbdevHWLeaveVT(ScrnInfoPtr pScrn);
 extern _X_EXPORT void fbdevHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags);
 
 extern _X_EXPORT Bool fbdevHWSaveScreen(ScreenPtr pScreen, int mode);
diff --git a/hw/xfree86/fbdevhw/fbdevhwstub.c b/hw/xfree86/fbdevhw/fbdevhwstub.c
index 6e0a470..b7b4d2e 100644
--- a/hw/xfree86/fbdevhw/fbdevhwstub.c
+++ b/hw/xfree86/fbdevhw/fbdevhwstub.c
@@ -131,30 +131,30 @@ fbdevHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
 }
 
 ModeStatus
-fbdevHWValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
+fbdevHWValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, Bool verbose, int flags)
 {
     return MODE_ERROR;
 }
 
 Bool
-fbdevHWSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+fbdevHWSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 {
     return FALSE;
 }
 
 void
-fbdevHWAdjustFrame(int scrnIndex, int x, int y, int flags)
+fbdevHWAdjustFrame(ScrnInfoPtr pScrn, int x, int y, int flags)
 {
 }
 
 Bool
-fbdevHWEnterVT(int scrnIndex, int flags)
+fbdevHWEnterVT(ScrnInfoPtr pScrn)
 {
     return FALSE;
 }
 
 void
-fbdevHWLeaveVT(int scrnIndex, int flags)
+fbdevHWLeaveVT(ScrnInfoPtr pScrn)
 {
 }
 
diff --git a/hw/xfree86/i2c/xf86i2c.c b/hw/xfree86/i2c/xf86i2c.c
index 1273f4b..2d261d4 100644
--- a/hw/xfree86/i2c/xf86i2c.c
+++ b/hw/xfree86/i2c/xf86i2c.c
@@ -709,6 +709,7 @@ xf86CreateI2CBusRec(void)
 
     if (b != NULL) {
         b->scrnIndex = -1;
+        b->pScrn = NULL;
         b->HoldTime = 5;        /* 100 kHz bus */
         b->BitTimeout = 5;
         b->ByteTimeout = 5;
diff --git a/hw/xfree86/i2c/xf86i2c.h b/hw/xfree86/i2c/xf86i2c.h
index 9a8fb21..e296d7d 100644
--- a/hw/xfree86/i2c/xf86i2c.h
+++ b/hw/xfree86/i2c/xf86i2c.h
@@ -6,6 +6,7 @@
 #define _XF86I2C_H
 
 #include "regionstr.h"
+#include "xf86.h"
 
 typedef unsigned char I2CByte;
 typedef unsigned short I2CSlaveAddr;
@@ -18,6 +19,7 @@ typedef struct _I2CDevRec *I2CDevPtr;
 typedef struct _I2CBusRec {
     char *BusName;
     int scrnIndex;
+    ScrnInfoPtr pScrn;
 
     void (*I2CUDelay) (I2CBusPtr b, int usec);
 
diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c
index 8614e0b..5343e47 100644
--- a/hw/xfree86/int10/generic.c
+++ b/hw/xfree86/int10/generic.c
@@ -70,12 +70,12 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
     void *base = 0;
     void *vbiosMem = 0;
     void *options = NULL;
-    int screen;
     legacyVGARec vga;
+    ScrnInfoPtr pScrn;
 
-    screen = (xf86FindScreenForEntity(entityIndex))->scrnIndex;
+    pScrn = xf86FindScreenForEntity(entityIndex);
 
-    options = xf86HandleInt10Options(xf86Screens[screen], entityIndex);
+    options = xf86HandleInt10Options(pScrn, entityIndex);
 
     if (int10skip(options)) {
         free(options);
@@ -89,7 +89,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
     pInt->mem = &genericMem;
     pInt->private = (pointer) xnfcalloc(1, sizeof(genericInt10Priv));
     INTPriv(pInt)->alloc = (pointer) xnfcalloc(1, ALLOC_ENTRIES(getpagesize()));
-    pInt->scrnIndex = screen;
+    pInt->pScrn = pScrn;
     base = INTPriv(pInt)->base = xnfalloc(SYS_BIOS);
 
     /* FIXME: Shouldn't this be a failure case?  Leaving dev as NULL seems like
@@ -109,7 +109,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
     INTPriv(pInt)->sysMem = sysMem;
 
     if (xf86ReadBIOS(0, 0, base, LOW_PAGE_SIZE) < 0) {
-        xf86DrvMsg(screen, X_ERROR, "Cannot read int vect\n");
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Cannot read int vect\n");
         goto error1;
     }
 
@@ -148,7 +148,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
             vbiosMem = (unsigned char *) base + bios_location;
             err = pci_device_read_rom(rom_device, vbiosMem);
             if (err) {
-                xf86DrvMsg(screen, X_ERROR, "Cannot read V_BIOS (3) %s\n",
+                xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Cannot read V_BIOS (3) %s\n",
                            strerror(err));
                 goto error1;
             }
@@ -249,7 +249,6 @@ MapVRam(xf86Int10InfoPtr pInt)
 static void
 UnmapVRam(xf86Int10InfoPtr pInt)
 {
-    int screen = pInt->scrnIndex;
     int pagesize = getpagesize();
     int size = ((VRAM_SIZE + pagesize - 1) / pagesize) * pagesize;
 
diff --git a/hw/xfree86/int10/helper_exec.c b/hw/xfree86/int10/helper_exec.c
index 1e90877..1c58cf7 100644
--- a/hw/xfree86/int10/helper_exec.c
+++ b/hw/xfree86/int10/helper_exec.c
@@ -125,7 +125,7 @@ run_bios_int(int num, xf86Int10InfoPtr pInt)
     if (MEM_RW(pInt, (num << 2) + 2) == (SYS_BIOS >> 4)) {      /* SYS_BIOS_SEG ? */
 
         if (num == 21 && X86_AH == 0x4e) {
-            xf86DrvMsg(pInt->scrnIndex, X_NOTICE,
+            xf86DrvMsg(pInt->pScrn->scrnIndex, X_NOTICE,
                        "Failing Find-Matching-File on non-PC"
                        " (int 21, func 4e)\n");
             X86_AX = 2;
@@ -133,7 +133,7 @@ run_bios_int(int num, xf86Int10InfoPtr pInt)
             return 1;
         }
         else {
-            xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+            xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                            "Ignoring int 0x%02x call\n", num);
             if (xf86GetVerbosity() > 3) {
                 dump_registers(pInt);
@@ -169,7 +169,7 @@ dump_code(xf86Int10InfoPtr pInt)
     int i;
     CARD32 lina = SEG_ADR((CARD32), X86_CS, IP);
 
-    xf86DrvMsgVerb(pInt->scrnIndex, X_INFO, 3, "code at 0x%8.8" PRIx32 ":\n",
+    xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3, "code at 0x%8.8" PRIx32 ":\n",
                    lina);
     for (i = 0; i < 0x10; i++)
         xf86ErrorFVerb(3, " %2.2x", MEM_RB(pInt, lina + i));
@@ -182,19 +182,19 @@ dump_code(xf86Int10InfoPtr pInt)
 void
 dump_registers(xf86Int10InfoPtr pInt)
 {
-    xf86DrvMsgVerb(pInt->scrnIndex, X_INFO, 3,
+    xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3,
                    "EAX=0x%8.8lx, EBX=0x%8.8lx, ECX=0x%8.8lx, EDX=0x%8.8lx\n",
                    (unsigned long) X86_EAX, (unsigned long) X86_EBX,
                    (unsigned long) X86_ECX, (unsigned long) X86_EDX);
-    xf86DrvMsgVerb(pInt->scrnIndex, X_INFO, 3,
+    xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3,
                    "ESP=0x%8.8lx, EBP=0x%8.8lx, ESI=0x%8.8lx, EDI=0x%8.8lx\n",
                    (unsigned long) X86_ESP, (unsigned long) X86_EBP,
                    (unsigned long) X86_ESI, (unsigned long) X86_EDI);
-    xf86DrvMsgVerb(pInt->scrnIndex, X_INFO, 3,
+    xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3,
                    "CS=0x%4.4x, SS=0x%4.4x,"
                    " DS=0x%4.4x, ES=0x%4.4x, FS=0x%4.4x, GS=0x%4.4x\n",
                    X86_CS, X86_SS, X86_DS, X86_ES, X86_FS, X86_GS);
-    xf86DrvMsgVerb(pInt->scrnIndex, X_INFO, 3,
+    xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3,
                    "EIP=0x%8.8lx, EFLAGS=0x%8.8lx\n",
                    (unsigned long) X86_EIP, (unsigned long) X86_EFLAGS);
 }
@@ -337,7 +337,7 @@ x_inb(CARD16 port)
     }
     else if (port < 0x0100) {   /* Don't interfere with mainboard */
         val = 0;
-        xf86DrvMsgVerb(Int10Current->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(Int10Current->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "inb 0x%4.4x\n", port);
         if (xf86GetVerbosity() > 3) {
             dump_registers(Int10Current);
@@ -395,7 +395,7 @@ x_outb(CARD16 port, CARD8 val)
 #ifdef __NOT_YET__
     }
     else if (port < 0x0100) {   /* Don't interfere with mainboard */
-        xf86DrvMsgVerb(Int10Current->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(Int10Current->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "outb 0x%4.4x,0x%2.2x\n", port, val);
         if (xf86GetVerbosity() > 3) {
             dump_registers(Int10Current);
diff --git a/hw/xfree86/int10/helper_mem.c b/hw/xfree86/int10/helper_mem.c
index 96c598a..160c5ae 100644
--- a/hw/xfree86/int10/helper_mem.c
+++ b/hw/xfree86/int10/helper_mem.c
@@ -281,7 +281,7 @@ xf86int10GetBiosLocationType(const xf86Int10InfoPtr pInt)
 
 #define CHECK_V_SEGMENT_RANGE(x)   \
     if (((x) << 4) < V_BIOS) { \
-	xf86DrvMsg(pInt->scrnIndex, X_ERROR, \
+	xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, \
 		   "V_BIOS address 0x%lx out of range\n", \
 		   (unsigned long)(x) << 4); \
 	return FALSE; \
@@ -306,17 +306,17 @@ xf86int10GetBiosSegment(xf86Int10InfoPtr pInt, void *base)
 
         CHECK_V_SEGMENT_RANGE(cs);
         vbiosMem = (unsigned char *) base + (cs << 4);
-        if (int10_check_bios(pInt->scrnIndex, cs, vbiosMem)) {
+        if (int10_check_bios(pInt->pScrn->scrnIndex, cs, vbiosMem)) {
             break;
         }
     }
 
     if (segments[i] == ~0) {
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR, "No V_BIOS found\n");
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "No V_BIOS found\n");
         return FALSE;
     }
 
-    xf86DrvMsg(pInt->scrnIndex, X_INFO, "Primary V_BIOS segment is: 0x%lx\n",
+    xf86DrvMsg(pInt->pScrn->scrnIndex, X_INFO, "Primary V_BIOS segment is: 0x%lx\n",
                (unsigned long) cs);
 
     pInt->BIOSseg = cs;
diff --git a/hw/xfree86/int10/xf86int10.c b/hw/xfree86/int10/xf86int10.c
index df347d4..5ead44f 100644
--- a/hw/xfree86/int10/xf86int10.c
+++ b/hw/xfree86/int10/xf86int10.c
@@ -57,7 +57,7 @@ int_handler(xf86Int10InfoPtr pInt)
         ret = run_bios_int(num, pInt);
 
     if (!ret) {
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Halting on int 0x%2.2x!\n", num);
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "Halting on int 0x%2.2x!\n", num);
         dump_registers(pInt);
         stack_trace(pInt);
     }
@@ -257,7 +257,7 @@ int42_handler(xf86Int10InfoPtr pInt)
         /*         DL = character column                      */
         /* Not Implemented                                    */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x04) -- Get Light Pen Position\n",
                        pInt->num);
         if (xf86GetVerbosity() > 3) {
@@ -314,10 +314,10 @@ int42_handler(xf86Int10InfoPtr pInt)
         /* Leave:  Nothing                                    */
         /* Not Implemented                                    */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x06) -- Initialise or Scroll Window Up\n",
                        pInt->num);
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 3,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3,
                        " AL=0x%2.2x, BH=0x%2.2x,"
                        " CH=0x%2.2x, CL=0x%2.2x, DH=0x%2.2x, DL=0x%2.2x\n",
                        X86_AL, X86_BH, X86_CH, X86_CL, X86_DH, X86_DL);
@@ -339,10 +339,10 @@ int42_handler(xf86Int10InfoPtr pInt)
         /* Leave:  Nothing                                    */
         /* Not Implemented                                    */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x07) -- Initialise or Scroll Window Down\n",
                        pInt->num);
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 3,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3,
                        " AL=0x%2.2x, BH=0x%2.2x,"
                        " CH=0x%2.2x, CL=0x%2.2x, DH=0x%2.2x, DL=0x%2.2x\n",
                        X86_AL, X86_BH, X86_CH, X86_CL, X86_DH, X86_DL);
@@ -360,10 +360,10 @@ int42_handler(xf86Int10InfoPtr pInt)
         /*         AL = character                             */
         /* Not Implemented                                    */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x08) -- Read Character and Attribute at"
                        " Cursor\n", pInt->num);
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 3,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3,
                        "BH=0x%2.2x\n", X86_BH);
         if (xf86GetVerbosity() > 3) {
             dump_registers(pInt);
@@ -382,10 +382,10 @@ int42_handler(xf86Int10InfoPtr pInt)
         /* Leave:  Nothing                                    */
         /* Not Implemented                                    */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x09) -- Write Character and Attribute at"
                        " Cursor\n", pInt->num);
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 3,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3,
                        "AL=0x%2.2x, BH=0x%2.2x, BL=0x%2.2x, CX=0x%4.4x\n",
                        X86_AL, X86_BH, X86_BL, X86_CX);
         if (xf86GetVerbosity() > 3) {
@@ -404,10 +404,10 @@ int42_handler(xf86Int10InfoPtr pInt)
         /* Leave:  Nothing                                    */
         /* Not Implemented                                    */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x0A) -- Write Character at Cursor\n",
                        pInt->num);
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 3,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3,
                        "AL=0x%2.2x, BH=0x%2.2x, BL=0x%2.2x, CX=0x%4.4x\n",
                        X86_AL, X86_BH, X86_BL, X86_CX);
         if (xf86GetVerbosity() > 3) {
@@ -450,10 +450,10 @@ int42_handler(xf86Int10InfoPtr pInt)
         /* Leave:  Nothing                                    */
         /* Not Implemented                                    */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x0C) -- Write Graphics Pixel\n",
                        pInt->num);
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 3,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3,
                        "AL=0x%2.2x, BH=0x%2.2x, CX=0x%4.4x, DX=0x%4.4x\n",
                        X86_AL, X86_BH, X86_CX, X86_DX);
         if (xf86GetVerbosity() > 3) {
@@ -471,10 +471,10 @@ int42_handler(xf86Int10InfoPtr pInt)
         /* Leave:  AL = pixel value                           */
         /* Not Implemented                                    */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x0D) -- Read Graphics Pixel\n",
                        pInt->num);
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 3,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3,
                        "BH=0x%2.2x, CX=0x%4.4x, DX=0x%4.4x\n", X86_BH, X86_CX,
                        X86_DX);
         if (xf86GetVerbosity() > 3) {
@@ -498,10 +498,10 @@ int42_handler(xf86Int10InfoPtr pInt)
         /*           which might or might not have been       */
         /*           installed yet.                           */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x0E) -- Write Character in Teletype Mode\n",
                        pInt->num);
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 3,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3,
                        "AL=0x%2.2x, BH=0x%2.2x, BL=0x%2.2x\n",
                        X86_AL, X86_BH, X86_BL);
         if (xf86GetVerbosity() > 3) {
@@ -564,10 +564,10 @@ int42_handler(xf86Int10InfoPtr pInt)
         /*           which might or might not have been       */
         /*           installed yet.                           */
     {                           /* Localise */
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x%2.2x(AH=0x13) -- Write String in Teletype Mode\n",
                        pInt->num);
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 3,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3,
                        "AL=0x%2.2x, BL=0x%2.2x, CX=0x%4.4x,"
                        " DH=0x%2.2x, DL=0x%2.2x, ES:BP=0x%4.4x:0x%4.4x\n",
                        X86_AL, X86_BL, X86_CX, X86_DH, X86_DL, X86_ES, X86_BP);
@@ -840,7 +840,7 @@ int1A_handler(xf86Int10InfoPtr pInt)
 #endif
         return 1;
     default:
-        xf86DrvMsgVerb(pInt->scrnIndex, X_NOT_IMPLEMENTED, 2,
+        xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2,
                        "int 0x1a subfunction\n");
         dump_registers(pInt);
         if (xf86GetVerbosity() > 3)
diff --git a/hw/xfree86/int10/xf86int10.h b/hw/xfree86/int10/xf86int10.h
index 36b659f..6d564fc 100644
--- a/hw/xfree86/int10/xf86int10.h
+++ b/hw/xfree86/int10/xf86int10.h
@@ -21,10 +21,10 @@
 /* int10 info structure */
 typedef struct {
     int entityIndex;
-    int scrnIndex;
-    pointer cpuRegs;
     CARD16 BIOSseg;
     CARD16 inb40time;
+    ScrnInfoPtr pScrn;
+    pointer cpuRegs;
     char *BIOSScratch;
     int Flags;
     pointer private;
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
index ab6ed5e..2c8878f 100644
--- a/hw/xfree86/modes/xf86Crtc.c
+++ b/hw/xfree86/modes/xf86Crtc.c
@@ -716,7 +716,7 @@ xf86CrtcCreateScreenResources(ScreenPtr screen)
  * Clean up config on server reset
  */
 static Bool
-xf86CrtcCloseScreen(int index, ScreenPtr screen)
+xf86CrtcCloseScreen(ScreenPtr screen)
 {
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
@@ -738,7 +738,7 @@ xf86CrtcCloseScreen(int index, ScreenPtr screen)
     }
     xf86RandR12CloseScreen(screen);
 
-    return screen->CloseScreen(index, screen);
+    return screen->CloseScreen(screen);
 }
 
 /*
@@ -3009,7 +3009,7 @@ xf86OutputGetEDID(xf86OutputPtr output, I2CBusPtr pDDCBus)
     ScrnInfoPtr scrn = output->scrn;
     xf86MonPtr mon;
 
-    mon = xf86DoEEDID(scrn->scrnIndex, pDDCBus, TRUE);
+    mon = xf86DoEEDID(scrn, pDDCBus, TRUE);
     if (mon)
         xf86DDCApplyQuirks(scrn->scrnIndex, mon);
 
diff --git a/hw/xfree86/modes/xf86DiDGA.c b/hw/xfree86/modes/xf86DiDGA.c
index fdec6cb..bb954ac 100644
--- a/hw/xfree86/modes/xf86DiDGA.c
+++ b/hw/xfree86/modes/xf86DiDGA.c
@@ -137,7 +137,7 @@ xf86_dga_get_viewport(ScrnInfoPtr scrn)
 static void
 xf86_dga_set_viewport(ScrnInfoPtr scrn, int x, int y, int flags)
 {
-    scrn->AdjustFrame(scrn->pScreen->myNum, x, y, flags);
+    scrn->AdjustFrame(scrn, x, y);
 }
 
 static Bool
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index e6b2052..59b6f82 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -515,7 +515,7 @@ xf86RandR12SetMode(ScreenPtr pScreen,
     Bool ret = TRUE;
 
     if (pRoot)
-        (*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE);
+        (*scrp->EnableDisableFBAccess) (scrp, FALSE);
     if (useVirtual) {
         scrp->virtualX = randrp->virtualX;
         scrp->virtualY = randrp->virtualY;
@@ -568,7 +568,7 @@ xf86RandR12SetMode(ScreenPtr pScreen,
     xf86SetViewport(pScreen, pScreen->width, pScreen->height);
     xf86SetViewport(pScreen, 0, 0);
     if (pRoot)
-        (*scrp->EnableDisableFBAccess) (pScreen->myNum, TRUE);
+        (*scrp->EnableDisableFBAccess) (scrp, TRUE);
     return ret;
 }
 
@@ -685,7 +685,7 @@ xf86RandR12ScreenSetSize(ScreenPtr pScreen,
         }
     }
     if (pRoot && pScrn->vtSema)
-        (*pScrn->EnableDisableFBAccess) (pScreen->myNum, FALSE);
+        (*pScrn->EnableDisableFBAccess) (pScrn, FALSE);
 
     /* Let the driver update virtualX and virtualY */
     if (!(*config->funcs->resize) (pScrn, width, height))
@@ -724,7 +724,7 @@ xf86RandR12ScreenSetSize(ScreenPtr pScreen,
     update_desktop_dimensions();
 
     if (pRoot && pScrn->vtSema)
-        (*pScrn->EnableDisableFBAccess) (pScreen->myNum, TRUE);
+        (*pScrn->EnableDisableFBAccess) (pScrn, TRUE);
 #if RANDR_12_INTERFACE
     if (xf86RandR12Key && pScreen->root && ret)
         RRScreenSizeNotify(pScreen);
@@ -1596,10 +1596,9 @@ xf86RandR12TellChanged(ScreenPtr pScreen)
 }
 
 static void
-xf86RandR12PointerMoved(int scrnIndex, int x, int y)
+xf86RandR12PointerMoved(ScrnInfoPtr pScrn, int x, int y)
 {
-    ScreenPtr pScreen = screenInfo.screens[scrnIndex];
-    ScrnInfoPtr pScrn = XF86SCRNINFO(pScreen);
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
     XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
     int c;
@@ -1688,10 +1687,9 @@ gamma_to_ramp(float gamma, CARD16 *ramp, int size)
 }
 
 static int
-xf86RandR12ChangeGamma(int scrnIndex, Gamma gamma)
+xf86RandR12ChangeGamma(ScrnInfoPtr pScrn, Gamma gamma)
 {
     CARD16 *points, *red, *green, *blue;
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
     int size;
 
@@ -1723,10 +1721,9 @@ xf86RandR12ChangeGamma(int scrnIndex, Gamma gamma)
 }
 
 static Bool
-xf86RandR12EnterVT(int screen_index, int flags)
+xf86RandR12EnterVT(ScrnInfoPtr pScrn)
 {
-    ScreenPtr pScreen = screenInfo.screens[screen_index];
-    ScrnInfoPtr pScrn = xf86Screens[screen_index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
     rrScrPrivPtr rp = rrGetScrPriv(pScreen);
     Bool ret;
@@ -1734,7 +1731,7 @@ xf86RandR12EnterVT(int screen_index, int flags)
 
     if (randrp->orig_EnterVT) {
         pScrn->EnterVT = randrp->orig_EnterVT;
-        ret = pScrn->EnterVT(screen_index, flags);
+        ret = pScrn->EnterVT(pScrn);
         randrp->orig_EnterVT = pScrn->EnterVT;
         pScrn->EnterVT = xf86RandR12EnterVT;
         if (!ret)
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 26eefc8..6a661e1 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -250,17 +250,16 @@ xf86RotateRedisplay(ScreenPtr pScreen)
 }
 
 static void
-xf86RotateBlockHandler(int screenNum, pointer blockData,
+xf86RotateBlockHandler(ScreenPtr pScreen,
                        pointer pTimeout, pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[screenNum];
-    ScrnInfoPtr pScrn = xf86Screens[screenNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
     Bool rotation_active;
 
     rotation_active = xf86RotateRedisplay(pScreen);
     pScreen->BlockHandler = xf86_config->BlockHandler;
-    (*pScreen->BlockHandler) (screenNum, blockData, pTimeout, pReadmask);
+    (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
     /* cannot avoid re-wrapping until all wrapping is audited */
     xf86_config->BlockHandler = pScreen->BlockHandler;
     pScreen->BlockHandler = xf86RotateBlockHandler;
diff --git a/hw/xfree86/os-support/linux/int10/linux.c b/hw/xfree86/os-support/linux/int10/linux.c
index fa58a72..8bca375 100644
--- a/hw/xfree86/os-support/linux/int10/linux.c
+++ b/hw/xfree86/os-support/linux/int10/linux.c
@@ -52,7 +52,6 @@ typedef struct {
     int highMem;
     char *base;
     char *base_high;
-    int screen;
     char *alloc;
 } linuxInt10Priv;
 
@@ -89,15 +88,16 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
     memType cs;
     legacyVGARec vga;
     Bool videoBiosMapped = FALSE;
-
+    ScrnInfoPtr pScrn;
     if (int10Generation != serverGeneration) {
         counter = 0;
         int10Generation = serverGeneration;
     }
 
-    screen = (xf86FindScreenForEntity(entityIndex))->scrnIndex;
+    pScrn = xf86FindScreenForEntity(entityIndex);
+    screen = pScrn->scrnIndex;
 
-    options = xf86HandleInt10Options(xf86Screens[screen], entityIndex);
+    options = xf86HandleInt10Options(pScrn, entityIndex);
 
     if (int10skip(options)) {
         free(options);
@@ -106,7 +106,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
 
 #if defined DoSubModules
     if (loadedSubModule == INT10_NOT_LOADED)
-        loadedSubModule = int10LinuxLoadSubModule(xf86Screens[screen]);
+        loadedSubModule = int10LinuxLoadSubModule(pScrn);
 
     if (loadedSubModule == INT10_LOAD_FAILED)
         return NULL;
@@ -145,7 +145,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
     }
 
     pInt = (xf86Int10InfoPtr) xnfcalloc(1, sizeof(xf86Int10InfoRec));
-    pInt->scrnIndex = screen;
+    pInt->pScrn = pScrn;
     pInt->entityIndex = entityIndex;
     pInt->dev = xf86GetPciInfoForEntity(entityIndex);
 
@@ -154,7 +154,6 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
     pInt->mem = &linuxMem;
     pagesize = getpagesize();
     pInt->private = (pointer) xnfcalloc(1, sizeof(linuxInt10Priv));
-    ((linuxInt10Priv *) pInt->private)->screen = screen;
     ((linuxInt10Priv *) pInt->private)->alloc =
         (pointer) xnfcalloc(1, ALLOC_ENTRIES(pagesize));
 
@@ -333,28 +332,28 @@ MapCurrentInt10(xf86Int10InfoPtr pInt)
     addr =
         shmat(((linuxInt10Priv *) pInt->private)->lowMem, (char *) 1, SHM_RND);
     if (addr == SHMERRORPTR) {
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot shmat() low memory\n");
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "Cannot shmat() low memory\n");
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR,
                    "shmat(low_mem) error: %s\n", strerror(errno));
         return FALSE;
     }
     if (mprotect((void *) 0, V_RAM, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR,
                    "Cannot set EXEC bit on low memory: %s\n", strerror(errno));
 
     if (((linuxInt10Priv *) pInt->private)->highMem >= 0) {
         addr = shmat(((linuxInt10Priv *) pInt->private)->highMem,
                      (char *) HIGH_MEM, 0);
         if (addr == SHMERRORPTR) {
-            xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+            xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR,
                        "Cannot shmat() high memory\n");
-            xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+            xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR,
                        "shmget error: %s\n", strerror(errno));
             return FALSE;
         }
         if (mprotect((void *) HIGH_MEM, HIGH_MEM_SIZE,
                      PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
-            xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+            xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR,
                        "Cannot set EXEC bit on high memory: %s\n",
                        strerror(errno));
     }
@@ -364,13 +363,13 @@ MapCurrentInt10(xf86Int10InfoPtr pInt)
                      PROT_READ | PROT_WRITE | PROT_EXEC,
                      MAP_SHARED | MAP_FIXED, fd, V_BIOS)
                 == MAP_FAILED) {
-                xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot map V_BIOS\n");
+                xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "Cannot map V_BIOS\n");
                 close(fd);
                 return FALSE;
             }
         }
         else {
-            xf86DrvMsg(pInt->scrnIndex, X_ERROR, "Cannot open %s\n", DEV_MEM);
+            xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "Cannot open %s\n", DEV_MEM);
             return FALSE;
         }
         close(fd);
diff --git a/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c b/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c
index 8502b21..1876983 100644
--- a/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c
+++ b/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c
@@ -210,19 +210,19 @@ vm86_GP_fault(xf86Int10InfoPtr pInt)
         return FALSE;
 
     case 0x0f:
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR,
                    "CPU 0x0f Trap at CS:EIP=0x%4.4x:0x%8.8lx\n", X86_CS,
                    X86_EIP);
         goto op0ferr;
 
     default:
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown reason for exception\n");
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "unknown reason for exception\n");
 
  op0ferr:
         dump_registers(pInt);
         stack_trace(pInt);
         dump_code(pInt);
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR, "cannot continue\n");
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "cannot continue\n");
         return FALSE;
     }                           /* end of switch() */
     return TRUE;
@@ -238,7 +238,7 @@ do_vm86(xf86Int10InfoPtr pInt)
     xf86InterceptSignals(NULL);
 
     if (signo >= 0) {
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR,
                    "vm86() syscall generated signal %d.\n", signo);
         dump_registers(pInt);
         dump_code(pInt);
@@ -252,7 +252,7 @@ do_vm86(xf86Int10InfoPtr pInt)
             return 0;
         break;
     case VM86_STI:
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR, "vm86_sti :-((\n");
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "vm86_sti :-((\n");
         dump_registers(pInt);
         dump_code(pInt);
         stack_trace(pInt);
@@ -260,7 +260,7 @@ do_vm86(xf86Int10InfoPtr pInt)
     case VM86_INTx:
         pInt->num = VM86_ARG(retval);
         if (!int_handler(pInt)) {
-            xf86DrvMsg(pInt->scrnIndex, X_ERROR,
+            xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR,
                        "Unknown vm86_int: 0x%X\n\n", VM86_ARG(retval));
             dump_registers(pInt);
             dump_code(pInt);
@@ -275,10 +275,10 @@ do_vm86(xf86Int10InfoPtr pInt)
          * we used to warn here and bail out - but now the sigio stuff
          * always fires signals at us. So we just ignore them for now.
          */
-        xf86DrvMsg(pInt->scrnIndex, X_WARNING, "received signal\n");
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_WARNING, "received signal\n");
         return 0;
     default:
-        xf86DrvMsg(pInt->scrnIndex, X_ERROR, "unknown type(0x%x)=0x%x\n",
+        xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "unknown type(0x%x)=0x%x\n",
                    VM86_ARG(retval), VM86_TYPE(retval));
         dump_registers(pInt);
         dump_code(pInt);
diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c
index 7fd70fc..15e2ada 100644
--- a/hw/xfree86/ramdac/xf86Cursor.c
+++ b/hw/xfree86/ramdac/xf86Cursor.c
@@ -43,14 +43,14 @@ static miPointerSpriteFuncRec xf86CursorSpriteFuncs = {
 static void xf86CursorInstallColormap(ColormapPtr);
 static void xf86CursorRecolorCursor(DeviceIntPtr pDev, ScreenPtr, CursorPtr,
                                     Bool);
-static Bool xf86CursorCloseScreen(int, ScreenPtr);
+static Bool xf86CursorCloseScreen(ScreenPtr);
 static void xf86CursorQueryBestSize(int, unsigned short *, unsigned short *,
                                     ScreenPtr);
 
 /* ScrnInfoRec functions */
 
-static void xf86CursorEnableDisableFBAccess(int, Bool);
-static Bool xf86CursorSwitchMode(int, DisplayModePtr, int);
+static void xf86CursorEnableDisableFBAccess(ScrnInfoPtr, Bool);
+static Bool xf86CursorSwitchMode(ScrnInfoPtr, DisplayModePtr);
 
 Bool
 xf86InitCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr)
@@ -118,7 +118,7 @@ xf86InitCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr)
 /***** Screen functions *****/
 
 static Bool
-xf86CursorCloseScreen(int i, ScreenPtr pScreen)
+xf86CursorCloseScreen(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     miPointerScreenPtr PointPriv =
@@ -149,7 +149,7 @@ xf86CursorCloseScreen(int i, ScreenPtr pScreen)
     free(ScreenPriv->transparentData);
     free(ScreenPriv);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static void
@@ -203,11 +203,11 @@ xf86CursorRecolorCursor(DeviceIntPtr pDev,
 /***** ScrnInfoRec functions *********/
 
 static void
-xf86CursorEnableDisableFBAccess(int index, Bool enable)
+xf86CursorEnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable)
 {
     DeviceIntPtr pDev = inputInfo.pointer;
 
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     xf86CursorScreenPtr ScreenPriv =
         (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
                                                xf86CursorScreenKey);
@@ -223,7 +223,7 @@ xf86CursorEnableDisableFBAccess(int index, Bool enable)
     }
 
     if (ScreenPriv->EnableDisableFBAccess)
-        (*ScreenPriv->EnableDisableFBAccess) (index, enable);
+        (*ScreenPriv->EnableDisableFBAccess) (pScrn, enable);
 
     if (enable && ScreenPriv->SavedCursor) {
         /*
@@ -237,10 +237,10 @@ xf86CursorEnableDisableFBAccess(int index, Bool enable)
 }
 
 static Bool
-xf86CursorSwitchMode(int index, DisplayModePtr mode, int flags)
+xf86CursorSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 {
     Bool ret;
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     xf86CursorScreenPtr ScreenPriv =
         (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
                                                xf86CursorScreenKey);
@@ -250,7 +250,7 @@ xf86CursorSwitchMode(int index, DisplayModePtr mode, int flags)
         ScreenPriv->isUp = FALSE;
     }
 
-    ret = (*ScreenPriv->SwitchMode) (index, mode, flags);
+    ret = (*ScreenPriv->SwitchMode) (pScrn, mode);
 
     /*
      * Cannot restore cursor here because the new frame[XY][01] haven't been
diff --git a/hw/xfree86/ramdac/xf86CursorPriv.h b/hw/xfree86/ramdac/xf86CursorPriv.h
index 062b2eb..d04f932 100644
--- a/hw/xfree86/ramdac/xf86CursorPriv.h
+++ b/hw/xfree86/ramdac/xf86CursorPriv.h
@@ -26,7 +26,7 @@ typedef struct {
     miPointerSpriteFuncPtr spriteFuncs;
     Bool PalettedCursor;
     ColormapPtr pInstalledMap;
-    Bool (*SwitchMode) (int, DisplayModePtr, int);
+    Bool (*SwitchMode) (ScrnInfoPtr, DisplayModePtr);
     xf86EnableDisableFBAccessProc *EnableDisableFBAccess;
     CursorPtr SavedCursor;
 
diff --git a/hw/xfree86/shadowfb/shadow.c b/hw/xfree86/shadowfb/shadow.c
index 5aeee6c..6145017 100644
--- a/hw/xfree86/shadowfb/shadow.c
+++ b/hw/xfree86/shadowfb/shadow.c
@@ -28,13 +28,13 @@
 
 #include "picturestr.h"
 
-static Bool ShadowCloseScreen(int i, ScreenPtr pScreen);
+static Bool ShadowCloseScreen(ScreenPtr pScreen);
 static void ShadowCopyWindow(WindowPtr pWin,
                              DDXPointRec ptOldOrg, RegionPtr prgn);
 static Bool ShadowCreateGC(GCPtr pGC);
 
-static Bool ShadowEnterVT(int index, int flags);
-static void ShadowLeaveVT(int index, int flags);
+static Bool ShadowEnterVT(ScrnInfoPtr pScrn);
+static void ShadowLeaveVT(ScrnInfoPtr pScrn);
 
 static void ShadowComposite(CARD8 op,
                             PicturePtr pSrc,
@@ -56,8 +56,8 @@ typedef struct {
     CreateGCProcPtr CreateGC;
     ModifyPixmapHeaderProcPtr ModifyPixmapHeader;
     CompositeProcPtr Composite;
-    Bool (*EnterVT) (int, int);
-    void (*LeaveVT) (int, int);
+    Bool (*EnterVT) (ScrnInfoPtr);
+    void (*LeaveVT) (ScrnInfoPtr);
     Bool vtSema;
 } ShadowScreenRec, *ShadowScreenPtr;
 
@@ -192,14 +192,13 @@ ShadowFBInit(ScreenPtr pScreen, RefreshAreaFuncPtr refreshArea)
 /**********************************************************/
 
 static Bool
-ShadowEnterVT(int index, int flags)
+ShadowEnterVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[index];
     Bool ret;
     ShadowScreenPtr pPriv = GET_SCREEN_PRIVATE(pScrn->pScreen);
 
     pScrn->EnterVT = pPriv->EnterVT;
-    ret = (*pPriv->EnterVT) (index, flags);
+    ret = (*pPriv->EnterVT) (pScrn);
     pPriv->EnterVT = pScrn->EnterVT;
     pScrn->EnterVT = ShadowEnterVT;
     if (ret) {
@@ -211,15 +210,14 @@ ShadowEnterVT(int index, int flags)
 }
 
 static void
-ShadowLeaveVT(int index, int flags)
+ShadowLeaveVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[index];
-    ShadowScreenPtr pPriv = GET_SCREEN_PRIVATE(xf86Screens[index]->pScreen);
+    ShadowScreenPtr pPriv = GET_SCREEN_PRIVATE(pScrn->pScreen);
 
     pPriv->vtSema = FALSE;
 
     pScrn->LeaveVT = pPriv->LeaveVT;
-    (*pPriv->LeaveVT) (index, flags);
+    (*pPriv->LeaveVT) (pScrn);
     pPriv->LeaveVT = pScrn->LeaveVT;
     pScrn->LeaveVT = ShadowLeaveVT;
 }
@@ -227,7 +225,7 @@ ShadowLeaveVT(int index, int flags)
 /**********************************************************/
 
 static Bool
-ShadowCloseScreen(int i, ScreenPtr pScreen)
+ShadowCloseScreen(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     ShadowScreenPtr pPriv = GET_SCREEN_PRIVATE(pScreen);
@@ -247,7 +245,7 @@ ShadowCloseScreen(int i, ScreenPtr pScreen)
 
     free((pointer) pPriv);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static void
diff --git a/hw/xfree86/vbe/vbe.c b/hw/xfree86/vbe/vbe.c
index bbb60e3..97a9bcf 100644
--- a/hw/xfree86/vbe/vbe.c
+++ b/hw/xfree86/vbe/vbe.c
@@ -179,7 +179,7 @@ static Bool
 vbeProbeDDC(vbeInfoPtr pVbe)
 {
     const char *ddc_level;
-    int screen = pVbe->pInt10->scrnIndex;
+    int screen = pVbe->pInt10->pScrn->scrnIndex;
 
     if (pVbe->ddc == DDC_NONE)
         return FALSE;
@@ -262,7 +262,8 @@ vbeReadEDID(vbeInfoPtr pVbe)
     unsigned char *tmp = NULL;
     Bool novbe = FALSE;
     Bool noddc = FALSE;
-    int screen = pVbe->pInt10->scrnIndex;
+    ScrnInfoPtr pScrn = pVbe->pInt10->pScrn;
+    int screen = pScrn->scrnIndex;
     OptionInfoPtr options;
 
     if (!page)
@@ -270,7 +271,7 @@ vbeReadEDID(vbeInfoPtr pVbe)
 
     options = xnfalloc(sizeof(VBEOptions));
     (void) memcpy(options, VBEOptions, sizeof(VBEOptions));
-    xf86ProcessOptions(screen, xf86Screens[screen]->options, options);
+    xf86ProcessOptions(screen, pScrn->options, options);
     xf86GetOptValBool(options, VBEOPT_NOVBE, &novbe);
     xf86GetOptValBool(options, VBEOPT_NODDC, &noddc);
     free(options);
@@ -330,7 +331,7 @@ vbeDoEDID(vbeInfoPtr pVbe, pointer pDDCModule)
 
     if (!(pModule = pDDCModule)) {
         pModule =
-            xf86LoadSubModule(xf86Screens[pVbe->pInt10->scrnIndex], "ddc");
+            xf86LoadSubModule(pVbe->pInt10->pScrn, "ddc");
         if (!pModule)
             return NULL;
     }
@@ -340,7 +341,7 @@ vbeDoEDID(vbeInfoPtr pVbe, pointer pDDCModule)
     if (!DDC_data)
         return NULL;
 
-    pMonitor = xf86InterpretEDID(pVbe->pInt10->scrnIndex, DDC_data);
+    pMonitor = xf86InterpretEDID(pVbe->pInt10->pScrn->scrnIndex, DDC_data);
 
     if (!pDDCModule)
         xf86UnloadSubModule(pModule);
@@ -598,7 +599,7 @@ VBESaveRestore(vbeInfoPtr pVbe, vbeSaveRestoreFunction function,
      */
 
     if ((pVbe->version & 0xff00) > 0x100) {
-        int screen = pVbe->pInt10->scrnIndex;
+        int screen = pVbe->pInt10->pScrn->scrnIndex;
 
         if (function == MODE_QUERY || (function == MODE_SAVE && !*memory)) {
             /* Query amount of memory to save state */
@@ -904,7 +905,7 @@ VBEBuildVbeModeList(vbeInfoPtr pVbe, VbeInfoBlock * vbe)
         m->n = id;
         m->next = ModeList;
 
-        xf86DrvMsgVerb(pVbe->pInt10->scrnIndex, X_PROBED, 3,
+        xf86DrvMsgVerb(pVbe->pInt10->pScrn->scrnIndex, X_PROBED, 3,
                        "BIOS reported VESA mode 0x%x: x:%i y:%i bpp:%i\n",
                        m->n, m->width, m->height, m->bpp);
 
@@ -1026,23 +1027,22 @@ VBEDPMSSet(vbeInfoPtr pVbe, int mode)
 }
 
 void
-VBEInterpretPanelID(int scrnIndex, struct vbePanelID *data)
+VBEInterpretPanelID(ScrnInfoPtr pScrn, struct vbePanelID *data)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     DisplayModePtr mode;
     const float PANEL_HZ = 60.0;
 
     if (!data)
         return;
 
-    xf86DrvMsg(scrnIndex, X_INFO, "PanelID returned panel resolution %dx%d\n",
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "PanelID returned panel resolution %dx%d\n",
                data->hsize, data->vsize);
 
     if (pScrn->monitor->nHsync || pScrn->monitor->nVrefresh)
         return;
 
     if (data->hsize < 320 || data->vsize < 240) {
-        xf86DrvMsg(scrnIndex, X_INFO, "...which I refuse to believe\n");
+        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "...which I refuse to believe\n");
         return;
     }
 
@@ -1069,7 +1069,7 @@ VBEReadPanelID(vbeInfoPtr pVbe)
     int RealOff = pVbe->real_mode_base;
     pointer page = pVbe->memory;
     void *tmp = NULL;
-    int screen = pVbe->pInt10->scrnIndex;
+    int screen = pVbe->pInt10->pScrn->scrnIndex;
 
     pVbe->pInt10->ax = 0x4F11;
     pVbe->pInt10->bx = 0x01;
diff --git a/hw/xfree86/vbe/vbe.h b/hw/xfree86/vbe/vbe.h
index 81be0ff..3907c53 100644
--- a/hw/xfree86/vbe/vbe.h
+++ b/hw/xfree86/vbe/vbe.h
@@ -350,7 +350,7 @@ struct vbePanelID {
     char reserved[14];
 };
 
-extern _X_EXPORT void VBEInterpretPanelID(int scrnIndex,
+extern _X_EXPORT void VBEInterpretPanelID(ScrnInfoPtr pScrn,
                                           struct vbePanelID *data);
 extern _X_EXPORT struct vbePanelID *VBEReadPanelID(vbeInfoPtr pVbe);
 
diff --git a/hw/xfree86/xaa/xaaInit.c b/hw/xfree86/xaa/xaaInit.c
index 48d0605..f146f3a 100644
--- a/hw/xfree86/xaa/xaaInit.c
+++ b/hw/xfree86/xaa/xaaInit.c
@@ -27,7 +27,7 @@
 
 #define MIN_OFFPIX_SIZE		(320*200)
 
-static Bool XAACloseScreen(int i, ScreenPtr pScreen);
+static Bool XAACloseScreen(ScreenPtr pScreen);
 static void XAAGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h,
                         unsigned int format, unsigned long planemask,
                         char *pdstLine);
@@ -36,10 +36,10 @@ static void XAAGetSpans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt,
 static PixmapPtr XAACreatePixmap(ScreenPtr pScreen, int w, int h, int depth,
                                  unsigned usage_hint);
 static Bool XAADestroyPixmap(PixmapPtr pPixmap);
-static Bool XAAEnterVT(int index, int flags);
-static void XAALeaveVT(int index, int flags);
-static int XAASetDGAMode(int index, int num, DGADevicePtr devRet);
-static void XAAEnableDisableFBAccess(int index, Bool enable);
+static Bool XAAEnterVT(ScrnInfoPtr pScrn);
+static void XAALeaveVT(ScrnInfoPtr pScrn);
+static int XAASetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr devRet);
+static void XAAEnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable);
 static Bool XAAChangeWindowAttributes(WindowPtr pWin, unsigned long mask);
 
 static DevPrivateKeyRec XAAScreenKeyRec;
@@ -214,7 +214,7 @@ XAAInit(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
 }
 
 static Bool
-XAACloseScreen(int i, ScreenPtr pScreen)
+XAACloseScreen(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     XAAScreenPtr pScreenPriv =
@@ -238,7 +238,7 @@ XAACloseScreen(int i, ScreenPtr pScreen)
 
     free((pointer) pScreenPriv);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static void
@@ -509,26 +509,24 @@ XAAChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
 /*  These two aren't really needed for anything */
 
 static Bool
-XAAEnterVT(int index, int flags)
+XAAEnterVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[index];
     Bool ret;
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XAAScreenPtr pScreenPriv =
         (XAAScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
 
     pScrn->EnterVT = pScreenPriv->EnterVT;
-    ret = ((*pScreenPriv->EnterVT) (index, flags));
+    ret = ((*pScreenPriv->EnterVT) (pScrn));
     pScreenPriv->EnterVT = pScrn->EnterVT;
     pScrn->EnterVT = XAAEnterVT;
     return ret;
 }
 
 static void
-XAALeaveVT(int index, int flags)
+XAALeaveVT(ScrnInfoPtr pScrn)
 {
-    ScrnInfoPtr pScrn = xf86Screens[index];
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XAAScreenPtr pScreenPriv =
         (XAAScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
     XAAInfoRecPtr infoRec = pScreenPriv->AccelInfoRec;
@@ -539,7 +537,7 @@ XAALeaveVT(int index, int flags)
     }
 
     pScrn->LeaveVT = pScreenPriv->LeaveVT;
-    (*pScreenPriv->LeaveVT) (index, flags);
+    (*pScreenPriv->LeaveVT) (pScrn);
     pScreenPriv->LeaveVT = pScrn->LeaveVT;
     pScrn->LeaveVT = XAALeaveVT;
 }
@@ -551,9 +549,9 @@ typedef struct {
 } SavedCacheState, *SavedCacheStatePtr;
 
 static int
-XAASetDGAMode(int index, int num, DGADevicePtr devRet)
+XAASetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr devRet)
 {
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
     XAAScreenPtr pScreenPriv =
         (XAAScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
@@ -569,7 +567,7 @@ XAASetDGAMode(int index, int num, DGADevicePtr devRet)
         infoRec->dgaSaves = NULL;
     }
 
-    ret = (*pScreenPriv->SetDGAMode) (index, num, devRet);
+    ret = (*pScreenPriv->SetDGAMode) (pScrn, num, devRet);
     if (ret != Success)
         return ret;
 
@@ -612,9 +610,9 @@ XAASetDGAMode(int index, int num, DGADevicePtr devRet)
 }
 
 static void
-XAAEnableDisableFBAccess(int index, Bool enable)
+XAAEnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable)
 {
-    ScreenPtr pScreen = screenInfo.screens[index];
+    ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
     XAAScreenPtr pScreenPriv =
         (XAAScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
@@ -627,7 +625,7 @@ XAAEnableDisableFBAccess(int index, Bool enable)
         SwitchedOut = TRUE;
     }
 
-    (*pScreenPriv->EnableDisableFBAccess) (index, enable);
+    (*pScreenPriv->EnableDisableFBAccess) (pScrn, enable);
 
     if (enable) {
         if ((infoRec->Flags & OFFSCREEN_PIXMAPS) && (infoRec->OffscreenPixmaps))
diff --git a/hw/xfree86/xaa/xaalocal.h b/hw/xfree86/xaa/xaalocal.h
index c028ef0..61d9eeb 100644
--- a/hw/xfree86/xaa/xaalocal.h
+++ b/hw/xfree86/xaa/xaalocal.h
@@ -47,10 +47,10 @@ typedef struct _XAAScreen {
     DestroyPixmapProcPtr DestroyPixmap;
     ChangeWindowAttributesProcPtr ChangeWindowAttributes;
     XAAInfoRecPtr AccelInfoRec;
-    Bool (*EnterVT) (int, int);
-    void (*LeaveVT) (int, int);
-    int (*SetDGAMode) (int, int, DGADevicePtr);
-    void (*EnableDisableFBAccess) (int, Bool);
+    Bool (*EnterVT) (ScrnInfoPtr);
+    void (*LeaveVT) (ScrnInfoPtr);
+    int (*SetDGAMode) (ScrnInfoPtr, int, DGADevicePtr);
+    void (*EnableDisableFBAccess) (ScrnInfoPtr, Bool);
     CompositeProcPtr Composite;
     GlyphsProcPtr Glyphs;
 } XAAScreenRec, *XAAScreenPtr;
diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c
index dd76cb8..7b3c1b3 100644
--- a/hw/xnest/Screen.c
+++ b/hw/xnest/Screen.c
@@ -129,7 +129,7 @@ static miPointerSpriteFuncRec xnestPointerSpriteFuncs = {
 };
 
 Bool
-xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
+xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
 {
     VisualPtr visuals;
     DepthPtr depths;
@@ -309,8 +309,6 @@ xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
 
     pScreen->BlockHandler = (ScreenBlockHandlerProcPtr) NoopDDA;
     pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr) NoopDDA;
-    pScreen->blockData = NULL;
-    pScreen->wakeupData = NULL;
 
     miDCInitialize(pScreen, &xnestPointerCursorFuncs);  /* init SW rendering */
     PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
@@ -409,7 +407,7 @@ xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
 }
 
 Bool
-xnestCloseScreen(int index, ScreenPtr pScreen)
+xnestCloseScreen(ScreenPtr pScreen)
 {
     int i;
 
diff --git a/hw/xnest/Screen.h b/hw/xnest/Screen.h
index 1d255d7..17c514a 100644
--- a/hw/xnest/Screen.h
+++ b/hw/xnest/Screen.h
@@ -19,7 +19,7 @@ extern Window xnestDefaultWindows[MAXSCREENS];
 extern Window xnestScreenSaverWindows[MAXSCREENS];
 
 ScreenPtr xnestScreen(Window window);
-Bool xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[]);
-Bool xnestCloseScreen(int index, ScreenPtr pScreen);
+Bool xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[]);
+Bool xnestCloseScreen(ScreenPtr pScreen);
 
 #endif                          /* XNESTSCREEN_H */
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 41db72a..d26f18a 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -193,7 +193,7 @@ DarwinSaveScreen(ScreenPtr pScreen, int on)
  *  Initialize the screen and communicate information about it back to dix.
  */
 static Bool
-DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
+DarwinScreenInit(ScreenPtr pScreen, int argc, char **argv)
 {
     int dpi;
     static int foundIndex = 0;
@@ -204,7 +204,7 @@ DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
         return FALSE;
 
     // reset index of found screens for each server generation
-    if (index == 0) {
+    if (pScreen->myNum == 0) {
         foundIndex = 0;
 
         // reset the visual list
@@ -275,7 +275,7 @@ DarwinScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     pScreen->SaveScreen = DarwinSaveScreen;
 
     // finish mode dependent screen setup including cursor support
-    if (!QuartzSetupScreen(index, pScreen)) {
+    if (!QuartzSetupScreen(pScreen->myNum, pScreen)) {
         return FALSE;
     }
 
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index ce90d05..878419d 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -275,7 +275,7 @@ typedef void (*winShadowUpdateProcPtr) (ScreenPtr, shadowBufPtr);
 
 typedef Bool (*winInitScreenProcPtr) (ScreenPtr);
 
-typedef Bool (*winCloseScreenProcPtr) (int, ScreenPtr);
+typedef Bool (*winCloseScreenProcPtr) (ScreenPtr);
 
 typedef Bool (*winInitVisualsProcPtr) (ScreenPtr);
 
@@ -779,7 +779,7 @@ void winSetAuthorization(void);
 
 void
 
-winBlockHandler(int nScreen,
+winBlockHandler(ScreenPtr pScreen,
                 pointer pBlockData, pointer pTimeout, pointer pReadMask);
 
 #ifdef XWIN_NATIVEGDI
@@ -1070,7 +1070,7 @@ winPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable,
  */
 
 Bool
- winScreenInit(int index, ScreenPtr pScreen, int argc, char **argv);
+ winScreenInit(ScreenPtr pScreen, int argc, char **argv);
 
 Bool
  winFinishScreenInitFB(int index, ScreenPtr pScreen, int argc, char **argv);
@@ -1122,7 +1122,7 @@ Bool
 
 void
 
-winWakeupHandler(int nScreen,
+winWakeupHandler(ScreenPtr pScreen,
                  pointer pWakeupData,
                  unsigned long ulResult, pointer pReadmask);
 
diff --git a/hw/xwin/winblock.c b/hw/xwin/winblock.c
index c18d080..5faa113 100644
--- a/hw/xwin/winblock.c
+++ b/hw/xwin/winblock.c
@@ -36,7 +36,7 @@
 
 /* See Porting Layer Definition - p. 6 */
 void
-winBlockHandler(int nScreen,
+winBlockHandler(ScreenPtr pScreen,
                 pointer pBlockData, pointer pTimeout, pointer pReadMask)
 {
 #if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
diff --git a/hw/xwin/winnativegdi.c b/hw/xwin/winnativegdi.c
index 8a1455b..a2a5123 100644
--- a/hw/xwin/winnativegdi.c
+++ b/hw/xwin/winnativegdi.c
@@ -44,7 +44,7 @@ static void
  winShadowUpdateNativeGDI(ScreenPtr pScreen, shadowBufPtr pBuf);
 
 static Bool
- winCloseScreenNativeGDI(int nIndex, ScreenPtr pScreen);
+ winCloseScreenNativeGDI(ScreenPtr pScreen);
 
 static Bool
  winInitVisualsNativeGDI(ScreenPtr pScreen);
@@ -104,7 +104,7 @@ winInitScreenNativeGDI(ScreenPtr pScreen)
  */
 
 static Bool
-winCloseScreenNativeGDI(int nIndex, ScreenPtr pScreen)
+winCloseScreenNativeGDI(ScreenPtr pScreen)
 {
     winScreenPriv(pScreen);
     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
diff --git a/hw/xwin/winpfbdd.c b/hw/xwin/winpfbdd.c
index 3fddd85..0fd0efe 100644
--- a/hw/xwin/winpfbdd.c
+++ b/hw/xwin/winpfbdd.c
@@ -44,7 +44,7 @@ static Bool
  winAllocateFBPrimaryDD(ScreenPtr pScreen);
 
 static Bool
- winCloseScreenPrimaryDD(int nIndex, ScreenPtr pScreen);
+ winCloseScreenPrimaryDD(ScreenPtr pScreen);
 
 static Bool
  winInitVisualsPrimaryDD(ScreenPtr pScreen);
@@ -264,7 +264,7 @@ winInitScreenPrimaryDD(ScreenPtr pScreen)
  */
 
 static Bool
-winCloseScreenPrimaryDD(int nIndex, ScreenPtr pScreen)
+winCloseScreenPrimaryDD(ScreenPtr pScreen)
 {
     winScreenPriv(pScreen);
     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
@@ -279,7 +279,7 @@ winCloseScreenPrimaryDD(int nIndex, ScreenPtr pScreen)
     /* Call the wrapped CloseScreen procedure */
     WIN_UNWRAP(CloseScreen);
     if (pScreen->CloseScreen)
-        fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+        fReturn = (*pScreen->CloseScreen) (pScreen);
 
     /* Delete the window property */
     RemoveProp(pScreenPriv->hwndScreen, WIN_SCR_PROP);
diff --git a/hw/xwin/winscrinit.c b/hw/xwin/winscrinit.c
index cf7d2c0..5f112f9 100644
--- a/hw/xwin/winscrinit.c
+++ b/hw/xwin/winscrinit.c
@@ -81,9 +81,9 @@ static Bool
  */
 
 Bool
-winScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
+winScreenInit(ScreenPtr pScreen, int argc, char **argv)
 {
-    winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index];
+    winScreenInfoPtr pScreenInfo = &g_ScreenInfo[pScreen->myNum];
     winPrivScreenPtr pScreenPriv;
     HDC hdc;
     DWORD dwInitialBPP;
@@ -202,11 +202,11 @@ winScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     miClearVisualTypes();
 
     /* Call the engine dependent screen initialization procedure */
-    if (!((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv))) {
+    if (!((*pScreenPriv->pwinFinishScreenInit) (pScreen->myNum, pScreen, argc, argv))) {
         ErrorF("winScreenInit - winFinishScreenInit () failed\n");
 
         /* call the engine dependent screen close procedure to clean up from a failure */
-        pScreenPriv->pwinCloseScreen(index, pScreen);
+        pScreenPriv->pwinCloseScreen(pScreen);
 
         return FALSE;
     }
@@ -224,7 +224,7 @@ winScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
     pScreen->y = pScreenInfo->dwInitialY - GetSystemMetrics(SM_YVIRTUALSCREEN);
 
     ErrorF("Screen %d added at virtual desktop coordinate (%d,%d).\n",
-           index, pScreen->x, pScreen->y);
+           pScreen->myNum, pScreen->x, pScreen->y);
 
 #if CYGDEBUG || YES
     winDebug("winScreenInit - returning\n");
@@ -355,8 +355,6 @@ winFinishScreenInitFB(int index, ScreenPtr pScreen, int argc, char **argv)
      */
     pScreen->BlockHandler = winBlockHandler;
     pScreen->WakeupHandler = winWakeupHandler;
-    pScreen->blockData = pScreen;
-    pScreen->wakeupData = pScreen;
 
     /* Render extension initialization, calls miPictureInit */
     if (!fbPictureInit(pScreen, NULL, 0)) {
@@ -636,8 +634,6 @@ winFinishScreenInitNativeGDI(int index,
      */
     pScreen->BlockHandler = winBlockHandler;
     pScreen->WakeupHandler = winWakeupHandler;
-    pScreen->blockData = pScreen;
-    pScreen->wakeupData = pScreen;
 
     /* Place our save screen function */
     pScreen->SaveScreen = winSaveScreen;
diff --git a/hw/xwin/winshaddd.c b/hw/xwin/winshaddd.c
index a2aaa39..4c77cc0 100644
--- a/hw/xwin/winshaddd.c
+++ b/hw/xwin/winshaddd.c
@@ -65,7 +65,7 @@ static void
  winShadowUpdateDD(ScreenPtr pScreen, shadowBufPtr pBuf);
 
 static Bool
- winCloseScreenShadowDD(int nIndex, ScreenPtr pScreen);
+ winCloseScreenShadowDD(ScreenPtr pScreen);
 
 static Bool
  winInitVisualsShadowDD(ScreenPtr pScreen);
@@ -648,7 +648,7 @@ winInitScreenShadowDD(ScreenPtr pScreen)
  */
 
 static Bool
-winCloseScreenShadowDD(int nIndex, ScreenPtr pScreen)
+winCloseScreenShadowDD(ScreenPtr pScreen)
 {
     winScreenPriv(pScreen);
     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
@@ -665,7 +665,7 @@ winCloseScreenShadowDD(int nIndex, ScreenPtr pScreen)
     /* Call the wrapped CloseScreen procedure */
     WIN_UNWRAP(CloseScreen);
     if (pScreen->CloseScreen)
-        fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+        fReturn = (*pScreen->CloseScreen) (pScreen);
 
     winFreeFBShadowDD(pScreen);
 
diff --git a/hw/xwin/winshadddnl.c b/hw/xwin/winshadddnl.c
index 6e71dd2..c087975 100644
--- a/hw/xwin/winshadddnl.c
+++ b/hw/xwin/winshadddnl.c
@@ -67,7 +67,7 @@ static void
  winShadowUpdateDDNL(ScreenPtr pScreen, shadowBufPtr pBuf);
 
 static Bool
- winCloseScreenShadowDDNL(int nIndex, ScreenPtr pScreen);
+ winCloseScreenShadowDDNL(ScreenPtr pScreen);
 
 static Bool
  winInitVisualsShadowDDNL(ScreenPtr pScreen);
@@ -719,7 +719,7 @@ winInitScreenShadowDDNL(ScreenPtr pScreen)
  */
 
 static Bool
-winCloseScreenShadowDDNL(int nIndex, ScreenPtr pScreen)
+winCloseScreenShadowDDNL(ScreenPtr pScreen)
 {
     winScreenPriv(pScreen);
     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
@@ -736,7 +736,7 @@ winCloseScreenShadowDDNL(int nIndex, ScreenPtr pScreen)
     /* Call the wrapped CloseScreen procedure */
     WIN_UNWRAP(CloseScreen);
     if (pScreen->CloseScreen)
-        fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+        fReturn = (*pScreen->CloseScreen) (pScreen);
 
     winFreeFBShadowDDNL(pScreen);
 
diff --git a/hw/xwin/winshadgdi.c b/hw/xwin/winshadgdi.c
index 3b7b8b5..cdbb46b 100644
--- a/hw/xwin/winshadgdi.c
+++ b/hw/xwin/winshadgdi.c
@@ -50,7 +50,7 @@ static void
  winShadowUpdateGDI(ScreenPtr pScreen, shadowBufPtr pBuf);
 
 static Bool
- winCloseScreenShadowGDI(int nIndex, ScreenPtr pScreen);
+ winCloseScreenShadowGDI(ScreenPtr pScreen);
 
 static Bool
  winInitVisualsShadowGDI(ScreenPtr pScreen);
@@ -579,7 +579,7 @@ winInitScreenShadowGDI(ScreenPtr pScreen)
  */
 
 static Bool
-winCloseScreenShadowGDI(int nIndex, ScreenPtr pScreen)
+winCloseScreenShadowGDI(ScreenPtr pScreen)
 {
     winScreenPriv(pScreen);
     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
@@ -596,7 +596,7 @@ winCloseScreenShadowGDI(int nIndex, ScreenPtr pScreen)
     /* Call the wrapped CloseScreen procedure */
     WIN_UNWRAP(CloseScreen);
     if (pScreen->CloseScreen)
-        fReturn = (*pScreen->CloseScreen) (nIndex, pScreen);
+        fReturn = (*pScreen->CloseScreen) (pScreen);
 
     /* Delete the window property */
     RemoveProp(pScreenPriv->hwndScreen, WIN_SCR_PROP);
diff --git a/hw/xwin/winwakeup.c b/hw/xwin/winwakeup.c
index 1d2bfed..8c9140b 100644
--- a/hw/xwin/winwakeup.c
+++ b/hw/xwin/winwakeup.c
@@ -38,7 +38,7 @@
 
 /* See Porting Layer Definition - p. 7 */
 void
-winWakeupHandler(int nScreen,
+winWakeupHandler(ScreenPtr pScreen,
                  pointer pWakeupData, unsigned long ulResult, pointer pReadmask)
 {
     MSG msg;
diff --git a/include/pixmap.h b/include/pixmap.h
index 26d737c..9bb5bb7 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -100,9 +100,9 @@ extern _X_EXPORT PixmapPtr GetScratchPixmapHeader(ScreenPtr /*pScreen */ ,
 
 extern _X_EXPORT void FreeScratchPixmapHeader(PixmapPtr /*pPixmap */ );
 
-extern _X_EXPORT Bool CreateScratchPixmapsForScreen(int /*scrnum */ );
+extern _X_EXPORT Bool CreateScratchPixmapsForScreen(ScreenPtr /*pScreen */ );
 
-extern _X_EXPORT void FreeScratchPixmapsForScreen(int /*scrnum */ );
+extern _X_EXPORT void FreeScratchPixmapsForScreen(ScreenPtr /*pScreen */ );
 
 extern _X_EXPORT PixmapPtr AllocatePixmap(ScreenPtr /*pScreen */ ,
                                           int /*pixDataSize */ );
diff --git a/include/screenint.h b/include/screenint.h
index 8817471..6b0cc70 100644
--- a/include/screenint.h
+++ b/include/screenint.h
@@ -55,7 +55,6 @@ typedef struct _Depth *DepthPtr;
 typedef struct _Screen *ScreenPtr;
 
 extern _X_EXPORT int AddScreen(Bool (* /*pfnInit */ )(
-                                                         int /*index */ ,
                                                          ScreenPtr /*pScreen */
                                                          ,
                                                          int /*argc */ ,
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 0ae9377..c592d1f 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -95,8 +95,7 @@ typedef struct _ScreenSaverStuff {
  *  or as a local variable) can easily do so and retain full type checking.
  */
 
-typedef Bool (*CloseScreenProcPtr) (int /*index */ ,
-                                    ScreenPtr /*pScreen */ );
+typedef Bool (*CloseScreenProcPtr) (ScreenPtr /*pScreen */ );
 
 typedef void (*QueryBestSizeProcPtr) (int /*class */ ,
                                       unsigned short * /*pwidth */ ,
@@ -258,13 +257,11 @@ typedef void (*SendGraphicsExposeProcPtr) (ClientPtr /*client */ ,
                                            int /*major */ ,
                                            int /*minor */ );
 
-typedef void (*ScreenBlockHandlerProcPtr) (int /*screenNum */ ,
-                                           pointer /*blockData */ ,
+typedef void (*ScreenBlockHandlerProcPtr) (ScreenPtr /*pScreen*/ ,
                                            pointer /*pTimeout */ ,
                                            pointer /*pReadmask */ );
 
-typedef void (*ScreenWakeupHandlerProcPtr) (int /*screenNum */ ,
-                                            pointer /*wakeupData */ ,
+typedef void (*ScreenWakeupHandlerProcPtr) (ScreenPtr /*pScreen*/ ,
                                             unsigned long /*result */ ,
                                             pointer /*pReadMask */ );
 
@@ -440,9 +437,6 @@ typedef struct _Screen {
     ScreenBlockHandlerProcPtr BlockHandler;
     ScreenWakeupHandlerProcPtr WakeupHandler;
 
-    pointer blockData;
-    pointer wakeupData;
-
     /* anybody can get a piece of this array */
     PrivateRec *devPrivates;
 
diff --git a/mi/midispcur.c b/mi/midispcur.c
index 24b9a70..9ee8242 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -63,7 +63,7 @@ static DevScreenPrivateKeyRec miDCDeviceKeyRec;
 
 #define miDCDeviceKey (&miDCDeviceKeyRec)
 
-static Bool miDCCloseScreen(int index, ScreenPtr pScreen);
+static Bool miDCCloseScreen(ScreenPtr pScreen);
 
 /* per device private data */
 typedef struct {
@@ -128,7 +128,7 @@ miDCInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
 }
 
 static Bool
-miDCCloseScreen(int index, ScreenPtr pScreen)
+miDCCloseScreen(ScreenPtr pScreen)
 {
     miDCScreenPtr pScreenPriv;
 
@@ -136,7 +136,7 @@ miDCCloseScreen(int index, ScreenPtr pScreen)
                                                    miDCScreenKey);
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     free((pointer) pScreenPriv);
-    return (*pScreen->CloseScreen) (index, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 Bool
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index f72159e..2bfd5e4 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -66,7 +66,7 @@ static Bool HasUnderlayChildren(WindowPtr);
 static void MarkUnderlayWindow(WindowPtr);
 static Bool CollectUnderlayChildrenRegions(WindowPtr, RegionPtr);
 
-static Bool miOverlayCloseScreen(int, ScreenPtr);
+static Bool miOverlayCloseScreen(ScreenPtr);
 static Bool miOverlayCreateWindow(WindowPtr);
 static Bool miOverlayDestroyWindow(WindowPtr);
 static Bool miOverlayUnrealizeWindow(WindowPtr);
@@ -160,7 +160,7 @@ miInitOverlay(ScreenPtr pScreen,
 }
 
 static Bool
-miOverlayCloseScreen(int i, ScreenPtr pScreen)
+miOverlayCloseScreen(ScreenPtr pScreen)
 {
     miOverlayScreenPtr pScreenPriv = MIOVERLAY_GET_SCREEN_PRIVATE(pScreen);
 
@@ -172,7 +172,7 @@ miOverlayCloseScreen(int i, ScreenPtr pScreen)
 
     free(pScreenPriv);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static Bool
diff --git a/mi/mipointer.c b/mi/mipointer.c
index de6698a..a56838e 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -91,7 +91,7 @@ static void miPointerCursorLimits(DeviceIntPtr pDev, ScreenPtr pScreen,
                                   BoxPtr pTopLeftBox);
 static Bool miPointerSetCursorPosition(DeviceIntPtr pDev, ScreenPtr pScreen,
                                        int x, int y, Bool generateEvent);
-static Bool miPointerCloseScreen(int index, ScreenPtr pScreen);
+static Bool miPointerCloseScreen(ScreenPtr pScreen);
 static void miPointerMove(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y);
 static Bool miPointerDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen);
 static void miPointerDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen);
@@ -154,7 +154,7 @@ miPointerInitialize(ScreenPtr pScreen,
  * @param pScreen The actual screen pointer
  */
 static Bool
-miPointerCloseScreen(int index, ScreenPtr pScreen)
+miPointerCloseScreen(ScreenPtr pScreen)
 {
     SetupScreen(pScreen);
 
@@ -162,7 +162,7 @@ miPointerCloseScreen(int index, ScreenPtr pScreen)
     free((pointer) pScreenPriv);
     FreeEventList(events, GetMaximumEventsNum());
     events = NULL;
-    return (*pScreen->CloseScreen) (index, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 /*
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index 2850c8d..4698b53 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -119,7 +119,7 @@ miModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth,
 }
 
 static Bool
-miCloseScreen(int iScreen, ScreenPtr pScreen)
+miCloseScreen(ScreenPtr pScreen)
 {
     return ((*pScreen->DestroyPixmap) ((PixmapPtr) pScreen->devPrivate));
 }
@@ -262,8 +262,6 @@ miScreenInit(ScreenPtr pScreen, pointer pbits,  /* pointer to screen bits */
     pScreen->SendGraphicsExpose = miSendGraphicsExpose;
     pScreen->BlockHandler = (ScreenBlockHandlerProcPtr) NoopDDA;
     pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr) NoopDDA;
-    pScreen->blockData = (pointer) 0;
-    pScreen->wakeupData = (pointer) 0;
     pScreen->MarkWindow = miMarkWindow;
     pScreen->MarkOverlappedWindows = miMarkOverlappedWindows;
     pScreen->MoveWindow = miMoveWindow;
diff --git a/mi/misprite.c b/mi/misprite.c
index c9fcabc..97bbf8e 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -191,7 +191,7 @@ static DevPrivateKeyRec miSpriteDevPrivatesKeyRec;
 
 #define miSpriteDevPrivatesKey (&miSpriteDevPrivatesKeyRec)
 
-static Bool miSpriteCloseScreen(int i, ScreenPtr pScreen);
+static Bool miSpriteCloseScreen(ScreenPtr pScreen);
 static void miSpriteGetImage(DrawablePtr pDrawable, int sx, int sy,
                              int w, int h, unsigned int format,
                              unsigned long planemask, char *pdstLine);
@@ -203,7 +203,7 @@ static void miSpriteSourceValidate(DrawablePtr pDrawable, int x, int y,
                                    unsigned int subWindowMode);
 static void miSpriteCopyWindow(WindowPtr pWindow,
                                DDXPointRec ptOldOrg, RegionPtr prgnSrc);
-static void miSpriteBlockHandler(int i, pointer blockData,
+static void miSpriteBlockHandler(ScreenPtr pScreen,
                                  pointer pTimeout, pointer pReadMask);
 static void miSpriteInstallColormap(ColormapPtr pMap);
 static void miSpriteStoreColors(ColormapPtr pMap, int ndef, xColorItem * pdef);
@@ -367,7 +367,7 @@ miSpriteInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
  */
 
 static Bool
-miSpriteCloseScreen(int i, ScreenPtr pScreen)
+miSpriteCloseScreen(ScreenPtr pScreen)
 {
     miSpriteScreenPtr pScreenPriv = GetSpriteScreen(pScreen);
 
@@ -382,7 +382,7 @@ miSpriteCloseScreen(int i, ScreenPtr pScreen)
 
     free(pScreenPriv);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static void
@@ -520,10 +520,9 @@ miSpriteCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 }
 
 static void
-miSpriteBlockHandler(int i, pointer blockData, pointer pTimeout,
+miSpriteBlockHandler(ScreenPtr pScreen, pointer pTimeout,
                      pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[i];
     miSpriteScreenPtr pPriv = GetSpriteScreen(pScreen);
     DeviceIntPtr pDev;
     miCursorInfoPtr pCursorInfo;
@@ -554,7 +553,7 @@ miSpriteBlockHandler(int i, pointer blockData, pointer pTimeout,
 
     SCREEN_PROLOGUE(pPriv, pScreen, BlockHandler);
 
-    (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
+    (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
 
     if (WorkToDo)
         SCREEN_EPILOGUE(pPriv, pScreen, BlockHandler);
diff --git a/miext/cw/cw.c b/miext/cw/cw.c
index 87ced2f..7543aff 100644
--- a/miext/cw/cw.c
+++ b/miext/cw/cw.c
@@ -51,7 +51,7 @@ DevPrivateKeyRec cwPictureKeyRec;
 extern GCOps cwGCOps;
 
 static Bool
- cwCloseScreen(int i, ScreenPtr pScreen);
+ cwCloseScreen(ScreenPtr pScreen);
 
 static void
  cwValidateGC(GCPtr pGC, unsigned long stateChanges, DrawablePtr pDrawable);
@@ -502,7 +502,7 @@ miInitializeCompositeWrapper(ScreenPtr pScreen)
 }
 
 static Bool
-cwCloseScreen(int i, ScreenPtr pScreen)
+cwCloseScreen(ScreenPtr pScreen)
 {
     cwScreenPtr pScreenPriv;
     PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
@@ -520,5 +520,5 @@ cwCloseScreen(int i, ScreenPtr pScreen)
 
     free((pointer) pScreenPriv);
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index 72ed659..85b54fc 100644
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -1646,7 +1646,7 @@ damageDestroyWindow(WindowPtr pWindow)
 }
 
 static Bool
-damageCloseScreen(int i, ScreenPtr pScreen)
+damageCloseScreen(ScreenPtr pScreen)
 {
     damageScrPriv(pScreen);
 
@@ -1655,7 +1655,7 @@ damageCloseScreen(int i, ScreenPtr pScreen)
     unwrap(pScrPriv, pScreen, CopyWindow);
     unwrap(pScrPriv, pScreen, CloseScreen);
     free(pScrPriv);
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 /**
diff --git a/miext/rootless/rootlessScreen.c b/miext/rootless/rootlessScreen.c
index ecc72ea..a1af3e7 100644
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@ -138,7 +138,7 @@ RootlessCreateScreenResources(ScreenPtr pScreen)
 }
 
 static Bool
-RootlessCloseScreen(int i, ScreenPtr pScreen)
+RootlessCloseScreen(ScreenPtr pScreen)
 {
     RootlessScreenRec *s;
 
@@ -154,7 +154,7 @@ RootlessCloseScreen(int i, ScreenPtr pScreen)
     }
 
     free(s);
-    return pScreen->CloseScreen(i, pScreen);
+    return pScreen->CloseScreen(pScreen);
 }
 
 static void
diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index d2ba684..2d869e5 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -96,7 +96,7 @@ shadowGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h,
 #define BACKWARDS_COMPATIBILITY
 
 static Bool
-shadowCloseScreen(int i, ScreenPtr pScreen)
+shadowCloseScreen(ScreenPtr pScreen)
 {
     shadowBuf(pScreen);
 
@@ -110,7 +110,7 @@ shadowCloseScreen(int i, ScreenPtr pScreen)
     if (pBuf->pPixmap)
         pScreen->DestroyPixmap(pBuf->pPixmap);
     free(pBuf);
-    return pScreen->CloseScreen(i, pScreen);
+    return pScreen->CloseScreen(pScreen);
 }
 
 #ifdef BACKWARDS_COMPATIBILITY
diff --git a/miext/sync/misync.c b/miext/sync/misync.c
index b1e2a36..d24921a 100644
--- a/miext/sync/misync.c
+++ b/miext/sync/misync.c
@@ -163,13 +163,13 @@ miSyncGetScreenFuncs(ScreenPtr pScreen)
 }
 
 static Bool
-SyncCloseScreen(int i, ScreenPtr pScreen)
+SyncCloseScreen(ScreenPtr pScreen)
 {
     SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen);
 
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
 
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 Bool
diff --git a/randr/randr.c b/randr/randr.c
index 9f3df5f..a64aae3 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -83,7 +83,7 @@ RRClientCallback(CallbackListPtr *list, pointer closure, pointer data)
 }
 
 static Bool
-RRCloseScreen(int i, ScreenPtr pScreen)
+RRCloseScreen(ScreenPtr pScreen)
 {
     rrScrPriv(pScreen);
     int j;
@@ -98,7 +98,7 @@ RRCloseScreen(int i, ScreenPtr pScreen)
     free(pScrPriv->outputs);
     free(pScrPriv);
     RRNScreens -= 1;            /* ok, one fewer screen with RandR running */
-    return (*pScreen->CloseScreen) (i, pScreen);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static void
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 1c0e9d4..38fb107 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -198,7 +198,7 @@ typedef Bool (*RRSetPanningProcPtr) (ScreenPtr pScrn,
 #endif                          /* RANDR_13_INTERFACE */
 
 typedef Bool (*RRGetInfoProcPtr) (ScreenPtr pScreen, Rotation * rotations);
-typedef Bool (*RRCloseScreenProcPtr) (int i, ScreenPtr pscreen);
+typedef Bool (*RRCloseScreenProcPtr) (ScreenPtr pscreen);
 
 /* These are for 1.0 compatibility */
 
diff --git a/render/animcur.c b/render/animcur.c
index 485c068..ebc5b8e 100644
--- a/render/animcur.c
+++ b/render/animcur.c
@@ -89,7 +89,7 @@ static DevPrivateKeyRec AnimCurScreenPrivateKeyRec;
 #define Unwrap(as,s,elt)    ((s)->elt = (as)->elt)
 
 static Bool
-AnimCurCloseScreen(int index, ScreenPtr pScreen)
+AnimCurCloseScreen(ScreenPtr pScreen)
 {
     AnimCurScreenPtr as = GetAnimCurScreen(pScreen);
     Bool ret;
@@ -103,7 +103,7 @@ AnimCurCloseScreen(int index, ScreenPtr pScreen)
     Unwrap(as, pScreen, UnrealizeCursor);
     Unwrap(as, pScreen, RecolorCursor);
     SetAnimCurScreen(pScreen, 0);
-    ret = (*pScreen->CloseScreen) (index, pScreen);
+    ret = (*pScreen->CloseScreen) (pScreen);
     free(as);
     return ret;
 }
@@ -135,11 +135,9 @@ AnimCurCursorLimits(DeviceIntPtr pDev,
  */
 
 static void
-AnimCurScreenBlockHandler(int screenNum,
-                          pointer blockData,
+AnimCurScreenBlockHandler(ScreenPtr pScreen,
                           pointer pTimeout, pointer pReadmask)
 {
-    ScreenPtr pScreen = screenInfo.screens[screenNum];
     AnimCurScreenPtr as = GetAnimCurScreen(pScreen);
     DeviceIntPtr dev;
     Bool activeDevice = FALSE;
@@ -183,7 +181,7 @@ AnimCurScreenBlockHandler(int screenNum,
         AdjustWaitForDelay(pTimeout, soonest - now);
 
     Unwrap(as, pScreen, BlockHandler);
-    (*pScreen->BlockHandler) (screenNum, blockData, pTimeout, pReadmask);
+    (*pScreen->BlockHandler) (pScreen, pTimeout, pReadmask);
     if (activeDevice)
         Wrap(as, pScreen, BlockHandler, AnimCurScreenBlockHandler);
     else
diff --git a/render/picture.c b/render/picture.c
index da3e499..7887853 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -72,14 +72,14 @@ PictureDestroyWindow(WindowPtr pWindow)
 }
 
 Bool
-PictureCloseScreen(int index, ScreenPtr pScreen)
+PictureCloseScreen(ScreenPtr pScreen)
 {
     PictureScreenPtr ps = GetPictureScreen(pScreen);
     Bool ret;
     int n;
 
     pScreen->CloseScreen = ps->CloseScreen;
-    ret = (*pScreen->CloseScreen) (index, pScreen);
+    ret = (*pScreen->CloseScreen) (pScreen);
     PictureResetFilters(pScreen);
     for (n = 0; n < ps->nformats; n++)
         if (ps->formats[n].type == PictTypeIndexed)
diff --git a/render/picturestr.h b/render/picturestr.h
index cd4ec49..6da5656 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -381,7 +381,7 @@ extern _X_EXPORT Bool
  PictureDestroyWindow(WindowPtr pWindow);
 
 extern _X_EXPORT Bool
- PictureCloseScreen(int Index, ScreenPtr pScreen);
+ PictureCloseScreen(ScreenPtr pScreen);
 
 extern _X_EXPORT void
  PictureStoreColors(ColormapPtr pColormap, int ndef, xColorItem * pdef);
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 602b906..467529a 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -190,7 +190,7 @@ CursorDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
 }
 
 static Bool
-CursorCloseScreen(int index, ScreenPtr pScreen)
+CursorCloseScreen(ScreenPtr pScreen)
 {
     CursorScreenPtr cs = GetCursorScreen(pScreen);
     Bool ret;
@@ -202,7 +202,7 @@ CursorCloseScreen(int index, ScreenPtr pScreen)
     Unwrap(cs, pScreen, DisplayCursor, display_proc);
     Unwrap(cs, pScreen, ConstrainCursorHarder, constrain_proc);
     deleteCursorHideCountsForScreen(pScreen);
-    ret = (*pScreen->CloseScreen) (index, pScreen);
+    ret = (*pScreen->CloseScreen) (pScreen);
     free(cs);
     return ret;
 }
commit 12f9aaff38ac2cf528387ce610e41fbd448698e2
Author: Chase Douglas <chase.douglas at canonical.com>
Date:   Fri Apr 6 12:44:07 2012 -0700

    test/touch: Initialize device name
    
    Without this change, the test will segfault when we switch to signal-
    safe logging.
    
    Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/test/touch.c b/test/touch.c
index 2ec535b..df1db11 100644
--- a/test/touch.c
+++ b/test/touch.c
@@ -40,6 +40,7 @@ touch_grow_queue(void)
     int i;
 
     memset(&dev, 0, sizeof(dev));
+    dev.name = "test device";
     dev.id = 2;
     dev.valuator = &val;
     val.numAxes = 5;
@@ -94,6 +95,7 @@ touch_find_ddxid(void)
     int i;
 
     memset(&dev, 0, sizeof(dev));
+    dev.name = "test device";
     dev.id = 2;
     dev.valuator = &val;
     val.numAxes = 5;
@@ -162,6 +164,7 @@ touch_begin_ddxtouch(void)
     int size = 5;
 
     memset(&dev, 0, sizeof(dev));
+    dev.name = "test device";
     dev.id = 2;
     dev.valuator = &val;
     val.numAxes = 5;
@@ -209,6 +212,7 @@ touch_begin_touch(void)
     screenInfo.screens[0] = &screen;
 
     memset(&dev, 0, sizeof(dev));
+    dev.name = "test device";
     dev.id = 2;
 
     memset(&sprite, 0, sizeof(sprite));
@@ -247,6 +251,7 @@ touch_init(void)
     screenInfo.screens[0] = &screen;
 
     memset(&dev, 0, sizeof(dev));
+    dev.name = "test device";
 
     memset(&sprite, 0, sizeof(sprite));
     dev.spriteInfo = &sprite;
commit 3476eb38063473a7a5fcd78e2095e284118de839
Merge: 78f0d9c 42ae2e8
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Jun 3 20:24:24 2012 -0700

    Merge remote-tracking branch 'whot/for-keith'

commit 42ae2e8199fe875319978249963de7499607988b
Author: Siddhesh Poyarekar <siddhesh.poyarekar at gmail.com>
Date:   Tue May 29 10:17:50 2012 +0530

    xkb: Allocate size_syms correctly when width of a type increases
    
    The current code seems to skip syms with width less than
    type->num_levels when calculating the total size for the new
    size_syms. This leads to less space being allocated than necessary
    during the next phase, which is to copy over the syms to the new
    location. This results in an overflow leading to a crash.
    
    Signed-off-by: Siddhesh Poyarekar <siddhesh.poyarekar at gmail.com>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/xkb/XKBMAlloc.c b/xkb/XKBMAlloc.c
index 645e905..3ffd5da 100644
--- a/xkb/XKBMAlloc.c
+++ b/xkb/XKBMAlloc.c
@@ -375,8 +375,10 @@ XkbResizeKeyType(XkbDescPtr xkb,
         nResize = 0;
         for (nTotal = 1, i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
             width = XkbKeyGroupsWidth(xkb, i);
-            if (width < type->num_levels)
+            if (width < type->num_levels || width >= new_num_lvls) {
+                nTotal += XkbKeyNumSyms(xkb,i);
                 continue;
+            }
             for (match = 0, g = XkbKeyNumGroups(xkb, i) - 1;
                  (g >= 0) && (!match); g--) {
                 if (XkbKeyKeyTypeIndex(xkb, i, g) == type_ndx) {
@@ -384,7 +386,7 @@ XkbResizeKeyType(XkbDescPtr xkb,
                     match = 1;
                 }
             }
-            if ((!match) || (width >= new_num_lvls))
+            if (!match)
                 nTotal += XkbKeyNumSyms(xkb, i);
             else {
                 nTotal += XkbKeyNumGroups(xkb, i) * new_num_lvls;
commit 88c767edb01ed7efb19ffe3a453e16107b27130b
Author: Michal Suchanek <hramrach at gmail.com>
Date:   Wed May 23 11:22:05 2012 +0200

    Fix crash for motion events from devices without valuators
    
    A WarpPointer request may trigger a motion event on a device without
    valuators. That request is ignored by GetPointerEvents but during smooth
    scroll emulation we dereference dev->valuators to get the number of axes.
    
    Break out early if the device doesn't have valuators.
    
    Signed-off-by: Michal Suchanek <hramrach at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/getevents.c b/dix/getevents.c
index ae4112f..4fbaa6c 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1615,7 +1615,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     /* Now turn the smooth-scrolling axes back into emulated button presses
      * for legacy clients, based on the integer delta between before and now */
     for (i = 0; i < valuator_mask_size(&mask); i++) {
-        if (i >= pDev->valuator->numAxes)
+        if ( !pDev->valuator || (i >= pDev->valuator->numAxes))
             break;
 
         if (!valuator_mask_isset(&mask, i))
commit b840ba5f54de5b00a7700ca49e51308b8cc66f92
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Dec 16 14:44:55 2011 -0800

    glx: Implement protocol for glXCreateContextAttribsARB
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/createcontext.c b/glx/createcontext.c
index 9c1eab3..025c423 100644
--- a/glx/createcontext.c
+++ b/glx/createcontext.c
@@ -24,13 +24,224 @@
 #include <dix-config.h>
 #endif
 
+#include <GL/glxtokens.h>
 #include "glxserver.h"
+#include "glxext.h"
 #include "indirect_dispatch.h"
 
+#define ALL_VALID_FLAGS \
+    (GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB)
+
+static Bool
+validate_GL_version(int major_version, int minor_version)
+{
+    if (major_version <= 0 || minor_version < 0)
+        return False;
+
+    switch (major_version) {
+    case 1:
+        if (minor_version > 5)
+            return False;
+        break;
+
+    case 2:
+        if (minor_version > 1)
+            return False;
+        break;
+
+    case 3:
+        if (minor_version > 3)
+            return False;
+        break;
+
+    default:
+        break;
+    }
+
+    return True;
+}
+
+static Bool
+validate_render_type(uint32_t render_type)
+{
+    switch (render_type) {
+    case GLX_RGBA_TYPE:
+    case GLX_COLOR_INDEX_TYPE:
+        return True;
+    default:
+        return False;
+    }
+}
+
 int
 __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
 {
-    return BadRequest;
+    ClientPtr client = cl->client;
+    xGLXCreateContextAttribsARBReq *req = (xGLXCreateContextAttribsARBReq *) pc;
+    int32_t *attribs = (req->numAttribs != 0) ? (int32_t *) (req + 1) : NULL;
+    unsigned i;
+    int major_version = 1;
+    int minor_version = 0;
+    uint32_t flags = 0;
+    uint32_t render_type = GLX_RGBA_TYPE;
+    __GLXcontext *ctx = NULL;
+    __GLXcontext *shareCtx = NULL;
+    __GLXscreen *glxScreen;
+    __GLXconfig *config;
+    int err;
+
+    /* Verify that the size of the packet matches the size inferred from the
+     * sizes specified for the various fields.
+     */
+    const unsigned expected_size = (sz_xGLXCreateContextAttribsARBReq
+                                    + (req->numAttribs * 8)) / 4;
+
+    if (req->length != expected_size)
+        return BadLength;
+
+    LEGAL_NEW_RESOURCE(req->context, client);
+
+    /* The GLX_ARB_create_context spec says:
+     *
+     *     "* If <config> is not a valid GLXFBConfig, GLXBadFBConfig is
+     *        generated."
+     *
+     * On the client, the screen comes from the FBConfig, so GLXBadFBConfig
+     * should be issued if the screen is nonsense.
+     */
+    if (!validGlxScreen(client, req->screen, &glxScreen, &err))
+        return __glXError(GLXBadFBConfig);
+
+    if (!validGlxFBConfig(client, glxScreen, req->fbconfig, &config, &err))
+        return __glXError(GLXBadFBConfig);
+
+    /* Validate the context with which the new context should share resources.
+     */
+    if (req->shareList != None) {
+        if (!validGlxContext(client, req->shareList, DixReadAccess,
+                             &shareCtx, &err))
+            return err;
+
+        /* The crazy condition is because C doesn't have a logical XOR
+         * operator.  Comparing directly for equality may fail if one is 1 and
+         * the other is 2 even though both are logically true.
+         */
+        if (!!req->isDirect != !!shareCtx->isDirect) {
+            client->errorValue = req->shareList;
+            return BadMatch;
+        }
+
+        /* The GLX_ARB_create_context spec says:
+         *
+         *     "* If the server context state for <share_context>...was
+         *        created on a different screen than the one referenced by
+         *        <config>...BadMatch is generated."
+         */
+        if (glxScreen != shareCtx->pGlxScreen) {
+            client->errorValue = shareCtx->pGlxScreen->pScreen->myNum;
+            return BadMatch;
+        }
+    }
+
+    for (i = 0; i < req->numAttribs; i++) {
+        switch (attribs[i * 2]) {
+        case GLX_CONTEXT_MAJOR_VERSION_ARB:
+            major_version = attribs[2 * i + 1];
+            break;
+
+        case GLX_CONTEXT_MINOR_VERSION_ARB:
+            minor_version = attribs[2 * i + 1];
+            break;
+
+        case GLX_CONTEXT_FLAGS_ARB:
+            flags = attribs[2 * i + 1];
+            break;
+
+        case GLX_RENDER_TYPE:
+            render_type = attribs[2 * i + 1];
+            break;
+
+        default:
+            return BadValue;
+        }
+    }
+
+    /* The GLX_ARB_create_context spec says:
+     *
+     *     "If attributes GLX_CONTEXT_MAJOR_VERSION_ARB and
+     *     GLX_CONTEXT_MINOR_VERSION_ARB, when considered together
+     *     with attributes GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB and
+     *     GLX_RENDER_TYPE, specify an OpenGL version and feature set
+     *     that are not defined, BadMatch is generated.
+     *
+     *     ...Feature deprecation was introduced with OpenGL 3.0, so
+     *     forward-compatible contexts may only be requested for
+     *     OpenGL 3.0 and above. Thus, examples of invalid
+     *     combinations of attributes include:
+     *
+     *       - Major version < 1 or > 3
+     *       - Major version == 1 and minor version < 0 or > 5
+     *       - Major version == 2 and minor version < 0 or > 1
+     *       - Major version == 3 and minor version > 2
+     *       - Forward-compatible flag set and major version < 3
+     *       - Color index rendering and major version >= 3"
+     */
+    if (!validate_GL_version(major_version, minor_version))
+        return BadMatch;
+
+    if (major_version < 3
+        && ((flags & GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) != 0))
+        return BadMatch;
+
+    if (major_version >= 3 && render_type == GLX_COLOR_INDEX_TYPE)
+        return BadMatch;
+
+    if (!validate_render_type(render_type))
+        return BadValue;
+
+    if ((flags & ~ALL_VALID_FLAGS) != 0)
+        return BadValue;
+
+    /* Allocate memory for the new context
+     */
+    if (req->isDirect) {
+        ctx = __glXdirectContextCreate(glxScreen, config, shareCtx);
+        err = BadAlloc;
+    }
+    else {
+        ctx = glxScreen->createContext(glxScreen, config, shareCtx,
+                                       req->numAttribs, (uint32_t *) attribs,
+                                       &err);
+    }
+
+    if (ctx == NULL)
+        return err;
+
+    ctx->pGlxScreen = glxScreen;
+    ctx->config = config;
+    ctx->id = req->context;
+    ctx->share_id = req->shareList;
+    ctx->idExists = True;
+    ctx->isCurrent = False;
+    ctx->isDirect = req->isDirect;
+    ctx->hasUnflushedCommands = False;
+    ctx->renderMode = GL_RENDER;
+    ctx->feedbackBuf = NULL;
+    ctx->feedbackBufSize = 0;
+    ctx->selectBuf = NULL;
+    ctx->selectBufSize = 0;
+    ctx->drawPriv = NULL;
+    ctx->readPriv = NULL;
+
+    /* Add the new context to the various global tables of GLX contexts.
+     */
+    if (!__glXAddContext(ctx)) {
+        (*ctx->destroy) (ctx);
+        client->errorValue = req->context;
+        return BadAlloc;
+    }
+
+    return Success;
 }
 
 int
commit 23612a63fc12be13442a63193a19f883d7a87e5d
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Dec 16 14:42:51 2011 -0800

    glx: Make several functions available outside the glxcmds.c compilation unit
    
    validGlxScreen, validGlxFBConfig, validGlxContext, and
    __glXdirectContextCreate will soon be used by createcontext.c.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index d9d2201..d483bbf 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -50,7 +50,7 @@
 #include "indirect_table.h"
 #include "indirect_util.h"
 
-static int
+_X_HIDDEN int
 validGlxScreen(ClientPtr client, int screen, __GLXscreen ** pGlxScreen,
                int *err)
 {
@@ -67,7 +67,7 @@ validGlxScreen(ClientPtr client, int screen, __GLXscreen ** pGlxScreen,
     return TRUE;
 }
 
-static int
+_X_HIDDEN int
 validGlxFBConfig(ClientPtr client, __GLXscreen * pGlxScreen, XID id,
                  __GLXconfig ** config, int *err)
 {
@@ -131,7 +131,7 @@ validGlxFBConfigForWindow(ClientPtr client, __GLXconfig * config,
     return TRUE;
 }
 
-static int
+_X_HIDDEN int
 validGlxContext(ClientPtr client, XID id, int access_mode,
                 __GLXcontext ** context, int *err)
 {
@@ -200,7 +200,7 @@ __glXdirectContextDestroy(__GLXcontext * context)
     free(context);
 }
 
-static __GLXcontext *
+_X_HIDDEN __GLXcontext *
 __glXdirectContextCreate(__GLXscreen * screen,
                          __GLXconfig * modes, __GLXcontext * shareContext)
 {
diff --git a/glx/glxcontext.h b/glx/glxcontext.h
index ef2c4db..b803a7f 100644
--- a/glx/glxcontext.h
+++ b/glx/glxcontext.h
@@ -121,4 +121,17 @@ struct __GLXcontext {
 
 void __glXContextDestroy(__GLXcontext * context);
 
+extern int validGlxScreen(ClientPtr client, int screen,
+                          __GLXscreen ** pGlxScreen, int *err);
+
+extern int validGlxFBConfig(ClientPtr client, __GLXscreen * pGlxScreen,
+                            XID id, __GLXconfig ** config, int *err);
+
+extern int validGlxContext(ClientPtr client, XID id, int access_mode,
+                           __GLXcontext ** context, int *err);
+
+extern __GLXcontext *__glXdirectContextCreate(__GLXscreen * screen,
+                                              __GLXconfig * modes,
+                                              __GLXcontext * shareContext);
+
 #endif                          /* !__GLX_context_h__ */
commit cd5689cac5ed722e9dc1a3fab9a260b798062ee6
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Sat Dec 10 15:15:18 2011 -0800

    glx: Use one function to add a context to all global tables
    
    Instead of having separate __glXAddContextToList and AddResource
    functions, just have one function that does both steps.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Jesse Barnes <jbarnes at virtuousgeek.org>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 8a9a1d3..d9d2201 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -308,16 +308,14 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
     glxc->drawPriv = NULL;
     glxc->readPriv = NULL;
 
-    /* Register this context as a resource.
+    /* Add the new context to the various global tables of GLX contexts.
      */
-    if (!AddResource(gcId, __glXContextRes, (pointer)glxc)) {
+    if (!__glXAddContext(glxc)) {
         (*glxc->destroy) (glxc);
         client->errorValue = gcId;
         return BadAlloc;
     }
 
-    __glXAddToContextList(glxc);
-
     return Success;
 }
 
diff --git a/glx/glxext.c b/glx/glxext.c
index 599f029..8d168d8 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -157,11 +157,18 @@ DrawableGone(__GLXdrawable * glxPriv, XID xid)
     return True;
 }
 
-void
-__glXAddToContextList(__GLXcontext * cx)
+Bool
+__glXAddContext(__GLXcontext * cx)
 {
+    /* Register this context as a resource.
+     */
+    if (!AddResource(cx->id, __glXContextRes, (pointer)cx)) {
+	return False;
+    }
+
     cx->next = glxAllContexts;
     glxAllContexts = cx;
+    return True;
 }
 
 static void
diff --git a/glx/glxext.h b/glx/glxext.h
index 7cd5cb4..9b0978b 100644
--- a/glx/glxext.h
+++ b/glx/glxext.h
@@ -38,7 +38,7 @@
 extern GLboolean __glXFreeContext(__GLXcontext * glxc);
 extern void __glXFlushContextCache(void);
 
-extern void __glXAddToContextList(__GLXcontext * cx);
+extern Bool __glXAddContext(__GLXcontext * cx);
 extern void __glXErrorCallBack(GLenum code);
 extern void __glXClearErrorOccured(void);
 extern GLboolean __glXErrorOccured(void);
commit c1d91ab37025d3e0df7e8f647fb21816fe0e8420
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Sat Dec 10 15:11:57 2011 -0800

    glx: Initialize remaining context fields
    
    There is no reason to assume the screen's context allocated
    initialized these fields, so don't.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Jesse Barnes <jbarnes at virtuousgeek.org>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 571ae50..8a9a1d3 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -299,7 +299,14 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
     glxc->idExists = GL_TRUE;
     glxc->isCurrent = GL_FALSE;
     glxc->isDirect = isDirect;
+    glxc->hasUnflushedCommands = GL_FALSE;
     glxc->renderMode = GL_RENDER;
+    glxc->feedbackBuf = NULL;
+    glxc->feedbackBufSize = 0;
+    glxc->selectBuf = NULL;
+    glxc->selectBufSize = 0;
+    glxc->drawPriv = NULL;
+    glxc->readPriv = NULL;
 
     /* Register this context as a resource.
      */
commit 0db76e5f771fb964e67de716a254850a38e02f19
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Sat Dec 10 15:09:57 2011 -0800

    glx: Initialize all context fields together
    
    v2: Fix whitespace error noticed by Christopher James Halse Rogers.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Jesse Barnes <jbarnes at virtuousgeek.org>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 308c14a..571ae50 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -290,26 +290,10 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
         return BadAlloc;
     }
 
-    /*
-     ** Initially, setup the part of the context that could be used by
-     ** a GL core that needs windowing information (e.g., Mesa).
+    /* Initialize the GLXcontext structure.
      */
     glxc->pGlxScreen = pGlxScreen;
     glxc->config = config;
-
-    /*
-     ** Register this context as a resource.
-     */
-    if (!AddResource(gcId, __glXContextRes, (pointer) glxc)) {
-        (*glxc->destroy) (glxc);
-        client->errorValue = gcId;
-        return BadAlloc;
-    }
-
-    /*
-     ** Finally, now that everything is working, setup the rest of the
-     ** context.
-     */
     glxc->id = gcId;
     glxc->share_id = shareList;
     glxc->idExists = GL_TRUE;
@@ -317,6 +301,14 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
     glxc->isDirect = isDirect;
     glxc->renderMode = GL_RENDER;
 
+    /* Register this context as a resource.
+     */
+    if (!AddResource(gcId, __glXContextRes, (pointer)glxc)) {
+        (*glxc->destroy) (glxc);
+        client->errorValue = gcId;
+        return BadAlloc;
+    }
+
     __glXAddToContextList(glxc);
 
     return Success;
commit befa76d251eb5de85edb621056eed52784722bc7
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Dec 9 17:28:21 2011 -0800

    glx: Implement GLX SetClientInfoARB protocol
    
    v2: Bump glproto version to 1.4.15.  This patch uses structure names
    that only exist in that glproto version and later.  Noticed by
    Christopher James Halse Rogers.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/configure.ac b/configure.ac
index 97ceab1..7282931 100644
--- a/configure.ac
+++ b/configure.ac
@@ -777,7 +777,7 @@ DRI2PROTO="dri2proto >= 2.6"
 XINERAMAPROTO="xineramaproto"
 BIGFONTPROTO="xf86bigfontproto >= 1.2.0"
 DGAPROTO="xf86dgaproto >= 2.0.99.1"
-GLPROTO="glproto >= 1.4.14"
+GLPROTO="glproto >= 1.4.15"
 DMXPROTO="dmxproto >= 2.2.99.1"
 VIDMODEPROTO="xf86vidmodeproto >= 2.2.99.1"
 WINDOWSWMPROTO="windowswmproto"
diff --git a/glx/clientinfo.c b/glx/clientinfo.c
index 15bbf15..b26ac1a 100644
--- a/glx/clientinfo.c
+++ b/glx/clientinfo.c
@@ -26,17 +26,62 @@
 
 #include "glxserver.h"
 #include "indirect_dispatch.h"
+#include "glxbyteorder.h"
+#include "unpack.h"
 
 int
 __glXDisp_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
 {
-    return BadRequest;
+    xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
+    char *gl_extensions;
+    char *glx_extensions;
+
+    /* Verify that the size of the packet matches the size inferred from the
+     * sizes specified for the various fields.
+     */
+    const unsigned expected_size = sz_xGLXSetClientInfoARBReq
+        + (req->numVersions * 8)
+        + __GLX_PAD(req->numGLExtensionBytes)
+        + __GLX_PAD(req->numGLXExtensionBytes);
+
+    if (req->length != (expected_size / 4))
+        return BadLength;
+
+    /* Verify that the actual length of the GL extension string matches what's
+     * encoded in protocol packet.
+     */
+    gl_extensions = (char *) (req + 1) + (req->numVersions * 8);
+    if (req->numGLExtensionBytes != 0
+        && memchr(gl_extensions, 0,
+                  __GLX_PAD(req->numGLExtensionBytes)) == NULL)
+        return BadLength;
+
+    /* Verify that the actual length of the GLX extension string matches
+     * what's encoded in protocol packet.
+     */
+    glx_extensions = gl_extensions + __GLX_PAD(req->numGLExtensionBytes);
+    if (req->numGLXExtensionBytes != 0
+        && memchr(glx_extensions, 0,
+                  __GLX_PAD(req->numGLXExtensionBytes)) == NULL)
+        return BadLength;
+
+    free(cl->GLClientextensions);
+    cl->GLClientextensions = strdup(gl_extensions);
+
+    return 0;
 }
 
 int
 __glXDispSwap_SetClientInfoARB(__GLXclientState * cl, GLbyte * pc)
 {
-    return BadRequest;
+    xGLXSetClientInfoARBReq *req = (xGLXSetClientInfoARBReq *) pc;
+
+    req->length = bswap_16(req->length);
+    req->numVersions = bswap_32(req->numVersions);
+    req->numGLExtensionBytes = bswap_32(req->numGLExtensionBytes);
+    req->numGLXExtensionBytes = bswap_32(req->numGLXExtensionBytes);
+
+    return __glXDisp_SetClientInfoARB(cl, pc);
 }
 
 int
commit 8b8cd6f6f4dbf9d058ace638221f31801da7df9f
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Dec 5 13:52:01 2011 -0800

    glx: Optionally call DRI2 createContextAttribs from __glXDRIscreenCreateContext
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 044016d..46620a0 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -47,6 +47,7 @@
 #include "glxserver.h"
 #include "glxutil.h"
 #include "glxdricommon.h"
+#include <GL/glxtokens.h>
 
 #include "glapitable.h"
 #include "glapi.h"
@@ -377,6 +378,143 @@ __glXDRIscreenDestroy(__GLXscreen * baseScreen)
     free(screen);
 }
 
+static Bool
+dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
+                         unsigned *major_ver, unsigned *minor_ver,
+                         uint32_t *flags, unsigned *error)
+{
+    unsigned i;
+
+    if (num_attribs == 0)
+        return True;
+
+    if (attribs == NULL) {
+        *error = BadImplementation;
+        return False;
+    }
+
+    *major_ver = 1;
+    *minor_ver = 0;
+
+    for (i = 0; i < num_attribs; i++) {
+        switch (attribs[i * 2]) {
+        case GLX_CONTEXT_MAJOR_VERSION_ARB:
+            *major_ver = attribs[i * 2 + 1];
+            break;
+        case GLX_CONTEXT_MINOR_VERSION_ARB:
+            *minor_ver = attribs[i * 2 + 1];
+            break;
+        case GLX_CONTEXT_FLAGS_ARB:
+            *flags = attribs[i * 2 + 1];
+            break;
+        case GLX_RENDER_TYPE:
+            break;
+        default:
+            /* If an unknown attribute is received, fail.
+             */
+            *error = BadValue;
+            return False;
+        }
+    }
+
+    /* Unknown flag value.
+     */
+    if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE)) {
+        *error = BadValue;
+        return False;
+    }
+
+    *error = Success;
+    return True;
+}
+
+static void
+create_driver_context(__GLXDRIcontext * context,
+                      __GLXDRIscreen * screen,
+                      __GLXDRIconfig * config,
+                      __DRIcontext * driShare,
+                      unsigned num_attribs,
+                      const uint32_t *attribs,
+                      int *error)
+{
+    context->driContext = NULL;
+
+#if __DRI_DRI2_VERSION >= 3
+    if (screen->dri2->base.version >= 3) {
+        uint32_t ctx_attribs[3 * 2];
+        unsigned num_ctx_attribs = 0;
+        unsigned dri_err = 0;
+        unsigned major_ver;
+        unsigned minor_ver;
+        uint32_t flags;
+
+        if (num_attribs != 0) {
+            if (!dri2_convert_glx_attribs(num_attribs, attribs,
+                                          &major_ver, &minor_ver,
+                                          &flags, (unsigned *) error))
+                return NULL;
+
+            ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
+            ctx_attribs[num_ctx_attribs++] = major_ver;
+            ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
+            ctx_attribs[num_ctx_attribs++] = minor_ver;
+
+            if (flags != 0) {
+                ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
+
+                /* The current __DRI_CTX_FLAG_* values are identical to the
+                 * GLX_CONTEXT_*_BIT values.
+                 */
+                ctx_attribs[num_ctx_attribs++] = flags;
+            }
+        }
+
+        context->driContext =
+            (*screen->dri2->createContextAttribs)(screen->driScreen,
+                                                  __DRI_API_OPENGL,
+                                                  config->driConfig,
+                                                  driShare,
+                                                  num_ctx_attribs / 2,
+                                                  ctx_attribs,
+                                                  &dri_err,
+                                                  context);
+
+        switch (dri_err) {
+        case __DRI_CTX_ERROR_SUCCESS:
+            *error = Success;
+            break;
+        case __DRI_CTX_ERROR_NO_MEMORY:
+            *error = BadAlloc;
+            break;
+        case __DRI_CTX_ERROR_BAD_API:
+            *error = __glXError(GLXBadProfileARB);
+            break;
+        case __DRI_CTX_ERROR_BAD_VERSION:
+        case __DRI_CTX_ERROR_BAD_FLAG:
+            *error = __glXError(GLXBadFBConfig);
+            break;
+        case __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE:
+        case __DRI_CTX_ERROR_UNKNOWN_FLAG:
+        default:
+            *error = BadValue;
+            break;
+        }
+
+        return;
+    }
+#endif
+
+    if (num_attribs != 0) {
+        *error = BadValue;
+        return;
+    }
+
+    context->driContext =
+        (*screen->dri2->createNewContext) (screen->driScreen,
+                                           config->driConfig,
+                                           driShare, context);
+}
+
 static __GLXcontext *
 __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
                             __GLXconfig * glxConfig,
@@ -397,8 +535,10 @@ __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
         driShare = NULL;
 
     context = calloc(1, sizeof *context);
-    if (context == NULL)
+    if (context == NULL) {
+        *error = BadAlloc;
         return NULL;
+    }
 
     context->base.destroy = __glXDRIcontextDestroy;
     context->base.makeCurrent = __glXDRIcontextMakeCurrent;
@@ -407,10 +547,8 @@ __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
     context->base.textureFromPixmap = &__glXDRItextureFromPixmap;
     context->base.wait = __glXDRIcontextWait;
 
-    context->driContext =
-        (*screen->dri2->createNewContext) (screen->driScreen,
-                                           config->driConfig,
-                                           driShare, context);
+    create_driver_context(context, screen, config, driShare, num_attribs,
+                          attribs, error);
     if (context->driContext == NULL) {
         free(context);
         return NULL;
@@ -646,6 +784,14 @@ initializeExtensions(__GLXDRIscreen * screen)
     __glXEnableExtension(screen->glx_enable_bits, "GLX_INTEL_swap_event");
     LogMessage(X_INFO, "AIGLX: enabled GLX_INTEL_swap_event\n");
 
+#if __DRI_DRI2_VERSION >= 3
+    if (screen->dri2->base.version >= 3) {
+        __glXEnableExtension(screen->glx_enable_bits,
+                             "GLX_ARB_create_context");
+        LogMessage(X_INFO, "AIGLX: enabled GLX_ARB_create_context\n");
+    }
+#endif
+
     if (DRI2HasSwapControl(pScreen)) {
         __glXEnableExtension(screen->glx_enable_bits, "GLX_SGI_swap_control");
         __glXEnableExtension(screen->glx_enable_bits, "GLX_MESA_swap_control");
commit 0a9226376c9a44c3b50baad25f2b7d2b9fecb708
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Dec 5 13:48:19 2011 -0800

    glx: Add tracking for GLX_ARB_create_context and GLX_ARB_create_context_profile
    
    The formatting of the extension data table was mangled by indent.
    This patch also undoes that and adds approripate control comments so
    that indent won't do it again.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/extension_string.c b/glx/extension_string.c
index 866f8bf..6a1a6c6 100644
--- a/glx/extension_string.c
+++ b/glx/extension_string.c
@@ -67,23 +67,27 @@ struct extension_info {
 
 static const struct extension_info known_glx_extensions[] = {
 /*   GLX_ARB_get_proc_address is implemented on the client. */
-    {GLX(ARB_multisample), VER(1, 4), Y,},
-
-    {GLX(EXT_import_context), VER(0, 0), Y,},
-    {GLX(EXT_texture_from_pixmap), VER(0, 0), Y,},
-    {GLX(EXT_visual_info), VER(0, 0), Y,},
-    {GLX(EXT_visual_rating), VER(0, 0), Y,},
-
-    {GLX(MESA_copy_sub_buffer), VER(0, 0), N,},
-    {GLX(OML_swap_method), VER(0, 0), Y,},
-    {GLX(SGI_make_current_read), VER(1, 3), N,},
-    {GLX(SGI_swap_control), VER(0, 0), N,},
-    {GLX(SGIS_multisample), VER(0, 0), Y,},
-    {GLX(SGIX_fbconfig), VER(1, 3), Y,},
-    {GLX(SGIX_pbuffer), VER(1, 3), Y,},
-    {GLX(SGIX_visual_select_group), VER(0, 0), Y,},
-    {GLX(INTEL_swap_event), VER(1, 4), N,},
-    {NULL}
+    /* *INDENT-OFF* */
+    { GLX(ARB_create_context),          VER(0,0), N, },
+    { GLX(ARB_create_context_profile),  VER(0,0), N, },
+    { GLX(ARB_multisample),             VER(1,4), Y, },
+
+    { GLX(EXT_import_context),          VER(0,0), Y, },
+    { GLX(EXT_texture_from_pixmap),     VER(0,0), Y, },
+    { GLX(EXT_visual_info),             VER(0,0), Y, },
+    { GLX(EXT_visual_rating),           VER(0,0), Y, },
+
+    { GLX(MESA_copy_sub_buffer),        VER(0,0), N, },
+    { GLX(OML_swap_method),             VER(0,0), Y, },
+    { GLX(SGI_make_current_read),       VER(1,3), N, },
+    { GLX(SGI_swap_control),            VER(0,0), N, },
+    { GLX(SGIS_multisample),            VER(0,0), Y, },
+    { GLX(SGIX_fbconfig),               VER(1,3), Y, },
+    { GLX(SGIX_pbuffer),                VER(1,3), Y, },
+    { GLX(SGIX_visual_select_group),    VER(0,0), Y, },
+    { GLX(INTEL_swap_event),            VER(1,4), N, },
+    { NULL }
+    /* *INDENT-ON* */
 };
 
 /**
diff --git a/glx/extension_string.h b/glx/extension_string.h
index e02213f..947bf89 100644
--- a/glx/extension_string.h
+++ b/glx/extension_string.h
@@ -36,7 +36,9 @@
 
 enum {
 /*   GLX_ARB_get_proc_address is implemented on the client. */
-    ARB_multisample_bit = 0,
+    ARB_create_context_bit = 0,
+    ARB_create_context_profile_bit,
+    ARB_multisample_bit,
     EXT_import_context_bit,
     EXT_texture_from_pixmap_bit,
     EXT_visual_info_bit,
commit 96d74138b1c0273e88933220d99a893858b649cd
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Dec 5 10:56:07 2011 -0800

    glx: Extend __GLXscreen::createContext to take attributes
    
    The attributes will be used for glXCreateContextAttribsARB additions
    in follow-on patches.
    
    v2: Add missing 'int *error' parameters noticed by Christopher James
    Halse Rogers.
    
    v3: Remove redundant 'int err;' declaration noticed by Christopher
    James Halse Rogers.  This was supposed to be in v2, but I missed it.
    
    v4: Add comma missing from additions in v2.  Ugh.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Jesse Barnes <jbarnes at virtuousgeek.org>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 5c70afa..308c14a 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -276,8 +276,14 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
     /*
      ** Allocate memory for the new context
      */
-    if (!isDirect)
-        glxc = pGlxScreen->createContext(pGlxScreen, config, shareglxc);
+    if (!isDirect) {
+        /* Without any attributes, the only error that the driver should be
+         * able to generate is BadAlloc.  As result, just drop the error
+         * returned from the driver on the floor.
+         */
+        glxc = pGlxScreen->createContext(pGlxScreen, config, shareglxc,
+                                         0, NULL, &err);
+    }
     else
         glxc = __glXdirectContextCreate(pGlxScreen, config, shareglxc);
     if (!glxc) {
diff --git a/glx/glxdri.c b/glx/glxdri.c
index b2209c5..666636e 100644
--- a/glx/glxdri.c
+++ b/glx/glxdri.c
@@ -599,7 +599,10 @@ __glXDRIscreenDestroy(__GLXscreen * baseScreen)
 static __GLXcontext *
 __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
                             __GLXconfig * glxConfig,
-                            __GLXcontext * baseShareContext)
+                            __GLXcontext * baseShareContext,
+                            unsigned num_attribs,
+                            const uint32_t *attribs,
+                            int *error)
 {
     __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
     __GLXDRIcontext *context, *shareContext;
@@ -611,6 +614,13 @@ __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
     drm_context_t hwContext;
     ScreenPtr pScreen = baseScreen->pScreen;
 
+    /* DRI1 cannot support createContextAttribs, so these parameters will
+     * never be used.
+     */
+    (void) num_attribs;
+    (void) attribs;
+    (void) error;
+
     shareContext = (__GLXDRIcontext *) baseShareContext;
     if (shareContext)
         driShare = shareContext->driContext;
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index cceb126..044016d 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -380,7 +380,10 @@ __glXDRIscreenDestroy(__GLXscreen * baseScreen)
 static __GLXcontext *
 __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
                             __GLXconfig * glxConfig,
-                            __GLXcontext * baseShareContext)
+                            __GLXcontext * baseShareContext,
+                            unsigned num_attribs,
+                            const uint32_t *attribs,
+                            int *error)
 {
     __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
     __GLXDRIcontext *context, *shareContext;
diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index c69b4d2..b478398 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -257,7 +257,10 @@ __glXDRIscreenDestroy(__GLXscreen * baseScreen)
 static __GLXcontext *
 __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
                             __GLXconfig * glxConfig,
-                            __GLXcontext * baseShareContext)
+                            __GLXcontext * baseShareContext,
+                            unsigned num_attribs,
+                            const uint32_t *attribs,
+                            int *error)
 {
     __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
     __GLXDRIcontext *context, *shareContext;
@@ -265,6 +268,13 @@ __glXDRIscreenCreateContext(__GLXscreen * baseScreen,
     const __DRIcoreExtension *core = screen->core;
     __DRIcontext *driShare;
 
+    /* DRISWRAST won't support createContextAttribs, so these parameters will
+     * never be used.
+     */
+    (void) num_attribs;
+    (void) attribs;
+    (void) error;
+
     shareContext = (__GLXDRIcontext *) baseShareContext;
     if (shareContext)
         driShare = shareContext->driContext;
diff --git a/glx/glxscreens.h b/glx/glxscreens.h
index d5420ee..7ef4657 100644
--- a/glx/glxscreens.h
+++ b/glx/glxscreens.h
@@ -117,7 +117,10 @@ struct __GLXscreen {
 
     __GLXcontext *(*createContext) (__GLXscreen * screen,
                                     __GLXconfig * modes,
-                                    __GLXcontext * shareContext);
+                                    __GLXcontext * shareContext,
+                                    unsigned num_attribs,
+                                    const uint32_t *attribs,
+                                    int *error);
 
     __GLXdrawable *(*createDrawable) (ClientPtr client,
                                       __GLXscreen * context,
commit 62f06b0dcde13cb87bc3d0c5ff86d8db7e3ff0ef
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Dec 2 21:14:46 2011 -0800

    glx: Don't track GLClientmajorVersion or GLClientminorVersion
    
    Nothing uses these fields anywhere in the server.
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Jesse Barnes <jbarnes at virtuousgeek.org>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 6fa10fe..5c70afa 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2396,8 +2396,6 @@ __glXDisp_ClientInfo(__GLXclientState * cl, GLbyte * pc)
     if (!memchr(buf, 0, (client->req_len << 2) - sizeof(xGLXClientInfoReq)))
         return BadLength;
 
-    cl->GLClientmajorVersion = req->major;
-    cl->GLClientminorVersion = req->minor;
     free(cl->GLClientextensions);
     cl->GLClientextensions = strdup(buf);
 
diff --git a/glx/glxext.c b/glx/glxext.c
index acd696e..599f029 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -281,8 +281,6 @@ glxClientCallback(CallbackListPtr *list, pointer closure, pointer data)
          ** By default, assume that the client supports
          ** GLX major version 1 minor version 0 protocol.
          */
-        cl->GLClientmajorVersion = 1;
-        cl->GLClientminorVersion = 0;
         cl->client = pClient;
         break;
 
diff --git a/glx/glxserver.h b/glx/glxserver.h
index 7076848..87c94d9 100644
--- a/glx/glxserver.h
+++ b/glx/glxserver.h
@@ -145,8 +145,6 @@ struct __GLXclientStateRec {
     /* Back pointer to X client record */
     ClientPtr client;
 
-    int GLClientmajorVersion;
-    int GLClientminorVersion;
     char *GLClientextensions;
 };
 
commit 724176a87afdb9a79ce6307214bc2e869530aef3
Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Dec 5 10:55:20 2011 -0800

    glx: Fix mishandling of shared contexts
    
    Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 24fed8f..6fa10fe 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -251,20 +251,20 @@ DoCreateContext(__GLXclientState * cl, GLXContextID gcId,
                              &shareglxc, &err))
             return err;
 
-        if (shareglxc->isDirect) {
-            /*
-             ** NOTE: no support for sharing display lists between direct
-             ** contexts, even if they are in the same address space.
-             */
-#if 0
-            /* Disabling this code seems to allow shared display lists
-             * and texture objects to work.  We'll leave it disabled for now.
-             */
+        /* Page 26 (page 32 of the PDF) of the GLX 1.4 spec says:
+         *
+         *     "The server context state for all sharing contexts must exist
+         *     in a single address space or a BadMatch error is generated."
+         *
+         * If the share context is indirect, force the new context to also be
+         * indirect.  If the shard context is direct but the new context
+         * cannot be direct, generate BadMatch.
+         */
+        if (shareglxc->isDirect && !isDirect) {
             client->errorValue = shareList;
             return BadMatch;
-#endif
         }
-        else {
+        else if (!shareglxc->isDirect) {
             /*
              ** Create an indirect context regardless of what the client asked
              ** for; this way we can share display list space with shareList.


More information about the Xquartz-changes mailing list